Reference documentation for deal.II version 9.1.0-pre
derivative_form.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2013 - 2018 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/tensor.h>
20 
21 DEAL_II_NAMESPACE_OPEN
22 
55 template <int order, int dim, int spacedim, typename Number = double>
57 {
58 public:
63 
68 
72  Tensor<order, dim, Number> &operator[](const unsigned int i);
73 
77  const Tensor<order, dim, Number> &operator[](const unsigned int i) const;
78 
84 
90 
96  operator Tensor<order + 1, dim, Number>() const;
97 
101  operator Tensor<1, dim, Number>() const;
102 
108  transpose() const;
109 
115  norm() const;
116 
122  Number
123  determinant() const;
124 
134  covariant_form() const;
135 
140  static std::size_t
142 
147  int,
148  << "Invalid DerivativeForm index " << arg1);
149 
150 private:
155  times_T_t(const Tensor<2, dim, Number> &T) const;
156 
157 
162 };
163 
164 
165 /*--------------------------- Inline functions -----------------------------*/
166 
167 #ifndef DOXYGEN
168 
169 
170 
171 template <int order, int dim, int spacedim, typename Number>
173 {
174  // default constructor. not specifying an initializer list calls
175  // the default constructor of the subobjects, which initialize them
176  // selves. therefore, the tensor array is set to zero this way
177 }
178 
179 
180 
181 template <int order, int dim, int spacedim, typename Number>
184 {
185  Assert((dim == spacedim),
186  ExcMessage("Only allowed for forms with dim==spacedim."));
187  if (dim == spacedim)
188  for (unsigned int j = 0; j < dim; ++j)
189  (*this)[j] = T[j];
190 }
191 
192 
193 
194 template <int order, int dim, int spacedim, typename Number>
198 {
199  Assert((dim == spacedim), ExcMessage("Only allowed when dim==spacedim."));
200 
201  if (dim == spacedim)
202  for (unsigned int j = 0; j < dim; ++j)
203  (*this)[j] = ta[j];
204  return *this;
205 }
206 
207 
208 
209 template <int order, int dim, int spacedim, typename Number>
213 {
214  Assert((1 == spacedim) && (order == 1),
215  ExcMessage("Only allowed for spacedim==1 and order==1."));
216 
217  (*this)[0] = T;
218 
219  return *this;
220 }
221 
222 
223 
224 template <int order, int dim, int spacedim, typename Number>
227 {
228  Assert(i < spacedim, ExcIndexRange(i, 0, spacedim));
229 
230  return tensor[i];
231 }
232 
233 
234 
235 template <int order, int dim, int spacedim, typename Number>
236 inline const Tensor<order, dim, Number> &
238  operator[](const unsigned int i) const
239 {
240  Assert(i < spacedim, ExcIndexRange(i, 0, spacedim));
241 
242  return tensor[i];
243 }
244 
245 
246 
247 template <int order, int dim, int spacedim, typename Number>
249 operator Tensor<1, dim, Number>() const
250 {
251  Assert((1 == spacedim) && (order == 1),
252  ExcMessage("Only allowed for spacedim==1."));
253 
254  return (*this)[0];
255 }
256 
257 
258 
259 template <int order, int dim, int spacedim, typename Number>
261 operator Tensor<order + 1, dim, Number>() const
262 {
263  Assert((dim == spacedim), ExcMessage("Only allowed when dim==spacedim."));
264 
266 
267  if (dim == spacedim)
268  for (unsigned int j = 0; j < dim; ++j)
269  t[j] = (*this)[j];
270 
271  return t;
272 }
273 
274 
275 
276 template <int order, int dim, int spacedim, typename Number>
279 {
280  Assert(order == 1, ExcMessage("Only for rectangular DerivativeForm."));
282 
283  for (unsigned int i = 0; i < spacedim; ++i)
284  for (unsigned int j = 0; j < dim; ++j)
285  tt[j][i] = (*this)[i][j];
286 
287  return tt;
288 }
289 
290 
291 
292 template <int order, int dim, int spacedim, typename Number>
295  const Tensor<2, dim, Number> &T) const
296 {
297  Assert(order == 1, ExcMessage("Only for order == 1."));
299  for (unsigned int i = 0; i < spacedim; ++i)
300  for (unsigned int j = 0; j < dim; ++j)
301  dest[i][j] = (*this)[i] * T[j];
302 
303  return dest;
304 }
305 
306 
307 
308 template <int order, int dim, int spacedim, typename Number>
311 {
312  typename numbers::NumberTraits<Number>::real_type sum_of_squares = 0;
313  for (unsigned int i = 0; i < spacedim; ++i)
314  sum_of_squares += tensor[i].norm_square();
315  return std::sqrt(sum_of_squares);
316 }
317 
318 
319 
320 template <int order, int dim, int spacedim, typename Number>
321 inline Number
323 {
324  Assert(order == 1, ExcMessage("Only for order == 1."));
325  if (dim == spacedim)
326  {
327  const Tensor<2, dim, Number> T =
328  static_cast<Tensor<2, dim, Number>>(*this);
330  }
331  else
332  {
333  Assert(spacedim > dim, ExcMessage("Only for spacedim>dim."));
335  Tensor<2, dim, Number> G; // First fundamental form
336  for (unsigned int i = 0; i < dim; ++i)
337  for (unsigned int j = 0; j < dim; ++j)
338  G[i][j] = DF_t[i] * DF_t[j];
339 
340  return (sqrt(::determinant(G)));
341  }
342 }
343 
344 
345 
346 template <int order, int dim, int spacedim, typename Number>
349 {
350  if (dim == spacedim)
351  {
352  const Tensor<2, dim, Number> DF_t =
353  ::transpose(invert(static_cast<Tensor<2, dim, Number>>(*this)));
355  }
356  else
357  {
358  const DerivativeForm<1, spacedim, dim> DF_t = this->transpose();
359  Tensor<2, dim, Number> G; // First fundamental form
360  for (unsigned int i = 0; i < dim; ++i)
361  for (unsigned int j = 0; j < dim; ++j)
362  G[i][j] = DF_t[i] * DF_t[j];
363 
364  return (this->times_T_t(invert(G)));
365  }
366 }
367 
368 
369 template <int order, int dim, int spacedim, typename Number>
370 inline std::size_t
372 {
374 }
375 
376 #endif // DOXYGEN
377 
378 
379 
388 template <int spacedim, int dim, typename Number>
391  const Tensor<1, dim, Number> & T)
392 {
394  for (unsigned int i = 0; i < spacedim; ++i)
395  dest[i] = DF[i] * T;
396  return dest;
397 }
398 
399 
400 
407 // rank=2
408 template <int spacedim, int dim, typename Number>
411  const Tensor<2, dim, Number> & T)
412 {
414  for (unsigned int i = 0; i < dim; ++i)
415  dest[i] = apply_transformation(DF, T[i]);
416 
417  return dest;
418 }
419 
426 template <int spacedim, int dim, typename Number>
430 {
432 
433  for (unsigned int i = 0; i < spacedim; ++i)
434  dest[i] = apply_transformation(DF1, DF2[i]);
435 
436  return dest;
437 }
438 
439 
447 template <int dim, int spacedim, typename Number>
450 {
452  tt = DF.transpose();
453  return tt;
454 }
455 
456 
457 DEAL_II_NAMESPACE_CLOSE
458 
459 #endif
DerivativeForm< 1, spacedim, dim > apply_transformation(const DerivativeForm< 1, dim, spacedim, Number > &DF, const Tensor< 2, dim, Number > &T)
Number determinant(const SymmetricTensor< 2, dim, Number > &)
DerivativeForm< 1, dim, spacedim, Number > times_T_t(const Tensor< 2, dim, Number > &T) const
Number determinant() const
DerivativeForm & operator=(const Tensor< order+1, dim, Number > &)
static::ExceptionBase & ExcIndexRange(int arg1, int arg2, int arg3)
SymmetricTensor< 2, dim, Number > invert(const SymmetricTensor< 2, dim, Number > &)
Tensor< order, dim, Number > tensor[spacedim]
static::ExceptionBase & ExcMessage(std::string arg1)
Tensor< 1, spacedim, Number > apply_transformation(const DerivativeForm< 1, dim, spacedim, Number > &DF, const Tensor< 1, dim, Number > &T)
#define DeclException1(Exception1, type1, outsequence)
Definition: exceptions.h:408
#define Assert(cond, exc)
Definition: exceptions.h:1227
Tensor< 2, spacedim, Number > apply_transformation(const DerivativeForm< 1, dim, spacedim, Number > &DF1, const DerivativeForm< 1, dim, spacedim, Number > &DF2)
static std::size_t memory_consumption()
numbers::NumberTraits< Number >::real_type norm() const
DerivativeForm< 1, spacedim, dim, Number > transpose() const
Definition: mpi.h:55
DerivativeForm< 1, dim, spacedim, Number > covariant_form() const
static::ExceptionBase & ExcInvalidTensorIndex(int arg1)
DerivativeForm< 1, spacedim, dim, Number > transpose(const DerivativeForm< 1, dim, spacedim, Number > &DF)
Tensor< order, dim, Number > & operator[](const unsigned int i)