Repository navigation
Conversation
- MRW: fix make_MRW_step overwriting the packet y coordinate with sample_zeta; return the diffusive path length ct and an outward Lambertian surface direction around the sphere normal. Pre-invert y_MRW(zeta) by bisection using the Jacobi theta_4 identity for y > 0.5 (O(1) lookup, avoids cancellation and endpoint 0/0 or log(0)) - cylindrical_grid: fix sin_phi_lim = 1e300 sentinel at phi = pi/2, 3*pi/2; fix k0 = 1 out-of-bounds read in azimuthal wall distances and guard phi walls with l3D .and. n_az > 1; do not treat z = 0 as a cell wall in 2D midplane cells (j = 1); guard virtual cells - spherical_grid: use cos_theta_lim(abs(thetaj0)) instead of cos_phi_lim(thetaj0) (wrong array and out-of-bounds for nz > n_az or 3D z < 0 cells); handle polar-cap (abs(j) = nz) and 2D midplane cells - Voronoi: divide bisector distance by norm2(n) instead of |n|^2 (AU units) in double precision; return 0 on/outside faces, in star cells, and bound by stellar surfaces in star-neighbour cells - random_numbers, test_mrw: add init_random_streams helper and unit tests for the MRW kernel and nearest-wall distances against cross_cell ray sweeps on 2D/3D cylindrical, spherical, and 3D Voronoi grids
- Pre-tabulate Rosseland transport mean extinction chi_Rosseland_MRW(T, p_icell) and dB/dT-weighted mean absorption opacity kappa_abs_MRW(T, p_icell) in init_reemission (OpenMP-parallel init_MRW_opacities), ensuring exact single-pass Bjorkman & Wood energy balance and automatic refresh across hydrostatic, sublimation, and Phantom iterations - Add compute_MRW_opacities and eval_MRW_opacities_at_T with log-log temperature interpolation, applying kappa_factor(icell) to chi_trans_cell while keeping kappa_abs_ref in save_radiation_field's reference convention for xKJ_abs - Allocate and populate cell-averaged scattering asymmetry tab_g_pos during Step 1 for both full phase-function (aniso_method=1) and HG (aniso_method=2) modes, respecting lisotropic, lno_scattering, lphase_function_file, and empty cells - Initialize frac = 0.0_dp in Temp_LTE below the T_min floor and guard MRW table deallocation in deallocate_temperature_calculation and deallocate_thermal_emission - Extend test_suite/unit/test_mrw.f90 (88 assertions) to verify grey, anisotropic, analytical power-law (beta=2), kappa_factor/ldens0, and opacity-refresh cases
… options
- Declare logical :: lMRW in parameters.f90 (default .false. in init_mcfost.f90).
- Add CLI parsing for -mrw [gamma], -no_mrw, -no-mrw, -gamma_mrw, and -mrw_gamma.
- Condition MRW table allocations on (lRE_LTE .and. lMRW) in thermal_emission.f90
and tab_g_pos on ((aniso_method == 2) .or. (lTemp .and. lMRW)) in mem.f90.
- Wire active MRW loop into propagate_packet (src/dust_transfer.f90):
* Gating checks: lMRW, letape_th, lonly_LTE, .not. lmono, .not. lxJ_abs_step1,
.not. flag_star, .not. flag_ISM, n_iteractions_in_cell >= 3, valid icell.
* Jump radius safety margin (1 - 1e-5) * d to guarantee interior containment.
* Absorption deposition xKJ_abs += kappa_abs_ref * ct * Stokes(1) matching
save_radiation_field conventions.
* Live opacities update during diffusion stepping via compute_MRW_opacities.
* Exit state: LTE re-emission wavelength sampling, Stokes depolarisation
(Q=U=V=0), flag resets, and fresh optical depth generation.
- Add test_mrw_transport() in test_suite/unit/test_mrw.f90 covering gating,
wall safety across geometries, energy deposition, cell counting, exit
depolarisation, and a 3D transport acceleration benchmark (122/122 assertions pass).
…arks - Add test_suite/test_mrw.py covering CLI flag validation (-mrw, -no_mrw, -gamma_mrw), temperature accuracy (MC_similar within 0.03%), and ray-traced thermal SED consistency. - Add -gamma_mrw <gamma> description to display_help() in src/init_mcfost.f90. - Validate temperature profiles against published benchmark codes (MCMax, TORUS, MCFOST 2009) with < 1.1% median differences and < 2.6% in vertical cuts. - Benchmark runtime scaling across tau in [1e3, 1e6], demonstrating up to 4.1x speedup at tau=1e6 while preserving 0.2% temperature fidelity. - Verify full test suite passes under DEBUG=yes with -fbounds-check enabled.
…r positions - tab_g_pos keeps the dust model g(lambda) when a phase function file is given (the file is monochromatic, for images): a single g from the file was used at all wavelengths, also changing HG runs without MRW - distance_to_closest_wall_Voronoi: neighbour positions from the ordered cache or Voronoi_xyz, as in cross_Voronoi_cell, instead of the Voronoi derived type
…not trigger Pre-compute per cell an upper bound of the MRW transport opacity over the temperature grid (chi_max_MRW, 0 when d_max * chi_max <= gamma_MRW with d_max the radius of the volume-equivalent sphere). The temperature and the MRW opacities are only evaluated when d * chi_max_MRW > gamma_MRW. Temperatures are bit-identical; temperature step 8-15 % faster (Pinte 2009 tau=1e4, 1.28e6 packets, 1 thread). MRW: default gamma = 5, reproducible optically thick benchmark test gamma = 2 biases the temperature low by 6-9 % in the hot midplane cells just inside the dark zone (Pinte 2009 tau = 1e4 to 1e6), gamma = 5 reduces this to 2-4 % while keeping a 2.6-3.3x speed-up over standard MC at tau >= 1e5. The benchmark test now runs with a fixed seed on 1 thread.
…le_zeta sample_zeta checked an unsynchronised flag at every sample. The table is initialised in transfert_poussiere and now also in init_MRW_cells, which covers library mode.
…zeta The table of Min et al. (2009) Eq. 7 is only built in init_MRW_cells (standalone and library mode, only with -mrw): no longer computed in runs without MRW. sample_zeta stops with an error if the table is not initialised instead of returning an infinite step time. The unit tests calling make_MRW_step initialise the table themselves.
Code Review by GeminiSummary of ReviewThe pull request introduces the Modified Random Walk (MRW) algorithm (Min et al. 2009; Robitaille 2010) to accelerate Monte Carlo temperature calculations in optically thick grid regions across cylindrical, spherical, and 3D Voronoi geometries. Overall, this is an exceptionally high-quality PR:
Detailed Findings1. Numerical Stability & Zeta Sampling
2. Grid Geometry & Nearest-Wall Distance
3. OpenMP & Thread Safety
ConclusionThe PR is mathematically sound, numerically stable, thread-safe, and thoroughly tested. It is safe to merge. |
The MRW exit time now uses an absorbing boundary at R0 + 0.7104/chi (Milne extrapolation length) and the exit direction follows the exact sphere walk (ballistic escapes, forward peak, mu (1 + 1.5 mu) for large spheres). Steps are no longer chained within a cell: a chained step loses the outward direction of the packet and, with the extrapolated boundary, over-deposits (+16 % in energy at gamma 2 in a grey slab). Pinte 2009 tau 1e5-1e6: band temperature bias -7 % -> -2 % at gamma 2, -2.7 % -> within noise at gamma 5, same run time. -mrw_chain <0|1|2> kept for testing. Unit tests: exit cosine and mean path against an exact walk at gamma 2, 5, 10.
cross_spherical_cell: at a midplane crossing (lower theta wall of |thetaj| = 1, z = 0 in double precision) the hemisphere was taken from the sign of z1, zero up to rounding; it now follows the direction of the packet, and z1 is placed on that side. New unit check (failed on gfortran and ifort with the old code). MRW unit test: run single-threaded (nb_proc = 1 sized arrays were overrun by the OpenMP loop of init_reemission: intermittent heap corruption on macOS arm). Exit-law peak fraction refitted (exit_peak_fraction, <mu> within 0.0015 of the exact walk for gamma 2-20). test_mrw.py: compiler-independent check of the gamma output, no 120 s timeout (macOS Intel runners).
Code Review by GeminiPhysical / Numerical PurposeThe changes introduce a Modified Random Walk (MRW) acceleration scheme (Min et al. 2009; Robitaille 2010) to the Monte Carlo thermal equilibrium calculation. In optically thick cells ( Code Review Findings1. High-Performance & Parallel Computing
2. Numerical Precision & Stability
3. Grid Geometry & Radiative Transfer Physics
4. Testing & Verification
Recommendations / Minor Suggestions
Summary & Conclusion
|
|
ERROR: # Code Review by Gemini |
The MRW step assumes an isotropic start with the re-emission spectrum. After a scattering by forward-scattering dust the packet still carries the direction of the net flux over about one transport mean free path, which an isotropic restart loses (-10 % in energy, -2.4 % in T at gamma 2 in an irradiated slab with live temperatures; -0.2 % with the new trigger). The trigger now also requires .not. flag_scatt. -mrw_after_scatt restores the old trigger (testing). Pinte 2009 disc, gamma 2, temperature bias (band mean inside the dark-zone edge): -2.0 -> +0.1 % (tau 1e5), -1.8 -> +0.9 % (tau 1e6, 6 seeds); gamma 5 unchanged. Run time of the temperature calculation +3-10 % at gamma 2, unchanged at gamma 5.
Code Review by GeminiHere is a code review for the Modified Random Walk (MRW) pull request. Overall AssessmentThe PR introduces a Modified Random Walk (MRW) implementation to accelerate Monte Carlo radiative transfer in optically thick regions, along with updates to wall-distance algorithms across cylindrical, spherical, and Voronoi grids. The core Fortran MRW logic and numerical transport routines are well-designed and covered by comprehensive unit/integration tests. However, there are a few issues—most notably a truncated Key Findings & Action Items1. Truncated CMake File
2. Missing C++ Header (
|
Type of PR:
Bug fix / modification to existing code
Description:
Modified Random Walk (MRW) for the temperature calculation
Adds an optional Modified Random Walk (Min et al. 2009, Robitaille 2010) to the
Monte Carlo temperature calculation: in optically thick cells, packets move by
diffusion steps to the cell wall instead of individual interactions. Energy is
deposited with a dB/dT-weighted absorption opacity, consistent with the
Bjorkman & Wood re-emission.
Off by default.
off with non-equilibrium grains or PAHs).
tau = 1e5-1e6, 2.4x at tau = 1e9. Temperatures agree with standard MC
within noise, except the last midplane cells before the dark zone (2-4 % low
at gamma = 5). With -diff_approx, this offset propagates into the dark zone
(-0.7 to -1.8 % on average): use gamma = 10 or no MRW for benchmark-quality
dark-zone temperatures.
opacities) and integration tests against standard MC.
Testing:
Updated unit and integration tests
Did you run the botscheck that the code and comments follow the code of conduct? yes
Did you update relevant documentation in the docs directory? yes