12#ifndef MFEM_DINVARIANTS_HPP
13#define MFEM_DINVARIANTS_HPP
33 const real_t * J_ =
nullptr;
57 real_t *
const dI1, *
const dI1b, *
const ddI1, *
const ddI1b;
58 real_t *
const dI2, *
const dI2b, *
const ddI2, *
const ddI2b;
64 dI1(
b.dI1_), dI1b(
b.dI1b_), ddI1(
b.ddI1_), ddI1b(
b.ddI1b_),
65 dI2(
b.dI2_), dI2b(
b.dI2b_), ddI2(
b.ddI2_), ddI2b(
b.ddI2b_) { }
69 const real_t I2b = J[0]*J[3] - J[1]*J[2];
70 sign_detJ = I2b >= 0.0 ? 1.0 : -1.0;
71 return sign_detJ * I2b;
88 return J[0]*J[0] + J[1]*J[1] + J[2]*J[2] + J[3]*J[3];
98 dI1[0] = 2*J[0]; dI1[2] = 2*J[2];
99 dI1[1] = 2*J[1]; dI1[3] = 2*J[3];
111 dI1b[0] = c1*(J[0] - c2*dI2b[0]);
112 dI1b[1] = c1*(J[1] - c2*dI2b[1]);
113 dI1b[2] = c1*(J[2] - c2*dI2b[2]);
114 dI1b[3] = c1*(J[3] - c2*dI2b[3]);
138 dI2b[0] = sign_detJ*J[3];
139 dI2b[1] = -sign_detJ*J[2];
140 dI2b[2] = -sign_detJ*J[1];
141 dI2b[3] = sign_detJ*J[0];
150 for (
int k=0; k<2; k++)
152 for (
int l=0; l<2; l++)
154 ddi1(k,l) = (i==k && j==l) ? 2.0 : 0.0;
167 real_t X1_p[4], X2_p[4], X3_p[4];
175 for (
int k=0; k<2; k++)
177 for (
int l=0; l<2; l++)
179 X1(k,l) =
alpha * (di2b(i,j)*di2b(k,l) + di2b(k,j)*di2b(i,l));
186 for (
int k=0; k<2; k++)
188 for (
int l=0; l<2; l++)
190 X2(k,l) =
beta * ddi1(k,l);
197 for (
int k=0; k<2; k++)
199 for (
int l=0; l<2; l++)
201 X3(k,l) = gamma * (Jpt(i,j)*di2b(k,l) + di2b(i,j)*Jpt(k,l));
205 for (
int k=0; k<2; k++)
207 for (
int l=0; l<2; l++)
209 ddi1b(k,l) = X1(k,l) + X2(k,l) + X3(k,l);
221 for (
int k=0; k<2; k++)
223 for (
int l=0; l<2; l++)
225 ddi2(k,l) = 2*di2b(i,j)*di2b(k,l)
226 + 2*(di2b(i,j)*di2b(k,l) - di2b(k,j)*di2b(i,l));
239 for (
int k=0; k<2; k++)
241 for (
int l=0; l<2; l++)
244 for (
int s=0;
s<2;
s++)
246 for (
int t=0;
t<2;
t++)
248 const real_t ks_it = k==
s && i==
t ? 1.0 : 0.0;
249 const real_t kt_si = k==
t &&
s==i ? 1.0 : 0.0;
250 ddi2b(k,l) +=
alpha * (ks_it - kt_si) * di2b(
t,j) * di2b(
s,l);
267 const real_t * J_ =
nullptr;
272 real_t * ddI1b_ =
nullptr;
276 real_t * ddI2b_ =
nullptr;
278 real_t * ddI3b_ =
nullptr;
298 real_t *
const dI1, *
const dI1b, *
const ddI1, *
const ddI1b;
299 real_t *
const dI2, *
const dI2b, *
const ddI2, *
const ddI2b;
300 real_t *
const dI3b, *
const ddI3b;
306 dI1(
b.dI1_), dI1b(
b.dI1b_), ddI1(
b.ddI1_), ddI1b(
b.ddI1b_),
307 dI2(
b.dI2_), dI2b(
b.dI2b_), ddI2(
b.ddI2_), ddI2b(
b.ddI2b_),
308 dI3b(
b.dI3b_), ddI3b(
b.ddI3b_) { }
312 const real_t I3b = + J[0]*(J[4]*J[8] - J[7]*J[5])
313 - J[1]*(J[3]*J[8] - J[5]*J[6])
314 + J[2]*(J[3]*J[7] - J[4]*J[6]);
315 sign_detJ = I3b >= 0.0 ? 1.0 : -1.0;
316 return sign_detJ * I3b;
321 const real_t I3b = + J[0]*(J[4]*J[8] - J[7]*J[5])
322 - J[1]*(J[3]*J[8] - J[5]*J[6])
323 + J[2]*(J[3]*J[7] - J[4]*J[6]);
337 return sign_detJ * std::pow(i3b, -2./3.);
343 return sign_detJ * std::pow(i3b, -2./3.);
348 B[0] = J[0]*J[0] + J[3]*J[3] + J[6]*J[6];
349 B[1] = J[1]*J[1] + J[4]*J[4] + J[7]*J[7];
350 B[2] = J[2]*J[2] + J[5]*J[5] + J[8]*J[8];
351 const real_t I1 = B[0] + B[1] + B[2];
355 MFEM_HOST_DEVICE
inline
366 B[3] = J[0]*J[1] + J[3]*J[4] + J[6]*J[7];
367 B[4] = J[0]*J[2] + J[3]*J[5] + J[6]*J[8];
368 B[5] = J[1]*J[2] + J[4]*J[5] + J[7]*J[8];
375 const real_t BF2 = B[0]*B[0] + B[1]*B[1] + B[2]*B[2] +
376 2*(B[3]*B[3] + B[4]*B[4] + B[5]*B[5]);
377 const real_t I2 = (I1*I1 - BF2)/2;
384 return Get_I2() * I3b_p * I3b_p;
389 for (
int i = 0; i < 9; i++) { dI1[i] = 2*J[i]; }
400 const real_t c1 = 2.0 * I3b_p;
403 for (
int i = 0; i < 9; i++) { dI1b[i] = c1*(J[i] - c2*dI3b[i]); }
416 2*(I1 - B[0]), 2*(I1 - B[1]), 2*(I1 - B[2]),
417 -2*B[3], -2*B[4], -2*B[5]
422 dI2[0] = C[0]*J[0] + C[3]*J[1] + C[4]*J[2];
423 dI2[1] = C[3]*J[0] + C[1]*J[1] + C[5]*J[2];
424 dI2[2] = C[4]*J[0] + C[5]*J[1] + C[2]*J[2];
426 dI2[3] = C[0]*J[3] + C[3]*J[4] + C[4]*J[5];
427 dI2[4] = C[3]*J[3] + C[1]*J[4] + C[5]*J[5];
428 dI2[5] = C[4]*J[3] + C[5]*J[4] + C[2]*J[5];
430 dI2[6] = C[0]*J[6] + C[3]*J[7] + C[4]*J[8];
431 dI2[7] = C[3]*J[6] + C[1]*J[7] + C[5]*J[8];
432 dI2[8] = C[4]*J[6] + C[5]*J[7] + C[2]*J[8];
445 const real_t c1 = I3b_p*I3b_p;
446 const real_t c2 = (4*I2/I3b)/3;
449 for (
int i = 0; i < 9; i++) { dI2b[i] = c1*(dI2[i] - c2*dI3b[i]); }
457 dI3b[0] = sign_detJ*(J[4]*J[8] - J[5]*J[7]);
458 dI3b[1] = sign_detJ*(J[5]*J[6] - J[3]*J[8]);
459 dI3b[2] = sign_detJ*(J[3]*J[7] - J[4]*J[6]);
460 dI3b[3] = sign_detJ*(J[2]*J[7] - J[1]*J[8]);
461 dI3b[4] = sign_detJ*(J[0]*J[8] - J[2]*J[6]);
462 dI3b[5] = sign_detJ*(J[1]*J[6] - J[0]*J[7]);
463 dI3b[6] = sign_detJ*(J[1]*J[5] - J[2]*J[4]);
464 dI3b[7] = sign_detJ*(J[2]*J[3] - J[0]*J[5]);
465 dI3b[8] = sign_detJ*(J[0]*J[4] - J[1]*J[3]);
473 for (
int k=0; k<3; k++)
475 for (
int l=0; l<3; l++)
477 const real_t I_ijkl = (i==k && j==l) ? 1.0 : 0.0;
478 ddi1(k,l) = 2.0 * I_ijkl;
493 real_t X1_p[9], X2_p[9], X3_p[9];
499 for (
int k=0; k<3; k++)
501 for (
int l=0; l<3; l++)
503 X1(k,l) =
alpha * ((2./3.)*di3b(i,j) * di3b(k,l) +
504 di3b(k,j)*di3b(i,l));
511 for (
int k=0; k<3; k++)
513 for (
int l=0; l<3; l++)
515 const real_t ddI1_ijkl = (i==k && j==l) ? 2.0 : 0.0;
516 X2(k,l) =
beta * ddI1_ijkl;
524 for (
int k=0; k<3; k++)
526 for (
int l=0; l<3; l++)
528 X3(k,l) = gamma * (Jpt(i,j) * di3b(k,l) + di3b(i,j) * Jpt(k,l));
532 for (
int k=0; k<3; k++)
534 for (
int l=0; l<3; l++)
536 ddi1b(k,l) = X1(k,l) + X2(k,l) + X3(k,l);
548 real_t x1_p[9], x2_p[9], x3_p[9];
552 for (
int k=0; k<3; k++)
554 for (
int l=0; l<3; l++)
556 const real_t ik_jl = (i==k && j==l) ? 1.0 : 0.0;
557 x1(k,l) = 2.0 * I1 * ik_jl;
562 for (
int k=0; k<3; k++)
564 for (
int l=0; l<3; l++)
567 for (
int u=0;
u<3;
u++)
569 for (
int v=0; v<3; v++)
571 const real_t ku_iv = k==
u && i==v ? 1.0 : 0.0;
572 const real_t ik_uv = i==k &&
u==v ? 1.0 : 0.0;
573 const real_t kv_iu = k==v && i==
u ? 1.0 : 0.0;
574 x2(k,l) += 2.0*(2.*ku_iv-ik_uv-kv_iu)*Jpt(v,j)*Jpt(
u,l);
580 B[0] = J[0]*J[0] + J[3]*J[3] + J[6]*J[6];
581 B[1] = J[1]*J[1] + J[4]*J[4] + J[7]*J[7];
582 B[2] = J[2]*J[2] + J[5]*J[5] + J[8]*J[8];
583 B[3] = J[0]*J[1] + J[3]*J[4] + J[6]*J[7];
584 B[4] = J[0]*J[2] + J[3]*J[5] + J[6]*J[8];
585 B[5] = J[1]*J[2] + J[4]*J[5] + J[7]*J[8];
593 for (
int k=0; k<3; k++)
595 for (
int l=0; l<3; l++)
597 const real_t jl = j==l ? 1.0 : 0.0;
598 x3(k,l) = -2.0 *
b(i,k) * jl;
603 for (
int k=0; k<3; k++)
605 for (
int l=0; l<3; l++)
607 ddi2(k,l) = x1(k,l) + x2(k,l) + x3(k,l);
620 real_t X1_p[9], X2_p[9], X3_p[9];
628 const real_t I3b_p43 = I3b_p*I3b_p;
629 const real_t I3b_p73 = I3b_p*I3b_p/I3b;
630 const real_t I3b_p103 = I3b_p*I3b_p/(I3b*I3b);
632 for (
int k=0; k<3; k++)
634 for (
int l=0; l<3; l++)
636 const real_t up = (16./9.)*I3b_p103*I2*di3b(i,j)*di3b(k,l);
637 const real_t down = (4./3.)*I3b_p103*I2*di3b(i,l)*di3b(k,j);
644 for (
int k=0; k<3; k++)
646 for (
int l=0; l<3; l++)
648 X2(k,l) = -(4./3.)*I3b_p73*(di2(i,j)*di3b(k,l)+di2(k,l)*di3b(i,j));
654 for (
int k=0; k<3; k++)
656 for (
int l=0; l<3; l++)
658 X3(k,l) = I3b_p43 * ddi2(k,l);
663 for (
int k=0; k<3; k++)
665 for (
int l=0; l<3; l++)
667 ddi2b(k,l) = X1(k,l) + X2(k,l) + X3(k,l);
680 for (
int k=0; k<3; k++)
682 for (
int l=0; l<3; l++)
685 for (
int s=0;
s<3;
s++)
687 for (
int t=0;
t<3;
t++)
689 const real_t ks_it = k==
s && i==
t ? 1.0 : 0.0;
690 const real_t kt_si = k==
t &&
s==i ? 1.0 : 0.0;
691 ddi3b(k,l) += c1*(ks_it-kt_si)*di3b(
t,j)*di3b(
s,l);
A basic generic Tensor class, appropriate for use on the GPU.
MFEM_HOST_DEVICE Buffers()
MFEM_HOST_DEVICE Buffers & dI2(real_t *b)
MFEM_HOST_DEVICE Buffers & dI2b(real_t *b)
MFEM_HOST_DEVICE Buffers & ddI2b(real_t *b)
MFEM_HOST_DEVICE Buffers & J(const real_t *b)
MFEM_HOST_DEVICE Buffers & ddI2(real_t *b)
MFEM_HOST_DEVICE Buffers & dI1(real_t *b)
MFEM_HOST_DEVICE Buffers & ddI1b(real_t *b)
MFEM_HOST_DEVICE Buffers & ddI1(real_t *b)
MFEM_HOST_DEVICE Buffers & dI1b(real_t *b)
MFEM_HOST_DEVICE real_t * Get_ddI2b(int i, int j)
MFEM_HOST_DEVICE real_t * Get_dI2()
MFEM_HOST_DEVICE real_t Get_I2()
MFEM_HOST_DEVICE InvariantsEvaluator2D(Buffers &b)
MFEM_HOST_DEVICE real_t * Get_ddI1b(int i, int j)
MFEM_HOST_DEVICE real_t * Get_dI2b()
MFEM_HOST_DEVICE real_t * Get_ddI2(int i, int j)
MFEM_HOST_DEVICE real_t Get_I2b()
MFEM_HOST_DEVICE real_t Get_I1()
MFEM_HOST_DEVICE real_t Get_I2b(real_t &sign_detJ)
MFEM_HOST_DEVICE real_t * Get_ddI1(int i, int j)
MFEM_HOST_DEVICE real_t * Get_dI1()
MFEM_HOST_DEVICE real_t * Get_dI1b()
MFEM_HOST_DEVICE real_t Get_I1b()
MFEM_HOST_DEVICE Buffers & dI2(real_t *b)
MFEM_HOST_DEVICE Buffers & ddI1(real_t *b)
MFEM_HOST_DEVICE Buffers & J(const real_t *b)
MFEM_HOST_DEVICE Buffers()
MFEM_HOST_DEVICE Buffers & B(real_t *b)
MFEM_HOST_DEVICE Buffers & ddI2(real_t *b)
MFEM_HOST_DEVICE Buffers & dI1(real_t *b)
MFEM_HOST_DEVICE Buffers & dI3b(real_t *b)
MFEM_HOST_DEVICE Buffers & dI2b(real_t *b)
MFEM_HOST_DEVICE Buffers & dI1b(real_t *b)
MFEM_HOST_DEVICE Buffers & ddI2b(real_t *b)
MFEM_HOST_DEVICE Buffers & ddI1b(real_t *b)
MFEM_HOST_DEVICE Buffers & ddI3b(real_t *b)
MFEM_HOST_DEVICE real_t Get_I3()
MFEM_HOST_DEVICE real_t Get_I3b(real_t &sign_detJ)
MFEM_HOST_DEVICE real_t Get_I3b_p()
MFEM_HOST_DEVICE real_t * Get_dI2()
MFEM_HOST_DEVICE real_t * Get_dI1b()
MFEM_HOST_DEVICE real_t * Get_dI3b(const real_t sign_detJ)
MFEM_HOST_DEVICE void Get_B_offd()
MFEM_HOST_DEVICE real_t * Get_ddI2b(int i, int j)
MFEM_HOST_DEVICE real_t Get_I3b()
MFEM_HOST_DEVICE real_t Get_I1b()
MFEM_HOST_DEVICE real_t * Get_ddI2(int i, int j)
MFEM_HOST_DEVICE real_t * Get_ddI1(int i, int j)
MFEM_HOST_DEVICE real_t Get_I1()
MFEM_HOST_DEVICE real_t * Get_dI1()
MFEM_HOST_DEVICE real_t * Get_dI2b()
MFEM_HOST_DEVICE InvariantsEvaluator3D(Buffers &b)
MFEM_HOST_DEVICE real_t * Get_ddI1b(int i, int j)
MFEM_HOST_DEVICE real_t Get_I3b_p(real_t &sign_detJ)
MFEM_HOST_DEVICE real_t Get_I2b()
MFEM_HOST_DEVICE real_t Get_I2()
MFEM_HOST_DEVICE real_t * Get_ddI3b(int i, int j)
real_t u(const Vector &xvec)