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