xref: /libCEED/tests/t324-basis.c (revision f9996dfd0db601698d1ad85cf5741d3360a86e68)
1 /// @file
2 /// Test grad transpose with a 2D Simplex non-tensor H1 basis
3 /// \test Test grad transposewith a 2D Simplex non-tensor H1 basis
4 #include <ceed.h>
5 #include <math.h>
6 #include "t320-basis.h"
7 
8 int main(int argc, char **argv) {
9   Ceed ceed;
10   CeedVector In, Out;
11   const CeedInt P = 6, Q = 4, dim = 2;
12   CeedBasis b;
13   CeedScalar q_ref[dim*Q], q_weight[Q];
14   CeedScalar interp[P*Q], grad[dim*P*Q];
15   const CeedScalar *out;
16   CeedScalar colsum[P];
17 
18   buildmats(q_ref, q_weight, interp, grad);
19 
20   CeedInit(argv[1], &ceed);
21 
22   for (int i=0; i<P; i++) {
23     colsum[i] = 0;
24     for (int j=0; j<Q*dim; j++) {
25       colsum[i] += grad[i+j*P];
26     }
27   }
28 
29   CeedBasisCreateH1(ceed, CEED_TOPOLOGY_TRIANGLE, 1, P, Q, interp, grad, q_ref,
30                     q_weight, &b);
31 
32   CeedVectorCreate(ceed, Q*dim, &In);
33   CeedVectorSetValue(In, 1);
34   CeedVectorCreate(ceed, P, &Out);
35   CeedVectorSetValue(Out, 0);
36 
37   CeedBasisApply(b, 1, CEED_TRANSPOSE, CEED_EVAL_GRAD, In, Out);
38 
39   // Check values at quadrature points
40   CeedVectorGetArrayRead(Out, CEED_MEM_HOST, &out);
41   for (int i=0; i<P; i++)
42     if (fabs(colsum[i] - out[i]) > 100.*CEED_EPSILON)
43       // LCOV_EXCL_START
44       printf("[%d] %f != %f\n", i, out[i], colsum[i]);
45   // LCOV_EXCL_STOP
46   CeedVectorRestoreArrayRead(Out, &out);
47 
48   CeedVectorDestroy(&In);
49   CeedVectorDestroy(&Out);
50   CeedBasisDestroy(&b);
51   CeedDestroy(&ceed);
52   return 0;
53 }
54