Conversation
754c6fb to
20025fc
Compare
|
Still in draft, but mostly for my own curiosity:
Some of the recent updates on the develop branch are showing up in the diff on this PR, which means something weird happened during rebasing. Shouldn't affect merging (since we squash merge anyway) but makes it a bit harder to read the diff. |
|
It never occurred to me to have a function in artisoptions. I don’t think that would restrict our ability to set the clumping factors in the way Stuart was thinking and it's obviously much more efficient. I will discuss it with him. Fv is for volume filling factor but was more of a place holder. Something more descriptive is probably the way to go. I think passing the clumping factor is easier, because it doesn’t require one to think about it each time those functions are used. But I have just noticed that right now I am applying the clumping factor at the return statement(s), but it would require less calls to And yes I messed up rebasing at some point, sorry about that! |
|
Ok, sounds good. For now, I recommend implementing it in the simplest way with the minimal code changes to give you the highest confidence that the solution is correct. After that, we can lock the checksums and make sure that the default case of constexpr float clumping_factor() {return 1.0} is being fully optimised out. The rate coefficients are called in tight loops in the macro atom and level pop solver are and fairly critical to performance. See ION_NLEVELS_EXCITED_NLTE() and NLEVELS_REQUIRETRANSITIONS() for examples of the constexpr functions. You should be able to pass in whatever you need (time_days, radial_velocity) as an argument, but if that's too limiting, you could use a #define that can call anything that is defined in the code. Let me know if you need any help with getting that to work. |
|
The way I have implemented it currently the clumping factors are read in during |
I don't think it's obvious which way to go on that, so choose with whichever you find easier to implement. There could be a performance benefit to storing and communicating the clumping factor of each cell if calculating them requires fetching several other numbers (e.g. the cell radial velocity is not stored directly, so has to be calculated from x-y-z coords, in case you want a radial dependence in the clumping factor), but I don't think it's easy to predict which will be faster. One nice thing about calculating it each time is that the compiler can see if your clump factor function always returns 1.00 and will just optimise it out without you having to have to define |
0e84ebc to
159fab8
Compare
233cf15 to
ff3ef72
Compare
b517d67 to
c01edb0
Compare
529e92d to
176a14b
Compare
268c5fa to
96acd97
Compare
428265c to
8e3dbf6
Compare
448d69a to
761eacd
Compare
…mping factor, as that is what is actually used in the calculations
…cells and tratmid. Add function to calculate mean radial velocity.
|
There are a few things copilot has brought up. I left the unresolved for you to have a look at. A couple of them I've left replies on explaining my thinking behind it. There are also a few things I want to check:
One last thing is because copilot automatically reviews, it comments on the same things multiple times and causes a lot of clutter and makes things difficult to follow. Is there a way to disable the automatic reviews? |
|
I’m on leave until April 20. If you’re reasonably confident that the implementation is correct then you can update the checksums to avoid breakage as you work on simplifying the design. |
| if constexpr (READ_VOLUME_FILLING_FACTORS_FROM_FILE) { | ||
| vol_filling_factors_file >> vol_filling_factor; | ||
|
|
There was a problem hiding this comment.
When READ_VOLUME_FILLING_FACTORS_FROM_FILE is enabled, vol_filling_factors_file >> vol_filling_factor is not checked for success. If the file has too few entries or the stream is in a bad state (e.g., a failed seekg()), vol_filling_factor will remain NaN and the subsequent set_clumpfactor() assertion will fail without clearly indicating an I/O/formatting problem. Consider asserting the stream state after the read (and/or before the read) to fail fast with a more diagnostic condition.
| if constexpr (READ_VOLUME_FILLING_FACTORS_FROM_FILE) { | |
| vol_filling_factors_file >> vol_filling_factor; | |
| if constexpr (READ_VOLUME_FILLING_FACTORS_FROM_FILE) { | |
| // Ensure the volume filling factors file stream is usable before reading | |
| assert_always(vol_filling_factors_file.is_open()); | |
| assert_always(!vol_filling_factors_file.bad()); | |
| vol_filling_factors_file >> vol_filling_factor; | |
| // Fail fast if the read did not succeed (e.g. EOF, format error, or prior bad state) | |
| assert_always(!vol_filling_factors_file.fail()); | |
| assert_always(!std::isnan(vol_filling_factor)); |
grid.h
Outdated
| template <typename T> | ||
| inline auto apply_clumping(const T val, const float clumpfactor) -> T { | ||
| if constexpr (USE_MICROCLUMPING) { | ||
| return val * clumpfactor; | ||
| } | ||
| return val; |
There was a problem hiding this comment.
No need to define a new function just to multiply two numbers together. Remove
grid.h
Outdated
| [[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); |
There was a problem hiding this comment.
The function is called set_clumpfactor but it takes a volume filling factor instead. Rename to 'set_vol_filling_factor' or take the clumping factor as an argument to be consistent.
| [[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; | ||
| } | ||
|
|
There was a problem hiding this comment.
Trivial function used only once. Inline at the call site.
| [[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; | ||
| } | ||
|
|
There was a problem hiding this comment.
Other parts of the code check if a cell is non-empty using the expression: grid::get_numpropcells(mgi) > 0
|
|
||
| constexpr bool USE_MICROCLUMPING = false; | ||
|
|
||
| constexpr bool READ_VOLUME_FILLING_FACTORS_FROM_FILE = false; |
There was a problem hiding this comment.
I thought we had eliminated the need for file I/O using the artisoptions function? Can that be removed now?
Microclumping
Function$f_v$ (in the interval $(0,1]$ ). These are used in $(1/f_v)$ .
volume_filling_factortakes time and radial velocity and returns a volume filling factorupdate_gridto set the clumping factorsVolume filling factors can instead be read from a file if
READ_CLUMIPNG_FACTORS_FROM_FILEistrue. File "clumping-factors.txt" is a table of floats formatted with%.6e. It has (num timesteps) rows and (num cells) cols. Will terminate immediately if file is expected but not found in any of the data folders.Storing Clumping Factors
New grid property
grid::clumpfactor_allcells. IfUSE_MICROCLUMPINGis set tofalseit is never allocated and a global clumping factor of1.is assumed.Using Clumping Factors
If microclumping is turned on
grid::apply_clumpingapplies the given clumping factor to the value. The processes impacted by microclumping are:Other processes are physically affected by clumping (e.g. non-thermal processes) but the effects balance eachother out so no changes are required.
Misc
Add function
grid::modelcell_mean_radial_velto calculate the radial velocity of a model grid cell.Add function
grid::check_mgi_is_nonemptyto determine if the cell with the given mgi is non-empty, and return the nonemptymgi if so.A (probably incomplete) list of things left to do
clumping-factors.txtexists incheck_microclumping_options()and terminate if it doesn't.artisoptions_doc.mdonce implementation is done.oneoverfvto something easier to read.Things which might be nice to do
clumping-factors.txt.