Add integration of physical function
Overview
Integration of physical function
Checklists
- [ ] Documentations are up-to-date.
- [ ] Added example(s)
- [x] Added test(s)
Summary by CodeRabbit
-
New Features
- Enhanced the integration functionality to accept spline objects, improving usability for spline integration.
- Expanded documentation for the integration function, including detailed parameter descriptions and type safety checks.
-
Tests
- Introduced a new test case to validate the integration of a specific parabolic function over a defined domain, ensuring the accuracy of the integration process.
[!IMPORTANT]
Review skipped
Auto reviews are disabled on base/target branches other than the default branch.
Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.
Walkthrough
The recent updates enhance the physical_function in splinepy for improved spline integration by introducing a spline parameter for greater clarity and usability. The function's logic is refined to handle various spline types and optimize performance using np.einsum. Additionally, a new test function validates the integration of a parabolic function over a rectangular domain, ensuring the implementation's correctness and robustness.
Changes
| Files | Change Summary |
|---|---|
splinepy/helpme/integrate.py |
Updated physical_function to include a spline parameter, adding comprehensive parameter documentation and error handling. Enhanced internal logic for better integration handling. |
tests/helpme/test_integrate.py |
Added test_physical_function_integration to validate integration of a parabolic function over a defined rectangular domain, ensuring correctness of the integration logic with B-splines. |
Poem
🐰 In a world of splines, oh what a delight,
With functions so clear, they shine ever bright.
Integrate with glee, let the numbers dance,
In the land of math, give new features a chance!
From parabolas bold, to knots that entwine,
Hooray for the changes, all perfectly fine! 🌟
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
🪧 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
@coderabbitaiin 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
@coderabbitaiin 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 pauseto pause the reviews on a PR. -
@coderabbitai resumeto resume the paused reviews. -
@coderabbitai reviewto trigger an incremental review. This is useful when automatic reviews are disabled for the repository. -
@coderabbitai full reviewto do a full review from scratch and review all the files again. -
@coderabbitai summaryto regenerate the summary of the PR. -
@coderabbitai generate docstringsto generate docstrings for this PR. -
@coderabbitai generate sequence diagramto generate a sequence diagram of the changes in this PR. -
@coderabbitai resolveresolve all the CodeRabbit review comments. -
@coderabbitai configurationto show the current CodeRabbit configuration for the repository. -
@coderabbitai helpto get help.
Other keywords and placeholders
- Add
@coderabbitai ignoreanywhere in the PR description to prevent this PR from being reviewed. - Add
@coderabbitai summaryto generate the high-level summary at a specific location in the PR description. - Add
@coderabbitaianywhere in the PR title to generate the title automatically.
CodeRabbit Configuration File (.coderabbit.yaml)
- You can programmatically configure CodeRabbit by adding a
.coderabbit.yamlfile 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.
I have added a quick test where I integrate a f(x)=1 function over the physical space. Which should be just the volume integral. At first, it looked good but then, I saw that the error was inconsistent between the analytical and numerical integral.
Example implementation
import splinepy
integral_analytical = ((4/3) * np.pi * r**3) * revolve_percentage
def one_function(points):
return np.ones((1,1))
# quarter sphere
quart_circle = splinepy.helpme.create.sphere(outer_radius=r, angle=(360 * revolve_percentage))
integral = splinepy.helpme.integrate.physical_function(
quart_circle, one_function
)
I had tested this over multiple revolve percentages and radii. This is the result.
with the error being calculated by np.sqrt((integral[0]-integral_analytical)**2) shown on the z-axis (upwards).
I think the error is too high, but I don't really know what you actually do in the physical_integration. I am also not certain if this is just such a bad approximation or if there is a bug in the implementation.
Thanks for doing the test.
The issue might have something to do with the splinepy.helpme.create.parametric_view which I used for the integration. I just saw that the function returns a BSpline with degree 1 in every direction, which is different to the degrees of sphere (which has degrees [1 2 2]). I'll have to check
Thanks for doing the test.
The issue might have something to do with the
splinepy.helpme.create.parametric_viewwhich I used for the integration. I just saw that the function returns aBSplinewith degree 1 in every direction, which is different to the degrees of sphere (which has degrees [1 2 2]). I'll have to check
You should be able to pass an argument to get a conforming basis parametric view. But why would you need that?
Thanks @jzwar. We integrated the fixes from #459 into this PR. The error shown above is still partly present, but it seems to be a numerical error. The relative error is at least e-5, and can be reduced by adding more knots into the spline.
Also thank @markriegler for starting this.