Skip to content

Commit 11436a0

Browse files
committed
examples/fluids: Set ctx->time via context fields
1 parent d92ccc1 commit 11436a0

5 files changed

Lines changed: 23 additions & 11 deletions

File tree

examples/fluids/navierstokes.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,7 @@ int main(int argc, char **argv) {
149149
// Set up libCEED
150150
// ---------------------------------------------------------------------------
151151
// -- Set up libCEED objects
152-
ierr = SetupLibceed(ceed, ceed_data, dm, user, app_ctx, problem, bc);
153-
CHKERRQ(ierr);
154-
155-
// -- Set up context for QFunctions
156-
ierr = problem->setup_ctx(ceed, ceed_data, app_ctx, setup_ctx, phys_ctx);
152+
ierr = SetupLibceed(ceed, ceed_data, dm, user, app_ctx, problem, bc, setup_ctx);
157153
CHKERRQ(ierr);
158154

159155
// ---------------------------------------------------------------------------

examples/fluids/navierstokes.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ struct Physics_private {
282282
PetscBool implicit;
283283
PetscBool has_curr_time;
284284
PetscBool has_neumann;
285+
CeedContextFieldLabel solution_time_label;
285286
};
286287

287288
// Problem specific data
@@ -384,7 +385,7 @@ PetscErrorCode CreateOperatorForDomain(Ceed ceed, DM dm, SimpleBC bc,
384385
CeedOperator *op_apply);
385386

386387
PetscErrorCode SetupLibceed(Ceed ceed, CeedData ceed_data, DM dm, User user,
387-
AppCtx app_ctx, ProblemData *problem, SimpleBC bc);
388+
AppCtx app_ctx, ProblemData *problem, SimpleBC bc, SetupContext setup_ctx);
388389

389390
// -----------------------------------------------------------------------------
390391
// Time-stepping functions

examples/fluids/problems/eulervortex.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,9 @@ PetscErrorCode SetupContext_EULER_VORTEX(Ceed ceed, CeedData ceed_data,
180180
CeedQFunctionContextSetData(ceed_data->euler_context, CEED_MEM_HOST,
181181
CEED_USE_POINTER,
182182
sizeof(*phys->euler_ctx), phys->euler_ctx);
183+
CeedQFunctionContextRegisterDouble(ceed_data->euler_context, "solution time",
184+
offsetof(struct EulerContext_, curr_time), 1, "Phyiscal time of the solution");
185+
183186
if (ceed_data->qf_ics)
184187
CeedQFunctionSetContext(ceed_data->qf_ics, ceed_data->euler_context);
185188
if (ceed_data->qf_rhs_vol)

examples/fluids/src/setuplibceed.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,16 @@ PetscErrorCode CreateOperatorForDomain(Ceed ceed, DM dm, SimpleBC bc,
205205
CeedOperatorDestroy(&op_apply_outflow);
206206
}
207207
}
208+
209+
// ----- Get Context Labels for Operator
210+
CeedOperatorContextGetFieldLabel(*op_apply, "solution time",
211+
&phys->solution_time_label);
212+
208213
PetscFunctionReturn(0);
209214
}
210215

211216
PetscErrorCode SetupLibceed(Ceed ceed, CeedData ceed_data, DM dm, User user,
212-
AppCtx app_ctx, ProblemData *problem, SimpleBC bc) {
217+
AppCtx app_ctx, ProblemData *problem, SimpleBC bc, SetupContext setup_ctx) {
213218
PetscErrorCode ierr;
214219
PetscFunctionBeginUser;
215220

@@ -452,6 +457,10 @@ PetscErrorCode SetupLibceed(Ceed ceed, CeedData ceed_data, DM dm, User user,
452457
CeedOperatorApply(ceed_data->op_setup_vol, ceed_data->x_coord,
453458
ceed_data->q_data, CEED_REQUEST_IMMEDIATE);
454459

460+
// -- Set up context for QFunctions
461+
ierr = problem->setup_ctx(ceed, ceed_data, app_ctx, setup_ctx, user->phys);
462+
CHKERRQ(ierr);
463+
455464
// -- Create and apply CEED Composite Operator for the entire domain
456465
if (!user->phys->implicit) { // RHS
457466
ierr = CreateOperatorForDomain(ceed, dm, bc, ceed_data, user->phys,

examples/fluids/src/setupts.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,9 @@ PetscErrorCode RHS_NS(TS ts, PetscReal t, Vec Q, Vec G, void *user_data) {
8989
PetscErrorCode ierr;
9090
PetscFunctionBeginUser;
9191

92-
// Update EulerContext
93-
if (user->phys->has_curr_time) user->phys->euler_ctx->curr_time = t;
92+
// Update solution time
93+
if (user->phys->solution_time_label)
94+
CeedOperatorContextSetDouble(user->op_rhs, user->phys->solution_time_label, &t);
9495

9596
// Get local vectors
9697
ierr = DMGetLocalVector(user->dm, &Q_loc); CHKERRQ(ierr);
@@ -146,8 +147,10 @@ PetscErrorCode IFunction_NS(TS ts, PetscReal t, Vec Q, Vec Q_dot, Vec G,
146147
PetscErrorCode ierr;
147148
PetscFunctionBeginUser;
148149

149-
// Update EulerContext
150-
if (user->phys->has_curr_time) user->phys->euler_ctx->curr_time = t;
150+
// Update solution time
151+
if (user->phys->solution_time_label)
152+
CeedOperatorContextSetDouble(user->op_ifunction,
153+
user->phys->solution_time_label, &t);
151154

152155
// Get local vectors
153156
ierr = DMGetLocalVector(user->dm, &Q_loc); CHKERRQ(ierr);

0 commit comments

Comments
 (0)