Reference documentation for deal.II version 9.2.0
\(\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 
59 template <int order, int dim, int spacedim, typename Number = double>
61 {
62 public:
66  DerivativeForm() = default;
67 
72 
76  Tensor<order, dim, Number> &operator[](const unsigned int i);
77 
81  const Tensor<order, dim, Number> &operator[](const unsigned int i) const;
82 
88 
94 
100  operator Tensor<order + 1, dim, Number>() const;
101 
105  operator Tensor<1, dim, Number>() const;
106 
112  transpose() const;
113 
120  norm() const;
121 
127  Number
128  determinant() const;
129 
140  covariant_form() const;
141 
146  static std::size_t
148 
153  int,
154  << "Invalid DerivativeForm index " << arg1);
155 
156 private:
162  times_T_t(const Tensor<2, dim, Number> &T) const;
163 
164 
169 };
170 
171 
172 /*--------------------------- Inline functions -----------------------------*/
173 
174 #ifndef DOXYGEN
175 
176 template <int order, int dim, int spacedim, typename Number>
179 {
180  Assert((dim == spacedim),
181  ExcMessage("Only allowed for forms with dim==spacedim."));
182  if (dim == spacedim)
183  for (unsigned int j = 0; j < dim; ++j)
184  (*this)[j] = T[j];
185 }
186 
187 
188 
189 template <int order, int dim, int spacedim, typename Number>
193 {
194  Assert((dim == spacedim), ExcMessage("Only allowed when dim==spacedim."));
195 
196  if (dim == spacedim)
197  for (unsigned int j = 0; j < dim; ++j)
198  (*this)[j] = ta[j];
199  return *this;
200 }
201 
202 
203 
204 template <int order, int dim, int spacedim, typename Number>
208 {
209  Assert((1 == spacedim) && (order == 1),
210  ExcMessage("Only allowed for spacedim==1 and order==1."));
211 
212  (*this)[0] = T;
213 
214  return *this;
215 }
216 
217 
218 
219 template <int order, int dim, int spacedim, typename Number>
222 {
223  AssertIndexRange(i, spacedim);
224 
225  return tensor[i];
226 }
227 
228 
229 
230 template <int order, int dim, int spacedim, typename Number>
231 inline const Tensor<order, dim, Number> &
233  operator[](const unsigned int i) const
234 {
235  AssertIndexRange(i, spacedim);
236 
237  return tensor[i];
238 }
239 
240 
241 
242 template <int order, int dim, int spacedim, typename Number>
244 operator Tensor<1, dim, Number>() const
245 {
246  Assert((1 == spacedim) && (order == 1),
247  ExcMessage("Only allowed for spacedim==1."));
248 
249  return (*this)[0];
250 }
251 
252 
253 
254 template <int order, int dim, int spacedim, typename Number>
256 operator Tensor<order + 1, dim, Number>() const
257 {
258  Assert((dim == spacedim), ExcMessage("Only allowed when dim==spacedim."));
259 
261 
262  if (dim == spacedim)
263  for (unsigned int j = 0; j < dim; ++j)
264  t[j] = (*this)[j];
265 
266  return t;
267 }
268 
269 
270 
271 template <int order, int dim, int spacedim, typename Number>
274 {
275  Assert(order == 1, ExcMessage("Only for rectangular DerivativeForm."));
277 
278  for (unsigned int i = 0; i < spacedim; ++i)
279  for (unsigned int j = 0; j < dim; ++j)
280  tt[j][i] = (*this)[i][j];
281 
282  return tt;
283 }
284 
285 
286 
287 template <int order, int dim, int spacedim, typename Number>
290  const Tensor<2, dim, Number> &T) const
291 {
292  Assert(order == 1, ExcMessage("Only for order == 1."));
294  for (unsigned int i = 0; i < spacedim; ++i)
295  for (unsigned int j = 0; j < dim; ++j)
296  dest[i][j] = (*this)[i] * T[j];
297 
298  return dest;
299 }
300 
301 
302 
303 template <int order, int dim, int spacedim, typename Number>
306 {
307  typename numbers::NumberTraits<Number>::real_type sum_of_squares = 0;
308  for (unsigned int i = 0; i < spacedim; ++i)
309  sum_of_squares += tensor[i].norm_square();
310  return std::sqrt(sum_of_squares);
311 }
312 
313 
314 
315 template <int order, int dim, int spacedim, typename Number>
316 inline Number
318 {
319  Assert(order == 1, ExcMessage("Only for order == 1."));
320  if (dim == spacedim)
321  {
322  const Tensor<2, dim, Number> T =
323  static_cast<Tensor<2, dim, Number>>(*this);
325  }
326  else
327  {
328  Assert(spacedim > dim, ExcMessage("Only for spacedim>dim."));
330  Tensor<2, dim, Number> G; // First fundamental form
331  for (unsigned int i = 0; i < dim; ++i)
332  for (unsigned int j = 0; j < dim; ++j)
333  G[i][j] = DF_t[i] * DF_t[j];
334 
335  return (std::sqrt(::determinant(G)));
336  }
337 }
338 
339 
340 
341 template <int order, int dim, int spacedim, typename Number>
344 {
345  if (dim == spacedim)
346  {
347  const Tensor<2, dim, Number> DF_t =
348  ::transpose(invert(static_cast<Tensor<2, dim, Number>>(*this)));
350  }
351  else
352  {
354  Tensor<2, dim, Number> G; // First fundamental form
355  for (unsigned int i = 0; i < dim; ++i)
356  for (unsigned int j = 0; j < dim; ++j)
357  G[i][j] = DF_t[i] * DF_t[j];
358 
359  return (this->times_T_t(invert(G)));
360  }
361 }
362 
363 
364 template <int order, int dim, int spacedim, typename Number>
365 inline std::size_t
367 {
369 }
370 
371 #endif // DOXYGEN
372 
373 
374 
397 template <int spacedim, int dim, typename Number>
400  const Tensor<1, dim, Number> & d_x)
401 {
403  for (unsigned int i = 0; i < spacedim; ++i)
404  dest[i] = grad_F[i] * d_x;
405  return dest;
406 }
407 
408 
409 
418 // rank=2
419 template <int spacedim, int dim, typename Number>
422  const Tensor<2, dim, Number> & D_X)
423 {
425  for (unsigned int i = 0; i < dim; ++i)
426  dest[i] = apply_transformation(grad_F, D_X[i]);
427 
428  return dest;
429 }
430 
447 template <int spacedim, int dim, typename Number>
451 {
453 
454  for (unsigned int i = 0; i < spacedim; ++i)
455  dest[i] = apply_transformation(DF1, DF2[i]);
456 
457  return dest;
458 }
459 
460 
468 template <int dim, int spacedim, typename Number>
471 {
473  tt = DF.transpose();
474  return tt;
475 }
476 
477 
479 
480 #endif
constexpr Number determinant(const SymmetricTensor< 2, dim, Number > &)
#define AssertIndexRange(index, range)
Definition: exceptions.h:1649
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:518
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:1419
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:359
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:450
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:358
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)