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