From 31dc35e18cc7f508155f1ef5ed8f18313c00bf87 Mon Sep 17 00:00:00 2001 From: Denis Davydov Date: Fri, 18 Aug 2017 15:44:35 +0200 Subject: [PATCH] move ConstantFunction and ZeroFunction to Functions:: namespace --- include/deal.II/base/function.h | 235 ++++++----- include/deal.II/base/function.templates.h | 460 +++++++++++----------- source/base/function.inst.in | 8 +- 3 files changed, 367 insertions(+), 336 deletions(-) diff --git a/include/deal.II/base/function.h b/include/deal.II/base/function.h index a377407d4c..2b618b8dd4 100644 --- a/include/deal.II/base/function.h +++ b/include/deal.II/base/function.h @@ -347,135 +347,158 @@ public: }; - -/** - * Provide a function which always returns zero. Obviously, also the derivates - * of this function are zero. Also, it returns zero on all components in case - * the function is not a scalar one, which can be obtained by passing the - * constructor the appropriate number of components. - * - * This function is of use when you want to implement homogeneous boundary - * conditions, or zero initial conditions. - * - * @ingroup functions - * @author Wolfgang Bangerth, 1998, 1999 - */ -template -class ZeroFunction : public Function +namespace Functions { -public: - /** - * Constructor. The number of components is preset to one. - */ - ZeroFunction (const unsigned int n_components = 1); + /** - * Virtual destructor; absolutely necessary in this case. + * Provide a function which always returns zero. Obviously, also the derivates + * of this function are zero. Also, it returns zero on all components in case + * the function is not a scalar one, which can be obtained by passing the + * constructor the appropriate number of components. * + * This function is of use when you want to implement homogeneous boundary + * conditions, or zero initial conditions. + * + * @ingroup functions + * @author Wolfgang Bangerth, 1998, 1999 */ - virtual ~ZeroFunction (); + template + class ZeroFunction : public Function + { + public: + /** + * Constructor. The number of components is preset to one. + */ + ZeroFunction (const unsigned int n_components = 1); - virtual Number value (const Point &p, - const unsigned int component) const; + /** + * Virtual destructor; absolutely necessary in this case. + * + */ + virtual ~ZeroFunction (); - virtual void vector_value (const Point &p, - Vector &return_value) const; + virtual Number value (const Point &p, + const unsigned int component = 0) const; - virtual void value_list (const std::vector > &points, - std::vector &values, - const unsigned int component = 0) const; + virtual void vector_value (const Point &p, + Vector &return_value) const; - virtual void vector_value_list (const std::vector > &points, - std::vector > &values) const; + virtual void value_list (const std::vector > &points, + std::vector &values, + const unsigned int component = 0) const; - virtual Tensor<1,dim, Number> gradient (const Point &p, - const unsigned int component = 0) const; + virtual void vector_value_list (const std::vector > &points, + std::vector > &values) const; - virtual void vector_gradient (const Point &p, - std::vector > &gradients) const; + virtual Tensor<1,dim, Number> gradient (const Point &p, + const unsigned int component = 0) const; - virtual void gradient_list (const std::vector > &points, - std::vector > &gradients, - const unsigned int component = 0) const; + virtual void vector_gradient (const Point &p, + std::vector > &gradients) const; - virtual void vector_gradient_list (const std::vector > &points, - std::vector > > &gradients) const; -}; + virtual void gradient_list (const std::vector > &points, + std::vector > &gradients, + const unsigned int component = 0) const; + + virtual void vector_gradient_list (const std::vector > &points, + std::vector > > &gradients) const; + }; + /** + * Provide a function which always returns the constant values handed to the + * constructor. + * + * Obviously, the derivates of this function are zero, which is why we derive + * this class from ZeroFunction: we then only have to overload the + * value functions, not all the derivatives. In some way, it would be more + * obvious to do the derivation in the opposite direction, i.e. let + * ZeroFunction be a more specialized version of + * ConstantFunction; however, this would be less efficient, since we + * could not make use of the fact that the function value of the + * ZeroFunction is known at compile time and need not be looked up + * somewhere in memory. + * + * @ingroup functions + * @author Wolfgang Bangerth, 1998, 1999, Lei Qiao, 2015 + */ + template + class ConstantFunction : public ZeroFunction + { + public: + /** + * Constructor; set values of all components to the provided one. The + * default number of components is one. + */ + ConstantFunction (const Number value, + const unsigned int n_components = 1); + + /** + * Constructor; takes an std::vector object as an argument. + * The number of components is determined by values.size(). + */ + ConstantFunction (const std::vector &values); + + /** + * Constructor; takes an Vector object as an argument. The + * number of components is determined by values.size(). + */ + ConstantFunction (const Vector &values); + + /** + * Constructor; uses whatever stores in [begin_ptr, begin_ptr+n_components) + * to initialize a new object. + */ + ConstantFunction (const Number *begin_ptr, const unsigned int n_components); + + /** + * Virtual destructor; absolutely necessary in this case. + */ + virtual ~ConstantFunction (); + + virtual Number value (const Point &p, + const unsigned int component = 0) const; + + virtual void vector_value (const Point &p, + Vector &return_value) const; + + virtual void value_list (const std::vector > &points, + std::vector &return_values, + const unsigned int component = 0) const; + + virtual void vector_value_list (const std::vector > &points, + std::vector > &return_values) const; + + std::size_t memory_consumption () const; + + protected: + /** + * Store the constant function value vector. + */ + std::vector function_value_vector; + }; + +} + /** * Provide a function which always returns the constant values handed to the * constructor. * - * Obviously, the derivates of this function are zero, which is why we derive - * this class from ZeroFunction: we then only have to overload the - * value functions, not all the derivatives. In some way, it would be more - * obvious to do the derivation in the opposite direction, i.e. let - * ZeroFunction be a more specialized version of - * ConstantFunction; however, this would be less efficient, since we - * could not make use of the fact that the function value of the - * ZeroFunction is known at compile time and need not be looked up - * somewhere in memory. - * - * @ingroup functions - * @author Wolfgang Bangerth, 1998, 1999, Lei Qiao, 2015 + * @deprecated use Functions::ConstantFunction instead. */ -template -class ConstantFunction : public ZeroFunction -{ -public: - /** - * Constructor; set values of all components to the provided one. The - * default number of components is one. - */ - ConstantFunction (const Number value, - const unsigned int n_components = 1); - - /** - * Constructor; takes an std::vector object as an argument. - * The number of components is determined by values.size(). - */ - ConstantFunction (const std::vector &values); - - /** - * Constructor; takes an Vector object as an argument. The - * number of components is determined by values.size(). - */ - ConstantFunction (const Vector &values); - - /** - * Constructor; uses whatever stores in [begin_ptr, begin_ptr+n_components) - * to initialize a new object. - */ - ConstantFunction (const Number *begin_ptr, const unsigned int n_components); - - /** - * Virtual destructor; absolutely necessary in this case. - */ - virtual ~ConstantFunction (); +template +using ConstantFunction DEAL_II_DEPRECATED = Functions::ConstantFunction; - virtual Number value (const Point &p, - const unsigned int component) const; - - virtual void vector_value (const Point &p, - Vector &return_value) const; - - virtual void value_list (const std::vector > &points, - std::vector &return_values, - const unsigned int component = 0) const; - - virtual void vector_value_list (const std::vector > &points, - std::vector > &return_values) const; - - std::size_t memory_consumption () const; +/** + * Provide a function which always returns zero. + * + * @deprecated use Functions::ZeroFunction instead. + */ +template +using ZeroFunction DEAL_II_DEPRECATED = Functions::ZeroFunction; -protected: - /** - * Store the constant function value vector. - */ - std::vector function_value_vector; -}; /** diff --git a/include/deal.II/base/function.templates.h b/include/deal.II/base/function.templates.h index bd6deb9ab1..14e87c92ca 100644 --- a/include/deal.II/base/function.templates.h +++ b/include/deal.II/base/function.templates.h @@ -297,240 +297,248 @@ Function::memory_consumption () const //--------------------------------------------------------------------------- - - -template -ZeroFunction::ZeroFunction (const unsigned int n_components) - : - Function (n_components) -{} - - -template -ZeroFunction::~ZeroFunction () -{} - - -template -Number ZeroFunction::value (const Point &, - const unsigned int) const -{ - return 0.; -} - - -template -void ZeroFunction::vector_value (const Point &, - Vector &return_value) const +namespace Functions { - Assert (return_value.size() == this->n_components, - ExcDimensionMismatch (return_value.size(), this->n_components)); - - std::fill (return_value.begin(), return_value.end(), 0.0); -} - - -template -void ZeroFunction::value_list ( - const std::vector > &points, - std::vector &values, - const unsigned int /*component*/) const -{ - (void)points; - Assert (values.size() == points.size(), - ExcDimensionMismatch(values.size(), points.size())); - std::fill (values.begin(), values.end(), 0.); -} + template + ZeroFunction::ZeroFunction (const unsigned int n_components) + : + Function (n_components) + {} + + + template + ZeroFunction::~ZeroFunction () + {} + + + template + Number ZeroFunction::value (const Point &, + const unsigned int) const + { + return 0.; + } + + + template + void ZeroFunction::vector_value (const Point &, + Vector &return_value) const + { + Assert (return_value.size() == this->n_components, + ExcDimensionMismatch (return_value.size(), this->n_components)); + + std::fill (return_value.begin(), return_value.end(), 0.0); + } + + + template + void ZeroFunction::value_list ( + const std::vector > &points, + std::vector &values, + const unsigned int /*component*/) const + { + (void)points; + Assert (values.size() == points.size(), + ExcDimensionMismatch(values.size(), points.size())); + + std::fill (values.begin(), values.end(), 0.); + } + + + template + void ZeroFunction::vector_value_list ( + const std::vector > &points, + std::vector > &values) const + { + Assert (values.size() == points.size(), + ExcDimensionMismatch(values.size(), points.size())); + + for (unsigned int i=0; in_components, + ExcDimensionMismatch(values[i].size(), this->n_components)); + std::fill (values[i].begin(), values[i].end(), 0.); + }; + } + + + template + Tensor<1,dim,Number> ZeroFunction::gradient (const Point &, + const unsigned int) const + { + return Tensor<1,dim,Number>(); + } + + + template + void ZeroFunction::vector_gradient ( + const Point &, + std::vector > &gradients) const + { + Assert (gradients.size() == this->n_components, + ExcDimensionMismatch(gradients.size(), this->n_components)); + + for (unsigned int c=0; cn_components; ++c) + gradients[c].clear (); + } + + + template + void ZeroFunction::gradient_list ( + const std::vector > &points, + std::vector > &gradients, + const unsigned int /*component*/) const + { + Assert (gradients.size() == points.size(), + ExcDimensionMismatch(gradients.size(), points.size())); + + for (unsigned int i=0; i + void ZeroFunction::vector_gradient_list ( + const std::vector > &points, + std::vector > > &gradients) const + { + Assert (gradients.size() == points.size(), + ExcDimensionMismatch(gradients.size(), points.size())); + for (unsigned int i=0; in_components, + ExcDimensionMismatch(gradients[i].size(), this->n_components)); + for (unsigned int c=0; cn_components; ++c) + gradients[i][c].clear (); + }; + } - -template -void ZeroFunction::vector_value_list ( - const std::vector > &points, - std::vector > &values) const -{ - Assert (values.size() == points.size(), - ExcDimensionMismatch(values.size(), points.size())); - - for (unsigned int i=0; in_components, - ExcDimensionMismatch(values[i].size(), this->n_components)); - std::fill (values[i].begin(), values[i].end(), 0.); - }; -} - - -template -Tensor<1,dim,Number> ZeroFunction::gradient (const Point &, - const unsigned int) const -{ - return Tensor<1,dim,Number>(); -} - - -template -void ZeroFunction::vector_gradient ( - const Point &, - std::vector > &gradients) const -{ - Assert (gradients.size() == this->n_components, - ExcDimensionMismatch(gradients.size(), this->n_components)); - - for (unsigned int c=0; cn_components; ++c) - gradients[c].clear (); -} - - -template -void ZeroFunction::gradient_list ( - const std::vector > &points, - std::vector > &gradients, - const unsigned int /*component*/) const -{ - Assert (gradients.size() == points.size(), - ExcDimensionMismatch(gradients.size(), points.size())); - - for (unsigned int i=0; i -void ZeroFunction::vector_gradient_list ( - const std::vector > &points, - std::vector > > &gradients) const -{ - Assert (gradients.size() == points.size(), - ExcDimensionMismatch(gradients.size(), points.size())); - for (unsigned int i=0; in_components, - ExcDimensionMismatch(gradients[i].size(), this->n_components)); - for (unsigned int c=0; cn_components; ++c) - gradients[i][c].clear (); - }; } //--------------------------------------------------------------------------- -template -ConstantFunction::ConstantFunction (const Number value, - const unsigned int n_components) - : - ZeroFunction (n_components), - function_value_vector (n_components, value) -{} - -template -ConstantFunction:: -ConstantFunction (const std::vector &values) - : - ZeroFunction (values.size()), - function_value_vector (values) -{} - - -template -ConstantFunction:: -ConstantFunction (const Vector &values) - : - ZeroFunction (values.size()), - function_value_vector (values.size()) -{ - Assert (values.size() == function_value_vector.size(), - ExcDimensionMismatch (values.size(), function_value_vector.size())); - std::copy (values.begin(),values.end(),function_value_vector.begin()); -} - - -template -ConstantFunction:: -ConstantFunction (const Number *begin_ptr, const unsigned int n_components) - : - ZeroFunction (n_components), - function_value_vector (n_components) -{ - Assert (begin_ptr != nullptr, ExcMessage ("Null pointer encountered!")); - std::copy (begin_ptr, begin_ptr+n_components, function_value_vector.begin()); -} - - - -template -ConstantFunction::~ConstantFunction () -{ - function_value_vector.clear(); -} - - -template -Number ConstantFunction::value (const Point &, - const unsigned int component) const -{ - Assert (component < this->n_components, - ExcIndexRange (component, 0, this->n_components)); - return function_value_vector[component]; -} +namespace Functions +{ + + template + ConstantFunction::ConstantFunction (const Number value, + const unsigned int n_components) + : + ZeroFunction (n_components), + function_value_vector (n_components, value) + {} + + template + ConstantFunction:: + ConstantFunction (const std::vector &values) + : + ZeroFunction (values.size()), + function_value_vector (values) + {} + + + template + ConstantFunction:: + ConstantFunction (const Vector &values) + : + ZeroFunction (values.size()), + function_value_vector (values.size()) + { + Assert (values.size() == function_value_vector.size(), + ExcDimensionMismatch (values.size(), function_value_vector.size())); + std::copy (values.begin(),values.end(),function_value_vector.begin()); + } + + + template + ConstantFunction:: + ConstantFunction (const Number *begin_ptr, const unsigned int n_components) + : + ZeroFunction (n_components), + function_value_vector (n_components) + { + Assert (begin_ptr != nullptr, ExcMessage ("Null pointer encountered!")); + std::copy (begin_ptr, begin_ptr+n_components, function_value_vector.begin()); + } + + + + template + ConstantFunction::~ConstantFunction () + { + function_value_vector.clear(); + } + + + template + Number ConstantFunction::value (const Point &, + const unsigned int component) const + { + Assert (component < this->n_components, + ExcIndexRange (component, 0, this->n_components)); + return function_value_vector[component]; + } + + + + template + void ConstantFunction::vector_value (const Point &, + Vector &return_value) const + { + Assert (return_value.size() == this->n_components, + ExcDimensionMismatch (return_value.size(), this->n_components)); + + std::copy (function_value_vector.begin(),function_value_vector.end(), + return_value.begin()); + } + + + + template + void ConstantFunction::value_list ( + const std::vector > &points, + std::vector &return_values, + const unsigned int component) const + { + // To avoid warning of unused parameter + (void)points; + Assert (component < this->n_components, + ExcIndexRange (component, 0, this->n_components)); + Assert (return_values.size() == points.size(), + ExcDimensionMismatch(return_values.size(), points.size())) + + std::fill (return_values.begin(), return_values.end(), function_value_vector[component]); + } + + + + template + void ConstantFunction::vector_value_list ( + const std::vector > &points, + std::vector > &return_values) const + { + Assert (return_values.size() == points.size(), + ExcDimensionMismatch(return_values.size(), points.size())); + + for (unsigned int i=0; in_components, + ExcDimensionMismatch(return_values[i].size(), this->n_components)); + std::copy (function_value_vector.begin(),function_value_vector.end(), + return_values[i].begin()); + }; + } + + + + template + std::size_t + ConstantFunction::memory_consumption () const + { + // Here we assume Number is a simple type. + return (sizeof(*this) + this->n_components*sizeof(Number)); + } - - -template -void ConstantFunction::vector_value (const Point &, - Vector &return_value) const -{ - Assert (return_value.size() == this->n_components, - ExcDimensionMismatch (return_value.size(), this->n_components)); - - std::copy (function_value_vector.begin(),function_value_vector.end(), - return_value.begin()); -} - - - -template -void ConstantFunction::value_list ( - const std::vector > &points, - std::vector &return_values, - const unsigned int component) const -{ - // To avoid warning of unused parameter - (void)points; - Assert (component < this->n_components, - ExcIndexRange (component, 0, this->n_components)); - Assert (return_values.size() == points.size(), - ExcDimensionMismatch(return_values.size(), points.size())) - - std::fill (return_values.begin(), return_values.end(), function_value_vector[component]); -} - - - -template -void ConstantFunction::vector_value_list ( - const std::vector > &points, - std::vector > &return_values) const -{ - Assert (return_values.size() == points.size(), - ExcDimensionMismatch(return_values.size(), points.size())); - - for (unsigned int i=0; in_components, - ExcDimensionMismatch(return_values[i].size(), this->n_components)); - std::copy (function_value_vector.begin(),function_value_vector.end(), - return_values[i].begin()); - }; -} - - - -template -std::size_t -ConstantFunction::memory_consumption () const -{ - // Here we assume Number is a simple type. - return (sizeof(*this) + this->n_components*sizeof(Number)); } //--------------------------------------------------------------------------- diff --git a/source/base/function.inst.in b/source/base/function.inst.in index 3d83238438..41bc637f27 100644 --- a/source/base/function.inst.in +++ b/source/base/function.inst.in @@ -17,8 +17,8 @@ for (S : REAL_SCALARS; dim : SPACE_DIMENSIONS) { template class Function; - template class ZeroFunction; - template class ConstantFunction; + template class Functions::ZeroFunction; + template class Functions::ConstantFunction; template class ComponentSelectFunction; template class ScalarFunctionFromFunctionObject; template class VectorFunctionFromScalarFunctionObject; @@ -28,8 +28,8 @@ for (S : REAL_SCALARS; dim : SPACE_DIMENSIONS) for (S : COMPLEX_SCALARS; dim : SPACE_DIMENSIONS) { template class Function; - template class ZeroFunction; - template class ConstantFunction; + template class Functions::ZeroFunction; + template class Functions::ConstantFunction; template class ComponentSelectFunction; template class ScalarFunctionFromFunctionObject; template class VectorFunctionFromScalarFunctionObject; -- 2.39.5