Skip to content

Solid Particle Implementation for E-L Solver#1301

Draft
JA0307 wants to merge 12 commits intoMFlowCode:masterfrom
JA0307:MovingParticlesFresh-Final
Draft

Solid Particle Implementation for E-L Solver#1301
JA0307 wants to merge 12 commits intoMFlowCode:masterfrom
JA0307:MovingParticlesFresh-Final

Conversation

@JA0307
Copy link

@JA0307 JA0307 commented Mar 11, 2026

Description

This update expands upon the pre-existing (in development) E-L solver for bubble dynamics to include solid particle dynamics. This is in support of the PSAAP center, which requires the capability to model solid particle dynamics in MFC.

Type of change

  • New feature
  • Refactor

Testing

The solver has been tested by running various 2D/3D problems involving fluid-particle interactions, such as spherical blasts surrounded by a layer of particles, shock-particle curtains, collision tests, etc.

The inputs to the EL solid particle solver have all been turned on/off to verify they work independent of each other, and together.

The code has been tested for CPU and GPU usage. The GPU usage has been tested on Tuolumne.

Two new files have been added:

m_particles_EL.fpp
m_particles_EL_kernels.fpp
File 1 has the main particle dynamics subroutines. This initializes the particles, computes fluid forces, coupling terms, computes collision forces, enforces boundary conditions, and writes the data for post-processing.

File 2 has the gaussian kernel projection code and the subroutine to compute the force on the particle due to the fluid. This compute the quasi-steady drag force, pressure gradient force, added mass force, stokes drag, gravitational force. Models for the quasi-steady drag are implemented here.

Checklist

  • I added or updated tests for new behavior
  • I updated documentation if user-facing behavior changed

See the developer guide for full coding standards.

GPU changes (expand if you modified src/simulation/)
  • GPU results match CPU results
  • Tested on NVIDIA GPU or AMD GPU

AI code reviews

Reviews are not triggered automatically. To request a review, comment on the PR:

  • @coderabbitai review — incremental review (new changes only)
  • @coderabbitai full review — full review from scratch
  • /review — Qodo review
  • /improve — Qodo code suggestions

jaguilar added 4 commits March 16, 2026 16:03
This adds checks for particles_lagrange wherever "bubbles_lagrange is checked
Variables for lagrangian solid particles are implemented
This adds two files to MFC. This includes src/simulation/m_particles_EL.fpp and src/simulation/m_particles_EL_kernels.fpp, which are used to compute particle dynamics, collisions, source terms, drag, integrate particle positions, etc.
…ication

This implements mpi communication of collision forces with ghost particles in simulation/m_mpi_proxy.fpp

The particle transfer between mpi ranks is made to support a "ghost" region and only the physical mpi domain. The ghost transfer is done when collisions are being computed. The physical transfer is done for true particle ownership.
This commit adds files necessary for compiling and running the EL particle solver. These files/changes are not part of this specific feature development. These changes are part of the MovingBubblesFresh commits.

Since this feature for moving solid lagrangian particles is a fork of the MovingBubblesFresh development fork, it has inherent dependencies. When MovingBubblesFresh gets merged into MFC, this commit will be irrelevant.
@sbryngelson sbryngelson force-pushed the MovingParticlesFresh-Final branch from a2bf4ac to e527f8f Compare March 16, 2026 20:08
@github-actions
Copy link

github-actions bot commented Mar 16, 2026

Claude Code Review

Incremental review from: e527f8f
Head SHA: 069237f

Previously-flagged issues addressed in this update: save variable, bare float literals in all four drag functions, kahan_comp dead code, weights_*_grad missing deallocations, stage missing intent, 5.0d-11 literal, bub_pp broadcast restoration, s_mpi_reduce_int_sum non-MPI path, s_transfer_collision_forces non-MPI path, hardcoded viscosity (conditionally fixed).


New findings since last Claude review

[HIGH] Declaration-after-executable-statement: Fortran syntax error in MPI builds
src/common/m_mpi_common.fpp, around the new bubs_glb = 0 line

The fix initializes bubs_glb before the #ifdef MFC_SIMULATION / #ifdef MFC_MPI-guarded local variable declarations (integer :: ierr, etc.). In a simulation+MPI build, the preprocessor expands to:

bubs_glb = 0           ! ← executable statement
integer :: ierr        ! ← local declaration after executable: Fortran syntax error
integer :: i, j, k, ...

Per the Fortran standard, all declarations must precede the first executable statement in a scoping unit. Move bubs_glb = 0 to after all local variable declarations (i.e., after the #ifdef-guarded block).


Remaining from prior review (not re-examined here): vL_x/vL_y/vL_z/vR_x/vR_y/vR_z intent(inout)→intent(in), case_validator.py entries for new parameters.

sbryngelson and others added 2 commits March 16, 2026 16:51
- Remove forbidden save variable (next_write_time)
- Add _wp suffixes to all bare float literals in drag correlations
- Fix d-exponent literal (5.0d-11 -> 5.0e-11_wp)
- Add missing @:DEALLOCATE for weights_*_grad arrays
- Add intent(in) on stage parameter
- Use fluid_pp Re when viscous=T instead of hardcoded viscosity
- Remove dead kahan_comp array (allocated/zeroed/freed, never read)
- Initialize bubs_glb=0 before conditional MPI reduce
- Add #else branch to s_mpi_reduce_int_sum for non-MPI builds
- Add #ifdef MFC_MPI guards to s_transfer_collision_forces
- Restore accidentally deleted bub_pp broadcasts in pre_process

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Fix *2 -> **2 typo in Osnes drag volume fraction correction (QS_ModifiedParmar, QS_Osnes)
- Fix MPI request buffer overflow in s_transfer_collision_forces (2*MAX_NEIGHBORS local arrays)
- Uncomment GPU_ROUTINE on s_fornberg_weights (called from GPU parallel loops)
- Add gauSum <= 0 guard to prevent division by zero in gaussian smearing
- Add rho_fluid > 0 guard for sound speed computation
- Add bounds limits to s_locate_cell while loops to prevent GPU hangs
- Fix bare 0. literal to 0._wp for precision discipline
- Fix 0._wp assigned to integer part_id
- Remove implicit save from local logicals (separate declaration from init)
- Re-enable particle radius NaN/negative validation in m_start_up
- Fix rad**3._wp to rad**3 for consistency and efficiency

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions
Copy link

Claude Code Review

Incremental review from: 069237f
Head SHA: 3c49f42

Previously-flagged issues addressed or carried forward: The declaration-after-executable bug (bubs_glb = 0 before integer :: ierr) flagged in the last review is still present in this commit — see [HIGH] below. The prior remaining note about vL_x/vL_y/vL_z/vR_x/vR_y/vR_z intent(inout)→intent(in) is now re-examined and partially confirmed for the new s_gradient_field in m_particles_EL.fpp — same finding applies there.


Findings since last Claude review

[HIGH] Declaration-after-executable still present — Fortran standard violation
src/common/m_mpi_common.fpp, s_mpi_reduce_stability_criteria_extrema

This was flagged in the previous review and remains unfixed. In an MFC_SIMULATION + MFC_MPI build the preprocessor expands to:

bubs_glb = 0           ! ← executable statement
! ...
integer :: ierr        ! ← local declaration AFTER executable: illegal per Fortran standard

Fix: move bubs_glb = 0 to after the #ifdef MFC_SIMULATION / #ifdef MFC_MPI guard block (i.e., after all local variable declarations), or restructure so the #ifdef-guarded integer :: ierr block comes first.


[MEDIUM] beta_vars allocated but never deallocated in pre_process and post_process

In src/pre_process/m_global_parameters.fpp and src/post_process/m_global_parameters.fpp, beta_vars is allocated (via bare allocate, not @:ALLOCATE) in s_compute_derived_variables when bubbles_lagrange or particles_lagrange is true, but s_finalize_global_parameters_module in both targets has no corresponding deallocation. The simulation target correctly uses @:DEALLOCATE(beta_vars) in its finalizer. The pre_process and post_process finalizers should be made consistent.


[MEDIUM] s_gradient_field in m_particles_EL.fpp: vL_field/vR_field declared intent(inout) but only read

src/simulation/m_particles_EL.fpp, ~line 2034:

real(wp), ..., intent(inout) :: vL_field
real(wp), ..., intent(inout) :: vR_field

The implementation only reads these arrays (computes dq = (vR - vL)/dx); it never writes to them. They should be intent(in). This is the same class of issue previously flagged for the analogous variables in m_bubbles_EL.fpp.


[LOW] Bare integer literal 3 in mixed real expression, m_bubbles.fpp f_advance_step case (3)

src/simulation/m_bubbles.fpp, ~line 600:

aTemp(l) = 2._wp*f_bTemp/(fmass_g + fmass_v) - 3*fV*fVel(l)/fR

The bare integer 3 is inconsistent with the style rule (use 3._wp) and with the analogous line in m_bubbles_EL.fpp which correctly writes 3._wp*myV*myVel(l)/myR. While Fortran's type promotion makes this numerically correct at wp, the inconsistency is a style violation and should use 3._wp.


[LOW] Typo in NVTX range label: BETA-COMM-SENDRECV-NO-RMDA

src/common/m_mpi_common.fpp, ~line 1344:

call nvtxStartRange("BETA-COMM-SENDRECV-NO-RMDA")

Should be NO-RDMA (the same typo also exists in the pre-existing RHS path at line 968, but this is new code adding it again).


Remaining from prior reviews (not re-examined here): case_validator.py entries for new particle parameters (currently no validation logic for particles parameters beyond definitions.py entries).

- Fix bubs_glb=0 placement after declarations (Fortran standard violation)
- Add missing max_dt declaration and GPU_DECLARE in m_time_steppers.fpp
- Add @:PROHIBIT for particle restart without MPI
- Deallocate beta_vars in pre_process and post_process finalizers
- Change vL_field/vR_field intent(inout) to intent(in) in s_gradient_field
- Fix bare integer 3 -> 3._wp in m_bubbles.fpp
- Fix NVTX typo RMDA -> RDMA

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions
Copy link

Claude Code Review

Incremental review from: 3c49f42
Head SHA: 38f7dd2

Previously-flagged issues addressed in this update: bubs_glb = 0 declaration-after-executable (fixed by moving into the #ifdef MFC_MPI block), beta_vars missing deallocation in pre/post finalizers (fixed), vL_field/vR_field intent(inout)intent(in) in s_gradient_field (fixed), bare integer literal 33._wp in m_bubbles.fpp (fixed), NVTX typo NO-RMDANO-RDMA (fixed), inc_ghost / only_beta moved after declarations in m_particles_EL.fpp (fixed).


New findings since last Claude review

[HIGH] Module-level max_dt array: missing deallocation + shadowed by local variable
src/simulation/m_time_steppers.fpp, lines 73 and 741

This commit adds:

! Module level (line 73)
real(wp), allocatable, dimension(:, :, :) :: max_dt

allocated conditionally in the initializer:

if (cfl_dt) then
    @:ALLOCATE(max_dt(0:m, 0:n, 0:p))   ! line 474
end if

but s_finalize_time_steppers_module has no corresponding @:DEALLOCATE(max_dt) — memory and GPU device memory leak whenever cfl_dt is true.

Additionally, inside s_compute_dt (line 741):

real(wp) :: max_dt   ! local scalar — shadows the module-level 3-D array

The GPU parallel loop at lines 766-769 passes this local scalar to s_compute_dt_from_cfl, not the module-level array. The 3-D array is therefore never written or read — it is allocated dead code, and the GPU declaration for it in GPU_DECLARE is superfluous.

Fix: add if (cfl_dt) @:DEALLOCATE(max_dt) to s_finalize_time_steppers_module, and either remove the module-level array (if the scalar per-cell caching was not actually intended) or rename the local scalar so it no longer shadows the module variable.


Remaining from prior reviews (not re-examined here): case_validator.py entries for new particle parameters (no physics-constraint validation logic currently).

sbryngelson and others added 2 commits March 16, 2026 18:09
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Add missing END_GPU_PARALLEL_LOOP in s_enforce_EL_particles_boundary_conditions
- Add GPU_ROUTINE on particle_in_domain_physical (called from GPU kernel)
- Fix p > 1 to p > 0 for 3D check in particle_in_domain (MFC convention)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions
Copy link

github-actions bot commented Mar 17, 2026

Claude Code Review

Incremental review from: 754cc32
Head SHA: 0756c08

Previously-flagged findings from last review: No new issues were found in the prior increment. All previously flagged issues (declaration-after-executable, beta_vars deallocation, vL_field/vR_field intent, bare integer literal, NVTX typo, max_dt shadow/leak, END_GPU_PARALLEL_LOOP terminator, p > 1p > 0) were resolved.


New findings since last Claude review

[MEDIUM] Optional type(scalar_field) argument in GPU device routine f_advance_step
src/simulation/m_bubbles.fpp, lines 469–484

f_advance_step is now a GPU device routine ($:GPU_ROUTINE(parallelism='[seq]')) with optional dummy arguments including type(scalar_field), intent(in), dimension(sys_size), optional :: q_prim_vf. scalar_field contains a Fortran pointer component, making it a derived type with pointer components — a class of optional argument that has incomplete support in OpenACC and OpenMP target device routines across all four CI-gated compilers.

The if (bubbles_lagrange) guard correctly prevents accessing absent arguments at runtime (safe for the EE call path without optional args). The existing codebase already uses optional real(wp) args in GPU device routines (s_vflux, f_bpres_dot), but extending this to a derived type with pointer components is higher-risk. The PR description notes successful testing on Tuolumne (Cray/OpenMP), but portability across nvfortran (--gpu acc), Intel ifx, and gfortran builds should be verified in CI.


[LOW] No-op assignments in f_advance_step default case
src/simulation/m_bubbles.fpp, lines 621–625

The case default block of the select case (lag_vel_model) loop contains self-assignments:

case default
    do l = 1, num_dims
        fVel(l) = fVel(l)
        fPos(l) = fPos(l)
    end do

These are no-ops. The block can be removed entirely or replaced with a comment.


[LOW] Unconditional MPI broadcast of hardcoded-IC variables in pre_process
src/pre_process/m_mpi_proxy.fpp, lines 1473–1477

interface_file, normFac, normMag, g0_ic, p0_ic are always broadcast regardless of whether particles_lagrange is set. No correctness impact (values are unused if the feature is off), but they should be guarded by if (particles_lagrange) for consistency with the rest of the file.


Remaining from prior reviews (not re-examined here): case_validator.py physics-constraint validation entries for new particles_lagrange parameters.

sbryngelson and others added 3 commits March 16, 2026 21:13
…gs, remove dead code

- Fix module @brief with proper E-L solver description and citation
- Fix 13 incorrect bubble->particle references in comments/docstrings
- Add array dimension convention documentation (stage 1=current, 2=RK)
- Add docstrings for collision, finalize_beta_field, build_linked_list
- Fix s_enforce_EL_particles_boundary_conditions docstring with phases
- Add docstring for f_interp_barycentric
- Document collision parameters with units (ksp, E, nu, cor)
- Fix mangled search-replace artifacts (fomu_fluidla -> formula)
- Fix @file header, author name typo (Madea -> Maeda)
- Fix MPI proxy docstrings (nBub -> nPart, remove stale params)
- Remove dead commented-out bubble variable code and gradient calls
- Remove no-op 1._wp* multiplier in s_compute_stddsv

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Add section 9.3 to case.md: parameter table and descriptions for all
  particle-specific parameters (particles_lagrange, nParticles_glb,
  qs_drag_model, collision_force, interpolation_order, etc.)
- Add section 6.3 to equations.md: governing equations for particle tracking
  including volume fraction, equation of motion, drag correlations,
  pressure gradient, added mass, and collision forces

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Update bubble_model description to include 0=Particle choice
- Add new bubble params to section 9.2: drag_model, vel_model, charNz,
  input_path, pressure_force, gravity_force, write_void_evol
- Add interfacial flow IC params to patch section: interface_file,
  normFac, normMag, g0_ic, p0_ic

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.

2 participants