1 /// @file 2 /// Test creation, evaluation, and destruction for qfunction by name 3 /// \test Test creation, evaluation, and destruction for qfunction by name 4 #include <ceed.h> 5 6 int main(int argc, char **argv) { 7 Ceed ceed; 8 CeedVector in[16], out[16]; 9 CeedVector Qdata, J, W, U, V; 10 CeedQFunction qf_setup, qf_mass; 11 CeedInt Q = 8; 12 const CeedScalar *vv; 13 CeedScalar j[Q], w[Q], u[Q], v[Q]; 14 15 16 CeedInit(argv[1], &ceed); 17 18 CeedQFunctionCreateInteriorByName(ceed, "Mass1DBuild", &qf_setup); 19 CeedQFunctionCreateInteriorByName(ceed, "MassApply", &qf_mass); 20 21 for (CeedInt i=0; i<Q; i++) { 22 CeedScalar x = 2.*i/(Q-1) - 1; 23 j[i] = 1; 24 w[i] = 1 - x*x; 25 u[i] = 2 + 3*x + 5*x*x; 26 v[i] = w[i] * u[i]; 27 } 28 29 CeedVectorCreate(ceed, Q, &J); 30 CeedVectorSetArray(J, CEED_MEM_HOST, CEED_USE_POINTER, j); 31 CeedVectorCreate(ceed, Q, &W); 32 CeedVectorSetArray(W, CEED_MEM_HOST, CEED_USE_POINTER, w); 33 CeedVectorCreate(ceed, Q, &U); 34 CeedVectorSetArray(U, CEED_MEM_HOST, CEED_USE_POINTER, u); 35 CeedVectorCreate(ceed, Q, &V); 36 CeedVectorSetValue(V, 0); 37 CeedVectorCreate(ceed, Q, &Qdata); 38 CeedVectorSetValue(Qdata, 0); 39 40 { 41 in[0] = J; 42 in[1] = W; 43 out[0] = Qdata; 44 CeedQFunctionApply(qf_setup, Q, in, out); 45 } 46 { 47 in[0] = W; 48 in[1] = U; 49 out[0] = V; 50 CeedQFunctionApply(qf_mass, Q, in, out); 51 } 52 53 CeedVectorGetArrayRead(V, CEED_MEM_HOST, &vv); 54 for (CeedInt i=0; i<Q; i++) 55 if (v[i] != vv[i]) 56 // LCOV_EXCL_START 57 printf("[%d] v %f != vv %f\n",i, v[i], vv[i]); 58 // LCOV_EXCL_STOP 59 CeedVectorRestoreArrayRead(V, &vv); 60 61 CeedVectorDestroy(&W); 62 CeedVectorDestroy(&U); 63 CeedVectorDestroy(&V); 64 CeedVectorDestroy(&Qdata); 65 CeedQFunctionDestroy(&qf_setup); 66 CeedQFunctionDestroy(&qf_mass); 67 CeedDestroy(&ceed); 68 return 0; 69 } 70