xref: /libCEED/examples/petsc/qfunctions/bps/bp2.h (revision 2459f3f1cd4d7d2e210e1c26d669bd2fde41a0b6)
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 mass operator example using PETSc
10 
11 #ifndef bp2_h
12 #define bp2_h
13 
14 #include <math.h>
15 
16 // -----------------------------------------------------------------------------
17 // This QFunction sets up the rhs and true solution for the problem
18 // -----------------------------------------------------------------------------
19 CEED_QFUNCTION(SetupMassRhs3)(void *ctx, const CeedInt Q,
20                               const CeedScalar *const *in,
21                               CeedScalar *const *out) {
22   const CeedScalar *x = in[0], *w = in[1];
23   CeedScalar *true_soln = out[0], *rhs = out[1];
24 
25   // Quadrature Point Loop
26   CeedPragmaSIMD
27   for (CeedInt i=0; i<Q; i++) {
28     // Component 1
29     true_soln[i+0*Q] =  sqrt(x[i]*x[i] + x[i+Q]*x[i+Q] + x[i+2*Q]*x[i+2*Q]);
30     // Component 2
31     true_soln[i+1*Q] = 2 * true_soln[i+0*Q];
32     // Component 3
33     true_soln[i+2*Q] = 3 * true_soln[i+0*Q];
34 
35     // Component 1
36     rhs[i+0*Q] = w[i] * true_soln[i+0*Q];
37     // Component 2
38     rhs[i+1*Q] = 2 * rhs[i+0*Q];
39     // Component 3
40     rhs[i+2*Q] = 3 * rhs[i+0*Q];
41   } // End of Quadrature Point Loop
42   return 0;
43 }
44 
45 // -----------------------------------------------------------------------------
46 // This QFunction applies the mass operator for a vector field of 3 components.
47 //
48 // Inputs:
49 //   u     - Input vector at quadrature points
50 //   q_data - Geometric factors
51 //
52 // Output:
53 //   v     - Output vector (test functions) at quadrature points
54 //
55 // -----------------------------------------------------------------------------
56 CEED_QFUNCTION(Mass3)(void *ctx, const CeedInt Q,
57                       const CeedScalar *const *in, CeedScalar *const *out) {
58   const CeedScalar *u = in[0], *q_data = in[1];
59   CeedScalar *v = out[0];
60 
61   // Quadrature Point Loop
62   CeedPragmaSIMD
63   for (CeedInt i=0; i<Q; i++) {
64     // Component 1
65     v[i+0*Q] = q_data[i] * u[i+0*Q];
66     // Component 2
67     v[i+1*Q] = q_data[i] * u[i+1*Q];
68     // Component 3
69     v[i+2*Q] = q_data[i] * u[i+2*Q];
70   } // End of Quadrature Point Loop
71   return 0;
72 }
73 // -----------------------------------------------------------------------------
74 
75 #endif // bp2_h
76