xref: /libCEED/tests/t330-basis.h (revision 59058f143caab4a5a45b9184e86ce60f92295465)
150c301a5SRezgar Shakeri // Copyright (c) 2017-2018, Lawrence Livermore National Security, LLC.
250c301a5SRezgar Shakeri // Produced at the Lawrence Livermore National Laboratory. LLNL-CODE-734707.
350c301a5SRezgar Shakeri // All Rights reserved. See files LICENSE and NOTICE for details.
450c301a5SRezgar Shakeri //
550c301a5SRezgar Shakeri // This file is part of CEED, a collection of benchmarks, miniapps, software
650c301a5SRezgar Shakeri // libraries and APIs for efficient high-order finite element and spectral
750c301a5SRezgar Shakeri // element discretizations for exascale applications. For more information and
850c301a5SRezgar Shakeri // source code availability see http://github.com/ceed.
950c301a5SRezgar Shakeri //
1050c301a5SRezgar Shakeri // The CEED research is supported by the Exascale Computing Project 17-SC-20-SC,
1150c301a5SRezgar Shakeri // a collaborative effort of two U.S. Department of Energy organizations (Office
1250c301a5SRezgar Shakeri // of Science and the National Nuclear Security Administration) responsible for
1350c301a5SRezgar Shakeri // the planning and preparation of a capable exascale ecosystem, including
1450c301a5SRezgar Shakeri // software, applications, hardware, advanced system engineering and early
1550c301a5SRezgar Shakeri // testbed platforms, in support of the nation's exascale computing imperative.
1650c301a5SRezgar Shakeri 
1750c301a5SRezgar Shakeri // Hdiv basis for quadrilateral linear BDMelement in 2D
1850c301a5SRezgar Shakeri // Local numbering is as follow (each edge has 2 vector dof)
1950c301a5SRezgar Shakeri //     b4     b5
2050c301a5SRezgar Shakeri //    2---------3
2150c301a5SRezgar Shakeri //  b7|         |b3
2250c301a5SRezgar Shakeri //    |         |
2350c301a5SRezgar Shakeri //  b6|         |b2
2450c301a5SRezgar Shakeri //    0---------1
2550c301a5SRezgar Shakeri //     b0     b1
2650c301a5SRezgar Shakeri // Bx[0-->7] = b0_x-->b7_x, By[0-->7] = b0_y-->b7_y
2750c301a5SRezgar Shakeri // To see how the nodal basis is constructed visit:
2850c301a5SRezgar Shakeri // https://github.com/rezgarshakeri/H-div-Tests
2950c301a5SRezgar Shakeri int NodalHdivBasisQuad(CeedScalar *X, CeedScalar *Bx, CeedScalar *By) {
3050c301a5SRezgar Shakeri   CeedScalar x_hat = X[0];
3150c301a5SRezgar Shakeri   CeedScalar y_hat = X[1];
3250c301a5SRezgar Shakeri   Bx[0] = -0.125 + 0.125*x_hat*x_hat;
3350c301a5SRezgar Shakeri   By[0] = -0.25 + 0.25*x_hat + 0.25*y_hat + -0.25*x_hat*y_hat;
3450c301a5SRezgar Shakeri   Bx[1] = 0.125 + -0.125*x_hat*x_hat;
3550c301a5SRezgar Shakeri   By[1] = -0.25 + -0.25*x_hat + 0.25*y_hat + 0.25*x_hat*y_hat;
3650c301a5SRezgar Shakeri   Bx[2] = 0.25 + 0.25*x_hat + -0.25*y_hat + -0.25*x_hat*y_hat;
3750c301a5SRezgar Shakeri   By[2] = -0.125 + 0.125*y_hat*y_hat;
3850c301a5SRezgar Shakeri   Bx[3] = 0.25 + 0.25*x_hat + 0.25*y_hat + 0.25*x_hat*y_hat;
3950c301a5SRezgar Shakeri   By[3] = 0.125 + -0.125*y_hat*y_hat;
4050c301a5SRezgar Shakeri   Bx[4] = -0.125 + 0.125*x_hat*x_hat;
4150c301a5SRezgar Shakeri   By[4] = 0.25 + -0.25*x_hat + 0.25*y_hat + -0.25*x_hat*y_hat;
4250c301a5SRezgar Shakeri   Bx[5] = 0.125 + -0.125*x_hat*x_hat;
4350c301a5SRezgar Shakeri   By[5] = 0.25 + 0.25*x_hat + 0.25*y_hat + 0.25*x_hat*y_hat;
4450c301a5SRezgar Shakeri   Bx[6] = -0.25 + 0.25*x_hat + 0.25*y_hat + -0.25*x_hat*y_hat;
4550c301a5SRezgar Shakeri   By[6] = -0.125 + 0.125*y_hat*y_hat;
4650c301a5SRezgar Shakeri   Bx[7] = -0.25 + 0.25*x_hat + -0.25*y_hat + 0.25*x_hat*y_hat;
4750c301a5SRezgar Shakeri   By[7] = 0.125 + -0.125*y_hat*y_hat;
4850c301a5SRezgar Shakeri   return 0;
4950c301a5SRezgar Shakeri }
5050c301a5SRezgar Shakeri static void HdivBasisQuad(CeedInt Q, CeedScalar *q_ref, CeedScalar *q_weights,
5150c301a5SRezgar Shakeri                           CeedScalar *interp, CeedScalar *div, CeedQuadMode quad_mode) {
5250c301a5SRezgar Shakeri 
5350c301a5SRezgar Shakeri   // Get 1D quadrature on [-1,1]
5450c301a5SRezgar Shakeri   CeedScalar q_ref_1d[Q], q_weight_1d[Q];
5550c301a5SRezgar Shakeri   switch (quad_mode) {
5650c301a5SRezgar Shakeri   case CEED_GAUSS:
5750c301a5SRezgar Shakeri     CeedGaussQuadrature(Q, q_ref_1d, q_weight_1d);
5850c301a5SRezgar Shakeri     break;
59*59058f14SJeremy L Thompson   // LCOV_EXCL_START
6050c301a5SRezgar Shakeri   case CEED_GAUSS_LOBATTO:
6150c301a5SRezgar Shakeri     CeedLobattoQuadrature(Q, q_ref_1d, q_weight_1d);
6250c301a5SRezgar Shakeri     break;
6350c301a5SRezgar Shakeri   }
64*59058f14SJeremy L Thompson   // LCOV_EXCL_STOP
6550c301a5SRezgar Shakeri 
6650c301a5SRezgar Shakeri   // Divergence operator; Divergence of nodal basis for ref element
6750c301a5SRezgar Shakeri   CeedScalar D[8] = {0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25};
6850c301a5SRezgar Shakeri   // Loop over quadrature points
6950c301a5SRezgar Shakeri   CeedScalar Bx[8], By[8];
7050c301a5SRezgar Shakeri   CeedScalar X[2];
7150c301a5SRezgar Shakeri 
7250c301a5SRezgar Shakeri   for (CeedInt i=0; i<Q; i++) {
7350c301a5SRezgar Shakeri     for (CeedInt j=0; j<Q; j++) {
7450c301a5SRezgar Shakeri       CeedInt k1 = Q*i+j;
7550c301a5SRezgar Shakeri       q_ref[k1] = q_ref_1d[j];
7650c301a5SRezgar Shakeri       q_ref[k1 + Q*Q] = q_ref_1d[i];
7750c301a5SRezgar Shakeri       q_weights[k1] = q_weight_1d[j]*q_weight_1d[i];
7850c301a5SRezgar Shakeri       X[0] = q_ref_1d[j];
7950c301a5SRezgar Shakeri       X[1] = q_ref_1d[i];
8050c301a5SRezgar Shakeri       NodalHdivBasisQuad(X, Bx, By);
8150c301a5SRezgar Shakeri       for (CeedInt k=0; k<8; k++) {
8250c301a5SRezgar Shakeri         interp[k1*8+k] = Bx[k];
8350c301a5SRezgar Shakeri         interp[k1*8+k+8*Q*Q] = By[k];
8450c301a5SRezgar Shakeri         div[k1*8+k] = D[k];
8550c301a5SRezgar Shakeri       }
8650c301a5SRezgar Shakeri     }
8750c301a5SRezgar Shakeri   }
8850c301a5SRezgar Shakeri }