xref: /libCEED/examples/petsc/qfunctions/bps/bp4.h (revision dc7d240c1c3ecbc40e893ea38e37c8e19d48593c)
1 // Copyright (c) 2017, Lawrence Livermore National Security, LLC. Produced at
2 // the Lawrence Livermore National Laboratory. LLNL-CODE-734707. All Rights
3 // reserved. See files LICENSE and NOTICE for details.
4 //
5 // This file is part of CEED, a collection of benchmarks, miniapps, software
6 // libraries and APIs for efficient high-order finite element and spectral
7 // element discretizations for exascale applications. For more information and
8 // source code availability see http://github.com/ceed.
9 //
10 // The CEED research is supported by the Exascale Computing Project 17-SC-20-SC,
11 // a collaborative effort of two U.S. Department of Energy organizations (Office
12 // of Science and the National Nuclear Security Administration) responsible for
13 // the planning and preparation of a capable exascale ecosystem, including
14 // software, applications, hardware, advanced system engineering and early
15 // testbed platforms, in support of the nation's exascale computing imperative.
16 
17 /// @file
18 /// libCEED QFunctions for diffusion operator example using PETSc
19 
20 // -----------------------------------------------------------------------------
21 CEED_QFUNCTION(SetupDiffRhs3)(void *ctx, CeedInt Q,
22                               const CeedScalar *const *in,
23                               CeedScalar *const *out) {
24 #ifndef M_PI
25 #  define M_PI    3.14159265358979323846
26 #endif
27   const CeedScalar *x = in[0], *J = in[1], *w = in[2];
28   CeedScalar *true_soln = out[0], *rhs = out[1];
29 
30   // Quadrature Point Loop
31   CeedPragmaSIMD
32   for (CeedInt i=0; i<Q; i++) {
33     const CeedScalar J11 = J[i+Q*0];
34     const CeedScalar J21 = J[i+Q*1];
35     const CeedScalar J31 = J[i+Q*2];
36     const CeedScalar J12 = J[i+Q*3];
37     const CeedScalar J22 = J[i+Q*4];
38     const CeedScalar J32 = J[i+Q*5];
39     const CeedScalar J13 = J[i+Q*6];
40     const CeedScalar J23 = J[i+Q*7];
41     const CeedScalar J33 = J[i+Q*8];
42     const CeedScalar A11 = J22*J33 - J23*J32;
43     const CeedScalar A12 = J13*J32 - J12*J33;
44     const CeedScalar A13 = J12*J23 - J13*J22;
45 
46     const CeedScalar c[3] = { 0, 1., 2. };
47     const CeedScalar k[3] = { 1., 2., 3. };
48 
49     // Component 1
50     true_soln[i+0*Q] = sin(M_PI*(c[0] + k[0]*x[i+Q*0])) *
51                        sin(M_PI*(c[1] + k[1]*x[i+Q*1])) *
52                        sin(M_PI*(c[2] + k[2]*x[i+Q*2]));
53     // Component 2
54     true_soln[i+1*Q] = true_soln[i+0*Q];
55     // Component 3
56     true_soln[i+2*Q] = true_soln[i+0*Q];
57 
58     const CeedScalar rho = w[i] * (J11*A11 + J21*A12 + J31*A13);
59     // Component 1
60     rhs[i+0*Q] = rho * M_PI*M_PI * (k[0]*k[0] + k[1]*k[1] + k[2]*k[2]) *
61                  true_soln[i+0*Q];
62     // Component 2
63     rhs[i+1*Q] = rhs[i+0*Q];
64     // Component 3
65     rhs[i+2*Q] = rhs[i+0*Q];
66   } // End of Quadrature Point Loop
67 
68   return 0;
69 }
70 
71 // -----------------------------------------------------------------------------
72 CEED_QFUNCTION(Diff3)(void *ctx, CeedInt Q,
73                      const CeedScalar *const *in, CeedScalar *const *out) {
74   const CeedScalar *ug = in[0], *qd = in[1];
75   CeedScalar *vg = out[0];
76 
77   // Quadrature Point Loop
78   CeedPragmaSIMD
79   for (CeedInt i=0; i<Q; i++) {
80     // Read spatial derivatives of u components
81     const CeedScalar uJ[3][3]        = {{ug[i+(0+0*3)*Q],
82                                          ug[i+(0+1*3)*Q],
83                                          ug[i+(0+2*3)*Q]},
84                                         {ug[i+(1+0*3)*Q],
85                                          ug[i+(1+1*3)*Q],
86                                          ug[i+(1+2*3)*Q]},
87                                         {ug[i+(2+0*3)*Q],
88                                          ug[i+(2+1*3)*Q],
89                                          ug[i+(2+2*3)*Q]}
90                                        };
91     // Read qdata (dXdxdXdxT symmetric matrix)
92     const CeedScalar dXdxdXdxT[3][3] = {{qd[i+0*Q],
93                                          qd[i+1*Q],
94                                          qd[i+2*Q]},
95                                         {qd[i+1*Q],
96                                          qd[i+3*Q],
97                                          qd[i+4*Q]},
98                                         {qd[i+2*Q],
99                                          qd[i+4*Q],
100                                          qd[i+5*Q]}
101                                        };
102 
103     for (int k=0; k<3; k++) // k = component
104       for (int j=0; j<3; j++) // j = direction of vg
105         vg[i+(k+j*3)*Q] = (uJ[k][0] * dXdxdXdxT[0][j] +
106                            uJ[k][1] * dXdxdXdxT[1][j] +
107                            uJ[k][2] * dXdxdXdxT[2][j]);
108   } // End of Quadrature Point Loop
109 
110   return 0;
111 }
112 // -----------------------------------------------------------------------------
113