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