From 12657232b663c53fb1c7f608c27b3ab076c17bff Mon Sep 17 00:00:00 2001 From: maier Date: Thu, 20 Jun 2013 11:19:52 +0000 Subject: [PATCH] Implement ConstantTensorFunction and ZeroTensorFunction git-svn-id: https://svn.dealii.org/trunk@29840 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/doc/news/changes.h | 7 + .../include/deal.II/base/tensor_function.h | 128 ++++++++++++++---- deal.II/source/base/tensor_function.cc | 112 +++++++++++++++ 3 files changed, 217 insertions(+), 30 deletions(-) diff --git a/deal.II/doc/news/changes.h b/deal.II/doc/news/changes.h index 738d2bf870..621adb6962 100644 --- a/deal.II/doc/news/changes.h +++ b/deal.II/doc/news/changes.h @@ -146,6 +146,13 @@ this function.

Specific improvements

    + +
  1. New: added ConstantTensorFunction and ZeroTensorFunction to provide +a tensor valued analogue to ConstantFunction and ZeroFunction. +
    +(Matthias Maier, 2013/06/20) +
  2. +
  3. Fixed: BlockSparsityPattern::column_number was returning wrong values.
    diff --git a/deal.II/include/deal.II/base/tensor_function.h b/deal.II/include/deal.II/base/tensor_function.h index b8a7bd7910..a55fd65326 100644 --- a/deal.II/include/deal.II/base/tensor_function.h +++ b/deal.II/include/deal.II/base/tensor_function.h @@ -53,66 +53,51 @@ DEAL_II_NAMESPACE_OPEN */ template class TensorFunction : public FunctionTime, - public Subscriptor + public Subscriptor { public: /** - * Define typedefs for the return - * types of the value - * functions. + * Define typedefs for the return types of the value functions. */ typedef Tensor value_type; typedef Tensor gradient_type; /** - * Constructor. May take an - * initial value for the time - * variable, which defaults to - * zero. + * Constructor. May take an initial value for the time variable, which + * defaults to zero. */ TensorFunction (const double initial_time = 0.0); /** - * Virtual destructor; absolutely - * necessary in this case, as - * classes are usually not used - * by their true type, but rather - * through pointers to this base - * class. + * Virtual destructor; absolutely necessary in this case, as classes are + * usually not used by their true type, but rather through pointers to + * this base class. */ virtual ~TensorFunction (); /** - * Return the value of the function - * at the given point. + * Return the value of the function at the given point. */ virtual value_type value (const Point &p) const; /** - * Set values to the point - * values of the function at the - * points. It is assumed - * that values already has - * the right size, i.e. the same - * size as the points array. + * Set values to the point values of the function at the + * points. It is assumed that values already has the + * right size, i.e. the same size as the points array. */ virtual void value_list (const std::vector > &points, std::vector &values) const; /** - * Return the gradient of the - * function at the given point. + * Return the gradient of the function at the given point. */ virtual gradient_type gradient (const Point &p) const; /** - * Set gradients to the - * gradients of the function at - * the points. It is assumed - * that values already has - * the right size, i.e. the same - * size as the points array. + * Set gradients to the gradients of the function at the + * points. It is assumed that values already has the + * right size, i.e. the same size as the points array. */ virtual void gradient_list (const std::vector > &points, std::vector &gradients) const; @@ -131,6 +116,89 @@ public: }; + + +/* + * Provide a tensor valued function which always returns a constant tensor + * value. Obviously, all derivates of this function are zero. + * + * @ingroup functions + * @author Matthias Maier, 2013 + */ +template +class ConstantTensorFunction : public TensorFunction +{ +public: + /** + * Constructor; takes the constant tensor value as an argument. + * The reference value is copied internally. + * + * An initial value for the time variable may be specified, otherwise it + * defaults to zero. + */ + ConstantTensorFunction (const dealii::Tensor &value, + const double initial_time = 0.0); + + /** + * Virtual destructor; absolutely necessary in this case, as classes are + * usually not used by their true type, but rather through pointers to + * this base class. + */ + virtual ~ConstantTensorFunction (); + + /** + * Return the value of the function at the given point. + */ + virtual typename dealii::TensorFunction::value_type value (const Point &p) const; + + /** + * Set values to the point values of the function at the + * points. It is assumed that values already has the + * right size, i.e. the same size as the points array. + */ + virtual void value_list (const std::vector > &points, + std::vector::value_type> &values) const; + + /** + * Return the gradient of the function at the given point. + */ + virtual typename dealii::TensorFunction::gradient_type gradient (const Point &p) const; + + /** + * Set gradients to the gradients of the function at the + * points. It is assumed that values already has the + * right size, i.e. the same size as the points array. + */ + virtual void gradient_list (const std::vector > &points, + std::vector::gradient_type> &gradients) const; + +private: + const dealii::Tensor _value; +}; + + + +/* + * Provide a tensor valued function which always returns zero. + * Obviously, all derivates of this function are zero. + * + * @ingroup functions + * @author Matthias Maier, 2013 + */ +template +class ZeroTensorFunction : public ConstantTensorFunction +{ +public: + /** + * Constructor. + * + * An initial value for the time variable may be specified, otherwise it + * defaults to zero. + */ + ZeroTensorFunction (const double initial_time = 0.0); +}; + + DEAL_II_NAMESPACE_CLOSE #endif diff --git a/deal.II/source/base/tensor_function.cc b/deal.II/source/base/tensor_function.cc index ec2d4a1a37..f903ed382e 100644 --- a/deal.II/source/base/tensor_function.cc +++ b/deal.II/source/base/tensor_function.cc @@ -21,6 +21,7 @@ DEAL_II_NAMESPACE_OPEN + ////////////////////////////////////////////////////////////////////// // TensorFunction ////////////////////////////////////////////////////////////////////// @@ -82,6 +83,90 @@ TensorFunction::gradient_list (const std::vector > &poin } + +////////////////////////////////////////////////////////////////////// +// ConstantTensorFunction +////////////////////////////////////////////////////////////////////// + + +template +ConstantTensorFunction::ConstantTensorFunction (const Tensor &value, + const double initial_time) + : + TensorFunction (initial_time), + _value(value) +{} + + +template +ConstantTensorFunction::~ConstantTensorFunction () +{} + + +template +typename TensorFunction::value_type +ConstantTensorFunction::value (const Point &/*point*/) const +{ + return _value; +} + + +template +void +ConstantTensorFunction::value_list (const std::vector > &points, + std::vector::value_type> &values) const +{ + Assert (values.size() == points.size(), + ExcDimensionMismatch(values.size(), points.size())); + + for (unsigned int i=0; i +typename TensorFunction::gradient_type +ConstantTensorFunction::gradient (const Point &) const +{ + static const Tensor zero; + + return zero; +} + + +template +void +ConstantTensorFunction::gradient_list (const std::vector > &points, + std::vector::gradient_type> &gradients) const +{ + Assert (gradients.size() == points.size(), + ExcDimensionMismatch(gradients.size(), points.size())); + + static const Tensor zero; + + for (unsigned int i=0; i +ZeroTensorFunction::ZeroTensorFunction (const double initial_time) + : + ConstantTensorFunction (dealii::Tensor(), initial_time) +{} + + + +////////////////////////////////////////////////////////////////////// +// Explicit instantiations: +////////////////////////////////////////////////////////////////////// + template class TensorFunction<1,1>; template class TensorFunction<2,1>; template class TensorFunction<3,1>; @@ -95,4 +180,31 @@ template class TensorFunction<2,3>; template class TensorFunction<3,3>; template class TensorFunction<4,3>; +template class ConstantTensorFunction<1,1>; +template class ConstantTensorFunction<2,1>; +template class ConstantTensorFunction<3,1>; +template class ConstantTensorFunction<4,1>; +template class ConstantTensorFunction<1,2>; +template class ConstantTensorFunction<2,2>; +template class ConstantTensorFunction<3,2>; +template class ConstantTensorFunction<4,2>; +template class ConstantTensorFunction<1,3>; +template class ConstantTensorFunction<2,3>; +template class ConstantTensorFunction<3,3>; +template class ConstantTensorFunction<4,3>; + +template class ZeroTensorFunction<1,1>; +template class ZeroTensorFunction<2,1>; +template class ZeroTensorFunction<3,1>; +template class ZeroTensorFunction<4,1>; +template class ZeroTensorFunction<1,2>; +template class ZeroTensorFunction<2,2>; +template class ZeroTensorFunction<3,2>; +template class ZeroTensorFunction<4,2>; +template class ZeroTensorFunction<1,3>; +template class ZeroTensorFunction<2,3>; +template class ZeroTensorFunction<3,3>; +template class ZeroTensorFunction<4,3>; + + DEAL_II_NAMESPACE_CLOSE -- 2.39.5