File: tensor_function.templates.h

package info (click to toggle)
deal.ii 9.7.1-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 326,024 kB
  • sloc: cpp: 440,899; ansic: 77,337; python: 3,307; perl: 1,041; sh: 1,022; xml: 252; makefile: 97; javascript: 14
file content (162 lines) | stat: -rw-r--r-- 4,629 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
// ------------------------------------------------------------------------
//
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (C) 1999 - 2023 by the deal.II authors
//
// This file is part of the deal.II library.
//
// Part of the source code is dual licensed under Apache-2.0 WITH
// LLVM-exception OR LGPL-2.1-or-later. Detailed license information
// governing the source code and code contributions can be found in
// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II.
//
// ------------------------------------------------------------------------

#ifndef dealii_tensor_function_templates_h
#define dealii_tensor_function_templates_h

#include <deal.II/base/config.h>

#include <deal.II/base/tensor.h>
#include <deal.II/base/tensor_function.h>

#include <deal.II/lac/vector.h>

#include <cmath>
#include <vector>

DEAL_II_NAMESPACE_OPEN


template <int rank, int dim, typename Number>
TensorFunction<rank, dim, Number>::TensorFunction(
  const typename TensorFunction<rank, dim, Number>::time_type initial_time)
  : FunctionTime<typename TensorFunction<rank, dim, Number>::time_type>(
      initial_time)
{}



template <int rank, int dim, typename Number>
typename TensorFunction<rank, dim, Number>::value_type
TensorFunction<rank, dim, Number>::value(const Point<dim> &) const
{
  Assert(false, ExcPureFunctionCalled());
  return Tensor<rank, dim, Number>();
}


template <int rank, int dim, typename Number>
void
TensorFunction<rank, dim, Number>::value_list(
  const std::vector<Point<dim>> &points,
  std::vector<value_type>       &values) const
{
  Assert(values.size() == points.size(),
         ExcDimensionMismatch(values.size(), points.size()));

  for (unsigned int i = 0; i < points.size(); ++i)
    values[i] = this->value(points[i]);
}


template <int rank, int dim, typename Number>
typename TensorFunction<rank, dim, Number>::gradient_type
TensorFunction<rank, dim, Number>::gradient(const Point<dim> &) const
{
  Assert(false, ExcPureFunctionCalled());
  return Tensor<rank + 1, dim, Number>();
}


template <int rank, int dim, typename Number>
void
TensorFunction<rank, dim, Number>::gradient_list(
  const std::vector<Point<dim>> &points,
  std::vector<gradient_type>    &gradients) const
{
  Assert(gradients.size() == points.size(),
         ExcDimensionMismatch(gradients.size(), points.size()));

  for (unsigned int i = 0; i < points.size(); ++i)
    gradients[i] = gradient(points[i]);
}



template <int rank, int dim, typename Number>
ConstantTensorFunction<rank, dim, Number>::ConstantTensorFunction(
  const Tensor<rank, dim, Number> &value,
  const typename ConstantTensorFunction<rank, dim, Number>::time_type
    initial_time)
  : TensorFunction<rank, dim, Number>(initial_time)
  , _value(value)
{}



template <int rank, int dim, typename Number>
typename TensorFunction<rank, dim, Number>::value_type
ConstantTensorFunction<rank, dim, Number>::value(
  const Point<dim> & /*point*/) const
{
  return _value;
}


template <int rank, int dim, typename Number>
void
ConstantTensorFunction<rank, dim, Number>::value_list(
  const std::vector<Point<dim>>                                       &points,
  std::vector<typename TensorFunction<rank, dim, Number>::value_type> &values)
  const
{
  (void)points;
  Assert(values.size() == points.size(),
         ExcDimensionMismatch(values.size(), points.size()));

  for (unsigned int i = 0; i < values.size(); ++i)
    values[i] = _value;
}


template <int rank, int dim, typename Number>
typename TensorFunction<rank, dim, Number>::gradient_type
ConstantTensorFunction<rank, dim, Number>::gradient(const Point<dim> &) const
{
  // Return a zero (=default initialized) tensor
  return {};
}


template <int rank, int dim, typename Number>
void
ConstantTensorFunction<rank, dim, Number>::gradient_list(
  const std::vector<Point<dim>> &points,
  std::vector<typename TensorFunction<rank, dim, Number>::gradient_type>
    &gradients) const
{
  (void)points;
  Assert(gradients.size() == points.size(),
         ExcDimensionMismatch(gradients.size(), points.size()));

  // Return an array of zero tensors.
  std::fill(gradients.begin(),
            gradients.end(),
            typename TensorFunction<rank, dim, Number>::gradient_type());
}



template <int rank, int dim, typename Number>
ZeroTensorFunction<rank, dim, Number>::ZeroTensorFunction(
  const typename ZeroTensorFunction<rank, dim, Number>::time_type initial_time)
  : ConstantTensorFunction<rank, dim, Number>(
      dealii::Tensor<rank, dim, Number>(),
      initial_time)
{}


DEAL_II_NAMESPACE_CLOSE

#endif /* dealii_tensor_function_templates_h */