xref: /libCEED/tests/t412-qfunction.c (revision 5cd6c1fb67d52eb6a42b887bb79c183682dd86ca)
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 #include <stdio.h>
7 
8 int main(int argc, char **argv) {
9   Ceed          ceed;
10   CeedVector    in[16], out[16];
11   CeedVector    u, v;
12   CeedQFunction qf;
13   CeedInt       q = 8, size = 3;
14   CeedScalar    u_array[q * size];
15 
16   CeedInit(argv[1], &ceed);
17 
18   CeedVectorCreate(ceed, q * size, &u);
19   for (CeedInt i = 0; i < q * size; i++) u_array[i] = i * i;
20   CeedVectorSetArray(u, CEED_MEM_HOST, CEED_USE_POINTER, u_array);
21   CeedVectorCreate(ceed, q * size, &v);
22   CeedVectorSetValue(v, 0);
23 
24   CeedQFunctionCreateIdentity(ceed, size, CEED_EVAL_INTERP, CEED_EVAL_NONE, &qf);
25   {
26     in[0]  = u;
27     out[0] = v;
28     CeedQFunctionApply(qf, q, in, out);
29   }
30 
31   // Verify results
32   {
33     const CeedScalar *v_array;
34 
35     CeedVectorGetArrayRead(v, CEED_MEM_HOST, &v_array);
36     for (CeedInt i = 0; i < q * size; i++) {
37       if (fabs(v_array[i] - u_array[i]) > 1e-12) printf("[%" CeedInt_FMT "] v %f != u %f\n", i, v_array[i], u_array[i]);
38     }
39     CeedVectorRestoreArrayRead(v, &v_array);
40   }
41 
42   CeedVectorDestroy(&u);
43   CeedVectorDestroy(&v);
44   CeedQFunctionDestroy(&qf);
45   CeedDestroy(&ceed);
46   return 0;
47 }
48