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

Enable open upper limits for the grids in interpolation code #440

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

mbkumar
Copy link
Collaborator

@mbkumar mbkumar commented Jul 31, 2024

This PR enables open endpoints for the upper limits of the meshes when doing interpolation. The main reason to enable this functionality is to allow for [0, phi_max) generated by BMW mesh.

Copy link
Contributor

@andrewgiuliani andrewgiuliani left a comment

Choose a reason for hiding this comment

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

Hi Bharat, I do not understand why this PR is needed, could you clarify?

You want to interpolate the BMW field on the cylindrical domain [rmin, rmax] x [phimin, phimax] x [zmin, zmax]. If you do not include the endpoint, what does the field interpolator do on the interval [rmax-h, rmax)?

The field is periodic in phi on 0 to 2pi, so I'm not sure why you can't just always include the endpoint there. If you're interpolating on 0 to 2pi/nfp, then same question as above, what happens on the subinterval (2pi/nfp - h, 2pi/nfp)?

phirange: a 3-tuple of the form ``(phimin, phimax, nphi)``.
zrange: a 3-tuple of the form ``(zmin, zmax, nz)``.
rrange: a 3-tuple of the form ``(rmin, rmax, nr)`` or a 4-tuple of the form ``(rmin, rmax, nr, include_endpoint)``.
The default for `include_endpoint` is True. This mean that the interval :math:`[rmin, rmax]` is
Copy link
Contributor

Choose a reason for hiding this comment

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

typo, this means

rrange: a 3-tuple of the form ``(rmin, rmax, nr)`` or a 4-tuple of the form ``(rmin, rmax, nr, include_endpoint)``.
The default for `include_endpoint` is True. This mean that the interval :math:`[rmin, rmax]` is
split into ``nr`` many subintervals. When `include_endpoint` is False, interval :math:`[rmin, rmax)` is
split into ``nr`` many subintervals.
Copy link
Contributor

@andrewgiuliani andrewgiuliani Jul 31, 2024

Choose a reason for hiding this comment

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

what does it mean [rmin, rmax] is split into nr many subintervals as opposed to [rmin, rmax) is split into nr many subintervals ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

To concretize this, lets suppose you want 5 points between 0 and 1. If you include the end point, the mesh would [0, 0.25, 0.5, 0.75, 1]. If you don't want to include the end point, the mesh generated would be [0, 0.2, 0.4, 0.6, 0.8]. So the mesh would be quite different. Unfortunately, BMW generates phi grid with end point not included.

Copy link
Contributor

Choose a reason for hiding this comment

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

But then what happens on the small subinterval (2pi/nfp - h, 2pi/nfp)? I guess the behavior would be dictated by the extrapolate keyword argument.

Since the BMW field is nfp-periodic, you can just rotate the B-field values from B(R, phi=0, Z) to B(R, phi=2pi/nfp, Z) and obtain the endpoint value.

Copy link

codecov bot commented Jul 31, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.19%. Comparing base (f4b943e) to head (3bacaca).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #440      +/-   ##
==========================================
- Coverage   92.52%   92.19%   -0.34%     
==========================================
  Files          75       75              
  Lines       13833    13833              
==========================================
- Hits        12799    12753      -46     
- Misses       1034     1080      +46     
Flag Coverage Δ
unittests 92.19% <100.00%> (-0.34%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mbkumar
Copy link
Collaborator Author

mbkumar commented Jul 31, 2024 via email

@landreman
Copy link
Contributor

My reaction is the same as @andrewgiuliani 's - to avoid extrapolating, the thing to do would be to rotate the BMW field from phi=0 by 2pi/nfp and add the result as a new grid point at phi=2pi/nfp. This could be done in whatever function you have that passes data from BMW to the InterpolatedField.

It seems unlikely that a user would have include_endpoint=False in the R or Z coordinates, so I'd be inclined not to support those cases for simplicity.

@smiet
Copy link
Contributor

smiet commented Aug 6, 2024

I agree with @landreman and @andrewgiuliani, BMW will interpolate between the last phi plane and the first (flipped and copied according to the relevant symmetry), and the equivalently functioning InterpolatedField will have the last phi plane appended.

Technically InterplolatedField contains redundant information, but the extra cost is almost negligible and evaluation potentially faster.

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.

4 participants