From: Denis Davydov Date: Sat, 19 Aug 2017 14:22:32 +0000 (+0200) Subject: change inheritance structure of ZeroFunction and ConstantFunction X-Git-Tag: v9.0.0-rc1~1198^2~1 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=29edaf91e8d6e2b5320780766a6c6aec51c602cd;p=dealii.git change inheritance structure of ZeroFunction and ConstantFunction --- diff --git a/include/deal.II/base/function.h b/include/deal.II/base/function.h index 8602e357a7..5b6fab9e41 100644 --- a/include/deal.II/base/function.h +++ b/include/deal.II/base/function.h @@ -350,82 +350,15 @@ public: namespace Functions { - - /** - * Provide a function which always returns zero. Obviously, also the derivatives - * 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 - { - public: - /** - * Constructor. The number of components is preset to one. - */ - ZeroFunction (const unsigned int n_components = 1); - - /** - * Virtual destructor; absolutely necessary in this case. - * - */ - virtual ~ZeroFunction (); - - 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 &values, - const unsigned int component = 0) const; - - virtual void vector_value_list (const std::vector > &points, - std::vector > &values) const; - - virtual Tensor<1,dim, Number> gradient (const Point &p, - const unsigned int component = 0) const; - - virtual void vector_gradient (const Point &p, - 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 derivatives 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 + class ConstantFunction : public Function { public: /** @@ -471,6 +404,19 @@ namespace Functions virtual void vector_value_list (const std::vector > &points, std::vector > &return_values) const; + virtual Tensor<1,dim, Number> gradient (const Point &p, + const unsigned int component = 0) const; + + virtual void vector_gradient (const Point &p, + 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; + std::size_t memory_consumption () const; protected: @@ -480,6 +426,37 @@ namespace Functions std::vector function_value_vector; }; + + + /** + * Provide a function which always returns zero. Obviously, also the derivatives + * 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 ConstantFunction + { + public: + /** + * Constructor. The number of components is preset to one. + */ + ZeroFunction (const unsigned int n_components = 1); + + /** + * Destructor. + * + */ + virtual ~ZeroFunction (); + + }; + } /** diff --git a/include/deal.II/base/function.templates.h b/include/deal.II/base/function.templates.h index 14e87c92ca..cfac4bd921 100644 --- a/include/deal.II/base/function.templates.h +++ b/include/deal.II/base/function.templates.h @@ -303,7 +303,7 @@ namespace Functions template ZeroFunction::ZeroFunction (const unsigned int n_components) : - Function (n_components) + ConstantFunction (Number(), n_components) {} @@ -311,108 +311,6 @@ namespace Functions 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 (); - }; - } - } //--------------------------------------------------------------------------- @@ -424,7 +322,7 @@ namespace Functions ConstantFunction::ConstantFunction (const Number value, const unsigned int n_components) : - ZeroFunction (n_components), + Function (n_components), function_value_vector (n_components, value) {} @@ -432,7 +330,7 @@ namespace Functions ConstantFunction:: ConstantFunction (const std::vector &values) : - ZeroFunction (values.size()), + Function (values.size()), function_value_vector (values) {} @@ -441,7 +339,7 @@ namespace Functions ConstantFunction:: ConstantFunction (const Vector &values) : - ZeroFunction (values.size()), + Function (values.size()), function_value_vector (values.size()) { Assert (values.size() == function_value_vector.size(), @@ -454,7 +352,7 @@ namespace Functions ConstantFunction:: ConstantFunction (const Number *begin_ptr, const unsigned int n_components) : - ZeroFunction (n_components), + Function (n_components), function_value_vector (n_components) { Assert (begin_ptr != nullptr, ExcMessage ("Null pointer encountered!")); @@ -539,6 +437,60 @@ namespace Functions return (sizeof(*this) + this->n_components*sizeof(Number)); } + + + template + Tensor<1,dim,Number> ConstantFunction::gradient (const Point &, + const unsigned int) const + { + return Tensor<1,dim,Number>(); + } + + + template + void ConstantFunction::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 ConstantFunction::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 ConstantFunction::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 (); + }; + } + + } //---------------------------------------------------------------------------