1*52bfb9bbSJeremy L Thompson /// @file 2*52bfb9bbSJeremy L Thompson /// Test grad with a 2D Simplex non-tensor H1 basis 3*52bfb9bbSJeremy L Thompson /// \test Test grad with a 2D Simplex non-tensor H1 basis 4*52bfb9bbSJeremy L Thompson #include <ceed.h> 5*52bfb9bbSJeremy L Thompson #include <math.h> 6*52bfb9bbSJeremy L Thompson #include "t320-basis.h" 7*52bfb9bbSJeremy L Thompson 8*52bfb9bbSJeremy L Thompson double feval(double x1, double x2) { 9*52bfb9bbSJeremy L Thompson return x1*x1 + x2*x2 + x1*x2 + 1; 10*52bfb9bbSJeremy L Thompson } 11*52bfb9bbSJeremy L Thompson 12*52bfb9bbSJeremy L Thompson double dfeval(double x1, double x2) { 13*52bfb9bbSJeremy L Thompson return 2*x1 + x2; 14*52bfb9bbSJeremy L Thompson } 15*52bfb9bbSJeremy L Thompson 16*52bfb9bbSJeremy L Thompson int main(int argc, char **argv) { 17*52bfb9bbSJeremy L Thompson Ceed ceed; 18*52bfb9bbSJeremy L Thompson CeedVector In, Out; 19*52bfb9bbSJeremy L Thompson const CeedInt P = 6, Q = 4, dim = 2; 20*52bfb9bbSJeremy L Thompson CeedBasis b; 21*52bfb9bbSJeremy L Thompson CeedScalar qref[dim*Q], qweight[Q]; 22*52bfb9bbSJeremy L Thompson CeedScalar interp[P*Q], grad[dim*P*Q]; 23*52bfb9bbSJeremy L Thompson CeedScalar xq[] = {0.2, 0.6, 1./3., 0.2, 0.2, 0.2, 1./3., 0.6}; 24*52bfb9bbSJeremy L Thompson CeedScalar xr[] = {0., 0.5, 1., 0., 0.5, 0., 0., 0., 0., 0.5, 0.5, 1.}; 25*52bfb9bbSJeremy L Thompson const CeedScalar *out; 26*52bfb9bbSJeremy L Thompson CeedScalar in[P], value; 27*52bfb9bbSJeremy L Thompson 28*52bfb9bbSJeremy L Thompson buildmats(qref, qweight, interp, grad); 29*52bfb9bbSJeremy L Thompson 30*52bfb9bbSJeremy L Thompson CeedInit(argv[1], &ceed); 31*52bfb9bbSJeremy L Thompson 32*52bfb9bbSJeremy L Thompson CeedBasisCreateH1(ceed, CEED_TRIANGLE, 1, P, Q, interp, grad, qref, 33*52bfb9bbSJeremy L Thompson qweight, &b); 34*52bfb9bbSJeremy L Thompson 35*52bfb9bbSJeremy L Thompson // Interpolate function to quadrature points 36*52bfb9bbSJeremy L Thompson for (int i=0; i<P; i++) 37*52bfb9bbSJeremy L Thompson in[i] = feval(xr[0*P+i], xr[1*P+i]); 38*52bfb9bbSJeremy L Thompson 39*52bfb9bbSJeremy L Thompson CeedVectorCreate(ceed, P, &In); 40*52bfb9bbSJeremy L Thompson CeedVectorSetArray(In, CEED_MEM_HOST, CEED_USE_POINTER, in); 41*52bfb9bbSJeremy L Thompson CeedVectorCreate(ceed, Q*dim, &Out); 42*52bfb9bbSJeremy L Thompson CeedVectorSetValue(Out, 0); 43*52bfb9bbSJeremy L Thompson 44*52bfb9bbSJeremy L Thompson CeedBasisApply(b, 1, CEED_NOTRANSPOSE, CEED_EVAL_GRAD, In, Out); 45*52bfb9bbSJeremy L Thompson 46*52bfb9bbSJeremy L Thompson // Check values at quadrature points 47*52bfb9bbSJeremy L Thompson CeedVectorGetArrayRead(Out, CEED_MEM_HOST, &out); 48*52bfb9bbSJeremy L Thompson for (int i=0; i<Q; i++) { 49*52bfb9bbSJeremy L Thompson value = dfeval(xq[0*Q+i], xq[1*Q+i]); 50*52bfb9bbSJeremy L Thompson if (fabs(out[0*Q+i] - value) > 1e-10) 51*52bfb9bbSJeremy L Thompson // LCOV_EXCL_START 52*52bfb9bbSJeremy L Thompson printf("[%d] %f != %f\n", i, out[0*Q+i], value); 53*52bfb9bbSJeremy L Thompson // LCOV_EXCL_STOP 54*52bfb9bbSJeremy L Thompson value = dfeval(xq[1*Q+i], xq[0*Q+i]); 55*52bfb9bbSJeremy L Thompson if (fabs(out[1*Q+i] - value) > 1e-10) 56*52bfb9bbSJeremy L Thompson // LCOV_EXCL_START 57*52bfb9bbSJeremy L Thompson printf("[%d] %f != %f\n", i, out[1*Q+i], value); 58*52bfb9bbSJeremy L Thompson // LCOV_EXCL_STOP 59*52bfb9bbSJeremy L Thompson } 60*52bfb9bbSJeremy L Thompson CeedVectorRestoreArrayRead(Out, &out); 61*52bfb9bbSJeremy L Thompson 62*52bfb9bbSJeremy L Thompson CeedVectorDestroy(&In); 63*52bfb9bbSJeremy L Thompson CeedVectorDestroy(&Out); 64*52bfb9bbSJeremy L Thompson CeedBasisDestroy(&b); 65*52bfb9bbSJeremy L Thompson CeedDestroy(&ceed); 66*52bfb9bbSJeremy L Thompson return 0; 67*52bfb9bbSJeremy L Thompson } 68