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