Debian Codegraph @

include/deal.II/base/derivative_form.h

raw
1 // ------------------------------------------------------------------------
2 //
3 // SPDX-License-Identifier: LGPL-2.1-or-later
4 // Copyright (C) 2013 - 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_derivative_form_h
16 #define dealii_derivative_form_h
17
18 #include <deal.II/base/config.h>
19
20 #include <deal.II/base/exceptions.h>
21 #include <deal.II/base/numbers.h>
22 #include <deal.II/base/template_constraints.h>
23 #include <deal.II/base/tensor.h>
24
25 #include <cstddef>
26
27
28 DEAL_II_NAMESPACE_OPEN
29
30 /**
31 * This class represents the (tangential) derivatives of a function $ \mathbf F:
32 * {\mathbb R}^{\text{dim}} \rightarrow {\mathbb R}^{\text{spacedim}}$. Such
33 * functions are always used to map the reference dim-dimensional cell into
34 * spacedim-dimensional space. For such objects, the first derivative of the
35 * function is a linear map from ${\mathbb R}^{\text{dim}}$ to ${\mathbb
36 * R}^{\text{spacedim}}$, i.e., it can be represented as a matrix in ${\mathbb
37 * R}^{\text{spacedim}\times \text{dim}}$. This makes sense since one would
38 * represent the first derivative, $\nabla \mathbf F(\mathbf x)$ with $\mathbf
39 * x\in
40 * {\mathbb R}^{\text{dim}}$, in such a way that the directional derivative in
41 * direction $\mathbf d\in {\mathbb R}^{\text{dim}}$ so that
42 * @f{align*}{
43 * \nabla \mathbf F(\mathbf x) \mathbf d
44 * = \lim_{\varepsilon\rightarrow 0}
45 * \frac{\mathbf F(\mathbf x + \varepsilon \mathbf d) - \mathbf F(\mathbf
46 * x)}{\varepsilon},
47 * @f}
48 * i.e., one needs to be able to multiply the matrix $\nabla \mathbf F(\mathbf
49 * x)$ by a vector in ${\mathbb R}^{\text{dim}}$, and the result is a difference
50 * of function values, which are in ${\mathbb R}^{\text{spacedim}}$.
51 * Consequently, the matrix must be of size $\text{spacedim}\times\text{dim}$.
52 *
53 * Similarly, the second derivative is a bilinear map from ${\mathbb
54 * R}^{\text{dim}} \times {\mathbb R}^{\text{dim}}$ to ${\mathbb
55 * R}^{\text{spacedim}}$, which one can think of a rank-3 object of size
56 * $\text{spacedim}\times\text{dim}\times\text{dim}$.
57 *
58 * In deal.II we represent these derivatives using objects of type
59 * DerivativeForm@<1,dim,spacedim,Number@>,
60 * DerivativeForm@<2,dim,spacedim,Number@> and so on.
61 */
62 template <int order, int dim, int spacedim, typename Number = double>
63 class DerivativeForm
64 {
65 public:
66 /**
67 * Constructor. Initialize all entries to zero.
68 */
69 DerivativeForm() = default;
70
71 /**
72 * Constructor from a tensor.
73 */
74 DerivativeForm(const Tensor<order + 1, dim, Number> &);
75
76 /**
77 * Constructor. This constructor initializes the data stored by this
78 * object from a `spacedim x dim^order` array that is represented
79 * by a Tensor with `spacedim` components each of which is a
80 * Tensor of rank `order` and size `dim`.
81 */
82 DerivativeForm(const Tensor<1, spacedim, Tensor<order, dim, Number>> &);
83
84 /**
85 * Read-Write access operator.
86 */
87 Tensor<order, dim, Number> &
88 operator[](const unsigned int i);
89
90 /**
91 * Read-only access operator.
92 */
93 const Tensor<order, dim, Number> &
94 operator[](const unsigned int i) const;
95
96 /**
97 * Assignment operator.
98 */
99 DerivativeForm &
100 operator=(const Tensor<order + 1, dim, Number> &);
101
102 /**
103 * Assignment operator.
104 */
105 DerivativeForm &
106 operator=(const Tensor<order, spacedim, Tensor<1, dim, Number>> &);
107
108 /**
109 * Assignment operator.
110 */
111 DerivativeForm &
112 operator=(const Tensor<1, dim, Number> &);
113
114 /**
115 * Number conversion operator.
116 */
117 template <typename OtherNumber>
118 DerivativeForm &
119 operator=(const DerivativeForm<order, dim, spacedim, OtherNumber> &df);
120
121 /**
122 * Converts a DerivativeForm <order, dim, dim, Number> to Tensor<order+1, dim,
123 * Number>. In particular, if order == 1 and the derivative is the Jacobian of
124 * $\mathbf F(\mathbf x)$, then Tensor[i] = $\nabla F_i(\mathbf x)$.
125 */
126 operator Tensor<order + 1, dim, Number>() const;
127
128 /**
129 * Converts a DerivativeForm<1, dim, 1, Number> to Tensor<1, dim, Number>.
130 */
131 operator Tensor<1, dim, Number>() const;
132
133 /**
134 * Return the transpose of a rectangular DerivativeForm,
135 * viewed as a two dimensional matrix.
136 */
137 DerivativeForm<1, spacedim, dim, Number>
138 transpose() const;
139
140 /**
141 * Compute the Frobenius norm of this form, i.e., the expression
142 * $\sqrt{\sum_{ij} |DF_{ij}|^2} =
143 * \sqrt{\sum_{ij} |\frac{\partial F_i}{\partial x_j}|^2}$.
144 */
145 typename numbers::NumberTraits<Number>::real_type
146 norm() const;
147
148 /**
149 * Compute the volume element associated with the Jacobian of the
150 * transformation $\mathbf F$. That is to say if $DF$ is square, it computes
151 * $\det(DF)$, in case DF is not square returns $\sqrt{\det(DF^T \,DF)}$.
152 */
153 Number
154 determinant() const;
155
156 /**
157 * Assuming that the current object stores the Jacobian of a mapping
158 * $\mathbf F$, then the current function computes the <i>covariant</i> form
159 * of the derivative, namely $(\nabla \mathbf F) {\mathbf G}^{-1}$, where
160 * $\mathbf G = (\nabla \mathbf F)^{T}(\nabla \mathbf F)$. If $\nabla \mathbf
161 * F$ is a square matrix (i.e., $\mathbf F:
162 * {\mathbb R}^n \mapsto {\mathbb R}^n$), then this function
163 * simplifies to computing $\nabla {\mathbf F}^{-T}$.
164 */
165 DerivativeForm<1, dim, spacedim, Number>
166 covariant_form() const;
167
168
169 /**
170 * Compute the first fundamental form. This is the tensor of dot products of
171 * the columns of the current object.
172 *
173 * @note This function is only defined for `order == 1`.
174 */
175 Tensor<2, dim, Number>
176 first_fundamental_form() const;
177
178 /**
179 * Determine an estimate for the memory consumption (in bytes) of this
180 * object.
181 */
182 static std::size_t
183 memory_consumption();
184
185 /**
186 * Exception.
187 */
188 DeclException1(ExcInvalidTensorIndex,
189 int,
190 << "Invalid DerivativeForm index " << arg1);
191
192 private:
193 /**
194 * Auxiliary function that computes $A T^{T}$ where A represents the current
195 * object.
196 */
197 DerivativeForm<1, dim, spacedim, Number>
198 times_T_t(const Tensor<2, dim, Number> &T) const;
199
200
201 /**
202 * Array of tensors holding the subelements.
203 */
204 Tensor<order, dim, Number> tensor[spacedim];
205 };
206
207
208 /*--------------------------- Inline functions -----------------------------*/
209
210 #ifndef DOXYGEN
211
212 template <int order, int dim, int spacedim, typename Number>
213 inline DerivativeForm<order, dim, spacedim, Number>::DerivativeForm(
214 const Tensor<order + 1, dim, Number> &T)
215 {
216 Assert((dim == spacedim),
217 ExcMessage("Only allowed for forms with dim==spacedim."));
218 if (dim == spacedim)
219 for (unsigned int j = 0; j < dim; ++j)
220 (*this)[j] = T[j];
221 }
222
223
224
225 template <int order, int dim, int spacedim, typename Number>
226 inline DerivativeForm<order, dim, spacedim, Number>::DerivativeForm(
227 const Tensor<1, spacedim, Tensor<order, dim, Number>> &T)
228 {
229 for (unsigned int j = 0; j < spacedim; ++j)
230 (*this)[j] = T[j];
231 }
232
233
234
235 template <int order, int dim, int spacedim, typename Number>
236 inline DerivativeForm<order, dim, spacedim, Number> &
237 DerivativeForm<order, dim, spacedim, Number>::operator=(
238 const Tensor<order + 1, dim, Number> &ta)
239 {
240 Assert((dim == spacedim), ExcMessage("Only allowed when dim==spacedim."));
241
242 if (dim == spacedim)
243 for (unsigned int j = 0; j < dim; ++j)
244 (*this)[j] = ta[j];
245 return *this;
246 }
247
248
249
250 template <int order, int dim, int spacedim, typename Number>
251 inline DerivativeForm<order, dim, spacedim, Number> &
252 DerivativeForm<order, dim, spacedim, Number>::operator=(
253 const Tensor<order, spacedim, Tensor<1, dim, Number>> &T)
254 {
255 for (unsigned int j = 0; j < spacedim; ++j)
256 (*this)[j] = T[j];
257 return *this;
258 }
259
260
261
262 template <int order, int dim, int spacedim, typename Number>
263 inline DerivativeForm<order, dim, spacedim, Number> &
264 DerivativeForm<order, dim, spacedim, Number>::operator=(
265 const Tensor<1, dim, Number> &T)
266 {
267 Assert((1 == spacedim) && (order == 1),
268 ExcMessage("Only allowed for spacedim==1 and order==1."));
269
270 (*this)[0] = T;
271
272 return *this;
273 }
274
275
276
277 template <int order, int dim, int spacedim, typename Number>
278 template <typename OtherNumber>
279 inline DerivativeForm<order, dim, spacedim, Number> &
280 DerivativeForm<order, dim, spacedim, Number>::operator=(
281 const DerivativeForm<order, dim, spacedim, OtherNumber> &df)
282 {
283 for (unsigned int j = 0; j < spacedim; ++j)
284 (*this)[j] = df[j];
285 return *this;
286 }
287
288
289
290 template <int order, int dim, int spacedim, typename Number>
291 inline Tensor<order, dim, Number> &
292 DerivativeForm<order, dim, spacedim, Number>::operator[](const unsigned int i)
293 {
294 AssertIndexRange(i, spacedim);
295
296 return tensor[i];
297 }
298
299
300
301 template <int order, int dim, int spacedim, typename Number>
302 inline const Tensor<order, dim, Number> &
303 DerivativeForm<order, dim, spacedim, Number>::operator[](
304 const unsigned int i) const
305 {
306 AssertIndexRange(i, spacedim);
307
308 return tensor[i];
309 }
310
311
312
313 template <int order, int dim, int spacedim, typename Number>
314 inline DerivativeForm<order, dim, spacedim, Number>::
315 operator Tensor<1, dim, Number>() const
316 {
317 Assert((1 == spacedim) && (order == 1),
318 ExcMessage("Only allowed for spacedim==1."));
319
320 return (*this)[0];
321 }
322
323
324
325 template <int order, int dim, int spacedim, typename Number>
326 inline DerivativeForm<order, dim, spacedim, Number>::
327 operator Tensor<order + 1, dim, Number>() const
328 {
329 Assert((dim == spacedim), ExcMessage("Only allowed when dim==spacedim."));
330
331 Tensor<order + 1, dim, Number> t;
332
333 if (dim == spacedim)
334 for (unsigned int j = 0; j < dim; ++j)
335 t[j] = (*this)[j];
336
337 return t;
338 }
339
340
341
342 template <int order, int dim, int spacedim, typename Number>
343 inline DerivativeForm<1, spacedim, dim, Number>
344 DerivativeForm<order, dim, spacedim, Number>::transpose() const
345 {
346 Assert(order == 1, ExcMessage("Only for rectangular DerivativeForm."));
347 DerivativeForm<1, spacedim, dim, Number> tt;
348
349 for (unsigned int i = 0; i < spacedim; ++i)
350 for (unsigned int j = 0; j < dim; ++j)
351 tt[j][i] = (*this)[i][j];
352
353 return tt;
354 }
355
356
357
358 template <int order, int dim, int spacedim, typename Number>
359 inline DerivativeForm<1, dim, spacedim, Number>
360 DerivativeForm<order, dim, spacedim, Number>::times_T_t(
361 const Tensor<2, dim, Number> &T) const
362 {
363 Assert(order == 1, ExcMessage("Only for order == 1."));
364 DerivativeForm<1, dim, spacedim, Number> dest;
365 for (unsigned int i = 0; i < spacedim; ++i)
366 for (unsigned int j = 0; j < dim; ++j)
367 dest[i][j] = (*this)[i] * T[j];
368
369 return dest;
370 }
371
372
373
374 template <int order, int dim, int spacedim, typename Number>
375 inline typename numbers::NumberTraits<Number>::real_type
376 DerivativeForm<order, dim, spacedim, Number>::norm() const
377 {
378 typename numbers::NumberTraits<Number>::real_type sum_of_squares = 0;
379 for (unsigned int i = 0; i < spacedim; ++i)
380 sum_of_squares += tensor[i].norm_square();
381 return std::sqrt(sum_of_squares);
382 }
383
384
385
386 template <int order, int dim, int spacedim, typename Number>
387 inline Number
388 DerivativeForm<order, dim, spacedim, Number>::determinant() const
389 {
390 Assert(order == 1, ExcMessage("Only for order == 1."));
391 if (dim == spacedim)
392 {
393 const Tensor<2, dim, Number> T =
394 static_cast<Tensor<2, dim, Number>>(*this);
395 return dealii::determinant(T);
396 }
397 else
398 {
399 Assert(spacedim > dim, ExcMessage("Only for spacedim>dim."));
400 return (std::sqrt(dealii::determinant(first_fundamental_form())));
401 }
402 }
403
404
405
406 template <int order, int dim, int spacedim, typename Number>
407 inline Tensor<2, dim, Number>
408 DerivativeForm<order, dim, spacedim, Number>::first_fundamental_form() const
409 {
410 Assert(order == 1, ExcMessage("Only for order == 1."));
411 const DerivativeForm<1, spacedim, dim, Number> DF_t = this->transpose();
412
413 Tensor<2, dim, Number> G;
414 for (unsigned int i = 0; i < dim; ++i)
415 for (unsigned int j = 0; j < dim; ++j)
416 G[i][j] = DF_t[i] * DF_t[j];
417
418 return G;
419 }
420
421
422
423 template <int order, int dim, int spacedim, typename Number>
424 inline DerivativeForm<1, dim, spacedim, Number>
425 DerivativeForm<order, dim, spacedim, Number>::covariant_form() const
426 {
427 if (dim == spacedim)
428 {
429 const Tensor<2, dim, Number> DF_t =
430 dealii::transpose(invert(static_cast<Tensor<2, dim, Number>>(*this)));
431 return DerivativeForm<1, dim, spacedim, Number>(DF_t);
432 }
433 else
434 {
435 return (this->times_T_t(invert(first_fundamental_form())));
436 }
437 }
438
439
440 template <int order, int dim, int spacedim, typename Number>
441 inline std::size_t
442 DerivativeForm<order, dim, spacedim, Number>::memory_consumption()
443 {
444 return sizeof(DerivativeForm<order, dim, spacedim, Number>);
445 }
446
447 #endif // DOXYGEN
448
449
450
451 /**
452 * Output operator for DerivativeForm. Print the elements consecutively, with a
453 * space in between, two spaces between rank 1 subtensors, three between rank 2
454 * and so on.
455 *
456 * @relatesalso DerivativeForm
457 */
458 template <int order, int dim, int spacedim, typename Number>
459 inline std::ostream &
460 operator<<(std::ostream &out,
461 const DerivativeForm<order, dim, spacedim, Number> &df)
462 {
463 for (unsigned int i = 0; i < spacedim; ++i)
464 {
465 out << df[i];
466 if (i != spacedim - 1)
467 for (unsigned int j = 0; j < order + 1; ++j)
468 out << ' ';
469 }
470
471 return out;
472 }
473
474
475
476 /**
477 * One of the uses of DerivativeForm is to apply it as a linear transformation.
478 * This function returns $\nabla \mathbf F(\mathbf x) \Delta \mathbf x$, which
479 * approximates the change in $\mathbf F(\mathbf x)$ when $\mathbf x$ is changed
480 * by the amount $\Delta \mathbf x$
481 * @f[
482 * \nabla \mathbf F(\mathbf x) \; \Delta \mathbf x
483 * \approx
484 * \mathbf F(\mathbf x + \Delta \mathbf x) - \mathbf F(\mathbf x).
485 * @f]
486 * The transformation corresponds to
487 * @f[
488 * [\text{result}]_{i_1,\dots,i_k} = i\sum_{j}
489 * \left[\nabla \mathbf F(\mathbf x)\right]_{i_1,\dots,i_k, j}
490 * \Delta x_j
491 * @f]
492 * in index notation and corresponds to
493 * $[\Delta \mathbf x] [\nabla \mathbf F(\mathbf x)]^T$ in matrix notation.
494 *
495 * @relatesalso DerivativeForm
496 */
497 template <int spacedim, int dim, typename Number1, typename Number2>
498 inline Tensor<1, spacedim, typename ProductType<Number1, Number2>::type>
499 apply_transformation(const DerivativeForm<1, dim, spacedim, Number1> &grad_F,
500 const Tensor<1, dim, Number2> &d_x)
501 {
502 Tensor<1, spacedim, typename ProductType<Number1, Number2>::type> dest;
503 for (unsigned int i = 0; i < spacedim; ++i)
504 dest[i] = grad_F[i] * d_x;
505 return dest;
506 }
507
508
509
510 /**
511 * Similar to the previous apply_transformation().
512 * Each row of the result corresponds to one of the rows of @p D_X transformed
513 * by @p grad_F, equivalent to $\mathrm{D\_X} \, \mathrm{grad\_F}^T$ in matrix
514 * notation.
515 *
516 * @relatesalso DerivativeForm
517 */
518 // rank=2
519 template <int spacedim, int dim, typename Number1, typename Number2>
520 inline DerivativeForm<1,
521 spacedim,
522 dim,
523 typename ProductType<Number1, Number2>::type>
524 apply_transformation(const DerivativeForm<1, dim, spacedim, Number1> &grad_F,
525 const Tensor<2, dim, Number2> &D_X)
526 {
527 DerivativeForm<1, spacedim, dim, typename ProductType<Number1, Number2>::type>
528 dest;
529 for (unsigned int i = 0; i < dim; ++i)
530 dest[i] = apply_transformation(grad_F, D_X[i]);
531
532 return dest;
533 }
534
535
536
537 /**
538 * Similar to the previous apply_transformation(), specialized for the case `dim
539 * == spacedim` where we can return a rank-2 tensor instead of the more general
540 * `DerivativeForm`.
541 * Each row of the result corresponds to one of the rows of @p D_X transformed
542 * by @p grad_F, equivalent to $\mathrm{D\_X} \, \mathrm{grad\_F}^T$ in matrix
543 * notation.
544 *
545 * @relatesalso DerivativeForm
546 */
547 // rank=2
548 template <int dim, typename Number1, typename Number2>
549 inline Tensor<2, dim, typename ProductType<Number1, Number2>::type>
550 apply_transformation(const DerivativeForm<1, dim, dim, Number1> &grad_F,
551 const Tensor<2, dim, Number2> &D_X)
552 {
553 Tensor<2, dim, typename ProductType<Number1, Number2>::type> dest;
554 for (unsigned int i = 0; i < dim; ++i)
555 dest[i] = apply_transformation(grad_F, D_X[i]);
556
557 return dest;
558 }
559
560
561
562 /**
563 * Similar to the previous apply_transformation().
564 * Each row of the result corresponds to one of the rows of @p D_X transformed
565 * by @p grad_F.
566 *
567 * @relatesalso DerivativeForm
568 */
569 template <int spacedim,
570 int dim,
571 int n_components,
572 typename Number1,
573 typename Number2>
574 inline Tensor<1,
575 n_components,
576 Tensor<1, spacedim, typename ProductType<Number1, Number2>::type>>
577 apply_transformation(
578 const DerivativeForm<1, dim, spacedim, Number1> &grad_F,
579 const Tensor<1, n_components, Tensor<1, dim, Number2>> &D_X)
580 {
581 Tensor<1,
582 n_components,
583 Tensor<1, spacedim, typename ProductType<Number1, Number2>::type>>
584 dest;
585 for (unsigned int i = 0; i < n_components; ++i)
586 dest[i] = apply_transformation(grad_F, D_X[i]);
587
588 return dest;
589 }
590
591
592
593 /**
594 * Similar to the previous apply_transformation(). In matrix notation, it
595 * computes $DF2 \, DF1^{T}$. Moreover, the result of this operation $\mathbf A$
596 * can be interpreted as a metric tensor in
597 * ${\mathbb R}^\text{spacedim}$ which corresponds to the Euclidean metric
598 * tensor in
599 * ${\mathbb R}^\text{dim}$. For every pair of vectors
600 * $\mathbf u, \mathbf v \in {\mathbb R}^\text{spacedim}$, we have:
601 * @f[
602 * \mathbf u \cdot \mathbf A \mathbf v =
603 * \text{DF2}^{-1}(\mathbf u) \cdot \text{DF1}^{-1}(\mathbf v)
604 * @f]
605 *
606 * @relatesalso DerivativeForm
607 */
608 template <int spacedim, int dim, typename Number1, typename Number2>
609 inline Tensor<2, spacedim, typename ProductType<Number1, Number2>::type>
610 apply_transformation(const DerivativeForm<1, dim, spacedim, Number1> &DF1,
611 const DerivativeForm<1, dim, spacedim, Number2> &DF2)
612 {
613 Tensor<2, spacedim, typename ProductType<Number1, Number2>::type> dest;
614
615 for (unsigned int i = 0; i < spacedim; ++i)
616 dest[i] = apply_transformation(DF1, DF2[i]);
617
618 return dest;
619 }
620
621
622
623 /**
624 * Transpose of a rectangular DerivativeForm DF, mostly for compatibility
625 * reasons.
626 *
627 * @relatesalso DerivativeForm
628 */
629 template <int dim, int spacedim, typename Number>
630 inline DerivativeForm<1, spacedim, dim, Number>
631 transpose(const DerivativeForm<1, dim, spacedim, Number> &DF)
632 {
633 return DF.transpose();
634 }
635
636
637
638 /**
639 * Specialization of apply_transformation() for a diagonal DerivativeForm.
640 *
641 * @relatesalso DerivativeForm
642 */
643 template <int spacedim, int dim, typename Number1, typename Number2>
644 inline Tensor<1, spacedim, typename ProductType<Number1, Number2>::type>
645 apply_diagonal_transformation(
646 const DerivativeForm<1, dim, spacedim, Number1> &grad_F,
647 const Tensor<1, dim, Number2> &d_x)
648 {
649 Assert(dim == spacedim,
650 ExcMessage("Only dim = spacedim allowed for diagonal transformation"));
651 Tensor<1, spacedim, typename ProductType<Number1, Number2>::type> dest;
652 for (unsigned int i = 0; i < spacedim; ++i)
653 dest[i] = grad_F[i][i] * d_x[i];
654 return dest;
655 }
656
657
658 /**
659 * Similar to the previous apply_diagonal_transformation(), specialized for the
660 * case `dim == spacedim` where we can return a rank-2 tensor instead of the
661 * more general `DerivativeForm`.
662 * Each row of the result corresponds to one of the rows of @p D_X transformed
663 * by @p grad_F, equivalent to $\mathrm{D\_X} \, \mathrm{grad\_F}^T$ in matrix
664 * notation.
665 *
666 * @relatesalso DerivativeForm
667 */
668 template <int dim, typename Number1, typename Number2>
669 inline Tensor<2, dim, typename ProductType<Number1, Number2>::type>
670 apply_diagonal_transformation(
671 const DerivativeForm<1, dim, dim, Number1> &grad_F,
672 const Tensor<2, dim, Number2> &D_X)
673 {
674 Tensor<2, dim, typename ProductType<Number1, Number2>::type> dest;
675 for (unsigned int i = 0; i < dim; ++i)
676 dest[i] = apply_diagonal_transformation(grad_F, D_X[i]);
677
678 return dest;
679 }
680
681
682
683 /**
684 * Similar to the previous apply_diagonal_transformation().
685 * Each row of the result corresponds to one of the rows of @p D_X transformed
686 * by @p grad_F.
687 *
688 * @relatesalso DerivativeForm
689 */
690 template <int spacedim,
691 int dim,
692 int n_components,
693 typename Number1,
694 typename Number2>
695 inline Tensor<1,
696 n_components,
697 Tensor<1, spacedim, typename ProductType<Number1, Number2>::type>>
698 apply_diagonal_transformation(
699 const DerivativeForm<1, dim, spacedim, Number1> &grad_F,
700 const Tensor<1, n_components, Tensor<1, dim, Number2>> &D_X)
701 {
702 Tensor<1,
703 n_components,
704 Tensor<1, spacedim, typename ProductType<Number1, Number2>::type>>
705 dest;
706 for (unsigned int i = 0; i < n_components; ++i)
707 dest[i] = apply_diagonal_transformation(grad_F, D_X[i]);
708
709 return dest;
710 }
711
712
713
714 /**
715 * Similar to the previous apply_transformation().
716 * Each row of the result corresponds to one of the rows of @p D_X transformed
717 * by @p grad_F, equivalent to $\mathrm{D\_X} \, \mathrm{grad\_F}^T$ in matrix
718 * notation.
719 *
720 * @relatesalso DerivativeForm
721 */
722 // rank=2
723 template <int spacedim, int dim, typename Number1, typename Number2>
724 inline DerivativeForm<1,
725 spacedim,
726 dim,
727 typename ProductType<Number1, Number2>::type>
728 apply_diagonal_transformation(
729 const DerivativeForm<1, dim, spacedim, Number1> &grad_F,
730 const Tensor<2, dim, Number2> &D_X)
731 {
732 DerivativeForm<1, spacedim, dim, typename ProductType<Number1, Number2>::type>
733 dest;
734 for (unsigned int i = 0; i < dim; ++i)
735 dest[i] = apply_diagonal_transformation(grad_F, D_X[i]);
736
737 return dest;
738 }
739
740
741 DEAL_II_NAMESPACE_CLOSE
742
743 #endif