Skip to content

fix(ibm): fix IB restart and state output for adaptive-dt (cfl_dt) runs#1382

Draft
mrvandenboom wants to merge 1 commit intoMFlowCode:masterfrom
mrvandenboom:ib-restart-fix
Draft

fix(ibm): fix IB restart and state output for adaptive-dt (cfl_dt) runs#1382
mrvandenboom wants to merge 1 commit intoMFlowCode:masterfrom
mrvandenboom:ib-restart-fix

Conversation

@mrvandenboom
Copy link
Copy Markdown
Contributor

Description

Summarize your changes and the motivation behind them.

Fixes issue where MFC does not find the restart file for adaptive time stepping runs. The issue was the conditional variable that only is present when doing fixed time stepping. Added a conditional statement to work with both time stepping modes.

Also changed the save points to occur on "save count" vs "time step".

Type of change

  • [ X] Bug fix
  • New feature
  • Refactor
  • Documentation
  • Other: describe

Testing

Ran single test case.

Checklist

  • I added or updated tests for new behavior
  • I updated documentation if user-facing behavior changed
GPU changes (expand if you modified src/simulation/)
  • GPU results match CPU results
  • Tested on NVIDIA GPU or AMD GPU

AI code reviews

@coderabbitai review
@claude full review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 27, 2026

📝 Walkthrough

Walkthrough

The pull request modifies the immersed boundary (IB) restart-state persistence logic in src/simulation/m_start_up.fpp. During save operations, IB state now keys off save_count (computed from mytime/t_save when cfl_dt is enabled, otherwise from t_step) to align with other output restart identifiers. Initialization logic for reading IB restart data is updated to select between n_start (when cfl_dt is enabled) and t_step_start (otherwise). The fresh-start detection for initial IB file writing is expanded to include the case (cfl_dt && n_start == 0) alongside the existing t_step_start == 0 condition. No public entity signatures changed.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main fix: adapting IB restart and state output logic for adaptive time-stepping (cfl_dt) runs, matching the core changeset.
Description check ✅ Passed The description covers the bug fix with adequate context about the adaptive time-stepping issue and save-count changes, though it lacks specific testing details and doesn't mark the GPU checklist items.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: bd6de904-3d92-43c3-b561-e70688cc245c

📥 Commits

Reviewing files that changed from the base of the PR and between be1e665 and 64b65de.

📒 Files selected for processing (1)
  • src/simulation/m_start_up.fpp

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

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 27, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 64.76%. Comparing base (be1e665) to head (64b65de).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1382      +/-   ##
==========================================
- Coverage   64.76%   64.76%   -0.01%     
==========================================
  Files          71       71              
  Lines       18713    18715       +2     
  Branches     1549     1549              
==========================================
+ Hits        12119    12120       +1     
- Misses       5638     5640       +2     
+ Partials      956      955       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sbryngelson sbryngelson marked this pull request as draft April 27, 2026 15:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant