xref: /libCEED/tests/t412-qfunction.c (revision 8ec64e9ae9d5df169dba8c8ee61d8ec8907b8f80)
1 /// @file
2 /// Test creation, evaluation, and destruction of identity QFunction with size>1
3 /// \test Test creation, evaluation, and destruction of identity QFunction with size>1
4 #include <ceed.h>
5 #include <math.h>
6 
7 int main(int argc, char **argv) {
8   Ceed              ceed;
9   CeedVector        in[16], out[16];
10   CeedVector        U, V;
11   CeedQFunction     qf;
12   CeedInt           Q = 8, size = 3;
13   const CeedScalar *v;
14   CeedScalar        u[Q * size];
15 
16   CeedInit(argv[1], &ceed);
17 
18   CeedQFunctionCreateIdentity(ceed, size, CEED_EVAL_INTERP, CEED_EVAL_NONE, &qf);
19 
20   for (CeedInt i = 0; i < Q * size; i++) u[i] = i * i;
21 
22   CeedVectorCreate(ceed, Q * size, &U);
23   CeedVectorSetArray(U, CEED_MEM_HOST, CEED_USE_POINTER, u);
24   CeedVectorCreate(ceed, Q * size, &V);
25   CeedVectorSetValue(V, 0);
26 
27   {
28     in[0]  = U;
29     out[0] = V;
30     CeedQFunctionApply(qf, Q, in, out);
31   }
32 
33   CeedVectorGetArrayRead(V, CEED_MEM_HOST, &v);
34   for (CeedInt i = 0; i < Q * size; i++) {
35     if (fabs(v[i] - u[i]) > 1e-12) printf("[%" CeedInt_FMT "] v %f != u %f\n", i, v[i], u[i]);
36   }
37   CeedVectorRestoreArrayRead(V, &v);
38 
39   CeedVectorDestroy(&U);
40   CeedVectorDestroy(&V);
41   CeedQFunctionDestroy(&qf);
42   CeedDestroy(&ceed);
43   return 0;
44 }
45