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.
3b7ec98d8SJeremy L Thompson //
43d8e8822SJeremy L Thompson // SPDX-License-Identifier: BSD-2-Clause
5b7ec98d8SJeremy L Thompson //
63d8e8822SJeremy L Thompson // This file is part of CEED: http://github.com/ceed
7b7ec98d8SJeremy 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) {
11b7ec98d8SJeremy L Thompson const CeedScalar *J = in[0], *weight = in[1];
12b7ec98d8SJeremy L Thompson CeedScalar *rho = out[0];
13b7ec98d8SJeremy L Thompson for (CeedInt i = 0; i < Q; i++) {
14b7ec98d8SJeremy L Thompson rho[i] = weight[i] * (J[i + Q * 0] * J[i + Q * 3] - J[i + Q * 1] * J[i + Q * 2]);
15b7ec98d8SJeremy L Thompson }
16b7ec98d8SJeremy L Thompson return 0;
17b7ec98d8SJeremy L Thompson }
18b7ec98d8SJeremy 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) {
20b7ec98d8SJeremy L Thompson // At every quadrature point, compute qw/det(J).adj(J).adj(J)^T and store
21b7ec98d8SJeremy L Thompson // the symmetric part of the result.
22b7ec98d8SJeremy L Thompson
23b7ec98d8SJeremy L Thompson // in[0] is Jacobians with shape [2, nc=2, Q]
24b7ec98d8SJeremy L Thompson // in[1] is quadrature weights, size (Q)
25b7ec98d8SJeremy L Thompson const CeedScalar *J = in[0], *qw = in[1];
26b7ec98d8SJeremy L Thompson
27b7ec98d8SJeremy L Thompson // out[0] is qdata, size (Q)
28b7ec98d8SJeremy L Thompson CeedScalar *qd = out[0];
29b7ec98d8SJeremy L Thompson
30b7ec98d8SJeremy L Thompson // Quadrature point loop
31b7ec98d8SJeremy L Thompson for (CeedInt i = 0; i < Q; i++) {
32b7ec98d8SJeremy L Thompson // J: 0 2 qd: 0 2 adj(J): J22 -J12
33b7ec98d8SJeremy L Thompson // 1 3 2 1 -J21 J11
34b7ec98d8SJeremy L Thompson const CeedScalar J11 = J[i + Q * 0];
35b7ec98d8SJeremy L Thompson const CeedScalar J21 = J[i + Q * 1];
36b7ec98d8SJeremy L Thompson const CeedScalar J12 = J[i + Q * 2];
37b7ec98d8SJeremy L Thompson const CeedScalar J22 = J[i + Q * 3];
38b7ec98d8SJeremy L Thompson const CeedScalar w = qw[i] / (J11 * J22 - J21 * J12);
39b7ec98d8SJeremy L Thompson qd[i + Q * 0] = w * (J12 * J12 + J22 * J22);
40b7ec98d8SJeremy L Thompson qd[i + Q * 1] = w * (J11 * J11 + J21 * J21);
41b7ec98d8SJeremy L Thompson qd[i + Q * 2] = -w * (J11 * J12 + J21 * J22);
42b7ec98d8SJeremy L Thompson }
43b7ec98d8SJeremy L Thompson
44b7ec98d8SJeremy L Thompson return 0;
45b7ec98d8SJeremy L Thompson }
46b7ec98d8SJeremy 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) {
48b7ec98d8SJeremy L Thompson // in[0] is gradient u, shape [2, nc=1, Q]
49b7ec98d8SJeremy L Thompson // in[1] is mass quadrature data, size (Q)
50b7ec98d8SJeremy L Thompson // in[2] is Poisson quadrature data, size (Q)
51b7ec98d8SJeremy L Thompson // in[3] is u, size (Q)
52b7ec98d8SJeremy L Thompson const CeedScalar *du = in[0], *qd_mass = in[1], *qd_diff = in[2], *u = in[3];
53b7ec98d8SJeremy L Thompson
54b7ec98d8SJeremy L Thompson // out[0] is output to multiply against v, size (Q)
55b7ec98d8SJeremy L Thompson // out[1] is output to multiply against gradient v, shape [2, nc=1, Q]
56b7ec98d8SJeremy L Thompson CeedScalar *v = out[0], *dv = out[1];
57b7ec98d8SJeremy L Thompson
58b7ec98d8SJeremy L Thompson // Quadrature point loop
59b7ec98d8SJeremy L Thompson for (CeedInt i = 0; i < Q; i++) {
60b7ec98d8SJeremy L Thompson // Mass
61b7ec98d8SJeremy L Thompson v[i] = qd_mass[i] * u[i];
62b7ec98d8SJeremy L Thompson // Diff
63b7ec98d8SJeremy L Thompson const CeedScalar du0 = du[i + Q * 0];
64b7ec98d8SJeremy L Thompson const CeedScalar du1 = du[i + Q * 1];
65b7ec98d8SJeremy L Thompson dv[i + Q * 0] = qd_diff[i + Q * 0] * du0 + qd_diff[i + Q * 2] * du1;
66b7ec98d8SJeremy L Thompson dv[i + Q * 1] = qd_diff[i + Q * 2] * du0 + qd_diff[i + Q * 1] * du1;
67b7ec98d8SJeremy L Thompson }
68b7ec98d8SJeremy L Thompson
69b7ec98d8SJeremy L Thompson return 0;
70b7ec98d8SJeremy L Thompson }
71