-
Notifications
You must be signed in to change notification settings - Fork 13
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
Helper functions for gismo export #439
base: develop
Are you sure you want to change the base?
Conversation
Are those all new features or can this replace any of the existing section? |
These are all new features. |
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the WalkthroughThe updates enhance the capability to create and export multipatch geometries in a gismo-compatible format, introducing a class for structured data management. Users can now easily define NURBS curves, set boundary conditions, and specify function blocks, streamlining the export process. The new features are thoroughly tested to ensure reliability, making the Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant export_gismo.py
participant gismo
participant gismo_io
User->>export_gismo.py: Trigger export
export_gismo.py->>gismo_io: Prepare geometries and boundaries
gismo_io->>export_gismo.py: Return structured data
export_gismo.py->>gismo: Call export with data
gismo->>User: Exported XML File
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (2)
- examples/export_gismo.py (1 hunks)
- splinepy/io/gismo.py (2 hunks)
Additional comments not posted (8)
examples/export_gismo.py (4)
40-44
: Approved: Functiondirichlet_identifier
correctly identifies Dirichlet boundaries.The function uses a logical OR operation to determine if points meet the Dirichlet conditions, which is appropriate given the use of EPS to handle boundary precision.
51-64
: Approved: Correct creation of function blocks forrhs
andmanufactured_solution
.The function blocks for right-hand side functions and manufactured solutions are created correctly using the new helper functions, with appropriate parameters for dimensions, function IDs, and descriptive comments.
67-84
: Approved: Correct creation of boundary conditions and assembly options blocks.The boundary conditions and assembly options blocks are correctly defined using the new helper functions, with all necessary parameters such as IDs, dimensions, and comments provided.
101-111
: Approved: Correct modification ofgismo.export()
function call.The function call to
gismo.export()
correctly includes the new function blocks and assembly options, ensuring that the XML file is generated with all necessary configurations.splinepy/io/gismo.py (4)
709-801
: Approved: Correct implementation ofcreate_boundary_conditions_block
function.The function
create_boundary_conditions_block
correctly creates a structured Python dictionary for boundary conditions, which can be used effectively in the gismo export function. The parameters and dictionary structure are appropriately handled.
804-852
: Approved: Correct implementation ofcreate_function_block
function.The function
create_function_block
is well-implemented, supporting both scalar-valued and vector-valued functions. The dictionary structure and parameter handling are correct, facilitating its use in the gismo export function.
855-972
: Approved: Correct implementation ofcreate_assembly_options_block
function.The function
create_assembly_options_block
effectively creates a Python dictionary for g+smo assembly options. The handling of various parameters and the structure of the dictionary are appropriate for its intended use.
453-455
: Approved: Correct update to_apply_options
function to include comments.The addition of the
comment_text
parameter in the_apply_options
function allows for comments to be included in the XML output, which is a useful feature for clarity and documentation purposes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 13
Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Files selected for processing (2)
- examples/export_gismo.py (1 hunks)
- splinepy/io/gismo.py (2 hunks)
Additional context used
Ruff
splinepy/io/gismo.py
766-766: Use
is
andis not
for type comparisons, orisinstance()
for isinstance checks(E721)
833-833: Use
is
andis not
for type comparisons, orisinstance()
for isinstance checks(E721)
Additional comments not posted (10)
examples/export_gismo.py (3)
6-7
: Imports look good.The import statements are appropriate for the functionality provided.
36-37
: Ensure correct multipatch creation and interface determination.The multipatch creation and interface determination look correct.
47-48
: Ensure correct boundary setting.The boundary setting looks correct.
splinepy/io/gismo.py (7)
709-717
: Ensure correct function signature.The function signature looks correct.
801-801
: Ensure correct return statement.The return statement looks correct.
804-817
: Ensure correct function signature.The function signature looks correct.
852-852
: Ensure correct return statement.The return statement looks correct.
855-867
: Ensure correct function signature.The function signature looks correct.
868-970
: Ensure correct implementation ofcreate_assembly_options_block
.The function implementation looks correct.
972-972
: Ensure correct return statement.The return statement looks correct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's be easier to use this if you pack those helper functions in a class called CommentBlock
. Can you think of anyway to test this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 12
Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Files selected for processing (4)
- examples/export_gismo.py (1 hunks)
- splinepy/io/gismo.py (2 hunks)
- tests/data/gismo_additional_blocks.xml (1 hunks)
- tests/io/test_gismo.py (2 hunks)
Additional comments not posted (7)
examples/export_gismo.py (1)
82-88
: Ensure correct function block creation for manufactured solution.The function block creation for the manufactured solution looks correct. Consider adding comments for better clarity.
# Create function block for manufactured solution + # Exact solution for reference additional_blocks.add_function_block( dim=2, block_id=3, function_string="sin(pi*x) * sin(pi*y)", comment="The manufactured exact solution (for reference)", )
Likely invalid or redundant comment.
splinepy/io/gismo.py (6)
71-71
: Useisinstance
for type checking.Use
isinstance
for type checks as suggested by static analysis tools.- if not isinstance(func_text, tuple): + if not isinstance(func_text, tuple):
105-106
: Ensure correct handling of comment text.The handling of
comment
looks correct. Consider adding comments for better clarity.+ # Append comment to XML if provided if comment is not None: bc_dict_for_xml["comment"] = comment
134-134
: Useisinstance
for type checking.Use
isinstance
for type checks as suggested by static analysis tools.- if not isinstance(function_string, tuple): + if not isinstance(function_string, tuple):
151-152
: Ensure correct handling of comment text.The handling of
comment
looks correct. Consider adding comments for better clarity.+ # Append comment to XML if provided if comment is not None: function_dict["comment"] = comment
266-267
: Ensure correct handling of comment text.The handling of
comment
looks correct. Consider adding comments for better clarity.+ # Append comment to XML if provided if comment is not None: assembly_dict["comment"] = comment
711-713
: Ensure correct handling of comment text.The handling of
comment_text
looks correct. Consider adding comments for better clarity.comment_text = gismo_dictionary.get("comment", None) + # Append comment to XML if provided if comment_text is not None: xml_data.append(_ET.Comment(comment_text))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 6
Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Files selected for processing (1)
- tests/io/test_gismo.py (1 hunks)
Additional comments not posted (3)
tests/io/test_gismo.py (3)
307-307
: Ensure temporary directory is properly cleaned up.Using
with
statement ensures that the temporary directory is properly cleaned up.
279-285
: Add comments for function blocks.Adding comments will help understand the purpose of each block.
# Function block for vector-valued variable + # Add a function block for a vector-valued function additional_blocks.add_function_block( dim=2, block_id=2, function_string=("x", "y"), comment="Vector-valued function", )
Likely invalid or redundant comment.
272-278
: Add comments for function blocks.Adding comments will help understand the purpose of each block.
# Function block for scalar variable + # Add a function block for a scalar-valued function additional_blocks.add_function_block( dim=2, block_id=1, function_string="2*pi^2*sin(pi*x)*sin(pi*y)", comment="Scalar-valued function", )
Likely invalid or redundant comment.
Thanks for the update! Can you please go through the comments from the bot and mark them resolved afterwards? Feel free to leave a small comment if needed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 10
Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Files selected for processing (3)
- examples/export_gismo.py (1 hunks)
- splinepy/io/gismo.py (2 hunks)
- tests/io/test_gismo.py (1 hunks)
Additional comments not posted (14)
examples/export_gismo.py (8)
85-91
: Consider adding comments for function block creation.The function block creation for the manufactured solution looks correct. Consider adding comments for better clarity.
# Exact solution for referenceLikely invalid or redundant comment.
93-106
: Consider adding comments for boundary conditions block creation.The boundary conditions block creation looks correct. Consider adding comments for better clarity.
# Define boundary conditions for the multipatchLikely invalid or redundant comment.
14-21
: Add a blank line after the docstring summary.To follow PEP 257 conventions, add a blank line after the one-line summary in the docstring.
"""Recreate multipatch geometry from g+smo repository ReturnsLikely invalid or redundant comment.
51-56
: Ensure correct boundary identification logic.The boundary identification function looks correct. Consider adding comments to explain the logic.
# Points with y=0 or (x=0 and y=2) are identified as Dirichlet boundariesLikely invalid or redundant comment.
64-73
: Add a blank line after the docstring summary.To follow PEP 257 conventions, add a blank line after the one-line summary in the docstring.
""" Create blocks for rhs, manufactured solution, boundary conditions and assembly options.Likely invalid or redundant comment.
121-133
: Consider adding comments for visualization of geometry and BCs.The visualization code looks correct. Consider adding comments for better clarity.
# Define boundary names for visualizationLikely invalid or redundant comment.
77-83
: Consider adding comments for function block creation.The function block creation for RHS looks correct. Consider adding comments for better clarity.
# Right-hand side function for the Poisson equationLikely invalid or redundant comment.
37-45
: Consider adding comments to clarify the manipulation of control points.Adding comments to explain the adjustment of control points for the outer arc can enhance clarity.
# Adjust control points for the outer arcLikely invalid or redundant comment.
tests/io/test_gismo.py (5)
274-274
: Add a comment to explain the Python version check.The condition checks if the Python version is greater than or equal to 3.9. Consider adding a comment to explain this check.
# Check if Python version is 3.9 or higherLikely invalid or redundant comment.
308-311
: Add comments for assembly options block.Adding comments will help understand the purpose of each block.
# Add a block for assembly optionsLikely invalid or redundant comment.
266-272
: Add a docstring to describe the test.Adding a docstring will help understand the purpose of the test.
""" Test the export of additional blocks, including scalar and vector function blocks, boundary conditions, and assembly options. """Likely invalid or redundant comment.
293-306
: Add comments for boundary conditions block.Adding comments will help understand the purpose of each block.
# Add a block for boundary conditionsLikely invalid or redundant comment.
276-276
: Add a comment to explain the purpose ofAdditionalBlocks
.Adding a comment will help understand the purpose of this class.
# Initialize AdditionalBlocks to manage various blocks for exportLikely invalid or redundant comment.
splinepy/io/gismo.py (1)
711-714
: Ensure correct handling of comment text.The handling of
comment_text
looks correct. Consider adding comments for better clarity.# Append comment to XML if providedLikely invalid or redundant comment.
There was a problem hiding this 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 details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Files selected for processing (1)
- splinepy/io/gismo.py (2 hunks)
Additional comments not posted (4)
splinepy/io/gismo.py (4)
23-113
: Implementation ofadd_boundary_conditions_block
is correct.The method is well-structured and correctly uses
isinstance
for type checks. The changes are approved.
115-159
: Implementation ofadd_function_block
is correct.The method is well-implemented, with appropriate handling of scalar and vector-valued functions. The changes are approved.
161-274
: Implementation ofadd_assembly_options_block
is correct.The method is well-structured and efficiently manages parameters using lists. The changes are approved.
716-719
: Implementation of_apply_options
is correct.The function correctly handles comment text and processes nested options. The changes are approved.
982561d
to
184975f
Compare
There was a problem hiding this 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 details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Files selected for processing (4)
- examples/export_gismo.py (1 hunks)
- splinepy/io/gismo.py (2 hunks)
- tests/data/gismo_additional_blocks.xml (1 hunks)
- tests/io/test_gismo.py (1 hunks)
Additional comments not posted (17)
examples/export_gismo.py (11)
64-73
: Add a blank line after the docstring summary.To follow PEP 257 conventions, add a blank line after the one-line summary in the docstring.
""" Create blocks for rhs, manufactured solution, boundary conditions and assembly options. + Returns ----------- additional_blocks: list<dict> List of dictionaries used for splinepy's gismo export function """
Likely invalid or redundant comment.
93-106
: Ensure correct boundary conditions block creation.The boundary conditions block creation looks correct. Consider adding comments for better clarity.
# Define boundary conditions for the multipatchLikely invalid or redundant comment.
85-91
: Ensure correct function block creation for manufactured solution.The function block creation for the manufactured solution looks correct. Consider adding comments for better clarity.
# Exact solution for referenceLikely invalid or redundant comment.
51-56
: Ensure correct boundary identification.The boundary identification function looks correct. Consider adding comments to explain the logic.
# Points with y < EPS or (x < EPS and y > 2 - EPS) are identified as Dirichlet boundariesLikely invalid or redundant comment.
37-45
: Ensure correct manipulation of control points.The control points for
arc_outer
are correctly defined. Consider adding comments for better clarity.arc_outer = arc_inner.copy() # Adjust control points for the outer arcLikely invalid or redundant comment.
135-141
: Ensure correct export to XML file.The export code looks correct. Consider adding comments for better clarity.
# Export the multipatch geometry and options to an XML fileLikely invalid or redundant comment.
14-21
: Add a blank line after the docstring summary.To follow PEP 257 conventions, add a blank line after the one-line summary in the docstring.
"""Recreate multipatch geometry from g+smo repository + Returns --------- multipatch: splinepy Multipatch Arc geometry consisting of two patches """
Likely invalid or redundant comment.
1-6
: Ensure the docstring follows PEP 257 conventions.The docstring should start with a one-line summary followed by a blank line and further description if needed.
""" Export to g+smo-compatible xml-file. + Recreates poisson2d_bvp.xml from gismo repo (see https://github.com/gismo/gismo/blob/stable/filedata/pde/poisson2d_bvp.xml) """
Likely invalid or redundant comment.
121-133
: Ensure correct visualization of geometry and BCs.The visualization code looks correct. Consider adding comments for better clarity.
# Define boundary names for visualizationLikely invalid or redundant comment.
108-111
: Ensure correct assembly options block creation.The assembly options block creation looks correct. Consider adding comments for better clarity.
# Define assembly options for the multipatchLikely invalid or redundant comment.
77-83
: Ensure correct function block creation for RHS.The function block creation for RHS looks correct. Consider adding comments for better clarity.
# Right-hand side function for the Poisson equationLikely invalid or redundant comment.
tests/data/gismo_additional_blocks.xml (1)
2-2
: Acknowledgment: Existing comment is sufficient.The comment on the second line adequately indicates the purpose of the XML file.
tests/io/test_gismo.py (1)
266-329
: LGTM! Ensure compatibility with other Python versions.The test function
test_gismo_export_additional_blocks
is well-structured and comprehensive.However, ensure that the test is compatible with other Python versions, especially if future changes are made to the codebase.
Run the following script to verify the test's compatibility with other Python versions:
Verification successful
Test Compatibility Confirmed for Python 3.9 and Above
The test function
test_gismo_export_additional_blocks
is designed to run only on Python versions 3.9 and above. It skips execution for versions below 3.8, ensuring compatibility with the intended Python versions.
- Ensure that any future changes maintain this compatibility requirement.
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify compatibility of the test function with other Python versions. # Test: Check for Python version compatibility. Expect: No issues with Python versions 3.9 and above. grep -A 5 'def test_gismo_export_additional_blocks' tests/io/test_gismo.pyLength of output: 413
Script:
#!/bin/bash # Description: Search for Python version-specific conditions or dependencies in the test file. # Search for any Python version checks in the test file rg 'python_version' tests/io/test_gismo.py -A 3Length of output: 1100
splinepy/io/gismo.py (4)
14-18
: LGTM! The class definition is well-structured.The
AdditionalBlocks
class provides a centralized way to manage additional XML blocks for gismo export.
23-113
: LGTM! The method implementation is correct.The
add_boundary_conditions_block
method is well-structured and correctly implements the creation of boundary conditions blocks.
115-159
: LGTM! The method implementation is correct.The
add_function_block
method is well-structured and correctly implements the creation of function blocks.
161-274
: LGTM! The method implementation is correct.The
add_assembly_options_block
method is well-structured and correctly implements the creation of assembly options blocks.
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
184975f
to
c32022f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I only have some naming suggestions
Can i merge this PR or do you do it? |
I will |
@markriegler can you comment on @s-tillmann's commits? |
As part of the boundary conditions in g+smo it is possible to prescribe a value at a certain corner (e.g. prescribing zero pressure at a specific corner for the lid driven cavity). @s-tillmann implemented this option for the export. |
Overview
I found the current implementation of exporting gismo-compatible xml-files regarding boundary conditions, custom functions and the assembly options too cumbersome and hard to read with all the nested curly brackets. Therefore, I added three new helper functions to gismo export: one for boundary conditions, one for a function block and one for the assembly options block. This should lead to clearer code.
New features
All related to gismo export.
Showcase
New example
examples/export_gismo.py
recreates the xml-file for gismo's Poisson example.Checklists
Summary by CodeRabbit
New Features
Enhancements
Testing