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 #include <stdio.h> 7 8 int main(int argc, char **argv) { 9 Ceed ceed; 10 CeedQFunctionContext ctx; 11 CeedScalar ctx_data[5] = {1, 2, 3, 4, 5}, *ctx_data_copy; 12 13 CeedInit(argv[1], &ceed); 14 15 // Set borrowed pointer 16 CeedQFunctionContextCreate(ceed, &ctx); 17 CeedQFunctionContextSetData(ctx, CEED_MEM_HOST, CEED_USE_POINTER, sizeof(ctx_data), &ctx_data); 18 19 // Update borrowed pointer 20 CeedQFunctionContextGetData(ctx, CEED_MEM_HOST, &ctx_data_copy); 21 ctx_data_copy[4] = 6; 22 CeedQFunctionContextRestoreData(ctx, &ctx_data_copy); 23 if (ctx_data[4] != 6) printf("error modifying data: %f != 6.0\n", ctx_data[4]); 24 25 // Take back borrowed pointer 26 CeedQFunctionContextTakeData(ctx, CEED_MEM_HOST, &ctx_data_copy); 27 if (ctx_data_copy[4] != 6) printf("error accessing borrowed data: %f != 6.0\n", ctx_data_copy[4]); 28 29 // Set copied data 30 ctx_data[4] = 6; 31 CeedQFunctionContextSetData(ctx, CEED_MEM_HOST, CEED_COPY_VALUES, sizeof(ctx_data), &ctx_data); 32 33 // Check copied data 34 CeedQFunctionContextGetData(ctx, CEED_MEM_HOST, &ctx_data_copy); 35 if (ctx_data_copy[4] != 6) printf("error accessing copied data: %f != 6.0\n", ctx_data_copy[4]); 36 CeedQFunctionContextRestoreData(ctx, &ctx_data_copy); 37 38 CeedQFunctionContextDestroy(&ctx); 39 CeedDestroy(&ceed); 40 return 0; 41 } 42