Reference documentation for deal.II version 9.0.0
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 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  Number 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
329 {
330  Assert( order==1, ExcMessage("Only for order == 1."));
331  if (dim == spacedim)
332  {
333  const Tensor<2,dim,Number> T = static_cast<Tensor<2,dim,Number> >(*this);
335  }
336  else
337  {
338  Assert( spacedim>dim, ExcMessage("Only for spacedim>dim."));
340  Tensor<2,dim,Number> 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 template <int order, int dim, int spacedim, typename Number>
352 inline
355 {
356  if (dim == spacedim)
357  {
358  const Tensor<2,dim,Number> DF_t
359  = ::transpose (invert (static_cast<Tensor<2,dim,Number> >(*this)));
360  return DerivativeForm<1,dim, spacedim> (DF_t);
361  }
362  else
363  {
364  const DerivativeForm<1,spacedim,dim> DF_t = this->transpose();
365  Tensor<2,dim,Number> G; //First fundamental form
366  for (unsigned int i=0; i<dim; ++i)
367  for (unsigned int j=0; j<dim; ++j)
368  G[i][j] = DF_t[i] * DF_t[j];
369 
370  return (this->times_T_t(invert(G)));
371  }
372 }
373 
374 
375 template <int order, int dim, int spacedim, typename Number>
376 inline
377 std::size_t
379 {
381 }
382 
383 #endif // DOXYGEN
384 
385 
386 
387 
388 
397 template <int spacedim, int dim, typename Number>
398 inline
401  const Tensor<1,dim,Number> &T)
402 {
404  for (unsigned int i=0; i<spacedim; ++i)
405  dest[i] = DF[i] * T;
406  return dest;
407 }
408 
409 
410 
417 //rank=2
418 template <int spacedim, int dim, typename Number>
419 inline
422  const Tensor<2,dim,Number> &T)
423 {
424 
426  for (unsigned int i=0; i<dim; ++i)
427  dest[i] = apply_transformation(DF, T[i]);
428 
429  return dest;
430 }
431 
438 template <int spacedim, int dim, typename Number>
439 inline
443 {
445 
446  for (unsigned int i=0; i<spacedim; ++i)
447  dest[i] = apply_transformation(DF1, DF2[i]);
448 
449  return dest;
450 }
451 
452 
460 template <int dim, int spacedim, typename Number>
461 inline
464 {
466  tt = DF.transpose();
467  return tt;
468 }
469 
470 
471 DEAL_II_NAMESPACE_CLOSE
472 
473 #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 > &)
SymmetricTensor< 2, dim, Number > invert(const SymmetricTensor< 2, dim, Number > &t)
DerivativeForm & operator=(const Tensor< order+1, dim, Number > &)
static ::ExceptionBase & ExcIndexRange(int arg1, int arg2, int arg3)
Number determinant() const
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:346
DerivativeForm< 1, dim, spacedim, Number > times_T_t(const Tensor< 2, dim, Number > &T) const
#define Assert(cond, exc)
Definition: exceptions.h:1142
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
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:53
Tensor< order, dim, Number > & operator[](const unsigned int i)
static ::ExceptionBase & ExcInvalidTensorIndex(int arg1)
DerivativeForm< 1, spacedim, dim, Number > transpose(const DerivativeForm< 1, dim, spacedim, Number > &DF)
Tensor< order, dim, Number > tensor[spacedim]