-
Notifications
You must be signed in to change notification settings - Fork 2
Integrate 1D toon #95
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| species: | ||
| - name: H2 | ||
| composition: {H: 2} | ||
| - name: He | ||
| composition: {He: 1} | ||
| - name: CH4 | ||
| composition: {C: 1, H: 4} | ||
| - name: H2O | ||
| composition: {H: 2, O: 1} | ||
| - name: NH3 | ||
| composition: {N: 1, H: 3} | ||
|
|
||
| geometry: | ||
| cells: | ||
| nx1: 100 | ||
|
|
||
| opacities: | ||
| h2o_line: | ||
| type: molecule-line | ||
| data: [h2_0p9_he_0p1_ch4_0p004_h2o_0p002_nh3_0p0003_xsection_120_730K_1_100bar_20_2500cm1.nc] | ||
| species: [H2O] | ||
|
|
||
| nh3_line: | ||
| type: molecule-line | ||
| data: [h2_0p9_he_0p1_ch4_0p004_h2o_0p002_nh3_0p0003_xsection_120_730K_1_100bar_20_2500cm1.nc] | ||
| species: [NH3] | ||
|
|
||
| ch4_line: | ||
| type: molecule-line | ||
| data: [h2_0p9_he_0p1_ch4_0p004_h2o_0p002_nh3_0p0003_xsection_120_730K_1_100bar_20_2500cm1.nc] | ||
| species: [CH4] | ||
|
|
||
| h2_h2_cia: | ||
| type: molecule-cia | ||
| data: [h2_0p9_he_0p1_ch4_0p004_h2o_0p002_nh3_0p0003_xsection_120_730K_1_100bar_20_2500cm1.nc] | ||
| species: [H2] | ||
|
|
||
| h2_he_cia: | ||
| type: molecule-cia | ||
| data: [h2_0p9_he_0p1_ch4_0p004_h2o_0p002_nh3_0p0003_xsection_120_730K_1_100bar_20_2500cm1.nc] | ||
| species: [H2, He] | ||
|
|
||
| bands: | ||
| - name: dump_lw | ||
| range: [20.0, 2500.0] | ||
| opacities: [h2o_line, nh3_line, ch4_line, h2_h2_cia, h2_he_cia] | ||
| solver: toon | ||
| flags: planck | ||
| nwave: 2481 | ||
| nstr: 4 | ||
|
|
||
| forcing: | ||
| const-gravity: | ||
| grav1: -24.79 | ||
|
|
||
| problem: | ||
| xH2: 0.9 | ||
| xHe: 0.1 | ||
| xCH4: 0.004 | ||
| xH2O: 0.002 | ||
| xNH3: 0.0003 | ||
|
|
||
| Pbot: 100.e5 | ||
| Ptop: 1.e4 | ||
|
|
||
| Tbot: 600. | ||
| Ttop: 130. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,89 @@ | ||
| // external | ||
| #include <gtest/gtest.h> | ||
|
|
||
| // C/C++ | ||
| #include <filesystem> | ||
|
|
||
| // harp | ||
| #include <harp/radiation/radiation.hpp> | ||
| #include <harp/radiation/radiation_band.hpp> | ||
| #include <harp/rtsolver/toon_mckay89.hpp> | ||
|
|
||
| // tests | ||
| #include "device_testing.hpp" | ||
|
|
||
| using namespace harp; | ||
|
|
||
| TEST(ToonConfig, from_yaml_reads_toon_options) { | ||
| auto yaml_path = | ||
| std::filesystem::path(__FILE__).parent_path() / "toon_test.yaml"; | ||
| auto rad = harp::RadiationOptionsImpl::from_yaml(yaml_path.string()); | ||
| ASSERT_EQ(rad->bands().size(), 2u); | ||
|
|
||
| auto const& op = rad->bands().front(); | ||
|
|
||
| ASSERT_EQ(op->solver_name(), "toon"); | ||
| ASSERT_NE(op->toon(), nullptr); | ||
| EXPECT_EQ(op->toon()->flags(), | ||
| "planck,zenith_correction,hard_surface,delta_eddington_lw"); | ||
| EXPECT_TRUE(op->toon()->planck()); | ||
| EXPECT_TRUE(op->toon()->zenith_correction()); | ||
| EXPECT_EQ(op->toon()->top_emission_flag(), -1); | ||
| EXPECT_TRUE(op->toon()->hard_surface()); | ||
| EXPECT_TRUE(op->toon()->delta_eddington_lw()); | ||
| EXPECT_EQ(op->toon()->wave_lower(), | ||
| (std::vector<double>{200.0, 200.0, 200.0})); | ||
| EXPECT_EQ(op->toon()->wave_upper(), | ||
| (std::vector<double>{2000.0, 2000.0, 2000.0})); | ||
| } | ||
|
|
||
| TEST(ToonConfig, radiation_band_registers_solver_module) { | ||
| auto op = harp::RadiationBandOptionsImpl::create(); | ||
| op->name("B_toon"); | ||
| op->solver_name("toon"); | ||
| op->toon(harp::ToonMcKay89OptionsImpl::create()); | ||
| op->toon()->flags("planck"); | ||
| op->nwave(2); | ||
| op->ncol(1); | ||
| op->nlyr(3); | ||
| op->wavenumber({300.0, 900.0}); | ||
| op->weight({600.0, 600.0}); | ||
| op->set_wave_lower({0.0, 600.0}); | ||
| op->set_wave_upper({600.0, 1200.0}); | ||
|
|
||
| harp::RadiationBand band(op); | ||
|
|
||
| EXPECT_NO_THROW({ (void)band->named_modules()["solver"]; }); | ||
| } | ||
|
|
||
| TEST(ToonConfig, planck_flag_controls_thermal_emission) { | ||
| auto wave_lower = std::vector<double>{200.0, 500.0}; | ||
| auto wave_upper = std::vector<double>{500.0, 1000.0}; | ||
|
|
||
| auto sw_op = harp::ToonMcKay89OptionsImpl::create(); | ||
| sw_op->wave_lower(wave_lower); | ||
| sw_op->wave_upper(wave_upper); | ||
| harp::ToonMcKay89 sw_toon(sw_op); | ||
|
|
||
| auto lw_op = harp::ToonMcKay89OptionsImpl::create(); | ||
| lw_op->wave_lower(wave_lower); | ||
| lw_op->wave_upper(wave_upper); | ||
| lw_op->flags("planck"); | ||
| harp::ToonMcKay89 lw_toon(lw_op); | ||
|
|
||
| auto prop = torch::zeros({2, 1, 3, 3}, torch::kFloat64); | ||
| prop.select(-1, 0).fill_(0.2); | ||
| auto temf = torch::ones({1, 4}, torch::kFloat64) * 300.0; | ||
| std::map<std::string, torch::Tensor> sw_bc; | ||
| std::map<std::string, torch::Tensor> lw_bc; | ||
|
|
||
| auto sw_result = sw_toon(prop, &sw_bc, /*band=*/"", temf); | ||
| auto lw_result = lw_toon(prop, &lw_bc, /*band=*/"", temf); | ||
|
|
||
| EXPECT_TRUE(torch::allclose(sw_result, torch::zeros_like(sw_result))); | ||
| EXPECT_GT(torch::max(torch::abs(lw_result)).item<double>(), 0.0); | ||
| } | ||
|
|
||
| TEST_P(DeviceTest, simple_toon_mckay89) { | ||
| auto op = harp::ToonMcKay89OptionsImpl::create(); | ||
| op->wave_lower({200., 500., 1000.}); | ||
|
|
@@ -50,6 +125,7 @@ TEST_P(DeviceTest, simple_toon_mckay89) { | |
| } | ||
|
|
||
| auto temf = torch::ones({ncol, nlyr + 1}, prop.options()) * tem_K; | ||
| op->flags("planck"); | ||
|
|
||
| for (auto [w0, g] : {std::make_pair(0.1, 0.5), std::make_pair(0.5, 0.5), | ||
|
Comment on lines
129
to
130
|
||
| std::make_pair(0.9, 0.5)}) { | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
.ADD_OPTION(std::string, ..., flags)expects an accessor pair with signaturesconst std::string& flags() constandToonMcKay89OptionsImpl& flags(std::string const&). The currentflags(std::string flags_str="") constinToonMcKay89OptionsImpldoes not match those signatures (returns by value, takes by value, and isconstwhile mutating), so this binding will fail to compile. Either adjustflagsto match theADD_OPTIONconvention or bind it with a custom.def(...)instead ofADD_OPTION.