177841947SLeila Ghaffari /// @file 277841947SLeila Ghaffari /// Test QFunction helper macro 377841947SLeila Ghaffari /// \test Test QFunction helper macro 477841947SLeila Ghaffari #include "t405-qfunction.h" 577841947SLeila Ghaffari 6*2b730f8bSJeremy L Thompson #include <ceed.h> 7*2b730f8bSJeremy L Thompson 877841947SLeila Ghaffari int main(int argc, char **argv) { 977841947SLeila Ghaffari Ceed ceed; 1077841947SLeila Ghaffari CeedVector in[16], out[16]; 1177841947SLeila Ghaffari CeedVector Q_data, W, U, V; 1277841947SLeila Ghaffari CeedQFunction qf_setup, qf_mass; 1377841947SLeila Ghaffari CeedInt Q = 8; 1477841947SLeila Ghaffari const CeedScalar *vv; 1577841947SLeila Ghaffari CeedScalar w[Q], u[Q], v[Q]; 1677841947SLeila Ghaffari 1777841947SLeila Ghaffari CeedInit(argv[1], &ceed); 1877841947SLeila Ghaffari 1977841947SLeila Ghaffari CeedQFunctionCreateInterior(ceed, 1, setup, setup_loc, &qf_setup); 2077841947SLeila Ghaffari CeedQFunctionAddInput(qf_setup, "w", 1, CEED_EVAL_WEIGHT); 2177841947SLeila Ghaffari CeedQFunctionAddOutput(qf_setup, "qdata", 1, CEED_EVAL_NONE); 2277841947SLeila Ghaffari 2377841947SLeila Ghaffari CeedQFunctionCreateInterior(ceed, 1, mass, mass_loc, &qf_mass); 2477841947SLeila Ghaffari CeedQFunctionAddInput(qf_mass, "qdata", 1, CEED_EVAL_NONE); 2577841947SLeila Ghaffari CeedQFunctionAddInput(qf_mass, "u", 1, CEED_EVAL_INTERP); 2677841947SLeila Ghaffari CeedQFunctionAddOutput(qf_mass, "v", 1, CEED_EVAL_INTERP); 2777841947SLeila Ghaffari 2877841947SLeila Ghaffari for (CeedInt i = 0; i < Q; i++) { 2977841947SLeila Ghaffari CeedScalar x = 2. * i / (Q - 1) - 1; 3077841947SLeila Ghaffari w[i] = 1 - x * x; 3177841947SLeila Ghaffari u[i] = 2 + 3 * x + 5 * x * x; 3277841947SLeila Ghaffari v[i] = w[i] * u[i]; 3377841947SLeila Ghaffari } 3477841947SLeila Ghaffari 3577841947SLeila Ghaffari CeedVectorCreate(ceed, Q, &W); 3677841947SLeila Ghaffari CeedVectorSetArray(W, CEED_MEM_HOST, CEED_USE_POINTER, w); 3777841947SLeila Ghaffari CeedVectorCreate(ceed, Q, &U); 3877841947SLeila Ghaffari CeedVectorSetArray(U, CEED_MEM_HOST, CEED_USE_POINTER, u); 3977841947SLeila Ghaffari CeedVectorCreate(ceed, Q, &V); 4077841947SLeila Ghaffari CeedVectorSetValue(V, 0); 4177841947SLeila Ghaffari CeedVectorCreate(ceed, Q, &Q_data); 4277841947SLeila Ghaffari CeedVectorSetValue(Q_data, 0); 4377841947SLeila Ghaffari 4477841947SLeila Ghaffari { 4577841947SLeila Ghaffari in[0] = W; 4677841947SLeila Ghaffari out[0] = Q_data; 4777841947SLeila Ghaffari CeedQFunctionApply(qf_setup, Q, in, out); 4877841947SLeila Ghaffari } 4977841947SLeila Ghaffari { 5077841947SLeila Ghaffari in[0] = W; 5177841947SLeila Ghaffari in[1] = U; 5277841947SLeila Ghaffari out[0] = V; 5377841947SLeila Ghaffari CeedQFunctionApply(qf_mass, Q, in, out); 5477841947SLeila Ghaffari } 5577841947SLeila Ghaffari 5677841947SLeila Ghaffari CeedVectorGetArrayRead(V, CEED_MEM_HOST, &vv); 57*2b730f8bSJeremy L Thompson for (CeedInt i = 0; i < Q; i++) { 58*2b730f8bSJeremy L Thompson if (2 * v[i] != vv[i]) printf("[%" CeedInt_FMT "] v %f != vv %f\n", i, v[i], vv[i]); 59*2b730f8bSJeremy L Thompson } 6077841947SLeila Ghaffari CeedVectorRestoreArrayRead(V, &vv); 6177841947SLeila Ghaffari 6277841947SLeila Ghaffari CeedVectorDestroy(&W); 6377841947SLeila Ghaffari CeedVectorDestroy(&U); 6477841947SLeila Ghaffari CeedVectorDestroy(&V); 6577841947SLeila Ghaffari CeedVectorDestroy(&Q_data); 6677841947SLeila Ghaffari CeedQFunctionDestroy(&qf_setup); 6777841947SLeila Ghaffari CeedQFunctionDestroy(&qf_mass); 6877841947SLeila Ghaffari CeedDestroy(&ceed); 6977841947SLeila Ghaffari return 0; 7077841947SLeila Ghaffari } 71