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 static int setup(void *ctx, CeedInt Q, const CeedScalar *const *in, 7 CeedScalar *const *out) { 8 const CeedScalar *w = in[0]; 9 CeedScalar *qdata = out[0]; 10 for (CeedInt i=0; i<Q; i++) { 11 qdata[i] = w[i]; 12 } 13 return 0; 14 } 15 16 static int mass(void *ctx, CeedInt Q, const CeedScalar *const *in, 17 CeedScalar *const *out) { 18 const CeedScalar *qdata = in[0], *u = in[1]; 19 CeedScalar *v = out[0]; 20 for (CeedInt i=0; i<Q; i++) { 21 v[i] = qdata[i] * u[i]; 22 } 23 return 0; 24 } 25 26 int main(int argc, char **argv) { 27 Ceed ceed; 28 CeedQFunction qf_setup, qf_mass; 29 CeedInt Q = 8; 30 CeedScalar qdata[Q], w[Q], u[Q], v[Q], vv[Q]; 31 32 33 CeedInit(argv[1], &ceed); 34 CeedQFunctionCreateInterior(ceed, 1, setup, __FILE__ ":setup", &qf_setup); 35 CeedQFunctionAddInput(qf_setup, "w", 1, CEED_EVAL_INTERP); 36 CeedQFunctionAddOutput(qf_setup, "qdata", 1, CEED_EVAL_INTERP); 37 38 CeedQFunctionCreateInterior(ceed, 1, mass, __FILE__ ":mass", &qf_mass); 39 CeedQFunctionAddInput(qf_mass, "qdata", 1, CEED_EVAL_INTERP); 40 CeedQFunctionAddInput(qf_mass, "u", 1, CEED_EVAL_INTERP); 41 CeedQFunctionAddOutput(qf_mass, "v", 1, CEED_EVAL_INTERP); 42 43 for (CeedInt i=0; i<Q; i++) { 44 CeedScalar x = 2.*i/(Q-1) - 1; 45 w[i] = 1 - x*x; 46 u[i] = 2 + 3*x + 5*x*x; 47 v[i] = w[i] * u[i]; 48 } 49 { 50 const CeedScalar *const in[1] = {w}; 51 CeedScalar *const out[1] = {qdata}; 52 CeedQFunctionApply(qf_setup, Q, in, out); 53 } 54 { 55 const CeedScalar *const in[2] = {qdata, u}; 56 CeedScalar *const out[1] = {vv}; 57 CeedQFunctionApply(qf_mass, Q, in, out); 58 } 59 for (CeedInt i=0; i<Q; i++) { 60 if (v[i] != vv[i]) printf("[%d] v %f != vv %f\n",i, v[i], vv[i]); 61 } 62 CeedQFunctionDestroy(&qf_setup); 63 CeedQFunctionDestroy(&qf_mass); 64 CeedDestroy(&ceed); 65 return 0; 66 } 67