-
Notifications
You must be signed in to change notification settings - Fork 17
Prepare for multigroup radiation (starting with jaybenne) in artemis. #135
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
base: develop
Are you sure you want to change the base?
Changes from all commits
5348c4d
89685f6
6309b03
0fc437c
db5fd89
fa909c3
cf946db
a46d96e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| +1 −0 | CHANGELOG.md | |
| +3 −0 | CMakeLists.txt | |
| +76 −0 | doc/sphinx/src/examples.rst | |
| +209 −0 | doc/sphinx/src/models.rst | |
| +2 −0 | example/CMakeLists.txt | |
| +235 −0 | example/custom_eos_to_spiner.cpp | |
| +534 −0 | plan_histories/MR632-2026-05-04-add-spiner-constructor-from-eos.md | |
| +114 −93 | sesame2spiner/generate_files.cpp | |
| +9 −1 | sesame2spiner/generate_files.hpp | |
| +338 −0 | singularity-eos/base/eos_concepts.hpp | |
| +90 −0 | singularity-eos/base/finite_diff.hpp | |
| +475 −0 | singularity-eos/eos/eos_spiner_construction.hpp | |
| +435 −0 | singularity-eos/eos/eos_spiner_rho_sie.hpp | |
| +250 −0 | singularity-eos/eos/eos_spiner_rho_temp.hpp | |
| +1 −0 | test/CMakeLists.txt | |
| +869 −0 | test/test_eos_spiner_constructors.cpp |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,163 @@ | ||
| //======================================================================================== | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Curious as to the why the move outside of the gas package? If we eventually add dust opacity, I also would think that belongs in dust package. But I could be convinced otherwise 😸
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a fair question - originally moved this here so that frequency grid information under either radiation package input node would be able to affect the construction of the opacity models. Also, figured it might be worth avoiding opacity construction altogether (e.g. in gas) if radiation is not getting used. All in all, guessing there is a better (parthenon-ic) way to design this notion of "opacity" being dependent on the existance of two other packages (e.g. radiation+dust or radiation+gas)... |
||
| // (C) (or copyright) 2026. Triad National Security, LLC. All rights reserved. | ||
| // | ||
| // This program was produced under U.S. Government contract 89233218CNA000001 for Los | ||
| // Alamos National Laboratory (LANL), which is operated by Triad National Security, LLC | ||
| // for the U.S. Department of Energy/National Nuclear Security Administration. All rights | ||
| // in the program are reserved by Triad National Security, LLC, and the U.S. Department | ||
| // of Energy/National Nuclear Security Administration. The Government is granted for | ||
| // itself and others acting on its behalf a nonexclusive, paid-up, irrevocable worldwide | ||
| // license in this material to reproduce, prepare derivative works, distribute copies to | ||
| // the public, perform publicly and display publicly, and to permit others to do so. | ||
| //======================================================================================== | ||
| #include "gas_opacity.hpp" | ||
| #include "utils/opacity/opacity.hpp" | ||
|
|
||
| namespace Gas { | ||
| void InitGasOpacity(ParameterInput *pin, const ArtemisUtils::Units &units, | ||
| Params ¶ms) { | ||
| using namespace singularity::photons; | ||
|
|
||
| // Opacity models | ||
| const Real time = units.GetTimeCodeToPhysical(); | ||
| const Real mass = units.GetMassCodeToPhysical(); | ||
| const Real length = units.GetLengthCodeToPhysical(); | ||
| const Real temp = units.GetTemperatureCodeToPhysical(); | ||
|
|
||
| // Get frequency type (it should already be set in radiation Initialization) | ||
| const auto frequency_type = params.Get<FrequencyType>("frequency_type"); | ||
|
|
||
| // TODO: read this (and consolidate gray/multigroup modes?) | ||
| const std::vector<Real> gray_bounds = {0.0, std::numeric_limits<Real>::infinity()}; | ||
| const int NG = static_cast<int>(gray_bounds.size()) - 1; | ||
|
|
||
| // Absorption opacity model | ||
| std::string opacity_model_name = | ||
| pin->GetOrAddString("gas/opacity/absorption", "opacity_model", "constant"); | ||
|
|
||
| // Mean absorption opacity (either read from table or uses model | ||
| ArtemisUtils::Opacity mg_opacity; | ||
| ArtemisUtils::MeanOpacity opacity; | ||
| if (opacity_model_name == "table") { | ||
| PARTHENON_REQUIRE(frequency_type == FrequencyType::gray, | ||
| "Only gray table opacity permitted, for now."); | ||
| std::string table_filename = | ||
| pin->GetString("gas/opacity/absorption", "opacity_table"); | ||
| opacity = | ||
| singularity::photons::MeanNonCGSUnits<singularity::photons::MeanOpacityBase>( | ||
| singularity::photons::MeanOpacityBase(table_filename), time, mass, length, | ||
| temp); | ||
| } else { | ||
| // Instantiate mean absorption opacity object (i.e., table) | ||
| const Real lRhoMin_a = pin->GetOrAddReal("gas/opacity/absorption", "lRhoMin", -1.0); | ||
| const Real lRhoMax_a = pin->GetOrAddReal("gas/opacity/absorption", "lRhoMax", 1.0); | ||
| const int NRho_a = pin->GetOrAddInteger("gas/opacity/absorption", "NRho", 2); | ||
| const Real lTMin_a = pin->GetOrAddReal("gas/opacity/absorption", "lTMin", -1.0); | ||
| const Real lTMax_a = pin->GetOrAddReal("gas/opacity/absorption", "lTMax", 1.0); | ||
| const int NT_a = pin->GetOrAddInteger("gas/opacity/absorption", "NT", 2); | ||
|
|
||
| if (opacity_model_name == "none") { | ||
| auto model = Gray(0.0); | ||
| opacity = | ||
| singularity::photons::MeanNonCGSUnits<singularity::photons::MeanOpacityBase>( | ||
| singularity::photons::MeanOpacityBase(model, lRhoMin_a, lRhoMax_a, NRho_a, | ||
| lTMin_a, lTMax_a, NT_a, gray_bounds, | ||
| NG), | ||
| time, mass, length, temp); | ||
| if (frequency_type == FrequencyType::multigroup) { | ||
| mg_opacity = singularity::photons::NonCGSUnits<singularity::photons::Gray>( | ||
| std::move(model), time, mass, length, temp); | ||
| } | ||
| } else if (opacity_model_name == "constant") { | ||
| const Real kappa_a = pin->GetOrAddReal("gas/opacity/absorption", "kappa_a", 0.0); | ||
| auto model = Gray(kappa_a); | ||
| opacity = | ||
| singularity::photons::MeanNonCGSUnits<singularity::photons::MeanOpacityBase>( | ||
| singularity::photons::MeanOpacityBase(model, lRhoMin_a, lRhoMax_a, NRho_a, | ||
| lTMin_a, lTMax_a, NT_a, gray_bounds, | ||
| NG), | ||
| time, mass, length, temp); | ||
| if (frequency_type == FrequencyType::multigroup) { | ||
| mg_opacity = singularity::photons::NonCGSUnits<singularity::photons::Gray>( | ||
| std::move(model), time, mass, length, temp); | ||
| } | ||
| } else if (opacity_model_name == "powerlaw") { | ||
| const Real coef_kappa_a = | ||
| pin->GetOrAddReal("gas/opacity/absorption", "coef_kappa_a", 0.0); | ||
| const Real rho_exp = pin->GetOrAddReal("gas/opacity/absorption", "rho_exp", 0.0); | ||
| const Real temp_exp = pin->GetOrAddReal("gas/opacity/absorption", "temp_exp", 0.0); | ||
| auto model = PowerLaw(coef_kappa_a, rho_exp, temp_exp); | ||
| opacity = | ||
| singularity::photons::MeanNonCGSUnits<singularity::photons::MeanOpacityBase>( | ||
| singularity::photons::MeanOpacityBase(model, lRhoMin_a, lRhoMax_a, NRho_a, | ||
| lTMin_a, lTMax_a, NT_a, gray_bounds, | ||
| NG), | ||
| time, mass, length, temp); | ||
| if (frequency_type == FrequencyType::multigroup) { | ||
| mg_opacity = singularity::photons::NonCGSUnits<singularity::photons::PowerLaw>( | ||
| std::move(model), time, mass, length, temp); | ||
| } | ||
| } else { | ||
| PARTHENON_FAIL("Opacity model not recognized!"); | ||
| } | ||
| } | ||
|
|
||
| params.Add("opacity_h", opacity); | ||
| params.Add("opacity_d", opacity.GetOnDevice()); | ||
| if (frequency_type == FrequencyType::multigroup) { | ||
| params.Add("mg_opacity_h", mg_opacity); | ||
| params.Add("mg_opacity_d", mg_opacity.GetOnDevice()); | ||
| } | ||
|
|
||
| // Scattering opacity model | ||
| std::string scattering_model_name = | ||
| pin->GetOrAddString("gas/opacity/scattering", "scattering_model", "none"); | ||
|
|
||
| // Instantiate mean scattering opacity object (i.e., table) | ||
| const Real lRhoMin_s = pin->GetOrAddReal("gas/opacity/scattering", "lRhoMin", -1.0); | ||
| const Real lRhoMax_s = pin->GetOrAddReal("gas/opacity/scattering", "lRhoMax", 1.0); | ||
| const int NRho_s = pin->GetOrAddInteger("gas/opacity/scattering", "NRho", 2); | ||
| const Real lTMin_s = pin->GetOrAddReal("gas/opacity/scattering", "lTMin", -1.0); | ||
| const Real lTMax_s = pin->GetOrAddReal("gas/opacity/scattering", "lTMax", 1.0); | ||
| const int NT_s = pin->GetOrAddInteger("gas/opacity/scattering", "NT", 2); | ||
|
|
||
| ArtemisUtils::Scattering mg_scattering; | ||
| ArtemisUtils::MeanScattering scattering; | ||
| if (scattering_model_name == "none") { | ||
| auto smodel = GrayS(0.0, 1.0); | ||
| scattering = | ||
| singularity::photons::MeanNonCGSUnitsS<singularity::photons::MeanSOpacityBase>( | ||
| singularity::photons::MeanSOpacityBase(smodel, lRhoMin_s, lRhoMax_s, NRho_s, | ||
| lTMin_s, lTMax_s, NT_s, gray_bounds, | ||
| NG), | ||
| time, mass, length, temp); | ||
| if (frequency_type == FrequencyType::multigroup) { | ||
| mg_scattering = singularity::photons::NonCGSUnitsS<singularity::photons::GrayS>( | ||
| std::move(smodel), time, mass, length, temp); | ||
| } | ||
| } else if (scattering_model_name == "constant") { | ||
| const Real kappa_s = pin->GetOrAddReal("gas/opacity/scattering", "kappa_s", 0.0); | ||
| auto smodel = GrayS(kappa_s, 1.0); | ||
| scattering = | ||
| singularity::photons::MeanNonCGSUnitsS<singularity::photons::MeanSOpacityBase>( | ||
| singularity::photons::MeanSOpacityBase(smodel, lRhoMin_s, lRhoMax_s, NRho_s, | ||
| lTMin_s, lTMax_s, NT_s, gray_bounds, | ||
| NG), | ||
| time, mass, length, temp); | ||
| if (frequency_type == FrequencyType::multigroup) { | ||
| mg_scattering = singularity::photons::NonCGSUnitsS<singularity::photons::GrayS>( | ||
| std::move(smodel), time, mass, length, temp); | ||
| } | ||
| } else { | ||
| PARTHENON_FAIL("Scattering model not recognized!"); | ||
| } | ||
|
|
||
| params.Add("scattering_h", scattering); | ||
| params.Add("scattering_d", scattering.GetOnDevice()); | ||
| if (frequency_type == FrequencyType::multigroup) { | ||
| params.Add("mg_scattering_h", mg_scattering); | ||
| params.Add("mg_scattering_d", mg_scattering.GetOnDevice()); | ||
| } | ||
| } | ||
|
|
||
| } // namespace Gas | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| //======================================================================================== | ||
| // (C) (or copyright) 2026. Triad National Security, LLC. All rights reserved. | ||
| // | ||
| // This program was produced under U.S. Government contract 89233218CNA000001 for Los | ||
| // Alamos National Laboratory (LANL), which is operated by Triad National Security, LLC | ||
| // for the U.S. Department of Energy/National Nuclear Security Administration. All rights | ||
| // in the program are reserved by Triad National Security, LLC, and the U.S. Department | ||
| // of Energy/National Nuclear Security Administration. The Government is granted for | ||
| // itself and others acting on its behalf a nonexclusive, paid-up, irrevocable worldwide | ||
| // license in this material to reproduce, prepare derivative works, distribute copies to | ||
| // the public, perform publicly and display publicly, and to permit others to do so. | ||
| //======================================================================================== | ||
| #ifndef RADIATION_GAS_OPACITY_HPP_ | ||
| #define RADIATION_GAS_OPACITY_HPP_ | ||
|
|
||
| // Artemis includes | ||
| #include "utils/units.hpp" | ||
|
|
||
| // Parthenon includes | ||
| #include <parthenon/driver.hpp> | ||
| #include <parthenon/package.hpp> | ||
|
|
||
| namespace Gas { | ||
| void InitGasOpacity(ParameterInput *pin, const ArtemisUtils::Units &units, | ||
| Params ¶ms); | ||
| } // namespace Gas | ||
|
|
||
| #endif // RADIATION_GAS_OPACITY_HPP_ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
newline