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