xref: /libCEED/tests/t307-basis.c (revision f82d2baa7ca109f28fd503bf3902b2ceeba90030)
1 /// @file
2 /// Test Colocated Grad calculated matches basis with Lobatto points
3 /// \test Test Colocated Grad calculated matches basis with Lobatto points
4 #include <ceed.h>
5 #include <math.h>
6 
7 int main(int argc, char **argv) {
8   Ceed ceed;
9   CeedInt P=4, Q=4;
10   CeedScalar colograd1d[Q*Q], colograd1d2[(P+2)*(P+2)];
11   CeedBasis b;
12 
13   CeedInit(argv[1], &ceed);
14 
15   // Already colocated, GetColocatedGrad will return grad1d
16   CeedBasisCreateTensorH1Lagrange(ceed, 1, 1, P, Q, CEED_GAUSS_LOBATTO, &b);
17   CeedBasisGetColocatedGrad(b, colograd1d);
18 
19   CeedBasisView(b, stdout);
20   for (int i=0; i<Q; i++) {
21     fprintf(stdout, "%12s[%d]:", "colograd1d", i);
22     for (int j=0; j<Q; j++) {
23       if (fabs(colograd1d[j+Q*i]) <= 1E-14) colograd1d[j+Q*i] = 0;
24       fprintf(stdout, "\t% 12.8f", colograd1d[j+Q*i]);
25     }
26     fprintf(stdout, "\n");
27   }
28   CeedBasisDestroy(&b);
29 
30   // Q = P, not already colocated
31   CeedBasisCreateTensorH1Lagrange(ceed, 1,  1, P, Q, CEED_GAUSS, &b);
32   CeedBasisGetColocatedGrad(b, colograd1d);
33 
34   CeedBasisView(b, stdout);
35   for (int i=0; i<Q; i++) {
36     fprintf(stdout, "%12s[%d]:", "colograd1d", i);
37     for (int j=0; j<Q; j++) {
38       if (fabs(colograd1d[j+Q*i]) <= 1E-14) colograd1d[j+Q*i] = 0;
39       fprintf(stdout, "\t% 12.8f", colograd1d[j+Q*i]);
40     }
41     fprintf(stdout, "\n");
42   }
43   CeedBasisDestroy(&b);
44 
45   // Q = P + 2, not already colocated
46   CeedBasisCreateTensorH1Lagrange(ceed, 1,  1, P, P+2, CEED_GAUSS, &b);
47   CeedBasisGetColocatedGrad(b, colograd1d2);
48 
49   CeedBasisView(b, stdout);
50   for (int i=0; i<P+2; i++) {
51     fprintf(stdout, "%12s[%d]:", "colograd1d", i);
52     for (int j=0; j<P+2; j++) {
53       if (fabs(colograd1d2[j+(P+2)*i]) <= 1E-14) colograd1d2[j+(P+2)*i] = 0;
54       fprintf(stdout, "\t% 12.8f", colograd1d2[j+(P+2)*i]);
55     }
56     fprintf(stdout, "\n");
57   }
58   CeedBasisDestroy(&b);
59 
60   CeedDestroy(&ceed);
61   return 0;
62 }
63