Reference documentation for deal.II version 8.5.1
derivative_form.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2013 - 2017 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 at
12 // the top level of the deal.II distribution.
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:
62  DerivativeForm ();
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 
83 
88 
94  operator Tensor<order+1,dim,Number>() const;
95 
99  operator Tensor<1,dim,Number>() const;
100 
106 
112  norm () const;
113 
119  double determinant () const;
120 
130 
135  static std::size_t memory_consumption ();
136 
141  int,
142  << "Invalid DerivativeForm index " << arg1);
143 
144 private:
149 
150 
155 };
156 
157 
158 /*--------------------------- Inline functions -----------------------------*/
159 
160 #ifndef DOXYGEN
161 
162 
163 
164 
165 template <int order, int dim, int spacedim, typename Number>
166 inline
168 {
169 // default constructor. not specifying an initializer list calls
170 // the default constructor of the subobjects, which initialize them
171 // selves. therefore, the tensor array is set to zero this way
172 }
173 
174 
175 
176 template <int order, int dim, int spacedim, typename Number>
177 inline
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 
190 template <int order, int dim, int spacedim, typename Number>
191 inline
194 {
195  Assert( (dim == spacedim),
196  ExcMessage("Only allowed when dim==spacedim."));
197 
198  if (dim == spacedim)
199  for (unsigned int j=0; j<dim; ++j)
200  (*this)[j] = ta[j];
201  return *this;
202 
203 }
204 
205 
206 
207 template <int order, int dim, int spacedim, typename Number>
208 inline
211 {
212  Assert( (1 == spacedim) && (order==1),
213  ExcMessage("Only allowed for spacedim==1 and order==1."));
214 
215  (*this)[0] = T;
216 
217  return *this;
218 
219 }
220 
221 
222 
223 template <int order, int dim, int spacedim, typename Number>
224 inline
226 operator[] (const unsigned int i)
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
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>
248 inline
250 {
251  Assert( (1 == spacedim) && (order==1),
252  ExcMessage("Only allowed for spacedim==1."));
253 
254  return (*this)[0];
255 
256 }
257 
258 
259 
260 template <int order, int dim, int spacedim, typename Number>
261 inline
263 {
264  Assert( (dim == spacedim),
265  ExcMessage("Only allowed when dim==spacedim."));
266 
268 
269  if (dim == spacedim)
270  for (unsigned int j=0; j<dim; ++j)
271  t[j] = (*this)[j];
272 
273  return t;
274 
275 }
276 
277 
278 
279 template <int order, int dim, int spacedim, typename Number>
280 inline
283 transpose () const
284 {
285  Assert(order==1, ExcMessage("Only for rectangular DerivativeForm."));
287 
288  for (unsigned int i=0; i<spacedim; ++i)
289  for (unsigned int j=0; j<dim; ++j)
290  tt[j][i] = (*this)[i][j];
291 
292  return tt;
293 }
294 
295 
296 
297 template <int order, int dim, int spacedim, typename Number>
298 inline
301 {
302  Assert( order==1, ExcMessage("Only for order == 1."));
304  for (unsigned int i=0; i<spacedim; ++i)
305  for (unsigned int j=0; j<dim; ++j)
306  dest[i][j] = (*this)[i] * T[j];
307 
308  return dest;
309 }
310 
311 
312 
313 template <int order, int dim, int spacedim, typename Number>
314 inline
317 {
318  typename numbers::NumberTraits<Number>::real_type sum_of_squares = 0;
319  for (unsigned int i=0; i<spacedim; ++i)
320  sum_of_squares += tensor[i].norm_square();
321  return std::sqrt(sum_of_squares);
322 }
323 
324 
325 
326 template <int order, int dim, int spacedim, typename Number>
327 inline
328 double
330 {
331  Assert( order==1, ExcMessage("Only for order == 1."));
332  if (dim == spacedim)
333  {
334  const Tensor<2,dim,Number> T = static_cast<Tensor<2,dim,Number> >(*this);
335  return ::determinant(T);
336  }
337  else
338  {
339  Assert( spacedim>dim, ExcMessage("Only for spacedim>dim."));
340  const DerivativeForm<1,spacedim,dim> DF_t = this->transpose();
341  Tensor<2,dim,Number> G; //First fundamental form
342  for (unsigned int i=0; i<dim; ++i)
343  for (unsigned int j=0; j<dim; ++j)
344  G[i][j] = DF_t[i] * DF_t[j];
345 
346  return ( sqrt(::determinant(G)) );
347  }
348 }
349 
350 
351 
352 template <int order, int dim, int spacedim, typename Number>
353 inline
356 {
357  if (dim == spacedim)
358  {
359  const Tensor<2,dim,Number> DF_t
360  = ::transpose (invert (static_cast<Tensor<2,dim,Number> >(*this)));
361  return DerivativeForm<1,dim, spacedim> (DF_t);
362  }
363  else
364  {
365  const DerivativeForm<1,spacedim,dim> DF_t = this->transpose();
366  Tensor<2,dim,Number> G; //First fundamental form
367  for (unsigned int i=0; i<dim; ++i)
368  for (unsigned int j=0; j<dim; ++j)
369  G[i][j] = DF_t[i] * DF_t[j];
370 
371  return (this->times_T_t(invert(G)));
372  }
373 }
374 
375 
376 template <int order, int dim, int spacedim, typename Number>
377 inline
378 std::size_t
380 {
382 }
383 
384 #endif // DOXYGEN
385 
386 
387 
388 
389 
398 template <int spacedim, int dim, typename Number>
399 inline
402  const Tensor<1,dim,Number> &T)
403 {
405  for (unsigned int i=0; i<spacedim; ++i)
406  dest[i] = DF[i] * T;
407  return dest;
408 }
409 
410 
411 
418 //rank=2
419 template <int spacedim, int dim, typename Number>
420 inline
423  const Tensor<2,dim,Number> &T)
424 {
425 
427  for (unsigned int i=0; i<dim; ++i)
428  dest[i] = apply_transformation(DF, T[i]);
429 
430  return dest;
431 }
432 
439 template <int spacedim, int dim, typename Number>
440 inline
444 {
446 
447  for (unsigned int i=0; i<spacedim; ++i)
448  dest[i] = apply_transformation(DF1, DF2[i]);
449 
450  return dest;
451 }
452 
453 
461 template <int dim, int spacedim, typename Number>
462 inline
465 {
467  tt = DF.transpose();
468  return tt;
469 }
470 
471 
472 DEAL_II_NAMESPACE_CLOSE
473 
474 #endif
DerivativeForm< 1, spacedim, dim > apply_transformation(const DerivativeForm< 1, dim, spacedim, Number > &DF, const Tensor< 2, dim, Number > &T)
DerivativeForm & operator=(const Tensor< order+1, dim, Number > &)
static ::ExceptionBase & ExcIndexRange(int arg1, int arg2, int arg3)
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:564
DerivativeForm< 1, dim, spacedim, Number > times_T_t(const Tensor< 2, dim, Number > &T) const
#define Assert(cond, exc)
Definition: exceptions.h:313
Tensor< 2, spacedim, Number > apply_transformation(const DerivativeForm< 1, dim, spacedim, Number > &DF1, const DerivativeForm< 1, dim, spacedim, Number > &DF2)
DerivativeForm< 1, spacedim, dim, Number > transpose() const
static std::size_t memory_consumption()
numbers::NumberTraits< Number >::real_type norm() const
double determinant() const
Number determinant(const SymmetricTensor< 2, dim, Number > &t)
VectorizedArray< Number > sqrt(const ::VectorizedArray< Number > &x)
DerivativeForm< 1, dim, spacedim, Number > covariant_form() const
Definition: mpi.h:41
Tensor< order, dim, Number > & operator[](const unsigned int i)
static ::ExceptionBase & ExcInvalidTensorIndex(int arg1)
SymmetricTensor< 2, dim, Number > invert(const SymmetricTensor< 2, dim, Number > &)
DerivativeForm< 1, spacedim, dim, Number > transpose(const DerivativeForm< 1, dim, spacedim, Number > &DF)
Tensor< order, dim, Number > tensor[spacedim]