1 // Copyright (c) 2017-2022, Lawrence Livermore National Security, LLC and other CEED contributors. 2 // All Rights Reserved. See the top-level LICENSE and NOTICE files for details. 3 // 4 // SPDX-License-Identifier: BSD-2-Clause 5 // 6 // This file is part of CEED: http://github.com/ceed 7 8 /// @file 9 /// libCEED QFunctions for diffusion operator example using PETSc 10 11 #ifndef bp4_h 12 #define bp4_h 13 14 #include <ceed.h> 15 #include <math.h> 16 17 // ----------------------------------------------------------------------------- 18 // This QFunction sets up the rhs and true solution for the problem 19 // ----------------------------------------------------------------------------- 20 CEED_QFUNCTION(SetupDiffRhs3)(void *ctx, CeedInt Q, 21 const CeedScalar *const *in, 22 CeedScalar *const *out) { 23 #ifndef M_PI 24 # define M_PI 3.14159265358979323846 25 #endif 26 const CeedScalar *x = in[0], *w = in[1]; 27 CeedScalar *true_soln = out[0], *rhs = out[1]; 28 29 // Quadrature Point Loop 30 CeedPragmaSIMD 31 for (CeedInt i=0; i<Q; i++) { 32 const CeedScalar c[3] = { 0, 1., 2. }; 33 const CeedScalar k[3] = { 1., 2., 3. }; 34 35 // Component 1 36 true_soln[i+0*Q] = sin(M_PI*(c[0] + k[0]*x[i+Q*0])) * 37 sin(M_PI*(c[1] + k[1]*x[i+Q*1])) * 38 sin(M_PI*(c[2] + k[2]*x[i+Q*2])); 39 // Component 2 40 true_soln[i+1*Q] = 2 * true_soln[i+0*Q]; 41 // Component 3 42 true_soln[i+2*Q] = 3 * true_soln[i+0*Q]; 43 44 // Component 1 45 rhs[i+0*Q] = w[i+Q*0] * M_PI*M_PI * (k[0]*k[0] + k[1]*k[1] + k[2]*k[2]) * 46 true_soln[i+0*Q]; 47 // Component 2 48 rhs[i+1*Q] = 2 * rhs[i+0*Q]; 49 // Component 3 50 rhs[i+2*Q] = 3 * rhs[i+0*Q]; 51 } // End of Quadrature Point Loop 52 53 return 0; 54 } 55 56 // ----------------------------------------------------------------------------- 57 // This QFunction applies the diffusion operator for a vector field of 3 components. 58 // 59 // Inputs: 60 // ug - Input vector Jacobian at quadrature points 61 // q_data - Geometric factors 62 // 63 // Output: 64 // vJ - Output vector (test functions) Jacobian at quadrature points 65 // 66 // ----------------------------------------------------------------------------- 67 CEED_QFUNCTION(Diff3)(void *ctx, CeedInt Q, 68 const CeedScalar *const *in, CeedScalar *const *out) { 69 const CeedScalar *ug = in[0], *qd = in[1]; 70 CeedScalar *vg = out[0]; 71 72 // Quadrature Point Loop 73 CeedPragmaSIMD 74 for (CeedInt i=0; i<Q; i++) { 75 // Read spatial derivatives of u components 76 const CeedScalar uJ[3][3] = {{ug[i+(0+0*3)*Q], 77 ug[i+(0+1*3)*Q], 78 ug[i+(0+2*3)*Q]}, 79 {ug[i+(1+0*3)*Q], 80 ug[i+(1+1*3)*Q], 81 ug[i+(1+2*3)*Q]}, 82 {ug[i+(2+0*3)*Q], 83 ug[i+(2+1*3)*Q], 84 ug[i+(2+2*3)*Q]} 85 }; 86 // Read q_data (dXdxdXdx_T symmetric matrix) 87 const CeedScalar dXdxdXdx_T[3][3] = {{qd[i+1*Q], 88 qd[i+2*Q], 89 qd[i+3*Q]}, 90 {qd[i+2*Q], 91 qd[i+4*Q], 92 qd[i+5*Q]}, 93 {qd[i+3*Q], 94 qd[i+5*Q], 95 qd[i+6*Q]} 96 }; 97 98 for (int k=0; k<3; k++) // k = component 99 for (int j=0; j<3; j++) // j = direction of vg 100 vg[i+(k+j*3)*Q] = (uJ[k][0] * dXdxdXdx_T[0][j] + 101 uJ[k][1] * dXdxdXdx_T[1][j] + 102 uJ[k][2] * dXdxdXdx_T[2][j]); 103 } // End of Quadrature Point Loop 104 105 return 0; 106 } 107 // ----------------------------------------------------------------------------- 108 109 #endif // bp4_h 110