| 1 |
// ------------------------------------------------------------------------ |
| 2 |
// |
| 3 |
// SPDX-License-Identifier: LGPL-2.1-or-later |
| 4 |
// Copyright (C) 2025 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_mapping_internal_h |
| 16 |
#define dealii_mapping_internal_h |
| 17 |
|
| 18 |
#include <deal.II/base/config.h> |
| 19 |
|
| 20 |
#include <deal.II/base/derivative_form.h> |
| 21 |
#include <deal.II/base/tensor.h> |
| 22 |
|
| 23 |
// Implementations of transformations used by several Mapping classes (such as |
| 24 |
// MappingFE, MappingQ, and MappingFEField, and MappingManifold) |
| 25 |
|
| 26 |
DEAL_II_NAMESPACE_OPEN |
| 27 |
|
| 28 |
namespace internal |
| 29 |
{ |
| 30 |
/** |
| 31 |
* Map the gradient of a covariant vector field. For more information see the |
| 32 |
* overload of Mapping::transform() which maps 2-differential forms from the |
| 33 |
* reference cell to the physical cell. |
| 34 |
*/ |
| 35 |
template <int dim, int spacedim, typename Number> |
| 36 |
Tensor<3, spacedim, Number> |
| 37 |
apply_covariant_gradient( |
| 38 |
const DerivativeForm<1, dim, spacedim, Number> &covariant, |
| 39 |
const DerivativeForm<2, dim, spacedim, Number> &input); |
| 40 |
|
| 41 |
/** |
| 42 |
* Map the Hessian of a contravariant vector field. For more information see |
| 43 |
* the overload of Mapping::transform() which maps 3-differential forms from |
| 44 |
* the reference cell to the physical cell. |
| 45 |
*/ |
| 46 |
template <int dim, int spacedim, typename Number> |
| 47 |
Tensor<3, spacedim, Number> |
| 48 |
apply_contravariant_hessian( |
| 49 |
const DerivativeForm<1, dim, spacedim, Number> &covariant, |
| 50 |
const DerivativeForm<1, dim, spacedim, Number> &contravariant, |
| 51 |
const Tensor<3, dim, Number> &input); |
| 52 |
|
| 53 |
/** |
| 54 |
* Map the Hessian of a covariant vector field. For more information see the |
| 55 |
* overload of Mapping::transform() which maps 3-differential forms from the |
| 56 |
* reference cell to the physical cell. |
| 57 |
*/ |
| 58 |
template <int dim, int spacedim, typename Number> |
| 59 |
Tensor<3, spacedim, Number> |
| 60 |
apply_covariant_hessian( |
| 61 |
const DerivativeForm<1, dim, spacedim, Number> &covariant, |
| 62 |
const Tensor<3, dim, Number> &input); |
| 63 |
|
| 64 |
/** |
| 65 |
* Map the Hessian of a Piola vector field. For more information see the |
| 66 |
* overload of Mapping::transform() which maps 3-differential forms from the |
| 67 |
* reference cell to the physical cell. |
| 68 |
*/ |
| 69 |
template <int dim, int spacedim, typename Number> |
| 70 |
Tensor<3, spacedim, Number> |
| 71 |
apply_piola_hessian( |
| 72 |
const DerivativeForm<1, dim, spacedim, Number> &covariant, |
| 73 |
const DerivativeForm<1, dim, spacedim, Number> &contravariant, |
| 74 |
const Number &volume_element, |
| 75 |
const Tensor<3, dim, Number> &input); |
| 76 |
} // namespace internal |
| 77 |
|
| 78 |
namespace internal |
| 79 |
{ |
| 80 |
template <int dim, int spacedim, typename Number> |
| 81 |
Tensor<3, spacedim, Number> |
| 82 |
apply_covariant_gradient( |
| 83 |
const DerivativeForm<1, dim, spacedim, Number> &covariant, |
| 84 |
const DerivativeForm<2, dim, spacedim, Number> &input) |
| 85 |
{ |
| 86 |
Tensor<3, spacedim, Number> output; |
| 87 |
for (unsigned int i = 0; i < spacedim; ++i) |
| 88 |
for (unsigned int j = 0; j < spacedim; ++j) |
| 89 |
{ |
| 90 |
double tmp[dim]; |
| 91 |
for (unsigned int K = 0; K < dim; ++K) |
| 92 |
{ |
| 93 |
tmp[K] = covariant[j][0] * input[i][0][K]; |
| 94 |
for (unsigned int J = 1; J < dim; ++J) |
| 95 |
tmp[K] += covariant[j][J] * input[i][J][K]; |
| 96 |
} |
| 97 |
for (unsigned int k = 0; k < spacedim; ++k) |
| 98 |
{ |
| 99 |
output[i][j][k] = covariant[k][0] * tmp[0]; |
| 100 |
for (unsigned int K = 1; K < dim; ++K) |
| 101 |
output[i][j][k] += covariant[k][K] * tmp[K]; |
| 102 |
} |
| 103 |
} |
| 104 |
|
| 105 |
return output; |
| 106 |
} |
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
template <int dim, int spacedim, typename Number> |
| 111 |
inline Tensor<3, spacedim, Number> |
| 112 |
apply_contravariant_hessian( |
| 113 |
const DerivativeForm<1, dim, spacedim, Number> &covariant, |
| 114 |
const DerivativeForm<1, dim, spacedim, Number> &contravariant, |
| 115 |
const Tensor<3, dim, Number> &input) |
| 116 |
{ |
| 117 |
Tensor<3, spacedim, Number> output; |
| 118 |
for (unsigned int i = 0; i < spacedim; ++i) |
| 119 |
{ |
| 120 |
Number tmp1[dim][dim]; |
| 121 |
for (unsigned int J = 0; J < dim; ++J) |
| 122 |
for (unsigned int K = 0; K < dim; ++K) |
| 123 |
{ |
| 124 |
tmp1[J][K] = contravariant[i][0] * input[0][J][K]; |
| 125 |
for (unsigned int I = 1; I < dim; ++I) |
| 126 |
tmp1[J][K] += contravariant[i][I] * input[I][J][K]; |
| 127 |
} |
| 128 |
for (unsigned int j = 0; j < spacedim; ++j) |
| 129 |
{ |
| 130 |
Number tmp2[dim]; |
| 131 |
for (unsigned int K = 0; K < dim; ++K) |
| 132 |
{ |
| 133 |
tmp2[K] = covariant[j][0] * tmp1[0][K]; |
| 134 |
for (unsigned int J = 1; J < dim; ++J) |
| 135 |
tmp2[K] += covariant[j][J] * tmp1[J][K]; |
| 136 |
} |
| 137 |
for (unsigned int k = 0; k < spacedim; ++k) |
| 138 |
{ |
| 139 |
output[i][j][k] = covariant[k][0] * tmp2[0]; |
| 140 |
for (unsigned int K = 1; K < dim; ++K) |
| 141 |
output[i][j][k] += covariant[k][K] * tmp2[K]; |
| 142 |
} |
| 143 |
} |
| 144 |
} |
| 145 |
|
| 146 |
return output; |
| 147 |
} |
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
template <int dim, int spacedim, typename Number> |
| 152 |
inline Tensor<3, spacedim, Number> |
| 153 |
apply_covariant_hessian( |
| 154 |
const DerivativeForm<1, dim, spacedim, Number> &covariant, |
| 155 |
const Tensor<3, dim, Number> &input) |
| 156 |
{ |
| 157 |
Tensor<3, spacedim, Number> output; |
| 158 |
for (unsigned int i = 0; i < spacedim; ++i) |
| 159 |
{ |
| 160 |
Number tmp1[dim][dim]; |
| 161 |
for (unsigned int J = 0; J < dim; ++J) |
| 162 |
for (unsigned int K = 0; K < dim; ++K) |
| 163 |
{ |
| 164 |
tmp1[J][K] = covariant[i][0] * input[0][J][K]; |
| 165 |
for (unsigned int I = 1; I < dim; ++I) |
| 166 |
tmp1[J][K] += covariant[i][I] * input[I][J][K]; |
| 167 |
} |
| 168 |
for (unsigned int j = 0; j < spacedim; ++j) |
| 169 |
{ |
| 170 |
Number tmp2[dim]; |
| 171 |
for (unsigned int K = 0; K < dim; ++K) |
| 172 |
{ |
| 173 |
tmp2[K] = covariant[j][0] * tmp1[0][K]; |
| 174 |
for (unsigned int J = 1; J < dim; ++J) |
| 175 |
tmp2[K] += covariant[j][J] * tmp1[J][K]; |
| 176 |
} |
| 177 |
for (unsigned int k = 0; k < spacedim; ++k) |
| 178 |
{ |
| 179 |
output[i][j][k] = covariant[k][0] * tmp2[0]; |
| 180 |
for (unsigned int K = 1; K < dim; ++K) |
| 181 |
output[i][j][k] += covariant[k][K] * tmp2[K]; |
| 182 |
} |
| 183 |
} |
| 184 |
} |
| 185 |
|
| 186 |
return output; |
| 187 |
} |
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
template <int dim, int spacedim, typename Number> |
| 192 |
inline Tensor<3, spacedim, Number> |
| 193 |
apply_piola_hessian( |
| 194 |
const DerivativeForm<1, dim, spacedim, Number> &covariant, |
| 195 |
const DerivativeForm<1, dim, spacedim, Number> &contravariant, |
| 196 |
const Number &volume_element, |
| 197 |
const Tensor<3, dim, Number> &input) |
| 198 |
{ |
| 199 |
Tensor<3, spacedim, Number> output; |
| 200 |
for (unsigned int i = 0; i < spacedim; ++i) |
| 201 |
{ |
| 202 |
Number factor[dim]; |
| 203 |
for (unsigned int I = 0; I < dim; ++I) |
| 204 |
factor[I] = contravariant[i][I] * (1. / volume_element); |
| 205 |
Number tmp1[dim][dim]; |
| 206 |
for (unsigned int J = 0; J < dim; ++J) |
| 207 |
for (unsigned int K = 0; K < dim; ++K) |
| 208 |
{ |
| 209 |
tmp1[J][K] = factor[0] * input[0][J][K]; |
| 210 |
for (unsigned int I = 1; I < dim; ++I) |
| 211 |
tmp1[J][K] += factor[I] * input[I][J][K]; |
| 212 |
} |
| 213 |
for (unsigned int j = 0; j < spacedim; ++j) |
| 214 |
{ |
| 215 |
Number tmp2[dim]; |
| 216 |
for (unsigned int K = 0; K < dim; ++K) |
| 217 |
{ |
| 218 |
tmp2[K] = covariant[j][0] * tmp1[0][K]; |
| 219 |
for (unsigned int J = 1; J < dim; ++J) |
| 220 |
tmp2[K] += covariant[j][J] * tmp1[J][K]; |
| 221 |
} |
| 222 |
for (unsigned int k = 0; k < spacedim; ++k) |
| 223 |
{ |
| 224 |
output[i][j][k] = covariant[k][0] * tmp2[0]; |
| 225 |
for (unsigned int K = 1; K < dim; ++K) |
| 226 |
output[i][j][k] += covariant[k][K] * tmp2[K]; |
| 227 |
} |
| 228 |
} |
| 229 |
} |
| 230 |
|
| 231 |
return output; |
| 232 |
} |
| 233 |
} // namespace internal |
| 234 |
|
| 235 |
DEAL_II_NAMESPACE_CLOSE |
| 236 |
|
| 237 |
#endif |