Skip to content

Commit

Permalink
Merge pull request #15 from lanl/dholladay00/scaleshift_fortran
Browse files Browse the repository at this point in the history
Dholladay00/scaleshift fortran
  • Loading branch information
dholladay00 authored Jun 10, 2021
2 parents d2839ee + b274531 commit 8513e81
Show file tree
Hide file tree
Showing 6 changed files with 256 additions and 55 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ if(SINGULARITY_USE_KOKKOS AND SINGULARITY_USE_CUDA)
set(CMAKE_CXX_COMPILER ${NVCC_WRAPPER_DIR}/nvcc_wrapper CACHE STRING "")
endif()

project(singularity-eos VERSION 1.3.0)
project(singularity-eos VERSION 1.4.0)

if(SINGULARITY_USE_FORTRAN)
enable_language(CXX Fortran)
Expand Down
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;
}
} // namespace EOSBuilder

} // namespace singularity
Expand Down
103 changes: 89 additions & 14 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,10 +35,34 @@ 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])

constexpr const int def_en[2] = {0, 0};
constexpr const double def_v[2] = {0.0, 0.0};

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

int init_sg_IdealGas(const int matindex, EOS* eos, const double gm1,
const double Cv) {
return init_sg_IdealGas(matindex, eos, gm1, Cv, def_en, def_v);
}

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,
int const * const enabled, double const * const vals) {
assert(matindex >= 0);
EOS eos_ = IdealGas(gm1, Cv);
EOS eos_ = SGAPPLYMOD(Gruneisen(C0, s1, s2, s3, G0, b, rho0, T0, P0, Cv));
eos[matindex] = eos_.GetOnDevice();
return 0;
}
Expand All @@ -46,17 +71,35 @@ 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) {
return init_sg_Gruneisen(matindex, eos, C0, s1, s2, s3, G0, b, rho0, T0, P0,
Cv, def_en, def_v);
}

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,
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(JWL(A, B, R1, R2, w, rho0, 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) {
return init_sg_JWL(matindex, eos, A, B, R1, R2, w, rho0, Cv, def_en,
def_v);
}

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,
int const * const enabled,
double const * const vals) {
assert(matindex >= 0);
EOS eos_ = JWL(A, B, R1, R2, w, rho0, Cv);
EOS eos_ = SGAPPLYMOD(DavisProducts(a, b, k, n, vc, pc, Cv, E0));
eos[matindex] = eos_.GetOnDevice();
return 0;
}
Expand All @@ -65,8 +108,20 @@ 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) {
return init_sg_DavisProducts(matindex, eos, a, b, k, n, vc, pc, Cv, E0,
def_en, def_v);
}

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,
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(DavisReactants(rho0, e0, P0, T0, A, B, C, G0, Z, alpha, Cv0));
eos[matindex] = eos_.GetOnDevice();
return 0;
}
Expand All @@ -76,38 +131,58 @@ int init_sg_DavisReactants(const int matindex, EOS* eos,
const double T0, const double A, const double B,
const double C, const double G0, const double Z,
const double alpha, const double Cv0) {
assert(matindex >= 0);
EOS eos_ = DavisReactants(rho0, e0, P0, T0, A, B, C, G0, Z, alpha, Cv0);
eos[matindex] = eos_.GetOnDevice();
return 0;
return init_sg_DavisReactants(matindex, eos, rho0, e0, P0, T0, A, B, C, G0, Z,
alpha, Cv0, def_en, def_v);
}

#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_SpinerDependsRhoT(const int matindex, EOS* eos,
const char* filename, const int matid) {
return init_sg_SpinerDependsRhoT(matindex, eos, filename, matid, def_en,
def_v);
}

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;
}
int init_sg_SpinerDependsRhoSie(const int matindex, EOS* eos,
const char* filename, const int matid) {
return init_sg_SpinerDependsRhoSie(matindex, eos, filename, matid, def_en,
def_v);
}
#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();
return 0;
}
int init_sg_eospac(const int matindex, EOS* eos, const int id) {
return init_sg_eospac(matindex, eos, id, def_en, def_v);
}
#endif // SINGULARITY_USE_EOSPAC

#undef SGAPPLYMOD

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

0 comments on commit 8513e81

Please sign in to comment.