refactor(tr): split trcomm.f90 into 6 logical submodules (Phase 2)#11
Conversation
Split the 817-line monolithic MODULE TRCOMM into six logical submodules
per Phase 2 of the TR refactoring design (spec section 5.2):
trcomm_const - physical constants (PI, AEE, AME, AMM, VC, RMU0,
EPS0, RKEV, NPSCM, VOID)
trcomm_param - namelist input parameters (RR, RA, BB, DT, profile
shape parameters, model selection MDL*, source/heating
parameters PNB*/PEC*/PLH*/PIC*/PEL*, etc.)
trcomm_ctrl - control variables (NT, NRAMAX, NTMAX_SAVE, T, IREAD,
PNSS, equation-selection NSS/NSV/NNS/NST/NEA, MDLEQ*,
UFILE control MDLUF/MDLXP/etc., file-name strings)
trcomm_mtx - matrix variables (XV, YV, AY, Y, ZV, AZ, Z, AX, X)
trcomm_profile - profile/source/coefficient/equilibrium/NCLASS/UFILE
storage/graphic/Honda-additional plasma variables
(RN, RT, AJ, RG, BP, QP, AK, ETA, RHO* metrics, AKDW*,
GRM/GVR graphic arrays, etc.)
trcomm_globals - derived global quantities (WPT, AJT, BETA0, TAUE1,
ANS0, TS0, WST, etc.)
MODULE TRCOMM is now a thin wrapper that USEs all six submodules and
re-exports their PUBLIC entities, so existing callers (`USE TRCOMM` and
`USE TRCOMM, ONLY: ...`) compile unchanged. ALLOCATE_TRCOMM /
DEALLOCATE_TRCOMM dispatch in dependency order to per-submodule
allocate/deallocate routines that preserve the original allocation
behaviour exactly.
Verification: tr_m0904 regression metrics match pre-Phase-2 baseline
within 1e-10 (compare_metrics.py). No other tr/*.f90 callers were
modified.
Spec: docs/superpowers/specs/2026-04-17-tr-refactoring-design.md (5.2)
|
@cursor review |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit a848ae3. Configure here.
|
Added Phase 2 submodule unit tests in 14 tests, all PASS:
Each submodule's Build + run: cd tr/tests/submodule_unit
make run # 'OK: all 14 submodule tests passed' / STOP 0Verified locally: Re-running @cursor review. |
…odule)
Each new TRCOMM submodule (trcomm_const, trcomm_param, trcomm_ctrl,
trcomm_mtx, trcomm_profile, trcomm_globals) gets its allocate/
deallocate routine exercised in isolation by a standalone Fortran
test program in tr/tests/submodule_unit/.
The driver wires up TRCOM0 sizing variables itself (mirroring the
derivation logic from ALLOCATE_TRCOMM) and then calls the per-submodule
allocate/deallocate routines directly. This catches regressions if
future Phase L work changes a single submodule independently.
Coverage: 14 tests total (smoke checks for const/param + alloc/dealloc/
idempotent/shape for each allocating submodule). Run with:
cd tr/tests/submodule_unit && make run
Expected: 'OK: all 14 submodule tests passed' / STOP 0.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
@cursor review |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 1b6fe5f. Configure here.
Summary
Phase 2 of the TR refactoring (spec section 5.2): split the 817-line monolithic
MODULE TRCOMM(~580 declared symbols) into six logical submodules.trcomm_constPI,AEE,AME,AMM,VC,RMU0,EPS0,RKEV,NPSCM,VOID)trcomm_paramRR,RA,BB,DT, profile shape, model selection, source/heatingPNB*/PEC*/PLH*/PIC*/PEL*, etc.)trcomm_ctrlNT,NRAMAX,NTMAX_SAVE,T,IREAD,PNSS, equation-selectionNSS/NSV/NNS/NST/NEA,MDLEQ*, UFILE control, file-name strings)trcomm_mtxXV,YV,AY,Y,ZV,AZ,Z,AX,X)trcomm_profiletrcomm_globalsWPT,AJT,BETA0,TAUE1,ANS0,TS0,WST, etc.)MODULE TRCOMMbecomes a thin wrapper thatUSEs all six submodules and re-exports their PUBLIC symbols. Existing callers usingUSE TRCOMMorUSE TRCOMM, ONLY: SOME_SYMBOL(including the four files updated in PR #4 plus all othertr/*.f90) compile unchanged.ALLOCATE_TRCOMM/DEALLOCATE_TRCOMMdispatch in dependency order to per-submoduleallocate_<name>/deallocate_<name>/deallocate_err_<name>routines that preserve the original allocation behaviour exactly (PNSS-allocation guard, sizing variablesNSTMAX/NEQMAXM/NVM/MWM/MLM/NRMP/NGLF/LDABstill set in the wrapper).Files
tr/trcomm_const.f90,tr/trcomm_param.f90,tr/trcomm_ctrl.f90,tr/trcomm_mtx.f90,tr/trcomm_profile.f90,tr/trcomm_globals.f90tr/trcomm.f90(wrapper, 817 -> 137 lines)tr/Makefile(SRCMextended; per-file deps for new submodules added)tr/*.f90files touched.Test plan
cd tr && make-- builds clean (tr2produced)OK: metrics match within tol=1e-10tr/*.f90callers (PR refactor(tr): Phase 1 - add ONLY clauses to USE TRCOMM (4 files) #4USE TRCOMM, ONLY:clauses still work)Spec:
docs/superpowers/specs/2026-04-17-tr-refactoring-design.mdsection 5.2.Note
Medium Risk
Moderate risk because it refactors a central shared state module and rewires allocation/deallocation paths; mistakes could surface as runtime allocation errors despite intent to preserve behavior.
Overview
Refactors
MODULE TRCOMMinto 6 new modules (trcomm_const,trcomm_param,trcomm_ctrl,trcomm_mtx,trcomm_profile,trcomm_globals) and turnstrcomm.f90into a wrapper thatUSEs them and re-exports symbols.Reworks memory lifecycle:
ALLOCATE_TRCOMM,DEALLOCATE_TRCOMM, andDEALLOCATE_ERR_TRCOMMnow delegate to per-submoduleallocate_*/deallocate_*/deallocate_err_*routines (with deallocation reversed by dependency).Build/test updates:
tr/Makefileis updated to compile the new submodule sources with explicit object dependencies, and a newtr/tests/submodule_unitharness is added to smoke-test constants/params and verify alloc/dealloc, idempotency, and array shapes for each allocatable submodule.Reviewed by Cursor Bugbot for commit 1b6fe5f. Bugbot is set up for automated code reviews on this repo. Configure here.