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.
30ef72598Sjeremylt //
43d8e8822SJeremy L Thompson // SPDX-License-Identifier: BSD-2-Clause
50ef72598Sjeremylt //
63d8e8822SJeremy L Thompson // This file is part of CEED: http://github.com/ceed
70ef72598Sjeremylt
80ef72598Sjeremylt //------------------------------------------------------------------------------
90ef72598Sjeremylt // Setup 1D mass matrix
100ef72598Sjeremylt //------------------------------------------------------------------------------
setup_mass(void * ctx,const CeedInt Q,const CeedScalar * const * in,CeedScalar * const * out)112b730f8bSJeremy L Thompson CEED_QFUNCTION(setup_mass)(void *ctx, const CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
120ef72598Sjeremylt // in[0] is quadrature weights, size (Q)
130ef72598Sjeremylt // in[1] is Jacobians, size (Q)
140ef72598Sjeremylt const CeedScalar *w = in[0], *J = in[1];
150ef72598Sjeremylt
160ef72598Sjeremylt // out[0] is quadrature data, size (Q)
170ef72598Sjeremylt CeedScalar *qdata = out[0];
180ef72598Sjeremylt
190ef72598Sjeremylt // Quadrature point loop
202b730f8bSJeremy L Thompson CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) { qdata[i] = J[i] * w[i]; }
210ef72598Sjeremylt
220ef72598Sjeremylt return 0;
230ef72598Sjeremylt }
240ef72598Sjeremylt
250ef72598Sjeremylt //------------------------------------------------------------------------------
260ef72598Sjeremylt // Setup 2D mass matrix
270ef72598Sjeremylt //------------------------------------------------------------------------------
setup_mass_2d(void * ctx,const CeedInt Q,const CeedScalar * const * in,CeedScalar * const * out)282b730f8bSJeremy L Thompson CEED_QFUNCTION(setup_mass_2d)(void *ctx, const CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
290ef72598Sjeremylt // in[0] is quadrature weights, size (Q)
300ef72598Sjeremylt // in[1] is Jacobians with shape [2, nc=2, Q]
310ef72598Sjeremylt const CeedScalar *w = in[0], *J = in[1];
320ef72598Sjeremylt
330ef72598Sjeremylt // out[0] is quadrature data, size (Q)
340ef72598Sjeremylt CeedScalar *qdata = out[0];
350ef72598Sjeremylt
360ef72598Sjeremylt // Quadrature point loop
372b730f8bSJeremy L Thompson CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) { qdata[i] = w[i] * (J[i + Q * 0] * J[i + Q * 3] - J[i + Q * 1] * J[i + Q * 2]); }
380ef72598Sjeremylt
390ef72598Sjeremylt return 0;
400ef72598Sjeremylt }
410ef72598Sjeremylt
420ef72598Sjeremylt //------------------------------------------------------------------------------
430ef72598Sjeremylt // Apply mass matrix
440ef72598Sjeremylt //------------------------------------------------------------------------------
apply_mass(void * ctx,const CeedInt Q,const CeedScalar * const * in,CeedScalar * const * out)452b730f8bSJeremy L Thompson CEED_QFUNCTION(apply_mass)(void *ctx, const CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
460ef72598Sjeremylt // Get scaling factor, if set
470ef72598Sjeremylt const CeedScalar *scale_array = ctx ? (CeedScalar *)ctx : NULL;
480ef72598Sjeremylt const CeedScalar scale = ctx ? scale_array[4] : 1.;
490ef72598Sjeremylt
500ef72598Sjeremylt // in[0] is quadrature data, size (Q)
510ef72598Sjeremylt // in[1] is u, size (Q)
520ef72598Sjeremylt const CeedScalar *qdata = in[0], *u = in[1];
530ef72598Sjeremylt
540ef72598Sjeremylt // out[0] is v, size (Q)
550ef72598Sjeremylt CeedScalar *v = out[0];
560ef72598Sjeremylt
570ef72598Sjeremylt // Quadrature point loop
582b730f8bSJeremy L Thompson CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) { v[i] = scale * qdata[i] * u[i]; }
590ef72598Sjeremylt
600ef72598Sjeremylt return 0;
610ef72598Sjeremylt }
620ef72598Sjeremylt
630ef72598Sjeremylt //------------------------------------------------------------------------------
640ef72598Sjeremylt // Apply mass matrix to two components
650ef72598Sjeremylt //------------------------------------------------------------------------------
apply_mass_two(void * ctx,const CeedInt Q,const CeedScalar * const * in,CeedScalar * const * out)662b730f8bSJeremy L Thompson CEED_QFUNCTION(apply_mass_two)(void *ctx, const CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
670ef72598Sjeremylt // in[0] is quadrature data, size (Q)
680ef72598Sjeremylt // in[1] is u, size (2*Q)
690ef72598Sjeremylt const CeedScalar *qdata = in[0], *u = in[1];
700ef72598Sjeremylt
710ef72598Sjeremylt // out[0] is v, size (2*Q)
720ef72598Sjeremylt CeedScalar *v = out[0];
730ef72598Sjeremylt
740ef72598Sjeremylt // Quadrature point loop
752b730f8bSJeremy L Thompson CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) {
760ef72598Sjeremylt v[i] = qdata[i] * u[i];
770ef72598Sjeremylt v[Q + i] = qdata[i] * u[Q + i];
780ef72598Sjeremylt }
790ef72598Sjeremylt
800ef72598Sjeremylt return 0;
810ef72598Sjeremylt }
820ef72598Sjeremylt
830ef72598Sjeremylt //------------------------------------------------------------------------------
84