1*9ba83ac0SJeremy L Thompson // Copyright (c) 2017-2026, Lawrence Livermore National Security, LLC and other CEED contributors.
23d8e8822SJeremy L Thompson // All Rights Reserved. See the top-level LICENSE and NOTICE files for details.
31d102b48SJeremy L Thompson //
43d8e8822SJeremy L Thompson // SPDX-License-Identifier: BSD-2-Clause
51d102b48SJeremy L Thompson //
63d8e8822SJeremy L Thompson // This file is part of CEED: http://github.com/ceed
71d102b48SJeremy L Thompson
8c0b5abf0SJeremy L Thompson #include <ceed/types.h>
9c9c2c079SJeremy L Thompson
setup_mass(void * ctx,const CeedInt Q,const CeedScalar * const * in,CeedScalar * const * out)102b730f8bSJeremy L Thompson CEED_QFUNCTION(setup_mass)(void *ctx, const CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
111d102b48SJeremy L Thompson const CeedScalar *J = in[0], *weight = in[1];
121d102b48SJeremy L Thompson CeedScalar *rho = out[0];
131d102b48SJeremy L Thompson for (CeedInt i = 0; i < Q; i++) {
141d102b48SJeremy L Thompson rho[i] = weight[i] * (J[i + Q * 0] * J[i + Q * 3] - J[i + Q * 1] * J[i + Q * 2]);
151d102b48SJeremy L Thompson }
161d102b48SJeremy L Thompson return 0;
171d102b48SJeremy L Thompson }
181d102b48SJeremy L Thompson
setup_diff(void * ctx,const CeedInt Q,const CeedScalar * const * in,CeedScalar * const * out)192b730f8bSJeremy L Thompson CEED_QFUNCTION(setup_diff)(void *ctx, const CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
201d102b48SJeremy L Thompson // At every quadrature point, compute qw/det(J).adj(J).adj(J)^T and store
211d102b48SJeremy L Thompson // the symmetric part of the result.
221d102b48SJeremy L Thompson
231d102b48SJeremy L Thompson // in[0] is Jacobians with shape [2, nc=2, Q]
241d102b48SJeremy L Thompson // in[1] is quadrature weights, size (Q)
251d102b48SJeremy L Thompson const CeedScalar *J = in[0], *qw = in[1];
261d102b48SJeremy L Thompson
271d102b48SJeremy L Thompson // out[0] is qdata, size (Q)
281d102b48SJeremy L Thompson CeedScalar *qd = out[0];
291d102b48SJeremy L Thompson
301d102b48SJeremy L Thompson // Quadrature point loop
311d102b48SJeremy L Thompson for (CeedInt i = 0; i < Q; i++) {
321d102b48SJeremy L Thompson // J: 0 2 qd: 0 2 adj(J): J22 -J12
331d102b48SJeremy L Thompson // 1 3 2 1 -J21 J11
341d102b48SJeremy L Thompson const CeedScalar J11 = J[i + Q * 0];
351d102b48SJeremy L Thompson const CeedScalar J21 = J[i + Q * 1];
361d102b48SJeremy L Thompson const CeedScalar J12 = J[i + Q * 2];
371d102b48SJeremy L Thompson const CeedScalar J22 = J[i + Q * 3];
381d102b48SJeremy L Thompson const CeedScalar w = qw[i] / (J11 * J22 - J21 * J12);
391d102b48SJeremy L Thompson qd[i + Q * 0] = w * (J12 * J12 + J22 * J22);
401d102b48SJeremy L Thompson qd[i + Q * 1] = w * (J11 * J11 + J21 * J21);
411d102b48SJeremy L Thompson qd[i + Q * 2] = -w * (J11 * J12 + J21 * J22);
421d102b48SJeremy L Thompson }
431d102b48SJeremy L Thompson
441d102b48SJeremy L Thompson return 0;
451d102b48SJeremy L Thompson }
461d102b48SJeremy L Thompson
apply(void * ctx,const CeedInt Q,const CeedScalar * const * in,CeedScalar * const * out)472b730f8bSJeremy L Thompson CEED_QFUNCTION(apply)(void *ctx, const CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
481d102b48SJeremy L Thompson // in[0] is gradient u, shape [2, nc=1, Q]
491d102b48SJeremy L Thompson // in[1] is mass quadrature data, size (Q)
505107b09fSJeremy L Thompson // in[2] is Poisson quadrature data, size (3*Q)
511d102b48SJeremy L Thompson // in[3] is u, size (Q)
521d102b48SJeremy L Thompson const CeedScalar *du = in[0], *qd_mass = in[1], *qd_diff = in[2], *u = in[3];
531d102b48SJeremy L Thompson
541d102b48SJeremy L Thompson // out[0] is output to multiply against v, size (Q)
551d102b48SJeremy L Thompson // out[1] is output to multiply against gradient v, shape [2, nc=1, Q]
561d102b48SJeremy L Thompson CeedScalar *v = out[0], *dv = out[1];
571d102b48SJeremy L Thompson
581d102b48SJeremy L Thompson // Quadrature point loop
591d102b48SJeremy L Thompson for (CeedInt i = 0; i < Q; i++) {
601d102b48SJeremy L Thompson // Mass
611d102b48SJeremy L Thompson v[i] = qd_mass[i] * u[i];
621d102b48SJeremy L Thompson // Diff
631d102b48SJeremy L Thompson const CeedScalar du0 = du[i + Q * 0];
641d102b48SJeremy L Thompson const CeedScalar du1 = du[i + Q * 1];
651d102b48SJeremy L Thompson dv[i + Q * 0] = qd_diff[i + Q * 0] * du0 + qd_diff[i + Q * 2] * du1;
661d102b48SJeremy L Thompson dv[i + Q * 1] = qd_diff[i + Q * 2] * du0 + qd_diff[i + Q * 1] * du1;
671d102b48SJeremy L Thompson }
681d102b48SJeremy L Thompson
691d102b48SJeremy L Thompson return 0;
701d102b48SJeremy L Thompson }
711d102b48SJeremy L Thompson
apply_lin(void * ctx,const CeedInt Q,const CeedScalar * const * in,CeedScalar * const * out)722b730f8bSJeremy L Thompson CEED_QFUNCTION(apply_lin)(void *ctx, const CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
731d102b48SJeremy L Thompson // in[0] is gradient u, shape [2, nc=1, Q]
745107b09fSJeremy L Thompson // in[1] is assembled quadrature data, size (9*Q)
751d102b48SJeremy L Thompson // in[2] is u, size (Q)
761d102b48SJeremy L Thompson const CeedScalar *du = in[0], *qd = in[1], *u = in[2];
771d102b48SJeremy L Thompson
781d102b48SJeremy L Thompson // out[0] is output to multiply against v, size (Q)
791d102b48SJeremy L Thompson // out[1] is output to multiply against gradient v, shape [2, nc=1, Q]
801d102b48SJeremy L Thompson CeedScalar *v = out[0], *dv = out[1];
811d102b48SJeremy L Thompson
821d102b48SJeremy L Thompson // Quadrature point loop
831d102b48SJeremy L Thompson for (CeedInt i = 0; i < Q; i++) {
841d102b48SJeremy L Thompson const CeedScalar du0 = du[i + Q * 0];
851d102b48SJeremy L Thompson const CeedScalar du1 = du[i + Q * 1];
861d102b48SJeremy L Thompson v[i + Q * 0] = qd[i + Q * 0] * du0 + qd[i + Q * 3] * du1 + qd[i + Q * 6] * u[i];
871d102b48SJeremy L Thompson dv[i + Q * 0] = qd[i + Q * 1] * du0 + qd[i + Q * 4] * du1 + qd[i + Q * 7] * u[i];
881d102b48SJeremy L Thompson dv[i + Q * 1] = qd[i + Q * 2] * du0 + qd[i + Q * 5] * du1 + qd[i + Q * 8] * u[i];
891d102b48SJeremy L Thompson }
901d102b48SJeremy L Thompson
911d102b48SJeremy L Thompson return 0;
921d102b48SJeremy L Thompson }
93