Reference documentation for deal.II version 9.3.3
\(\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\}}\)
derivative_form.h
Go to the documentation of this file.
1// ---------------------------------------------------------------------
2//
3// Copyright (C) 2013 - 2020 by the deal.II authors
4//
5// This file is part of the deal.II library.
6//
7// The deal.II library is free software; you can use it, redistribute
8// it, and/or modify it under the terms of the GNU Lesser General
9// Public License as published by the Free Software Foundation; either
10// version 2.1 of the License, or (at your option) any later version.
11// The full text of the license can be found in the file LICENSE.md at
12// the top level directory of deal.II.
13//
14// ---------------------------------------------------------------------
15
16#ifndef dealii_derivative_form_h
17#define dealii_derivative_form_h
18
19#include <deal.II/base/config.h>
20
21#include <deal.II/base/tensor.h>
22
24
57template <int order, int dim, int spacedim, typename Number = double>
59{
60public:
64 DerivativeForm() = default;
65
70
74 DerivativeForm(const Tensor<order, spacedim, Tensor<1, dim, Number>> &);
75
79 Tensor<order, dim, Number> &operator[](const unsigned int i);
80
84 const Tensor<order, dim, Number> &operator[](const unsigned int i) const;
85
91
96 operator=(const Tensor<order, spacedim, Tensor<1, dim, Number>> &);
97
103
110
114 operator Tensor<1, dim, Number>() const;
115
121 transpose() const;
122
129 norm() const;
130
136 Number
137 determinant() const;
138
150
155 static std::size_t
157
162 int,
163 << "Invalid DerivativeForm index " << arg1);
164
165private:
172
173
178};
179
180
181/*--------------------------- Inline functions -----------------------------*/
182
183#ifndef DOXYGEN
184
185template <int order, int dim, int spacedim, typename Number>
188{
189 Assert((dim == spacedim),
190 ExcMessage("Only allowed for forms with dim==spacedim."));
191 if (dim == spacedim)
192 for (unsigned int j = 0; j < dim; ++j)
193 (*this)[j] = T[j];
194}
195
196
197
198template <int order, int dim, int spacedim, typename Number>
200 const Tensor<order, spacedim, Tensor<1, dim, Number>> &T)
201{
202 for (unsigned int j = 0; j < spacedim; ++j)
203 (*this)[j] = T[j];
204}
205
206
207
208template <int order, int dim, int spacedim, typename Number>
212{
213 Assert((dim == spacedim), ExcMessage("Only allowed when dim==spacedim."));
214
215 if (dim == spacedim)
216 for (unsigned int j = 0; j < dim; ++j)
217 (*this)[j] = ta[j];
218 return *this;
219}
220
221
222
223template <int order, int dim, int spacedim, typename Number>
226operator=(const Tensor<order, spacedim, Tensor<1, dim, Number>> &T)
227{
228 for (unsigned int j = 0; j < spacedim; ++j)
229 (*this)[j] = T[j];
230 return *this;
231}
232
233
234
235template <int order, int dim, int spacedim, typename Number>
239{
240 Assert((1 == spacedim) && (order == 1),
241 ExcMessage("Only allowed for spacedim==1 and order==1."));
242
243 (*this)[0] = T;
244
245 return *this;
246}
247
248
249
250template <int order, int dim, int spacedim, typename Number>
253{
254 AssertIndexRange(i, spacedim);
255
256 return tensor[i];
257}
258
259
260
261template <int order, int dim, int spacedim, typename Number>
262inline const Tensor<order, dim, Number> &
264 operator[](const unsigned int i) const
265{
266 AssertIndexRange(i, spacedim);
267
268 return tensor[i];
269}
270
271
272
273template <int order, int dim, int spacedim, typename Number>
275operator Tensor<1, dim, Number>() const
276{
277 Assert((1 == spacedim) && (order == 1),
278 ExcMessage("Only allowed for spacedim==1."));
279
280 return (*this)[0];
281}
282
283
284
285template <int order, int dim, int spacedim, typename Number>
287operator Tensor<order + 1, dim, Number>() const
288{
289 Assert((dim == spacedim), ExcMessage("Only allowed when dim==spacedim."));
290
292
293 if (dim == spacedim)
294 for (unsigned int j = 0; j < dim; ++j)
295 t[j] = (*this)[j];
296
297 return t;
298}
299
300
301
302template <int order, int dim, int spacedim, typename Number>
305{
306 Assert(order == 1, ExcMessage("Only for rectangular DerivativeForm."));
308
309 for (unsigned int i = 0; i < spacedim; ++i)
310 for (unsigned int j = 0; j < dim; ++j)
311 tt[j][i] = (*this)[i][j];
312
313 return tt;
314}
315
316
317
318template <int order, int dim, int spacedim, typename Number>
321 const Tensor<2, dim, Number> &T) const
322{
323 Assert(order == 1, ExcMessage("Only for order == 1."));
325 for (unsigned int i = 0; i < spacedim; ++i)
326 for (unsigned int j = 0; j < dim; ++j)
327 dest[i][j] = (*this)[i] * T[j];
328
329 return dest;
330}
331
332
333
334template <int order, int dim, int spacedim, typename Number>
337{
338 typename numbers::NumberTraits<Number>::real_type sum_of_squares = 0;
339 for (unsigned int i = 0; i < spacedim; ++i)
340 sum_of_squares += tensor[i].norm_square();
341 return std::sqrt(sum_of_squares);
342}
343
344
345
346template <int order, int dim, int spacedim, typename Number>
347inline Number
349{
350 Assert(order == 1, ExcMessage("Only for order == 1."));
351 if (dim == spacedim)
352 {
354 static_cast<Tensor<2, dim, Number>>(*this);
356 }
357 else
358 {
359 Assert(spacedim > dim, ExcMessage("Only for spacedim>dim."));
361 Tensor<2, dim, Number> G; // First fundamental form
362 for (unsigned int i = 0; i < dim; ++i)
363 for (unsigned int j = 0; j < dim; ++j)
364 G[i][j] = DF_t[i] * DF_t[j];
365
366 return (std::sqrt(::determinant(G)));
367 }
368}
369
370
371
372template <int order, int dim, int spacedim, typename Number>
375{
376 if (dim == spacedim)
377 {
378 const Tensor<2, dim, Number> DF_t =
379 ::transpose(invert(static_cast<Tensor<2, dim, Number>>(*this)));
381 }
382 else
383 {
385 Tensor<2, dim, Number> G; // First fundamental form
386 for (unsigned int i = 0; i < dim; ++i)
387 for (unsigned int j = 0; j < dim; ++j)
388 G[i][j] = DF_t[i] * DF_t[j];
389
390 return (this->times_T_t(invert(G)));
391 }
392}
393
394
395template <int order, int dim, int spacedim, typename Number>
396inline std::size_t
398{
400}
401
402#endif // DOXYGEN
403
404
405
427template <int spacedim, int dim, typename Number1, typename Number2>
430 const Tensor<1, dim, Number2> & d_x)
431{
433 for (unsigned int i = 0; i < spacedim; ++i)
434 dest[i] = grad_F[i] * d_x;
435 return dest;
436}
437
438
439
448// rank=2
449template <int spacedim, int dim, typename Number1, typename Number2>
450inline DerivativeForm<1,
451 spacedim,
452 dim,
455 const Tensor<2, dim, Number2> & D_X)
456{
458 dest;
459 for (unsigned int i = 0; i < dim; ++i)
460 dest[i] = apply_transformation(grad_F, D_X[i]);
461
462 return dest;
463}
464
465
466
474template <int spacedim,
475 int dim,
476 int n_components,
477 typename Number1,
478 typename Number2>
479inline Tensor<1,
480 n_components,
484 const Tensor<1, n_components, Tensor<1, dim, Number2>> &D_X)
485{
486 Tensor<1,
487 n_components,
489 dest;
490 for (unsigned int i = 0; i < n_components; ++i)
491 dest[i] = apply_transformation(grad_F, D_X[i]);
492
493 return dest;
494}
495
496
497
513template <int spacedim, int dim, typename Number1, typename Number2>
517{
519
520 for (unsigned int i = 0; i < spacedim; ++i)
521 dest[i] = apply_transformation(DF1, DF2[i]);
522
523 return dest;
524}
525
526
527
534template <int dim, int spacedim, typename Number>
537{
539 tt = DF.transpose();
540 return tt;
541}
542
543
545
546#endif
static std::size_t memory_consumption()
DerivativeForm & operator=(const Tensor< order, spacedim, Tensor< 1, dim, Number > > &)
Tensor< order, dim, Number > tensor[spacedim]
Number determinant() const
Tensor< 1, n_components, Tensor< 1, spacedim, typename ProductType< Number1, Number2 >::type > > apply_transformation(const DerivativeForm< 1, dim, spacedim, Number1 > &grad_F, const Tensor< 1, n_components, Tensor< 1, dim, Number2 > > &D_X)
DerivativeForm< 1, dim, spacedim, Number > covariant_form() const
DerivativeForm< 1, spacedim, dim, Number > transpose(const DerivativeForm< 1, dim, spacedim, Number > &DF)
DerivativeForm< 1, spacedim, dim, typename ProductType< Number1, Number2 >::type > apply_transformation(const DerivativeForm< 1, dim, spacedim, Number1 > &grad_F, const Tensor< 2, dim, Number2 > &D_X)
DerivativeForm< 1, spacedim, dim, Number > transpose() const
DerivativeForm()=default
Tensor< 1, spacedim, typename ProductType< Number1, Number2 >::type > apply_transformation(const DerivativeForm< 1, dim, spacedim, Number1 > &grad_F, const Tensor< 1, dim, Number2 > &d_x)
const Tensor< order, dim, Number > & operator[](const unsigned int i) const
DerivativeForm< 1, dim, spacedim, Number > times_T_t(const Tensor< 2, dim, Number > &T) const
Tensor< 2, spacedim, typename ProductType< Number1, Number2 >::type > apply_transformation(const DerivativeForm< 1, dim, spacedim, Number1 > &DF1, const DerivativeForm< 1, dim, spacedim, Number2 > &DF2)
DerivativeForm & operator=(const Tensor< order+1, dim, Number > &)
numbers::NumberTraits< Number >::real_type norm() const
DerivativeForm & operator=(const Tensor< 1, dim, Number > &)
DerivativeForm(const Tensor< order, spacedim, Tensor< 1, dim, Number > > &)
DerivativeForm(const Tensor< order+1, dim, Number > &)
Tensor< order, dim, Number > & operator[](const unsigned int i)
constexpr SymmetricTensor< 2, dim, Number > invert(const SymmetricTensor< 2, dim, Number > &t)
constexpr Number determinant(const SymmetricTensor< 2, dim, Number > &t)
Definition: tensor.h:472
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:402
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:403
static ::ExceptionBase & ExcInvalidTensorIndex(int arg1)
#define Assert(cond, exc)
Definition: exceptions.h:1465
#define AssertIndexRange(index, range)
Definition: exceptions.h:1690
#define DeclException1(Exception1, type1, outsequence)
Definition: exceptions.h:515
static ::ExceptionBase & ExcMessage(std::string arg1)
static const char T
::VectorizedArray< Number, width > sqrt(const ::VectorizedArray< Number, width > &)
typename internal::ProductTypeImpl< typename std::decay< T >::type, typename std::decay< U >::type >::type type
constexpr Number determinant(const SymmetricTensor< 2, dim, Number > &)