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