xref: /libCEED/tests/t324-basis.c (revision 4fee36f0a30516a0b5ad51bf7eb3b32d83efd623)
1edcde79dSjeremylt /// @file
2edcde79dSjeremylt /// Test grad transpose with a 2D Simplex non-tensor H1 basis
3edcde79dSjeremylt /// \test Test grad transpose with a 2D Simplex non-tensor H1 basis
4edcde79dSjeremylt #include <ceed.h>
5edcde79dSjeremylt #include <math.h>
62b730f8bSJeremy L Thompson 
7edcde79dSjeremylt #include "t320-basis.h"
8edcde79dSjeremylt 
9edcde79dSjeremylt int main(int argc, char **argv) {
10edcde79dSjeremylt   Ceed          ceed;
11*4fee36f0SJeremy L Thompson   CeedVector    u, v;
12*4fee36f0SJeremy L Thompson   const CeedInt p = 6, q = 4, dim = 2;
13*4fee36f0SJeremy L Thompson   CeedBasis     basis;
14*4fee36f0SJeremy L Thompson   CeedScalar    q_ref[dim * q], q_weight[q];
15*4fee36f0SJeremy L Thompson   CeedScalar    interp[p * q], grad[dim * p * q];
16*4fee36f0SJeremy L Thompson   CeedScalar    column_sum[p];
17edcde79dSjeremylt 
18edcde79dSjeremylt   CeedInit(argv[1], &ceed);
19edcde79dSjeremylt 
20*4fee36f0SJeremy L Thompson   CeedVectorCreate(ceed, q * dim, &u);
21*4fee36f0SJeremy L Thompson   CeedVectorSetValue(u, 1);
22*4fee36f0SJeremy L Thompson   CeedVectorCreate(ceed, p, &v);
23*4fee36f0SJeremy L Thompson   CeedVectorSetValue(v, 0);
24edcde79dSjeremylt 
25*4fee36f0SJeremy L Thompson   Build2DSimplex(q_ref, q_weight, interp, grad);
26*4fee36f0SJeremy L Thompson   CeedBasisCreateH1(ceed, CEED_TOPOLOGY_TRIANGLE, 1, p, q, interp, grad, q_ref, q_weight, &basis);
27edcde79dSjeremylt 
28*4fee36f0SJeremy L Thompson   CeedBasisApply(basis, 1, CEED_TRANSPOSE, CEED_EVAL_GRAD, u, v);
29edcde79dSjeremylt 
30edcde79dSjeremylt   // Check values at quadrature points
31*4fee36f0SJeremy L Thompson   for (int i = 0; i < p; i++) {
32*4fee36f0SJeremy L Thompson     column_sum[i] = 0;
33*4fee36f0SJeremy L Thompson     for (int j = 0; j < q * dim; j++) {
34*4fee36f0SJeremy L Thompson       column_sum[i] += grad[i + j * p];
352b730f8bSJeremy L Thompson     }
36*4fee36f0SJeremy L Thompson   }
37*4fee36f0SJeremy L Thompson   {
38*4fee36f0SJeremy L Thompson     const CeedScalar *v_array;
39edcde79dSjeremylt 
40*4fee36f0SJeremy L Thompson     CeedVectorGetArrayRead(v, CEED_MEM_HOST, &v_array);
41*4fee36f0SJeremy L Thompson     for (int i = 0; i < p; i++) {
42*4fee36f0SJeremy L Thompson       if (fabs(column_sum[i] - v_array[i]) > 100. * CEED_EPSILON) printf("[%" CeedInt_FMT "] %f != %f\n", i, v_array[i], column_sum[i]);
43*4fee36f0SJeremy L Thompson     }
44*4fee36f0SJeremy L Thompson     CeedVectorRestoreArrayRead(v, &v_array);
45*4fee36f0SJeremy L Thompson   }
46*4fee36f0SJeremy L Thompson 
47*4fee36f0SJeremy L Thompson   CeedVectorDestroy(&u);
48*4fee36f0SJeremy L Thompson   CeedVectorDestroy(&v);
49*4fee36f0SJeremy L Thompson   CeedBasisDestroy(&basis);
50edcde79dSjeremylt   CeedDestroy(&ceed);
51edcde79dSjeremylt   return 0;
52edcde79dSjeremylt }
53