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