xref: /libCEED/tests/t411-qfunction.c (revision 49aac155e7a09736f56fb3abac0f57dab29f7cbf)
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>
6*49aac155SJeremy L Thompson #include <stdio.h>
70219ea01SJeremy L Thompson 
main(int argc,char ** argv)80219ea01SJeremy L Thompson int main(int argc, char **argv) {
90219ea01SJeremy L Thompson   Ceed          ceed;
100219ea01SJeremy L Thompson   CeedVector    in[16], out[16];
114fee36f0SJeremy L Thompson   CeedVector    u, v;
120219ea01SJeremy L Thompson   CeedQFunction qf;
134fee36f0SJeremy L Thompson   CeedInt       q = 8;
144fee36f0SJeremy L Thompson   CeedScalar    u_array[q];
150219ea01SJeremy L Thompson 
160219ea01SJeremy L Thompson   CeedInit(argv[1], &ceed);
170219ea01SJeremy L Thompson 
184fee36f0SJeremy L Thompson   CeedVectorCreate(ceed, q, &u);
194fee36f0SJeremy L Thompson   for (CeedInt i = 0; i < q; i++) u_array[i] = i * i;
204fee36f0SJeremy L Thompson   CeedVectorSetArray(u, CEED_MEM_HOST, CEED_USE_POINTER, u_array);
214fee36f0SJeremy L Thompson   CeedVectorCreate(ceed, q, &v);
224fee36f0SJeremy L Thompson   CeedVectorSetValue(v, 0);
234fee36f0SJeremy L Thompson 
2460f77c51Sjeremylt   CeedQFunctionCreateIdentity(ceed, 1, CEED_EVAL_INTERP, CEED_EVAL_INTERP, &qf);
250219ea01SJeremy L Thompson   {
264fee36f0SJeremy L Thompson     in[0]  = u;
274fee36f0SJeremy L Thompson     out[0] = v;
284fee36f0SJeremy L Thompson     CeedQFunctionApply(qf, q, in, out);
290219ea01SJeremy L Thompson   }
300219ea01SJeremy L Thompson 
314fee36f0SJeremy L Thompson   // Verify results
324fee36f0SJeremy L Thompson   {
334fee36f0SJeremy L Thompson     const CeedScalar *v_array;
340219ea01SJeremy L Thompson 
354fee36f0SJeremy L Thompson     CeedVectorGetArrayRead(v, CEED_MEM_HOST, &v_array);
364fee36f0SJeremy L Thompson     for (CeedInt i = 0; i < q; i++) {
374fee36f0SJeremy 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]);
384fee36f0SJeremy L Thompson     }
394fee36f0SJeremy L Thompson     CeedVectorRestoreArrayRead(v, &v_array);
404fee36f0SJeremy L Thompson   }
414fee36f0SJeremy L Thompson 
424fee36f0SJeremy L Thompson   CeedVectorDestroy(&u);
434fee36f0SJeremy L Thompson   CeedVectorDestroy(&v);
440219ea01SJeremy L Thompson   CeedQFunctionDestroy(&qf);
450219ea01SJeremy L Thompson   CeedDestroy(&ceed);
460219ea01SJeremy L Thompson   return 0;
470219ea01SJeremy L Thompson }
48