177841947SLeila Ghaffari /// @file 277841947SLeila Ghaffari /// Test QFunction helper macro 377841947SLeila Ghaffari /// \test Test QFunction helper macro 477841947SLeila Ghaffari #include "t405-qfunction.h" 577841947SLeila Ghaffari 62b730f8bSJeremy L Thompson #include <ceed.h> 7*49aac155SJeremy L Thompson #include <stdio.h> 82b730f8bSJeremy L Thompson 977841947SLeila Ghaffari int main(int argc, char **argv) { 1077841947SLeila Ghaffari Ceed ceed; 1177841947SLeila Ghaffari CeedVector in[16], out[16]; 124fee36f0SJeremy L Thompson CeedVector q_data, w, u, v; 1377841947SLeila Ghaffari CeedQFunction qf_setup, qf_mass; 144fee36f0SJeremy L Thompson CeedInt q = 8; 154fee36f0SJeremy L Thompson CeedScalar v_true[q]; 1677841947SLeila Ghaffari 1777841947SLeila Ghaffari CeedInit(argv[1], &ceed); 1877841947SLeila Ghaffari 194fee36f0SJeremy L Thompson CeedVectorCreate(ceed, q, &w); 204fee36f0SJeremy L Thompson CeedVectorCreate(ceed, q, &u); 214fee36f0SJeremy L Thompson { 224fee36f0SJeremy L Thompson CeedScalar w_array[q], u_array[q]; 234fee36f0SJeremy L Thompson 244fee36f0SJeremy L Thompson for (CeedInt i = 0; i < q; i++) { 254fee36f0SJeremy L Thompson CeedScalar x = 2. * i / (q - 1) - 1; 264fee36f0SJeremy L Thompson w_array[i] = 1 - x * x; 274fee36f0SJeremy L Thompson u_array[i] = 2 + 3 * x + 5 * x * x; 284fee36f0SJeremy L Thompson v_true[i] = w_array[i] * u_array[i]; 294fee36f0SJeremy L Thompson } 304fee36f0SJeremy L Thompson CeedVectorSetArray(w, CEED_MEM_HOST, CEED_COPY_VALUES, w_array); 314fee36f0SJeremy L Thompson CeedVectorSetArray(u, CEED_MEM_HOST, CEED_COPY_VALUES, u_array); 324fee36f0SJeremy L Thompson } 334fee36f0SJeremy L Thompson CeedVectorCreate(ceed, q, &v); 344fee36f0SJeremy L Thompson CeedVectorSetValue(v, 0); 354fee36f0SJeremy L Thompson CeedVectorCreate(ceed, q, &q_data); 364fee36f0SJeremy L Thompson CeedVectorSetValue(q_data, 0); 374fee36f0SJeremy L Thompson 3877841947SLeila Ghaffari CeedQFunctionCreateInterior(ceed, 1, setup, setup_loc, &qf_setup); 3977841947SLeila Ghaffari CeedQFunctionAddInput(qf_setup, "w", 1, CEED_EVAL_WEIGHT); 4077841947SLeila Ghaffari CeedQFunctionAddOutput(qf_setup, "q data", 1, CEED_EVAL_NONE); 414fee36f0SJeremy L Thompson { 424fee36f0SJeremy L Thompson in[0] = w; 434fee36f0SJeremy L Thompson out[0] = q_data; 444fee36f0SJeremy L Thompson CeedQFunctionApply(qf_setup, q, in, out); 454fee36f0SJeremy L Thompson } 4677841947SLeila Ghaffari 4777841947SLeila Ghaffari CeedQFunctionCreateInterior(ceed, 1, mass, mass_loc, &qf_mass); 4877841947SLeila Ghaffari CeedQFunctionAddInput(qf_mass, "q data", 1, CEED_EVAL_NONE); 4977841947SLeila Ghaffari CeedQFunctionAddInput(qf_mass, "u", 1, CEED_EVAL_INTERP); 5077841947SLeila Ghaffari CeedQFunctionAddOutput(qf_mass, "v", 1, CEED_EVAL_INTERP); 5177841947SLeila Ghaffari { 524fee36f0SJeremy L Thompson in[0] = w; 534fee36f0SJeremy L Thompson in[1] = u; 544fee36f0SJeremy L Thompson out[0] = v; 554fee36f0SJeremy L Thompson CeedQFunctionApply(qf_mass, q, in, out); 5677841947SLeila Ghaffari } 574fee36f0SJeremy L Thompson 584fee36f0SJeremy L Thompson // Verify result 5977841947SLeila Ghaffari { 604fee36f0SJeremy L Thompson const CeedScalar *v_array; 614fee36f0SJeremy L Thompson 624fee36f0SJeremy L Thompson CeedVectorGetArrayRead(v, CEED_MEM_HOST, &v_array); 634fee36f0SJeremy L Thompson for (CeedInt i = 0; i < q; i++) { 644fee36f0SJeremy L Thompson if (2 * v_true[i] != v_array[i]) printf("[%" CeedInt_FMT "] v %f != vv %f\n", i, 2 * v_true[i], v_array[i]); 654fee36f0SJeremy L Thompson } 664fee36f0SJeremy L Thompson CeedVectorRestoreArrayRead(v, &v_array); 6777841947SLeila Ghaffari } 6877841947SLeila Ghaffari 694fee36f0SJeremy L Thompson CeedVectorDestroy(&w); 704fee36f0SJeremy L Thompson CeedVectorDestroy(&u); 714fee36f0SJeremy L Thompson CeedVectorDestroy(&v); 724fee36f0SJeremy L Thompson CeedVectorDestroy(&q_data); 7377841947SLeila Ghaffari CeedQFunctionDestroy(&qf_setup); 7477841947SLeila Ghaffari CeedQFunctionDestroy(&qf_mass); 7577841947SLeila Ghaffari CeedDestroy(&ceed); 7677841947SLeila Ghaffari return 0; 7777841947SLeila Ghaffari } 78