xref: /libCEED/tests/t332-basis.c (revision cdf95791513f7c35170bef3ba2e19f272fe04533)
1 /// @file
2 /// Test GetDiv and BasisApply for a 2D Quad non-tensor H(div) basis
3 /// \test Test GetDiv and BasisApply for a 2D Quad non-tensor H(div) basis
4 #include <ceed.h>
5 #include <math.h>
6 #include "t330-basis.h"
7 
8 int main(int argc, char **argv) {
9   Ceed ceed;
10   const CeedInt num_nodes = 4, Q = 3, dim = 2, num_qpts = Q*Q;
11   CeedInt num_comp = 1;      // one vector componenet
12   CeedInt P = dim*num_nodes; // dof per element!
13   CeedBasis b;
14   CeedScalar q_ref[dim*num_qpts], q_weights[num_qpts];
15   CeedScalar div[P*num_qpts], interp[P*dim*num_qpts];
16   CeedVector X, Y;
17   const CeedScalar *y, *x;
18 
19   CeedInit(argv[1], &ceed);
20 
21   HdivBasisQuad(Q, q_ref, q_weights, interp, div, CEED_GAUSS);
22   CeedBasisCreateHdiv(ceed, CEED_TOPOLOGY_QUAD, num_comp, P, num_qpts, interp,
23                       div, q_ref, q_weights, &b);
24   // Test GetDiv
25   const CeedScalar *div2;
26   CeedBasisGetDiv(b, &div2);
27   for (CeedInt i=0; i<P*num_qpts; i++) {
28     if (fabs(div[i] - div2[i]) > 100.*CEED_EPSILON)
29       // LCOV_EXCL_START
30       printf("%f != %f\n", div[i], div2[i]);
31     // LCOV_EXCL_STOP
32   }
33   CeedVectorCreate(ceed, P, &X);
34   CeedVectorSetValue(X, 1);
35   CeedVectorCreate(ceed, num_qpts, &Y);
36   CeedVectorSetValue(Y, 0);
37   // BasisApply for H(div): CEED_EVAL_DIV, NOTRANSPOSE case
38   CeedBasisApply(b, 1, CEED_NOTRANSPOSE, CEED_EVAL_DIV, X, Y);
39 
40   CeedVectorGetArrayRead(Y, CEED_MEM_HOST, &y);
41   for (CeedInt i=0; i<num_qpts; i++) {
42     if (fabs(P*0.25 - y[i]) > 100.*CEED_EPSILON)
43       // LCOV_EXCL_START
44       printf("%f != %f\n", 2.0, y[i]);
45     // LCOV_EXCL_STOP
46   }
47   CeedVectorRestoreArrayRead(Y, &y);
48 
49   CeedVectorSetValue(Y, 1.0);
50   CeedVectorSetValue(X, 0.0);
51   // BasisApply for H(div): CEED_EVAL_DIV, TRANSPOSE case
52   CeedBasisApply(b, 1, CEED_TRANSPOSE, CEED_EVAL_DIV, Y, X);
53 
54   CeedVectorGetArrayRead(X, CEED_MEM_HOST, &x);
55   for (CeedInt i=0; i<P; i++) {
56     if (fabs(num_qpts*0.25 - x[i]) > 100.*CEED_EPSILON)
57       // LCOV_EXCL_START
58       printf("%f != %f\n", 2.0, x[i]);
59     // LCOV_EXCL_STOP
60   }
61   CeedVectorRestoreArrayRead(X, &x);
62 
63   CeedBasisDestroy(&b);
64   CeedVectorDestroy(&X);
65   CeedVectorDestroy(&Y);
66   CeedDestroy(&ceed);
67   return 0;
68 }
69