Intrepid
Intrepid_MiniTensor_Mechanics.t.h
1 // @HEADER
2 // ************************************************************************
3 //
4 // Intrepid Package
5 // Copyright (2007) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions: Alejandro Mota (amota@sandia.gov)
38 //
39 // ************************************************************************
40 // @HEADER
41 
42 #if !defined(Intrepid_MiniTensor_Mechanics_t_h)
43 #define Intrepid_MiniTensor_Mechanics_t_h
44 
45 namespace Intrepid {
46 
47 //
48 // Push forward covariant vector
49 // \param \f$ F, u \f$
50 // \return \f$ F^{-T} u \f$
51 //
52 template<typename T>
53 Vector<T>
54 push_forward_covariant(Tensor<T> const & F, Vector<T> const & u)
55 {
56  Index const
57  N = F.get_dimension();
58 
59  Vector<T>
60  v(N);
61 
62  T const
63  J = det(F);
64 
65  assert(J > 0.0);
66 
67  switch (N) {
68 
69  default:
70  std::cerr << "ERROR: " << __PRETTY_FUNCTION__;
71  std::cerr << std::endl;
72  std::cerr << "Supports only 2D and 3D. Found dimension: " << N;
73  std::cerr << std::endl;
74  exit(1);
75  break;
76 
77  case 3:
78  v(0) = ((-F(1,2)*F(2,1) + F(1,1)*F(2,2)) * u(0) +
79  ( F(1,2)*F(2,0) - F(1,0)*F(2,2)) * u(1) +
80  (-F(1,1)*F(2,0) + F(1,0)*F(2,1)) * u(2)) / J;
81 
82  v(1) = (( F(0,2)*F(2,1) - F(0,1)*F(2,2)) * u(0) +
83  (-F(0,2)*F(2,0) + F(0,0)*F(2,2)) * u(1) +
84  ( F(0,1)*F(2,0) - F(0,0)*F(2,1)) * u(2)) / J;
85 
86  v(2) = ((-F(0,2)*F(1,1) + F(0,1)*F(1,2)) * u(0) +
87  ( F(0,2)*F(1,0) - F(0,0)*F(1,2)) * u(1) +
88  (-F(0,1)*F(1,0) + F(0,0)*F(1,1)) * u(2)) / J;
89 
90  break;
91 
92  case 2:
93  v(0) = ( F(1,1) * u(0) - F(1,0) * u(1)) / J;
94  v(1) = (-F(0,1) * u(0) + F(0,0) * u(1)) / J;
95  break;
96 
97  }
98 
99  return v;
100 }
101 
102 //
103 // Pull back covariant vector
104 // \param \f$ F, v \f$
105 // \return \f$ F^T v \f$
106 //
107 template<typename T>
108 Vector<T>
109 pull_back_covariant(Tensor<T> const & F, Vector<T> const & u)
110 {
111  Index const
112  N = F.get_dimension();
113 
114  Vector<T>
115  v(N);
116 
117  switch (N) {
118 
119  default:
120  std::cerr << "ERROR: " << __PRETTY_FUNCTION__;
121  std::cerr << std::endl;
122  std::cerr << "Supports only 2D and 3D. Found dimension: " << N;
123  std::cerr << std::endl;
124  exit(1);
125  break;
126 
127  case 3:
128  v(0) = F(0,0) * u(0) + F(1,0) * u(1) + F(2,0) * u(2);
129  v(1) = F(0,1) * u(0) + F(1,1) * u(1) + F(2,1) * u(2);
130  v(2) = F(0,2) * u(0) + F(1,2) * u(1) + F(2,2) * u(2);
131 
132  break;
133 
134  case 2:
135  v(0) = F(0,0) * u(0) + F(1,0) * u(1);
136  v(1) = F(0,1) * u(0) + F(1,1) * u(1);
137 
138  break;
139 
140  }
141 
142  return v;
143 }
144 
145 //
146 // Push forward contravariant vector
147 // \param \f$ F, u \f$
148 // \return \f$ F u \f$
149 //
150 template<typename T>
151 Vector<T>
152 push_forward_contravariant(Tensor<T> const & F, Vector<T> const & u)
153 {
154  Index const
155  N = F.get_dimension();
156 
157  Vector<T>
158  v(N);
159 
160  switch (N) {
161 
162  default:
163  std::cerr << "ERROR: " << __PRETTY_FUNCTION__;
164  std::cerr << std::endl;
165  std::cerr << "Supports only 2D and 3D. Found dimension: " << N;
166  std::cerr << std::endl;
167  exit(1);
168  break;
169 
170  case 3:
171  v(0) = F(0,0) * u(0) + F(0,1) * u(1) + F(0,2) * u(2);
172  v(1) = F(1,0) * u(0) + F(1,1) * u(1) + F(1,2) * u(2);
173  v(2) = F(2,0) * u(0) + F(2,1) * u(1) + F(2,2) * u(2);
174 
175  break;
176 
177  case 2:
178  v(0) = F(0,0) * u(0) + F(0,1) * u(1);
179  v(1) = F(1,0) * u(0) + F(1,1) * u(1);
180 
181  break;
182 
183  }
184 
185  return v;
186 }
187 
188 //
189 // Pull back contravariant vector
190 // \param \f$ F, u \f$
191 // \return \f$ F^{-1} u \f$
192 //
193 template<typename T>
194 Vector<T>
195 pull_back_contravariant(Tensor<T> const & F, Vector<T> const & u)
196 {
197  Index const
198  N = F.get_dimension();
199 
200  Vector<T>
201  v(N);
202 
203  T const
204  J = det(F);
205 
206  assert(J > 0.0);
207 
208  switch (N) {
209 
210  default:
211  std::cerr << "ERROR: " << __PRETTY_FUNCTION__;
212  std::cerr << std::endl;
213  std::cerr << "Supports only 2D and 3D. Found dimension: " << N;
214  std::cerr << std::endl;
215  exit(1);
216  break;
217 
218  case 3:
219  v(0) = ((-F(1,2)*F(2,1) + F(1,1)*F(2,2)) * u(0) +
220  ( F(0,2)*F(2,1) - F(0,1)*F(2,2)) * u(1) +
221  (-F(0,2)*F(1,1) + F(0,1)*F(1,2)) * u(2)) / J;
222 
223  v(1) = (( F(1,2)*F(2,0) - F(1,0)*F(2,2)) * u(0) +
224  (-F(0,2)*F(2,0) + F(0,0)*F(2,2)) * u(1) +
225  ( F(0,2)*F(1,0) - F(0,0)*F(1,2)) * u(2)) / J;
226 
227  v(2) = ((-F(1,1)*F(2,0) + F(1,0)*F(2,1)) * u(0) +
228  ( F(0,1)*F(2,0) - F(0,0)*F(2,1)) * u(1) +
229  (-F(0,1)*F(1,0) + F(0,0)*F(1,1)) * u(2)) / J;
230 
231  break;
232 
233  case 2:
234  v(0) = ( F(1,1) * u(0) - F(0,1) * u(1)) / J;
235  v(1) = (-F(1,0) * u(0) + F(0,0) * u(1)) / J;
236  break;
237 
238  }
239 
240  return v;
241 }
242 
243 //
244 // Push forward covariant tensor
245 // \param \f$ F, A \f$
246 // \return \f$ F^{-T} A F^{-1} \f$
247 //
248 template<typename T>
249 Tensor<T>
250 push_forward_covariant(Tensor<T> const & F, Tensor<T> const & A)
251 {
252  Index const
253  N = F.get_dimension();
254 
255  Tensor<T>
256  G(N);
257 
258  T const
259  J = det(F);
260 
261  assert(J > 0.0);
262 
263  switch (N) {
264 
265  default:
266  std::cerr << "ERROR: " << __PRETTY_FUNCTION__;
267  std::cerr << std::endl;
268  std::cerr << "Supports only 2D and 3D. Found dimension: " << N;
269  std::cerr << std::endl;
270  exit(1);
271  break;
272 
273  case 3:
274  G(0,0) = (-F(1,2)*F(2,1) + F(1,1)*F(2,2)) / J;
275  G(0,1) = ( F(0,2)*F(2,1) - F(0,1)*F(2,2)) / J;
276  G(0,2) = (-F(0,2)*F(1,1) + F(0,1)*F(1,2)) / J;
277 
278  G(1,0) = ( F(1,2)*F(2,0) - F(1,0)*F(2,2)) / J;
279  G(1,1) = (-F(0,2)*F(2,0) + F(0,0)*F(2,2)) / J;
280  G(1,2) = ( F(0,2)*F(1,0) - F(0,0)*F(1,2)) / J;
281 
282  G(2,0) = (-F(1,1)*F(2,0) + F(1,0)*F(2,1)) / J;
283  G(2,1) = ( F(0,1)*F(2,0) - F(0,0)*F(2,1)) / J;
284  G(2,2) = (-F(0,1)*F(1,0) + F(0,0)*F(1,1)) / J;
285  break;
286 
287  case 2:
288  G(0,0) = F(1,1) / J;
289  G(0,1) = -F(0,1) / J;
290 
291  G(1,0) = -F(1,0) / J;
292  G(1,1) = F(0,0) / J;
293  break;
294 
295  }
296 
297  return t_dot(G, dot(A, G));
298 }
299 
300 //
301 // Pull back covariant tensor
302 // \param \f$ F, A \f$
303 // \return \f$ F^T A F\f$
304 //
305 template<typename T>
306 Tensor<T>
307 pull_back_covariant(Tensor<T> const & F, Tensor<T> const & A)
308 {
309  return t_dot(F, dot(A, F));
310 }
311 
312 //
313 // Push forward contravariant tensor
314 // \param \f$ F, A \f$
315 // \return \f$ F A F^T \f$
316 //
317 template<typename T>
318 Tensor<T>
319 push_forward_contravariant(Tensor<T> const & F, Tensor<T> const & A)
320 {
321  return dot_t(dot(F, A), F);
322 }
323 
324 //
325 // Pull back contravariant tensor
326 // \param \f$ F, A \f$
327 // \return \f$ F^{-1} A F^{-T} \f$
328 //
329 template<typename T>
330 Tensor<T>
331 pull_back_contravariant(Tensor<T> const & F, Tensor<T> const & A)
332 {
333  Index const
334  N = F.get_dimension();
335 
336  Tensor<T>
337  G(N);
338 
339  T const
340  J = det(F);
341 
342  assert(J > 0.0);
343 
344  switch (N) {
345 
346  default:
347  std::cerr << "ERROR: " << __PRETTY_FUNCTION__;
348  std::cerr << std::endl;
349  std::cerr << "Supports only 2D and 3D. Found dimension: " << N;
350  std::cerr << std::endl;
351  exit(1);
352  break;
353 
354  case 3:
355  G(0,0) = (-F(1,2)*F(2,1) + F(1,1)*F(2,2)) / J;
356  G(0,1) = ( F(0,2)*F(2,1) - F(0,1)*F(2,2)) / J;
357  G(0,2) = (-F(0,2)*F(1,1) + F(0,1)*F(1,2)) / J;
358 
359  G(1,0) = ( F(1,2)*F(2,0) - F(1,0)*F(2,2)) / J;
360  G(1,1) = (-F(0,2)*F(2,0) + F(0,0)*F(2,2)) / J;
361  G(1,2) = ( F(0,2)*F(1,0) - F(0,0)*F(1,2)) / J;
362 
363  G(2,0) = (-F(1,1)*F(2,0) + F(1,0)*F(2,1)) / J;
364  G(2,1) = ( F(0,1)*F(2,0) - F(0,0)*F(2,1)) / J;
365  G(2,2) = (-F(0,1)*F(1,0) + F(0,0)*F(1,1)) / J;
366  break;
367 
368  case 2:
369  G(0,0) = F(1,1) / J;
370  G(0,1) = -F(0,1) / J;
371 
372  G(1,0) = -F(1,0) / J;
373  G(1,1) = F(0,0) / J;
374  break;
375 
376  }
377 
378  return dot_t(dot(G, A), G);
379 }
380 
381 //
382 // Piola transformation for vector
383 // \param \f$ F, u \f$
384 // \return \f$ \det F F^{-1} u \f$
385 //
386 template<typename T>
387 Vector<T>
388 piola(Tensor<T> const & F, Vector<T> const & u)
389 {
390  Index const
391  N = F.get_dimension();
392 
393  Vector<T>
394  v(N);
395 
396  switch (N) {
397 
398  default:
399  std::cerr << "ERROR: " << __PRETTY_FUNCTION__;
400  std::cerr << std::endl;
401  std::cerr << "Supports only 2D and 3D. Found dimension: " << N;
402  std::cerr << std::endl;
403  exit(1);
404  break;
405 
406  case 3:
407  v(0) = ((-F(1,2)*F(2,1) + F(1,1)*F(2,2)) * u(0) +
408  ( F(0,2)*F(2,1) - F(0,1)*F(2,2)) * u(1) +
409  (-F(0,2)*F(1,1) + F(0,1)*F(1,2)) * u(2));
410 
411  v(1) = (( F(1,2)*F(2,0) - F(1,0)*F(2,2)) * u(0) +
412  (-F(0,2)*F(2,0) + F(0,0)*F(2,2)) * u(1) +
413  ( F(0,2)*F(1,0) - F(0,0)*F(1,2)) * u(2));
414 
415  v(2) = ((-F(1,1)*F(2,0) + F(1,0)*F(2,1)) * u(0) +
416  ( F(0,1)*F(2,0) - F(0,0)*F(2,1)) * u(1) +
417  (-F(0,1)*F(1,0) + F(0,0)*F(1,1)) * u(2));
418 
419  break;
420 
421  case 2:
422  v(0) = ( F(1,1) * u(0) - F(0,1) * u(1));
423  v(1) = (-F(1,0) * u(0) + F(0,0) * u(1));
424  break;
425 
426  }
427 
428  return v;
429 }
430 
431 //
432 // Inverse Piola transformation for vector
433 // \param \f$ F, u \f$
434 // \return \f$ (\det F)^{-1} F u \f$
435 //
436 template<typename T>
437 Vector<T>
438 piola_inverse(Tensor<T> const & F, Vector<T> const & u)
439 {
440  Index const
441  N = F.get_dimension();
442 
443  Vector<T>
444  v(N);
445 
446  T const
447  J = det(F);
448 
449  assert(J > 0.0);
450 
451  switch (N) {
452 
453  default:
454  std::cerr << "ERROR: " << __PRETTY_FUNCTION__;
455  std::cerr << std::endl;
456  std::cerr << "Supports only 2D and 3D. Found dimension: " << N;
457  std::cerr << std::endl;
458  exit(1);
459  break;
460 
461  case 3:
462  v(0) = (F(0,0) * u(0) + F(0,1) * u(1) + F(0,2) * u(2)) / J;
463  v(1) = (F(1,0) * u(0) + F(1,1) * u(1) + F(1,2) * u(2)) / J;
464  v(2) = (F(2,0) * u(0) + F(2,1) * u(1) + F(2,2) * u(2)) / J;
465 
466  break;
467 
468  case 2:
469  v(0) = (F(0,0) * u(0) + F(0,1) * u(1)) / J;
470  v(1) = (F(1,0) * u(0) + F(1,1) * u(1)) / J;
471 
472  break;
473 
474  }
475 
476  return v;
477 }
478 
479 //
480 // Piola transformation for tensor, applied on second
481 // index. Useful for transforming Cauchy stress to 1PK stress.
482 // \param \f$ F, \sigma \f$
483 // \return \f$ \det F \sigma F^{-T} \f$
484 //
485 template<typename T>
486 Tensor<T>
487 piola(Tensor<T> const & F, Tensor<T> const & sigma)
488 {
489  Index const
490  N = F.get_dimension();
491 
492  Tensor<T>
493  G(N);
494 
495  switch (N) {
496 
497  default:
498  std::cerr << "ERROR: " << __PRETTY_FUNCTION__;
499  std::cerr << std::endl;
500  std::cerr << "Supports only 2D and 3D. Found dimension: " << N;
501  std::cerr << std::endl;
502  exit(1);
503  break;
504 
505  case 3:
506  G(0,0) = (-F(1,2)*F(2,1) + F(1,1)*F(2,2));
507  G(0,1) = ( F(0,2)*F(2,1) - F(0,1)*F(2,2));
508  G(0,2) = (-F(0,2)*F(1,1) + F(0,1)*F(1,2));
509 
510  G(1,0) = ( F(1,2)*F(2,0) - F(1,0)*F(2,2));
511  G(1,1) = (-F(0,2)*F(2,0) + F(0,0)*F(2,2));
512  G(1,2) = ( F(0,2)*F(1,0) - F(0,0)*F(1,2));
513 
514  G(2,0) = (-F(1,1)*F(2,0) + F(1,0)*F(2,1));
515  G(2,1) = ( F(0,1)*F(2,0) - F(0,0)*F(2,1));
516  G(2,2) = (-F(0,1)*F(1,0) + F(0,0)*F(1,1));
517  break;
518 
519  case 2:
520  G(0,0) = F(1,1);
521  G(0,1) = -F(0,1);
522 
523  G(1,0) = -F(1,0);
524  G(1,1) = F(0,0);
525  break;
526 
527  }
528 
529  return dot_t(sigma, G);
530 }
531 
532 //
533 // Inverse Piola transformation for tensor, applied on second
534 // index. Useful for transforming 1PK stress to Cauchy stress.
535 // \param \f$ F, P \f$
536 // \return \f$ (\det F)^{-1} P F^T \f$
537 //
538 template<typename T>
539 Tensor<T>
540 piola_inverse(Tensor<T> const & F, Tensor<T> const & P)
541 {
542  T const
543  J = det(F);
544 
545  assert(J > 0.0);
546 
547  return dot_t(P, F) / J;
548 }
549 
550 //
551 // Check strict ellipticity condition for 4th-order tensor.
552 // Assume A has major symmetries.
553 //
554 template<typename T>
555 bool
556 check_strict_ellipticity(Tensor4<T> const & A)
557 {
558  // Convert to 2nd-order tensor
559  Tensor<T> const
560  B(A);
561 
562  // Check bounds for eigenvalues
563  T const
564  lower_bound = bounds_eigenvalues(B).first;
565 
566  if (lower_bound > 0.0) {
567  return true;
568  }
569 
570  // Get eigenvalues only
571  Vector<T> const
572  D = diag(eig_sym(B).second);
573 
574  T const
575  smallest_eigenvalue = D(B.get_dimension() - 1);
576 
577  if (smallest_eigenvalue > 0.0) {
578  return true;
579  }
580 
581  return false;
582 }
583 
584 //
585 // Check strong ellipticity condition for 4th-order tensor.
586 // Assume A has major symmetries.
587 //
588 template<typename T>
589 std::pair<bool, Vector<T> >
590 check_strong_ellipticity(Tensor4<T> const & A)
591 {
592  bool
593  is_elliptic = true;
594 
595  Index const
596  dimension = A.get_dimension();
597 
598  Vector<T>
599  eigenvector(dimension, 1.0 / dimension);
600 
601  Index const
602  maximum_iterarions = 128;
603 
604  T const
605  tolerance = machine_epsilon<T>();
606 
607  T
608  error = 1.0;
609 
610  T
611  prev_eigenvalue =
612  std::numeric_limits<typename Sacado::ScalarType<T>::type>::max();
613 
614  T
615  curr_eigenvalue = prev_eigenvalue;
616 
617  Index
618  iteration = 0;
619 
620  while (error > tolerance && iteration < maximum_iterarions) {
621 
622  Tensor<T>
623  Q = dot(eigenvector, dot(A, eigenvector));
624 
625  Tensor<T>
626  V;
627 
628  Tensor<T>
629  D;
630 
631  boost::tie(V, D) = eig_sym(Q);
632 
633  curr_eigenvalue = D(dimension - 1, dimension - 1);
634 
635  eigenvector = col(V, dimension - 1);
636 
637  error = std::abs(prev_eigenvalue) / std::abs(curr_eigenvalue) - 1.0;
638 
639  prev_eigenvalue = curr_eigenvalue;
640 
641  ++iteration;
642  }
643 
644  if (curr_eigenvalue <= 0.0) {
645  is_elliptic = false;
646  }
647 
648  return std::make_pair(is_elliptic, eigenvector);
649 }
650 
651 } // namespace Intrepid
652 
653 #endif // Intrepid_MiniTensor_Mechanics_t_h
654 
655 
656 
657