Skip to content

Commit

Permalink
use UpdateContextLabel()
Browse files Browse the repository at this point in the history
  • Loading branch information
LeilaGhaffari committed Jul 10, 2023
1 parent e516332 commit 9aea10a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
5 changes: 4 additions & 1 deletion examples/fluids/navierstokes.h
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,9 @@ PetscErrorCode TSSolve_NS(DM dm, User user, AppCtx app_ctx, Physics phys, Vec *Q
// Update Boundary Values when time has changed
PetscErrorCode UpdateBoundaryValues(User user, Vec Q_loc, PetscReal t);

// Update the context label value to new value if necessary
PetscErrorCode UpdateContextLabel(MPI_Comm comm, PetscScalar update_value, CeedOperator op, CeedContextFieldLabel label);

// -----------------------------------------------------------------------------
// Setup DM
// -----------------------------------------------------------------------------
Expand Down Expand Up @@ -385,7 +388,7 @@ PetscErrorCode DMPlexInsertBoundaryValues_NS(DM dm, PetscBool insert_essential,
PetscErrorCode RegressionTests_NS(AppCtx app_ctx, Vec Q);

// Get error for problems with exact solutions
PetscErrorCode ComputeL2Error(Vec Q_loc, PetscReal l2_error[5], OperatorApplyContext op_error_ctx, CeedContextFieldLabel time_label, CeedScalar time);
PetscErrorCode ComputeL2Error(MPI_Comm comm, Vec Q_loc, PetscReal l2_error[5], OperatorApplyContext op_error_ctx, CeedContextFieldLabel time_label, CeedScalar time);
PetscErrorCode GetError_NS(CeedData ceed_data, DM dm, User user, ProblemData *problem, Vec Qsource_soln, PetscScalar final_time);

// Post-processing
Expand Down
10 changes: 5 additions & 5 deletions examples/fluids/src/misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,13 @@ PetscErrorCode RegressionTests_NS(AppCtx app_ctx, Vec Q) {
PetscFunctionReturn(PETSC_SUCCESS);
}

PetscErrorCode ComputeL2Error(Vec Q_loc, PetscReal l2_error[5], OperatorApplyContext op_error_ctx, CeedContextFieldLabel time_label,
PetscErrorCode ComputeL2Error(MPI_Comm comm, Vec Q_loc, PetscReal l2_error[5], OperatorApplyContext op_error_ctx, CeedContextFieldLabel time_label,
CeedScalar time) {
Vec E;
PetscReal l2_norm[5];
PetscFunctionBeginUser;

if (time_label) CeedOperatorSetContextDouble(op_error_ctx->op, time_label, &time);
if (time_label) PetscCall(UpdateContextLabel(comm, time, op_error_ctx->op, time_label));
PetscCall(VecDuplicate(Q_loc, &E));
PetscCall(ApplyCeedOperatorLocalToGlobal(Q_loc, E, op_error_ctx));
PetscCall(VecStrideNormAll(E, NORM_1, l2_norm));
Expand All @@ -166,9 +166,9 @@ PetscErrorCode GetError_NS(CeedData ceed_data, DM dm, User user, ProblemData *pr
PetscCall(DMPlexInsertBoundaryValues_NS(dm, PETSC_TRUE, Q_loc, final_time, NULL, NULL, NULL));

// Compute the L2 error in the source state variables
if (user->phys->ics_time_label) CeedOperatorSetContextDouble(ceed_data->op_ics_ctx->op, user->phys->ics_time_label, &final_time);
if (user->phys->ics_time_label) PetscCall(UpdateContextLabel(user->comm, final_time, ceed_data->op_ics_ctx->op, user->phys->ics_time_label));
CeedOperatorApply(ceed_data->op_ics_ctx->op, ceed_data->x_coord, ceed_data->q_true, CEED_REQUEST_IMMEDIATE);
PetscCall(ComputeL2Error(Q_loc, l2_error, ceed_data->op_error_ctx, NULL, final_time));
PetscCall(ComputeL2Error(user->comm, Q_loc, l2_error, ceed_data->op_error_ctx, NULL, final_time));

// Print the error
PetscCall(PetscPrintf(PETSC_COMM_WORLD, "\nL2 Error:\n"));
Expand All @@ -180,7 +180,7 @@ PetscErrorCode GetError_NS(CeedData ceed_data, DM dm, User user, ProblemData *pr
const char *state_var_target = "Primitive";

// Convert the L2 error to the target state variable
PetscCall(ComputeL2Error(Q_loc, l2_error_converted, ceed_data->op_convert_error_ctx, user->phys->ics_time_label, final_time));
PetscCall(ComputeL2Error(user->comm, Q_loc, l2_error_converted, ceed_data->op_convert_error_ctx, user->phys->ics_time_label, final_time));

// Print the error
if (user->phys->state_var == STATEVAR_PRIMITIVE) state_var_target = "Conservative";
Expand Down

0 comments on commit 9aea10a

Please sign in to comment.