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