xref: /libCEED/tests/t567-operator.h (revision c9c2c07970382857cc7b4a28d359710237b91a3e)
196461910SJeremy L Thompson // Copyright (c) 2017-2022, Lawrence Livermore National Security, LLC and other CEED contributors.
296461910SJeremy L Thompson // All Rights Reserved. See the top-level LICENSE and NOTICE files for details.
396461910SJeremy L Thompson //
496461910SJeremy L Thompson // SPDX-License-Identifier: BSD-2-Clause
596461910SJeremy L Thompson //
696461910SJeremy L Thompson // This file is part of CEED:  http://github.com/ceed
796461910SJeremy L Thompson 
8*c9c2c079SJeremy L Thompson #include <ceed.h>
9*c9c2c079SJeremy L Thompson 
1096461910SJeremy L Thompson CEED_QFUNCTION(setup)(void *ctx, const CeedInt Q,
1196461910SJeremy L Thompson                       const CeedScalar *const *in,
1296461910SJeremy L Thompson                       CeedScalar *const *out) {
1396461910SJeremy L Thompson     // *INDENT-OFF*
1496461910SJeremy L Thompson   const CeedScalar                  *w = in[0],
1596461910SJeremy L Thompson                    (*J)[2][CEED_Q_VLA] = (const CeedScalar(*)[2][CEED_Q_VLA])in[1];
1696461910SJeremy L Thompson   CeedScalar     (*q_data)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0];
1796461910SJeremy L Thompson     // *INDENT-ON*
1896461910SJeremy L Thompson 
1996461910SJeremy L Thompson   // Quadrature point loop
2096461910SJeremy L Thompson   CeedPragmaSIMD
2196461910SJeremy L Thompson   for (CeedInt i=0; i<Q; i++) {
2296461910SJeremy L Thompson     // Qdata stored in Voigt convention
2396461910SJeremy L Thompson     // J: 0 2   q_data: 0 2   adj(J):  J11 -J01
2496461910SJeremy L Thompson     //    1 3           2 1           -J10  J00
2596461910SJeremy L Thompson     const CeedScalar J00 = J[0][0][i];
2696461910SJeremy L Thompson     const CeedScalar J10 = J[0][1][i];
2796461910SJeremy L Thompson     const CeedScalar J01 = J[1][0][i];
2896461910SJeremy L Thompson     const CeedScalar J11 = J[1][1][i];
2996461910SJeremy L Thompson     const CeedScalar qw = w[i] / (J00*J11 - J10*J01);
3096461910SJeremy L Thompson     q_data[0][i] =   qw * (J01*J01 + J11*J11);
3196461910SJeremy L Thompson     q_data[1][i] =   qw * (J00*J00 + J10*J10);
3296461910SJeremy L Thompson     q_data[2][i] = - qw * (J00*J01 + J10*J11);
3396461910SJeremy L Thompson   } // End of Quadrature Point Loop
3496461910SJeremy L Thompson 
3596461910SJeremy L Thompson   return 0;
3696461910SJeremy L Thompson }
3796461910SJeremy L Thompson 
3896461910SJeremy L Thompson CEED_QFUNCTION(diff)(void *ctx, const CeedInt Q, const CeedScalar *const *in,
3996461910SJeremy L Thompson                      CeedScalar *const *out) {
4096461910SJeremy L Thompson     // *INDENT-OFF*
4196461910SJeremy L Thompson   const CeedScalar (*q_data)[CEED_Q_VLA]    = (const CeedScalar(*)[CEED_Q_VLA])in[0],
4210a06a06SJeremy L Thompson                        (*ug)[2][CEED_Q_VLA] = (const CeedScalar(*)[2][CEED_Q_VLA])in[1];
4310a06a06SJeremy L Thompson   CeedScalar           (*vg)[2][CEED_Q_VLA] = (CeedScalar(*)[2][CEED_Q_VLA])out[0];
4496461910SJeremy L Thompson     // *INDENT-ON*
4596461910SJeremy L Thompson 
4696461910SJeremy L Thompson   const CeedInt dim = 2;
4710a06a06SJeremy L Thompson   const CeedScalar num_comp = 2;
4896461910SJeremy L Thompson   const CeedScalar scale[2][2] = {
4996461910SJeremy L Thompson     {1.0, 2.0},
5096461910SJeremy L Thompson     {3.0, 4.0},
5196461910SJeremy L Thompson   };
5296461910SJeremy L Thompson 
5396461910SJeremy L Thompson   // Quadrature point loop
5496461910SJeremy L Thompson   CeedPragmaSIMD
5596461910SJeremy L Thompson   for (CeedInt i=0; i<Q; i++) {
5696461910SJeremy L Thompson     // Read qdata (dXdxdXdxT symmetric matrix)
5796461910SJeremy L Thompson     // Stored in Voigt convention
5896461910SJeremy L Thompson     // 0 2
5996461910SJeremy L Thompson     // 2 1
6096461910SJeremy L Thompson     // *INDENT-OFF*
6196461910SJeremy L Thompson     const CeedScalar dXdxdXdxT[2][2] = {{q_data[0][i],
6296461910SJeremy L Thompson                                          q_data[2][i]},
6396461910SJeremy L Thompson                                         {q_data[2][i],
6496461910SJeremy L Thompson                                          q_data[1][i]}
6596461910SJeremy L Thompson                                        };
6696461910SJeremy L Thompson     // *INDENT-ON*
6796461910SJeremy L Thompson 
6896461910SJeremy L Thompson     // Apply Poisson operator
6996461910SJeremy L Thompson     // j = direction of vg
7010a06a06SJeremy L Thompson     for (CeedInt j=0; j<dim; j++) {
7110a06a06SJeremy L Thompson       for (CeedInt k=0; k<num_comp; k++) {
7210a06a06SJeremy L Thompson         vg[j][k][i] = (ug[0][k][i] * dXdxdXdxT[0][j] * scale[0][j] +
7310a06a06SJeremy L Thompson                        ug[1][k][i] * dXdxdXdxT[1][j] * scale[1][j]);
7410a06a06SJeremy L Thompson       }
7510a06a06SJeremy L Thompson     }
7696461910SJeremy L Thompson   } // End of Quadrature Point Loop
7796461910SJeremy L Thompson 
7896461910SJeremy L Thompson   return 0;
7996461910SJeremy L Thompson }
80