| 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_tensor_product_manifold_h |
| 16 |
#define dealii_tensor_product_manifold_h |
| 17 |
|
| 18 |
#include <deal.II/base/config.h> |
| 19 |
|
| 20 |
#include <deal.II/base/enable_observer_pointer.h> |
| 21 |
#include <deal.II/base/point.h> |
| 22 |
#include <deal.II/base/utilities.h> |
| 23 |
|
| 24 |
#include <deal.II/grid/manifold.h> |
| 25 |
|
| 26 |
#include <memory> |
| 27 |
|
| 28 |
DEAL_II_NAMESPACE_OPEN |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
/** |
| 33 |
* @brief Tensor product manifold of two ChartManifolds. |
| 34 |
* |
| 35 |
* This manifold will combine the ChartManifolds @p A and @p B given in the |
| 36 |
* constructor to form a new ChartManifold by building the tensor product |
| 37 |
* $A\otimes B$. The first @p spacedim_A dimensions in the real space and the |
| 38 |
* first @p chartdim_A dimensions of the chart will be given by manifold @p A, |
| 39 |
* while the remaining coordinates are given by @p B. The manifold is to be |
| 40 |
* used by a <tt>Triangulation@<dim, space_dim_A+space_dim_B@></tt>. |
| 41 |
* |
| 42 |
* An example usage would be the combination of a SphericalManifold with space |
| 43 |
* dimension 2 and a FlatManifold with space dimension 1 to form a cylindrical |
| 44 |
* manifold. |
| 45 |
* |
| 46 |
* pull_back(), push_forward(), and push_forward_gradient() are implemented by |
| 47 |
* splitting the input argument into inputs for @p A and @p B according to the |
| 48 |
* given dimensions and applying the corresponding operations before |
| 49 |
* concatenating the result. |
| 50 |
* |
| 51 |
* @note The dimension arguments @p dim_A and @p dim_B are not used. |
| 52 |
* |
| 53 |
* @tparam dim Dimension of cells (needs to match first template argument of |
| 54 |
* the Triangulation to be attached to. |
| 55 |
* @tparam dim_A Dimension of ChartManifold A. |
| 56 |
* @tparam spacedim_A Spatial dimension of ChartManifold A. |
| 57 |
* @tparam chartdim_A Chart dimension of ChartManifold A. |
| 58 |
* @tparam dim_B Dimension of ChartManifold B. |
| 59 |
* @tparam spacedim_B Spatial dimension of ChartManifold B. |
| 60 |
* @tparam chartdim_B Chart dimension of ChartManifold B. |
| 61 |
*/ |
| 62 |
template <int dim, |
| 63 |
int dim_A, |
| 64 |
int spacedim_A, |
| 65 |
int chartdim_A, |
| 66 |
int dim_B, |
| 67 |
int spacedim_B, |
| 68 |
int chartdim_B> |
| 69 |
class TensorProductManifold |
| 70 |
: public ChartManifold<dim, spacedim_A + spacedim_B, chartdim_A + chartdim_B> |
| 71 |
{ |
| 72 |
public: |
| 73 |
/** |
| 74 |
* The chart dimension is the sum of the chart dimensions of the manifolds |
| 75 |
* @p A and @p B. |
| 76 |
*/ |
| 77 |
static const unsigned int chartdim = chartdim_A + chartdim_B; |
| 78 |
/** |
| 79 |
* The space dimension is the sum of the space dimensions of the manifolds |
| 80 |
* @p A and @p B. |
| 81 |
*/ |
| 82 |
static const unsigned int spacedim = spacedim_A + spacedim_B; |
| 83 |
|
| 84 |
/** |
| 85 |
* Constructor. |
| 86 |
*/ |
| 87 |
TensorProductManifold( |
| 88 |
const ChartManifold<dim_A, spacedim_A, chartdim_A> &manifold_A, |
| 89 |
const ChartManifold<dim_B, spacedim_B, chartdim_B> &manifold_B); |
| 90 |
|
| 91 |
/** |
| 92 |
* Clone this manifold. |
| 93 |
*/ |
| 94 |
virtual std::unique_ptr<Manifold<dim, spacedim_A + spacedim_B>> |
| 95 |
clone() const override; |
| 96 |
|
| 97 |
/** |
| 98 |
* Pull back operation. |
| 99 |
*/ |
| 100 |
virtual Point<chartdim> |
| 101 |
pull_back(const Point<spacedim> &space_point) const override; |
| 102 |
|
| 103 |
/** |
| 104 |
* Push forward operation. |
| 105 |
*/ |
| 106 |
virtual Point<spacedim> |
| 107 |
push_forward(const Point<chartdim> &chart_point) const override; |
| 108 |
|
| 109 |
/** |
| 110 |
* Gradient. |
| 111 |
*/ |
| 112 |
virtual DerivativeForm<1, chartdim, spacedim> |
| 113 |
push_forward_gradient(const Point<chartdim> &chart_point) const override; |
| 114 |
|
| 115 |
private: |
| 116 |
std::unique_ptr<const ChartManifold<dim_A, spacedim_A, chartdim_A>> |
| 117 |
manifold_A; |
| 118 |
|
| 119 |
std::unique_ptr<const ChartManifold<dim_B, spacedim_B, chartdim_B>> |
| 120 |
manifold_B; |
| 121 |
}; |
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
/*------------------Template Implementations------------------------*/ |
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
namespace internal |
| 130 |
{ |
| 131 |
namespace TensorProductManifoldImplementation |
| 132 |
{ |
| 133 |
template <int dim1, int dim2> |
| 134 |
Tensor<1, dim1 + dim2> |
| 135 |
concat(const Tensor<1, dim1> &p1, const Tensor<1, dim2> &p2) |
| 136 |
{ |
| 137 |
Tensor<1, dim1 + dim2> r; |
| 138 |
for (unsigned int d = 0; d < dim1; ++d) |
| 139 |
r[d] = p1[d]; |
| 140 |
for (unsigned int d = 0; d < dim2; ++d) |
| 141 |
r[dim1 + d] = p2[d]; |
| 142 |
return r; |
| 143 |
} |
| 144 |
|
| 145 |
template <int dim1, int dim2> |
| 146 |
Point<dim1 + dim2> |
| 147 |
concat(const Point<dim1> &p1, const Point<dim2> &p2) |
| 148 |
{ |
| 149 |
Point<dim1 + dim2> r; |
| 150 |
for (unsigned int d = 0; d < dim1; ++d) |
| 151 |
r[d] = p1[d]; |
| 152 |
for (unsigned int d = 0; d < dim2; ++d) |
| 153 |
r[dim1 + d] = p2[d]; |
| 154 |
return r; |
| 155 |
} |
| 156 |
|
| 157 |
template <int dim1, int dim2> |
| 158 |
void |
| 159 |
split_point(const Point<dim1 + dim2> &source, |
| 160 |
Point<dim1> &p1, |
| 161 |
Point<dim2> &p2) |
| 162 |
{ |
| 163 |
for (unsigned int d = 0; d < dim1; ++d) |
| 164 |
p1[d] = source[d]; |
| 165 |
for (unsigned int d = 0; d < dim2; ++d) |
| 166 |
p2[d] = source[dim1 + d]; |
| 167 |
} |
| 168 |
|
| 169 |
} // namespace TensorProductManifoldImplementation |
| 170 |
} // namespace internal |
| 171 |
|
| 172 |
template <int dim, |
| 173 |
int dim_A, |
| 174 |
int spacedim_A, |
| 175 |
int chartdim_A, |
| 176 |
int dim_B, |
| 177 |
int spacedim_B, |
| 178 |
int chartdim_B> |
| 179 |
TensorProductManifold<dim, |
| 180 |
dim_A, |
| 181 |
spacedim_A, |
| 182 |
chartdim_A, |
| 183 |
dim_B, |
| 184 |
spacedim_B, |
| 185 |
chartdim_B>:: |
| 186 |
TensorProductManifold( |
| 187 |
const ChartManifold<dim_A, spacedim_A, chartdim_A> &manifold_A, |
| 188 |
const ChartManifold<dim_B, spacedim_B, chartdim_B> &manifold_B) |
| 189 |
: ChartManifold<dim, spacedim_A + spacedim_B, chartdim_A + chartdim_B>( |
| 190 |
internal::TensorProductManifoldImplementation::concat( |
| 191 |
manifold_A.get_periodicity(), |
| 192 |
manifold_B.get_periodicity())) |
| 193 |
, manifold_A(Utilities::dynamic_unique_cast< |
| 194 |
ChartManifold<dim_A, spacedim_A, chartdim_A>, |
| 195 |
Manifold<dim_A, spacedim_A>>(manifold_A.clone())) |
| 196 |
, manifold_B(Utilities::dynamic_unique_cast< |
| 197 |
ChartManifold<dim_B, spacedim_B, chartdim_B>, |
| 198 |
Manifold<dim_B, spacedim_B>>(manifold_B.clone())) |
| 199 |
{} |
| 200 |
|
| 201 |
template <int dim, |
| 202 |
int dim_A, |
| 203 |
int spacedim_A, |
| 204 |
int chartdim_A, |
| 205 |
int dim_B, |
| 206 |
int spacedim_B, |
| 207 |
int chartdim_B> |
| 208 |
std::unique_ptr<Manifold<dim, spacedim_A + spacedim_B>> |
| 209 |
TensorProductManifold<dim, |
| 210 |
dim_A, |
| 211 |
spacedim_A, |
| 212 |
chartdim_A, |
| 213 |
dim_B, |
| 214 |
spacedim_B, |
| 215 |
chartdim_B>::clone() const |
| 216 |
{ |
| 217 |
return std::make_unique<TensorProductManifold<dim, |
| 218 |
dim_A, |
| 219 |
spacedim_A, |
| 220 |
chartdim_A, |
| 221 |
dim_B, |
| 222 |
spacedim_B, |
| 223 |
chartdim_B>>(*manifold_A, |
| 224 |
*manifold_B); |
| 225 |
} |
| 226 |
|
| 227 |
template <int dim, |
| 228 |
int dim_A, |
| 229 |
int spacedim_A, |
| 230 |
int chartdim_A, |
| 231 |
int dim_B, |
| 232 |
int spacedim_B, |
| 233 |
int chartdim_B> |
| 234 |
Point<TensorProductManifold<dim, |
| 235 |
dim_A, |
| 236 |
spacedim_A, |
| 237 |
chartdim_A, |
| 238 |
dim_B, |
| 239 |
spacedim_B, |
| 240 |
chartdim_B>::chartdim> |
| 241 |
TensorProductManifold<dim, |
| 242 |
dim_A, |
| 243 |
spacedim_A, |
| 244 |
chartdim_A, |
| 245 |
dim_B, |
| 246 |
spacedim_B, |
| 247 |
chartdim_B>:: |
| 248 |
pull_back( |
| 249 |
const Point<TensorProductManifold<dim, |
| 250 |
dim_A, |
| 251 |
spacedim_A, |
| 252 |
chartdim_A, |
| 253 |
dim_B, |
| 254 |
spacedim_B, |
| 255 |
chartdim_B>::spacedim> &space_point) const |
| 256 |
{ |
| 257 |
Point<spacedim_A> space_point_A; |
| 258 |
Point<spacedim_B> space_point_B; |
| 259 |
internal::TensorProductManifoldImplementation::split_point(space_point, |
| 260 |
space_point_A, |
| 261 |
space_point_B); |
| 262 |
|
| 263 |
Point<chartdim_A> result_A = manifold_A->pull_back(space_point_A); |
| 264 |
Point<chartdim_B> result_B = manifold_B->pull_back(space_point_B); |
| 265 |
|
| 266 |
return internal::TensorProductManifoldImplementation::concat(result_A, |
| 267 |
result_B); |
| 268 |
} |
| 269 |
|
| 270 |
template <int dim, |
| 271 |
int dim_A, |
| 272 |
int spacedim_A, |
| 273 |
int chartdim_A, |
| 274 |
int dim_B, |
| 275 |
int spacedim_B, |
| 276 |
int chartdim_B> |
| 277 |
Point<TensorProductManifold<dim, |
| 278 |
dim_A, |
| 279 |
spacedim_A, |
| 280 |
chartdim_A, |
| 281 |
dim_B, |
| 282 |
spacedim_B, |
| 283 |
chartdim_B>::spacedim> |
| 284 |
TensorProductManifold<dim, |
| 285 |
dim_A, |
| 286 |
spacedim_A, |
| 287 |
chartdim_A, |
| 288 |
dim_B, |
| 289 |
spacedim_B, |
| 290 |
chartdim_B>:: |
| 291 |
push_forward( |
| 292 |
const Point<TensorProductManifold<dim, |
| 293 |
dim_A, |
| 294 |
spacedim_A, |
| 295 |
chartdim_A, |
| 296 |
dim_B, |
| 297 |
spacedim_B, |
| 298 |
chartdim_B>::chartdim> &chart_point) const |
| 299 |
{ |
| 300 |
Point<chartdim_A> chart_point_A; |
| 301 |
Point<chartdim_B> chart_point_B; |
| 302 |
internal::TensorProductManifoldImplementation::split_point(chart_point, |
| 303 |
chart_point_A, |
| 304 |
chart_point_B); |
| 305 |
|
| 306 |
Point<spacedim_A> result_A = manifold_A->push_forward(chart_point_A); |
| 307 |
Point<spacedim_B> result_B = manifold_B->push_forward(chart_point_B); |
| 308 |
|
| 309 |
return internal::TensorProductManifoldImplementation::concat(result_A, |
| 310 |
result_B); |
| 311 |
} |
| 312 |
|
| 313 |
template <int dim, |
| 314 |
int dim_A, |
| 315 |
int spacedim_A, |
| 316 |
int chartdim_A, |
| 317 |
int dim_B, |
| 318 |
int spacedim_B, |
| 319 |
int chartdim_B> |
| 320 |
DerivativeForm<1, |
| 321 |
TensorProductManifold<dim, |
| 322 |
dim_A, |
| 323 |
spacedim_A, |
| 324 |
chartdim_A, |
| 325 |
dim_B, |
| 326 |
spacedim_B, |
| 327 |
chartdim_B>::chartdim, |
| 328 |
TensorProductManifold<dim, |
| 329 |
dim_A, |
| 330 |
spacedim_A, |
| 331 |
chartdim_A, |
| 332 |
dim_B, |
| 333 |
spacedim_B, |
| 334 |
chartdim_B>::spacedim> |
| 335 |
|
| 336 |
TensorProductManifold<dim, |
| 337 |
dim_A, |
| 338 |
spacedim_A, |
| 339 |
chartdim_A, |
| 340 |
dim_B, |
| 341 |
spacedim_B, |
| 342 |
chartdim_B>:: |
| 343 |
push_forward_gradient( |
| 344 |
const Point<TensorProductManifold<dim, |
| 345 |
dim_A, |
| 346 |
spacedim_A, |
| 347 |
chartdim_A, |
| 348 |
dim_B, |
| 349 |
spacedim_B, |
| 350 |
chartdim_B>::chartdim> &chart_point) const |
| 351 |
{ |
| 352 |
Point<chartdim_A> chart_point_A; |
| 353 |
Point<chartdim_B> chart_point_B; |
| 354 |
internal::TensorProductManifoldImplementation::split_point(chart_point, |
| 355 |
chart_point_A, |
| 356 |
chart_point_B); |
| 357 |
|
| 358 |
DerivativeForm<1, chartdim_A, spacedim_A> result_A = |
| 359 |
manifold_A->push_forward_gradient(chart_point_A); |
| 360 |
DerivativeForm<1, chartdim_B, spacedim_B> result_B = |
| 361 |
manifold_B->push_forward_gradient(chart_point_B); |
| 362 |
|
| 363 |
|
| 364 |
DerivativeForm<1, chartdim, spacedim> result; |
| 365 |
for (unsigned int i = 0; i < chartdim_A; ++i) |
| 366 |
for (unsigned int j = 0; j < spacedim_A; ++j) |
| 367 |
result[j][i] = result_A[j][i]; |
| 368 |
for (unsigned int i = 0; i < chartdim_B; ++i) |
| 369 |
for (unsigned int j = 0; j < spacedim_B; ++j) |
| 370 |
result[j + spacedim_A][i + chartdim_A] = result_B[j][i]; |
| 371 |
|
| 372 |
return result; |
| 373 |
} |
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
DEAL_II_NAMESPACE_CLOSE |
| 378 |
|
| 379 |
#endif |