Reference documentation for deal.II version 8.1.0
derivative_form.h
1 // ---------------------------------------------------------------------
2 // @f$Id: derivative_form.h 31808 2013-11-26 16:43:06Z heister @f$
3 //
4 // Copyright (C) 2013 by the deal.II authors
5 //
6 // This file is part of the deal.II library.
7 //
8 // The deal.II library is free software; you can use it, redistribute
9 // it, and/or modify it under the terms of the GNU Lesser General
10 // Public License as published by the Free Software Foundation; either
11 // version 2.1 of the License, or (at your option) any later version.
12 // The full text of the license can be found in the file LICENSE at
13 // the top level of the deal.II distribution.
14 //
15 // ---------------------------------------------------------------------
16 
17 #ifndef __deal2__derivative_form_h
18 #define __deal2__derivative_form_h
19 
20 #include <deal.II/base/tensor.h>
21 
23 
40 template <int order, int dim, int spacedim>
42 {
43 public:
48  DerivativeForm ();
49 
53  DerivativeForm (const Tensor<2,dim> &);
54 
58  Tensor<order,dim> &operator [] (const unsigned int i);
59 
63  const Tensor<order,dim> &operator [] (const unsigned int i) const;
64 
69 
70 
75 
80 
87  operator Tensor<2,dim>() const;
88 
93  operator Tensor<1,dim>() const;
94 
100 
101 
109  double determinant () const;
110 
111 
121 
122 
123 
124 
130  static std::size_t memory_consumption ();
131 
135  DeclException1 (ExcInvalidTensorIndex,
136  int,
137  << "Invalid DerivativeForm index " << arg1);
138 
139 
140 private:
144 
145 
146 private:
152 
153 
154 };
155 
156 
157 /*--------------------------- Inline functions -----------------------------*/
158 
159 #ifndef DOXYGEN
160 
161 
162 
163 
164 template <int order, int dim, int spacedim>
165 inline
167 {
168 // default constructor. not specifying an initializer list calls
169 // the default constructor of the subobjects, which initialize them
170 // selves. therefore, the tensor array is set to zero this way
171 }
172 
173 
174 
175 template <int order, int dim, int spacedim>
176 inline
178 {
179  Assert( (dim == spacedim) && (order==1),
180  ExcMessage("Only allowed for square tensors."));
181  if ((dim == spacedim) && (order==1))
182  for (unsigned int j=0; j<dim; ++j)
183  (*this)[j] = T[j];
184 }
185 
186 
187 
188 template <int order, int dim, int spacedim>
189 inline
193 {
194  for (unsigned int j=0; j<spacedim; ++j)
195  (*this)[j] = ta[j];
196  return *this;
197 }
198 
199 
200 
201 template <int order, int dim, int spacedim>
202 inline
204 operator = (const Tensor<2,dim> &ta)
205 {
206  Assert( (dim == spacedim) && (order==1),
207  ExcMessage("Only allowed for square tensors."));
208 
209  if ((dim == spacedim) && (order==1))
210  for (unsigned int j=0; j<dim; ++j)
211  (*this)[j] = ta[j];
212  return *this;
213 
214 }
215 
216 
217 
218 template <int order, int dim, int spacedim>
219 inline
221 operator = (const Tensor<1,dim> &T)
222 {
223  Assert( (1 == spacedim) && (order==1),
224  ExcMessage("Only allowed for spacedim==1 and order==1."));
225 
226  (*this)[0] = T;
227 
228  return *this;
229 
230 }
231 
232 
233 
234 template <int order, int dim, int spacedim>
235 inline
237 operator[] (const unsigned int i)
238 {
239  Assert (i<spacedim, ExcIndexRange(i, 0, spacedim));
240 
241  return tensor[i];
242 }
243 
244 
245 
246 template <int order, int dim, int spacedim>
247 inline
249 operator[] (const unsigned int i) const
250 {
251  Assert (i<spacedim, ExcIndexRange(i, 0, spacedim));
252 
253  return tensor[i];
254 }
255 
256 
257 
258 template <int order, int dim, int spacedim>
259 inline
261 {
262  Assert( (1 == spacedim) && (order==1),
263  ExcMessage("Only allowed for spacedim==1."));
264 
265  return (*this)[0];
266 
267 }
268 
269 
270 
271 template <int order, int dim, int spacedim>
272 inline
274 {
275  Assert( (dim == spacedim) && (order==1),
276  ExcMessage("Only allowed for square tensors."));
277 
278 
279 
280  Tensor<2,dim> t;
281 
282  if ((dim == spacedim) && (order==1))
283  for (unsigned int j=0; j<dim; ++j)
284  t[j] = (*this)[j];
285 
286  return t;
287 
288 }
289 
290 
291 
292 template <int order, int dim, int spacedim>
293 inline
296 transpose () const
297 {
298  Assert(order==1, ExcMessage("Only for rectangular DerivativeForm."));
300 
301  for (unsigned int i=0; i<spacedim; ++i)
302  for (unsigned int j=0; j<dim; ++j)
303  tt[j][i] = (*this)[i][j];
304 
305  return tt;
306 }
307 
308 
309 
310 template <int order, int dim, int spacedim>
311 inline
314 {
315  Assert( order==1, ExcMessage("Only for order == 1."));
317  for (unsigned int i=0; i<spacedim; ++i)
318  for (unsigned int j=0; j<dim; ++j)
319  dest[i][j] = (*this)[i] * T[j];
320 
321  return dest;
322 }
323 
324 
325 template <int order, int dim, int spacedim>
326 inline
327 double
329 {
330  Assert( order==1, ExcMessage("Only for order == 1."));
331  if (dim == spacedim)
332  {
333  Tensor<2,dim> T = (Tensor<2,dim>)( (*this) );
334  return ::determinant(T);
335  }
336  else
337  {
338  Assert( spacedim>dim, ExcMessage("Only for spacedim>dim."));
340  Tensor<2, dim> G; //First fundamental form
341  for (unsigned int i=0; i<dim; ++i)
342  for (unsigned int j=0; j<dim; ++j)
343  G[i][j] = DF_t[i] * DF_t[j];
344 
345  return ( sqrt(::determinant(G)) );
346 
347  }
348 
349 }
350 
351 
352 
353 template <int order, int dim, int spacedim>
354 inline
357 {
358 
359  if (dim == spacedim)
360  {
361 
362  Tensor<2,dim> DF_t (::transpose(invert( (Tensor<2,dim>)(*this) )));
363  DerivativeForm<1,dim, spacedim> result = DF_t;
364  return (result);
365  }
366  else
367  {
368 
370  Tensor<2, dim> G; //First fundamental form
371  for (unsigned int i=0; i<dim; ++i)
372  for (unsigned int j=0; j<dim; ++j)
373  G[i][j] = DF_t[i] * DF_t[j];
374 
375  return (this->times_T_t(invert(G)));
376 
377  }
378 
379 }
380 
381 
382 template <int order, int dim, int spacedim>
383 inline
384 std::size_t
386 {
388 }
389 
390 #endif // DOXYGEN
391 
392 
393 
394 
395 
406 template <int spacedim, int dim>
407 inline
410  const Tensor<1,dim> &T)
411 {
412  Tensor<1, spacedim> dest;
413  for (unsigned int i=0; i<spacedim; ++i)
414  dest[i] = DF[i] * T;
415  return dest;
416 }
417 
418 
419 
426 //rank=2
427 template <int spacedim, int dim>
428 inline
431  const Tensor<2,dim> &T)
432 {
433 
435  for (unsigned int i=0; i<dim; ++i)
436  dest[i] = apply_transformation(DF, T[i]);
437 
438  return dest;
439 }
440 
447 template <int spacedim, int dim>
448 inline
452 {
453  Tensor<2, spacedim> dest;
454 
455  for (unsigned int i=0; i<spacedim; ++i)
456  dest[i] = apply_transformation(DF1, DF2[i]);
457 
458  return dest;
459 }
460 
461 
468 template <int dim, int spacedim>
469 inline
472 {
474  tt = DF.transpose();
475  return tt;
476 }
477 
478 
479 DEAL_II_NAMESPACE_CLOSE
480 
481 #endif
Tensor< order, dim > tensor[spacedim]
DerivativeForm & operator=(const DerivativeForm< order, dim, spacedim > &)
DerivativeForm< 1, spacedim, dim > apply_transformation(const DerivativeForm< 1, dim, spacedim > &DF, const Tensor< 2, dim > &T)
::ExceptionBase & ExcMessage(std::string arg1)
DerivativeForm< 1, dim, spacedim > covariant_form() const
DeclException1(ExcInvalidTensorIndex, int,<< "Invalid DerivativeForm index "<< arg1)
double determinant() const
#define Assert(cond, exc)
Definition: exceptions.h:299
SymmetricTensor< rank, dim, Number > transpose(const SymmetricTensor< rank, dim, Number > &t)
::ExceptionBase & ExcIndexRange(int arg1, int arg2, int arg3)
DerivativeForm< 1, spacedim, dim > transpose() const
Tensor< order, dim > & operator[](const unsigned int i)
Tensor< 2, spacedim > apply_transformation(const DerivativeForm< 1, dim, spacedim > &DF1, const DerivativeForm< 1, dim, spacedim > &DF2)
Number determinant(const SymmetricTensor< 2, dim, Number > &t)
VectorizedArray< Number > sqrt(const ::VectorizedArray< Number > &x)
DerivativeForm< 1, dim, spacedim > times_T_t(Tensor< 2, dim > T) const
static std::size_t memory_consumption()
Tensor< 1, spacedim > apply_transformation(const DerivativeForm< 1, dim, spacedim > &DF, const Tensor< 1, dim > &T)
DerivativeForm< 1, spacedim, dim > transpose(const DerivativeForm< 1, dim, spacedim > &DF)
SymmetricTensor< 4, dim, Number > invert(const SymmetricTensor< 4, dim, Number > &t)