xref: /libCEED/examples/petsc/qfunctions/bps/bp1.h (revision a57ca787a7f60d7c960eb3632298c2a0ffab656b)
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 mass operator example using PETSc
19 
20 #ifndef bp1_h
21 #define bp1_h
22 #include <ceed.h>
23 
24 #ifndef __CUDACC__
25 #  include <math.h>
26 #endif
27 
28 // *****************************************************************************
29 // This QFunction sets up the geometric factors required to apply the
30 //   mass operator
31 //
32 // The quadrature data is stored in the array qdata.
33 //
34 // We require the determinant of the Jacobian to properly compute integrals of
35 //   the form: int( u v )
36 //
37 // Qdata: detJ * w
38 //
39 // *****************************************************************************
40 
41 // -----------------------------------------------------------------------------
42 CEED_QFUNCTION(SetupMassGeo)(void *ctx, const CeedInt Q,
43                              const CeedScalar *const *in,
44                              CeedScalar *const *out) {
45   const CeedScalar *J = in[0], *w = in[1];
46   CeedScalar *qdata = out[0];
47 
48   // Quadrature Point Loop
49   CeedPragmaSIMD
50   for (CeedInt i=0; i<Q; i++) {
51     const CeedScalar detJ = (J[i+Q*0]*(J[i+Q*4]*J[i+Q*8] - J[i+Q*5]*J[i+Q*7]) -
52                              J[i+Q*1]*(J[i+Q*3]*J[i+Q*8] - J[i+Q*5]*J[i+Q*6]) +
53                              J[i+Q*2]*(J[i+Q*3]*J[i+Q*7] - J[i+Q*4]*J[i+Q*6]));
54     qdata[i] = detJ * w[i];
55   } // End of Quadrature Point Loop
56   return 0;
57 }
58 
59 // *****************************************************************************
60 // This QFunction sets up the rhs and true solution for the problem
61 // *****************************************************************************
62 
63 // -----------------------------------------------------------------------------
64 CEED_QFUNCTION(SetupMassRhs)(void *ctx, const CeedInt Q,
65                              const CeedScalar *const *in,
66                              CeedScalar *const *out) {
67   const CeedScalar *x = in[0], *J = in[1], *w = in[2];
68   CeedScalar *true_soln = out[0], *rhs = out[1];
69 
70   // Quadrature Point Loop
71   CeedPragmaSIMD
72   for (CeedInt i=0; i<Q; i++) {
73     const CeedScalar det = (J[i+Q*0]*(J[i+Q*4]*J[i+Q*8] - J[i+Q*5]*J[i+Q*7]) -
74                             J[i+Q*1]*(J[i+Q*3]*J[i+Q*8] - J[i+Q*5]*J[i+Q*6]) +
75                             J[i+Q*2]*(J[i+Q*3]*J[i+Q*7] - J[i+Q*4]*J[i+Q*6]));
76 
77     true_soln[i] = sqrt(x[i]*x[i] + x[i+Q]*x[i+Q] + x[i+2*Q]*x[i+2*Q]);
78 
79     rhs[i] = det * w[i] * true_soln[i];
80   } // End of Quadrature Point Loop
81   return 0;
82 }
83 
84 
85 // *****************************************************************************
86 // This QFunction applies the mass operator for a scalar field.
87 //
88 // Inputs:
89 //   u     - Input vector at quadrature points
90 //   qdata - Geometric factors
91 //
92 // Output:
93 //   v     - Output vector (test functions) at quadrature points
94 //
95 // *****************************************************************************
96 
97 // -----------------------------------------------------------------------------
98 CEED_QFUNCTION(Mass)(void *ctx, const CeedInt Q,
99                      const CeedScalar *const *in, CeedScalar *const *out) {
100   const CeedScalar *u = in[0], *qdata = in[1];
101   CeedScalar *v = out[0];
102 
103   // Quadrature Point Loop
104   CeedPragmaSIMD
105   for (CeedInt i=0; i<Q; i++)
106     v[i] = qdata[i] * u[i];
107 
108   return 0;
109 }
110 // -----------------------------------------------------------------------------
111 
112 #endif // bp1_h
113