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