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

Dholladay00/scaleshift fortran #15

Merged
merged 5 commits into from
Jun 10, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
14 changes: 12 additions & 2 deletions eos/eos.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1489,14 +1489,23 @@ class EOSPAC {
using EOS = Variant<
IdealGas, Gruneisen, JWL, DavisReactants, DavisProducts,
ScaledEOS<IdealGas>, ShiftedEOS<IdealGas>, ShiftedEOS<ScaledEOS<IdealGas>>,
RelativisticEOS<IdealGas>
ScaledEOS<ShiftedEOS<IdealGas>>, RelativisticEOS<IdealGas>,
ScaledEOS<Gruneisen>, ShiftedEOS<Gruneisen>,
ScaledEOS<ShiftedEOS<Gruneisen>>,
ScaledEOS<JWL>, ShiftedEOS<JWL>, ScaledEOS<ShiftedEOS<JWL>>,
ScaledEOS<DavisReactants>, ShiftedEOS<DavisReactants>,
ScaledEOS<ShiftedEOS<DavisReactants>>,
ScaledEOS<DavisProducts>, ShiftedEOS<DavisProducts>,
ScaledEOS<ShiftedEOS<DavisProducts>>
#ifdef SPINER_USE_HDF
,
SpinerEOSDependsRhoT, SpinerEOSDependsRhoSie,
ScaledEOS<SpinerEOSDependsRhoT>, ScaledEOS<SpinerEOSDependsRhoSie>,
ShiftedEOS<SpinerEOSDependsRhoT>, ShiftedEOS<SpinerEOSDependsRhoSie>,
ShiftedEOS<ScaledEOS<SpinerEOSDependsRhoT>>,
ShiftedEOS<ScaledEOS<SpinerEOSDependsRhoSie>>,
ScaledEOS<ShiftedEOS<SpinerEOSDependsRhoT>>,
ScaledEOS<ShiftedEOS<SpinerEOSDependsRhoSie>>,
RelativisticEOS<SpinerEOSDependsRhoT>,
RelativisticEOS<SpinerEOSDependsRhoSie>,
// TODO(JMM): Might need shifted + relativistic
Expand All @@ -1508,7 +1517,8 @@ using EOS = Variant<
#endif // SPINER_USE_HDF
#ifdef SINGULARITY_USE_EOSPAC
,
EOSPAC, ScaledEOS<EOSPAC>, ShiftedEOS<EOSPAC>, ShiftedEOS<ScaledEOS<EOSPAC>>
EOSPAC, ScaledEOS<EOSPAC>, ShiftedEOS<EOSPAC>,
ShiftedEOS<ScaledEOS<EOSPAC>>, ScaledEOS<ShiftedEOS<EOSPAC>>
#endif // SINGULARITY_USE_EOSPAC
>;

Expand Down
22 changes: 20 additions & 2 deletions eos/eos_builder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ namespace EOSBuilder {

template<typename T>
EOS applyScaleAndShift(T&& eos,
bool scaled, bool shifted,
Real scale, Real shift) {
bool scaled, bool shifted,
Real scale, Real shift) {
if (shifted && scaled) {
ScaledEOS<T> a(std::move(eos),scale);
ShiftedEOS<ScaledEOS<T>> b(std::move(a),shift);
Expand All @@ -89,6 +89,24 @@ namespace EOSBuilder {
}
return eos;
}

template<typename T>
EOS applyShiftAndScale(T&& eos,
bool scaled, bool shifted,
Real scale, Real shift) {
if (shifted && scaled) {
ShiftedEOS<T> a(std::forward<T>(eos),shift);
ScaledEOS<ShiftedEOS<T>> b(std::move(a),scale);
return b;
}
if (shifted) {
return ShiftedEOS<T>(std::forward<T>(eos),shift);
}
if (scaled) {
return ScaledEOS<T>(std::forward<T>(eos),scale);
}
return eos;
}
Comment on lines +93 to +109
Copy link
Collaborator

Choose a reason for hiding this comment

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

If this is the canonical form used in rage, should we remove support for the other one?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm not sure it hurts anything to leave it there, but I'm not opposed to removing it either.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Well let's leave it for now, I suppose. Because riot does it that way. But we should probably unify that at some point.

} // namespace EOSBuilder

} // namespace singularity
Expand Down
52 changes: 36 additions & 16 deletions eos/singularity_eos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
//------------------------------------------------------------------------------

#include "singularity_eos.hpp"
#include "eos_builder.hpp"
#include <map>
#include <algorithm>
#include <cassert>
Expand All @@ -34,39 +35,48 @@ int init_sg_eos(const int nmat, EOS* &eos) {
return 0;
}

#define SGAPPLYMOD(A) \
EOSBuilder::applyShiftAndScale(A, enabled[0] == 1, enabled[1] == 1,\
vals[0], vals[1])
Comment on lines +38 to +40
Copy link
Collaborator

Choose a reason for hiding this comment

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

Clever.


int init_sg_IdealGas(const int matindex, EOS* eos, const double gm1,
const double Cv) {
const double Cv,
int const * const enabled, double const * const vals) {
assert(matindex >= 0);
EOS eos_ = IdealGas(gm1, Cv);
EOS eos_ = SGAPPLYMOD(IdealGas(gm1, Cv));
eos[matindex] = eos_.GetOnDevice();
return 0;
}

int init_sg_Gruneisen(const int matindex, EOS* eos, const double C0,
const double s1, const double s2, const double s3,
const double G0, const double b, const double rho0,
const double T0, const double P0, const double Cv) {
const double T0, const double P0, const double Cv,
int const * const enabled, double const * const vals) {
assert(matindex >= 0);
EOS eos_ = Gruneisen(C0, s1, s2, s3, G0, b, rho0, T0, P0, Cv);
EOS eos_ = SGAPPLYMOD(Gruneisen(C0, s1, s2, s3, G0, b, rho0, T0, P0, Cv));
eos[matindex] = eos_.GetOnDevice();
return 0;
}

int init_sg_JWL(const int matindex, EOS* eos, const double A,
const double B, const double R1, const double R2,
const double w, const double rho0, const double Cv) {
const double w, const double rho0, const double Cv,
int const * const enabled, double const * const vals) {
assert(matindex >= 0);
EOS eos_ = JWL(A, B, R1, R2, w, rho0, Cv);
EOS eos_ = SGAPPLYMOD(JWL(A, B, R1, R2, w, rho0, Cv));
eos[matindex] = eos_.GetOnDevice();
return 0;
}

int init_sg_DavisProducts(const int matindex, EOS* eos, const double a,
const double b, const double k, const double n,
const double vc, const double pc, const double Cv,
const double E0) {
const double E0,
int const * const enabled,
double const * const vals) {
assert(matindex >= 0);
EOS eos_ = DavisProducts(a, b, k, n, vc, pc, Cv, E0);
EOS eos_ = SGAPPLYMOD(DavisProducts(a, b, k, n, vc, pc, Cv, E0));
eos[matindex] = eos_.GetOnDevice();
return 0;
}
Expand All @@ -75,39 +85,49 @@ int init_sg_DavisReactants(const int matindex, EOS* eos,
const double rho0, const double e0, const double P0,
const double T0, const double A, const double B,
const double C, const double G0, const double Z,
const double alpha, const double Cv0) {
const double alpha, const double Cv0,
int const * const enabled,
double const * const vals) {
assert(matindex >= 0);
EOS eos_ = DavisReactants(rho0, e0, P0, T0, A, B, C, G0, Z, alpha, Cv0);
EOS eos_ =
SGAPPLYMOD(DavisReactants(rho0, e0, P0, T0, A, B, C, G0, Z, alpha, Cv0));
eos[matindex] = eos_.GetOnDevice();
return 0;
}

#ifdef SPINER_USE_HDF
int init_sg_SpinerDependsRhoT(const int matindex, EOS* eos,
const char* filename, const int matid) {
const char* filename, const int matid,
int const * const enabled,
double const * const vals) {
assert(matindex >= 0);
EOS eos_ = SpinerEOSDependsRhoT(std::string(filename), matid);
EOS eos_ = SGAPPLYMOD(SpinerEOSDependsRhoT(std::string(filename), matid));
eos[matindex] = eos_.GetOnDevice();
return 0;
}

int init_sg_SpinerDependsRhoSie(const int matindex, EOS* eos,
const char* filename, const int matid) {
const char* filename, const int matid,
int const * const enabled,
double const * const vals) {
assert(matindex >= 0);
EOS eos_ = SpinerEOSDependsRhoSie(std::string(filename), matid);
EOS eos_ = SGAPPLYMOD(SpinerEOSDependsRhoSie(std::string(filename), matid));
eos[matindex] = eos_.GetOnDevice();
return 0;
}
#endif

#ifdef SINGULARITY_USE_EOSPAC
int init_sg_eospac(const int matindex, EOS* eos, const int id) {
int init_sg_eospac(const int matindex, EOS* eos, const int id,
int const * const enabled, double const * const vals) {
assert(matindex >= 0);
EOS eos_ = EOSPAC(id);
EOS eos_ = SGAPPLYMOD(EOSPAC(id));
eos[matindex] = eos_.GetOnDevice();
}
#endif // SINGULARITY_USE_EOSPAC

#undef SGAPPLYMOD

#ifdef PORTABILITY_STRATEGY_KOKKOS
using Lrgt = Kokkos::LayoutRight;
template< typename T>
Expand Down
Loading