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

add para to parent scaling #459

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open

add para to parent scaling #459

wants to merge 1 commit into from

Conversation

j042
Copy link
Member

@j042 j042 commented Sep 30, 2024

Overview

Integrations for bsplines weren't correct - it was missing parametric space to "parent" (or integration) element scaling.
Added corresponding test

Addressed issues

  • consider parametric space to parent element mapping

Checklists

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

Summary by CodeRabbit

  • New Features

    • Enhanced integration method for parametric functions, improving accuracy for splines with knot vectors.
    • Introduced a new method for physical function integration (currently not implemented).
  • Bug Fixes

    • Updated integration calculations to better account for spline geometry.
  • Tests

    • Added comprehensive tests for volume integration across 1D, 2D, and 3D splines, ensuring consistency after operations like degree elevation and knot insertion.
    • Included tests for complex geometries and validation of error handling for unsupported operations.

Copy link

coderabbitai bot commented Sep 30, 2024

Walkthrough

The changes involve updates to the parametric_function method in the splinepy/helpme/integrate.py file, enhancing the integration of functions defined in parametric domains. A new physical_function method is introduced, currently raising a NotImplementedError. Additionally, the tests/helpme/test_integrate.py file has been expanded with various tests for volume integration across different spline types and dimensions, ensuring the correctness of the integration process and handling of edge cases.

Changes

File Change Summary
splinepy/helpme/integrate.py Updated parametric_function to include a new multiplication factor for integration. Added physical_function method that raises NotImplementedError.
tests/helpme/test_integrate.py Introduced multiple tests for volume integration of splines in 1D, 2D, and 3D, validating results against expected outcomes and handling exceptions for unsupported operations.

Poem

🐇 In the land of splines where curves do play,
A function's dance brings joy today.
With tests aplenty, we leap and bound,
Ensuring volumes are safe and sound.
Hooray for changes, let’s hop with glee,
For every spline, there's magic to see! ✨


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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 using 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration 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
Copy link
Member Author

j042 commented Sep 30, 2024

I think this is also missing in iga-galerkin example

@j042 j042 changed the base branch from main to develop September 30, 2024 13:38
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: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between 148f29e and 59c603f.

📒 Files selected for processing (2)
  • splinepy/helpme/integrate.py (1 hunks)
  • tests/helpme/test_integrate.py (1 hunks)
🔇 Additional comments (2)
tests/helpme/test_integrate.py (1)

189-194: Test implementation correctly validates volume integration for Bezier splines

The assertion accurately verifies that integrating the volume_function over the Bezier spline yields the expected results. The code is correct and functions as intended.

splinepy/helpme/integrate.py (1)

204-207: Adjustment of integration measure scaling is correct

Including the scaling factor _np.prod(_np.diff(bezier_element.control_point_bounds, axis=0)) in the integration calculation properly accounts for the mapping between the parametric space and the parent element. This change effectively resolves the issue with incorrect integration of B-splines due to the omission of parametric space scaling.

Comment on lines +181 to 183
vf = np.ones((len(x), 2))
# scale it with a factor to get a different value
vf[:, 1] = col1_factor
Copy link

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Clarify the variable name col1_factor or adjust indexing in volume_function

In the volume_function, the variable col1_factor is used to scale vf[:, 1], which corresponds to the second column (since Python uses zero-based indexing). This may cause confusion. Consider renaming the variable to col2_factor, or adjust the indexing to vf[:, 0] if you intended to scale the first column.

Comment on lines +195 to +200
# try bsplines
bspline = bezier.bspline
assert np.allclose(
[bspline.integrate.volume(), col1_factor * bspline.integrate.volume()],
bspline.integrate.parametric_function(volume_function),
)
Copy link

@coderabbitai coderabbitai bot Sep 30, 2024

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider adding tests for rationalbezier and nurbs spline types

Currently, the test covers Bezier and B-spline types. To ensure comprehensive test coverage, consider adding similar integration tests for rationalbezier and nurbs spline types to validate the integration functionality across all spline types.

Copy link
Contributor

Choose a reason for hiding this comment

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

I am guessing that the integration of a function inside the parametric domain is spline agnostic. At least for the implemented spline? The original function only iterates through the bezier view of the spline? Or is it just not implemented for the other splines?

Copy link

Choose a reason for hiding this comment

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

@clemens-fricke, thank you for the clarification. You are correct—the integration of a function inside the parametric domain is spline agnostic for the implemented splines, as it iterates over the Bezier view of the spline. Therefore, additional tests for rationalbezier and nurbs spline types may not be necessary in this context.

(•‾⌣‾•)و Curious bunny appreciates the insight!


✏️ Learnings added
Learnt from: clemens-fricke
PR: tataratat/splinepy#459
File: tests/helpme/test_integrate.py:195-200
Timestamp: 2024-10-01T08:34:23.291Z
Learning: Integration of a function inside the parametric domain is spline agnostic for the implemented splines, as it iterates over the Bezier view of the spline.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

Copy link
Contributor

@clemens-fricke clemens-fricke left a comment

Choose a reason for hiding this comment

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

The proposed change is optional. If the question from the second comment is trivial, I have no problems with this PR. Thanks for the work. Looks good.

@@ -178,15 +178,23 @@ def test_function_integration(np_rng):
col1_factor = 2

def volume_function(x):
vf = np.ones((x.shape[0], 2))
vf = np.ones((len(x), 2))
# scale it with a factor to get a different value
vf[:, 1] = col1_factor
Copy link
Contributor

Choose a reason for hiding this comment

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

Also a factor would assume a multiplication and not just the value. In this special case, the result is the same, but it might be a little weird for someone to read it and see that it just overwrites the value instead of multiplying it. So col2_value would be more accurate.

Copy link
Member Author

Choose a reason for hiding this comment

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

I thought col starts at 0?

Comment on lines +195 to +200
# try bsplines
bspline = bezier.bspline
assert np.allclose(
[bspline.integrate.volume(), col1_factor * bspline.integrate.volume()],
bspline.integrate.parametric_function(volume_function),
)
Copy link
Contributor

Choose a reason for hiding this comment

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

I am guessing that the integration of a function inside the parametric domain is spline agnostic. At least for the implemented spline? The original function only iterates through the bezier view of the spline? Or is it just not implemented for the other splines?

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.

2 participants