Skip to content

Commit

Permalink
fluids: Unify Newtonian Primitive functions #1035
Browse files Browse the repository at this point in the history
Merge separate IFunction and IJacobian routines into a single helper function and 
separate wrappers for each state variable option.
  • Loading branch information
jrwrigh authored Aug 26, 2022
2 parents 99b47b4 + 3d02368 commit 12f40bf
Show file tree
Hide file tree
Showing 11 changed files with 211 additions and 448 deletions.
2 changes: 1 addition & 1 deletion examples/fluids/navierstokes.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ struct Physics_private {
EulerTestType euler_test;
StabilizationType stab;
PetscBool implicit;
PetscBool primitive;
PetscBool use_primitive;
PetscBool has_curr_time;
PetscBool has_neumann;
CeedContextFieldLabel solution_time_label;
Expand Down
2 changes: 1 addition & 1 deletion examples/fluids/problems/channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ PetscErrorCode NS_CHANNEL(ProblemData *problem, DM dm, void *ctx) {
CeedQFunctionContextDestroy(&problem->ics.qfunction_context);
problem->ics.qfunction = ICsChannel;
problem->ics.qfunction_loc = ICsChannel_loc;
if (!user->phys->primitive) {
if (!user->phys->use_primitive) {
problem->apply_inflow.qfunction = Channel_Inflow;
problem->apply_inflow.qfunction_loc = Channel_Inflow_loc;
problem->apply_outflow.qfunction = Channel_Outflow;
Expand Down
54 changes: 28 additions & 26 deletions examples/fluids/problems/newtonian.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ PetscErrorCode NS_NEWTONIAN_IG(ProblemData *problem, DM dm, void *ctx) {
MPI_Comm comm = PETSC_COMM_WORLD;
PetscBool implicit;
PetscBool has_curr_time = PETSC_FALSE,
prim_var, unit_tests;
use_primitive, unit_tests;
PetscInt ierr;
NewtonianIdealGasContext newtonian_ig_ctx;
CeedQFunctionContext newtonian_ig_context;
Expand Down Expand Up @@ -137,40 +137,42 @@ PetscErrorCode NS_NEWTONIAN_IG(ProblemData *problem, DM dm, void *ctx) {
NULL);
// -- Conservative vs Primitive variables
ierr = PetscOptionsBool("-primitive", "Use primitive variables",
NULL, prim_var=PETSC_FALSE, &prim_var, NULL); CHKERRQ(ierr);
if (prim_var) {
NULL, use_primitive=PETSC_FALSE, &use_primitive, NULL); CHKERRQ(ierr);
// *INDENT-OFF*
if (use_primitive) {
problem->ics.qfunction = ICsNewtonianIG_Prim;
problem->ics.qfunction_loc = ICsNewtonianIG_Prim_loc;
problem->apply_vol_ifunction.qfunction = IFunction_Newtonian_Prim;
problem->apply_vol_ifunction.qfunction_loc = IFunction_Newtonian_Prim_loc;
problem->apply_vol_ijacobian.qfunction = IJacobian_Newtonian_Prim;
problem->apply_vol_ijacobian.qfunction_loc = IJacobian_Newtonian_Prim_loc;
problem->apply_inflow.qfunction = BoundaryIntegral;
problem->apply_inflow.qfunction_loc = BoundaryIntegral_loc;
problem->apply_inflow_jacobian.qfunction = BoundaryIntegral_Jacobian;
problem->apply_inflow_jacobian.qfunction_loc = BoundaryIntegral_Jacobian_loc;
problem->apply_outflow.qfunction = PressureOutflow;
problem->apply_outflow.qfunction_loc = PressureOutflow_loc;
problem->apply_outflow_jacobian.qfunction = PressureOutflow_Jacobian;
problem->apply_outflow_jacobian.qfunction_loc = PressureOutflow_Jacobian_loc;
problem->apply_inflow.qfunction = BoundaryIntegral_Prim;
problem->apply_inflow.qfunction_loc = BoundaryIntegral_Prim_loc;
problem->apply_inflow_jacobian.qfunction = BoundaryIntegral_Jacobian_Prim;
problem->apply_inflow_jacobian.qfunction_loc = BoundaryIntegral_Jacobian_Prim_loc;
problem->apply_outflow.qfunction = PressureOutflow_Prim;
problem->apply_outflow.qfunction_loc = PressureOutflow_Prim_loc;
problem->apply_outflow_jacobian.qfunction = PressureOutflow_Jacobian_Prim;
problem->apply_outflow_jacobian.qfunction_loc = PressureOutflow_Jacobian_Prim_loc;
} else {
problem->ics.qfunction = ICsNewtonianIG;
problem->ics.qfunction_loc = ICsNewtonianIG_loc;
problem->apply_vol_rhs.qfunction = RHSFunction_Newtonian;
problem->apply_vol_rhs.qfunction_loc = RHSFunction_Newtonian_loc;
problem->apply_vol_ifunction.qfunction = IFunction_Newtonian;
problem->apply_vol_ifunction.qfunction_loc = IFunction_Newtonian_loc;
problem->apply_vol_ijacobian.qfunction = IJacobian_Newtonian;
problem->apply_vol_ijacobian.qfunction_loc = IJacobian_Newtonian_loc;
problem->apply_inflow.qfunction = BoundaryIntegral;
problem->apply_inflow.qfunction_loc = BoundaryIntegral_loc;
problem->apply_inflow_jacobian.qfunction = BoundaryIntegral_Jacobian;
problem->apply_inflow_jacobian.qfunction_loc = BoundaryIntegral_Jacobian_loc;
problem->apply_outflow.qfunction = PressureOutflow;
problem->apply_outflow.qfunction_loc = PressureOutflow_loc;
problem->apply_outflow_jacobian.qfunction = PressureOutflow_Jacobian;
problem->apply_outflow_jacobian.qfunction_loc = PressureOutflow_Jacobian_loc;
problem->apply_vol_ifunction.qfunction = IFunction_Newtonian_Conserv;
problem->apply_vol_ifunction.qfunction_loc = IFunction_Newtonian_Conserv_loc;
problem->apply_vol_ijacobian.qfunction = IJacobian_Newtonian_Conserv;
problem->apply_vol_ijacobian.qfunction_loc = IJacobian_Newtonian_Conserv_loc;
problem->apply_inflow.qfunction = BoundaryIntegral_Conserv;
problem->apply_inflow.qfunction_loc = BoundaryIntegral_Conserv_loc;
problem->apply_inflow_jacobian.qfunction = BoundaryIntegral_Jacobian_Conserv;
problem->apply_inflow_jacobian.qfunction_loc = BoundaryIntegral_Jacobian_Conserv_loc;
problem->apply_outflow.qfunction = PressureOutflow_Conserv;
problem->apply_outflow.qfunction_loc = PressureOutflow_Conserv_loc;
problem->apply_outflow_jacobian.qfunction = PressureOutflow_Jacobian_Conserv;
problem->apply_outflow_jacobian.qfunction_loc = PressureOutflow_Jacobian_Conserv_loc;
}
// *INDENT-ON*

// -- Physics
ierr = PetscOptionsScalar("-cv", "Heat capacity at constant volume",
Expand Down Expand Up @@ -231,7 +233,7 @@ PetscErrorCode NS_NEWTONIAN_IG(ProblemData *problem, DM dm, void *ctx) {
"Warning! Use -stab supg only with -implicit\n");
CHKERRQ(ierr);
}
if (prim_var && !implicit) {
if (use_primitive && !implicit) {
SETERRQ(comm, PETSC_ERR_ARG_NULL,
"RHSFunction is not provided for primitive variables (use -primitive only with -implicit)\n");
}
Expand Down Expand Up @@ -279,7 +281,7 @@ PetscErrorCode NS_NEWTONIAN_IG(ProblemData *problem, DM dm, void *ctx) {
// -- Solver Settings
user->phys->stab = stab;
user->phys->implicit = implicit;
user->phys->primitive = prim_var;
user->phys->use_primitive = use_primitive;
user->phys->has_curr_time = has_curr_time;

// -- QFunction Context
Expand All @@ -296,7 +298,7 @@ PetscErrorCode NS_NEWTONIAN_IG(ProblemData *problem, DM dm, void *ctx) {
newtonian_ig_ctx->Ctau_E = Ctau_E;
newtonian_ig_ctx->stabilization = stab;
newtonian_ig_ctx->is_implicit = implicit;
newtonian_ig_ctx->is_primitive = prim_var;
newtonian_ig_ctx->use_primitive = use_primitive;
ierr = PetscArraycpy(newtonian_ig_ctx->g, g, 3); CHKERRQ(ierr);

CeedQFunctionContextCreate(user->ceed, &problem->ics.qfunction_context);
Expand Down
2 changes: 1 addition & 1 deletion examples/fluids/problems/stg_shur14.c
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ PetscErrorCode SetupStrongSTG(DM dm, SimpleBC bc, ProblemData *problem,
PetscFunctionBeginUser;

PetscInt comps[5], num_comps=4;
if (phys->primitive) {
if (phys->use_primitive) {
// {1,2,3,4} for u, v, w, T
for(int i=0; i<4; i++) comps[i] = i+1;
} else {
Expand Down
2 changes: 1 addition & 1 deletion examples/fluids/qfunctions/channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ CEED_QFUNCTION(ICsChannel)(void *ctx, CeedInt Q,
const CeedScalar x[] = {X[0][i], X[1][i], X[2][i]};
State s = Exact_Channel(3, 0., x, 5, ctx);
CeedScalar q[5] = {0};
if (context->newtonian_ctx.is_primitive)
if (context->newtonian_ctx.use_primitive)
UnpackState_Y(s.Y, q);
else
UnpackState_U(s.U, q);
Expand Down
2 changes: 1 addition & 1 deletion examples/fluids/qfunctions/densitycurrent.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ CEED_QFUNCTION(ICsDC)(void *ctx, CeedInt Q,
const CeedScalar x[] = {X[0][i], X[1][i], X[2][i]};
State s = Exact_DC(3, 0., x, 5, ctx);
CeedScalar q[5] = {0};
if (context->newtonian_ctx.is_primitive)
if (context->newtonian_ctx.use_primitive)
UnpackState_Y(s.Y, q);
else
UnpackState_U(s.U, q);
Expand Down
Loading

0 comments on commit 12f40bf

Please sign in to comment.