xref: /libCEED/tests/t411-qfunction.c (revision a0154adecfab8547cdc0febbbf40ac009dbe9d1d)
1 /// @file
2 /// Test creation, evaluation, and destruction of identity QFunction
3 /// \test Test creation, evaluation, and destruction of identity QFunction
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;
13   const CeedScalar *v;
14   CeedScalar u[Q];
15 
16   CeedInit(argv[1], &ceed);
17 
18   CeedQFunctionCreateIdentity(ceed, 1, CEED_EVAL_INTERP, CEED_EVAL_INTERP, &qf);
19 
20   for (CeedInt i=0; i<Q; i++)
21     u[i] = i*i;
22 
23   CeedVectorCreate(ceed, Q, &U);
24   CeedVectorSetArray(U, CEED_MEM_HOST, CEED_USE_POINTER, u);
25   CeedVectorCreate(ceed, Q, &V);
26   CeedVectorSetValue(V, 0);
27 
28   {
29     in[0] = U;
30     out[0] = V;
31     CeedQFunctionApply(qf, Q, in, out);
32   }
33 
34   CeedVectorGetArrayRead(V, CEED_MEM_HOST, &v);
35   for (CeedInt i=0; i<Q; i++)
36     if (fabs(v[i] - u[i])>1e-14)
37       // LCOV_EXCL_START
38       printf("[%d] v %f != u %f\n",i, v[i], u[i]);
39   // LCOV_EXCL_STOP
40   CeedVectorRestoreArrayRead(V, &v);
41 
42   CeedVectorDestroy(&U);
43   CeedVectorDestroy(&V);
44   CeedQFunctionDestroy(&qf);
45   CeedDestroy(&ceed);
46   return 0;
47 }
48