1*9ba83ac0SJeremy L Thompson // Copyright (c) 2017-2026, Lawrence Livermore National Security, LLC and other CEED contributors.
23c11f1fcSJeremy L Thompson // All Rights Reserved. See the top-level LICENSE and NOTICE files for details.
33c11f1fcSJeremy L Thompson //
43c11f1fcSJeremy L Thompson // SPDX-License-Identifier: BSD-2-Clause
53c11f1fcSJeremy L Thompson //
63c11f1fcSJeremy L Thompson // This file is part of CEED: http://github.com/ceed
73c11f1fcSJeremy L Thompson
83c11f1fcSJeremy L Thompson /// @file
93c11f1fcSJeremy L Thompson /// libCEED QFunctions for diffusion operator example using PETSc
103c11f1fcSJeremy L Thompson
113c11f1fcSJeremy L Thompson #include <ceed/types.h>
123c11f1fcSJeremy L Thompson #ifndef CEED_RUNNING_JIT_PASS
133c11f1fcSJeremy L Thompson #include <math.h>
143c11f1fcSJeremy L Thompson #endif
153c11f1fcSJeremy L Thompson
163c11f1fcSJeremy L Thompson // -----------------------------------------------------------------------------
173c11f1fcSJeremy L Thompson // This QFunction sets up the rhs and true solution for the problem
183c11f1fcSJeremy L Thompson // -----------------------------------------------------------------------------
SetupMassDiffRhs3(void * ctx,CeedInt Q,const CeedScalar * const * in,CeedScalar * const * out)193c11f1fcSJeremy L Thompson CEED_QFUNCTION(SetupMassDiffRhs3)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
203c11f1fcSJeremy L Thompson #ifndef M_PI
213c11f1fcSJeremy L Thompson #define M_PI 3.14159265358979323846
223c11f1fcSJeremy L Thompson #endif
233c11f1fcSJeremy L Thompson const CeedScalar *x = in[0], *w = in[1];
243c11f1fcSJeremy L Thompson CeedScalar *true_soln = out[0], *rhs = out[1];
253c11f1fcSJeremy L Thompson
263c11f1fcSJeremy L Thompson // Quadrature Point Loop
273c11f1fcSJeremy L Thompson CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) {
283c11f1fcSJeremy L Thompson const CeedScalar c[3] = {0, 1., 2.};
293c11f1fcSJeremy L Thompson const CeedScalar k[3] = {1., 2., 3.};
303c11f1fcSJeremy L Thompson
313c11f1fcSJeremy L Thompson // Component 1
323c11f1fcSJeremy L Thompson true_soln[i + 0 * Q] =
333c11f1fcSJeremy L Thompson sin(M_PI * (c[0] + k[0] * x[i + Q * 0])) * sin(M_PI * (c[1] + k[1] * x[i + Q * 1])) * sin(M_PI * (c[2] + k[2] * x[i + Q * 2]));
343c11f1fcSJeremy L Thompson // Component 2
353c11f1fcSJeremy L Thompson true_soln[i + 1 * Q] = 2 * true_soln[i + 0 * Q];
363c11f1fcSJeremy L Thompson // Component 3
373c11f1fcSJeremy L Thompson true_soln[i + 2 * Q] = 3 * true_soln[i + 0 * Q];
383c11f1fcSJeremy L Thompson
393c11f1fcSJeremy L Thompson // Component 1
403c11f1fcSJeremy L Thompson rhs[i + 0 * Q] = w[i + Q * 0] * (M_PI * M_PI * (k[0] * k[0] + k[1] * k[1] + k[2] * k[2]) + 1.0) * true_soln[i + 0 * Q];
413c11f1fcSJeremy L Thompson // Component 2
423c11f1fcSJeremy L Thompson rhs[i + 1 * Q] = 2 * rhs[i + 0 * Q];
433c11f1fcSJeremy L Thompson // Component 3
443c11f1fcSJeremy L Thompson rhs[i + 2 * Q] = 3 * rhs[i + 0 * Q];
453c11f1fcSJeremy L Thompson } // End of Quadrature Point Loop
463c11f1fcSJeremy L Thompson return 0;
473c11f1fcSJeremy L Thompson }
483c11f1fcSJeremy L Thompson
493c11f1fcSJeremy L Thompson // -----------------------------------------------------------------------------
503c11f1fcSJeremy L Thompson // This QFunction applies the mass + diffusion operator for a vector field of 3 components.
513c11f1fcSJeremy L Thompson //
523c11f1fcSJeremy L Thompson // Inputs:
533c11f1fcSJeremy L Thompson // u - Input vector at quadrature points
543c11f1fcSJeremy L Thompson // ug - Input vector Jacobian at quadrature points
553c11f1fcSJeremy L Thompson // q_data - Geometric factors
563c11f1fcSJeremy L Thompson //
573c11f1fcSJeremy L Thompson // Output:
583c11f1fcSJeremy L Thompson // v - Output vector (test functions) at quadrature points
593c11f1fcSJeremy L Thompson // vJ - Output vector (test functions) Jacobian at quadrature points
603c11f1fcSJeremy L Thompson // -----------------------------------------------------------------------------
MassDiff3(void * ctx,CeedInt Q,const CeedScalar * const * in,CeedScalar * const * out)613c11f1fcSJeremy L Thompson CEED_QFUNCTION(MassDiff3)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
623c11f1fcSJeremy L Thompson const CeedScalar *u = in[0], *ug = in[1], *q_data = in[2];
633c11f1fcSJeremy L Thompson CeedScalar *v = out[0], *vg = out[1];
643c11f1fcSJeremy L Thompson
653c11f1fcSJeremy L Thompson // Quadrature Point Loop
663c11f1fcSJeremy L Thompson CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) {
673c11f1fcSJeremy L Thompson // Read spatial derivatives of u components
683c11f1fcSJeremy L Thompson const CeedScalar uJ[3][3] = {
693c11f1fcSJeremy L Thompson {ug[i + (0 + 0 * 3) * Q], ug[i + (0 + 1 * 3) * Q], ug[i + (0 + 2 * 3) * Q]},
703c11f1fcSJeremy L Thompson {ug[i + (1 + 0 * 3) * Q], ug[i + (1 + 1 * 3) * Q], ug[i + (1 + 2 * 3) * Q]},
713c11f1fcSJeremy L Thompson {ug[i + (2 + 0 * 3) * Q], ug[i + (2 + 1 * 3) * Q], ug[i + (2 + 2 * 3) * Q]}
723c11f1fcSJeremy L Thompson };
733c11f1fcSJeremy L Thompson // Read q_data (dXdxdXdx_T symmetric matrix)
743c11f1fcSJeremy L Thompson const CeedScalar dXdxdXdx_T[3][3] = {
753c11f1fcSJeremy L Thompson {q_data[i + 1 * Q], q_data[i + 2 * Q], q_data[i + 3 * Q]},
763c11f1fcSJeremy L Thompson {q_data[i + 2 * Q], q_data[i + 4 * Q], q_data[i + 5 * Q]},
773c11f1fcSJeremy L Thompson {q_data[i + 3 * Q], q_data[i + 5 * Q], q_data[i + 6 * Q]}
783c11f1fcSJeremy L Thompson };
793c11f1fcSJeremy L Thompson
803c11f1fcSJeremy L Thompson for (int k = 0; k < 3; k++) { // k = component
813c11f1fcSJeremy L Thompson // Mass
823c11f1fcSJeremy L Thompson v[i + k * Q] = q_data[i + 0 * Q] * u[i + k * Q];
833c11f1fcSJeremy L Thompson // Diff
843c11f1fcSJeremy L Thompson for (int j = 0; j < 3; j++) { // j = direction of vg
853c11f1fcSJeremy L Thompson vg[i + (k + j * 3) * Q] = (uJ[k][0] * dXdxdXdx_T[0][j] + uJ[k][1] * dXdxdXdx_T[1][j] + uJ[k][2] * dXdxdXdx_T[2][j]);
863c11f1fcSJeremy L Thompson }
873c11f1fcSJeremy L Thompson }
883c11f1fcSJeremy L Thompson } // End of Quadrature Point Loop
893c11f1fcSJeremy L Thompson
903c11f1fcSJeremy L Thompson return 0;
913c11f1fcSJeremy L Thompson }
923c11f1fcSJeremy L Thompson // -----------------------------------------------------------------------------
93