xref: /libCEED/tests/t411-qfunction.c (revision 0219ea01e2c00bd70a330a05b50ef0218d6ddcb0)
1*0219ea01SJeremy L Thompson /// @file
2*0219ea01SJeremy L Thompson /// Test creation, evaluation, and destruction for qfunction by name
3*0219ea01SJeremy L Thompson /// \test Test creation, evaluation, and destruction for qfunction by name
4*0219ea01SJeremy L Thompson #include <ceed.h>
5*0219ea01SJeremy L Thompson #include <math.h>
6*0219ea01SJeremy L Thompson 
7*0219ea01SJeremy L Thompson int main(int argc, char **argv) {
8*0219ea01SJeremy L Thompson   Ceed ceed;
9*0219ea01SJeremy L Thompson   CeedVector in[16], out[16];
10*0219ea01SJeremy L Thompson   CeedVector U, V;
11*0219ea01SJeremy L Thompson   CeedQFunction qf;
12*0219ea01SJeremy L Thompson   CeedInt Q = 8;
13*0219ea01SJeremy L Thompson   const CeedScalar *v;
14*0219ea01SJeremy L Thompson   CeedScalar u[Q];
15*0219ea01SJeremy L Thompson 
16*0219ea01SJeremy L Thompson   CeedInit(argv[1], &ceed);
17*0219ea01SJeremy L Thompson 
18*0219ea01SJeremy L Thompson   CeedQFunctionCreateIdentity(ceed, 1, &qf);
19*0219ea01SJeremy L Thompson 
20*0219ea01SJeremy L Thompson   for (CeedInt i=0; i<Q; i++)
21*0219ea01SJeremy L Thompson     u[i] = i*i;
22*0219ea01SJeremy L Thompson 
23*0219ea01SJeremy L Thompson   CeedVectorCreate(ceed, Q, &U);
24*0219ea01SJeremy L Thompson   CeedVectorSetArray(U, CEED_MEM_HOST, CEED_USE_POINTER, u);
25*0219ea01SJeremy L Thompson   CeedVectorCreate(ceed, Q, &V);
26*0219ea01SJeremy L Thompson   CeedVectorSetValue(V, 0);
27*0219ea01SJeremy L Thompson 
28*0219ea01SJeremy L Thompson   {
29*0219ea01SJeremy L Thompson     in[0] = U;
30*0219ea01SJeremy L Thompson     out[0] = V;
31*0219ea01SJeremy L Thompson     CeedQFunctionApply(qf, Q, in, out);
32*0219ea01SJeremy L Thompson   }
33*0219ea01SJeremy L Thompson 
34*0219ea01SJeremy L Thompson   CeedVectorGetArrayRead(V, CEED_MEM_HOST, &v);
35*0219ea01SJeremy L Thompson   for (CeedInt i=0; i<Q; i++)
36*0219ea01SJeremy L Thompson     if (fabs(v[i] - u[i])>1E-14)
37*0219ea01SJeremy L Thompson       // LCOV_EXCL_START
38*0219ea01SJeremy L Thompson       printf("[%d] v %f != u %f\n",i, v[i], u[i]);
39*0219ea01SJeremy L Thompson   // LCOV_EXCL_STOP
40*0219ea01SJeremy L Thompson   CeedVectorRestoreArrayRead(V, &v);
41*0219ea01SJeremy L Thompson 
42*0219ea01SJeremy L Thompson   CeedVectorDestroy(&U);
43*0219ea01SJeremy L Thompson   CeedVectorDestroy(&V);
44*0219ea01SJeremy L Thompson   CeedQFunctionDestroy(&qf);
45*0219ea01SJeremy L Thompson   CeedDestroy(&ceed);
46*0219ea01SJeremy L Thompson   return 0;
47*0219ea01SJeremy L Thompson }
48