deal.II version GIT relicensing-6834-g5b78e6bcdf 2026-10-01 11:20:01+00:00
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Loading...
Searching...
No Matches
function_restriction.cc
Go to the documentation of this file.
1// -----------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
4// Copyright (C) 2021 - 2025 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Detailed license information governing the source code and contributions
9// can be found in LICENSE.md and CONTRIBUTING.md at the top level directory.
10//
11// -----------------------------------------------------------------------------
12
15
17namespace internal
18{
19 template <int dim>
22 const unsigned int component_in_dim_plus_1,
23 const double coordinate_value)
24 {
25 AssertIndexRange(component_in_dim_plus_1, dim + 1);
26
27 Point<dim + 1> output;
28 output[component_in_dim_plus_1] = coordinate_value;
29 for (int d = 0; d < dim; ++d)
30 {
31 const unsigned int component_to_write_to =
32 ::internal::coordinate_to_one_dim_higher<dim>(
33 component_in_dim_plus_1, d);
34 output[component_to_write_to] = point[d];
35 }
36
37 return output;
38 }
39} // namespace internal
40
41
42
43namespace Functions
44{
45 template <int dim>
47 const Function<dim + 1> &function,
48 const unsigned int direction,
49 const double coordinate_value)
50 : function(&function)
51 , restricted_direction(direction)
52 , coordinate_value(coordinate_value)
53 {
55 }
56
57
58
59 template <int dim>
60 double
62 const unsigned int component) const
63 {
64 const Point<dim + 1> full_point =
66 restricted_direction,
67 coordinate_value);
68
69 return function->value(full_point, component);
70 }
71
72
73
74 template <int dim>
77 const unsigned int component) const
78 {
79 const Point<dim + 1> full_point =
81 restricted_direction,
82 coordinate_value);
83
84 const Tensor<1, dim + 1> full_gradient =
85 function->gradient(full_point, component);
86
87 // CoordinateRestriction is constant in restricted direction. Through away
88 // the derivatives with respect to this direction and copy the other
89 // values.
90 Tensor<1, dim> grad;
91 for (unsigned int d = 0; d < dim; ++d)
92 {
93 const unsigned int index_to_write_from =
94 internal::coordinate_to_one_dim_higher<dim>(restricted_direction, d);
95 grad[d] = full_gradient[index_to_write_from];
96 }
97 return grad;
98 }
99
100
101
102 template <int dim>
105 const unsigned int component) const
106 {
107 const Point<dim + 1> full_point =
109 restricted_direction,
110 coordinate_value);
111
112 const Tensor<2, dim + 1> full_hessian =
113 function->hessian(full_point, component);
114
115 // CoordinateRestriction is constant in restricted direction. Through away
116 // the derivatives with respect to this direction and copy the other
117 // values.
119 for (unsigned int i = 0; i < dim; ++i)
120 {
121 const unsigned int i_to_write_from =
122 internal::coordinate_to_one_dim_higher<dim>(restricted_direction, i);
123 for (unsigned int j = 0; j < dim; ++j)
124 {
125 const unsigned int j_to_write_from =
126 internal::coordinate_to_one_dim_higher<dim>(restricted_direction,
127 j);
128 hess[i][j] = full_hessian[i_to_write_from][j_to_write_from];
129 }
131 return hess;
132 }
133
134
135
136 template <int dim>
138 const unsigned int open_direction,
139 const Point<dim> &point)
140 : function(&function)
141 , open_direction(open_direction)
142 , point(point)
143 {
145 }
146
147
148
149 template <int dim>
150 double
152 const unsigned int component) const
153 {
154 const Point<dim + 1> full_point =
155 internal::create_higher_dim_point(point, open_direction, point_1D[0]);
156 return function->value(full_point, component);
157 }
158
159
160
161 template <int dim>
164 const unsigned int component) const
165 {
166 const Point<dim + 1> full_point =
167 internal::create_higher_dim_point(point, open_direction, point_1D[0]);
168 const Tensor<1, dim + 1> full_gradient =
169 function->gradient(full_point, component);
170
171 // The PointRestrictions is constant in all but the open direction. Throw
172 // away the derivatives in all but this direction.
173 Tensor<1, 1> grad;
174 grad[0] = full_gradient[open_direction];
175 return grad;
176 }
177
178
179
180 template <int dim>
183 const unsigned int component) const
184 {
185 const Point<dim + 1> full_point =
186 internal::create_higher_dim_point(point, open_direction, point_1D[0]);
187 const Tensor<2, dim + 1> full_hessian =
188 function->hessian(full_point, component);
189
190 // The PointRestrictions is constant in all but the open direction. Throw
191 // away the derivatives in all but this direction.
193 hess[0][0] = full_hessian[open_direction][open_direction];
194 return hess;
195 }
196
197
198
199} // namespace Functions
200#include "base/function_restriction.inst"
double value(const Point< dim > &point, const unsigned int component) const override
Tensor< 1, dim > gradient(const Point< dim > &point, const unsigned int component) const override
SymmetricTensor< 2, dim > hessian(const Point< dim > &point, const unsigned int component) const override
CoordinateRestriction(const Function< dim+1 > &function, const unsigned int direction, const double coordinate_value)
PointRestriction(const Function< dim+1 > &function, const unsigned int open_direction, const Point< dim > &point)
double value(const Point< 1 > &point, const unsigned int component) const override
Tensor< 1, 1 > gradient(const Point< 1 > &point, const unsigned int component) const override
SymmetricTensor< 2, 1 > hessian(const Point< 1 > &point, const unsigned int component) const override
Definition point.h:111
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:38
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:39
#define AssertIndexRange(index, range)
Point< dim+1 > create_higher_dim_point(const Point< dim > &point, const unsigned int component_in_dim_plus_1, const double coordinate_value)