From ca8c64571c479047c5e1d13c818ba18ee890a946 Mon Sep 17 00:00:00 2001 From: Daniel Arndt Date: Fri, 26 Oct 2018 11:28:51 +0200 Subject: [PATCH] Describe time by real scalar types in Function and friends --- .../incompatibilities/20181026DanielArndt | 5 +++ include/deal.II/base/function.h | 9 ++++-- include/deal.II/base/function.templates.h | 8 +++-- include/deal.II/base/tensor_function.h | 16 +++++++--- .../deal.II/base/tensor_function.templates.h | 12 ++++--- tests/base/functions_13.cc | 31 ++++++++++++++----- 6 files changed, 58 insertions(+), 23 deletions(-) create mode 100644 doc/news/changes/incompatibilities/20181026DanielArndt diff --git a/doc/news/changes/incompatibilities/20181026DanielArndt b/doc/news/changes/incompatibilities/20181026DanielArndt new file mode 100644 index 0000000000..7a45d4d4a6 --- /dev/null +++ b/doc/news/changes/incompatibilities/20181026DanielArndt @@ -0,0 +1,5 @@ +Changed: Time is described by a real-valued scalar in Function, TensorFunction, +ConstantTensorFunction and ZeroTensorFunction, i.e. all of them derive from +FunctionTime with a real-valued scalar template parameter. +
+(Daniel Arndt, 2018/10/26) diff --git a/include/deal.II/base/function.h b/include/deal.II/base/function.h index 16fcdbaf89..952ec34c1e 100644 --- a/include/deal.II/base/function.h +++ b/include/deal.II/base/function.h @@ -145,7 +145,9 @@ class TensorFunction; * @author Wolfgang Bangerth, 1998, 1999, Luca Heltai 2014 */ template -class Function : public FunctionTime, public Subscriptor +class Function : public FunctionTime< + typename numbers::NumberTraits::real_type>, + public Subscriptor { public: /** @@ -164,8 +166,9 @@ public: * (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 RangeNumberType initial_time = 0.0); + Function(const unsigned int n_components = 1, + const typename numbers::NumberTraits::real_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 3dbbb7245c..a2d57e8c35 100644 --- a/include/deal.II/base/function.templates.h +++ b/include/deal.II/base/function.templates.h @@ -33,9 +33,11 @@ const unsigned int Function::dimension; template -Function::Function(const unsigned int n_components, - const RangeNumberType initial_time) - : FunctionTime(initial_time) +Function::Function( + const unsigned int n_components, + const typename numbers::NumberTraits::real_type initial_time) + : FunctionTime::real_type>( + initial_time) , n_components(n_components) { // avoid the construction of function objects that don't return any diff --git a/include/deal.II/base/tensor_function.h b/include/deal.II/base/tensor_function.h index 8b80dae6ca..564b4c5963 100644 --- a/include/deal.II/base/tensor_function.h +++ b/include/deal.II/base/tensor_function.h @@ -54,7 +54,9 @@ DEAL_II_NAMESPACE_OPEN * @author Guido Kanschat, 1999 */ template -class TensorFunction : public FunctionTime, public Subscriptor +class TensorFunction + : public FunctionTime::real_type>, + public Subscriptor { public: /** @@ -68,7 +70,9 @@ public: * Constructor. May take an initial value for the time variable, which * defaults to zero. */ - TensorFunction(const Number initial_time = Number(0.0)); + TensorFunction( + const typename numbers::NumberTraits::real_type initial_time = + typename numbers::NumberTraits::real_type(0.0)); /** * Virtual destructor; absolutely necessary in this case, as classes are @@ -128,8 +132,9 @@ public: * An initial value for the time variable may be specified, otherwise it * defaults to zero. */ - ConstantTensorFunction(const dealii::Tensor &value, - const Number initial_time = 0.0); + ConstantTensorFunction( + const dealii::Tensor & value, + const typename numbers::NumberTraits::real_type initial_time = 0.0); virtual ~ConstantTensorFunction() override = default; @@ -175,7 +180,8 @@ public: * An initial value for the time variable may be specified, otherwise it * defaults to zero. */ - ZeroTensorFunction(const Number initial_time = 0.0); + ZeroTensorFunction( + const typename numbers::NumberTraits::real_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 5e5b0c1992..398a7f6452 100644 --- a/include/deal.II/base/tensor_function.templates.h +++ b/include/deal.II/base/tensor_function.templates.h @@ -28,8 +28,10 @@ DEAL_II_NAMESPACE_OPEN template -TensorFunction::TensorFunction(const Number initial_time) - : FunctionTime(initial_time) +TensorFunction::TensorFunction( + const typename numbers::NumberTraits::real_type initial_time) + : FunctionTime::real_type>( + initial_time) {} @@ -83,8 +85,8 @@ TensorFunction::gradient_list( template ConstantTensorFunction::ConstantTensorFunction( - const Tensor &value, - const Number initial_time) + const Tensor & value, + const typename numbers::NumberTraits::real_type initial_time) : TensorFunction(initial_time) , _value(value) {} @@ -147,7 +149,7 @@ ConstantTensorFunction::gradient_list( template ZeroTensorFunction::ZeroTensorFunction( - const Number initial_time) + const typename numbers::NumberTraits::real_type initial_time) : ConstantTensorFunction( dealii::Tensor(), initial_time) diff --git a/tests/base/functions_13.cc b/tests/base/functions_13.cc index 7b1b7e9bd8..29e7c8b5e9 100644 --- a/tests/base/functions_13.cc +++ b/tests/base/functions_13.cc @@ -23,18 +23,16 @@ #include "../tests.h" -using namespace dealii; - template -class MyFunctionTime : dealii::FunctionTime +class MyFunctionTime : public dealii::FunctionTime {}; template -class MyFunction : dealii::Function +class MyFunction : public dealii::Function {}; template -class MyTensorFunction : dealii::TensorFunction +class MyTensorFunction : public dealii::TensorFunction {}; int @@ -42,11 +40,30 @@ main() { initlog(); + MyFunctionTime> function_time_1; + static_assert(std::is_same>::value, + "Wrong return type for FunctionTime::get_time()."); + MyFunctionTime> function_time_2; + static_assert(std::is_same>::value, + "Wrong return type for FunctionTime::get_time()."); + MyFunction<1, std::complex> function_1; - MyFunction<2, std::complex> function_2; + static_assert(std::is_same::value, + "Wrong return type for Function::get_time()."); + MyFunction<2, std::complex> function_2; + static_assert(std::is_same::value, + "Wrong return type for Function::get_time()."); MyTensorFunction<1, 1, std::complex> tensor_function_1; - MyTensorFunction<2, 2, std::complex> tensor_function_2; + static_assert( + std::is_same::value, + "Wrong return type for TensorFunction::get_time()."); + MyTensorFunction<2, 2, std::complex> tensor_function_2; + static_assert( + std::is_same::value, + "Wrong return type for TensorFunction::get_time()."); deallog << "OK" << std::endl; } -- 2.39.5