xref: /libCEED/tests/t325-basis.c (revision 2b730f8b5a9c809740a0b3b302db43a719c636b1)
1 /// @file
2 /// Test grad transpose with a 2D Simplex non-tensor H1 basis
3 /// \test Test grad transposewith a 2D Simplex non-tensor H1 basis
4 #include <ceed.h>
5 #include <math.h>
6 
7 #include "t320-basis.h"
8 
9 int main(int argc, char **argv) {
10   Ceed              ceed;
11   CeedVector        In, Out;
12   const CeedInt     P = 6, Q = 4, dim = 2, num_comp = 3;
13   CeedBasis         b;
14   CeedScalar        q_ref[dim * Q], q_weight[Q];
15   CeedScalar        interp[P * Q], grad[dim * P * Q];
16   const CeedScalar *out;
17   CeedScalar        colsum[P], *in;
18 
19   buildmats(q_ref, q_weight, interp, grad);
20 
21   CeedInit(argv[1], &ceed);
22 
23   for (int i = 0; i < P; i++) {
24     colsum[i] = 0;
25     for (int j = 0; j < Q * dim; j++) {
26       colsum[i] += grad[i + j * P];
27     }
28   }
29 
30   CeedBasisCreateH1(ceed, CEED_TOPOLOGY_TRIANGLE, num_comp, P, Q, interp, grad, q_ref, q_weight, &b);
31 
32   CeedVectorCreate(ceed, Q * dim * num_comp, &In);
33   CeedVectorGetArrayWrite(In, CEED_MEM_HOST, &in);
34   for (int d = 0; d < dim; d++) {
35     for (int n = 0; n < num_comp; n++) {
36       for (int q = 0; q < Q; q++) in[q + (n + d * num_comp) * Q] = n * 1.0;
37     }
38   }
39   CeedVectorRestoreArray(In, &in);
40   CeedVectorCreate(ceed, P * num_comp, &Out);
41   CeedVectorSetValue(Out, 0);
42 
43   CeedBasisApply(b, 1, CEED_TRANSPOSE, CEED_EVAL_GRAD, In, Out);
44 
45   // Check values at quadrature points
46   CeedVectorGetArrayRead(Out, CEED_MEM_HOST, &out);
47   for (int p = 0; p < P; p++) {
48     for (int n = 0; n < num_comp; n++) {
49       if (fabs(n * colsum[p] - out[p + n * P]) > 100. * CEED_EPSILON) printf("[%" CeedInt_FMT "] %f != %f\n", p, out[p + n * P], n * colsum[p]);
50     }
51   }
52   CeedVectorRestoreArrayRead(Out, &out);
53 
54   CeedVectorDestroy(&In);
55   CeedVectorDestroy(&Out);
56   CeedBasisDestroy(&b);
57   CeedDestroy(&ceed);
58   return 0;
59 }
60