Skip to content

Commit

Permalink
Merge pull request CEED#1550 from CEED/jrwrigh/consistent_fluids_qf
Browse files Browse the repository at this point in the history
refactor(fluids): Make QF comments consistent
  • Loading branch information
jrwrigh authored Apr 2, 2024
2 parents 780fa44 + f0b0115 commit a035cd8
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 156 deletions.
16 changes: 4 additions & 12 deletions examples/fluids/qfunctions/bc_freestream.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,20 +220,16 @@ CEED_QFUNCTION(RiemannOutflow_Prim)(void *ctx, CeedInt Q, const CeedScalar *cons
// *****************************************************************************
CEED_QFUNCTION_HELPER int RiemannOutflow_Jacobian(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out,
StateVariable state_var) {
// Inputs
const CeedScalar(*dq)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[0];
const CeedScalar(*Grad_dq) = in[1];
const CeedScalar(*q_data_sur) = in[2];
const CeedScalar(*jac_data_sur) = in[4];

// Outputs
CeedScalar(*v)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0];
CeedScalar(*v)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0];

const OutflowContext outflow = (OutflowContext)ctx;
const NewtonianIdealGasContext gas = &outflow->gas;
const bool is_implicit = gas->is_implicit;

// Quadrature Point Loop
CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) {
CeedScalar wdetJb, dXdx[2][3], norm[3];
QdataBoundaryUnpack_3D(Q, i, q_data_sur, &wdetJb, dXdx, norm);
Expand Down Expand Up @@ -279,7 +275,7 @@ CEED_QFUNCTION_HELPER int RiemannOutflow_Jacobian(void *ctx, CeedInt Q, const Ce
FluxTotal_RiemannBoundary(dF_inviscid_normal, dstress, dFe, norm, dFlux);

for (int j = 0; j < 5; j++) v[j][i] = -wdetJb * dFlux[j];
} // End Quadrature Point Loop
}
return 0;
}

Expand Down Expand Up @@ -357,20 +353,16 @@ CEED_QFUNCTION(PressureOutflow_Prim)(void *ctx, CeedInt Q, const CeedScalar *con
// *****************************************************************************
CEED_QFUNCTION_HELPER int PressureOutflow_Jacobian(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out,
StateVariable state_var) {
// Inputs
const CeedScalar(*dq)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[0];
const CeedScalar(*Grad_dq) = in[1];
const CeedScalar(*q_data_sur) = in[2];
const CeedScalar(*jac_data_sur) = in[4];

// Outputs
CeedScalar(*v)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0];
CeedScalar(*v)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0];

const OutflowContext outflow = (OutflowContext)ctx;
const NewtonianIdealGasContext gas = &outflow->gas;
const bool is_implicit = gas->is_implicit;

// Quadrature Point Loop
CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) {
CeedScalar wdetJb, dXdx[2][3], norm[3];
QdataBoundaryUnpack_3D(Q, i, q_data_sur, &wdetJb, dXdx, norm);
Expand Down Expand Up @@ -403,7 +395,7 @@ CEED_QFUNCTION_HELPER int PressureOutflow_Jacobian(void *ctx, CeedInt Q, const C
FluxTotal_Boundary(dF_inviscid, dstress, dFe, norm, dFlux);

for (int j = 0; j < 5; j++) v[j][i] = -wdetJb * dFlux[j];
} // End Quadrature Point Loop
}
return 0;
}

Expand Down
10 changes: 2 additions & 8 deletions examples/fluids/qfunctions/channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,11 @@ CEED_QFUNCTION_HELPER State Exact_Channel(CeedInt dim, CeedScalar time, const Ce
// This QFunction set the initial condition
// *****************************************************************************
CEED_QFUNCTION(ICsChannel)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
// Inputs
const CeedScalar(*X)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[0];
CeedScalar(*q0)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0];

// Outputs
CeedScalar(*q0)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0];

// Context
const ChannelContext context = (ChannelContext)ctx;

// Quadrature Point Loop
CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) {
const CeedScalar x[] = {X[0][i], X[1][i], X[2][i]};
State s = Exact_Channel(3, 0., x, 5, ctx);
Expand All @@ -85,8 +80,7 @@ CEED_QFUNCTION(ICsChannel)(void *ctx, CeedInt Q, const CeedScalar *const *in, Ce
}

for (CeedInt j = 0; j < 5; j++) q0[j][i] = q[j];

} // End of Quadrature Point Loop
}
return 0;
}

Expand Down
11 changes: 2 additions & 9 deletions examples/fluids/qfunctions/densitycurrent.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,16 +130,11 @@ CEED_QFUNCTION_HELPER State Exact_DC(CeedInt dim, CeedScalar time, const CeedSca
// This QFunction sets the initial conditions for density current
// *****************************************************************************
CEED_QFUNCTION(ICsDC)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
// Inputs
const CeedScalar(*X)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[0];
CeedScalar(*q0)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0];

// Outputs
CeedScalar(*q0)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0];

// Context
const DensityCurrentContext context = (DensityCurrentContext)ctx;

// Quadrature Point Loop
CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) {
const CeedScalar x[] = {X[0][i], X[1][i], X[2][i]};
State s = Exact_DC(3, 0., x, 5, ctx);
Expand All @@ -154,8 +149,6 @@ CEED_QFUNCTION(ICsDC)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedSca
}

for (CeedInt j = 0; j < 5; j++) q0[j][i] = q[j];

} // End of Quadrature Point Loop

}
return 0;
}
56 changes: 15 additions & 41 deletions examples/fluids/qfunctions/eulervortex.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ CEED_QFUNCTION_HELPER int Exact_Euler(CeedInt dim, CeedScalar time, const CeedSc
q[4] = rho * (cv * T + (u[0] * u[0] + u[1] * u[1]) / 2.);
break;
}
// Return
return 0;
}

Expand Down Expand Up @@ -225,24 +224,18 @@ CEED_QFUNCTION_HELPER void Tau_spatial(CeedScalar Tau_x[3], const CeedScalar dXd
// This QFunction sets the initial conditions for Euler traveling vortex
// *****************************************************************************
CEED_QFUNCTION(ICsEuler)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
// Inputs
const CeedScalar(*X)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[0];
CeedScalar(*q0)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0];

// Outputs
CeedScalar(*q0)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0];
const EulerContext context = (EulerContext)ctx;
const EulerContext context = (EulerContext)ctx;

// Quadrature Point Loop
CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) {
const CeedScalar x[] = {X[0][i], X[1][i], X[2][i]};
CeedScalar q[5] = {0.};

Exact_Euler(3, context->curr_time, x, 5, q, ctx);

for (CeedInt j = 0; j < 5; j++) q0[j][i] = q[j];
} // End of Quadrature Point Loop

// Return
}
return 0;
}

Expand Down Expand Up @@ -271,20 +264,16 @@ CEED_QFUNCTION(ICsEuler)(void *ctx, CeedInt Q, const CeedScalar *const *in, Ceed
// gamma = cp / cv, Specific heat ratio
// *****************************************************************************
CEED_QFUNCTION(Euler)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
// Inputs
const CeedScalar(*q)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[0];
const CeedScalar(*dq)[5][CEED_Q_VLA] = (const CeedScalar(*)[5][CEED_Q_VLA])in[1];
const CeedScalar(*q_data) = in[2];

// Outputs
CeedScalar(*v)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0];
CeedScalar(*dv)[5][CEED_Q_VLA] = (CeedScalar(*)[5][CEED_Q_VLA])out[1];
CeedScalar(*v)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0];
CeedScalar(*dv)[5][CEED_Q_VLA] = (CeedScalar(*)[5][CEED_Q_VLA])out[1];

EulerContext context = (EulerContext)ctx;
const CeedScalar c_tau = context->c_tau;
const CeedScalar gamma = 1.4;

// Quadrature Point Loop
CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) {
// Setup
// -- Interp in
Expand Down Expand Up @@ -387,34 +376,27 @@ CEED_QFUNCTION(Euler)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedSca
case 2: // SUPG is not implemented for explicit scheme
break;
}

} // End Quadrature Point Loop

// Return
}
return 0;
}

// *****************************************************************************
// This QFunction implements the Euler equations with (mentioned above) with implicit time stepping method
// *****************************************************************************
CEED_QFUNCTION(IFunction_Euler)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
// Inputs
const CeedScalar(*q)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[0];
const CeedScalar(*dq)[5][CEED_Q_VLA] = (const CeedScalar(*)[5][CEED_Q_VLA])in[1];
const CeedScalar(*q_dot)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[2];
const CeedScalar(*q_data) = in[3];

// Outputs
CeedScalar(*v)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0];
CeedScalar(*dv)[5][CEED_Q_VLA] = (CeedScalar(*)[5][CEED_Q_VLA])out[1];
CeedScalar *jac_data = out[2];
CeedScalar(*v)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0];
CeedScalar(*dv)[5][CEED_Q_VLA] = (CeedScalar(*)[5][CEED_Q_VLA])out[1];
CeedScalar *jac_data = out[2];

EulerContext context = (EulerContext)ctx;
const CeedScalar c_tau = context->c_tau;
const CeedScalar gamma = 1.4;
const CeedScalar zeros[14] = {0.};

// Quadrature Point Loop
CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) {
// Setup
// -- Interp in
Expand Down Expand Up @@ -532,9 +514,7 @@ CEED_QFUNCTION(IFunction_Euler)(void *ctx, CeedInt Q, const CeedScalar *const *i
break;
}
StoredValuesPack(Q, i, 0, 14, zeros, jac_data);
} // End Quadrature Point Loop

// Return
}
return 0;
}
// *****************************************************************************
Expand All @@ -543,10 +523,9 @@ CEED_QFUNCTION(IFunction_Euler)(void *ctx, CeedInt Q, const CeedScalar *const *i
// Prescribed T_inlet and P_inlet are converted to conservative variables and applied weakly.
// *****************************************************************************
CEED_QFUNCTION(TravelingVortex_Inflow)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
// Inputs
const CeedScalar(*q_data_sur) = in[2];
// Outputs
CeedScalar(*v)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0];
CeedScalar(*v)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0];

EulerContext context = (EulerContext)ctx;
const int euler_test = context->euler_test;
const bool is_implicit = context->implicit;
Expand All @@ -565,7 +544,6 @@ CEED_QFUNCTION(TravelingVortex_Inflow)(void *ctx, CeedInt Q, const CeedScalar *c
if (euler_test == 1 || euler_test == 2) T_inlet = P_inlet = .4;
else T_inlet = P_inlet = 1.;

// Quadrature Point Loop
CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) {
CeedScalar wdetJb, norm[3];
QdataBoundaryUnpack_3D(Q, i, q_data_sur, &wdetJb, NULL, norm);
Expand Down Expand Up @@ -595,8 +573,7 @@ CEED_QFUNCTION(TravelingVortex_Inflow)(void *ctx, CeedInt Q, const CeedScalar *c
// -- Total Energy Density
v[4][i] -= wdetJb * face_normal * (E_inlet + P_inlet);
}

} // End Quadrature Point Loop
}
return 0;
}

Expand All @@ -607,19 +584,16 @@ CEED_QFUNCTION(TravelingVortex_Inflow)(void *ctx, CeedInt Q, const CeedScalar *c
// The validity of the weak form of the governing equations is extended to the outflow.
// *****************************************************************************
CEED_QFUNCTION(Euler_Outflow)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
// Inputs
const CeedScalar(*q)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[0];
const CeedScalar(*q_data_sur) = in[2];
CeedScalar(*v)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0];

// Outputs
CeedScalar(*v)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0];
EulerContext context = (EulerContext)ctx;
const bool is_implicit = context->implicit;
CeedScalar *mean_velocity = context->mean_velocity;

const CeedScalar gamma = 1.4;

// Quadrature Point Loop
CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) {
// Setup
// -- Interp in
Expand Down Expand Up @@ -652,6 +626,6 @@ CEED_QFUNCTION(Euler_Outflow)(void *ctx, CeedInt Q, const CeedScalar *const *in,
// -- Total Energy Density
v[4][i] -= wdetJb * u_normal * (E + P);
}
} // End Quadrature Point Loop
}
return 0;
}
5 changes: 1 addition & 4 deletions examples/fluids/qfunctions/mass.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,9 @@
//
// *****************************************************************************
CEED_QFUNCTION_HELPER int Mass_N(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out, const CeedInt N) {
// Inputs
const CeedScalar(*u)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[0];
const CeedScalar(*q_data) = in[1];

// Outputs
CeedScalar(*v)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0];
CeedScalar(*v)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0];

CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) {
CeedPragmaSIMD for (CeedInt j = 0; j < N; j++) { v[j][i] = q_data[i] * u[j][i]; }
Expand Down
Loading

0 comments on commit a035cd8

Please sign in to comment.