From 186236e08978c17a3297630b2d8f8e6d19291b3f Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Wed, 24 May 2023 15:40:50 -0600 Subject: [PATCH 1/8] Add scratch vectorization support for UnitSystem (no test) --- .../eos/modifiers/eos_unitsystem.hpp | 147 ++++++++++++++++++ 1 file changed, 147 insertions(+) diff --git a/singularity-eos/eos/modifiers/eos_unitsystem.hpp b/singularity-eos/eos/modifiers/eos_unitsystem.hpp index 5e7f6b033a..9a5c4f5c81 100644 --- a/singularity-eos/eos/modifiers/eos_unitsystem.hpp +++ b/singularity-eos/eos/modifiers/eos_unitsystem.hpp @@ -251,6 +251,153 @@ class UnitSystem : public EosBase> { return inv_temp_unit_ * t_.MinimumTemperature(); } + // vector implementations + template + inline void TemperatureFromDensityInternalEnergy( + const Real *rhos, const Real *sies, Real *temperatures, Real *scratch, + const int num, LambdaIndexer &&lambdas, Transform &&transform = Transform()) const { + transform.x.apply(rho_unit_); + transform.y.apply(sie_unit_); + transform.f.apply(inv_temp_unit_); + t_.TemperatureFromDensityInternalEnergy(rhos, sies, temperatures, scratch, num, + std::forward(lambdas), + std::forward(transform)); + } + + template + inline void PressureFromDensityTemperature(const Real *rhos, const Real *temperatures, + Real *pressures, Real *scratch, + const int num, LambdaIndexer &&lambdas, + Transform &&transform = Transform()) const { + transform.x.apply(rho_unit_); + transform.y.apply(temp_unit_); + transform.f.apply(inv_press_unit_); + t_.PressureFromDensityTemperature(rhos, temperatures, pressures, scratch, num, + std::forward(lambdas), + std::forward(transform)); + } + + template + inline void + PressureFromDensityInternalEnergy(const Real *rhos, const Real *sies, Real *pressures, + Real *scratch, const int num, LambdaIndexer &&lambdas, + Transform &&transform = Transform()) const { + transform.x.apply(rho_unit_); + transform.y.apply(sie_unit_); + transform.f.apply(inv_press_unit_); + t_.PressureFromDensityInternalEnergy(rhos, sies, pressures, scratch, num, + std::forward(lambdas), + std::forward(transform)); + } + + template + inline void SpecificHeatFromDensityTemperature( + const Real *rhos, const Real *temperatures, Real *cvs, Real *scratch, const int num, + LambdaIndexer &&lambdas, Transform &&transform = Transform()) const { + transform.x.apply(rho_unit_); + transform.y.apply(temp_unit_); + transform.f.apply(inv_cv_unit_); + t_.SpecificHeatFromDensityTemperature(rhos, temperatures, cvs, scratch, num, + std::forward(lambdas), + std::forward(transform)); + } + + template + inline void SpecificHeatFromDensityInternalEnergy( + const Real *rhos, const Real *sies, Real *cvs, Real *scratch, const int num, + LambdaIndexer &&lambdas, Transform &&transform = Transform()) const { + transform.x.apply(rho_unit_); + transform.y.apply(sie_unit_); + transform.f.apply(inv_cv_unit_); + t_.SpecificHeatFromDensityInternalEnergy(rhos, sies, cvs, scratch, num, + std::forward(lambdas), + std::forward(transform)); + } + + template + inline void BulkModulusFromDensityTemperature( + const Real *rhos, const Real *temperatures, Real *bmods, Real *scratch, + const int num, LambdaIndexer &&lambdas, Transform &&transform = Transform()) const { + transform.x.apply(rho_unit_); + transform.y.apply(temp_unit_); + transform.f.apply(inv_bmod_unit_); + t_.BulkModulusFromDensityTemperature(rhos, temperatures, bmods, scratch, num, + std::forward(lambdas), + std::forward(transform)); + } + + template + inline void BulkModulusFromDensityInternalEnergy( + const Real *rhos, const Real *sies, Real *bmods, Real *scratch, const int num, + LambdaIndexer &&lambdas, Transform &&transform = Transform()) const { + transform.x.apply(rho_unit_); + transform.y.apply(sie_unit_); + transform.f.apply(inv_bmod_unit_); + t_.BulkModulusFromDensityInternalEnergy(rhos, sies, bmods, scratch, num, + std::forward(lambdas), + std::forward(transform)); + } + + template + inline void GruneisenParamFromDensityTemperature( + const Real *rhos, const Real *temperatures, Real *gm1s, Real *scratch, + const int num, LambdaIndexer &&lambdas, Transform &&transform = Transform()) const { + transform.x.apply(rho_unit_); + transform.y.apply(temp_unit_); + t_.GruneisenParamFromDensityTemperature(rhos, temperatures, gm1s, scratch, num, + std::forward(lambdas), + std::forward(transform)); + } + + template + inline void GruneisenParamFromDensityInternalEnergy( + const Real *rhos, const Real *sies, Real *gm1s, Real *scratch, const int num, + LambdaIndexer &&lambdas, Transform &&transform = Transform()) const { + transform.x.apply(rho_unit_); + transform.y.apply(sie_unit_); + t_.GruneisenParamFromDensityInternalEnergy(rhos, sies, gm1s, scratch, num, + std::forward(lambdas), + std::forward(transform)); + } + + template + inline void InternalEnergyFromDensityTemperature( + const Real *rhos, const Real *temperatures, Real *sies, Real *scratch, + const int num, LambdaIndexer &&lambdas, Transform &&transform = Transform()) const { + transform.x.apply(rho_unit_); + transform.y.apply(temp_unit_); + transform.f.apply(inv_sie_unit_); + t_.InternalEnergyFromDensityTemperature(rhos, temperatures, sies, scratch, num, + std::forward(lambdas), + std::forward(transform)); + } + + template + inline void EntropyFromDensityTemperature(const Real *rhos, const Real *temperatures, + Real *entropies, Real *scratch, const int num, + LambdaIndexer &&lambdas, + Transform &&transform = Transform()) const { + transform.x.apply(rho_unit_); + transform.y.apply(temp_unit_); + transform.f.apply(inv_entropy_unit_); + t_.EntropyFromDensityTemperature(rhos, temperatures, entropies, scratch, num, + std::forward(lambdas), + std::forward(transform)); + } + + template + inline void + EntropyFromDensityInternalEnergy(const Real *rhos, const Real *sies, Real *entropies, + Real *scratch, const int num, LambdaIndexer &&lambdas, + Transform &&transform = Transform()) const { + transform.x.apply(rho_unit_); + transform.y.apply(sie_unit_); + transform.f.apply(inv_entropy_unit_); + t_.EntropyFromDensityInternalEnergy(rhos, sies, entropies, scratch, num, + std::forward(lambdas), + std::forward(transform)); + } + PORTABLE_INLINE_FUNCTION int nlambda() const noexcept { return t_.nlambda(); } From 42dfef305c54d2147adddffd2af78103f01cda15 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Wed, 5 Jul 2023 22:09:41 -0600 Subject: [PATCH 2/8] Correct format string --- singularity-eos/eos/eos_eospac.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/singularity-eos/eos/eos_eospac.hpp b/singularity-eos/eos/eos_eospac.hpp index 011b636297..9f8e858986 100644 --- a/singularity-eos/eos/eos_eospac.hpp +++ b/singularity-eos/eos/eos_eospac.hpp @@ -1135,7 +1135,7 @@ class EOSPAC : public EosBase { inline void Finalize() {} static std::string EosType() { return std::string("EOSPAC"); } static std::string EosPyType() { return EosType(); } - inline void PrintParams() const { printf("EOSPAC parameters:\nmatid = %s\n", matid_); } + inline void PrintParams() const { printf("EOSPAC parameters:\nmatid = %d\n", matid_); } PORTABLE_FORCEINLINE_FUNCTION Real MinimumDensity() const { return rho_min_; } PORTABLE_FORCEINLINE_FUNCTION Real MinimumTemperature() const { return temp_min_; } From 7fa5cea90db794db93c497421eeacd337442aaae Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Wed, 5 Jul 2023 22:11:18 -0600 Subject: [PATCH 3/8] add missing variants, apply unit_system to eospac --- singularity-eos/eos/eos.hpp | 60 +++++++++++++++++++++++++------------ 1 file changed, 41 insertions(+), 19 deletions(-) diff --git a/singularity-eos/eos/eos.hpp b/singularity-eos/eos/eos.hpp index 379246669f..0015dc7e0b 100644 --- a/singularity-eos/eos/eos.hpp +++ b/singularity-eos/eos/eos.hpp @@ -73,44 +73,66 @@ static constexpr const auto full_eos_list = EOSPAC #endif // SINGULARITY_USE_EOSPAC >{}; -// eos's that get relativistic and unit system modifiers -static constexpr const auto partial_eos_list = +// eos's that get relativistic modifier +static constexpr const auto relativistic_eos_list = tl{}; +// eos's that get unit system modifier +static constexpr const auto unit_system_eos_list = + tl{}; // modifiers that get applied to all eos's static constexpr const auto apply_to_all = al{}; -// modifiers thet get applied to a subset of eos's -static constexpr const auto apply_to_partial = al{}; -// variadic list of eos's with shifted or scaled modifiers -static constexpr const auto shifted = - transform_variadic_list(full_eos_list, al{}); -static constexpr const auto scaled = - transform_variadic_list(full_eos_list, al{}); -// variadic list of Scaled>'s -static constexpr const auto scaled_of_shifted = - transform_variadic_list(shifted, al{}); // variadic list of UnitSystem's static constexpr const auto unit_system = - transform_variadic_list(partial_eos_list, al{}); + transform_variadic_list(unit_system_eos_list, al{}); // variadic list of Relativistic's static constexpr const auto relativistic = - transform_variadic_list(partial_eos_list, al{}); + transform_variadic_list(relativistic_eos_list, al{}); +// variadic list of eos's with shifted or scaled modifiers +static constexpr const auto shifted_1 = + transform_variadic_list(full_eos_list, al{}); +static constexpr const auto scaled_1 = + transform_variadic_list(full_eos_list, al{}); // relativistic and unit system modifiers static constexpr const auto unit_or_rel = - transform_variadic_list(partial_eos_list, apply_to_partial); + singularity::detail::concat(unit_system, relativistic); +// variadic list of eos with shifted, relativistic or unit system modifiers +static constexpr const auto shifted_of_unit_or_rel = + transform_variadic_list(unit_or_rel, al{}); +// combined list of all shifted EOS +static constexpr const auto shifted = + singularity::detail::concat(shifted_1, shifted_of_unit_or_rel); +// variadic list of eos with scaled, relativistic or unit system modifiers +static constexpr const auto scaled_of_unit_or_rel = + transform_variadic_list(unit_or_rel, al{}); +// variadic list of Scaled>'s +static constexpr const auto scaled_of_shifted = + transform_variadic_list(shifted, al{}); +// combined list of all scaled EOS +static constexpr const auto scaled = + singularity::detail::concat(scaled_1, scaled_of_unit_or_rel, scaled_of_shifted); // create combined list -static constexpr const auto combined_list_1 = singularity::detail::concat( - full_eos_list, shifted, scaled, scaled_of_shifted, unit_or_rel); +static constexpr const auto combined_list_1 = + singularity::detail::concat(full_eos_list, shifted, scaled, unit_or_rel); // make a ramped eos of everything static constexpr const auto ramped_all = transform_variadic_list(combined_list_1, al{}); // final combined list -static constexpr const auto combined_list = singularity::detail::concat( - full_eos_list, shifted, scaled, scaled_of_shifted, unit_or_rel, ramped_all); +static constexpr const auto combined_list = + singularity::detail::concat(full_eos_list, shifted, scaled, unit_or_rel, ramped_all); // a function that returns a Variant from a typelist template struct tl_to_Variant_struct { From ca8cbbaebdd85ef2dd3d6d0f98e2ad8a50dbb83a Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Wed, 5 Jul 2023 22:45:37 -0600 Subject: [PATCH 4/8] Avoid C++17 extension warning --- singularity-eos/eos/eos.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/singularity-eos/eos/eos.hpp b/singularity-eos/eos/eos.hpp index 0015dc7e0b..c2e54ada61 100644 --- a/singularity-eos/eos/eos.hpp +++ b/singularity-eos/eos/eos.hpp @@ -55,7 +55,7 @@ namespace singularity { template using tl = singularity::detail::type_list; -template