xref: /libCEED/tests/t411-qfunction.c (revision 60f77c51b5a8877aa3ab66b685cde4f5f7c967bb)
10219ea01SJeremy L Thompson /// @file
21134a487Sjeremylt /// Test creation, evaluation, and destruction of identity qfunction
31134a487Sjeremylt /// \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];
100219ea01SJeremy L Thompson   CeedVector U, V;
110219ea01SJeremy L Thompson   CeedQFunction qf;
120219ea01SJeremy L Thompson   CeedInt Q = 8;
130219ea01SJeremy L Thompson   const CeedScalar *v;
140219ea01SJeremy L Thompson   CeedScalar u[Q];
150219ea01SJeremy L Thompson 
160219ea01SJeremy L Thompson   CeedInit(argv[1], &ceed);
170219ea01SJeremy L Thompson 
18*60f77c51Sjeremylt   CeedQFunctionCreateIdentity(ceed, 1, CEED_EVAL_INTERP, CEED_EVAL_INTERP, &qf);
190219ea01SJeremy L Thompson 
200219ea01SJeremy L Thompson   for (CeedInt i=0; i<Q; i++)
210219ea01SJeremy L Thompson     u[i] = i*i;
220219ea01SJeremy L Thompson 
230219ea01SJeremy L Thompson   CeedVectorCreate(ceed, Q, &U);
240219ea01SJeremy L Thompson   CeedVectorSetArray(U, CEED_MEM_HOST, CEED_USE_POINTER, u);
250219ea01SJeremy L Thompson   CeedVectorCreate(ceed, Q, &V);
260219ea01SJeremy L Thompson   CeedVectorSetValue(V, 0);
270219ea01SJeremy L Thompson 
280219ea01SJeremy L Thompson   {
290219ea01SJeremy L Thompson     in[0] = U;
300219ea01SJeremy L Thompson     out[0] = V;
310219ea01SJeremy L Thompson     CeedQFunctionApply(qf, Q, in, out);
320219ea01SJeremy L Thompson   }
330219ea01SJeremy L Thompson 
340219ea01SJeremy L Thompson   CeedVectorGetArrayRead(V, CEED_MEM_HOST, &v);
350219ea01SJeremy L Thompson   for (CeedInt i=0; i<Q; i++)
364e367ab1Sjeremylt     if (fabs(v[i] - u[i])>1e-14)
370219ea01SJeremy L Thompson       // LCOV_EXCL_START
380219ea01SJeremy L Thompson       printf("[%d] v %f != u %f\n",i, v[i], u[i]);
390219ea01SJeremy L Thompson   // LCOV_EXCL_STOP
400219ea01SJeremy L Thompson   CeedVectorRestoreArrayRead(V, &v);
410219ea01SJeremy L Thompson 
420219ea01SJeremy L Thompson   CeedVectorDestroy(&U);
430219ea01SJeremy L Thompson   CeedVectorDestroy(&V);
440219ea01SJeremy L Thompson   CeedQFunctionDestroy(&qf);
450219ea01SJeremy L Thompson   CeedDestroy(&ceed);
460219ea01SJeremy L Thompson   return 0;
470219ea01SJeremy L Thompson }
48