Conversation
Code Review by GeminiHere is the code review for the pull request "Adding hydrostatic equilibrium". Physical & Numerical UnderstandingThis PR implements an iterative hydrostatic equilibrium loop for the gas disk structure coupled with vertical dust settling redistribution.
Key Findings1. CRITICAL: Stale
|
…cs for hydrostatic equilibrium - Per-iteration snapshots & restart: * Write Temperature_iterNNNN.fits.gz to data_th/ and gas_density_iterNNNN.fits.gz to data_disk/ after each iteration. * Automatically detect existing iterations on launch to resume hydrostatic calculations or load the converged state for post-processing (-img, -mol, etc.). * Defer writing Temperature.fits.gz and .sed_th.fits.gz until convergence, and add '!' prefix to prevent CFITSIO error 105. * Automatically create ./data_disk when hydrostatic equilibrium is enabled. - Diagnostics & CLI: * Add -n_iter_physics command-line option (default: 100). * Report real-time convergence progress: max |dT|/T with cell (i, j) coordinates and mean |dT|/T. * Compute vertical scale heights at Rref (H_68, H_mid, initial H0, H_rms, H_thermal) and local flaring index between 0.9 and 1.1 Rref. - Numerical & physics fixes: * Clamp gas_shape to >= 0 in get_gas_shape() to prevent negative base in strat exponentiation. * Use exact physical cell spacing dz = z(j) - z(j-1) in equilibre_hydrostatique().
Code Review by GeminiOverviewThis PR implements an iterative hydrostatic equilibrium loop for MCFOST, coupling the gas vertical density calculation to the thermal radiative transfer structure ( Overall, the physical model and numerical implementation are sound and well-thought-out. The vertical dust redistribution correctly conserves column mass, dimensional unit conversions are handled accurately, and the restart mechanism via iteration snapshots ( Below are a few issues identified during the review regarding memory persistence and potential floating-point division edge cases. Findings1.
|
Per-cell relative Tdust tolerance previously used a single flat threshold (hydrostatic_precision), which could block convergence when iteration- to-iteration differences are dominated by MC shot noise rather than real structural change. - Add lsave_n_packet_per_cell flag (parameters.f90), decoupled from lmcfost_lib, to gate per-cell photon-packet counting (xN_abs) in radiation_field.f90. Enabled for library mode (mcfost2phantom.f90, unchanged behaviour) and now also for hydrostatic equilibrium runs (dust_transfer.f90). - allocate_radiation_field_step1 allocates xN_abs for the standalone case; deallocate_radiation_field cleans it up. Library mode keeps its own allocation, sized on SPH particle count, untouched. - dust_transfer_sub: estimate the relative MC noise on Tdust per cell from its photon count in the current and previous iteration, combined in quadrature (sigma ~ 0.25 x sqrt(1/N_cur + 1/N_prev), following the T ~ E^(1/4) grey/LTE scaling). Relax the per-cell tolerance to 3*sigma when that exceeds hydrostatic_precision, capped at 30%, following Min et al. (2009, A&A 497, 155). Cells with fewer than 10 packets in either iteration fall back to the flat threshold, as before. - Log both the flat and noise-adjusted mean target alongside max/mean |dT|/T for visibility into how much the floor is engaging.
Code Review by GeminiHere is a code review of the pull request. Summary of AssessmentThis PR adds iterative gas hydrostatic equilibrium coupled with vertical dust settling and Monte Carlo thermal radiative transfer. Overall, the physical formulation and numerical convergence controls (under-relaxation, photon-noise floor adjustments, monotonicity enforcement) are well constructed. However, there are critical issues regarding silent output corruption for thermal SEDs, state persistence bugs in repeated/library executions, and a potential floating-point exception hazard. Key Findings & Recommendations1. CRITICAL: Thermal SED Output is Wiped in Hydrostatic Mode
if ((.not. lmcfost_lib) .and. lwrite) then
call ecriture_temperature(1)
call ecriture_sed(1)
endif
! Only reset SED arrays if they were written; otherwise let caller read them
if (lwrite) then
sed = 0.0; sed_q = 0.0; sed_u = 0.0; sed_v = 0.0
n_phot_sed = 0.0; n_phot_sed2 = 0.0; n_phot_envoyes = 0.0
sed_star = 0.0; sed_star_scat = 0.0; sed_disk = 0.0; sed_disk_scat = 0.0
endif2. HIGH: State Persistence & Out-of-Bounds Hazard in
|
Type of PR:
This adds new physics and implement an iterative loop to compute the hydrostatic equilibrium
Description:
Iterate between gas hydrostatic equilibrium, dust setlling and thermal calculations
Testing:
No tests yet
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? no