Skip to content

Adding cpp&MATLAB example - 2D imcompressible square cylinder flow#274

Open
yiyuef wants to merge 17 commits intocsrc-sdsu:mainfrom
yiyuef:cylinder_branch
Open

Adding cpp&MATLAB example - 2D imcompressible square cylinder flow#274
yiyuef wants to merge 17 commits intocsrc-sdsu:mainfrom
yiyuef:cylinder_branch

Conversation

@yiyuef
Copy link

@yiyuef yiyuef commented Feb 7, 2026

Description

This PR adds a new C++ example cylinder_flow_2D that solves 2D incompressible channel flow past a cylinder-like obstacle (implemented as a masked no-slip region) using a projection (pressure-correction) method built on MOLE mimetic operators.

It also adds Sphinx/MyST documentation for the example and includes a representative output figure.

Type of Change

  • New core functionality
  • New example
  • Documentation update
  • Bug fix
  • Performance improvement

Mathematical Details

Not applicable (no new operators added).
The example solves the incompressible Navier–Stokes equations with a fractional-step (projection) method and uses MOLE discrete operators (divergence, gradient, Laplacian) for the Helmholtz/Poisson solves.

Testing

  • Unit tests pass
  • Examples run successfully
  • Convergence studies completed (if applicable)
  • Cross-platform compatibility verified

Documentation

  • Code is well-commented
  • API documentation updated
  • Example documentation added (if applicable)
  • Mathematical background provided

Related Issues

#211

Additional Notes

  • Output image cylinder_flow_2D_output1.png is included alongside the documentation page.

@valeriabarra
Copy link
Collaborator

Thank you, @yiyuef for this terrific contribution!

I ran the example and can see the output figure is quite small. Can you please increase its size? Also, any specific reason why the extension .ppm was chosen for non-MAC-OS users? It is a quite uncommon and unsupported file format.

Finally, I thought we also wanted to include the MATLAB/octave version to the library. I thought you had completed that implementation, first? Thank you!

yiyuef and others added 2 commits February 11, 2026 14:43
Co-authored-by: Valeria Barra <39932030+valeriabarra@users.noreply.github.com>
Signed-off-by: Yiyue Feng <79966731+yiyuef@users.noreply.github.com>
@yiyuef
Copy link
Author

yiyuef commented Feb 12, 2026

@valeriabarra Thanks for the careful review!

  1. You’re right about the inconsistent message and the .ppm choice. So I removed the platform-dependent PPM/PNG output and now the example only writes the three CSV outputs (U_final.csv, V_final.csv, p_final.csv). Visualization is handled via a separate gnuplot script, so the output messaging is now consistent. The reason I chose ppm is that I found cpp can output this format without outside packages.

  2. Regarding the figure size: I updated the gnuplot script to generate a larger PNG.

  3. markdown file also modified, to be consistant with the above change.

  4. For the MATLAB version, I thougth I should open another PR. Because source functions in MATLAB have been changed a little bit so my old code was not good. I have looked into in and now it should work. Matlab exmaple is now also part of this PR.

@yiyuef yiyuef changed the title Adding cpp example - 2D imcompressible cylinder flow Adding cpp&MATLAB example - 2D imcompressible square cylinder flow Feb 12, 2026
@@ -0,0 +1,35 @@
set datafile separator ","
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hi @yiyuef , thank you for updating your PR.
I don't think we want to add a separate gnu plot file here. I understand the intention was for separation of concerns and tidiness, however, we want the examples to be as self-contained as possible. See for instance other C++ examples in the library, like the lock exchange.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Please incorporate the gnu plot functionality in the same C++ source file examples/cpp/cylinder_flow_2D.cpp

Copy link
Author

Choose a reason for hiding this comment

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

I see that this code file still gnerates gnu scripts, in a automatic way

// Generate Gnuplot script for visualization
generateGnuplotScript("plot_lock_exchange.gnu", a, b, c, d);

But I think it might be better to simply leave csv files as outputs? There are also other examples not directly outputing png.

Once user has csv, they can visualize it in their preferred ways.

Copy link
Author

Choose a reason for hiding this comment

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

alright I will do it. I've got a delay in receiving your reply.

Copy link
Author

Choose a reason for hiding this comment

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

Now the gnu function is within the cpp script.

@valeriabarra valeriabarra requested a review from mdumett February 12, 2026 01:04
@valeriabarra valeriabarra added the Examples Addition or improvement of examples that showcase the main functionality of the library label Feb 12, 2026
@valeriabarra valeriabarra linked an issue Feb 12, 2026 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Examples Addition or improvement of examples that showcase the main functionality of the library

Projects

None yet

Development

Successfully merging this pull request may close these issues.

adding C++/matlab example, channel flow / cylinder flow

2 participants