Skip to content

Commit

Permalink
surface copying classmethod
Browse files Browse the repository at this point in the history
  • Loading branch information
smiet committed Aug 29, 2023
1 parent c859dfb commit 9da8baa
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/simsopt/geo/surfacerzfourier.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,40 @@ def from_wout(cls, filename: str, s: float = 1.0,

surf.local_full_x = surf.get_dofs()
return surf


@classmethod
def from_other_surface(cls, other: "SurfaceRZFourier", **kwargs):
"""
Initialize a new SurfaceRZFourier object from another surface, changing
the parameters specified by **kwargs
"""
ntheta = kwargs.pop("ntheta", None)
nphi = kwargs.pop("nphi", None)
grid_range = kwargs.pop("range", None)

Check warning on line 228 in src/simsopt/geo/surfacerzfourier.py

View check run for this annotation

Codecov / codecov/patch

src/simsopt/geo/surfacerzfourier.py#L226-L228

Added lines #L226 - L228 were not covered by tests

otherntheta = other.quadpoints_theta.size
othernphi = other.quadpoints_phi.size

Check warning on line 231 in src/simsopt/geo/surfacerzfourier.py

View check run for this annotation

Codecov / codecov/patch

src/simsopt/geo/surfacerzfourier.py#L230-L231

Added lines #L230 - L231 were not covered by tests

#recalculate the quadpoints if necessary (grid_range is not stored in the
# surface object, so assume that if it is given, the gridpoints should be
# recalculated to the specified size)
if ntheta is not otherntheta and nphi is not othernphi and grid_range is not None:
kwargs["quadpoints_phi"], kwargs["quadpoints_theta"] = Surface.get_quadpoints(

Check warning on line 237 in src/simsopt/geo/surfacerzfourier.py

View check run for this annotation

Codecov / codecov/patch

src/simsopt/geo/surfacerzfourier.py#L236-L237

Added lines #L236 - L237 were not covered by tests
ntheta=ntheta, nphi=nphi, nfp=other.nfp, range=grid_range)
else:
kwargs["quadpoints_phi"] = other.quadpoints_phi
kwargs["quadpoints_theta"] = other.quadpoints_theta

Check warning on line 241 in src/simsopt/geo/surfacerzfourier.py

View check run for this annotation

Codecov / codecov/patch

src/simsopt/geo/surfacerzfourier.py#L240-L241

Added lines #L240 - L241 were not covered by tests

surf = cls(mpol=other.mpol, ntor=other.ntor, nfp=other.nfp, stellsym=other.stellsym,

Check warning on line 243 in src/simsopt/geo/surfacerzfourier.py

View check run for this annotation

Codecov / codecov/patch

src/simsopt/geo/surfacerzfourier.py#L243

Added line #L243 was not covered by tests
**kwargs)
surf.rc[:, :] = other.rc
surf.zs[:, :] = other.zs
if not other.stellsym:
surf.rs[:, :] = other.rs
surf.zc[:, :] = other.zc
surf.local_full_x = surf.get_dofs()
return surf

Check warning on line 251 in src/simsopt/geo/surfacerzfourier.py

View check run for this annotation

Codecov / codecov/patch

src/simsopt/geo/surfacerzfourier.py#L245-L251

Added lines #L245 - L251 were not covered by tests

@classmethod
def from_vmec_input(cls, filename: str, **kwargs):
Expand Down

0 comments on commit 9da8baa

Please sign in to comment.