-
Notifications
You must be signed in to change notification settings - Fork 8
Add microclumping #275
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?
Add microclumping #275
Changes from 74 commits
80a5c1b
8378493
6fa75d0
7603c8c
c63fd73
d4d81a9
c0dad9c
4667293
108f4e2
bb248f2
60e76fd
7677762
728eff5
364e2a8
038420c
defb34a
686ed72
d03d97e
f6feda0
340b711
6fbcd1d
eee7c3c
4f55f30
9ae070d
eb1a329
77cf234
0580850
9316e01
2fb1d56
7cb6d7f
614771a
68b8923
ca137a7
fc30a28
f2b2ed1
7059e58
00927fd
8d8bd5c
4306c85
7a27b9b
7c60728
f04bc83
b3c6201
4fe758d
e0a1585
cc93982
1a779dc
a3f073c
90d9547
4156f5c
c555db6
cd1c76a
250c680
4ebdbd4
3642506
7cf9b1e
7941363
3f28d1b
3835f22
b16ac52
de2dced
9233232
4d6b0c9
c591795
65fffaf
9f4979c
70ba5e7
7efa654
f650739
17bf183
48d0f7c
374cbb6
274db1a
0f42ee4
6a7e956
08a33a9
c8dcddf
73452bd
3729fb9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -461,7 +461,11 @@ void allocate_nonemptymodelcells() { | |
| kappagrey_allcells = MPI_shared_malloc_span<float>(nonempty_npts_model, 0.); | ||
| grey_depth_allcells = MPI_shared_malloc_span<float>(nonempty_npts_model, 0.); | ||
| thick_allcells = MPI_shared_malloc_span<int>(nonempty_npts_model, 0); | ||
| const auto modelgrid_mem_usage = nonempty_npts_model * ((sizeof(float) * 9) + sizeof(double) + sizeof(int)); | ||
| if constexpr (USE_MICROCLUMPING) { | ||
| clumpfactor_allcells = MPI_shared_malloc_span<float>(nonempty_npts_model, -1.); | ||
lukeshingles marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| const auto modelgrid_mem_usage = | ||
| nonempty_npts_model * ((sizeof(float) * (USE_MICROCLUMPING ? 10 : 9)) + sizeof(double) + sizeof(int)); | ||
| printlnlog( | ||
| "[info] mem_usage: the modelgrid properties (temperatures and electron densities) occupies {:.3f} MB (node " | ||
| "shared memory)", | ||
|
|
@@ -1516,6 +1520,18 @@ auto get_rho_tmin(const int modelgridindex) -> float { return modelgrid_input[mo | |
| return nne_allcells[nonemptymgi]; | ||
| } | ||
|
|
||
| [[gnu::pure]] [[nodiscard]] DEVICE_FUNC auto get_clumpfactor(const int nonemptymgi) -> float { | ||
| assert_testmodeonly(nonemptymgi >= 0); | ||
| assert_testmodeonly(nonemptymgi < get_nonempty_npts_model()); | ||
|
|
||
| if constexpr (USE_MICROCLUMPING) { | ||
AMG3141 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| assert_testmodeonly(std::isfinite(clumpfactor_allcells[nonemptymgi]) && clumpfactor_allcells[nonemptymgi] >= 1.F); | ||
| return clumpfactor_allcells[nonemptymgi]; | ||
| } | ||
|
|
||
| return 1.; | ||
| } | ||
AMG3141 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| [[gnu::pure]] [[nodiscard]] DEVICE_FUNC auto get_nnetot(const int nonemptymgi) -> float { | ||
| assert_testmodeonly(nonemptymgi >= 0); | ||
| assert_testmodeonly(nonemptymgi < get_nonempty_npts_model()); | ||
|
|
@@ -1532,6 +1548,16 @@ auto get_rho_tmin(const int modelgridindex) -> float { return modelgrid_input[mo | |
| return modelgrid_input[modelgridindex].initial_radial_pos_sum * tratmid / assoc_cells; | ||
| } | ||
|
|
||
| [[gnu::pure]] [[nodiscard]] DEVICE_FUNC auto get_modelcell_mean_radial_vel(const int modelgridindex, const double tmin) | ||
| -> double { | ||
| // TODO: both versions give the same thing. uncommented one should give ever so slightly better performance | ||
|
|
||
| const int assoc_cells = grid::get_numpropcells(modelgridindex); | ||
| return modelgrid_input[modelgridindex].initial_radial_pos_sum / tmin / assoc_cells; | ||
| // --------------- | ||
| // return get_modelcell_mean_radial_pos(modelgridindex, tratmid) / tmid; | ||
| } | ||
|
|
||
|
Comment on lines
+1541
to
+1550
Member
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. Trivial function used only once. Inline at the call site. |
||
| // mass fraction of an element (all isotopes combined) | ||
| [[gnu::pure]] [[nodiscard]] auto get_elem_abundance(const std::ptrdiff_t nonemptymgi, const int element) -> float { | ||
| const auto massfrac = elem_massfracs_allcells[(nonemptymgi * get_nelements()) + element]; | ||
|
|
@@ -1589,6 +1615,12 @@ void set_nne(const int nonemptymgi, const float nne) { | |
| nne_allcells[nonemptymgi] = nne; | ||
| } | ||
|
|
||
| void set_clumpfactor(const int nonemptymgi, const float vol_filling_factor) { | ||
| assert_testmodeonly(USE_MICROCLUMPING); | ||
| assert_always(0 < vol_filling_factor && vol_filling_factor <= 1); | ||
| clumpfactor_allcells[nonemptymgi] = 1.F / vol_filling_factor; | ||
| } | ||
|
|
||
| // Calculate and set the total density of electrons (free and bound) in grid cell. These are targets for Compton | ||
| // scattering of gamma rays | ||
| void set_nnetot(const int nonemptymgi) { | ||
|
|
@@ -1688,6 +1720,18 @@ DEVICE_FUNC auto get_modelgridtype() -> GridType { | |
| return nonemptymgi; | ||
| } | ||
|
|
||
| // Check if cell with index `mgi` is a non-empty cell | ||
| // If the cell is non-empty will return `true` and `nonemptymgi` will be set accordingly, otherwise returns `false` and | ||
| // `nonemptymgi` is set to -1 | ||
| [[nodiscard]] DEVICE_FUNC auto check_mgi_is_nonempty(const int mgi, int& nonemptymgi) -> bool { | ||
| assert_testmodeonly(get_nonempty_npts_model() > 0); | ||
| assert_testmodeonly(mgi >= 0); | ||
| assert_testmodeonly(mgi < get_npts_model()); | ||
|
|
||
| nonemptymgi = nonemptymgi_of_mgi[mgi]; | ||
| return nonemptymgi >= 0; | ||
| } | ||
|
|
||
|
Comment on lines
+1716
to
+1724
Member
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. Other parts of the code check if a cell is non-empty using the expression: |
||
| // get the index in the list of non-empty cells for a given model grid cell | ||
| [[gnu::pure]] [[nodiscard]] DEVICE_FUNC auto get_mgi_of_nonemptymgi(const ptrdiff_t nonemptymgi) -> int { | ||
| assert_testmodeonly(get_nonempty_npts_model() > 0); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,6 +25,7 @@ inline std::span<float> kappagrey_allcells; | |
| inline std::span<float> grey_depth_allcells; // Grey optical depth to surface of the modelgridcell | ||
| inline std::span<int> | ||
| thick_allcells; // whether the cell is optically thick (1) or not (0), or (2) thick for vpkts only | ||
| inline std::span<float> clumpfactor_allcells; | ||
|
|
||
| inline ptrdiff_t ngrid{0}; | ||
|
|
||
|
|
@@ -50,6 +51,7 @@ void set_elements_uppermost_ion(int nonemptymgi, int element, int uppermost_ion) | |
| [[gnu::pure]] [[nodiscard]] DEVICE_FUNC auto get_ffegrp(int modelgridindex) -> float; | ||
| [[gnu::pure]] [[nodiscard]] DEVICE_FUNC auto get_modelcell_mean_radial_pos(int modelgridindex, double tratmid) | ||
| -> double; | ||
| [[gnu::pure]] [[nodiscard]] DEVICE_FUNC auto get_modelcell_mean_radial_vel(int modelgridindex, double tmin) -> double; | ||
| void set_elem_abundance(std::ptrdiff_t nonemptymgi, int element, float newabundance); | ||
| [[gnu::pure]] [[nodiscard]] DEVICE_FUNC auto get_elem_numberdens(std::ptrdiff_t nonemptymgi, int element) -> double; | ||
| [[gnu::pure]] [[nodiscard]] DEVICE_FUNC auto get_initenergyq(int modelgridindex) -> double; | ||
|
|
@@ -76,6 +78,7 @@ void set_element_meanweight(std::ptrdiff_t nonemptymgi, int element, float meanw | |
| [[gnu::pure]] [[nodiscard]] DEVICE_FUNC auto get_numpropcells(int modelgridindex) -> int; | ||
| [[gnu::pure]] [[nodiscard]] DEVICE_FUNC auto get_nonemptymgi_of_mgi(int mgi) -> int; | ||
| [[gnu::pure]] [[nodiscard]] DEVICE_FUNC auto get_mgi_of_nonemptymgi(std::ptrdiff_t nonemptymgi) -> int; | ||
| [[nodiscard]] DEVICE_FUNC auto check_mgi_is_nonempty(int mgi, int& nonemptymgi) -> bool; | ||
| [[gnu::pure]] [[nodiscard]] DEVICE_FUNC auto get_modelgridtype() -> GridType; | ||
| [[gnu::pure]] [[nodiscard]] DEVICE_FUNC auto get_npts_model() -> int; | ||
| [[gnu::pure]] [[nodiscard]] DEVICE_FUNC auto get_nonempty_npts_model() -> int; | ||
|
|
@@ -93,6 +96,8 @@ void write_grid_restart_data(int timestep); | |
| [[nodiscard]] auto get_propcell_random_position_tmin(int cellindex) -> Vec3d; | ||
| [[nodiscard]] DEVICE_FUNC auto boundary_distance(const Vec3d& dir, const Vec3d& pos, double tstart, int cellindex) | ||
| -> std::tuple<double, int>; | ||
| void set_clumpfactor(int nonemptymgi, float vol_filling_factor); | ||
|
||
| [[gnu::pure]] [[nodiscard]] DEVICE_FUNC auto get_clumpfactor(int nonemptymgi) -> float; | ||
|
|
||
| [[nodiscard]] auto calculate_cell_kappagrey(int nonemptymgi) -> float; | ||
|
|
||
|
|
@@ -124,6 +129,15 @@ inline auto get_ejecta_kinetic_energy() { | |
| return E_kin; | ||
| } | ||
|
|
||
| // Applies the clumping factor to `val` if microclumping is being used | ||
| template <typename T> | ||
| inline auto apply_clumping(const T val, const float clumpfactor) -> T { | ||
| if constexpr (USE_MICROCLUMPING) { | ||
| return val * clumpfactor; | ||
| } | ||
| return val; | ||
|
||
| } | ||
|
|
||
| } // namespace grid | ||
|
|
||
| #endif // GRIDINIT_H | ||
Uh oh!
There was an error while loading. Please reload this page.
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.
I thought we had eliminated the need for file I/O using the artisoptions function? Can that be removed now?