24 static constexpr int nv = 4;
25 static constexpr int ne = 4;
26 static constexpr int dim = 2;
27 static constexpr int ddm2 = (
dim*(
dim+1))/2;
28 static constexpr int ngeom = ddm2 + 1;
29 static constexpr int o = ORDER;
30 static constexpr int op1 = ORDER + 1;
31 static constexpr int ndof_per_el =
dim*o*op1;
32 static constexpr int nnz_per_row = 7;
33 static constexpr int sz_local_mat = ne*ne;
35 const bool const_mq =
c1.
Size() == 1;
36 const auto MQ = const_mq
39 const bool const_dq =
c2.
Size() == 1;
40 const auto DQ = const_dq
55 MFEM_FOREACH_THREAD(iy,y,o)
57 MFEM_FOREACH_THREAD(ix,x,op1)
59 for (
int c=0; c<2; ++c)
61 for (
int j=0; j<nnz_per_row; ++j)
63 V(j,ix+iy*op1,c,iel_ho) = 0.0;
71 MFEM_FOREACH_THREAD(ky,y,ORDER)
73 MFEM_FOREACH_THREAD(kx,x,ORDER)
77 real_t local_mat_[sz_local_mat];
83 for (
int i=0; i<sz_local_mat; ++i) { local_mat[i] = 0.0; }
87 for (
int iqx=0; iqx<2; ++iqx)
89 for (
int iqy=0; iqy<2; ++iqy)
91 const real_t mq = const_mq ? MQ(0,0,0) : MQ(kx+iqx, ky+iqy, iel_ho);
92 const real_t dq = const_dq ? DQ(0,0,0) : DQ(kx+iqx, ky+iqy, iel_ho);
95 for (
int cj=0; cj<
dim; ++cj)
97 for (
int bj=0; bj<2; ++bj)
99 const real_t curl_j = ((cj == 0) ? 1 : -1)*((bj == 0) ? 1 : -1);
100 const real_t bxj = (cj == 0) ? ((bj == iqy) ? 1 : 0) : 0;
101 const real_t byj = (cj == 1) ? ((bj == iqx) ? 1 : 0) : 0;
103 const real_t jj_loc = bj + 2*cj;
105 for (
int ci=0; ci<
dim; ++ci)
107 for (
int bi=0; bi<2; ++bi)
109 const real_t curl_i = ((ci == 0) ? 1 : -1)*((bi == 0) ? 1 : -1);
110 const real_t bxi = (ci == 0) ? ((bi == iqy) ? 1 : 0) : 0;
111 const real_t byi = (ci == 1) ? ((bi == iqx) ? 1 : 0) : 0;
113 const real_t ii_loc = bi + 2*ci;
117 if (jj_loc > ii_loc) {
continue; }
120 val += bxi*bxj*Q(0,iqy,iqx);
121 val += byi*bxj*Q(1,iqy,iqx);
122 val += bxi*byj*Q(1,iqy,iqx);
123 val += byi*byj*Q(2,iqy,iqx);
125 val += dq*curl_i*curl_j*Q(3,iqy,iqx);
127 local_mat(ii_loc, jj_loc) += val;
137 for (
int ii_loc=0; ii_loc<ne; ++ii_loc)
139 const int ci = ii_loc/2;
140 const int bi = ii_loc%2;
141 const int ix = (ci == 0) ? 0 : bi;
142 const int iy = (ci == 1) ? 0 : bi;
144 int ii = (ci == 0) ? kx+ix + (ky+iy)*o : kx+ix + (ky+iy)*op1;
146 for (
int jj_loc=0; jj_loc<ne; ++jj_loc)
148 const int cj = jj_loc/2;
149 const int bj = jj_loc%2;
151 const int jj_off = (ci == cj) ? (bj - bi + 1) : (3 + bj + (1-bi)*2);
154 const real_t val = (jj_loc <= ii_loc)
155 ? local_mat(ii_loc, jj_loc)
156 : local_mat(jj_loc, ii_loc);
157 AtomicAdd(V(jj_off, ii, ci, iel_ho), val);
167 for (
int ci=0; ci<2; ++ci)
169 for (
int i1=0; i1<o; ++i1)
171 for (
int i2=0; i2<op1; ++i2)
173 const int ii_el = (ci == 0) ? i1 + i2*o : i2 + i1*op1 + o*op1;
174 for (
int cj=0; cj<2; ++cj)
176 const int j1_begin = (ci == cj) ? i1 : ((i2 > 0) ? i2-1 : i2);
177 const int j1_end = (ci == cj) ? i1 : ((i2 < o) ? i2 : i2-1);
178 const int j2_begin = (ci == cj) ? ((i2 > 0) ? i2-1 : i2) : i1;
179 const int j2_end = (ci == cj) ? ((i2 < o) ? i2+1 : i2) : i1+1;
181 for (
int j1=j1_begin; j1<=j1_end; ++j1)
183 for (
int j2=j2_begin; j2<=j2_end; ++j2)
185 const int jj_el = (cj == 0) ? j1 + j2*o : j2 + j1*op1 + o*op1;
186 int jj_off = (ci == cj) ? (j2-i2+1) : 3 + (j2-i1) + 2*(j1-i2+1);
187 map(jj_off, ii_el) = jj_el;
201 static constexpr int nv = 8;
202 static constexpr int ne = 12;
203 static constexpr int dim = 3;
204 static constexpr int ddm2 = (
dim*(
dim+1))/2;
205 static constexpr int ngeom = 2*ddm2;
206 static constexpr int o = ORDER;
207 static constexpr int op1 = ORDER + 1;
208 static constexpr int ndof_per_el =
dim*o*op1*op1;
209 static constexpr int nnz_per_row = 33;
210 static constexpr int sz_local_mat = ne*ne;
212 const bool const_mq =
c1.
Size() == 1;
213 const auto MQ = const_mq
216 const bool const_dq =
c2.
Size() == 1;
217 const auto DQ = const_dq
228 [=] MFEM_HOST_DEVICE (
int iel_ho)
230 MFEM_FOREACH_THREAD(iz,z,o)
232 MFEM_FOREACH_THREAD(iy,y,op1)
234 MFEM_FOREACH_THREAD(ix,x,op1)
236 for (
int c=0; c<
dim; ++c)
238 for (
int j=0; j<nnz_per_row; ++j)
240 V(j,ix+iy*op1+iz*op1*op1,c,iel_ho) = 0.0;
249 MFEM_FOREACH_THREAD(kz,z,ORDER)
251 MFEM_FOREACH_THREAD(ky,y,ORDER)
253 MFEM_FOREACH_THREAD(kx,x,ORDER)
259 real_t local_mat_[sz_local_mat];
261 for (
int i=0; i<sz_local_mat; ++i) { local_mat[i] = 0.0; }
263 real_t vx[8], vy[8], vz[8];
266 for (
int iqz=0; iqz<2; ++iqz)
268 for (
int iqy=0; iqy<2; ++iqy)
270 for (
int iqx=0; iqx<2; ++iqx)
283 const real_t w_detJ = w/detJ;
290 Q(0,iqz,iqy,iqx) = w_detJ*(A(0,0)*A(0,0)+A(0,1)*A(0,1)+A(0,2)*A(0,2));
291 Q(1,iqz,iqy,iqx) = w_detJ*(A(0,0)*A(1,0)+A(0,1)*A(1,1)+A(0,2)*A(1,2));
292 Q(2,iqz,iqy,iqx) = w_detJ*(A(0,0)*A(2,0)+A(0,1)*A(2,1)+A(0,2)*A(2,2));
293 Q(3,iqz,iqy,iqx) = w_detJ*(A(1,0)*A(1,0)+A(1,1)*A(1,1)+A(1,2)*A(1,2));
294 Q(4,iqz,iqy,iqx) = w_detJ*(A(1,0)*A(2,0)+A(1,1)*A(2,1)+A(1,2)*A(2,2));
295 Q(5,iqz,iqy,iqx) = w_detJ*(A(2,0)*A(2,0)+A(2,1)*A(2,1)+A(2,2)*A(2,2));
298 Q(6,iqz,iqy,iqx) = w_detJ*(J(0,0)*J(0,0)+J(1,0)*J(1,0)+J(2,0)*J(2,0));
299 Q(7,iqz,iqy,iqx) = w_detJ*(J(0,0)*J(0,1)+J(1,0)*J(1,1)+J(2,0)*J(2,1));
300 Q(8,iqz,iqy,iqx) = w_detJ*(J(0,0)*J(0,2)+J(1,0)*J(1,2)+J(2,0)*J(2,2));
301 Q(9,iqz,iqy,iqx) = w_detJ*(J(0,1)*J(0,1)+J(1,1)*J(1,1)+J(2,1)*J(2,1));
302 Q(10,iqz,iqy,iqx) = w_detJ*(J(0,1)*J(0,2)+J(1,1)*J(1,2)+J(2,1)*J(2,2));
303 Q(11,iqz,iqy,iqx) = w_detJ*(J(0,2)*J(0,2)+J(1,2)*J(1,2)+J(2,2)*J(2,2));
307 for (
int iqz=0; iqz<2; ++iqz)
309 for (
int iqy=0; iqy<2; ++iqy)
311 for (
int iqx=0; iqx<2; ++iqx)
313 const real_t mq = const_mq ? MQ(0,0,0,0) : MQ(kx+iqx, ky+iqy, kz+iqz, iel_ho);
314 const real_t dq = const_dq ? DQ(0,0,0,0) : DQ(kx+iqx, ky+iqy, kz+iqz, iel_ho);
316 for (
int cj=0; cj<
dim; ++cj)
318 const real_t jq1 = (cj == 0) ? iqy : ((cj == 1) ? iqz : iqx);
319 const real_t jq2 = (cj == 0) ? iqz : ((cj == 1) ? iqx : iqy);
322 const int jd_1 = (cj + 1)%3;
323 const int jd_2 = (cj + 2)%3;
325 for (
int bj=0; bj<4; ++bj)
327 const int bj1 = bj%2;
328 const int bj2 = bj/2;
332 curl_j[jd_1] = ((bj1 == 0) ? jq1 - 1 : -jq1)*((bj2 == 0) ? 1 : -1);
333 curl_j[jd_2] = ((bj2 == 0) ? 1 - jq2 : jq2)*((bj1 == 0) ? 1 : -1);
336 basis_j[jd_0] = ((bj1 == 0) ? 1 - jq1 : jq1)*((bj2 == 0) ? 1 - jq2 : jq2);
340 const int jj_loc = bj + 4*cj;
342 for (
int ci=0; ci<
dim; ++ci)
344 const real_t iq1 = (ci == 0) ? iqy : ((ci == 1) ? iqz : iqx);
345 const real_t iq2 = (ci == 0) ? iqz : ((ci == 1) ? iqx : iqy);
348 const int id_1 = (ci + 1)%3;
349 const int id_2 = (ci + 2)%3;
351 for (
int bi=0; bi<4; ++bi)
353 const int bi1 = bi%2;
354 const int bi2 = bi/2;
358 curl_i[id_1] = ((bi1 == 0) ? iq1 - 1 : -iq1)*((bi2 == 0) ? 1 : -1);
359 curl_i[id_2] = ((bi2 == 0) ? 1 - iq2 : iq2)*((bi1 == 0) ? 1 : -1);
362 basis_i[id_0] = ((bi1 == 0) ? 1 - iq1 : iq1)*((bi2 == 0) ? 1 - iq2 : iq2);
366 const int ii_loc = bi + 4*ci;
370 if (jj_loc > ii_loc) {
continue; }
373 curl_curl += Q(6,iqz,iqy,iqx)*curl_i[0]*curl_j[0];
374 curl_curl += Q(7,iqz,iqy,iqx)*(curl_i[0]*curl_j[1] + curl_i[1]*curl_j[0]);
375 curl_curl += Q(8,iqz,iqy,iqx)*(curl_i[0]*curl_j[2] + curl_i[2]*curl_j[0]);
376 curl_curl += Q(9,iqz,iqy,iqx)*curl_i[1]*curl_j[1];
377 curl_curl += Q(10,iqz,iqy,iqx)*(curl_i[1]*curl_j[2] + curl_i[2]*curl_j[1]);
378 curl_curl += Q(11,iqz,iqy,iqx)*curl_i[2]*curl_j[2];
381 basis_basis += Q(0,iqz,iqy,iqx)*basis_i[0]*basis_j[0];
382 basis_basis += Q(1,iqz,iqy,iqx)*(basis_i[0]*basis_j[1] + basis_i[1]*basis_j[0]);
383 basis_basis += Q(2,iqz,iqy,iqx)*(basis_i[0]*basis_j[2] + basis_i[2]*basis_j[0]);
384 basis_basis += Q(3,iqz,iqy,iqx)*basis_i[1]*basis_j[1];
385 basis_basis += Q(4,iqz,iqy,iqx)*(basis_i[1]*basis_j[2] + basis_i[2]*basis_j[1]);
386 basis_basis += Q(5,iqz,iqy,iqx)*basis_i[2]*basis_j[2];
388 const real_t val = dq*curl_curl + mq*basis_basis;
390 local_mat(ii_loc, jj_loc) += val;
409 for (
int ii_loc=0; ii_loc<ne; ++ii_loc)
411 const int ci = ii_loc/4;
412 const int bi = ii_loc%4;
415 const int id1 = (ci+1)%3;
416 const int id2 = (ci+2)%3;
427 const int nx = (ci == 0) ? o : op1;
428 const int ny = (ci == 1) ? o : op1;
430 const int ii = kx+ii_lex[0] + (ky+ii_lex[1])*nx + (kz+ii_lex[2])*nx*ny;
432 for (
int jj_loc=0; jj_loc<ne; ++jj_loc)
434 const int cj = jj_loc/4;
437 const int cj_rel = (3 + cj - ci)%3;
439 const int bj = jj_loc%4;
441 const int jd0 = cj_rel;
442 const int jd1 = (cj_rel+1)%3;
443 const int jd2 = (cj_rel+2)%3;
450 const int d0 = jj_rel[0] - i0;
451 const int d1 = 1 + jj_rel[1] - i1;
452 const int d2 = 1 + jj_rel[2] - i2;
454 if (cj_rel == 0) { jj_off = d1 + 3*d2; }
455 else if (cj_rel == 1) { jj_off = 9 + d0 + 2*d1 + 4*d2; }
456 else { jj_off = 21 + d0 + 2*d1 + 6*d2; }
459 const real_t val = (jj_loc <= ii_loc)
460 ? local_mat(ii_loc, jj_loc)
461 : local_mat(jj_loc, ii_loc);
462 AtomicAdd(V(jj_off, ii, ci, iel_ho), val);
473 for (
int ci=0; ci<
dim; ++ci)
475 const int i_off = ci*o*op1*op1;
477 const int id1 = (ci+1)%3;
478 const int id2 = (ci+2)%3;
480 const int nxi = (ci == 0) ? o : op1;
481 const int nyi = (ci == 1) ? o : op1;
483 for (
int i0=0; i0<o; ++i0)
485 for (
int i1=0; i1<op1; ++i1)
487 for (
int i2=0; i2<op1; ++i2)
493 const int ii_el = i_off + ii_lex[0] + ii_lex[1]*nxi + ii_lex[2]*nxi*nyi;
495 for (
int cj_rel=0; cj_rel<
dim; ++cj_rel)
497 const int cj = (ci + cj_rel) % 3;
498 const int j_off = cj*o*op1*op1;
500 const int nxj = (cj == 0) ? o : op1;
501 const int nyj = (cj == 1) ? o : op1;
503 const int j0_begin = i0;
504 const int j0_end = (cj_rel == 0) ? i0 : i0 + 1;
505 const int j1_begin = (i1 > 0) ? i1-1 : i1;
506 const int j1_end = (cj_rel == 1)
507 ? ((i1 < o) ? i1 : i1-1)
508 : ((i1 < o) ? i1+1 : i1);
509 const int j2_begin = (i2 > 0) ? i2-1 : i2;
510 const int j2_end = (cj_rel == 2)
511 ? ((i2 < o) ? i2 : i2-1)
512 : ((i2 < o) ? i2+1 : i2);
514 for (
int j0=j0_begin; j0<=j0_end; ++j0)
516 const int d0 = j0 - i0;
517 for (
int j1=j1_begin; j1<=j1_end; ++j1)
519 const int d1 = j1 - i1 + 1;
520 for (
int j2=j2_begin; j2<=j2_end; ++j2)
522 const int d2 = j2 - i2 + 1;
527 const int jj_el = j_off + jj_lex[0] + jj_lex[1]*nxj + jj_lex[2]*nxj*nyj;
529 if (cj_rel == 0) { jj_off = d1 + 3*d2; }
530 else if (cj_rel == 1) { jj_off = 9 + d0 + 2*d1 + 4*d2; }
531 else { jj_off = 21 + d0 + 2*d1 + 6*d2; }
532 map(jj_off, ii_el) = jj_el;