Reference documentation for deal.II version 8.4.2
derivative_form.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2013 - 2016 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 
84 
89 
94 
100  operator Tensor<order+1,dim,Number>() const;
101 
105  operator Tensor<1,dim,Number>() const;
106 
112 
113 
119  double determinant () const;
120 
121 
128 
129 
130 
131 
136  static std::size_t memory_consumption ();
137 
141  DeclException1 (ExcInvalidTensorIndex,
142  int,
143  << "Invalid DerivativeForm index " << arg1);
144 
145 
146 private:
151 
152 
153 private:
158 
159 
160 };
161 
162 
163 /*--------------------------- Inline functions -----------------------------*/
164 
165 #ifndef DOXYGEN
166 
167 
168 
169 
170 template <int order, int dim, int spacedim, typename Number>
171 inline
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>
182 inline
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>
195 inline
199 {
200  for (unsigned int j=0; j<spacedim; ++j)
201  (*this)[j] = ta[j];
202  return *this;
203 }
204 
205 
206 
207 template <int order, int dim, int spacedim, typename Number>
208 inline
211 {
212  Assert( (dim == spacedim),
213  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 
224 template <int order, int dim, int spacedim, typename Number>
225 inline
228 {
229  Assert( (1 == spacedim) && (order==1),
230  ExcMessage("Only allowed for spacedim==1 and order==1."));
231 
232  (*this)[0] = T;
233 
234  return *this;
235 
236 }
237 
238 
239 
240 template <int order, int dim, int spacedim, typename Number>
241 inline
243 operator[] (const unsigned int i)
244 {
245  Assert (i<spacedim, ExcIndexRange(i, 0, spacedim));
246 
247  return tensor[i];
248 }
249 
250 
251 
252 template <int order, int dim, int spacedim, typename Number>
253 inline
255 operator[] (const unsigned int i) const
256 {
257  Assert (i<spacedim, ExcIndexRange(i, 0, spacedim));
258 
259  return tensor[i];
260 }
261 
262 
263 
264 template <int order, int dim, int spacedim, typename Number>
265 inline
267 {
268  Assert( (1 == spacedim) && (order==1),
269  ExcMessage("Only allowed for spacedim==1."));
270 
271  return (*this)[0];
272 
273 }
274 
275 
276 
277 template <int order, int dim, int spacedim, typename Number>
278 inline
280 {
281  Assert( (dim == spacedim),
282  ExcMessage("Only allowed when dim==spacedim."));
283 
285 
286  if (dim == spacedim)
287  for (unsigned int j=0; j<dim; ++j)
288  t[j] = (*this)[j];
289 
290  return t;
291 
292 }
293 
294 
295 
296 template <int order, int dim, int spacedim, typename Number>
297 inline
300 transpose () const
301 {
302  Assert(order==1, ExcMessage("Only for rectangular DerivativeForm."));
304 
305  for (unsigned int i=0; i<spacedim; ++i)
306  for (unsigned int j=0; j<dim; ++j)
307  tt[j][i] = (*this)[i][j];
308 
309  return tt;
310 }
311 
312 
313 
314 template <int order, int dim, int spacedim, typename Number>
315 inline
318 {
319  Assert( order==1, ExcMessage("Only for order == 1."));
321  for (unsigned int i=0; i<spacedim; ++i)
322  for (unsigned int j=0; j<dim; ++j)
323  dest[i][j] = (*this)[i] * T[j];
324 
325  return dest;
326 }
327 
328 
329 template <int order, int dim, int spacedim, typename Number>
330 inline
331 double
333 {
334  Assert( order==1, ExcMessage("Only for order == 1."));
335  if (dim == spacedim)
336  {
338  return ::determinant(T);
339  }
340  else
341  {
342  Assert( spacedim>dim, ExcMessage("Only for spacedim>dim."));
344  Tensor<2,dim,Number> G; //First fundamental form
345  for (unsigned int i=0; i<dim; ++i)
346  for (unsigned int j=0; j<dim; ++j)
347  G[i][j] = DF_t[i] * DF_t[j];
348 
349  return ( sqrt(::determinant(G)) );
350 
351  }
352 
353 }
354 
355 
356 
357 template <int order, int dim, int spacedim, typename Number>
358 inline
361 {
362 
363  if (dim == spacedim)
364  {
365 
366  Tensor<2,dim,Number> DF_t (::transpose(invert( (Tensor<2,dim,Number>)(*this) )));
367  DerivativeForm<1,dim, spacedim> result = DF_t;
368  return (result);
369  }
370  else
371  {
372 
374  Tensor<2,dim,Number> G; //First fundamental form
375  for (unsigned int i=0; i<dim; ++i)
376  for (unsigned int j=0; j<dim; ++j)
377  G[i][j] = DF_t[i] * DF_t[j];
378 
379  return (this->times_T_t(invert(G)));
380 
381  }
382 
383 }
384 
385 
386 template <int order, int dim, int spacedim, typename Number>
387 inline
388 std::size_t
390 {
392 }
393 
394 #endif // DOXYGEN
395 
396 
397 
398 
399 
408 template <int spacedim, int dim, typename Number>
409 inline
412  const Tensor<1,dim,Number> &T)
413 {
415  for (unsigned int i=0; i<spacedim; ++i)
416  dest[i] = DF[i] * T;
417  return dest;
418 }
419 
420 
421 
428 //rank=2
429 template <int spacedim, int dim, typename Number>
430 inline
433  const Tensor<2,dim,Number> &T)
434 {
435 
437  for (unsigned int i=0; i<dim; ++i)
438  dest[i] = apply_transformation(DF, T[i]);
439 
440  return dest;
441 }
442 
449 template <int spacedim, int dim, typename Number>
450 inline
454 {
456 
457  for (unsigned int i=0; i<spacedim; ++i)
458  dest[i] = apply_transformation(DF1, DF2[i]);
459 
460  return dest;
461 }
462 
463 
471 template <int dim, int spacedim, typename Number>
472 inline
475 {
477  tt = DF.transpose();
478  return tt;
479 }
480 
481 
482 DEAL_II_NAMESPACE_CLOSE
483 
484 #endif
DerivativeForm< 1, spacedim, dim > apply_transformation(const DerivativeForm< 1, dim, spacedim, Number > &DF, const Tensor< 2, dim, Number > &T)
DerivativeForm & operator=(const DerivativeForm< order, dim, spacedim, Number > &)
::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 Assert(cond, exc)
Definition: exceptions.h:294
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()
double determinant() const
DerivativeForm< 1, dim, spacedim, Number > covariant_form() const
Definition: mpi.h:48
Tensor< order, dim, Number > & operator[](const unsigned int i)
DeclException1(ExcInvalidTensorIndex, int,<< "Invalid DerivativeForm index "<< arg1)
DerivativeForm< 1, dim, spacedim, Number > times_T_t(Tensor< 2, dim, Number > T) const
DerivativeForm< 1, spacedim, dim, Number > transpose(const DerivativeForm< 1, dim, spacedim, Number > &DF)
Tensor< order, dim, Number > tensor[spacedim]