Reference documentation for deal.II version Git 78a8940608 2021-04-17 09:24:19 -0400
\(\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 
57 template <int order, int dim, int spacedim, typename Number = double>
59 {
60 public:
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 
109  operator Tensor<order + 1, dim, Number>() const;
110 
114  operator Tensor<1, dim, Number>() const;
115 
121  transpose() const;
122 
129  norm() const;
130 
136  Number
137  determinant() const;
138 
149  covariant_form() const;
150 
155  static std::size_t
157 
162  int,
163  << "Invalid DerivativeForm index " << arg1);
164 
165 private:
171  times_T_t(const Tensor<2, dim, Number> &T) const;
172 
173 
178 };
179 
180 
181 /*--------------------------- Inline functions -----------------------------*/
182 
183 #ifndef DOXYGEN
184 
185 template <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 
198 template <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 
208 template <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 
223 template <int order, int dim, int spacedim, typename Number>
226 operator=(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 
235 template <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 
250 template <int order, int dim, int spacedim, typename Number>
253 {
254  AssertIndexRange(i, spacedim);
255 
256  return tensor[i];
257 }
258 
259 
260 
261 template <int order, int dim, int spacedim, typename Number>
262 inline 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 
273 template <int order, int dim, int spacedim, typename Number>
275 operator 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 
285 template <int order, int dim, int spacedim, typename Number>
287 operator 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 
302 template <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 
318 template <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 
334 template <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 
346 template <int order, int dim, int spacedim, typename Number>
347 inline Number
349 {
350  Assert(order == 1, ExcMessage("Only for order == 1."));
351  if (dim == spacedim)
352  {
353  const Tensor<2, dim, Number> T =
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 
372 template <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 
395 template <int order, int dim, int spacedim, typename Number>
396 inline std::size_t
398 {
400 }
401 
402 #endif // DOXYGEN
403 
404 
405 
427 template <int spacedim, int dim, typename Number>
430  const Tensor<1, dim, Number> & 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
449 template <int spacedim, int dim, typename Number>
452  const Tensor<2, dim, Number> & D_X)
453 {
455  for (unsigned int i = 0; i < dim; ++i)
456  dest[i] = apply_transformation(grad_F, D_X[i]);
457 
458  return dest;
459 }
460 
461 
462 
470 template <int spacedim, int dim, int n_components, typename Number>
473  const Tensor<1, n_components, Tensor<1, dim, Number>> &D_X)
474 {
476  for (unsigned int i = 0; i < n_components; ++i)
477  dest[i] = apply_transformation(grad_F, D_X[i]);
478 
479  return dest;
480 }
481 
482 
483 
499 template <int spacedim, int dim, typename Number>
503 {
505 
506  for (unsigned int i = 0; i < spacedim; ++i)
507  dest[i] = apply_transformation(DF1, DF2[i]);
508 
509  return dest;
510 }
511 
512 
513 
520 template <int dim, int spacedim, typename Number>
523 {
525  tt = DF.transpose();
526  return tt;
527 }
528 
529 
531 
532 #endif
constexpr Number determinant(const SymmetricTensor< 2, dim, Number > &)
#define AssertIndexRange(index, range)
Definition: exceptions.h:1691
DerivativeForm & operator=(const Tensor< order+1, dim, Number > &)
Number determinant() const
Tensor< order, dim, Number > tensor[spacedim]
static ::ExceptionBase & ExcMessage(std::string arg1)
#define DeclException1(Exception1, type1, outsequence)
Definition: exceptions.h:515
static const char T
DerivativeForm< 1, dim, spacedim, Number > times_T_t(const Tensor< 2, dim, Number > &T) const
#define Assert(cond, exc)
Definition: exceptions.h:1466
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:396
DerivativeForm()=default
DerivativeForm< 1, spacedim, dim, Number > transpose() const
static std::size_t memory_consumption()
numbers::NumberTraits< Number >::real_type norm() const
Tensor< 1, spacedim, Number > apply_transformation(const DerivativeForm< 1, dim, spacedim, Number > &grad_F, const Tensor< 1, dim, Number > &d_x)
DerivativeForm< 1, dim, spacedim, Number > covariant_form() const
Definition: tensor.h:449
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:395
static ::ExceptionBase & ExcInvalidTensorIndex(int arg1)
constexpr SymmetricTensor< 2, dim, Number > invert(const SymmetricTensor< 2, dim, Number > &)
Tensor< order, dim, Number > & operator[](const unsigned int i)