152bfb9bbSJeremy L Thompson /// @file 252bfb9bbSJeremy L Thompson /// Test interpolation with a 2D Simplex non-tensor H1 basis 352bfb9bbSJeremy L Thompson /// \test Test interpolaton with a 2D Simplex non-tensor H1 basis 452bfb9bbSJeremy L Thompson #include <ceed.h> 552bfb9bbSJeremy L Thompson #include <math.h> 6*2b730f8bSJeremy L Thompson 752bfb9bbSJeremy L Thompson #include "t320-basis.h" 852bfb9bbSJeremy L Thompson 9*2b730f8bSJeremy L Thompson // polynomial eval helper 10*2b730f8bSJeremy L Thompson static CeedScalar feval(CeedScalar x1, CeedScalar x2) { return x1 * x1 + x2 * x2 + x1 * x2 + 1; } 1152bfb9bbSJeremy L Thompson 12*2b730f8bSJeremy L Thompson // main test 1352bfb9bbSJeremy L Thompson int main(int argc, char **argv) { 1452bfb9bbSJeremy L Thompson Ceed ceed; 1552bfb9bbSJeremy L Thompson CeedVector In, Out; 1652bfb9bbSJeremy L Thompson const CeedInt P = 6, Q = 4, dim = 2; 1752bfb9bbSJeremy L Thompson CeedBasis b; 18d1d35e2fSjeremylt CeedScalar q_ref[dim * Q], q_weight[Q]; 1952bfb9bbSJeremy L Thompson CeedScalar interp[P * Q], grad[dim * P * Q]; 2052bfb9bbSJeremy L Thompson CeedScalar xq[] = {0.2, 0.6, 1. / 3., 0.2, 0.2, 0.2, 1. / 3., 0.6}; 2152bfb9bbSJeremy L Thompson CeedScalar xr[] = {0., 0.5, 1., 0., 0.5, 0., 0., 0., 0., 0.5, 0.5, 1.}; 2252bfb9bbSJeremy L Thompson const CeedScalar *out; 2352bfb9bbSJeremy L Thompson CeedScalar in[P], value; 2452bfb9bbSJeremy L Thompson 25d1d35e2fSjeremylt buildmats(q_ref, q_weight, interp, grad); 2652bfb9bbSJeremy L Thompson 2752bfb9bbSJeremy L Thompson CeedInit(argv[1], &ceed); 2852bfb9bbSJeremy L Thompson 29*2b730f8bSJeremy L Thompson CeedBasisCreateH1(ceed, CEED_TOPOLOGY_TRIANGLE, 1, P, Q, interp, grad, q_ref, q_weight, &b); 3052bfb9bbSJeremy L Thompson 3152bfb9bbSJeremy L Thompson // Interpolate function to quadrature points 32*2b730f8bSJeremy L Thompson for (int i = 0; i < P; i++) in[i] = feval(xr[0 * P + i], xr[1 * P + i]); 3352bfb9bbSJeremy L Thompson 3452bfb9bbSJeremy L Thompson CeedVectorCreate(ceed, P, &In); 3552bfb9bbSJeremy L Thompson CeedVectorSetArray(In, CEED_MEM_HOST, CEED_USE_POINTER, in); 3652bfb9bbSJeremy L Thompson CeedVectorCreate(ceed, Q, &Out); 3752bfb9bbSJeremy L Thompson CeedVectorSetValue(Out, 0); 3852bfb9bbSJeremy L Thompson 3952bfb9bbSJeremy L Thompson CeedBasisApply(b, 1, CEED_NOTRANSPOSE, CEED_EVAL_INTERP, In, Out); 4052bfb9bbSJeremy L Thompson 4152bfb9bbSJeremy L Thompson // Check values at quadrature points 4252bfb9bbSJeremy L Thompson CeedVectorGetArrayRead(Out, CEED_MEM_HOST, &out); 4352bfb9bbSJeremy L Thompson for (int i = 0; i < Q; i++) { 4452bfb9bbSJeremy L Thompson value = feval(xq[0 * Q + i], xq[1 * Q + i]); 45*2b730f8bSJeremy L Thompson if (fabs(out[i] - value) > 100. * CEED_EPSILON) printf("[%" CeedInt_FMT "] %f != %f\n", i, out[i], value); 4652bfb9bbSJeremy L Thompson } 4752bfb9bbSJeremy L Thompson CeedVectorRestoreArrayRead(Out, &out); 4852bfb9bbSJeremy L Thompson 4952bfb9bbSJeremy L Thompson CeedVectorDestroy(&In); 5052bfb9bbSJeremy L Thompson CeedVectorDestroy(&Out); 5152bfb9bbSJeremy L Thompson CeedBasisDestroy(&b); 5252bfb9bbSJeremy L Thompson CeedDestroy(&ceed); 5352bfb9bbSJeremy L Thompson return 0; 5452bfb9bbSJeremy L Thompson } 55