xref: /libCEED/tests/t302-basis.c (revision 9df49d7ef0a77c7a3baec2427d8a7274681409b6)
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 collo_grad_1d[Q*Q], collo_grad_1d_2[(P+2)*(P+2)];
12   CeedBasis b;
13 
14   CeedInit(argv[1], &ceed);
15 
16   // Already collocated, GetCollocatedGrad will return grad_1d
17   CeedBasisCreateTensorH1Lagrange(ceed, 1, 1, P, Q, CEED_GAUSS_LOBATTO, &b);
18   CeedBasisGetCollocatedGrad(b, collo_grad_1d);
19 
20   for (int i=0; i<Q; i++) {
21     fprintf(stdout, "%12s[%d]:", "collograd1d", i);
22     for (int j=0; j<Q; j++) {
23       if (fabs(collo_grad_1d[j+Q*i]) <= 1E-14) collo_grad_1d[j+Q*i] = 0;
24       fprintf(stdout, "\t% 12.8f", collo_grad_1d[j+Q*i]);
25     }
26     fprintf(stdout, "\n");
27   }
28   CeedBasisDestroy(&b);
29 
30   // Q = P, not already collocated
31   CeedBasisCreateTensorH1Lagrange(ceed, 1,  1, P, Q, CEED_GAUSS, &b);
32   CeedBasisGetCollocatedGrad(b, collo_grad_1d);
33 
34   for (int i=0; i<Q; i++) {
35     fprintf(stdout, "%12s[%d]:", "collograd1d", i);
36     for (int j=0; j<Q; j++) {
37       if (fabs(collo_grad_1d[j+Q*i]) <= 1E-14) collo_grad_1d[j+Q*i] = 0;
38       fprintf(stdout, "\t% 12.8f", collo_grad_1d[j+Q*i]);
39     }
40     fprintf(stdout, "\n");
41   }
42   CeedBasisDestroy(&b);
43 
44   // Q = P + 2, not already collocated
45   CeedBasisCreateTensorH1Lagrange(ceed, 1,  1, P, P+2, CEED_GAUSS, &b);
46   CeedBasisGetCollocatedGrad(b, collo_grad_1d_2);
47 
48   for (int i=0; i<P+2; i++) {
49     fprintf(stdout, "%12s[%d]:", "collograd1d", i);
50     for (int j=0; j<P+2; j++) {
51       if (fabs(collo_grad_1d_2[j+(P+2)*i]) <= 1E-14) collo_grad_1d_2[j+(P+2)*i] = 0;
52       fprintf(stdout, "\t% 12.8f", collo_grad_1d_2[j+(P+2)*i]);
53     }
54     fprintf(stdout, "\n");
55   }
56   CeedBasisDestroy(&b);
57 
58   CeedDestroy(&ceed);
59   return 0;
60 }
61