xref: /libCEED/tests/t408-qfunction.c (revision 49aac155e7a09736f56fb3abac0f57dab29f7cbf)
128bfd0b7SJeremy L Thompson /// @file
228bfd0b7SJeremy L Thompson /// Test read access for QFunctionContext data
328bfd0b7SJeremy L Thompson /// \test Test read access for QFunctionContext data
428bfd0b7SJeremy L Thompson #include <ceed.h>
528bfd0b7SJeremy L Thompson #include <math.h>
6*49aac155SJeremy L Thompson #include <stdio.h>
728bfd0b7SJeremy L Thompson 
828bfd0b7SJeremy L Thompson int main(int argc, char **argv) {
928bfd0b7SJeremy L Thompson   Ceed                 ceed;
1028bfd0b7SJeremy L Thompson   CeedQFunctionContext ctx;
114fee36f0SJeremy L Thompson   CeedScalar           ctx_data[5] = {1, 2, 3, 4, 5}, *ctx_data_copy;
1228bfd0b7SJeremy L Thompson 
1328bfd0b7SJeremy L Thompson   CeedInit(argv[1], &ceed);
1428bfd0b7SJeremy L Thompson 
1528bfd0b7SJeremy L Thompson   CeedQFunctionContextCreate(ceed, &ctx);
164fee36f0SJeremy L Thompson   CeedQFunctionContextSetData(ctx, CEED_MEM_HOST, CEED_COPY_VALUES, sizeof(ctx_data), &ctx_data);
1728bfd0b7SJeremy L Thompson 
1828bfd0b7SJeremy L Thompson   // Get data access
194fee36f0SJeremy L Thompson   CeedQFunctionContextGetDataRead(ctx, CEED_MEM_HOST, &ctx_data_copy);
204fee36f0SJeremy L Thompson   if (ctx_data_copy[4] != 5)
2128bfd0b7SJeremy L Thompson     // LCOV_EXCL_START
224fee36f0SJeremy L Thompson     printf("error reading data: %f != 5.0\n", ctx_data_copy[4]);
2328bfd0b7SJeremy L Thompson   // LCOV_EXCL_STOP
244fee36f0SJeremy L Thompson   CeedQFunctionContextRestoreDataRead(ctx, &ctx_data_copy);
2528bfd0b7SJeremy L Thompson 
2628bfd0b7SJeremy L Thompson   // Check access protection - should error
274fee36f0SJeremy L Thompson   CeedQFunctionContextGetDataRead(ctx, CEED_MEM_HOST, &ctx_data_copy);
284fee36f0SJeremy L Thompson   CeedQFunctionContextGetData(ctx, CEED_MEM_HOST, &ctx_data_copy);
294fee36f0SJeremy L Thompson   CeedQFunctionContextRestoreData(ctx, &ctx_data_copy);
304fee36f0SJeremy L Thompson   CeedQFunctionContextRestoreDataRead(ctx, &ctx_data_copy);
3128bfd0b7SJeremy L Thompson 
3228bfd0b7SJeremy L Thompson   CeedQFunctionContextDestroy(&ctx);
3328bfd0b7SJeremy L Thompson   CeedDestroy(&ceed);
3428bfd0b7SJeremy L Thompson   return 0;
3528bfd0b7SJeremy L Thompson }
36