Reference documentation for deal.II version 9.1.1
\(\newcommand{\dealcoloneq}{\mathrel{\vcenter{:}}=}\)
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.md at
12 // the top level directory of deal.II.
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 
38  int,
39  << "You have requested contraction of tensors over index " << 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 inline Number
54  const Tensor<2, dim, Number> &src2);
55 
56 
66 template <int dim, typename Number>
67 DEAL_II_DEPRECATED inline void
69  const Tensor<4, dim, Number> &src1,
70  const Tensor<2, dim, Number> &src2);
71 
82 template <int dim, typename Number>
83 DEAL_II_DEPRECATED inline void contract(Tensor<2, dim, Number> & dest,
84  const Tensor<2, dim, Number> &src1,
85  const unsigned int index1,
86  const Tensor<2, dim, Number> &src2,
87  const unsigned int index3);
88 
98 template <int dim, typename Number>
99 DEAL_II_DEPRECATED inline void contract(Tensor<2, dim, Number> & dest,
100  const Tensor<3, dim, Number> &src1,
101  const unsigned int index1,
102  const Tensor<1, dim, Number> &src2);
103 
114 template <int dim, typename Number>
115 DEAL_II_DEPRECATED inline void contract(Tensor<3, dim, Number> & dest,
116  const Tensor<3, dim, Number> &src1,
117  const unsigned int index1,
118  const Tensor<2, dim, Number> &src2,
119  const unsigned int index2);
120 
129 template <int rank_1, int rank_2, int dim, typename Number>
130 DEAL_II_DEPRECATED inline void
132  const Tensor<rank_1, dim, Number> & src1,
133  const Tensor<rank_2, dim, Number> & src2);
134 
141 template <int dim, typename Number, typename OtherNumber>
142 DEAL_II_DEPRECATED inline typename ProductType<Number, OtherNumber>::type
143 contract(const Tensor<1, dim, Number> & src1,
144  const Tensor<1, dim, OtherNumber> &src2);
145 
146 
154 template <int dim, typename Number>
155 DEAL_II_DEPRECATED inline void cross_product(Tensor<1, dim, Number> & dst,
156  const Tensor<1, dim, Number> &src);
157 
164 template <int dim, typename Number>
165 DEAL_II_DEPRECATED inline void
167  const Tensor<1, dim, Number> &src1,
168  const Tensor<1, dim, Number> &src2);
169 
176 template <int rank_1, int rank_2, int dim, typename Number>
177 DEAL_II_DEPRECATED inline void
179  const Tensor<rank_1, dim, Number> & src1,
180  const Tensor<rank_2, dim, Number> & src2);
181 
188 template <int dim, typename Number>
189 DEAL_II_DEPRECATED inline void
191  const Number src1,
192  const Tensor<1, dim, Number> &src2);
193 
200 template <int dim, typename Number>
201 DEAL_II_DEPRECATED inline void outer_product(Tensor<1, dim, Number> & dst,
202  const Tensor<1, dim, Number> src1,
203  const Number src2);
204 
209 template <int rank, typename Number>
210 DEAL_II_DEPRECATED inline Number
212 
213 
218 template <typename Number>
219 DEAL_II_DEPRECATED inline Number
221 
223 
224 /* ----------------------------- Definitions: ------------------------------- */
225 
226 template <int dim, typename Number>
227 inline Number
229  const Tensor<2, dim, Number> &src2)
230 {
231  Number res = internal::NumberType<Number>::value(0.0);
232  for (unsigned int i = 0; i < dim; ++i)
233  res += src1[i] * src2[i];
234 
235  return res;
236 }
237 
238 template <int dim, typename Number>
240  const Tensor<4, dim, Number> &src1,
241  const Tensor<2, dim, Number> &src2)
242 {
243  dest.clear();
244  for (unsigned int i = 0; i < dim; ++i)
245  for (unsigned int j = 0; j < dim; ++j)
246  for (unsigned int k = 0; k < dim; ++k)
247  for (unsigned int l = 0; l < dim; ++l)
248  dest[i][j] += src1[i][j][k][l] * src2[k][l];
249 }
250 
251 template <int dim, typename Number>
252 inline void contract(Tensor<2, dim, Number> & dest,
253  const Tensor<2, dim, Number> &src1,
254  const unsigned int index1,
255  const Tensor<2, dim, Number> &src2,
256  const unsigned int index2)
257 {
258  dest.clear();
259 
260  switch (index1)
261  {
262  case 1:
263  switch (index2)
264  {
265  case 1:
266  for (unsigned int i = 0; i < dim; ++i)
267  for (unsigned int j = 0; j < dim; ++j)
268  for (unsigned int k = 0; k < dim; ++k)
269  dest[i][j] += src1[k][i] * src2[k][j];
270  break;
271  case 2:
272  for (unsigned int i = 0; i < dim; ++i)
273  for (unsigned int j = 0; j < dim; ++j)
274  for (unsigned int k = 0; k < dim; ++k)
275  dest[i][j] += src1[k][i] * src2[j][k];
276  break;
277 
278  default:
279  Assert(false, (ExcInvalidTensorContractionIndex(index2)));
280  };
281  break;
282  case 2:
283  switch (index2)
284  {
285  case 1:
286  for (unsigned int i = 0; i < dim; ++i)
287  for (unsigned int j = 0; j < dim; ++j)
288  for (unsigned int k = 0; k < dim; ++k)
289  dest[i][j] += src1[i][k] * src2[k][j];
290  break;
291  case 2:
292  for (unsigned int i = 0; i < dim; ++i)
293  for (unsigned int j = 0; j < dim; ++j)
294  for (unsigned int k = 0; k < dim; ++k)
295  dest[i][j] += src1[i][k] * src2[j][k];
296  break;
297 
298  default:
299  Assert(false, (ExcInvalidTensorContractionIndex(index2)));
300  };
301  break;
302 
303  default:
304  Assert(false, (ExcInvalidTensorContractionIndex(index1)));
305  };
306 }
307 
308 template <int dim, typename Number>
309 inline void contract(Tensor<2, dim, Number> & dest,
310  const Tensor<3, dim, Number> &src1,
311  const unsigned int index1,
312  const Tensor<1, dim, Number> &src2)
313 {
314  dest.clear();
315 
316  switch (index1)
317  {
318  case 1:
319  for (unsigned int i = 0; i < dim; ++i)
320  for (unsigned int j = 0; j < dim; ++j)
321  for (unsigned int k = 0; k < dim; ++k)
322  dest[i][j] += src1[k][i][j] * src2[k];
323  break;
324 
325  case 2:
326  for (unsigned int i = 0; i < dim; ++i)
327  for (unsigned int j = 0; j < dim; ++j)
328  for (unsigned int k = 0; k < dim; ++k)
329  dest[i][j] += src1[i][k][j] * src2[k];
330  break;
331 
332  case 3:
333  for (unsigned int i = 0; i < dim; ++i)
334  for (unsigned int j = 0; j < dim; ++j)
335  for (unsigned int k = 0; k < dim; ++k)
336  dest[i][j] += src1[i][j][k] * src2[k];
337  break;
338 
339  default:
340  Assert(false, (ExcInvalidTensorContractionIndex(index1)));
341  };
342 }
343 
344 template <int dim, typename Number>
345 inline void contract(Tensor<3, dim, Number> & dest,
346  const Tensor<3, dim, Number> &src1,
347  const unsigned int index1,
348  const Tensor<2, dim, Number> &src2,
349  const unsigned int index2)
350 {
351  dest.clear();
352 
353  switch (index1)
354  {
355  case 1:
356  switch (index2)
357  {
358  case 1:
359  for (unsigned int i = 0; i < dim; ++i)
360  for (unsigned int j = 0; j < dim; ++j)
361  for (unsigned int k = 0; k < dim; ++k)
362  for (unsigned int l = 0; l < dim; ++l)
363  dest[i][j][k] += src1[l][i][j] * src2[l][k];
364  break;
365  case 2:
366  for (unsigned int i = 0; i < dim; ++i)
367  for (unsigned int j = 0; j < dim; ++j)
368  for (unsigned int k = 0; k < dim; ++k)
369  for (unsigned int l = 0; l < dim; ++l)
370  dest[i][j][k] += src1[l][i][j] * src2[k][l];
371  break;
372  default:
373  Assert(false, (ExcInvalidTensorContractionIndex(index2)));
374  }
375 
376  break;
377  case 2:
378  switch (index2)
379  {
380  case 1:
381  for (unsigned int i = 0; i < dim; ++i)
382  for (unsigned int j = 0; j < dim; ++j)
383  for (unsigned int k = 0; k < dim; ++k)
384  for (unsigned int l = 0; l < dim; ++l)
385  dest[i][j][k] += src1[i][l][j] * src2[l][k];
386  break;
387  case 2:
388  for (unsigned int i = 0; i < dim; ++i)
389  for (unsigned int j = 0; j < dim; ++j)
390  for (unsigned int k = 0; k < dim; ++k)
391  for (unsigned int l = 0; l < dim; ++l)
392  dest[i][j][k] += src1[i][l][j] * src2[k][l];
393  break;
394  default:
395  Assert(false, (ExcInvalidTensorContractionIndex(index2)));
396  }
397 
398  break;
399  case 3:
400  switch (index2)
401  {
402  case 1:
403  for (unsigned int i = 0; i < dim; ++i)
404  for (unsigned int j = 0; j < dim; ++j)
405  for (unsigned int k = 0; k < dim; ++k)
406  for (unsigned int l = 0; l < dim; ++l)
407  dest[i][j][k] += src1[i][j][l] * src2[l][k];
408  break;
409  case 2:
410  for (unsigned int i = 0; i < dim; ++i)
411  for (unsigned int j = 0; j < dim; ++j)
412  for (unsigned int k = 0; k < dim; ++k)
413  for (unsigned int l = 0; l < dim; ++l)
414  dest[i][j][k] += src1[i][j][l] * src2[k][l];
415  break;
416  default:
417  Assert(false, (ExcInvalidTensorContractionIndex(index2)));
418  }
419 
420  break;
421  default:
422  Assert(false, (ExcInvalidTensorContractionIndex(index1)));
423  }
424 }
425 
426 template <int rank_1, int rank_2, int dim, typename Number>
428  const Tensor<rank_1, dim, Number> & src1,
429  const Tensor<rank_2, dim, Number> & src2)
430 {
431  TensorAccessors::internal::
432  ReorderedIndexView<0, rank_2, const Tensor<rank_2, dim, Number>>
433  reordered = TensorAccessors::reordered_index_view<0, rank_2>(src2);
434  TensorAccessors::contract<1, rank_1, rank_2, dim>(dest, src1, reordered);
435 }
436 
437 template <int dim, typename Number, typename OtherNumber>
438 inline typename ProductType<Number, OtherNumber>::type
440  const Tensor<1, dim, OtherNumber> &src2)
441 {
442  typename ProductType<Number, OtherNumber>::type res =
443  typename ProductType<Number, OtherNumber>::type();
444  for (unsigned int i = 0; i < dim; ++i)
445  res += src1[i] * src2[i];
446 
447  return res;
448 }
449 
450 template <int dim, typename Number>
452  const Tensor<1, dim, Number> &src)
453 {
454  dst = cross_product_2d(src);
455 }
456 
457 template <int dim, typename Number>
459  const Tensor<1, dim, Number> &src1,
460  const Tensor<1, dim, Number> &src2)
461 {
462  dst = cross_product_3d(src1, src2);
463 }
464 
465 template <int rank_1, int rank_2, int dim, typename Number>
466 inline void
468  const Tensor<rank_1, dim, Number> & src1,
469  const Tensor<rank_2, dim, Number> & src2)
470 {
471  TensorAccessors::contract<0, rank_1, rank_2, dim>(dst, src1, src2);
472 }
473 
474 template <int dim, typename Number>
476  const Number src1,
477  const Tensor<1, dim, Number> &src2)
478 {
479  for (unsigned int i = 0; i < dim; ++i)
480  dst[i] = src1 * src2[i];
481 }
482 
483 template <int dim, typename Number>
485  const Tensor<1, dim, Number> src1,
486  const Number src2)
487 {
488  for (unsigned int i = 0; i < dim; ++i)
489  dst[i] = src1[i] * src2;
490 }
491 
492 template <int rank, typename Number>
493 inline Number
495 {
496  return determinant(t[0]);
497 }
498 
499 template <typename Number>
500 inline Number
502 {
503  return t[0];
504 }
505 
506 DEAL_II_NAMESPACE_CLOSE
507 
508 #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:518
Tensor< 1, dim, Number > cross_product_2d(const Tensor< 1, dim, Number > &src)
Definition: tensor.h:2075
#define Assert(cond, exc)
Definition: exceptions.h:1407
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:2100
Number determinant(const SymmetricTensor< 2, dim, Number > &t)
Definition: mpi.h:90
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:1823
void clear()
Definition: tensor.h:1437
static ::ExceptionBase & ExcInvalidTensorContractionIndex(int arg1)