Skip to content

Commit 0b563a4

Browse files
committed
fix(com1DFA): handle dtSave updates correctly for initial timestep export
- Store original `dtSave` to ensure accurate initial timestep decisions. - Update `dtSave` only after initial timestep export to avoid unintended modifications. - Improve readability of conditions by explicitly referencing `dtSaveOriginal`. Root Cause: The code uses dtSave for two decisions but modifies it between them: 1. Line 2107: Checks if dtSave contains t=0 → decides to export initial timestep 2. Line 2114: Calls updateSavingTimeStep() which modifies dtSave (changes [0] to [2*tEnd]) 3. Line 2142: Checks dtSave again → decides whether to add t=0 to Tsave array The Problem: When tSteps = "0": - Line 2107 check passes → exports t=0 - Line 2114 modifies dtSave from [0] to [2*tEnd] - Line 2142 check fails → Tsave remains empty - Result: t=0 was exported but not tracked in Tsave (inconsistency) Proposed Fix: ✓ CORRECT The fix saves the original dtSave before modifications and uses it for both decisions. This ensures consistency between the export and Tsave array decisions.
1 parent 2f1755f commit 0b563a4

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

avaframe/com1DFA/com1DFA.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2103,15 +2103,21 @@ def DFAIterate(cfg, particles, fields, dem, inputSimLines, outDir, cuSimName, si
21032103
outDirData = outDir / "particles"
21042104
fU.makeADir(outDirData)
21052105

2106-
# export initial time step only if t=0 is explicitly in dtSave
2107-
if cfg["EXPORTS"].getboolean("exportData") and (dtSave.size > 0 and np.any(dtSave <= 1.0e-8)):
2106+
# Save original dtSave for initial timestep decisions
2107+
dtSaveOriginal = dtSave.copy()
2108+
2109+
# export initial time step only if t=0 is explicitly in dtSaveOriginal
2110+
if cfg["EXPORTS"].getboolean("exportData") and (
2111+
dtSaveOriginal.size > 0 and np.any(dtSaveOriginal <= 1.0e-8)
2112+
):
21082113
exportFields(cfg, t, fields, dem, outDir, cuSimName, TSave="initial")
21092114

21102115
if "particles" in resTypes:
21112116
savePartToPickle(particles, outDirData, cuSimName)
21122117

21132118
# Update dtSave to remove the initial timestep we just saved
2114-
dtSave = updateSavingTimeStep(dtSave, cfgGen, t)
2119+
dtSave = updateSavingTimeStep(dtSaveOriginal, cfgGen, t)
2120+
21152121

21162122
# export particles properties for visulation
21172123
if cfg["VISUALISATION"].getboolean("writePartToCSV"):
@@ -2139,10 +2145,11 @@ def DFAIterate(cfg, particles, fields, dem, inputSimLines, outDir, cuSimName, si
21392145
cfgRangeTime["GENERAL"]["simHash"] = simHash
21402146

21412147
# add initial time step to Tsave array only if it was exported
2142-
if dtSave.size > 0 and np.any(dtSave <= 1.0e-8):
2148+
if dtSaveOriginal.size > 0 and np.any(dtSaveOriginal <= 1.0e-8):
21432149
Tsave = [0]
21442150
else:
21452151
Tsave = []
2152+
21462153
# derive time step for first iteration
21472154
if cfgGen.getboolean("sphKernelRadiusTimeStepping"):
21482155
dtSPHKR = tD.getSphKernelRadiusTimeStep(dem, cfgGen)

0 commit comments

Comments
 (0)