xref: /libCEED/tests/t402-qfunction.c (revision f2989f2b3b8649d855bed22b6730ee0ecfa6b31b)
1 /// @file
2 /// Test viewing of QFunction and QFunctionContext
3 /// \test Test viewing of QFunction and QFunctionContext
4 #include <ceed.h>
5 #include <stdio.h>
6 
7 #include "t400-qfunction.h"
8 
main(int argc,char ** argv)9 int main(int argc, char **argv) {
10   Ceed                 ceed;
11   CeedQFunction        qf_setup, qf_mass;
12   CeedQFunctionContext ctx;
13 
14   CeedInit(argv[1], &ceed);
15 
16   CeedQFunctionCreateInterior(ceed, 1, setup, setup_loc, &qf_setup);
17   CeedQFunctionAddInput(qf_setup, "w", 1, CEED_EVAL_WEIGHT);
18   CeedQFunctionAddOutput(qf_setup, "q data", 1, CEED_EVAL_NONE);
19 
20   CeedQFunctionCreateInterior(ceed, 1, mass, mass_loc, &qf_mass);
21   CeedQFunctionAddInput(qf_mass, "q data", 1, CEED_EVAL_NONE);
22   CeedQFunctionAddInput(qf_mass, "u", 1, CEED_EVAL_INTERP);
23   CeedQFunctionAddOutput(qf_mass, "v", 1, CEED_EVAL_INTERP);
24 
25   CeedQFunctionView(qf_setup, stdout);
26   CeedQFunctionView(qf_mass, stdout);
27 
28   CeedQFunctionContextCreate(ceed, &ctx);
29   {
30     double ctxData[5] = {1, 2, 3, 4, 5};
31 
32     CeedQFunctionContextSetData(ctx, CEED_MEM_HOST, CEED_COPY_VALUES, sizeof(ctxData), &ctxData);
33     CeedQFunctionContextRegisterDouble(ctx, "scale", 0, 5, "scaling values");
34   }
35   CeedQFunctionContextView(ctx, stdout);
36 
37   // Check tabs and CeedObject functionality
38   {
39     CeedQFunction        qf_mass_copy = NULL;
40     CeedQFunctionContext ctx_copy     = NULL;
41 
42     CeedQFunctionReferenceCopy(qf_mass, &qf_mass_copy);
43     CeedQFunctionSetNumViewTabs(qf_mass_copy, 1);
44     CeedObjectView((CeedObject)qf_mass_copy, stdout);
45     CeedObjectDestroy((CeedObject *)&qf_mass_copy);
46 
47     CeedQFunctionContextReferenceCopy(ctx, &ctx_copy);
48     CeedQFunctionContextSetNumViewTabs(ctx_copy, 1);
49     CeedObjectView((CeedObject)ctx_copy, stdout);
50     CeedObjectDestroy((CeedObject *)&ctx_copy);
51   }
52 
53   CeedQFunctionDestroy(&qf_setup);
54   CeedQFunctionDestroy(&qf_mass);
55   CeedQFunctionContextDestroy(&ctx);
56   CeedDestroy(&ceed);
57   return 0;
58 }
59