| 1 |
// ------------------------------------------------------------------------ |
| 2 |
// |
| 3 |
// SPDX-License-Identifier: LGPL-2.1-or-later |
| 4 |
// Copyright (C) 1999 - 2023 by the deal.II authors |
| 5 |
// |
| 6 |
// This file is part of the deal.II library. |
| 7 |
// |
| 8 |
// Part of the source code is dual licensed under Apache-2.0 WITH |
| 9 |
// LLVM-exception OR LGPL-2.1-or-later. Detailed license information |
| 10 |
// governing the source code and code contributions can be found in |
| 11 |
// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II. |
| 12 |
// |
| 13 |
// ------------------------------------------------------------------------ |
| 14 |
|
| 15 |
#ifndef dealii_tensor_function_templates_h |
| 16 |
#define dealii_tensor_function_templates_h |
| 17 |
|
| 18 |
#include <deal.II/base/config.h> |
| 19 |
|
| 20 |
#include <deal.II/base/tensor.h> |
| 21 |
#include <deal.II/base/tensor_function.h> |
| 22 |
|
| 23 |
#include <deal.II/lac/vector.h> |
| 24 |
|
| 25 |
#include <cmath> |
| 26 |
#include <vector> |
| 27 |
|
| 28 |
DEAL_II_NAMESPACE_OPEN |
| 29 |
|
| 30 |
|
| 31 |
template <int rank, int dim, typename Number> |
| 32 |
TensorFunction<rank, dim, Number>::TensorFunction( |
| 33 |
const typename TensorFunction<rank, dim, Number>::time_type initial_time) |
| 34 |
: FunctionTime<typename TensorFunction<rank, dim, Number>::time_type>( |
| 35 |
initial_time) |
| 36 |
{} |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
template <int rank, int dim, typename Number> |
| 41 |
typename TensorFunction<rank, dim, Number>::value_type |
| 42 |
TensorFunction<rank, dim, Number>::value(const Point<dim> &) const |
| 43 |
{ |
| 44 |
Assert(false, ExcPureFunctionCalled()); |
| 45 |
return Tensor<rank, dim, Number>(); |
| 46 |
} |
| 47 |
|
| 48 |
|
| 49 |
template <int rank, int dim, typename Number> |
| 50 |
void |
| 51 |
TensorFunction<rank, dim, Number>::value_list( |
| 52 |
const std::vector<Point<dim>> &points, |
| 53 |
std::vector<value_type> &values) const |
| 54 |
{ |
| 55 |
Assert(values.size() == points.size(), |
| 56 |
ExcDimensionMismatch(values.size(), points.size())); |
| 57 |
|
| 58 |
for (unsigned int i = 0; i < points.size(); ++i) |
| 59 |
values[i] = this->value(points[i]); |
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
template <int rank, int dim, typename Number> |
| 64 |
typename TensorFunction<rank, dim, Number>::gradient_type |
| 65 |
TensorFunction<rank, dim, Number>::gradient(const Point<dim> &) const |
| 66 |
{ |
| 67 |
Assert(false, ExcPureFunctionCalled()); |
| 68 |
return Tensor<rank + 1, dim, Number>(); |
| 69 |
} |
| 70 |
|
| 71 |
|
| 72 |
template <int rank, int dim, typename Number> |
| 73 |
void |
| 74 |
TensorFunction<rank, dim, Number>::gradient_list( |
| 75 |
const std::vector<Point<dim>> &points, |
| 76 |
std::vector<gradient_type> &gradients) const |
| 77 |
{ |
| 78 |
Assert(gradients.size() == points.size(), |
| 79 |
ExcDimensionMismatch(gradients.size(), points.size())); |
| 80 |
|
| 81 |
for (unsigned int i = 0; i < points.size(); ++i) |
| 82 |
gradients[i] = gradient(points[i]); |
| 83 |
} |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
template <int rank, int dim, typename Number> |
| 88 |
ConstantTensorFunction<rank, dim, Number>::ConstantTensorFunction( |
| 89 |
const Tensor<rank, dim, Number> &value, |
| 90 |
const typename ConstantTensorFunction<rank, dim, Number>::time_type |
| 91 |
initial_time) |
| 92 |
: TensorFunction<rank, dim, Number>(initial_time) |
| 93 |
, _value(value) |
| 94 |
{} |
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
template <int rank, int dim, typename Number> |
| 99 |
typename TensorFunction<rank, dim, Number>::value_type |
| 100 |
ConstantTensorFunction<rank, dim, Number>::value( |
| 101 |
const Point<dim> & /*point*/) const |
| 102 |
{ |
| 103 |
return _value; |
| 104 |
} |
| 105 |
|
| 106 |
|
| 107 |
template <int rank, int dim, typename Number> |
| 108 |
void |
| 109 |
ConstantTensorFunction<rank, dim, Number>::value_list( |
| 110 |
const std::vector<Point<dim>> &points, |
| 111 |
std::vector<typename TensorFunction<rank, dim, Number>::value_type> &values) |
| 112 |
const |
| 113 |
{ |
| 114 |
(void)points; |
| 115 |
Assert(values.size() == points.size(), |
| 116 |
ExcDimensionMismatch(values.size(), points.size())); |
| 117 |
|
| 118 |
for (unsigned int i = 0; i < values.size(); ++i) |
| 119 |
values[i] = _value; |
| 120 |
} |
| 121 |
|
| 122 |
|
| 123 |
template <int rank, int dim, typename Number> |
| 124 |
typename TensorFunction<rank, dim, Number>::gradient_type |
| 125 |
ConstantTensorFunction<rank, dim, Number>::gradient(const Point<dim> &) const |
| 126 |
{ |
| 127 |
// Return a zero (=default initialized) tensor |
| 128 |
return {}; |
| 129 |
} |
| 130 |
|
| 131 |
|
| 132 |
template <int rank, int dim, typename Number> |
| 133 |
void |
| 134 |
ConstantTensorFunction<rank, dim, Number>::gradient_list( |
| 135 |
const std::vector<Point<dim>> &points, |
| 136 |
std::vector<typename TensorFunction<rank, dim, Number>::gradient_type> |
| 137 |
&gradients) const |
| 138 |
{ |
| 139 |
(void)points; |
| 140 |
Assert(gradients.size() == points.size(), |
| 141 |
ExcDimensionMismatch(gradients.size(), points.size())); |
| 142 |
|
| 143 |
// Return an array of zero tensors. |
| 144 |
std::fill(gradients.begin(), |
| 145 |
gradients.end(), |
| 146 |
typename TensorFunction<rank, dim, Number>::gradient_type()); |
| 147 |
} |
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
template <int rank, int dim, typename Number> |
| 152 |
ZeroTensorFunction<rank, dim, Number>::ZeroTensorFunction( |
| 153 |
const typename ZeroTensorFunction<rank, dim, Number>::time_type initial_time) |
| 154 |
: ConstantTensorFunction<rank, dim, Number>( |
| 155 |
dealii::Tensor<rank, dim, Number>(), |
| 156 |
initial_time) |
| 157 |
{} |
| 158 |
|
| 159 |
|
| 160 |
DEAL_II_NAMESPACE_CLOSE |
| 161 |
|
| 162 |
#endif /* dealii_tensor_function_templates_h */ |