Reference documentation for deal.II version 9.0.0
tensor_deprecated.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 1998 - 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_tensor_deprecated_h
17 #define dealii_tensor_deprecated_h
18 
19 #include <deal.II/base/tensor.h>
20 
21 
22 /* --------- Deprecated non-member functions operating on tensors. ---------- */
23 
24 DEAL_II_NAMESPACE_OPEN
25 
30 
37  int,
38  << "You have requested contraction of tensors over index "
39  << arg1
40  << ", but this is not possible for tensors of the current type.");
41 
42 
51 template <int dim, typename Number>
52 DEAL_II_DEPRECATED
53 inline
54 Number double_contract (const Tensor<2, dim, Number> &src1,
55  const Tensor<2, dim, Number> &src2);
56 
57 
67 template <int dim, typename Number>
68 DEAL_II_DEPRECATED
69 inline
71  const Tensor<4,dim,Number> &src1,
72  const Tensor<2,dim,Number> &src2);
73 
84 template <int dim, typename Number>
85 DEAL_II_DEPRECATED
86 inline
87 void contract (Tensor<2,dim,Number> &dest,
88  const Tensor<2,dim,Number> &src1,
89  const unsigned int index1,
90  const Tensor<2,dim,Number> &src2,
91  const unsigned int index3);
92 
102 template <int dim, typename Number>
103 DEAL_II_DEPRECATED
104 inline
105 void contract (Tensor<2,dim,Number> &dest,
106  const Tensor<3,dim,Number> &src1,
107  const unsigned int index1,
108  const Tensor<1,dim,Number> &src2);
109 
120 template <int dim, typename Number>
121 DEAL_II_DEPRECATED
122 inline
123 void contract (Tensor<3,dim,Number> &dest,
124  const Tensor<3,dim,Number> &src1,
125  const unsigned int index1,
126  const Tensor<2,dim,Number> &src2,
127  const unsigned int index2);
128 
137 template <int rank_1, int rank_2, int dim, typename Number>
138 DEAL_II_DEPRECATED
139 inline
141  const Tensor<rank_1, dim, Number> &src1,
142  const Tensor<rank_2, dim, Number> &src2);
143 
150 template <int dim, typename Number, typename OtherNumber>
151 DEAL_II_DEPRECATED
152 inline
153 typename ProductType<Number,OtherNumber>::type
154 contract (const Tensor<1,dim,Number> &src1,
155  const Tensor<1,dim,OtherNumber> &src2);
156 
157 
165 template <int dim, typename Number>
166 DEAL_II_DEPRECATED
167 inline
168 void
170  const Tensor<1,dim,Number> &src);
171 
178 template <int dim, typename Number>
179 DEAL_II_DEPRECATED
180 inline
181 void
183  const Tensor<1,dim,Number> &src1,
184  const Tensor<1,dim,Number> &src2);
185 
192 template <int rank_1, int rank_2, int dim, typename Number>
193 DEAL_II_DEPRECATED
194 inline
196  const Tensor<rank_1, dim, Number> &src1,
197  const Tensor<rank_2, dim, Number> &src2);
198 
205 template <int dim, typename Number>
206 DEAL_II_DEPRECATED
207 inline
209  const Number src1,
210  const Tensor<1,dim,Number> &src2);
211 
218 template <int dim, typename Number>
219 DEAL_II_DEPRECATED
220 inline
222  const Tensor<1,dim,Number> src1,
223  const Number src2);
224 
229 template <int rank, typename Number>
230 DEAL_II_DEPRECATED
231 inline
232 Number determinant (const Tensor<rank,1,Number> &t);
233 
234 
239 template <typename Number>
240 DEAL_II_DEPRECATED
241 inline
242 Number determinant (const Tensor<1,1,Number> &t);
243 
245 
246 /* ----------------------------- Definitions: ------------------------------- */
247 
248 template <int dim, typename Number>
249 inline
251  const Tensor<2, dim, Number> &src2)
252 {
253  Number res = internal::NumberType<Number>::value(0.0);
254  for (unsigned int i=0; i<dim; ++i)
255  res += src1[i] * src2[i];
256 
257  return res;
258 }
259 
260 template <int dim, typename Number>
261 inline
263  const Tensor<4,dim,Number> &src1,
264  const Tensor<2,dim,Number> &src2)
265 {
266  dest.clear ();
267  for (unsigned int i=0; i<dim; ++i)
268  for (unsigned int j=0; j<dim; ++j)
269  for (unsigned int k=0; k<dim; ++k)
270  for (unsigned int l=0; l<dim; ++l)
271  dest[i][j] += src1[i][j][k][l] * src2[k][l];
272 }
273 
274 template <int dim, typename Number>
275 inline
277  const Tensor<2,dim,Number> &src1, const unsigned int index1,
278  const Tensor<2,dim,Number> &src2, const unsigned int index2)
279 {
280  dest.clear ();
281 
282  switch (index1)
283  {
284  case 1:
285  switch (index2)
286  {
287  case 1:
288  for (unsigned int i=0; i<dim; ++i)
289  for (unsigned int j=0; j<dim; ++j)
290  for (unsigned int k=0; k<dim; ++k)
291  dest[i][j] += src1[k][i] * src2[k][j];
292  break;
293  case 2:
294  for (unsigned int i=0; i<dim; ++i)
295  for (unsigned int j=0; j<dim; ++j)
296  for (unsigned int k=0; k<dim; ++k)
297  dest[i][j] += src1[k][i] * src2[j][k];
298  break;
299 
300  default:
301  Assert (false, (ExcInvalidTensorContractionIndex (index2)));
302  };
303  break;
304  case 2:
305  switch (index2)
306  {
307  case 1:
308  for (unsigned int i=0; i<dim; ++i)
309  for (unsigned int j=0; j<dim; ++j)
310  for (unsigned int k=0; k<dim; ++k)
311  dest[i][j] += src1[i][k] * src2[k][j];
312  break;
313  case 2:
314  for (unsigned int i=0; i<dim; ++i)
315  for (unsigned int j=0; j<dim; ++j)
316  for (unsigned int k=0; k<dim; ++k)
317  dest[i][j] += src1[i][k] * src2[j][k];
318  break;
319 
320  default:
321  Assert (false, (ExcInvalidTensorContractionIndex (index2)));
322  };
323  break;
324 
325  default:
326  Assert (false, (ExcInvalidTensorContractionIndex (index1)));
327  };
328 }
329 
330 template <int dim, typename Number>
331 inline
333  const Tensor<3,dim,Number> &src1, const unsigned int index1,
334  const Tensor<1,dim,Number> &src2)
335 {
336  dest.clear ();
337 
338  switch (index1)
339  {
340  case 1:
341  for (unsigned int i=0; i<dim; ++i)
342  for (unsigned int j=0; j<dim; ++j)
343  for (unsigned int k=0; k<dim; ++k)
344  dest[i][j] += src1[k][i][j] * src2[k];
345  break;
346 
347  case 2:
348  for (unsigned int i=0; i<dim; ++i)
349  for (unsigned int j=0; j<dim; ++j)
350  for (unsigned int k=0; k<dim; ++k)
351  dest[i][j] += src1[i][k][j] * src2[k];
352  break;
353 
354  case 3:
355  for (unsigned int i=0; i<dim; ++i)
356  for (unsigned int j=0; j<dim; ++j)
357  for (unsigned int k=0; k<dim; ++k)
358  dest[i][j] += src1[i][j][k] * src2[k];
359  break;
360 
361  default:
362  Assert (false, (ExcInvalidTensorContractionIndex (index1)));
363  };
364 }
365 
366 template <int dim, typename Number>
367 inline
369  const Tensor<3,dim,Number> &src1, const unsigned int index1,
370  const Tensor<2,dim,Number> &src2, const unsigned int index2)
371 {
372  dest.clear ();
373 
374  switch (index1)
375  {
376  case 1:
377  switch (index2)
378  {
379  case 1:
380  for (unsigned int i=0; i<dim; ++i)
381  for (unsigned int j=0; j<dim; ++j)
382  for (unsigned int k=0; k<dim; ++k)
383  for (unsigned int l=0; l<dim; ++l)
384  dest[i][j][k] += src1[l][i][j] * src2[l][k];
385  break;
386  case 2:
387  for (unsigned int i=0; i<dim; ++i)
388  for (unsigned int j=0; j<dim; ++j)
389  for (unsigned int k=0; k<dim; ++k)
390  for (unsigned int l=0; l<dim; ++l)
391  dest[i][j][k] += src1[l][i][j] * src2[k][l];
392  break;
393  default:
394  Assert (false, (ExcInvalidTensorContractionIndex (index2)));
395  }
396 
397  break;
398  case 2:
399  switch (index2)
400  {
401  case 1:
402  for (unsigned int i=0; i<dim; ++i)
403  for (unsigned int j=0; j<dim; ++j)
404  for (unsigned int k=0; k<dim; ++k)
405  for (unsigned int l=0; l<dim; ++l)
406  dest[i][j][k] += src1[i][l][j] * src2[l][k];
407  break;
408  case 2:
409  for (unsigned int i=0; i<dim; ++i)
410  for (unsigned int j=0; j<dim; ++j)
411  for (unsigned int k=0; k<dim; ++k)
412  for (unsigned int l=0; l<dim; ++l)
413  dest[i][j][k] += src1[i][l][j] * src2[k][l];
414  break;
415  default:
416  Assert (false, (ExcInvalidTensorContractionIndex (index2)));
417  }
418 
419  break;
420  case 3:
421  switch (index2)
422  {
423  case 1:
424  for (unsigned int i=0; i<dim; ++i)
425  for (unsigned int j=0; j<dim; ++j)
426  for (unsigned int k=0; k<dim; ++k)
427  for (unsigned int l=0; l<dim; ++l)
428  dest[i][j][k] += src1[i][j][l] * src2[l][k];
429  break;
430  case 2:
431  for (unsigned int i=0; i<dim; ++i)
432  for (unsigned int j=0; j<dim; ++j)
433  for (unsigned int k=0; k<dim; ++k)
434  for (unsigned int l=0; l<dim; ++l)
435  dest[i][j][k] += src1[i][j][l] * src2[k][l];
436  break;
437  default:
438  Assert (false, (ExcInvalidTensorContractionIndex (index2)));
439  }
440 
441  break;
442  default:
443  Assert (false, (ExcInvalidTensorContractionIndex (index1)));
444  }
445 }
446 
447 template <int rank_1, int rank_2, int dim, typename Number>
448 inline
450  const Tensor<rank_1, dim, Number> &src1,
451  const Tensor<rank_2, dim, Number> &src2)
452 {
453  TensorAccessors::internal::ReorderedIndexView<0, rank_2, const Tensor<rank_2, dim, Number> >
454  reordered = TensorAccessors::reordered_index_view<0, rank_2>(src2);
455  TensorAccessors::contract<1, rank_1, rank_2, dim>(dest, src1, reordered);
456 }
457 
458 template <int dim, typename Number, typename OtherNumber>
459 inline
460 typename ProductType<Number,OtherNumber>::type
462  const Tensor<1,dim,OtherNumber> &src2)
463 {
464  typename ProductType<Number,OtherNumber>::type res
465  = typename ProductType<Number,OtherNumber>::type();
466  for (unsigned int i=0; i<dim; ++i)
467  res += src1[i] * src2[i];
468 
469  return res;
470 }
471 
472 template <int dim, typename Number>
473 inline
474 void
476  const Tensor<1,dim,Number> &src)
477 {
478  dst = cross_product_2d(src);
479 }
480 
481 template <int dim, typename Number>
482 inline
483 void
485  const Tensor<1,dim,Number> &src1,
486  const Tensor<1,dim,Number> &src2)
487 {
488  dst = cross_product_3d(src1, src2);
489 }
490 
491 template <int rank_1, int rank_2, int dim, typename Number>
492 inline
494  const Tensor<rank_1, dim, Number> &src1,
495  const Tensor<rank_2, dim, Number> &src2)
496 {
497  TensorAccessors::contract<0, rank_1, rank_2, dim>(dst, src1, src2);
498 }
499 
500 template <int dim, typename Number>
501 inline
503  const Number src1,
504  const Tensor<1,dim,Number> &src2)
505 {
506  for (unsigned int i=0; i<dim; ++i)
507  dst[i] = src1 * src2[i];
508 }
509 
510 template <int dim, typename Number>
511 inline
513  const Tensor<1,dim,Number> src1,
514  const Number src2)
515 {
516  for (unsigned int i=0; i<dim; ++i)
517  dst[i] = src1[i] * src2;
518 }
519 
520 template <int rank, typename Number>
521 inline
523 {
524  return determinant(t[0]);
525 }
526 
527 template <typename Number>
528 inline
530 {
531  return t[0];
532 }
533 
534 DEAL_II_NAMESPACE_CLOSE
535 
536 #endif
void double_contract(SymmetricTensor< 2, 1, typename ProductType< Number, OtherNumber >::type > &tmp, const SymmetricTensor< 4, 1, Number > &t, const SymmetricTensor< 2, 1, OtherNumber > &s)
void cross_product(Tensor< 1, dim, Number > &dst, const Tensor< 1, dim, Number > &src)
#define DeclException1(Exception1, type1, outsequence)
Definition: exceptions.h:346
Tensor< 1, dim, Number > cross_product_2d(const Tensor< 1, dim, Number > &src)
Definition: tensor.h:1945
#define Assert(cond, exc)
Definition: exceptions.h:1142
SymmetricTensor< 4, dim, Number > outer_product(const SymmetricTensor< 2, dim, Number > &t1, const SymmetricTensor< 2, dim, Number > &t2)
Tensor< 1, dim, Number > cross_product_3d(const Tensor< 1, dim, Number > &src1, const Tensor< 1, dim, Number > &src2)
Definition: tensor.h:1971
Number determinant(const SymmetricTensor< 2, dim, Number > &t)
Definition: mpi.h:53
Tensor< rank_1+rank_2 - 2, dim, typename ProductType< Number, OtherNumber >::type >::tensor_type contract(const Tensor< rank_1, dim, Number > &src1, const Tensor< rank_2, dim, OtherNumber > &src2)
Definition: tensor.h:1732
void clear()
Definition: tensor.h:1356
static ::ExceptionBase & ExcInvalidTensorContractionIndex(int arg1)