9 #include <xtensor/xadapt.hpp>
10 #include <xtensor/xtensor.hpp>
11 #include <xtensor/xview.hpp>
12 #include <xtl/xspan.hpp>
25 doubleContravariantPiola,
33 template <
typename O,
typename Mat0,
typename Mat1,
typename Mat2>
34 void dot22(O& r,
const Mat0& A,
const Mat1& B,
const Mat2& C)
36 assert(A.shape(1) == B.shape(0));
38 for (std::size_t i = 0; i < r.shape(0); ++i)
39 for (std::size_t j = 0; j < r.shape(1); ++j)
40 for (std::size_t k = 0; k < A.shape(1); ++k)
41 for (std::size_t l = 0; l < B.shape(1); ++l)
42 r(i, j) += A(i, k) * B(k, l) * C(l, j);
45 template <
typename Vec,
typename Mat0,
typename Mat1>
46 void dot21(Vec& r,
const Mat0& A,
const Mat1& B)
50 for (std::size_t i = 0; i < r.shape(0); ++i)
51 for (std::size_t k = 0; k < A.shape(1); ++k)
52 r[i] += A(i, k) * B[k];
55 template <
typename Vec0,
typename Vec1,
typename Mat0,
typename Mat1>
56 void identity(Vec0& r,
const Vec1& U,
const Mat0& ,
double ,
62 template <
typename O,
typename P,
typename Q,
typename R>
63 void covariant_piola(O&& r,
const P& U,
const Q& ,
double ,
66 auto Kt = xt::transpose(K);
67 for (std::size_t p = 0; p < U.shape(0); ++p)
69 auto r_p = xt::row(r, p);
70 auto U_p = xt::row(U, p);
75 template <
typename O,
typename P,
typename Q,
typename R>
76 void contravariant_piola(O&& r,
const P& U,
const Q& J,
double detJ,
79 for (std::size_t p = 0; p < U.shape(0); ++p)
81 auto r_p = xt::row(r, p);
82 auto U_p = xt::row(U, p);
88 template <
typename O,
typename P,
typename Q,
typename R>
89 void double_covariant_piola(O& r,
const P& U,
const Q& J,
double ,
92 for (std::size_t p = 0; p < U.shape(0); ++p)
94 auto r_p = xt::row(r, p);
95 auto U_p = xt::row(U, p);
96 auto _U = xt::reshape_view(U_p, {J.shape(1), J.shape(1)});
97 auto _r = xt::reshape_view(r_p, {K.shape(1), K.shape(1)});
98 dot22(_r, xt::transpose(K), _U, K);
102 template <
typename O,
typename P,
typename Q,
typename R>
103 void double_contravariant_piola(O& r,
const P& U,
const Q& J,
double detJ,
106 auto Jt = xt::transpose(J);
107 for (std::size_t p = 0; p < U.shape(0); ++p)
109 auto r_p = xt::row(r, p);
110 auto U_p = xt::row(U, p);
111 auto _U = xt::reshape_view(U_p, {J.shape(1), J.shape(1)});
112 auto _r = xt::reshape_view(r_p, {J.shape(0), J.shape(0)});
113 dot22(_r, J, _U, Jt);
129 template <
typename O,
typename P,
typename Mat0,
typename Mat1>
130 void apply_map(O&& u,
const P& U,
const Mat0& J,
double detJ,
const Mat1& K,
135 case maps::type::identity:
136 return impl::identity(u, U, J, detJ, K);
137 case maps::type::covariantPiola:
138 return impl::covariant_piola(u, U, J, detJ, K);
139 case maps::type::contravariantPiola:
140 return impl::contravariant_piola(u, U, J, detJ, K);
141 case maps::type::doubleCovariantPiola:
142 return impl::double_covariant_piola(u, U, J, detJ, K);
143 case maps::type::doubleContravariantPiola:
144 return impl::double_contravariant_piola(u, U, J, detJ, K);
146 throw std::runtime_error(
"Mapping not yet implemented");