xref: /libCEED/tests/t411-qfunction.c (revision 4fee36f0a30516a0b5ad51bf7eb3b32d83efd623)
10219ea01SJeremy L Thompson /// @file
2d1d35e2fSjeremylt /// Test creation, evaluation, and destruction of identity QFunction
3d1d35e2fSjeremylt /// \test Test creation, evaluation, and destruction of identity QFunction
40219ea01SJeremy L Thompson #include <ceed.h>
50219ea01SJeremy L Thompson #include <math.h>
60219ea01SJeremy L Thompson 
70219ea01SJeremy L Thompson int main(int argc, char **argv) {
80219ea01SJeremy L Thompson   Ceed          ceed;
90219ea01SJeremy L Thompson   CeedVector    in[16], out[16];
10*4fee36f0SJeremy L Thompson   CeedVector    u, v;
110219ea01SJeremy L Thompson   CeedQFunction qf;
12*4fee36f0SJeremy L Thompson   CeedInt       q = 8;
13*4fee36f0SJeremy L Thompson   CeedScalar    u_array[q];
140219ea01SJeremy L Thompson 
150219ea01SJeremy L Thompson   CeedInit(argv[1], &ceed);
160219ea01SJeremy L Thompson 
17*4fee36f0SJeremy L Thompson   CeedVectorCreate(ceed, q, &u);
18*4fee36f0SJeremy L Thompson   for (CeedInt i = 0; i < q; i++) u_array[i] = i * i;
19*4fee36f0SJeremy L Thompson   CeedVectorSetArray(u, CEED_MEM_HOST, CEED_USE_POINTER, u_array);
20*4fee36f0SJeremy L Thompson   CeedVectorCreate(ceed, q, &v);
21*4fee36f0SJeremy L Thompson   CeedVectorSetValue(v, 0);
22*4fee36f0SJeremy L Thompson 
2360f77c51Sjeremylt   CeedQFunctionCreateIdentity(ceed, 1, CEED_EVAL_INTERP, CEED_EVAL_INTERP, &qf);
240219ea01SJeremy L Thompson   {
25*4fee36f0SJeremy L Thompson     in[0]  = u;
26*4fee36f0SJeremy L Thompson     out[0] = v;
27*4fee36f0SJeremy L Thompson     CeedQFunctionApply(qf, q, in, out);
280219ea01SJeremy L Thompson   }
290219ea01SJeremy L Thompson 
30*4fee36f0SJeremy L Thompson   // Verify results
31*4fee36f0SJeremy L Thompson   {
32*4fee36f0SJeremy L Thompson     const CeedScalar *v_array;
330219ea01SJeremy L Thompson 
34*4fee36f0SJeremy L Thompson     CeedVectorGetArrayRead(v, CEED_MEM_HOST, &v_array);
35*4fee36f0SJeremy L Thompson     for (CeedInt i = 0; i < q; i++) {
36*4fee36f0SJeremy L Thompson       if (fabs(v_array[i] - u_array[i]) > 1e-14) printf("[%" CeedInt_FMT "] v %f != u %f\n", i, v_array[i], u_array[i]);
37*4fee36f0SJeremy L Thompson     }
38*4fee36f0SJeremy L Thompson     CeedVectorRestoreArrayRead(v, &v_array);
39*4fee36f0SJeremy L Thompson   }
40*4fee36f0SJeremy L Thompson 
41*4fee36f0SJeremy L Thompson   CeedVectorDestroy(&u);
42*4fee36f0SJeremy L Thompson   CeedVectorDestroy(&v);
430219ea01SJeremy L Thompson   CeedQFunctionDestroy(&qf);
440219ea01SJeremy L Thompson   CeedDestroy(&ceed);
450219ea01SJeremy L Thompson   return 0;
460219ea01SJeremy L Thompson }
47