1b249f0c7SJeremy L Thompson /// @file
2b249f0c7SJeremy L Thompson /// Test creation, evaluation, and destruction for vector Poisson QFunction by name
3b249f0c7SJeremy L Thompson /// \test Test creation, evaluation, and destruction for vector Poisson QFunction by name
4b249f0c7SJeremy L Thompson #include <ceed.h>
5b249f0c7SJeremy L Thompson #include <math.h>
6*49aac155SJeremy L Thompson #include <stdio.h>
7b249f0c7SJeremy L Thompson #include <string.h>
8b249f0c7SJeremy L Thompson
main(int argc,char ** argv)9b249f0c7SJeremy L Thompson int main(int argc, char **argv) {
10b249f0c7SJeremy L Thompson Ceed ceed;
11b249f0c7SJeremy L Thompson CeedVector in[16], out[16];
124fee36f0SJeremy L Thompson CeedVector q_data, dx, w, du, dv;
13b249f0c7SJeremy L Thompson CeedQFunction qf_setup, qf_diff;
144fee36f0SJeremy L Thompson CeedInt q = 8;
15b249f0c7SJeremy L Thompson const CeedInt num_comp = 3;
16b249f0c7SJeremy L Thompson
17b249f0c7SJeremy L Thompson CeedInit(argv[1], &ceed);
18b249f0c7SJeremy L Thompson
19b249f0c7SJeremy L Thompson for (CeedInt dim = 1; dim <= 3; dim++) {
204fee36f0SJeremy L Thompson CeedInt num_qpts = CeedIntPow(q, dim);
21b249f0c7SJeremy L Thompson
224fee36f0SJeremy L Thompson CeedVectorCreate(ceed, num_qpts * dim * dim, &dx);
234fee36f0SJeremy L Thompson CeedVectorCreate(ceed, num_qpts, &w);
244fee36f0SJeremy L Thompson CeedVectorCreate(ceed, num_qpts * dim * num_comp, &du);
254fee36f0SJeremy L Thompson {
264fee36f0SJeremy L Thompson CeedScalar dx_array[num_qpts * dim * dim], w_array[num_qpts], du_array[num_qpts * dim * num_comp];
27b249f0c7SJeremy L Thompson
28b249f0c7SJeremy L Thompson for (CeedInt i = 0; i < num_qpts; i++) {
294fee36f0SJeremy L Thompson w_array[i] = 1.0 / num_qpts;
30b249f0c7SJeremy L Thompson }
31b249f0c7SJeremy L Thompson for (CeedInt d = 0; d < dim; d++) {
32b249f0c7SJeremy L Thompson for (CeedInt g = 0; g < dim; g++) {
33b249f0c7SJeremy L Thompson for (CeedInt i = 0; i < num_qpts; i++) {
344fee36f0SJeremy L Thompson dx_array[i + (g * dim + d) * num_qpts] = d == g;
35b249f0c7SJeremy L Thompson }
36b249f0c7SJeremy L Thompson }
37b249f0c7SJeremy L Thompson }
38b249f0c7SJeremy L Thompson for (CeedInt c = 0; c < num_comp; c++) {
39b249f0c7SJeremy L Thompson for (CeedInt g = 0; g < dim; g++) {
40b249f0c7SJeremy L Thompson for (CeedInt i = 0; i < num_qpts; i++) {
414fee36f0SJeremy L Thompson du_array[i + (g * num_comp + c) * num_qpts] = c + 1;
42b249f0c7SJeremy L Thompson }
43b249f0c7SJeremy L Thompson }
44b249f0c7SJeremy L Thompson }
45b249f0c7SJeremy L Thompson
464fee36f0SJeremy L Thompson CeedVectorSetArray(dx, CEED_MEM_HOST, CEED_COPY_VALUES, dx_array);
474fee36f0SJeremy L Thompson CeedVectorSetArray(w, CEED_MEM_HOST, CEED_COPY_VALUES, w_array);
484fee36f0SJeremy L Thompson CeedVectorSetArray(du, CEED_MEM_HOST, CEED_COPY_VALUES, du_array);
494fee36f0SJeremy L Thompson }
504fee36f0SJeremy L Thompson CeedVectorCreate(ceed, num_qpts * dim * (dim + 1) / 2, &q_data);
514fee36f0SJeremy L Thompson CeedVectorSetValue(q_data, 0.0);
524fee36f0SJeremy L Thompson CeedVectorCreate(ceed, num_qpts * dim * num_comp, &dv);
534fee36f0SJeremy L Thompson CeedVectorSetValue(dv, 0.0);
54b249f0c7SJeremy L Thompson
554fee36f0SJeremy L Thompson char name_setup[26] = "", name_apply[26] = "";
564fee36f0SJeremy L Thompson snprintf(name_setup, sizeof name_setup, "Poisson%" CeedInt_FMT "DBuild", dim);
574fee36f0SJeremy L Thompson CeedQFunctionCreateInteriorByName(ceed, name_setup, &qf_setup);
58b249f0c7SJeremy L Thompson {
594fee36f0SJeremy L Thompson in[0] = dx;
604fee36f0SJeremy L Thompson in[1] = w;
614fee36f0SJeremy L Thompson out[0] = q_data;
62b249f0c7SJeremy L Thompson CeedQFunctionApply(qf_setup, num_qpts, in, out);
63b249f0c7SJeremy L Thompson }
644fee36f0SJeremy L Thompson
654fee36f0SJeremy L Thompson snprintf(name_apply, sizeof name_apply, "Vector3Poisson%" CeedInt_FMT "DApply", dim);
664fee36f0SJeremy L Thompson CeedQFunctionCreateInteriorByName(ceed, name_apply, &qf_diff);
67b249f0c7SJeremy L Thompson {
684fee36f0SJeremy L Thompson in[0] = du;
694fee36f0SJeremy L Thompson in[1] = q_data;
704fee36f0SJeremy L Thompson out[0] = dv;
71b249f0c7SJeremy L Thompson CeedQFunctionApply(qf_diff, num_qpts, in, out);
72b249f0c7SJeremy L Thompson }
73b249f0c7SJeremy L Thompson
744fee36f0SJeremy L Thompson // Verify results
754fee36f0SJeremy L Thompson {
764fee36f0SJeremy L Thompson const CeedScalar *v_array;
774fee36f0SJeremy L Thompson
784fee36f0SJeremy L Thompson CeedVectorGetArrayRead(dv, CEED_MEM_HOST, &v_array);
79b249f0c7SJeremy L Thompson for (CeedInt c = 0; c < num_comp; c++) {
80b249f0c7SJeremy L Thompson CeedScalar sum = 0;
812b730f8bSJeremy L Thompson for (CeedInt i = 0; i < num_qpts; i++) {
824fee36f0SJeremy L Thompson for (CeedInt g = 0; g < dim; g++) sum += v_array[i + (g * num_comp + c) * num_qpts];
832b730f8bSJeremy L Thompson }
842b730f8bSJeremy L Thompson if (fabs(sum - dim * (c + 1)) > 10 * CEED_EPSILON) {
85b249f0c7SJeremy L Thompson // LCOV_EXCL_START
862b730f8bSJeremy L Thompson printf("%" CeedInt_FMT "D volume error in component %" CeedInt_FMT ": %f != %f\n", dim, c, sum, dim * (c + 1.0));
87b249f0c7SJeremy L Thompson // LCOV_EXCL_STOP
88b249f0c7SJeremy L Thompson }
892b730f8bSJeremy L Thompson }
904fee36f0SJeremy L Thompson CeedVectorRestoreArrayRead(dv, &v_array);
914fee36f0SJeremy L Thompson }
92b249f0c7SJeremy L Thompson
934fee36f0SJeremy L Thompson CeedVectorDestroy(&dx);
944fee36f0SJeremy L Thompson CeedVectorDestroy(&w);
954fee36f0SJeremy L Thompson CeedVectorDestroy(&du);
964fee36f0SJeremy L Thompson CeedVectorDestroy(&dv);
974fee36f0SJeremy L Thompson CeedVectorDestroy(&q_data);
98b249f0c7SJeremy L Thompson CeedQFunctionDestroy(&qf_setup);
99b249f0c7SJeremy L Thompson CeedQFunctionDestroy(&qf_diff);
100b249f0c7SJeremy L Thompson }
101b249f0c7SJeremy L Thompson
102b249f0c7SJeremy L Thompson CeedDestroy(&ceed);
103b249f0c7SJeremy L Thompson return 0;
104b249f0c7SJeremy L Thompson }
105