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