Debian Codegraph @

include/deal.II/grid/composition_manifold.h

raw
1 // ------------------------------------------------------------------------
2 //
3 // SPDX-License-Identifier: LGPL-2.1-or-later
4 // Copyright (C) 2016 - 2024 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_composition_manifold_h
16 #define dealii_composition_manifold_h
17
18
19 /*---------------------------- composition_manifold.h ------------*/
20
21 #include <deal.II/base/config.h>
22
23 #include <deal.II/base/derivative_form.h>
24 #include <deal.II/base/enable_observer_pointer.h>
25 #include <deal.II/base/point.h>
26 #include <deal.II/base/quadrature_lib.h>
27
28 #include <deal.II/grid/manifold.h>
29 #include <deal.II/grid/tria.h>
30 #include <deal.II/grid/tria_accessor.h>
31 #include <deal.II/grid/tria_iterator.h>
32
33 #include <memory>
34
35 DEAL_II_NAMESPACE_OPEN
36
37 /**
38 * CompositionManifold. Take two ChartManifold objects, and make
39 * their composition. The CompositionManifold object is a
40 * ChartManifold going from the chart of the first ChartManifold to
41 * the embedding space of the second ChartManifold. If the first
42 * ChartManifold is periodic, so is the resulting ChartManifold, with
43 * the same periodicity. Periodicity on the second ChartManifold is not
44 * allowed, and the constructor will throw an exception if the second
45 * Manifold is periodic.
46 *
47 * This class only works for dim <= chartdim <= intermediate_spacedim
48 * <= spacedim. If you try to instantiate anything different, an
49 * Exception will be thrown in one of the ChartManifold classes that
50 * violates this condition.
51 *
52 * Given the ChartManifold F and the ChartManifold G, this class
53 * represents the composition of G after F.
54 *
55 * The template parameters have the following meaning:
56 *
57 * @tparam dim The dimension of the resulting ChartManifold
58 * @tparam spacedim The space dimension of the resulting ChartManifold
59 * @tparam chartdim The chart dimension of the resulting ChartManifold
60 * @tparam intermediate_dim The space dimension of the first ChartManifold
61 * @tparam dim1 The dimension of the first ChartManifold, which coincides also
62 * with the chart dimension of the second ChartManifold
63 * @tparam dim2 The dimension of the second ChartManifold
64 *
65 * @ingroup manifold
66 */
67 template <int dim,
68 int spacedim = dim,
69 int chartdim = dim,
70 int intermediate_dim = dim,
71 int dim1 = dim,
72 int dim2 = dim>
73 class CompositionManifold : public ChartManifold<dim, spacedim, chartdim>
74 {
75 public:
76 /**
77 * Construct the composition of the two given manifolds.
78 */
79 CompositionManifold(const ChartManifold<dim1, intermediate_dim, chartdim> &F,
80 const ChartManifold<dim2, spacedim, intermediate_dim> &G);
81
82 /**
83 * Make a clone of this Manifold.
84 */
85 virtual std::unique_ptr<Manifold<dim, spacedim>>
86 clone() const override;
87
88 /**
89 * Pull back the given point in spacedim to the Euclidean chartdim
90 * dimensional space. This function calls the pull_back() function
91 * of G, and then the pull_back() function of F.
92 */
93 virtual Point<chartdim>
94 pull_back(const Point<spacedim> &space_point) const;
95
96
97 /**
98 * Push forward the chartdim dimensional point to a spacedim
99 * Euclidean point. The function calls first the push_forward() of
100 * F, and then the push_forward() of G.
101 */
102 virtual Point<spacedim>
103 push_forward(const Point<chartdim> &chart_point) const;
104
105 /**
106 * Return the derivative of the composition of G after F.
107 */
108 virtual DerivativeForm<1, chartdim, spacedim>
109 push_forward_gradient(const Point<chartdim> &chart_point) const;
110
111 private:
112 /**
113 * The first ChartManifold.
114 */
115 ObserverPointer<
116 const ChartManifold<dim1, intermediate_dim, chartdim>,
117 CompositionManifold<dim, spacedim, chartdim, dim1, dim2, intermediate_dim>>
118 F;
119
120
121 /**
122 * The second ChartManifold.
123 */
124 ObserverPointer<
125 const ChartManifold<dim2, spacedim, intermediate_dim>,
126 CompositionManifold<dim, spacedim, chartdim, dim1, dim2, intermediate_dim>>
127 G;
128 };
129
130
131 /*------------------Template Implementations------------------------*/
132
133 template <int dim,
134 int spacedim,
135 int chartdim,
136 int intermediate_dim,
137 int dim1,
138 int dim2>
139 CompositionManifold<dim, spacedim, chartdim, intermediate_dim, dim1, dim2>::
140 CompositionManifold(const ChartManifold<dim1, intermediate_dim, chartdim> &F,
141 const ChartManifold<dim2, spacedim, intermediate_dim> &G)
142 : ChartManifold<dim, spacedim, chartdim>(F.get_periodicity())
143 , F(&F)
144 , G(&G)
145 {
146 // We don't know what to do with a periodicity in the second manifold, so
147 // throw an assertion if the second manifold is periodic
148 Assert(G.get_periodicity().norm() == 0.0,
149 ExcMessage("The second manifold cannot be periodic."));
150 }
151
152
153 template <int dim,
154 int spacedim,
155 int chartdim,
156 int intermediate_dim,
157 int dim1,
158 int dim2>
159 std::unique_ptr<Manifold<dim, spacedim>>
160 CompositionManifold<dim, spacedim, chartdim, intermediate_dim, dim1, dim2>::
161 clone() const
162 {
163 return std::make_unique<
164 CompositionManifold<dim, spacedim, chartdim, intermediate_dim, dim1, dim2>>(
165 *F, *G);
166 }
167
168
169 template <int dim,
170 int spacedim,
171 int chartdim,
172 int intermediate_dim,
173 int dim1,
174 int dim2>
175 Point<chartdim>
176 CompositionManifold<dim, spacedim, chartdim, intermediate_dim, dim1, dim2>::
177 pull_back(const Point<spacedim> &space_point) const
178 {
179 return F->pull_back(G->pull_back(space_point));
180 }
181
182
183
184 template <int dim,
185 int spacedim,
186 int chartdim,
187 int intermediate_dim,
188 int dim1,
189 int dim2>
190 Point<spacedim>
191 CompositionManifold<dim, spacedim, chartdim, intermediate_dim, dim1, dim2>::
192 push_forward(const Point<chartdim> &chart_point) const
193 {
194 return G->push_forward(F->push_forward(chart_point));
195 }
196
197
198
199 template <int dim,
200 int spacedim,
201 int chartdim,
202 int intermediate_dim,
203 int dim1,
204 int dim2>
205 DerivativeForm<1, chartdim, spacedim>
206 CompositionManifold<dim, spacedim, chartdim, intermediate_dim, dim1, dim2>::
207 push_forward_gradient(const Point<chartdim> &chart_point) const
208 {
209 DerivativeForm<1, chartdim, intermediate_dim> DF =
210 F->push_forward_gradient(chart_point);
211
212 DerivativeForm<1, intermediate_dim, spacedim> DG =
213 G->push_forward_gradient(F->push_forward(chart_point));
214
215 DerivativeForm<1, chartdim, spacedim> DF_DG;
216
217 for (unsigned int d = 0; d < spacedim; ++d)
218 for (unsigned int c = 0; c < chartdim; ++c)
219 for (unsigned int s = 0; s < intermediate_dim; ++s)
220 DF_DG[d][c] += DG[d][s] * DF[s][c];
221
222 return DF_DG;
223 }
224
225
226 DEAL_II_NAMESPACE_CLOSE
227
228 #endif