xref: /libCEED/tests/t404-qfunction.c (revision 1f9221fe62e2635d1a8dba99f0dac116b51a901d)
1 /// @file
2 /// Test creation, setting, and taking data for QFunctionContext
3 /// \test Test creation, setting, and taking data for QFunctionContext
4 #include <ceed.h>
5 #include <math.h>
6 
7 int main(int argc, char **argv) {
8   Ceed ceed;
9   CeedQFunctionContext ctx;
10   CeedScalar ctxData[5] = {1, 2, 3, 4, 5}, *ctxDataCopy;
11 
12   CeedInit(argv[1], &ceed);
13 
14   CeedQFunctionContextCreate(ceed, &ctx);
15   CeedQFunctionContextSetData(ctx, CEED_MEM_HOST, CEED_USE_POINTER,
16                               sizeof(ctxData), &ctxData);
17 
18   CeedQFunctionContextGetData(ctx, CEED_MEM_HOST, &ctxDataCopy);
19   ctxDataCopy[4] = 6;
20   CeedQFunctionContextRestoreData(ctx, &ctxDataCopy);
21   if (ctxData[4] != 6)
22     // LCOV_EXCL_START
23     printf("error modifying data: %f != 6.0\n", ctxData[4]);
24   // LCOV_EXCL_STOP
25 
26   CeedQFunctionContextTakeData(ctx, CEED_MEM_HOST, &ctxDataCopy);
27   CeedQFunctionContextDestroy(&ctx);
28   CeedDestroy(&ceed);
29   return 0;
30 }
31