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. 3cb32e2e7SValeria Barra // 43d8e8822SJeremy L Thompson // SPDX-License-Identifier: BSD-2-Clause 5cb32e2e7SValeria Barra // 63d8e8822SJeremy L Thompson // This file is part of CEED: http://github.com/ceed 7cb32e2e7SValeria Barra 8cb32e2e7SValeria Barra /// @file 9cb32e2e7SValeria Barra /// libCEED QFunctions for diffusion operator example using PETSc 10cb32e2e7SValeria Barra 11c0b5abf0SJeremy L Thompson #include <ceed/types.h> 12c0b5abf0SJeremy L Thompson #ifndef CEED_RUNNING_JIT_PASS 13f6b55d2cSvaleriabarra #include <math.h> 14c0b5abf0SJeremy L Thompson #endif 15f6b55d2cSvaleriabarra 16e83e87a5Sjeremylt // ----------------------------------------------------------------------------- 1713921685Svaleriabarra // This QFunction sets up the rhs and true solution for the problem 18cb32e2e7SValeria Barra // ----------------------------------------------------------------------------- 192b730f8bSJeremy L Thompson CEED_QFUNCTION(SetupDiffRhs3)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 20cb32e2e7SValeria Barra #ifndef M_PI 21cb32e2e7SValeria Barra #define M_PI 3.14159265358979323846 22cb32e2e7SValeria Barra #endif 23e83e87a5Sjeremylt const CeedScalar *x = in[0], *w = in[1]; 24cb32e2e7SValeria Barra CeedScalar *true_soln = out[0], *rhs = out[1]; 25cb32e2e7SValeria Barra 26cb32e2e7SValeria Barra // Quadrature Point Loop 272b730f8bSJeremy L Thompson CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) { 28cb32e2e7SValeria Barra const CeedScalar c[3] = {0, 1., 2.}; 29cb32e2e7SValeria Barra const CeedScalar k[3] = {1., 2., 3.}; 30cb32e2e7SValeria Barra 31cb32e2e7SValeria Barra // Component 1 322b730f8bSJeremy L Thompson true_soln[i + 0 * Q] = 332b730f8bSJeremy 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])); 34cb32e2e7SValeria Barra // Component 2 3582311801Sjeremylt true_soln[i + 1 * Q] = 2 * true_soln[i + 0 * Q]; 36cb32e2e7SValeria Barra // Component 3 3782311801Sjeremylt true_soln[i + 2 * Q] = 3 * true_soln[i + 0 * Q]; 38cb32e2e7SValeria Barra 39cb32e2e7SValeria Barra // Component 1 402b730f8bSJeremy 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]) * true_soln[i + 0 * Q]; 41cb32e2e7SValeria Barra // Component 2 4282311801Sjeremylt rhs[i + 1 * Q] = 2 * rhs[i + 0 * Q]; 43cb32e2e7SValeria Barra // Component 3 4482311801Sjeremylt rhs[i + 2 * Q] = 3 * rhs[i + 0 * Q]; 45cb32e2e7SValeria Barra } // End of Quadrature Point Loop 46cb32e2e7SValeria Barra return 0; 47cb32e2e7SValeria Barra } 48cb32e2e7SValeria Barra 49e83e87a5Sjeremylt // ----------------------------------------------------------------------------- 50ed264d09SValeria Barra // This QFunction applies the diffusion operator for a vector field of 3 components. 51ed264d09SValeria Barra // 52ed264d09SValeria Barra // Inputs: 53ed264d09SValeria Barra // ug - Input vector Jacobian at quadrature points 549b072555Sjeremylt // q_data - Geometric factors 55ed264d09SValeria Barra // 56ed264d09SValeria Barra // Output: 57ed264d09SValeria Barra // vJ - Output vector (test functions) Jacobian at quadrature points 58cb32e2e7SValeria Barra // ----------------------------------------------------------------------------- 592b730f8bSJeremy L Thompson CEED_QFUNCTION(Diff3)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 603c11f1fcSJeremy L Thompson const CeedScalar *ug = in[0], *q_data = in[1]; 61cb32e2e7SValeria Barra CeedScalar *vg = out[0]; 62cb32e2e7SValeria Barra 63cb32e2e7SValeria Barra // Quadrature Point Loop 642b730f8bSJeremy L Thompson CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) { 65cb32e2e7SValeria Barra // Read spatial derivatives of u components 662b730f8bSJeremy L Thompson const CeedScalar uJ[3][3] = { 672b730f8bSJeremy L Thompson {ug[i + (0 + 0 * 3) * Q], ug[i + (0 + 1 * 3) * Q], ug[i + (0 + 2 * 3) * Q]}, 682b730f8bSJeremy L Thompson {ug[i + (1 + 0 * 3) * Q], ug[i + (1 + 1 * 3) * Q], ug[i + (1 + 2 * 3) * Q]}, 692b730f8bSJeremy L Thompson {ug[i + (2 + 0 * 3) * Q], ug[i + (2 + 1 * 3) * Q], ug[i + (2 + 2 * 3) * Q]} 70cb32e2e7SValeria Barra }; 719b072555Sjeremylt // Read q_data (dXdxdXdx_T symmetric matrix) 722b730f8bSJeremy L Thompson const CeedScalar dXdxdXdx_T[3][3] = { 733c11f1fcSJeremy L Thompson {q_data[i + 1 * Q], q_data[i + 2 * Q], q_data[i + 3 * Q]}, 743c11f1fcSJeremy L Thompson {q_data[i + 2 * Q], q_data[i + 4 * Q], q_data[i + 5 * Q]}, 753c11f1fcSJeremy L Thompson {q_data[i + 3 * Q], q_data[i + 5 * Q], q_data[i + 6 * Q]} 76cb32e2e7SValeria Barra }; 77cb32e2e7SValeria Barra 782b730f8bSJeremy L Thompson for (int k = 0; k < 3; k++) { // k = component 792b730f8bSJeremy L Thompson for (int j = 0; j < 3; j++) { // j = direction of vg 802b730f8bSJeremy 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]); 812b730f8bSJeremy L Thompson } 822b730f8bSJeremy L Thompson } 83cb32e2e7SValeria Barra } // End of Quadrature Point Loop 84cb32e2e7SValeria Barra return 0; 85cb32e2e7SValeria Barra } 86cb32e2e7SValeria Barra // ----------------------------------------------------------------------------- 87