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