1 /// @file 2 /// Test setting QFunctionContext fields from Operator 3 /// \test Test setting QFunctionContext fields from Operator 4 #include <ceed.h> 5 #include <stddef.h> 6 #include "t500-operator.h" 7 8 typedef struct { 9 int count; 10 double other; 11 } TestContext1; 12 13 typedef struct { 14 double time; 15 double other; 16 } TestContext2; 17 18 int main(int argc, char **argv) { 19 Ceed ceed; 20 CeedQFunctionContext qf_ctx_sub_1, qf_ctx_sub_2; 21 CeedContextFieldLabel count_label, other_label, time_label; 22 CeedQFunction qf_sub_1, qf_sub_2; 23 CeedOperator op_sub_1, op_sub_2, op_composite; 24 25 TestContext1 ctx_data_1 = { 26 .count = 42, 27 .other = -3.0, 28 }; 29 TestContext2 ctx_data_2 = { 30 .time = 1.0, 31 .other = -3.0, 32 }; 33 34 CeedInit(argv[1], &ceed); 35 36 // First sub-operator 37 CeedQFunctionContextCreate(ceed, &qf_ctx_sub_1); 38 CeedQFunctionContextSetData(qf_ctx_sub_1, CEED_MEM_HOST, CEED_USE_POINTER, 39 sizeof(TestContext1), &ctx_data_1); 40 CeedQFunctionContextRegisterInt32(qf_ctx_sub_1, "count", offsetof(TestContext1, 41 count), "some sort of counter"); 42 CeedQFunctionContextRegisterDouble(qf_ctx_sub_1, "other", offsetof(TestContext1, 43 other), "some other value"); 44 45 CeedQFunctionCreateInterior(ceed, 1, setup, setup_loc, &qf_sub_1); 46 CeedQFunctionSetContext(qf_sub_1, qf_ctx_sub_1); 47 48 CeedOperatorCreate(ceed, qf_sub_1, CEED_QFUNCTION_NONE, CEED_QFUNCTION_NONE, 49 &op_sub_1); 50 51 // Check setting field in operator 52 CeedOperatorContextGetFieldLabel(op_sub_1, "count", &count_label); 53 CeedOperatorContextSetInt32(op_sub_1, count_label, 43); 54 if (ctx_data_1.count != 43) 55 // LCOV_EXCL_START 56 printf("Incorrect context data for count: %d != 43", ctx_data_1.count); 57 // LCOV_EXCL_STOP 58 59 // Second sub-operator 60 CeedQFunctionContextCreate(ceed, &qf_ctx_sub_2); 61 CeedQFunctionContextSetData(qf_ctx_sub_2, CEED_MEM_HOST, CEED_USE_POINTER, 62 sizeof(TestContext2), &ctx_data_2); 63 CeedQFunctionContextRegisterDouble(qf_ctx_sub_2, "time", offsetof(TestContext2, 64 time), "current time"); 65 CeedQFunctionContextRegisterDouble(qf_ctx_sub_2, "other", offsetof(TestContext2, 66 other), "some other value"); 67 68 CeedQFunctionCreateInterior(ceed, 1, mass, mass_loc, &qf_sub_2); 69 CeedQFunctionSetContext(qf_sub_2, qf_ctx_sub_2); 70 71 CeedOperatorCreate(ceed, qf_sub_2, CEED_QFUNCTION_NONE, CEED_QFUNCTION_NONE, 72 &op_sub_2); 73 74 // Composite operator 75 CeedCompositeOperatorCreate(ceed, &op_composite); 76 CeedCompositeOperatorAddSub(op_composite, op_sub_1); 77 CeedCompositeOperatorAddSub(op_composite, op_sub_2); 78 79 // Check setting field in context of single sub-operator for composite operator 80 CeedOperatorContextGetFieldLabel(op_composite, "time", &time_label); 81 CeedOperatorContextSetDouble(op_composite, time_label, 2.0); 82 if (ctx_data_2.time != 2.0) 83 // LCOV_EXCL_START 84 printf("Incorrect context data for time: %f != 2.0", ctx_data_2.time); 85 // LCOV_EXCL_STOP 86 87 // Check setting field in context of multiple sub-operators for composite operator 88 CeedOperatorContextGetFieldLabel(op_composite, "other", &other_label); 89 CeedOperatorContextSetDouble(op_composite, other_label, 9000.); 90 if (ctx_data_1.other != 9000.0) 91 // LCOV_EXCL_START 92 printf("Incorrect context data for other: %f != 2.0", ctx_data_1.other); 93 // LCOV_EXCL_STOP 94 if (ctx_data_2.other != 9000.0) 95 // LCOV_EXCL_START 96 printf("Incorrect context data for other: %f != 2.0", ctx_data_2.other); 97 // LCOV_EXCL_STOP 98 99 CeedQFunctionContextDestroy(&qf_ctx_sub_1); 100 CeedQFunctionContextDestroy(&qf_ctx_sub_2); 101 CeedQFunctionDestroy(&qf_sub_1); 102 CeedQFunctionDestroy(&qf_sub_2); 103 CeedOperatorDestroy(&op_sub_1); 104 CeedOperatorDestroy(&op_sub_2); 105 CeedOperatorDestroy(&op_composite); 106 CeedDestroy(&ceed); 107 return 0; 108 } 109