xref: /libCEED/python/tests/test-qfunctions.h (revision 0ef725981a32b9079ff6c5100673b913b8f4d7c0)
1*0ef72598Sjeremylt // Copyright (c) 2017-2018, Lawrence Livermore National Security, LLC.
2*0ef72598Sjeremylt // Produced at the Lawrence Livermore National Laboratory. LLNL-CODE-734707.
3*0ef72598Sjeremylt // All Rights reserved. See files LICENSE and NOTICE for details.
4*0ef72598Sjeremylt //
5*0ef72598Sjeremylt // This file is part of CEED, a collection of benchmarks, miniapps, software
6*0ef72598Sjeremylt // libraries and APIs for efficient high-order finite element and spectral
7*0ef72598Sjeremylt // element discretizations for exascale applications. For more information and
8*0ef72598Sjeremylt // source code availability see http://github.com/ceed.
9*0ef72598Sjeremylt //
10*0ef72598Sjeremylt // The CEED research is supported by the Exascale Computing Project 17-SC-20-SC,
11*0ef72598Sjeremylt // a collaborative effort of two U.S. Department of Energy organizations (Office
12*0ef72598Sjeremylt // of Science and the National Nuclear Security Administration) responsible for
13*0ef72598Sjeremylt // the planning and preparation of a capable exascale ecosystem, including
14*0ef72598Sjeremylt // software, applications, hardware, advanced system engineering and early
15*0ef72598Sjeremylt // testbed platforms, in support of the nation's exascale computing imperative.
16*0ef72598Sjeremylt 
17*0ef72598Sjeremylt //------------------------------------------------------------------------------
18*0ef72598Sjeremylt // Setup 1D mass matrix
19*0ef72598Sjeremylt //------------------------------------------------------------------------------
20*0ef72598Sjeremylt CEED_QFUNCTION(setup_mass)(void *ctx, const CeedInt Q,
21*0ef72598Sjeremylt                            const CeedScalar *const *in,
22*0ef72598Sjeremylt                            CeedScalar *const *out) {
23*0ef72598Sjeremylt   // in[0] is quadrature weights, size (Q)
24*0ef72598Sjeremylt   // in[1] is Jacobians, size (Q)
25*0ef72598Sjeremylt   const CeedScalar *w = in[0], *J = in[1];
26*0ef72598Sjeremylt 
27*0ef72598Sjeremylt   // out[0] is quadrature data, size (Q)
28*0ef72598Sjeremylt   CeedScalar *qdata = out[0];
29*0ef72598Sjeremylt 
30*0ef72598Sjeremylt   // Quadrature point loop
31*0ef72598Sjeremylt   CeedPragmaSIMD
32*0ef72598Sjeremylt   for (CeedInt i=0; i<Q; i++) {
33*0ef72598Sjeremylt     qdata[i] = J[i] * w[i];
34*0ef72598Sjeremylt   }
35*0ef72598Sjeremylt 
36*0ef72598Sjeremylt   return 0;
37*0ef72598Sjeremylt }
38*0ef72598Sjeremylt 
39*0ef72598Sjeremylt //------------------------------------------------------------------------------
40*0ef72598Sjeremylt // Setup 2D mass matrix
41*0ef72598Sjeremylt //------------------------------------------------------------------------------
42*0ef72598Sjeremylt CEED_QFUNCTION(setup_mass_2d)(void *ctx, const CeedInt Q,
43*0ef72598Sjeremylt                               const CeedScalar *const *in,
44*0ef72598Sjeremylt                               CeedScalar *const *out) {
45*0ef72598Sjeremylt   // in[0] is quadrature weights, size (Q)
46*0ef72598Sjeremylt   // in[1] is Jacobians with shape [2, nc=2, Q]
47*0ef72598Sjeremylt   const CeedScalar *w = in[0], *J = in[1];
48*0ef72598Sjeremylt 
49*0ef72598Sjeremylt   // out[0] is quadrature data, size (Q)
50*0ef72598Sjeremylt   CeedScalar *qdata = out[0];
51*0ef72598Sjeremylt 
52*0ef72598Sjeremylt   // Quadrature point loop
53*0ef72598Sjeremylt   CeedPragmaSIMD
54*0ef72598Sjeremylt   for (CeedInt i=0; i<Q; i++) {
55*0ef72598Sjeremylt     qdata[i] = w[i] * (J[i+Q*0]*J[i+Q*3] - J[i+Q*1]*J[i+Q*2]);
56*0ef72598Sjeremylt   }
57*0ef72598Sjeremylt 
58*0ef72598Sjeremylt   return 0;
59*0ef72598Sjeremylt }
60*0ef72598Sjeremylt 
61*0ef72598Sjeremylt //------------------------------------------------------------------------------
62*0ef72598Sjeremylt // Apply mass matrix
63*0ef72598Sjeremylt //------------------------------------------------------------------------------
64*0ef72598Sjeremylt CEED_QFUNCTION(apply_mass)(void *ctx, const CeedInt Q,
65*0ef72598Sjeremylt                            const CeedScalar *const *in,
66*0ef72598Sjeremylt                            CeedScalar *const *out) {
67*0ef72598Sjeremylt   // Get scaling factor, if set
68*0ef72598Sjeremylt   const CeedScalar *scale_array = ctx ? (CeedScalar *)ctx : NULL;
69*0ef72598Sjeremylt   const CeedScalar scale = ctx ? scale_array[4] : 1.;
70*0ef72598Sjeremylt 
71*0ef72598Sjeremylt   // in[0] is quadrature data, size (Q)
72*0ef72598Sjeremylt   // in[1] is u, size (Q)
73*0ef72598Sjeremylt   const CeedScalar *qdata = in[0], *u = in[1];
74*0ef72598Sjeremylt 
75*0ef72598Sjeremylt   // out[0] is v, size (Q)
76*0ef72598Sjeremylt   CeedScalar *v = out[0];
77*0ef72598Sjeremylt 
78*0ef72598Sjeremylt   // Quadrature point loop
79*0ef72598Sjeremylt   CeedPragmaSIMD
80*0ef72598Sjeremylt   for (CeedInt i=0; i<Q; i++) {
81*0ef72598Sjeremylt     v[i] = scale * qdata[i] * u[i];
82*0ef72598Sjeremylt   }
83*0ef72598Sjeremylt 
84*0ef72598Sjeremylt   return 0;
85*0ef72598Sjeremylt }
86*0ef72598Sjeremylt 
87*0ef72598Sjeremylt //------------------------------------------------------------------------------
88*0ef72598Sjeremylt // Apply mass matrix to two components
89*0ef72598Sjeremylt //------------------------------------------------------------------------------
90*0ef72598Sjeremylt CEED_QFUNCTION(apply_mass_two)(void *ctx, const CeedInt Q,
91*0ef72598Sjeremylt                                const CeedScalar *const *in,
92*0ef72598Sjeremylt                                CeedScalar *const *out) {
93*0ef72598Sjeremylt   // in[0] is quadrature data, size (Q)
94*0ef72598Sjeremylt   // in[1] is u, size (2*Q)
95*0ef72598Sjeremylt   const CeedScalar *qdata = in[0], *u = in[1];
96*0ef72598Sjeremylt 
97*0ef72598Sjeremylt   // out[0] is v, size (2*Q)
98*0ef72598Sjeremylt   CeedScalar *v = out[0];
99*0ef72598Sjeremylt 
100*0ef72598Sjeremylt   // Quadrature point loop
101*0ef72598Sjeremylt   CeedPragmaSIMD
102*0ef72598Sjeremylt   for (CeedInt i=0; i<Q; i++) {
103*0ef72598Sjeremylt     v[i]   = qdata[i] * u[i];
104*0ef72598Sjeremylt     v[Q+i] = qdata[i] * u[Q+i];
105*0ef72598Sjeremylt   }
106*0ef72598Sjeremylt 
107*0ef72598Sjeremylt   return 0;
108*0ef72598Sjeremylt }
109*0ef72598Sjeremylt 
110*0ef72598Sjeremylt //------------------------------------------------------------------------------
111