Skip to content

Commit

Permalink
Make EOS functions templates to allow for CellData as an argument (AM…
Browse files Browse the repository at this point in the history
…ReX-Combustion#536)

* template for celldata in EOS

* static asserts in templates

* templating for RY2 functions for all EOS

* Fix clang-tidy (AMReX-Combustion#535)

* fix unused variable

* free shared ptr for manfunc parm

---------

Co-authored-by: Marc T. Henry de Frahan <[email protected]>
  • Loading branch information
baperry2 and marchdf authored Nov 5, 2024
1 parent 7161406 commit 0674560
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 33 deletions.
1 change: 1 addition & 0 deletions Source/Eos/EosParams.H
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ struct InitParm<eos::EosParm<eos::Manifold>>
static void host_deallocate(PeleParams<eos::EosParm<eos::Manifold>>* parm_in)
{
parm_in->m_host_only_parm.manfunc_par->deallocate();
parm_in->m_host_only_parm.manfunc_par = nullptr;
}
};
#endif
Expand Down
22 changes: 14 additions & 8 deletions Source/Eos/Fuego.H
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,26 @@ struct Fuego

static std::string identifier() { return "Fuego"; }

AMREX_GPU_HOST_DEVICE
AMREX_FORCE_INLINE
static void RY2R(const amrex::Real RY[], amrex::Real& R)
// ReallArrayLike can be anything with an [] operator that returns
// amrex::Real&
template <typename RealArrayLike>
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE static void
RY2R(const RealArrayLike& RY, amrex::Real& R, int first = 0)
{
R = 0.0;
for (int i = 0; i < NUM_SPECIES; i++) {
R += RY[i];
R += RY[first + i];
}
}

AMREX_GPU_HOST_DEVICE
AMREX_FORCE_INLINE
static void RY2RRinvY(
const amrex::Real RY[], amrex::Real& R, amrex::Real& Rinv, amrex::Real Y[])
// ReallArrayLike can be anything with an [] operator that returns
// amrex::Real&
template <typename RealArrayLike1, typename RealArrayLike2>
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE static void RY2RRinvY(
const RealArrayLike1& RY,
amrex::Real& R,
amrex::Real& Rinv,
RealArrayLike2&& Y)
{
RY2R(RY, R);
Rinv = 1.0 / R;
Expand Down
32 changes: 23 additions & 9 deletions Source/Eos/GammaLaw.H
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,32 @@ struct GammaLaw

static std::string identifier() { return "GammaLaw"; }

AMREX_GPU_HOST_DEVICE
AMREX_FORCE_INLINE
static void RY2R(const amrex::Real RY[], amrex::Real& R) { R = RY[0]; }
// ReallArrayLike can be anything with an [] operator that returns
// amrex::Real&
template <typename RealArrayLike>
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE static void
RY2R(const RealArrayLike& RY, amrex::Real& R, int first = 0)
{
R = 0.0;
for (int i = 0; i < NUM_SPECIES; i++) {
R += RY[first + i];
}
}

AMREX_GPU_HOST_DEVICE
AMREX_FORCE_INLINE
static void RY2RRinvY(
const amrex::Real RY[], amrex::Real& R, amrex::Real& Rinv, amrex::Real Y[])
// ReallArrayLike can be anything with an [] operator that returns
// amrex::Real&
template <typename RealArrayLike1, typename RealArrayLike2>
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE static void RY2RRinvY(
const RealArrayLike1& RY,
amrex::Real& R,
amrex::Real& Rinv,
RealArrayLike2&& Y)
{
R = RY[0];
RY2R(RY, R);
Rinv = 1.0 / R;
Y[0] = 1.0;
for (int i = 0; i < NUM_SPECIES; i++) {
Y[i] = RY[i] * Rinv;
}
}

AMREX_GPU_HOST_DEVICE
Expand Down
22 changes: 14 additions & 8 deletions Source/Eos/Manifold.H
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,23 @@ struct Manifold

static std::string identifier() { return "Manifold"; }

AMREX_GPU_HOST_DEVICE
AMREX_FORCE_INLINE
static void RY2R(const amrex::Real RY[], amrex::Real& R)
// ReallArrayLike can be anything with an [] operator that returns
// amrex::Real&
template <typename RealArrayLike>
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE static void
RY2R(const RealArrayLike& RY, amrex::Real& R, int first = 0)
{
R = RY[NUM_SPECIES - 1];
R = RY[first + NUM_SPECIES - 1];
}

AMREX_GPU_HOST_DEVICE
AMREX_FORCE_INLINE
static void RY2RRinvY(
const amrex::Real RY[], amrex::Real& R, amrex::Real& Rinv, amrex::Real Y[])
// ReallArrayLike can be anything with an [] operator that returns
// amrex::Real&
template <typename RealArrayLike1, typename RealArrayLike2>
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE static void RY2RRinvY(
const RealArrayLike1& RY,
amrex::Real& R,
amrex::Real& Rinv,
RealArrayLike2&& Y)
{
RY2R(RY, R);
Rinv = 1.0 / R;
Expand Down
22 changes: 14 additions & 8 deletions Source/Eos/SRK.H
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,26 @@ struct SRK

static std::string identifier() { return "SRK"; }

AMREX_GPU_HOST_DEVICE
AMREX_FORCE_INLINE
static void RY2R(const amrex::Real RY[], amrex::Real& R)
// ReallArrayLike can be anything with an [] operator that returns
// amrex::Real&
template <typename RealArrayLike>
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE static void
RY2R(const RealArrayLike& RY, amrex::Real& R, int first = 0)
{
R = 0.0;
for (int i = 0; i < NUM_SPECIES; i++) {
R += RY[i];
R += RY[first + i];
}
}

AMREX_GPU_HOST_DEVICE
AMREX_FORCE_INLINE
static void RY2RRinvY(
const amrex::Real RY[], amrex::Real& R, amrex::Real& Rinv, amrex::Real Y[])
// ReallArrayLike can be anything with an [] operator that returns
// amrex::Real&
template <typename RealArrayLike1, typename RealArrayLike2>
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE static void RY2RRinvY(
const RealArrayLike1& RY,
amrex::Real& R,
amrex::Real& Rinv,
RealArrayLike2&& Y)
{
RY2R(RY, R);
Rinv = 1.0 / R;
Expand Down
1 change: 1 addition & 0 deletions Source/Transport/TransportParams.H
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ struct InitParm<transport::TransParm<EOSType, transport::ManifoldTransport>>
if (!parm_in->m_host_only_parm.use_eos_manifold) {
parm_in->m_host_only_parm.manfunc_par->deallocate();
}
parm_in->m_host_only_parm.manfunc_par = nullptr;
}
};

Expand Down

0 comments on commit 0674560

Please sign in to comment.