]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Introduce a time_type alias for Function and friends
authorDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Fri, 26 Oct 2018 11:06:20 +0000 (13:06 +0200)
committerDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Fri, 26 Oct 2018 13:38:45 +0000 (15:38 +0200)
include/deal.II/base/function.h
include/deal.II/base/function.templates.h
include/deal.II/base/function_time.h
include/deal.II/base/tensor_function.h
include/deal.II/base/tensor_function.templates.h

index 952ec34c1e347d5291400602be91b1bd9bc0afcf..d7bd1042ab9b8e54a59148776e894cf73d31ae81 100644 (file)
@@ -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<RangeNumberType>::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<RangeNumberType>::real_type
-             initial_time = 0.0);
+           const time_type    initial_time = 0.0);
 
   /**
    * Virtual destructor; absolutely necessary in this case.
index a2d57e8c35235a84c26c957a542312a614f008ac..3cab781f8188b9b8f45c835a50bc07335aa39a20 100644 (file)
@@ -34,9 +34,9 @@ const unsigned int Function<dim, RangeNumberType>::dimension;
 
 template <int dim, typename RangeNumberType>
 Function<dim, RangeNumberType>::Function(
-  const unsigned int                                               n_components,
-  const typename numbers::NumberTraits<RangeNumberType>::real_type initial_time)
-  : FunctionTime<typename numbers::NumberTraits<RangeNumberType>::real_type>(
+  const unsigned int                                       n_components,
+  const typename Function<dim, RangeNumberType>::time_type initial_time)
+  : FunctionTime<typename Function<dim, RangeNumberType>::time_type>(
       initial_time)
   , n_components(n_components)
 {
index 3955acbe684f6eda36bc9f78b1ac305a10055789..36361811289f3b5f1b2a3fb21bae8a07726f2181 100644 (file)
@@ -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.
index 564b4c59634ae3fa6785f63957f50fc7eb94f0d4..2fe1f9c29810756d34c50c3866128ba153a797f0 100644 (file)
@@ -60,19 +60,26 @@ class TensorFunction
 {
 public:
   /**
-   * Define alias for the return types of the <tt>value</tt> functions.
+   * Alias for the return types of the <tt>value</tt> function.
    */
   using value_type = Tensor<rank, dim, Number>;
 
+  /**
+   * Alias for the return types of the <tt>gradient</tt> functions.
+   */
   using gradient_type = Tensor<rank + 1, dim, Number>;
 
+  /**
+   * The scalar-valued real type used for representing time.
+   */
+  using typename FunctionTime<
+    typename numbers::NumberTraits<Number>::real_type>::time_type;
+
   /**
    * Constructor. May take an initial value for the time variable, which
    * defaults to zero.
    */
-  TensorFunction(
-    const typename numbers::NumberTraits<Number>::real_type initial_time =
-      typename numbers::NumberTraits<Number>::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 <int rank, int dim, typename Number = double>
 class ConstantTensorFunction : public TensorFunction<rank, dim, Number>
 {
 public:
+  /**
+   * The scalar-valued real type used for representing time.
+   */
+  using typename TensorFunction<rank, dim, Number>::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<rank, dim, Number> &               value,
-    const typename numbers::NumberTraits<Number>::real_type initial_time = 0.0);
+  ConstantTensorFunction(const dealii::Tensor<rank, dim, Number> &value,
+                         const time_type initial_time = 0.0);
 
   virtual ~ConstantTensorFunction() override = default;
 
@@ -174,14 +185,18 @@ template <int rank, int dim, typename Number = double>
 class ZeroTensorFunction : public ConstantTensorFunction<rank, dim, Number>
 {
 public:
+  /**
+   * The scalar-valued real type used for representing time.
+   */
+  using typename ConstantTensorFunction<rank, dim, Number>::time_type;
+
   /**
    * Constructor.
    *
    * An initial value for the time variable may be specified, otherwise it
    * defaults to zero.
    */
-  ZeroTensorFunction(
-    const typename numbers::NumberTraits<Number>::real_type initial_time = 0.0);
+  ZeroTensorFunction(const time_type initial_time = 0.0);
 };
 
 
index 398a7f645272099df113a9dd604a79b7b8d4d14d..2b00368aedcfa709ac737de42f095b68558c360d 100644 (file)
@@ -29,8 +29,8 @@ DEAL_II_NAMESPACE_OPEN
 
 template <int rank, int dim, typename Number>
 TensorFunction<rank, dim, Number>::TensorFunction(
-  const typename numbers::NumberTraits<Number>::real_type initial_time)
-  : FunctionTime<typename numbers::NumberTraits<Number>::real_type>(
+  const typename TensorFunction<rank, dim, Number>::time_type initial_time)
+  : FunctionTime<typename TensorFunction<rank, dim, Number>::time_type>(
       initial_time)
 {}
 
@@ -85,8 +85,8 @@ TensorFunction<rank, dim, Number>::gradient_list(
 
 template <int rank, int dim, typename Number>
 ConstantTensorFunction<rank, dim, Number>::ConstantTensorFunction(
-  const Tensor<rank, dim, Number> &                       value,
-  const typename numbers::NumberTraits<Number>::real_type initial_time)
+  const Tensor<rank, dim, Number> &                           value,
+  const typename ConstantTensorFunction<rank, dim, Number>::time_type initial_time)
   : TensorFunction<rank, dim, Number>(initial_time)
   , _value(value)
 {}
@@ -149,7 +149,7 @@ ConstantTensorFunction<rank, dim, Number>::gradient_list(
 
 template <int rank, int dim, typename Number>
 ZeroTensorFunction<rank, dim, Number>::ZeroTensorFunction(
-  const typename numbers::NumberTraits<Number>::real_type initial_time)
+  const typename ZeroTensorFunction<rank, dim, Number>::time_type initial_time)
   : ConstantTensorFunction<rank, dim, Number>(
       dealii::Tensor<rank, dim, Number>(),
       initial_time)

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.