MiniTensor Version of the Day
Loading...
Searching...
No Matches
MiniTensor_Mechanics.h
Go to the documentation of this file.
1// @HEADER
2// *****************************************************************************
3// MiniTensor Package
4//
5// Copyright 2016 NTESS and the MiniTensor contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8// @HEADER
9
10#if !defined(MiniTensor_Mechanics_h)
11#define MiniTensor_Mechanics_h
12
13#include "MiniTensor_Tensor.h"
14
15namespace minitensor {
16
19
25template<typename T, Index N>
28vol(Tensor<T, N> const & A);
29
35template<typename T, Index N>
38dev(Tensor<T, N> const & A);
39
46template<typename T, Index N>
50
57template<typename T, Index N>
61
68template<typename T, Index N>
72
79template<typename T, Index N>
83
90template<typename T, Index N>
94
101template<typename T, Index N>
104pull_back_covariant(Tensor<T, N> const & F, Tensor<T, N> const & A);
105
112template<typename T, Index N>
116
123template<typename T, Index N>
127
134template<typename T, Index N>
137piola(Tensor<T, N> const & F, Vector<T, N> const & u);
138
145template<typename T, Index N>
148piola_inverse(Tensor<T, N> const & F, Vector<T, N> const & u);
149
157template<typename T, Index N>
160piola(Tensor<T, N> const & F, Tensor<T, N> const & sigma);
161
169template<typename T, Index N>
172piola_inverse(Tensor<T, N> const & F, Tensor<T, N> const & P);
173
177template<typename T, Index N>
179T
181
188template<typename T, Index N>
189std::pair<bool, Vector<T, N>>
191
192} // namespace minitensor
193
194namespace minitensor {
195
196//
197// R^N volumetric part of 2nd-order tensor
198// \return \f$ \frac{1}{N} \mathrm{tr}\:(A) I \f$
199//
200template<typename T, Index N>
204{
205 Index const
206 dimension = A.get_dimension();
207
208 T const
209 theta = (1.0/dimension) * trace(A);
210
211 return theta * eye<T, N>(dimension);
212}
213
214//
215// R^N deviatoric part of 2nd-order tensor
216// \return \f$ A - vol(A) \f$
217//
218template<typename T, Index N>
220Tensor<T, N>
222{
223 return A - vol(A);
224}
225
226} // namespace minitensor
227namespace minitensor {
228
229//
230// Push forward covariant vector
231// \param \f$ F, u \f$
232// \return \f$ F^{-T} u \f$
233//
234template<typename T, Index N>
238{
239 Index const
240 dimension = F.get_dimension();
241
243 v(dimension);
244
245 T const
246 J = det(F);
247
248 assert(J > 0.0);
249
250 switch (dimension) {
251
252 default:
253 MT_ERROR_EXIT("Supports only 2D and 3D.");
254 break;
255
256 case 3:
257 v(0) = (
258 (-F(1,2)*F(2,1) + F(1,1)*F(2,2)) * u(0) +
259 ( F(1,2)*F(2,0) - F(1,0)*F(2,2)) * u(1) +
260 (-F(1,1)*F(2,0) + F(1,0)*F(2,1)) * u(2)) / J;
261
262 v(1) = (
263 ( F(0,2)*F(2,1) - F(0,1)*F(2,2)) * u(0) +
264 (-F(0,2)*F(2,0) + F(0,0)*F(2,2)) * u(1) +
265 ( F(0,1)*F(2,0) - F(0,0)*F(2,1)) * u(2)) / J;
266
267 v(2) = (
268 (-F(0,2)*F(1,1) + F(0,1)*F(1,2)) * u(0) +
269 ( F(0,2)*F(1,0) - F(0,0)*F(1,2)) * u(1) +
270 (-F(0,1)*F(1,0) + F(0,0)*F(1,1)) * u(2)) / J;
271
272 break;
273
274 case 2:
275 v(0) = ( F(1,1) * u(0) - F(1,0) * u(1)) / J;
276 v(1) = (-F(0,1) * u(0) + F(0,0) * u(1)) / J;
277 break;
278
279 }
280
281 return v;
282}
283
284//
285// Pull back covariant vector
286// \param \f$ F, v \f$
287// \return \f$ F^T v \f$
288//
289template<typename T, Index N>
291Vector<T, N>
293{
294 Index const
295 dimension = F.get_dimension();
296
298 v(dimension);
299
300 switch (dimension) {
301
302 default:
303 MT_ERROR_EXIT("Supports only 2D and 3D.");
304 break;
305
306 case 3:
307 v(0) = F(0,0) * u(0) + F(1,0) * u(1) + F(2,0) * u(2);
308 v(1) = F(0,1) * u(0) + F(1,1) * u(1) + F(2,1) * u(2);
309 v(2) = F(0,2) * u(0) + F(1,2) * u(1) + F(2,2) * u(2);
310
311 break;
312
313 case 2:
314 v(0) = F(0,0) * u(0) + F(1,0) * u(1);
315 v(1) = F(0,1) * u(0) + F(1,1) * u(1);
316
317 break;
318
319 }
320
321 return v;
322}
323
324//
325// Push forward contravariant vector
326// \param \f$ F, u \f$
327// \return \f$ F u \f$
328//
329template<typename T, Index N>
331Vector<T, N>
333{
334 Index const
335 dimension = F.get_dimension();
336
338 v(dimension);
339
340 switch (dimension) {
341
342 default:
343 MT_ERROR_EXIT("Supports only 2D and 3D.");
344 break;
345
346 case 3:
347 v(0) = F(0,0) * u(0) + F(0,1) * u(1) + F(0,2) * u(2);
348 v(1) = F(1,0) * u(0) + F(1,1) * u(1) + F(1,2) * u(2);
349 v(2) = F(2,0) * u(0) + F(2,1) * u(1) + F(2,2) * u(2);
350
351 break;
352
353 case 2:
354 v(0) = F(0,0) * u(0) + F(0,1) * u(1);
355 v(1) = F(1,0) * u(0) + F(1,1) * u(1);
356
357 break;
358
359 }
360
361 return v;
362}
363
364//
365// Pull back contravariant vector
366// \param \f$ F, u \f$
367// \return \f$ F^{-1} u \f$
368//
369template<typename T, Index N>
371Vector<T, N>
373{
374 Index const
375 dimension = F.get_dimension();
376
378 v(dimension);
379
380 T const
381 J = det(F);
382
383 assert(J > 0.0);
384
385 switch (dimension) {
386
387 default:
388 MT_ERROR_EXIT("Supports only 2D and 3D.");
389 break;
390
391 case 3:
392 v(0) = (
393 (-F(1,2)*F(2,1) + F(1,1)*F(2,2)) * u(0) +
394 ( F(0,2)*F(2,1) - F(0,1)*F(2,2)) * u(1) +
395 (-F(0,2)*F(1,1) + F(0,1)*F(1,2)) * u(2)) / J;
396
397 v(1) = (
398 ( F(1,2)*F(2,0) - F(1,0)*F(2,2)) * u(0) +
399 (-F(0,2)*F(2,0) + F(0,0)*F(2,2)) * u(1) +
400 ( F(0,2)*F(1,0) - F(0,0)*F(1,2)) * u(2)) / J;
401
402 v(2) = (
403 (-F(1,1)*F(2,0) + F(1,0)*F(2,1)) * u(0) +
404 ( F(0,1)*F(2,0) - F(0,0)*F(2,1)) * u(1) +
405 (-F(0,1)*F(1,0) + F(0,0)*F(1,1)) * u(2)) / J;
406
407 break;
408
409 case 2:
410 v(0) = ( F(1,1) * u(0) - F(0,1) * u(1)) / J;
411 v(1) = (-F(1,0) * u(0) + F(0,0) * u(1)) / J;
412 break;
413
414 }
415
416 return v;
417}
418
419//
420// Push forward covariant tensor
421// \param \f$ F, A \f$
422// \return \f$ F^{-T} A F^{-1} \f$
423//
424template<typename T, Index N>
426Tensor<T, N>
428{
429 Index const
430 dimension = F.get_dimension();
431
433 G(dimension);
434
435 T const
436 J = det(F);
437
438 assert(J > 0.0);
439
440 switch (dimension) {
441
442 default:
443 MT_ERROR_EXIT("Supports only 2D and 3D.");
444 break;
445
446 case 3:
447 G(0,0) = (-F(1,2)*F(2,1) + F(1,1)*F(2,2)) / J;
448 G(0,1) = ( F(0,2)*F(2,1) - F(0,1)*F(2,2)) / J;
449 G(0,2) = (-F(0,2)*F(1,1) + F(0,1)*F(1,2)) / J;
450
451 G(1,0) = ( F(1,2)*F(2,0) - F(1,0)*F(2,2)) / J;
452 G(1,1) = (-F(0,2)*F(2,0) + F(0,0)*F(2,2)) / J;
453 G(1,2) = ( F(0,2)*F(1,0) - F(0,0)*F(1,2)) / J;
454
455 G(2,0) = (-F(1,1)*F(2,0) + F(1,0)*F(2,1)) / J;
456 G(2,1) = ( F(0,1)*F(2,0) - F(0,0)*F(2,1)) / J;
457 G(2,2) = (-F(0,1)*F(1,0) + F(0,0)*F(1,1)) / J;
458 break;
459
460 case 2:
461 G(0,0) = F(1,1) / J;
462 G(0,1) = -F(0,1) / J;
463
464 G(1,0) = -F(1,0) / J;
465 G(1,1) = F(0,0) / J;
466 break;
467
468 }
469
470 return t_dot(G, dot(A, G));
471}
472
473//
474// Pull back covariant tensor
475// \param \f$ F, A \f$
476// \return \f$ F^T A F\f$
477//
478template<typename T, Index N>
480Tensor<T, N>
482{
483 return t_dot(F, dot(A, F));
484}
485
486//
487// Push forward contravariant tensor
488// \param \f$ F, A \f$
489// \return \f$ F A F^T \f$
490//
491template<typename T, Index N>
493Tensor<T, N>
495{
496 return dot_t(dot(F, A), F);
497}
498
499//
500// Pull back contravariant tensor
501// \param \f$ F, A \f$
502// \return \f$ F^{-1} A F^{-T} \f$
503//
504template<typename T, Index N>
506Tensor<T, N>
508{
509 Index const
510 dimension = F.get_dimension();
511
513 G(dimension);
514
515 T const
516 J = det(F);
517
518 assert(J > 0.0);
519
520 switch (dimension) {
521
522 default:
523 MT_ERROR_EXIT("Supports only 2D and 3D.");
524 break;
525
526 case 3:
527 G(0,0) = (-F(1,2)*F(2,1) + F(1,1)*F(2,2)) / J;
528 G(0,1) = ( F(0,2)*F(2,1) - F(0,1)*F(2,2)) / J;
529 G(0,2) = (-F(0,2)*F(1,1) + F(0,1)*F(1,2)) / J;
530
531 G(1,0) = ( F(1,2)*F(2,0) - F(1,0)*F(2,2)) / J;
532 G(1,1) = (-F(0,2)*F(2,0) + F(0,0)*F(2,2)) / J;
533 G(1,2) = ( F(0,2)*F(1,0) - F(0,0)*F(1,2)) / J;
534
535 G(2,0) = (-F(1,1)*F(2,0) + F(1,0)*F(2,1)) / J;
536 G(2,1) = ( F(0,1)*F(2,0) - F(0,0)*F(2,1)) / J;
537 G(2,2) = (-F(0,1)*F(1,0) + F(0,0)*F(1,1)) / J;
538 break;
539
540 case 2:
541 G(0,0) = F(1,1) / J;
542 G(0,1) = -F(0,1) / J;
543
544 G(1,0) = -F(1,0) / J;
545 G(1,1) = F(0,0) / J;
546 break;
547
548 }
549
550 return dot_t(dot(G, A), G);
551}
552
553//
554// Piola transformation for vector
555// \param \f$ F, u \f$
556// \return \f$ \det F F^{-1} u \f$
557//
558template<typename T, Index N>
560Vector<T, N>
561piola(Tensor<T, N> const & F, Vector<T, N> const & u)
562{
563 Index const
564 dimension = F.get_dimension();
565
567 v(dimension);
568
569 switch (dimension) {
570
571 default:
572 MT_ERROR_EXIT("Supports only 2D and 3D.");
573 break;
574
575 case 3:
576 v(0) = (
577 (-F(1,2)*F(2,1) + F(1,1)*F(2,2)) * u(0) +
578 ( F(0,2)*F(2,1) - F(0,1)*F(2,2)) * u(1) +
579 (-F(0,2)*F(1,1) + F(0,1)*F(1,2)) * u(2));
580
581 v(1) = (
582 ( F(1,2)*F(2,0) - F(1,0)*F(2,2)) * u(0) +
583 (-F(0,2)*F(2,0) + F(0,0)*F(2,2)) * u(1) +
584 ( F(0,2)*F(1,0) - F(0,0)*F(1,2)) * u(2));
585
586 v(2) = (
587 (-F(1,1)*F(2,0) + F(1,0)*F(2,1)) * u(0) +
588 ( F(0,1)*F(2,0) - F(0,0)*F(2,1)) * u(1) +
589 (-F(0,1)*F(1,0) + F(0,0)*F(1,1)) * u(2));
590
591 break;
592
593 case 2:
594 v(0) = ( F(1,1) * u(0) - F(0,1) * u(1));
595 v(1) = (-F(1,0) * u(0) + F(0,0) * u(1));
596 break;
597
598 }
599
600 return v;
601}
602
603//
604// Inverse Piola transformation for vector
605// \param \f$ F, u \f$
606// \return \f$ (\det F)^{-1} F u \f$
607//
608template<typename T, Index N>
610Vector<T, N>
612{
613 Index const
614 dimension = F.get_dimension();
615
617 v(dimension);
618
619 T const
620 J = det(F);
621
622 assert(J > 0.0);
623
624 switch (dimension) {
625
626 default:
627 MT_ERROR_EXIT("Supports only 2D and 3D.");
628 break;
629
630 case 3:
631 v(0) = (F(0,0) * u(0) + F(0,1) * u(1) + F(0,2) * u(2)) / J;
632 v(1) = (F(1,0) * u(0) + F(1,1) * u(1) + F(1,2) * u(2)) / J;
633 v(2) = (F(2,0) * u(0) + F(2,1) * u(1) + F(2,2) * u(2)) / J;
634
635 break;
636
637 case 2:
638 v(0) = (F(0,0) * u(0) + F(0,1) * u(1)) / J;
639 v(1) = (F(1,0) * u(0) + F(1,1) * u(1)) / J;
640
641 break;
642
643 }
644
645 return v;
646}
647
648//
649// Piola transformation for tensor, applied on second
650// index. Useful for transforming Cauchy stress to 1PK stress.
651// \param \f$ F, \sigma \f$
652// \return \f$ \det F \sigma F^{-T} \f$
653//
654template<typename T, Index N>
656Tensor<T, N>
657piola(Tensor<T, N> const & F, Tensor<T, N> const & sigma)
658{
659 Index const
660 dimension = F.get_dimension();
661
663 G(dimension);
664
665 switch (dimension) {
666
667 default:
668 MT_ERROR_EXIT("Supports only 2D and 3D.");
669 break;
670
671 case 3:
672 G(0,0) = (-F(1,2)*F(2,1) + F(1,1)*F(2,2));
673 G(0,1) = ( F(0,2)*F(2,1) - F(0,1)*F(2,2));
674 G(0,2) = (-F(0,2)*F(1,1) + F(0,1)*F(1,2));
675
676 G(1,0) = ( F(1,2)*F(2,0) - F(1,0)*F(2,2));
677 G(1,1) = (-F(0,2)*F(2,0) + F(0,0)*F(2,2));
678 G(1,2) = ( F(0,2)*F(1,0) - F(0,0)*F(1,2));
679
680 G(2,0) = (-F(1,1)*F(2,0) + F(1,0)*F(2,1));
681 G(2,1) = ( F(0,1)*F(2,0) - F(0,0)*F(2,1));
682 G(2,2) = (-F(0,1)*F(1,0) + F(0,0)*F(1,1));
683 break;
684
685 case 2:
686 G(0,0) = F(1,1);
687 G(0,1) = -F(0,1);
688
689 G(1,0) = -F(1,0);
690 G(1,1) = F(0,0);
691 break;
692
693 }
694
695 return dot_t(sigma, G);
696}
697
698//
699// Inverse Piola transformation for tensor, applied on second
700// index. Useful for transforming 1PK stress to Cauchy stress.
701// \param \f$ F, P \f$
702// \return \f$ (\det F)^{-1} P F^T \f$
703//
704template<typename T, Index N>
706Tensor<T, N>
708{
709 T const
710 J = det(F);
711
712 assert(J > 0.0);
713
714 return dot_t(P, F) / J;
715}
716
717//
718// Smallest eigenvalue by inverse iteration.
719//
720template<typename T, Index N>
722T
724{
726 B = inverse(A);
727
728 T const
729 tolerance = machine_epsilon<T>();
730
731 Index const
732 dimension = A.get_dimension();
733
735 v(dimension, Filler::ONES);
736
737 Index const
738 maximum_iterations = 128;
739
740 T
741 relative_error = 1.0;
742
743 Index
744 k = 0;
745
746 while (relative_error > tolerance && k < maximum_iterations) {
747
748 Vector<T, N> const
749 w = v;
750
751 v = unit(B * w);
752
753 relative_error = norm(v - w) / norm(w);
754
755 ++k;
756 }
757
758 return v * A * v;
759}
760
761//
762// Check strong ellipticity condition for 4th-order tensor.
763// Assume A has major and minor symmetries.
764//
765template<typename T, Index N>
766std::pair<bool, Vector<T, N>>
768{
769 bool
770 is_elliptic = true;
771
772 Index const
773 dimension = A.get_dimension();
774
776 eigenvector(dimension, Filler::ONES);
777
778 eigenvector /= dimension;
779
780 Index const
781 maximum_iterarions = 128;
782
783 T const
784 tolerance = machine_epsilon<T>();
785
786 T
787 error = 1.0;
788
789#if defined(KOKKOS_ENABLE_CUDA)
790 T
791 prev_eigenvalue = DBL_MAX;
792#else
793 using S = typename Sacado::ScalarType<T>::type;
794
795 T
796 prev_eigenvalue = std::numeric_limits<S>::max();
797#endif
798
799 T
800 curr_eigenvalue = prev_eigenvalue;
801
802 Index
803 iteration = 0;
804
805 while (error > tolerance && iteration < maximum_iterarions) {
806
808 Q = dot2(eigenvector, dot(A, eigenvector));
809
811 V;
812
814 D;
815
816 std::tie(V, D) = eig_sym(Q);
817
818 curr_eigenvalue = D(dimension - 1, dimension - 1);
819
820 eigenvector = col(V, dimension - 1);
821
822 error = std::abs(prev_eigenvalue) / std::abs(curr_eigenvalue) - 1.0;
823
824 prev_eigenvalue = curr_eigenvalue;
825
826 ++iteration;
827 }
828
829 if (curr_eigenvalue <= 0.0) {
830 is_elliptic = false;
831 }
832
833 return std::make_pair(is_elliptic, eigenvector);
834}
835
837} // namespace minitensor
838
839#endif // MiniTensor_Mechanics_h
#define KOKKOS_INLINE_FUNCTION
#define MT_ERROR_EXIT(...)
KOKKOS_INLINE_FUNCTION Tensor< T, N > const eye()
KOKKOS_INLINE_FUNCTION Index get_dimension() const
KOKKOS_INLINE_FUNCTION Vector< T, M > col(Matrix< T, M, N > const &A, Index const j)
KOKKOS_INLINE_FUNCTION Index get_dimension() const
KOKKOS_INLINE_FUNCTION Matrix< typename Promote< S, T >::type, M, N > dot_t(Matrix< S, M, P > const &A, Matrix< T, N, P > const &B)
KOKKOS_INLINE_FUNCTION Vector< typename Promote< S, T >::type, M > dot(Matrix< T, M, N > const &A, Vector< S, N > const &u)
KOKKOS_INLINE_FUNCTION Matrix< typename Promote< S, T >::type, M, N > t_dot(Matrix< S, P, M > const &A, Matrix< T, P, N > const &B)
KOKKOS_INLINE_FUNCTION Tensor< typename Promote< S, T >::type, N > dot2(Tensor3< T, N > const &A, Vector< S > const &u)
std::pair< Tensor< T, N >, Tensor< T, N > > eig_sym(Tensor< T, N > const &A)
KOKKOS_INLINE_FUNCTION Tensor< T, N > inverse(Tensor< T, N > const &A)
std::pair< bool, Vector< T, N > > check_strong_ellipticity(Tensor4< T, N > const &A)
KOKKOS_INLINE_FUNCTION Vector< T, N > piola(Tensor< T, N > const &F, Vector< T, N > const &u)
KOKKOS_INLINE_FUNCTION Vector< T, N > push_forward_contravariant(Tensor< T, N > const &F, Vector< T, N > const &u)
KOKKOS_INLINE_FUNCTION Tensor< T, N > dev(Tensor< T, N > const &A)
KOKKOS_INLINE_FUNCTION Vector< T, N > push_forward_covariant(Tensor< T, N > const &F, Vector< T, N > const &u)
KOKKOS_INLINE_FUNCTION Vector< T, N > pull_back_covariant(Tensor< T, N > const &F, Vector< T, N > const &u)
KOKKOS_INLINE_FUNCTION T smallest_eigenvalue(Tensor< T, N > const &A)
KOKKOS_INLINE_FUNCTION Tensor< T, N > vol(Tensor< T, N > const &A)
KOKKOS_INLINE_FUNCTION Vector< T, N > pull_back_contravariant(Tensor< T, N > const &F, Vector< T, N > const &u)
KOKKOS_INLINE_FUNCTION Vector< T, N > piola_inverse(Tensor< T, N > const &F, Vector< T, N > const &u)
KOKKOS_INLINE_FUNCTION T norm(Tensor< T, N > const &A)
KOKKOS_INLINE_FUNCTION T det(Tensor< T, N > const &A)
KOKKOS_INLINE_FUNCTION T trace(Tensor< T, N > const &A)
KOKKOS_INLINE_FUNCTION Quaternion< T > unit(Quaternion< T > const &q)
KOKKOS_INLINE_FUNCTION Sacado::ScalarType< T >::type machine_epsilon()
uint32_t Index
Indexing type.