Skip to content

Conversation

@MaxBille
Copy link
Collaborator

@MaxBille MaxBille commented Oct 28, 2025

Description

(Work in Progress)

Associated to issue #270 and related to feature requests #271 , #273 . See respective issue descriptions.

  • implementing fwbb, hwbb and ibb boundaries with efficiency improvement
  • implement cylinder flow as an example and test case

Checklist

  • This pull request is associated to an issue
  • This PR contains a description
  • Did you add a new method? If so, you need to
    • add method description
    • maybe mention class in the corresponding __init__
    • add an example using the method in examples/advanced_flows/ or examples/simple_flows/
    • add a test in tests/
  • Add someone else as reviewer and wait for approval before merging.

relevant files and changes

  • The advanced project lives in the directory:
    examples/advanced_projects/efficient_bounce_back_obstacle/
  • It contains a Jupyter Notebook 00_run_parameterized_project.ipynb with two examples of parametrized calls of the main simulation-script to run:
    • 2D, Re=200 simulation of a circular cylinder with periodic vortex shedding. Coefficients of drag and lift, as well as the Strouhal number are calculated
    • 3D, Re=3900 simulation of a circular cylinder with turbulent vortex shedding. Average velocity and Reynolds stress profiles are calculated and compared to reference values
  • The project writes data to specified output directories.
  • The profile contains a folder with reference data in .csv format for average velocity and Reynolds stress profiles
  • The main simulation script 01_script_cylinder_simulation.py contains:
    • argument parsing: physics, domain, solver-components, algorithms, reporters, observables, vtk output etc.
    • parameter-preprocessing
    • assembling of all solver components: stencil, context, flow, collision operator, simulation, reporter
    • the simulation run: call of simulation()
    • data post-processing and plotting: calculation, plotting, saving data and plots to disk
  • Efficient bounce back boundary implementations with the ability to calculate the momentum exchange (MEA) between solid and fluid:
    • Fullway (FWBB)
    • Halfway (HWBB)
    • Linearly Interpolated (IBB or IBB1)
  • adapted simulation class ebb_simulation.py that improves the regular simulation class to use post-streaming boundaries and let boundaries get post-collision but pre-streaming information on populations, needed for their bounce back algorithm (for HWBB and IBB).
  • flow class obstacle_cylinder.py: advanced obstacle flow with a symmetrical cylinder in 2D or 3D that can be run with periodic or solid boundary channel walls and efficient bounce back boundaries for the solid cylinder itself.
    • at this point, the flow class calculates all interpolation constants via an analytical function. In future versions, this might be outsourced to a CAD-kernel to use arbitrary solid geometry and calculate interpolation constants and masks (of index lists) from it. The use of the solid_boundary_data class enables unified containment of bounce back data (masks, population-indices, interpolation-constants,...)
    • mind the use of post_streaming_boundaries that are (at the point of writing) not native in lettuce master branch, because the simulation class does not allow them!
  • observables: coefficients of lift and drag, relying on the MEA-capabilities of the efficient BB boundaries (see above)
    • plot_force_coefficients: part of the data_processing_and_plotting.py utility.
    • analyze_periodic_timeseries: part of the data_processing_and_plotting.py utility. Gives statistics and frequency of a periodic signal (used for drag and lift in this project)
  • Advanced vtk reporter: two advanced vtk reporters that allow the selection of start and stop (step) of reporting and pulling observables (velocity and pressure) to 0 on the solid (especially useful when using FWBB). 2D slicing-functionality with the VTKsliceReporter
  • Average velocity and Reynolds stress profiles
    • reporter: The profile reporter reports the spatially averaged velocity profiles at a given position
    • ProfilePlotter: part of the data_processing_and_plotting.py utility. It allows the loading of reference data, processing of profile reporter data and plotting of both.

MaxBille and others added 3 commits September 4, 2025 18:21
…aster.

including: obstacle_cylinder.py, example-Simulation-script, HWBB and IBB boundary conditions, MEA for Bounce back boundaries, drag and lift observables...
…aster.

including: obstacle_cylinder.py, example-Simulation-script, HWBB and IBB boundary conditions, MEA for Bounce back boundaries, drag and lift observables...
@MaxBille MaxBille marked this pull request as draft October 28, 2025 13:15
@MaxBille MaxBille requested review from McBs and PhiSpel October 28, 2025 13:16
@MaxBille MaxBille self-assigned this Oct 28, 2025
@MaxBille MaxBille added the enhancement New feature or request label Oct 28, 2025
…ed from MP2 and MA).

obstacle_cylinder.py implements the flow, the boundary classes are implemented in the respective files under /_boundary
WorkInProgress, see ToDOs
…ack boundaries to folder examples/advanced_projects/efficient_bounce_back_obstacle.

Includes boundary conditions, obstacle_cylinder.py and placeholders for simulation-scripts for Re40-300 and Re3900, and a jupyter-notebook to run the scripts interactively

_simulation.py: added comments for clarification
@MaxBille
Copy link
Collaborator Author

@PhiSpel @McBs
The cylinder flow is now "running" with fwbb, hwbb or ibb boundary condition. Validation of physical correctness pending, because respective observable-reporters have to be implemented in the next step.
See commit: (Commit SHA: ea1705f from 21.11.25).

README:

  • simulation can be run with:
    python 01a_script_cylinder_lowRe --outdir "./datafolder" --char_length_lu 10 --n_steps 1000 --bbbc_type ibb1 --reynolds_number 50 --domain_width_z_in_d 3
  • ebb_simulation is a child of simulation class which allows post_streaming_boundaries to be used. This is necessary for FWBB, HWBB and IBB in the efficient sparse implementation.
  • obstacle_cylinder is the flow class
  • solid_boundary_data is the container class which contains masks, f_index-lists and ibb-d-data
  • 01a_script_cylinder_lowRe.py is the parameterized script to run the simulation.

Copy link
Contributor

Choose a reason for hiding this comment

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

@MaxBille, could you revert these changes for cleaner history?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

of course. Will try to overwrite file back to original from master branch!

Copy link
Contributor

Choose a reason for hiding this comment

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

@MaxBille, these are useful comments! Can you add them in a separate PR, though?

Copy link
Contributor

Choose a reason for hiding this comment

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

@MaxBille didn't you add these changes separately?

Copy link
Contributor

Choose a reason for hiding this comment

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

@MaxBille @McBs is this due to pyproject.toml requiring notebook? I suggest updating this, too, in a separate PR

Copy link
Contributor

Choose a reason for hiding this comment

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

@MaxBille, this, too, should be handled in a separate PR, related to #288

self.f_index_fwbb[:, 1],
self.f_index_fwbb[:, 2],
self.f_index_fwbb[:, 3]]
print("FWBB call, DONE")
Copy link
Contributor

Choose a reason for hiding this comment

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

remove redundant print? @MaxBille, check for more of those

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

will do; and will do in final version, together with obsolete comments and "old" code snippets

Copy link
Contributor

@PhiSpel PhiSpel left a comment

Choose a reason for hiding this comment

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

@MaxBille nice job so far!
Could you

self.f_collided_gt = None
# will be populated in initialize_f_collided() method

# DEPRECATED: got moved to method initialize f_collided
Copy link
Contributor

Choose a reason for hiding this comment

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

remove old code

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

will be removed in final/release/merge version. I keep sections like this in the code, to remind me of past versions and various ways to do stuff.

def make_no_streaming_mask(self, f_shape, context: Context):
# no_stream_mask has to be dimensions: (q,x,y,z) (z optional), but CAN be (x,y,z) (z optional).
# ...in the latter case, torch.where broadcasts the mask to (q,x,y,z), so ALL q populations of a lattice-node are marked equally
# return torch.tensor(self.mask, dtype=torch.bool)
Copy link
Contributor

Choose a reason for hiding this comment

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

remove old code

# ...in the initial solution of your flow, especially if visualization or post-processing uses the field-values
# ...in the whole domain (including the boundary region)!

# return torch.tensor(self.mask, dtype=torch.bool) # self.context.convert_to_tensor(self.mask)
Copy link
Contributor

Choose a reason for hiding this comment

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

remove old code

self.f_index_gt[:, 3]],
self.flow.stencil.e[self.f_index_gt[:, 0]].float())

# TODO: find a way to use pre- and post-Streaming Populations for bounce...
Copy link
Contributor

Choose a reason for hiding this comment

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

isn't this done?

mask=self.in_mask,
velocity=self.u_inlet) # (is this still true??): works with a 1 x D vector or an ny x D vector thanks to einsum-magic in EquilibriumBoundaryPU

lateral_boundary = None # stays None if lateral walls are not specified... (NOT IMPLEMENTED YET, see below)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we may just remove all channel-related definitions for now. The most interesting part is how the cylinder is handled, right, @MaxBille ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Do these changes break the old code or fix something? If they just work with everything else, OK. If they are required as a fix, please add this in a separate issue

MaxBille and others added 7 commits November 26, 2025 17:14
…ample to validate against MP2 and cylinder-paper data; to be tested...
- comments
- print-statements
- ToDos
- revert changes in .ipynbs (less clutter in later PR)
…numerically there are diffs. of ~1% in mean Drag... this might be due to the new pre/ost-boundary strategy of lettuce 2025.

Needs further investigation (issue already open).
Further improvements and corrections:
- implemented lateral walls option (for FWBB)
- removed some comments and old code sections.
NEXT will be output/data/vtk cleaning and example .ipynb script for execution
- methods for force coefficient plotting and analysis were outsourced to data_processing_and_plotting.py
- files for NaN-, HighMa-, and Progress-Reporter created (but work in progress)
MaxBille and others added 9 commits December 11, 2025 17:19
…ed profile-data-post-processing und -plotting.

implemented advanced vtk reporter (3D with step start and end and 2D for XY-slices)
…r flow with 01_script_cylinder_simulation.py through ipynb: 00_run_parameterized_project.ipynb

added "show" parameter to plotting-reporters methods, to not only plot and save but also show the plotted data
@MaxBille MaxBille requested a review from PhiSpel December 18, 2025 14:40
@MaxBille
Copy link
Collaborator Author

@McBs @PhiSpel the current commit 8f12b6a is ready for the next review cycle. This is basically a final version so far.

Copy link
Contributor

Choose a reason for hiding this comment

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

@MaxBille did you keep these changes intentionally?

"h5py==3.11.0",
"matplotlib>=3.9.2",
"mmh3>=4.1.0",
"notebook>=7.4.7",
Copy link
Contributor

Choose a reason for hiding this comment

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

Why was this added?

Copy link
Contributor

Choose a reason for hiding this comment

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

@MaxBille didn't you add these changes separately?

-> use the ProfilePlotter in post-processing to further process
and plot data!
"""

Copy link
Contributor

Choose a reason for hiding this comment

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

remove double linebreak

"""
output the mask as a vtk-file for visualizatione etc.
UPDATE 28.08.2024 (MBille: outputs mask as cell data. cell data represents the approx.
Copy link
Contributor

Choose a reason for hiding this comment

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

Is UPDATE necessary? Can't this be a permanent comment?

@PhiSpel PhiSpel marked this pull request as ready for review December 18, 2025 15:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants