Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/simulation/m_start_up.fpp
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ contains
end if

! Write IB kinematic state for restart
if (ib) call s_write_ib_state_file(t_step)
if (ib) call s_write_ib_state_file(save_count)

call nvtxEndRange
call cpu_time(finish)
Expand Down Expand Up @@ -914,9 +914,13 @@ contains

if (model_eqns == 3) call s_initialize_internal_energy_equations(q_cons_ts(1)%vf)
if (ib) then
if (t_step_start > 0) call s_read_ib_restart_data(t_step_start)
if (cfl_dt .and. n_start > 0) then
call s_read_ib_restart_data(n_start)
else if (t_step_start > 0) then
call s_read_ib_restart_data(t_step_start)
end if
call s_ibm_setup()
if (t_step_start == 0) then
if (t_step_start == 0 .or. (cfl_dt .and. n_start == 0)) then
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Look for how t_step_start interacts with cfl_dt / n_start during input assignment and validation
rg -nP --type=fortran -C3 '\bt_step_start\b' src/common src/simulation | rg -nP -C3 '(cfl_dt|n_start|dflt|default|assign)'
rg -nP --type=fortran -C3 '\bn_start\b' src/common src/simulation | rg -nP -C3 '(cfl_dt|t_step_start|dflt|default|assign)'
# Default value for t_step_start
ast-grep --pattern 't_step_start = $_'

Repository: MFlowCode/MFC

Length of output: 325


🏁 Script executed:

# Find default value of t_step_start in module declarations
rg -nP --type=fortran 't_step_start\s*=' src/common src/simulation | grep -i 'default\|init\|=\s*0'

# Look at context around line 923 in m_start_up.fpp
sed -n '915,935p' src/simulation/m_start_up.fpp

# Find how n_start and t_step_start are used in cfl_dt logic
rg -nP --type=fortran -B5 -A5 'if.*cfl_dt' src/simulation/m_start_up.fpp | head -60

# Search for input assignment routines
fd -e fpp -e f90 'assign.*default\|assign.*input' src/

Repository: MFlowCode/MFC

Length of output: 3582


🏁 Script executed:

# Find where t_step_start is declared and initialized
rg -nP --type=fortran 'integer.*::.*t_step_start|t_step_start\s*=' src/common src/simulation | head -20

# Find where n_start is declared and initialized
rg -nP --type=fortran 'integer.*::.*n_start|n_start\s*=' src/common src/simulation | head -20

# Look for input assignment/validation routines
fd -e fpp -e f90 . src/common src/simulation | xargs rg -l 's_assign_default\|s_read.*input\|s_initialize.*input' | head -5

# Check if there's any synchronization logic between cfl_dt mode and these variables
rg -nP --type=fortran -B3 -A3 'n_start.*t_step_start|t_step_start.*n_start' src/

Repository: MFlowCode/MFC

Length of output: 39


🏁 Script executed:

# Search more carefully for declarations and defaults
rg -nP 't_step_start' src/simulation/m_start_up.fpp | head -10

# Look for module variable declarations (usually at top)
head -100 src/simulation/m_start_up.fpp | grep -n 'integer\|real\|logical'

# Check global variables module
rg -nP 't_step_start' src/common/m_global_variables.fpp

# Check Python input case
rg -nP 't_step_start\|n_start' toolchain/mfc/state.py | head -20

Repository: MFlowCode/MFC

Length of output: 1261


🏁 Script executed:

# Look at the top of m_start_up.fpp for module declarations and USE statements
head -50 src/simulation/m_start_up.fpp

# Find where these globals are declared - likely in another module
rg -nP 'integer.*t_step_start|integer.*n_start' src/ --type=fortran | grep -v 'intent\|character\|write'

# Check if they're in a global_variables type module
fd -e fpp -e f90 . src/common | xargs rg -l 't_step_start\|n_start'

Repository: MFlowCode/MFC

Length of output: 1084


🏁 Script executed:

# Find m_global_parameters module
fd -e fpp -e f90 m_global_parameters src/

# Search for t_step_start and n_start declarations
rg -nP 't_step_start|n_start' src/common/m_global_parameters.fpp | head -30

Repository: MFlowCode/MFC

Length of output: 270


🏁 Script executed:

# Search for t_step_start and n_start in the simulation module
rg -nP 't_step_start|n_start' src/simulation/m_global_parameters.fpp | head -50

# Look for initialization/default values
rg -nP -B2 -A2 't_step_start\s*=|n_start\s*=' src/simulation/m_global_parameters.fpp

Repository: MFlowCode/MFC

Length of output: 481


🏁 Script executed:

# Find what dflt_int is set to
rg -nP 'dflt_int\s*=' src/simulation/m_global_parameters.fpp

# Also check if there's input reading/assignment that explicitly sets these for restart cases
rg -nP -B5 -A5 's_read_input_file|s_assign_default' src/simulation/m_start_up.fpp | head -40

Repository: MFlowCode/MFC

Length of output: 1614


🏁 Script executed:

# Search for dflt_int definition across all source files
rg -nP 'parameter.*dflt_int|dflt_int\s*=\s*' src/ --type=fortran | head -20

# Look at s_read_input_file to understand input assignment
sed -n '75,150p' src/simulation/m_start_up.fpp

# Search for where t_step_start and n_start are set from input
rg -nP 't_step_start\s*=|n_start\s*=' src/simulation/m_start_up.fpp

Repository: MFlowCode/MFC

Length of output: 3817


🏁 Script executed:

# Find dflt_int definition - likely in parameters module
rg -nP 'parameter.*dflt_int' src/ --type=fortran

# Also check what value it gets set to
rg -nP 'dflt_int' src/pre_process/m_global_parameters.fpp | head -5

Repository: MFlowCode/MFC

Length of output: 231


🏁 Script executed:

# Search for dflt_int parameter definition
rg -nP 'integer.*parameter.*dflt_int|dflt_int.*=' src/simulation/m_global_parameters.fpp | grep -v 't_step\|n_start'

# Check parameter declarations at the top of the module
head -200 src/simulation/m_global_parameters.fpp | grep -n 'parameter\|dflt'

Repository: MFlowCode/MFC

Length of output: 2842


🏁 Script executed:

# Search directly for dflt_int as a named constant
rg -nP 'dflt_int' src/simulation/m_global_parameters.fpp | grep 'parameter\|integer.*dflt'

# Also check if it's imported from elsewhere or defined in a common parameters file
rg -nP 'dflt_int' src/ --type=fortran | grep -i 'parameter\|=-\|=0'

Repository: MFlowCode/MFC

Length of output: 39


🏁 Script executed:

# Look at the actual definitions in the module - search broadly
rg -nP 'dflt' src/simulation/m_global_parameters.fpp | head -20

# Check if it's a Fypp macro
grep -n 'dflt_int' src/simulation/m_global_parameters.fpp | head -10

Repository: MFlowCode/MFC

Length of output: 1092


🏁 Script executed:

# Check the includes at the top - case.fpp and macros.fpp
cat src/simulation/case.fpp | head -50

# Also check macros
cat src/common/include/macros.fpp | grep -n 'dflt'

Repository: MFlowCode/MFC

Length of output: 113


🏁 Script executed:

# Look for case.fpp in include directory
find src -name 'case.fpp' -o -name 'macros.fpp'

# Search for dflt_int definition in include files
find src -name '*.fpp' -o -name '*.fpp' | xargs rg -l 'dflt_int'

# Check if dflt_int is set to a specific value
rg -nP '#:set|dflt_int\s*:=' src/

Repository: MFlowCode/MFC

Length of output: 35019


🏁 Script executed:

# Search for dflt_int definition in macros.fpp
rg -nP 'dflt_int' src/common/include/macros.fpp

# Also check case.fpp
rg -nP 'dflt_int' src/common/include/case.fpp

Repository: MFlowCode/MFC

Length of output: 39


🏁 Script executed:

# Search for dflt_int across the entire codebase more carefully
rg 'dflt_int' src/ --type=fortran -C1 | grep -E '(parameter|integer|=)' | head -20

# Look at what the actual value would be - search in Python/config
rg 'dflt_int|default.*int' toolchain/ | head -10

# Check if it's defined via preprocessing - look at the actual generated file
rg -nP 'integer.*parameter' src/simulation/m_global_parameters.fpp | head -20

Repository: MFlowCode/MFC

Length of output: 1780


Mode-exclusive check needed for initial IBM file writes in cfl_dt restart.

The disjunction at line 923 is mode-agnostic: t_step_start == 0 .or. (cfl_dt .and. n_start == 0) short-circuits on the first clause. When restarting with cfl_dt=true and n_start > 0, if t_step_start remains at its default value, the first clause evaluates true and the branch overwrites ib_data_0/ib_state_0 files with initial state, clobbering the restart data.

The restart read logic (lines 920–922) correctly branches on cfl_dt: use n_start when enabled, else use t_step_start. The write condition must follow the same pattern:

🛠️ Proposed fix
-            if (t_step_start == 0 .or. (cfl_dt .and. n_start == 0)) then
+            if ((cfl_dt .and. n_start == 0) .or. &
+                (.not. cfl_dt .and. t_step_start == 0)) then
                 call s_write_ib_data_file(0)
                 call s_write_ib_state_file(0)
             end if
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (t_step_start == 0 .or. (cfl_dt .and. n_start == 0)) then
if ((cfl_dt .and. n_start == 0) .or. &
(.not. cfl_dt .and. t_step_start == 0)) then

call s_write_ib_data_file(0)
call s_write_ib_state_file(0)
end if
Expand Down
Loading