-
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
Ft mfem 3d single-patch IO #445
base: main
Are you sure you want to change the base?
Conversation
WalkthroughThe recent updates enhance the NURBS spline handling in the Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant SplineLoader
participant SplineExporter
Note over User, SplineLoader: Loading a spline
User->>SplineLoader: Call load function
SplineLoader->>SplineLoader: Initialize degrees, ncps, knot_vectors
SplineLoader->>SplineLoader: Populate knot_vectors using loop
SplineLoader->>SplineLoader: Validate spline information
SplineLoader-->>User: Return loaded spline
Note over User, SplineExporter: Exporting a spline
User->>SplineExporter: Call export function
SplineExporter->>SplineExporter: Check for mixed orders
SplineExporter->>SplineExporter: Handle 3D section (elements, boundaries, etc.)
SplineExporter->>SplineExporter: Format knot vectors using kv_sec
SplineExporter-->>User: Return exported spline
Poem
Tip AI model upgrade
|
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: ASSERTIVE
Files selected for processing (2)
- splinepy/io/mfem.py (3 hunks)
- tests/io/test_mfem_export.py (1 hunks)
Additional comments not posted (9)
tests/io/test_mfem_export.py (2)
Line range hint
1-132
: LGTM! The test function is comprehensive and well-structured.The
test_mfem_export
function effectively tests the MFEM export routine for both 2D and 3D splines. The test coverage appears adequate for the current functionality.
133-156
: LGTM! The new test function is comprehensive and well-structured.The
test_mfem_single_patch_export
function effectively tests the MFEM single patch export routine. The test coverage appears adequate for the current functionality.splinepy/io/mfem.py (7)
Line range hint
89-116
: LGTM! The enhancements improve the robustness of the function.The
load
function is well-structured, and the changes to handle knot vectors and degrees, as well as the improved validation logic, enhance the robustness of the function.
Line range hint
118-149
: LGTM! The function is well-structured.The
read_solution
function is well-structured and no issues are detected.
Line range hint
151-176
: LGTM! The function is well-structured.The
_mfem_dof_map_2d
function is well-structured and no issues are detected.
Line range hint
178-220
: LGTM! The function is well-structured.The
_mfem_dof_map_3d
function is well-structured and no issues are detected.
Line range hint
222-235
: LGTM! The function is well-structured.The
dof_mapping
function is well-structured and no issues are detected.
Line range hint
237-586
: LGTM! The enhancements improve the robustness of the function.The
export_cartesian
function is well-structured, and the changes to handle 3D cases and improved handling of knot vectors and degrees enhance the robustness of the function.
Line range hint
588-674
: LGTM! The enhancements improve the robustness of the function.The
export
function is well-structured, and the changes to handle 3D cases and improved handling of knot vectors and degrees enhance the robustness of the function.
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: 4
Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Files selected for processing (1)
- splinepy/io/mfem.py (4 hunks)
Additional comments not posted (3)
splinepy/io/mfem.py (3)
588-599
: Add handling for 3D cases.The added code correctly handles 3D cases by defining
elements_sec
,boundary_sec
, andedges_sec
. Ensure that the boundary and edge definitions are accurate.
628-634
: Ensure degree elevation logic is necessary.The degree elevation logic ensures that all degrees match the maximum degree. Verify that this operation is necessary and does not introduce unintended side effects.
644-663
: Ensure knot vector formatting is correct.The
kv_sec
function formats knot vectors for export. Verify that the formatting meets the requirements of the MFEM format.
splinepy/io/mfem.py
Outdated
else: | ||
raise ValueError("mfem output support 2D and 3D splines.") | ||
|
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.
Clarify the error message for unsupported dimensions.
The error message can be more descriptive to help users understand the limitation.
- raise ValueError("mfem output support 2D and 3D splines.")
+ raise ValueError("MFEM output currently supports only 2D and 3D splines.")
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
else: | |
raise ValueError("mfem output support 2D and 3D splines.") | |
else: | |
raise ValueError("MFEM output currently supports only 2D and 3D splines.") |
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: 5
Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Files selected for processing (2)
- splinepy/io/mfem.py (5 hunks)
- tests/io/test_mfem_export.py (1 hunks)
Additional comments not posted (3)
tests/io/test_mfem_export.py (2)
Line range hint
1-132
: Comprehensive test coverage for MFEM export functionality.The function
test_mfem_export
is well-structured and covers multiple scenarios for 2D and 3D exports. The test cases validate the export functionality for different types of splines effectively.
134-167
: Comprehensive test coverage for single patch export functionality.The function
test_mfem_single_patch_export
is well-structured and covers multiple scenarios for 2D and 3D single patch exports. The test cases validate the single patch export functionality for different types of splines effectively.splinepy/io/mfem.py (1)
588-647
: LGTM!The changes in the
export
function are well-structured and consistent with the requirements for 3D single patch support.
degrees = [] | ||
ncps = 1 | ||
for kv in knot_vectors: | ||
degrees.append(kv.pop(0)) | ||
ncps *= kv.pop(0) |
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.
Clarify the purpose of ncps
and its calculation.
The variable ncps
is initialized to 1 and then multiplied by the second element of each knot vector. A brief comment explaining its purpose would improve readability.
# Initialize ncps to 1, will be used to calculate the number of control points
ncps = 1
for kv in knot_vectors:
degrees.append(kv.pop(0))
ncps *= kv.pop(0) # Multiply by the number of control points in each dimension
else: | ||
raise ValueError("mfem output support 2D and 3D splines.") |
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.
Clarify the error message for unsupported dimensions.
The error message can be more descriptive to help users understand the limitation.
- raise ValueError("mfem output support 2D and 3D splines.")
+ raise ValueError("MFEM output currently supports only 2D and 3D splines.")
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
else: | |
raise ValueError("mfem output support 2D and 3D splines.") | |
else: | |
raise ValueError("MFEM output currently supports only 2D and 3D splines.") |
@@ -31,7 +31,7 @@ | |||
def load(fname): | |||
"""Reads mfem spline and returns a spline. | |||
|
|||
Again, only supports 2D single patch. | |||
Again, only supports 2D/3D single patch. |
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.
Clarify the scope of support for 2D/3D single patch.
The comment only mentions 2D/3D single patch support. Consider updating it to reflect the current functionality accurately.
- Again, only supports 2D/3D single patch.
+ Supports 2D/3D single patch.
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
Again, only supports 2D/3D single patch. | |
Supports 2D/3D single patch. |
knot_vectors_sec = nurbs_dict["knotvectors"][1:] | ||
knot_vectors = [] | ||
for kvs in knot_vectors_sec: | ||
knot_vectors.append(eval("[" + kvs.replace(" ", ",") + "]")) |
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.
Ensure safe evaluation of knot vectors.
Using eval
can be risky as it may execute arbitrary code. Consider using ast.literal_eval
for safer evaluation.
- for kvs in knot_vectors_sec:
- knot_vectors.append(eval("[" + kvs.replace(" ", ",") + "]"))
+ import ast
+ for kvs in knot_vectors_sec:
+ knot_vectors.append(ast.literal_eval("[" + kvs.replace(" ", ",") + "]"))
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
knot_vectors_sec = nurbs_dict["knotvectors"][1:] | |
knot_vectors = [] | |
for kvs in knot_vectors_sec: | |
knot_vectors.append(eval("[" + kvs.replace(" ", ",") + "]")) | |
knot_vectors_sec = nurbs_dict["knotvectors"][1:] | |
knot_vectors = [] | |
import ast | |
for kvs in knot_vectors_sec: | |
knot_vectors.append(ast.literal_eval("[" + kvs.replace(" ", ",") + "]")) |
or int(nurbs_dict["knotvectors"][0]) != len(degrees) | ||
or len(degrees) != len(knot_vectors) |
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.
Improve error message for inconsistent spline info.
The error message can include more details about the inconsistency for better debugging.
- raise ValueError("Inconsistent spline info in " + fname)
+ raise ValueError(f"Inconsistent spline info in {fname}: "
+ f"ncps = {ncps}, len(control_points) = {len(control_points)}, "
+ f"len(weights) = {len(weights)}, "
+ f"len(degrees) = {len(degrees)}, "
+ f"len(knot_vectors) = {len(knot_vectors)}")
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
or int(nurbs_dict["knotvectors"][0]) != len(degrees) | |
or len(degrees) != len(knot_vectors) | |
or int(nurbs_dict["knotvectors"][0]) != len(degrees) | |
or len(degrees) != len(knot_vectors): | |
raise ValueError(f"Inconsistent spline info in {fname}: " | |
f"ncps = {ncps}, len(control_points) = {len(control_points)}, " | |
f"len(weights) = {len(weights)}, " | |
f"len(degrees) = {len(degrees)}, " | |
f"len(knot_vectors) = {len(knot_vectors)}") |
Overview
Extends single-patch IO to 3D
Addressed issues
Next
For complex multipatches, either revive
edges
or contribute to MFEMChecklists
Summary by CodeRabbit
New Features
Tests