Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjusted cartesian mesh generation for 2D meshes #66

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

neysecco
Copy link
Contributor

@neysecco neysecco commented Dec 1, 2023

Purpose

Hello everyone,

The explicitCart and simpleCart functions could not generate cartesian meshes for 2D cases when used from the command line. The issue was that we could not set multiple symmetry planes from the command line, even though the Python part of these functions already had this functionality.
I adapted the parser to read multiple symmetry planes and mesh spacings. This modification should be backward-compatible.
This is further explained in the documentation of these functions ("$ cgns_utils explicitCart -h" and "$ cgns_utils simpleCart -h").

I also made minor changes to the cartesian function due to changes in scipy.optimize inteface and Python3 standards. However, I strongly recommend that we remove this function, since explicitCart and simpleCart give better control over mesh spacings.

Type of change

Changes to the command-line interface

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (non-backwards-compatible fix or feature)
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no API changes)
  • Documentation update
  • Maintenance update
  • Other (please describe)

Testing

The code can be tested with:
$ cgns_utils explicitCart -3 -3 0 4 3 1 0.3,0.3,1.0 10.0 15 zmin,zmax 0 bg.cgns

The expected output is:
Grid Dimensions: [54, 51, 2]
Grid Ratios: [1.12192755 1.12387294 4. ]

A new file named bg.cgns will be created with a cartesian mesh for 2D simulation.

Checklist

  • I have run flake8 and black to make sure the Python code adheres to PEP-8 and is consistently formatted
  • I have formatted the Fortran code with fprettify or C/C++ code with clang-format as applicable
  • I have run unit and regression tests which pass locally with my changes
  • I have added new tests that prove my fix is effective or that my feature works
  • I have added necessary documentation

@neysecco neysecco requested a review from a team as a code owner December 1, 2023 13:24
@neysecco neysecco requested review from eirikurj and sseraj December 1, 2023 13:24
Copy link

codecov bot commented Dec 1, 2023

Codecov Report

Attention: Patch coverage is 0% with 34 lines in your changes missing coverage. Please review.

Project coverage is 17.88%. Comparing base (86116bc) to head (168f9be).

Files with missing lines Patch % Lines
cgnsutilities/cgns_utils.py 0.00% 26 Missing ⚠️
cgnsutilities/cgnsutilities.py 0.00% 8 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #66      +/-   ##
==========================================
- Coverage   17.95%   17.88%   -0.07%     
==========================================
  Files           3        3              
  Lines        2323     2331       +8     
==========================================
  Hits          417      417              
- Misses       1906     1914       +8     

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

Copy link
Contributor

@eirikurj eirikurj left a comment

Choose a reason for hiding this comment

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

Hey, @neysecco, hope you are doing well! Sorry for the delay, and thanks for the PR! Did a quick pass and overall the changes look good, but see my comments. I would not be too worried about backwards compatibility, for these options, so if you have any alternate ideas please let us know. Aside from that, we should add some examples or tests, or both. This could be something simple as just showing how to use the command, and compare the cgns output file to a reference file. For reference we do something similar for pyHyp tests.

cgnsutilities/cgns_utils.py Outdated Show resolved Hide resolved
cgnsutilities/cgns_utils.py Outdated Show resolved Hide resolved
@@ -922,7 +983,18 @@ def main():
sys.exit(0)

elif args.mode == "simpleCart":
curGrid.simpleCart(args.dh, args.hExtra, args.nExtra, args.sym, args.mgcycle, args.outFile)
# Change dh to a list of integers, since we had
# to define it as a string in arg_parser to avoid
Copy link
Contributor

Choose a reason for hiding this comment

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

Most of the new code here is a duplication from explicitCart. Refactoring this into a function processing the cart inputs would be great.

@marcomangano marcomangano mentioned this pull request Feb 27, 2024
13 tasks
eirikurj
eirikurj previously approved these changes Feb 3, 2025
Copy link
Contributor

@eirikurj eirikurj left a comment

Choose a reason for hiding this comment

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

This has been stale for over a year now. Fixed a couple of my own comments, but I suggest we merge this and add tests and other improvements in later PRs. @marcomangano please review if possible

@eirikurj eirikurj requested a review from marcomangano February 3, 2025 11:11
Copy link
Contributor

@marcomangano marcomangano left a comment

Choose a reason for hiding this comment

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

I agree we can add tests and cleanup the code at a later stage. The updated documentation and fixes are very useful.
I just have a comment below:

@@ -988,7 +987,7 @@ def func(P):
x0bin = xmin + dxBin * binIndex
xfbin = xmin + dxBin * (binIndex + 1)
# Find cells that touch this interval and get their edges
bol = -(((S[:-1] < x0bin) * (S[1:] < x0bin)) + ((S[:-1] > xfbin) * (S[1:] > xfbin)))
bol = ~(((S[:-1] < x0bin) * (S[1:] < x0bin)) + ((S[:-1] > xfbin) * (S[1:] > xfbin)))
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand this change.

Copy link
Contributor

Choose a reason for hiding this comment

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

This is essentially inverting a boolean array. This is a bit cryptic, and perhaps numpys invert would be more readable (see docs here).

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh ok yeah, it is a bit cryptic, you mean flipping the boolean values element-by-element? Could you just expand the comment in the code? Otherwise the PR is ready to go for me.

Copy link
Contributor

Choose a reason for hiding this comment

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

I added a comment on this, but not sure if this is useful. Please take a look. In any case, Ney suggests that this is not a useful function, and we should perhaps deprecate in favor of explicitCart and simpleCart.

@marcomangano marcomangano mentioned this pull request Feb 6, 2025
13 tasks
Copy link
Contributor

@marcomangano marcomangano left a comment

Choose a reason for hiding this comment

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

Thanks for the updated comment, LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants