Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Manifold EoS in RK64 Reactor #513

Merged
merged 23 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
235e8cf
updates to reactions for manifold in RK64
baperry2 Jun 15, 2024
d3e2b87
fail if trying to use manifold EOS and unsupported reactors
baperry2 Jul 19, 2024
bb1c21e
fixes for ReactornNull with eosparm
baperry2 Jul 19, 2024
2d7a293
Merge branch 'development' into reactor-manifold
baperry2 Jul 25, 2024
873b452
Merge branch 'development' into reactor-manifold
baperry2 Sep 12, 2024
54129d6
fix cgs vs mks error in ignition python script
baperry2 Sep 12, 2024
35ae03c
fix species naming in null mechanism
baperry2 Sep 13, 2024
2472810
fix pointer in unused RTY2E manifold EOS function
baperry2 Sep 13, 2024
65ae447
don't do energy stuff for manifold EOS reactions
baperry2 Sep 13, 2024
8583a85
allow ignitionDelay case to run with manifold model
baperry2 Sep 13, 2024
4ee4c2e
allow slightly more uncertainty for ignition delay so manifold passes
baperry2 Sep 13, 2024
79cd988
ignition delay inputs for manifold
baperry2 Sep 13, 2024
10b7dff
run manifold reactor in CI
baperry2 Sep 13, 2024
8900aaa
add chemtable for ignition
baperry2 Sep 13, 2024
b3ff86c
fix CI for manifold integration
baperry2 Sep 13, 2024
0c86cb5
fix typo
baperry2 Sep 13, 2024
3658850
another CI fix
baperry2 Sep 13, 2024
809d138
update README
baperry2 Sep 13, 2024
ea128d0
deallocate eosparms in tests
baperry2 Sep 13, 2024
d8063e0
fux typo in README
baperry2 Sep 20, 2024
a3025ca
Merge branch 'development' into reactor-manifold
baperry2 Sep 23, 2024
9fea10d
fix pressure unit conversion in writeResult
baperry2 Sep 23, 2024
4e116e2
add user arguments for check_igndelay function
baperry2 Sep 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,15 @@ jobs:
pip install numpy
ccache -z
make -j ${{env.NPROCS}} Eos_Model=Fuego Chemistry_Model=dodecane_lu TINY_PROFILE=TRUE USE_CCACHE=TRUE ${{matrix.amrex_build_args}}
bash exec_ignDelay.sh
bash exec_ignDelay.sh firstpass
python check_ignDelay.py
if [ $? -ne 0 ]; then exit 1; fi; \
rm log PPreaction.txt inputs/inputs.0d_refine
make realclean
make -j ${{env.NPROCS}} Eos_Model=Manifold Transport_Model=Manifold Manifold_Dim=1 Chemistry_Model=Null TINY_PROFILE=TRUE USE_CCACHE=TRUE ${{matrix.amrex_build_args}}
bash exec_ignDelay.sh manifold
python check_ignDelay.py 0.0766 10
if [ $? -ne 0 ]; then exit 1; fi; \
fi;
make realclean
- name: Ignition delay ccache report
Expand Down
4 changes: 2 additions & 2 deletions Mechanisms/Null/mechanism.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ void
CKSYME_STR(amrex::Vector<std::string>& ename)
{
ename.resize(1);
ename[0] = "XO";
ename[0] = "X0";
}
void
CKSYMS_STR(amrex::Vector<std::string>& kname)
{
kname.resize(NUM_SPECIES);
for (int i = 0; i < NUM_SPECIES; ++i) {
kname[0] = "X" + std::to_string(i);
kname[i] = "X" + std::to_string(i);
}
}

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ PelePhysics contains C++ source code for the following physics and other modules
* *Reactions*: Routines for substepped integration of stiff chemical systems, including with CVODE
* *Spray*: Lagrangian spray droplet library, formerly part of [PeleMP](https://github.com/AMReX-Combustion/PeleMP)
* *Soot*: An implementation of the Hybrid Method of Moments soot model, formerly part of [PeleMP](https://github.com/AMReX-Combustion/PeleMP)
* *Radiation*: Raidative heat transfer model based on the spherical harmonics method, formerly [PeleRad](https://github.com/AMReX-Combustion/PeleRad)
* *Radiation*: Radiative heat transfer model based on the spherical harmonics method, formerly [PeleRad](https://github.com/AMReX-Combustion/PeleRad)
* *Utility*: Several handy modules for data management across other Pele codes

Additionally, PelePhysics contains a variety of stand-alone tools to aid in Pele simulation workflows, found in the `Support` directory.
Expand Down
2 changes: 1 addition & 1 deletion Source/Eos/Manifold.H
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ struct Manifold
const amrex::Real /*R*/,
const amrex::Real /*T*/,
const amrex::Real* /*Y[]*/,
amrex::Real* /*E*/)
amrex::Real /*E*/)
{
amrex::Error("RTY2E does not have significance for Manifold EOS");
}
Expand Down
17 changes: 17 additions & 0 deletions Source/Reactions/ReactorBase.H
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,28 @@ public:

void set_typ_vals_ode(const std::vector<amrex::Real>& ExtTypVals);

// Manifold EOS needs an eosparm - right now that is only propagated through
// the RK64 reactor
virtual void set_eos_parm(
const pele::physics::eos::EosParm<pele::physics::PhysicsType::eos_type>*
eosparm)
{
auto eos = pele::physics::PhysicsType::eos(eosparm);
if (eos.identifier() == "Manifold") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could replace all this with AMREX_ALWAYS_ASSERT_WITH_MESSAGE

amrex::Abort(
"Manifold EOS only supported with ReactorRK64 and ReactorNull for now");
} else {
m_eosparm = eosparm;
}
}

~ReactorBase() override = default;

protected:
int verbose{0};
amrex::GpuArray<amrex::Real, NUM_SPECIES + 1> m_typ_vals = {0.0};
const pele::physics::eos::EosParm<pele::physics::PhysicsType::eos_type>*
m_eosparm;
};
} // namespace pele::physics::reactions
#endif
7 changes: 7 additions & 0 deletions Source/Reactions/ReactorNull.H
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ public:
rhoE, frcEExt, FC_in, y_vect, vect_energy, FCunt, dt);
}

void set_eos_parm(
const pele::physics::eos::EosParm<pele::physics::PhysicsType::eos_type>*
eosparm) override
{
m_eosparm = eosparm;
}

private:
utils::FlattenOps<Ordering> flatten_ops;
int m_reactor_type{0};
Expand Down
3 changes: 2 additions & 1 deletion Source/Reactions/ReactorNull.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ ReactorNull::react(
#endif

int captured_reactor_type = m_reactor_type;
const auto* leosparm = m_eosparm;

ParallelFor(box, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
amrex::Real renergy_loc =
Expand All @@ -60,7 +61,7 @@ ReactorNull::react(
}
amrex::Real energy_loc = renergy_loc / rho_loc;
amrex::Real T_loc = T_in(i, j, k, 0);
auto eos = pele::physics::PhysicsType::eos();
auto eos = pele::physics::PhysicsType::eos(leosparm);
if (captured_reactor_type == ReactorTypes::e_reactor_type) {
eos.REY2T(rho_loc, energy_loc, Y_loc, T_loc);
} else if (captured_reactor_type == ReactorTypes::h_reactor_type) {
Expand Down
7 changes: 7 additions & 0 deletions Source/Reactions/ReactorRK64.H
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,13 @@ public:
rhoE, frcEExt, FC_in, y_vect, vect_energy, FCunt, dt);
}

void set_eos_parm(
const pele::physics::eos::EosParm<pele::physics::PhysicsType::eos_type>*
eosparm) override
{
m_eosparm = eosparm;
}

private:
amrex::Real absTol{1e-10};
int rk64_nsubsteps_guess{10};
Expand Down
29 changes: 12 additions & 17 deletions Source/Reactions/ReactorRK64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ ReactorRK64::react(
const int captured_nsubsteps_min = rk64_nsubsteps_min;
const int captured_nsubsteps_max = rk64_nsubsteps_max;
const amrex::Real captured_abstol = absTol;
const auto* leosparm = m_eosparm;
RK64Params rkp;

amrex::Gpu::DeviceVector<int> v_nsteps(ncells, 0);
Expand Down Expand Up @@ -103,7 +104,7 @@ ReactorRK64::react(
for (int stage = 0; stage < rkp.nstages_rk64; stage++) {
utils::fKernelSpec<Ordering>(
0, 1, current_time - time_init, captured_reactor_type, soln_reg, ydot,
rhoe_init, rhoesrc_ext, rYsrc_ext);
rhoe_init, rhoesrc_ext, rYsrc_ext, leosparm);

for (int sp = 0; sp < neq; sp++) {
error_reg[sp] += rkp.err_rk64[stage] * dt_rk * ydot[sp];
Expand Down Expand Up @@ -131,9 +132,9 @@ ReactorRK64::react(
rkp.betaerr_rk64 * pow((captured_abstol / max_err), rkp.exp2_rk64);
dt_rk = amrex::max<amrex::Real>(dt_rk_min, dt_rk * change_factor);
}
// Don't overstep the integration time
dt_rk = amrex::min<amrex::Real>(dt_rk, time_out - current_time);
}
// Don't overstep the integration time
dt_rk = amrex::min<amrex::Real>(dt_rk, time_out - current_time);
d_nsteps[icell] = nsteps;
// copy data back
for (int sp = 0; sp < neq; sp++) {
Expand Down Expand Up @@ -192,6 +193,7 @@ ReactorRK64::react(
const int captured_nsubsteps_min = rk64_nsubsteps_min;
const int captured_nsubsteps_max = rk64_nsubsteps_max;
const amrex::Real captured_abstol = absTol;
const auto* leosparm = m_eosparm;
RK64Params rkp;

int ncells = static_cast<int>(box.numPts());
Expand All @@ -210,21 +212,18 @@ ReactorRK64::react(
amrex::Real current_time = time_init;
const int neq = (NUM_SPECIES + 1);

amrex::Real rho = 0.0;
auto eos = pele::physics::PhysicsType::eos(leosparm);
for (int sp = 0; sp < NUM_SPECIES; sp++) {
soln_reg[sp] = rY_in(i, j, k, sp);
carryover_reg[sp] = soln_reg[sp];
rho += rY_in(i, j, k, sp);
}
amrex::Real rho_inv = 1.0 / rho;
amrex::Real rho = 0.0, rho_inv = 0.0;
amrex::Real mass_frac[NUM_SPECIES] = {0.0};
for (int sp = 0; sp < NUM_SPECIES; sp++) {
mass_frac[sp] = rY_in(i, j, k, sp) * rho_inv;
}
eos.RY2RRinvY(soln_reg, rho, rho_inv, mass_frac);

amrex::Real temp = T_in(i, j, k, 0);

amrex::Real Enrg_loc = rEner_in(i, j, k, 0) * rho_inv;
auto eos = pele::physics::PhysicsType::eos();
if (captured_reactor_type == ReactorTypes::e_reactor_type) {
eos.REY2T(rho, Enrg_loc, mass_frac, temp);
} else if (captured_reactor_type == ReactorTypes::h_reactor_type) {
Expand Down Expand Up @@ -255,7 +254,7 @@ ReactorRK64::react(
for (int stage = 0; stage < rkp.nstages_rk64; stage++) {
utils::fKernelSpec<Ordering>(
0, 1, current_time - time_init, captured_reactor_type, soln_reg, ydot,
rhoe_init, rhoesrc_ext, rYsrc_ext);
rhoe_init, rhoesrc_ext, rYsrc_ext, leosparm);

for (int sp = 0; sp < neq; sp++) {
error_reg[sp] += rkp.err_rk64[stage] * dt_rk * ydot[sp];
Expand Down Expand Up @@ -290,15 +289,11 @@ ReactorRK64::react(
// copy data back
int icell = (k - lo.z) * len.x * len.y + (j - lo.y) * len.x + (i - lo.x);
d_nsteps[icell] = nsteps;
rho = 0.0;
for (int sp = 0; sp < NUM_SPECIES; sp++) {
rY_in(i, j, k, sp) = soln_reg[sp];
rho += rY_in(i, j, k, sp);
}
rho_inv = 1.0 / rho;
for (int sp = 0; sp < NUM_SPECIES; sp++) {
mass_frac[sp] = rY_in(i, j, k, sp) * rho_inv;
}
eos.RY2RRinvY(soln_reg, rho, rho_inv, mass_frac);

temp = soln_reg[NUM_SPECIES];
rEner_in(i, j, k, 0) = rhoe_init[0] + dt_react * rhoesrc_ext[0];
Enrg_loc = rEner_in(i, j, k, 0) * rho_inv;
Expand Down
23 changes: 11 additions & 12 deletions Source/Reactions/ReactorUtils.H
Original file line number Diff line number Diff line change
Expand Up @@ -369,29 +369,27 @@ fKernelSpec(
amrex::Real* ydot_d, // NOLINT(readability-non-const-parameter)
const amrex::Real* rhoe_init,
const amrex::Real* rhoesrc_ext,
const amrex::Real* rYs)
const amrex::Real* rYs,
const pele::physics::eos::EosParm<pele::physics::PhysicsType::eos_type>*
eosparm = nullptr)
{
amrex::Real rho_pt = 0.0;
amrex::GpuArray<amrex::Real, NUM_SPECIES> massfrac = {0.0};
auto eos = pele::physics::PhysicsType::eos(eosparm);
amrex::Real rho_pt = 0.0, rho_pt_inv = 0.0;
amrex::GpuArray<amrex::Real, NUM_SPECIES> massfrac = {0.0}, massdens = {0.0};
for (int n = 0; n < NUM_SPECIES; n++) {
massfrac[n] = yvec_d[vec_index<OrderType>(n, icell, ncells)];
rho_pt += massfrac[n];
}
const amrex::Real rho_pt_inv = 1.0 / rho_pt;

for (int n = 0; n < NUM_SPECIES; n++) {
massfrac[n] *= rho_pt_inv;
massdens[n] = yvec_d[vec_index<OrderType>(n, icell, ncells)];
}
eos.RY2RRinvY(massdens.data(), rho_pt, rho_pt_inv, massfrac.data());

const amrex::Real nrg_pt =
(rhoe_init[icell] + rhoesrc_ext[icell] * dt_save) * rho_pt_inv;

amrex::Real temp_pt =
yvec_d[vec_index<OrderType>(NUM_SPECIES, icell, ncells)];

amrex::Real Cv_pt = 0.0;
amrex::Real Cv_pt = 1.0;
amrex::GpuArray<amrex::Real, NUM_SPECIES> ei_pt = {0.0};
auto eos = pele::physics::PhysicsType::eos();
#ifndef USE_MANIFOLD_EOS
if (reactor_type == ReactorTypes::e_reactor_type) {
eos.REY2T(rho_pt, nrg_pt, massfrac.arr, temp_pt);
eos.RTY2Ei(rho_pt, temp_pt, massfrac.arr, ei_pt.arr);
Expand All @@ -403,6 +401,7 @@ fKernelSpec(
} else {
amrex::Abort("Wrong reactor type. Choose between 1 (e) or 2 (h).");
}
#endif

amrex::GpuArray<amrex::Real, NUM_SPECIES> cdots_pt = {0.0};
eos.RTY2WDOT(rho_pt, temp_pt, massfrac.arr, cdots_pt.arr);
Expand Down
Binary file added Support/CMLM/autoignition.ctb
Binary file not shown.
2 changes: 2 additions & 0 deletions Testing/Exec/EosEval/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ main(int argc, char* argv[])
amrex::WriteSingleLevelPlotfile(
outfile, VarPlt, plt_VarsName, geom, 0.0, 0);
}

eos_parms.deallocate();
}

amrex::Finalize();
Expand Down
20 changes: 13 additions & 7 deletions Testing/Exec/IgnitionDelay/GPU_misc.H
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ initialize_data(
amrex::Real t0,
amrex::Real equiv_ratio,
amrex::Real p,
amrex::GeometryData const& geomdata) noexcept
amrex::GeometryData const& geomdata,
const pele::physics::eos::EosParm<pele::physics::PhysicsType::eos_type>*
eosparm) noexcept
{
const amrex::Real* plo = geomdata.ProbLo();
const amrex::Real* phi = geomdata.ProbHi();
Expand All @@ -50,26 +52,30 @@ initialize_data(
P[n] = L[n] / 4.0;
}
// Y
auto eos = pele::physics::PhysicsType::eos(eosparm);

#ifndef USE_MANIFOLD_EOS
for (int n = 0; n < NUM_SPECIES; n++) {
X[n] = 0.0;
}
// X[O2_ID] = 0.7;
// X[fuel_id] = 0.3;
// Assumes n-Dodecane
X[O2_ID] = 1.0 / (equiv_ratio / 18.5 + 1 + 0.79 / 0.21);
X[N2_ID] = 0.79 * X[O2_ID] / 0.21;
X[fuel_id] = 1.0 - X[O2_ID] - X[N2_ID];

auto eos = pele::physics::PhysicsType::eos();

eos.X2Y(&X[0], &Y[0]);
#else
Y[0] = 0.0; // Progress variable
Y[1] = 1.0; // Density
#endif

// T
temp = t0;
// temp = Temp_lo + (Temp_hi-Temp_lo)*y/L[1] + dTemp *
// std::sin(2.0*pi*y/P[1]);
if (energy_type == 1) {
// get rho and E
eos.PYT2RE(pressure, &Y[0], temp, density, energy);
eos.PYT2R(pressure, &Y[0], temp, density);
eos.RTY2E(density, temp, &Y[0], energy);
} else {
// get rho and H
eos.PYT2R(pressure, &Y[0], temp, density);
Expand Down
2 changes: 1 addition & 1 deletion Testing/Exec/IgnitionDelay/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ Ignition delay will call the Pele executable find in this directory. If you have

3. Adjust your parameters in `inputs/inputs.0d_firstpass`

4. Execute `bash exec_ignDelay.sh`. The result is outputted in `log`.
4. Execute `bash exec_ignDelay.sh firstpass`. The result is outputted in `log`.
10 changes: 9 additions & 1 deletion Testing/Exec/IgnitionDelay/check_ignDelay.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,19 @@ def readResult(filename):


if __name__=="__main__":
# Two arguments: intended correct value and uncertainty factor
if len(sys.argv) > 1:
correct_value = float(sys.argv[1])
uncertainty_factor = float(sys.argv[2])
else:
correct_value = 0.0763
uncertainty_factor = 10.0

# Read ignition delay output
tIgn,uncertainty = readResult('log')

# Compare to theoretical value
if abs(tIgn-0.0763)>10*uncertainty:
if abs(tIgn-correct_value)>uncertainty_factor*uncertainty:
sys.exit(1)
else:
sys.exit(0)
Loading
Loading