xref: /libCEED/tests/t311-basis.c (revision a7dfafedf609254b38e08b1a69b8cef563b749ef)
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 #include "t310-basis.h"
7 
8 double feval(double x1, double x2) {
9   return x1*x1 + x2*x2 + x1*x2 + 1;
10 }
11 
12 int main(int argc, char **argv) {
13   Ceed ceed;
14   const CeedInt P = 6, Q = 4, dim = 2;
15   CeedBasis b;
16   CeedScalar qref[dim*Q], qweight[Q];
17   CeedScalar interp[P*Q], grad[dim*P*Q];
18   CeedScalar xq[] = {0.2, 0.6, 1./3., 0.2, 0.2, 0.2, 1./3., 0.6};
19   CeedScalar xr[] = {0., 0.5, 1., 0., 0.5, 0., 0., 0., 0., 0.5, 0.5, 1.};
20   CeedScalar in[P], out[Q], value;
21 
22   buildmats(qref, qweight, interp, grad);
23 
24   CeedInit(argv[1], &ceed);
25   CeedBasisCreateH1(ceed, CEED_TRIANGLE, 1, P, Q, interp, grad, qref, qweight,
26                     &b);
27 
28   // Interpolate function to quadrature points
29   for (int i=0; i<P; i++)
30     in[i] = feval(xr[0*P+i], xr[1*P+i]);
31   CeedBasisApply(b, 1, CEED_NOTRANSPOSE, CEED_EVAL_INTERP, in, out);
32 
33   // Check values at quadrature points
34   for (int i=0; i<Q; i++) {
35     value = feval(xq[0*Q+i], xq[1*Q+i]);
36     if (fabs(out[i] - value) > 1e-10)
37       printf("[%d] %f != %f\n", i, out[i], value);
38   }
39 
40   CeedBasisDestroy(&b);
41   CeedDestroy(&ceed);
42   return 0;
43 }
44