1 /// @file
2 /// Test QFunction helper macro
3 /// \test Test QFunction helper macro
4 #include "t405-qfunction.h"
5
6 #include <ceed.h>
7 #include <stdio.h>
8
main(int argc,char ** argv)9 int main(int argc, char **argv) {
10 Ceed ceed;
11 CeedVector in[16], out[16];
12 CeedVector q_data, w, u, v;
13 CeedQFunction qf_setup, qf_mass;
14 CeedInt q = 8;
15 CeedScalar v_true[q];
16
17 CeedInit(argv[1], &ceed);
18
19 CeedVectorCreate(ceed, q, &w);
20 CeedVectorCreate(ceed, q, &u);
21 {
22 CeedScalar w_array[q], u_array[q];
23
24 for (CeedInt i = 0; i < q; i++) {
25 CeedScalar x = 2. * i / (q - 1) - 1;
26 w_array[i] = 1 - x * x;
27 u_array[i] = 2 + 3 * x + 5 * x * x;
28 v_true[i] = w_array[i] * u_array[i];
29 }
30 CeedVectorSetArray(w, CEED_MEM_HOST, CEED_COPY_VALUES, w_array);
31 CeedVectorSetArray(u, CEED_MEM_HOST, CEED_COPY_VALUES, u_array);
32 }
33 CeedVectorCreate(ceed, q, &v);
34 CeedVectorSetValue(v, 0);
35 CeedVectorCreate(ceed, q, &q_data);
36 CeedVectorSetValue(q_data, 0);
37
38 CeedQFunctionCreateInterior(ceed, 1, setup, setup_loc, &qf_setup);
39 CeedQFunctionAddInput(qf_setup, "w", 1, CEED_EVAL_WEIGHT);
40 CeedQFunctionAddOutput(qf_setup, "q data", 1, CEED_EVAL_NONE);
41 {
42 in[0] = w;
43 out[0] = q_data;
44 CeedQFunctionApply(qf_setup, q, in, out);
45 }
46
47 CeedQFunctionCreateInterior(ceed, 1, mass, mass_loc, &qf_mass);
48 CeedQFunctionAddInput(qf_mass, "q data", 1, CEED_EVAL_NONE);
49 CeedQFunctionAddInput(qf_mass, "u", 1, CEED_EVAL_INTERP);
50 CeedQFunctionAddOutput(qf_mass, "v", 1, CEED_EVAL_INTERP);
51 {
52 in[0] = w;
53 in[1] = u;
54 out[0] = v;
55 CeedQFunctionApply(qf_mass, q, in, out);
56 }
57
58 // Verify result
59 {
60 const CeedScalar *v_array;
61
62 CeedVectorGetArrayRead(v, CEED_MEM_HOST, &v_array);
63 for (CeedInt i = 0; i < q; i++) {
64 if (2 * v_true[i] != v_array[i]) printf("[%" CeedInt_FMT "] v %f != vv %f\n", i, 2 * v_true[i], v_array[i]);
65 }
66 CeedVectorRestoreArrayRead(v, &v_array);
67 }
68
69 CeedVectorDestroy(&w);
70 CeedVectorDestroy(&u);
71 CeedVectorDestroy(&v);
72 CeedVectorDestroy(&q_data);
73 CeedQFunctionDestroy(&qf_setup);
74 CeedQFunctionDestroy(&qf_mass);
75 CeedDestroy(&ceed);
76 return 0;
77 }
78