1d8dd9a91SJeremy L Thompson /// @file 2d8dd9a91SJeremy L Thompson /// Test setting QFunctionContext fields from Operator 3d8dd9a91SJeremy L Thompson /// \test Test setting QFunctionContext fields from Operator 4d8dd9a91SJeremy L Thompson #include <ceed.h> 5d8dd9a91SJeremy L Thompson #include <stddef.h> 6*2b730f8bSJeremy L Thompson 7d8dd9a91SJeremy L Thompson #include "t500-operator.h" 8d8dd9a91SJeremy L Thompson 9d8dd9a91SJeremy L Thompson typedef struct { 10d8dd9a91SJeremy L Thompson int count; 11d8dd9a91SJeremy L Thompson double other; 12d8dd9a91SJeremy L Thompson } TestContext1; 13d8dd9a91SJeremy L Thompson 14d8dd9a91SJeremy L Thompson typedef struct { 15d8dd9a91SJeremy L Thompson double time; 16d8dd9a91SJeremy L Thompson double other; 17d8dd9a91SJeremy L Thompson } TestContext2; 18d8dd9a91SJeremy L Thompson 19d8dd9a91SJeremy L Thompson int main(int argc, char **argv) { 20d8dd9a91SJeremy L Thompson Ceed ceed; 21d8dd9a91SJeremy L Thompson CeedQFunctionContext qf_ctx_sub_1, qf_ctx_sub_2; 22f2adece3SJeremy L Thompson CeedContextFieldLabel count_label, other_label, time_label, bad_label; 23d8dd9a91SJeremy L Thompson CeedQFunction qf_sub_1, qf_sub_2; 24d8dd9a91SJeremy L Thompson CeedOperator op_sub_1, op_sub_2, op_composite; 253668ca4bSJeremy L Thompson 26d8dd9a91SJeremy L Thompson TestContext1 ctx_data_1 = { 27d8dd9a91SJeremy L Thompson .count = 42, 28d8dd9a91SJeremy L Thompson .other = -3.0, 29d8dd9a91SJeremy L Thompson }; 30d8dd9a91SJeremy L Thompson TestContext2 ctx_data_2 = { 31d8dd9a91SJeremy L Thompson .time = 1.0, 32d8dd9a91SJeremy L Thompson .other = -3.0, 33d8dd9a91SJeremy L Thompson }; 34d8dd9a91SJeremy L Thompson 35d8dd9a91SJeremy L Thompson CeedInit(argv[1], &ceed); 36d8dd9a91SJeremy L Thompson 37d8dd9a91SJeremy L Thompson // First sub-operator 38d8dd9a91SJeremy L Thompson CeedQFunctionContextCreate(ceed, &qf_ctx_sub_1); 39*2b730f8bSJeremy L Thompson CeedQFunctionContextSetData(qf_ctx_sub_1, CEED_MEM_HOST, CEED_USE_POINTER, sizeof(TestContext1), &ctx_data_1); 40*2b730f8bSJeremy L Thompson CeedQFunctionContextRegisterInt32(qf_ctx_sub_1, "count", offsetof(TestContext1, count), 1, "some sort of counter"); 41*2b730f8bSJeremy L Thompson CeedQFunctionContextRegisterDouble(qf_ctx_sub_1, "other", offsetof(TestContext1, other), 1, "some other value"); 42d8dd9a91SJeremy L Thompson 43d8dd9a91SJeremy L Thompson CeedQFunctionCreateInterior(ceed, 1, setup, setup_loc, &qf_sub_1); 44d8dd9a91SJeremy L Thompson CeedQFunctionSetContext(qf_sub_1, qf_ctx_sub_1); 45d8dd9a91SJeremy L Thompson 46*2b730f8bSJeremy L Thompson CeedOperatorCreate(ceed, qf_sub_1, CEED_QFUNCTION_NONE, CEED_QFUNCTION_NONE, &op_sub_1); 47d8dd9a91SJeremy L Thompson 48d8dd9a91SJeremy L Thompson // Check setting field in operator 493668ca4bSJeremy L Thompson CeedOperatorContextGetFieldLabel(op_sub_1, "count", &count_label); 507bfe0f0eSJeremy L Thompson int value_count = 43; 517bfe0f0eSJeremy L Thompson CeedOperatorContextSetInt32(op_sub_1, count_label, &value_count); 52*2b730f8bSJeremy L Thompson if (ctx_data_1.count != 43) printf("Incorrect context data for count: %" CeedInt_FMT " != 43", ctx_data_1.count); 53d8dd9a91SJeremy L Thompson 54d8dd9a91SJeremy L Thompson // Second sub-operator 55d8dd9a91SJeremy L Thompson CeedQFunctionContextCreate(ceed, &qf_ctx_sub_2); 56*2b730f8bSJeremy L Thompson CeedQFunctionContextSetData(qf_ctx_sub_2, CEED_MEM_HOST, CEED_USE_POINTER, sizeof(TestContext2), &ctx_data_2); 57*2b730f8bSJeremy L Thompson CeedQFunctionContextRegisterDouble(qf_ctx_sub_2, "time", offsetof(TestContext2, time), 1, "current time"); 58*2b730f8bSJeremy L Thompson CeedQFunctionContextRegisterDouble(qf_ctx_sub_2, "other", offsetof(TestContext2, other), 1, "some other value"); 59d8dd9a91SJeremy L Thompson 60d8dd9a91SJeremy L Thompson CeedQFunctionCreateInterior(ceed, 1, mass, mass_loc, &qf_sub_2); 61d8dd9a91SJeremy L Thompson CeedQFunctionSetContext(qf_sub_2, qf_ctx_sub_2); 62d8dd9a91SJeremy L Thompson 63*2b730f8bSJeremy L Thompson CeedOperatorCreate(ceed, qf_sub_2, CEED_QFUNCTION_NONE, CEED_QFUNCTION_NONE, &op_sub_2); 64d8dd9a91SJeremy L Thompson 65d8dd9a91SJeremy L Thompson // Composite operator 66d8dd9a91SJeremy L Thompson CeedCompositeOperatorCreate(ceed, &op_composite); 67d8dd9a91SJeremy L Thompson CeedCompositeOperatorAddSub(op_composite, op_sub_1); 68d8dd9a91SJeremy L Thompson CeedCompositeOperatorAddSub(op_composite, op_sub_2); 69d8dd9a91SJeremy L Thompson 70d8dd9a91SJeremy L Thompson // Check setting field in context of single sub-operator for composite operator 713668ca4bSJeremy L Thompson CeedOperatorContextGetFieldLabel(op_composite, "time", &time_label); 727bfe0f0eSJeremy L Thompson double value_time = 2.0; 737bfe0f0eSJeremy L Thompson CeedOperatorContextSetDouble(op_composite, time_label, &value_time); 74*2b730f8bSJeremy L Thompson if (ctx_data_2.time != 2.0) printf("Incorrect context data for time: %f != 2.0\n", ctx_data_2.time); 75d8dd9a91SJeremy L Thompson 76d8dd9a91SJeremy L Thompson // Check setting field in context of multiple sub-operators for composite operator 773668ca4bSJeremy L Thompson CeedOperatorContextGetFieldLabel(op_composite, "other", &other_label); 78dab60d25SJeremy L Thompson // No issue requesting same label twice 79dab60d25SJeremy L Thompson CeedOperatorContextGetFieldLabel(op_composite, "other", &other_label); 807bfe0f0eSJeremy L Thompson double value_other = 9000.; 817bfe0f0eSJeremy L Thompson CeedOperatorContextSetDouble(op_composite, other_label, &value_other); 82*2b730f8bSJeremy L Thompson if (ctx_data_1.other != 9000.0) printf("Incorrect context data for other: %f != 2.0\n", ctx_data_1.other); 83*2b730f8bSJeremy L Thompson if (ctx_data_2.other != 9000.0) printf("Incorrect context data for other: %f != 2.0\n", ctx_data_2.other); 84d8dd9a91SJeremy L Thompson 85f2adece3SJeremy L Thompson // Check requesting label for field that doesn't exist returns NULL 86f2adece3SJeremy L Thompson CeedOperatorContextGetFieldLabel(op_composite, "bad", &bad_label); 87*2b730f8bSJeremy L Thompson if (bad_label) printf("Incorrect context label returned\n"); 88f2adece3SJeremy L Thompson 89d8dd9a91SJeremy L Thompson CeedQFunctionContextDestroy(&qf_ctx_sub_1); 90d8dd9a91SJeremy L Thompson CeedQFunctionContextDestroy(&qf_ctx_sub_2); 91d8dd9a91SJeremy L Thompson CeedQFunctionDestroy(&qf_sub_1); 92d8dd9a91SJeremy L Thompson CeedQFunctionDestroy(&qf_sub_2); 93d8dd9a91SJeremy L Thompson CeedOperatorDestroy(&op_sub_1); 94d8dd9a91SJeremy L Thompson CeedOperatorDestroy(&op_sub_2); 95d8dd9a91SJeremy L Thompson CeedOperatorDestroy(&op_composite); 96d8dd9a91SJeremy L Thompson CeedDestroy(&ceed); 97d8dd9a91SJeremy L Thompson return 0; 98d8dd9a91SJeremy L Thompson } 99