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