From d90580f3c2066303d911ac72a5dcd09769bc8d0f Mon Sep 17 00:00:00 2001 From: Daniel Arndt Date: Fri, 26 Oct 2018 13:06:20 +0200 Subject: [PATCH] Introduce a time_type alias for Function and friends --- include/deal.II/base/function.h | 9 +++-- include/deal.II/base/function.templates.h | 6 ++-- include/deal.II/base/function_time.h | 5 +++ include/deal.II/base/tensor_function.h | 33 ++++++++++++++----- .../deal.II/base/tensor_function.templates.h | 10 +++--- 5 files changed, 44 insertions(+), 19 deletions(-) diff --git a/include/deal.II/base/function.h b/include/deal.II/base/function.h index 952ec34c1e..d7bd1042ab 100644 --- a/include/deal.II/base/function.h +++ b/include/deal.II/base/function.h @@ -161,14 +161,19 @@ public: */ const unsigned int n_components; + /** + * The scalar-valued real type used for representing time. + */ + using typename FunctionTime< + typename numbers::NumberTraits::real_type>::time_type; + /** * Constructor. May take an initial value for the number of components * (which defaults to one, i.e. a scalar function), and the time variable, * which defaults to zero. */ Function(const unsigned int n_components = 1, - const typename numbers::NumberTraits::real_type - initial_time = 0.0); + const time_type initial_time = 0.0); /** * Virtual destructor; absolutely necessary in this case. diff --git a/include/deal.II/base/function.templates.h b/include/deal.II/base/function.templates.h index a2d57e8c35..3cab781f81 100644 --- a/include/deal.II/base/function.templates.h +++ b/include/deal.II/base/function.templates.h @@ -34,9 +34,9 @@ const unsigned int Function::dimension; template Function::Function( - const unsigned int n_components, - const typename numbers::NumberTraits::real_type initial_time) - : FunctionTime::real_type>( + const unsigned int n_components, + const typename Function::time_type initial_time) + : FunctionTime::time_type>( initial_time) , n_components(n_components) { diff --git a/include/deal.II/base/function_time.h b/include/deal.II/base/function_time.h index 3955acbe68..3636181128 100644 --- a/include/deal.II/base/function_time.h +++ b/include/deal.II/base/function_time.h @@ -102,6 +102,11 @@ public: virtual void advance_time(const Number delta_t); + /** + * The type this class is initialized with and that is used to represent time. + */ + using time_type = Number; + private: /** * Store the present time. diff --git a/include/deal.II/base/tensor_function.h b/include/deal.II/base/tensor_function.h index 564b4c5963..2fe1f9c298 100644 --- a/include/deal.II/base/tensor_function.h +++ b/include/deal.II/base/tensor_function.h @@ -60,19 +60,26 @@ class TensorFunction { public: /** - * Define alias for the return types of the value functions. + * Alias for the return types of the value function. */ using value_type = Tensor; + /** + * Alias for the return types of the gradient functions. + */ using gradient_type = Tensor; + /** + * The scalar-valued real type used for representing time. + */ + using typename FunctionTime< + typename numbers::NumberTraits::real_type>::time_type; + /** * Constructor. May take an initial value for the time variable, which * defaults to zero. */ - TensorFunction( - const typename numbers::NumberTraits::real_type initial_time = - typename numbers::NumberTraits::real_type(0.0)); + TensorFunction(const time_type initial_time = time_type(0.0)); /** * Virtual destructor; absolutely necessary in this case, as classes are @@ -125,6 +132,11 @@ template class ConstantTensorFunction : public TensorFunction { public: + /** + * The scalar-valued real type used for representing time. + */ + using typename TensorFunction::time_type; + /** * Constructor; takes the constant tensor value as an argument. The * reference value is copied internally. @@ -132,9 +144,8 @@ public: * An initial value for the time variable may be specified, otherwise it * defaults to zero. */ - ConstantTensorFunction( - const dealii::Tensor & value, - const typename numbers::NumberTraits::real_type initial_time = 0.0); + ConstantTensorFunction(const dealii::Tensor &value, + const time_type initial_time = 0.0); virtual ~ConstantTensorFunction() override = default; @@ -174,14 +185,18 @@ template class ZeroTensorFunction : public ConstantTensorFunction { public: + /** + * The scalar-valued real type used for representing time. + */ + using typename ConstantTensorFunction::time_type; + /** * Constructor. * * An initial value for the time variable may be specified, otherwise it * defaults to zero. */ - ZeroTensorFunction( - const typename numbers::NumberTraits::real_type initial_time = 0.0); + ZeroTensorFunction(const time_type initial_time = 0.0); }; diff --git a/include/deal.II/base/tensor_function.templates.h b/include/deal.II/base/tensor_function.templates.h index 398a7f6452..2b00368aed 100644 --- a/include/deal.II/base/tensor_function.templates.h +++ b/include/deal.II/base/tensor_function.templates.h @@ -29,8 +29,8 @@ DEAL_II_NAMESPACE_OPEN template TensorFunction::TensorFunction( - const typename numbers::NumberTraits::real_type initial_time) - : FunctionTime::real_type>( + const typename TensorFunction::time_type initial_time) + : FunctionTime::time_type>( initial_time) {} @@ -85,8 +85,8 @@ TensorFunction::gradient_list( template ConstantTensorFunction::ConstantTensorFunction( - const Tensor & value, - const typename numbers::NumberTraits::real_type initial_time) + const Tensor & value, + const typename ConstantTensorFunction::time_type initial_time) : TensorFunction(initial_time) , _value(value) {} @@ -149,7 +149,7 @@ ConstantTensorFunction::gradient_list( template ZeroTensorFunction::ZeroTensorFunction( - const typename numbers::NumberTraits::real_type initial_time) + const typename ZeroTensorFunction::time_type initial_time) : ConstantTensorFunction( dealii::Tensor(), initial_time) -- 2.39.5