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

Ft mfem 3d single-patch IO #445

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

Ft mfem 3d single-patch IO #445

wants to merge 6 commits into from

Conversation

j042
Copy link
Member

@j042 j042 commented Jul 3, 2024

Overview

Extends single-patch IO to 3D

Addressed issues

  • We had dof mapping, and IO was missing.

Next

For complex multipatches, either revive edges or contribute to MFEM

Checklists

  • Documentations are up-to-date.
  • Added example(s)
  • Added test(s)

Summary by CodeRabbit

  • New Features

    • Improved NURBS spline loading and exporting, including better handling of knot vectors and consistency checks.
  • Tests

    • Added a new test for MFEM single patch export to validate the process of creating, modifying, exporting, and loading NURBS splines.

Copy link

coderabbitai bot commented Jul 3, 2024

Walkthrough

The recent updates enhance the NURBS spline handling in the splinepy/io/mfem.py module, specifically by improving the loading and exporting functionalities. The changes ensure accurate knot vector processing, better validation, and support for multiple dimensions, particularly addressing 3D cases. Additionally, a new test function test_mfem_single_patch_export has been introduced to validate these functionalities.

Changes

File / Module Change Summary
splinepy/io/mfem.py Updated load and export functions: enhanced knot vector handling, added 3D support, validation logic improvements.
tests/io/test_mfem_export.py Added test_mfem_single_patch_export to validate MFEM single patch export.

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
Loading

Poem

In code we weave the spline's delight,
With knot and point, dimensions bright.
Through 3D space our paths entwine,
Export, import - the process shines.
Celebrate the patch, a single quest,
For NURBS now perform their best!
🌟✨

Tip

AI model upgrade

gpt-4o model for reviews and chat is now live

OpenAI claims that this model is better at understanding and generating code than the previous models. Please join our Discord Community to provide any feedback or to report any issues.


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?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@j042 j042 requested review from clemens-fricke and jzwar July 3, 2024 13:21
Copy link

@coderabbitai coderabbitai bot left a 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

Commits

Files that changed from the base of the PR and between b82c602 and 1ec6aa6.

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.

Copy link

@coderabbitai coderabbitai bot left a 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

Commits

Files that changed from the base of the PR and between 1ec6aa6 and 014888d.

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, and edges_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.

Comment on lines 623 to 625
else:
raise ValueError("mfem output support 2D and 3D splines.")

Copy link

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.

Suggested change
else:
raise ValueError("mfem output support 2D and 3D splines.")
else:
raise ValueError("MFEM output currently supports only 2D and 3D splines.")

Copy link

@coderabbitai coderabbitai bot left a 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

Commits

Files that changed from the base of the PR and between 014888d and c8dceda.

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.

Comment on lines +95 to +99
degrees = []
ncps = 1
for kv in knot_vectors:
degrees.append(kv.pop(0))
ncps *= kv.pop(0)
Copy link

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

Comment on lines +623 to +624
else:
raise ValueError("mfem output support 2D and 3D splines.")
Copy link

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.

Suggested change
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.
Copy link

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.

Suggested change
Again, only supports 2D/3D single patch.
Supports 2D/3D single patch.

Comment on lines +89 to +92
knot_vectors_sec = nurbs_dict["knotvectors"][1:]
knot_vectors = []
for kvs in knot_vectors_sec:
knot_vectors.append(eval("[" + kvs.replace(" ", ",") + "]"))
Copy link

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.

Suggested change
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(" ", ",") + "]"))

Comment on lines +115 to +116
or int(nurbs_dict["knotvectors"][0]) != len(degrees)
or len(degrees) != len(knot_vectors)
Copy link

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.

Suggested change
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)}")

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.

None yet

1 participant