Conversation
| and self.grid.NFP != self.basis.NFP | ||
| and self.basis.N != 0 | ||
| and grid.node_pattern != "custom" | ||
| and not isinstance(grid, Grid) |
There was a problem hiding this comment.
This is equivalent to the old code, since the old Grid class was hard-coded to have node_pattern="custom". In the new code, node_pattern is only an attribute of the ConcentricGrid class.
|
Add checks in objectives and inside geometric/magneticfield/coil compute methods to ensure grids passed in are correct (i.e. 1D for a filament coil, 3D for finite build coil, 1D or 2D rtz for surface) |
|
Rename AbstractRTZGrid to AbstractGridFlux instead of RTZ |
Memory benchmark result| Test Name | %Δ | Master (MB) | PR (MB) | Δ (MB) | Time PR (s) | Time Master (s) |
| -------------------------------------- | ------------ | ------------------ | ------------------ | ------------ | ------------------ | ------------------ |
test_objective_jac_w7x | 1.92 % | 3.843e+03 | 3.917e+03 | 73.83 | 38.77 | 35.84 |
test_proximal_jac_w7x_with_eq_update | -0.75 % | 6.614e+03 | 6.564e+03 | -49.76 | 160.17 | 158.04 |
test_proximal_freeb_jac | 0.12 % | 1.322e+04 | 1.323e+04 | 16.08 | 83.02 | 80.99 |
test_proximal_freeb_jac_blocked | -0.32 % | 7.564e+03 | 7.540e+03 | -24.30 | 72.80 | 71.30 |
test_proximal_freeb_jac_batched | 0.20 % | 7.479e+03 | 7.494e+03 | 15.05 | 72.90 | 73.29 |
test_proximal_jac_ripple | -2.18 % | 3.631e+03 | 3.552e+03 | -79.10 | 63.47 | 64.59 |
test_proximal_jac_ripple_bounce1d | -1.00 % | 3.548e+03 | 3.512e+03 | -35.59 | 74.33 | 74.43 |
test_eq_solve | -1.13 % | 2.034e+03 | 2.011e+03 | -23.03 | 92.25 | 91.33 |For the memory plots, go to the summary of |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #2053 +/- ##
==========================================
- Coverage 94.48% 94.21% -0.27%
==========================================
Files 102 107 +5
Lines 28721 29280 +559
==========================================
+ Hits 27137 27587 +450
- Misses 1584 1693 +109
🚀 New features to boost your workflow:
|
|
Presently we cannot do the following, because it throws an error that a variable is used before it is defined: The easy solution is to use a different variable name other than |
Does this work on master? I feel like it should behave the same. I don't think I've ever imported the grid module by itself though, only desc.grid |
this works on master from desc import grid
g = grid.LinearGrid() |
This also seems to work on this branch: @ddudt are you sure this is an issue? |
|
If you try to create a new from desc import grid as grid_module
grid = grid_module.Grid() |
| safenorm(data["e_theta"], axis=-1), | ||
| line_label="theta", | ||
| fix_surface=("rho", max_rho), | ||
| fix_surface=("x0", 0.0), |
| """ | ||
| line_label = grid.get_label(line_label) | ||
| line_label = grid.get_label(line_label) # general coordinate -> x0, x1, or x2 | ||
| fix_label = grid.get_label(fix_surface[0]) |
There was a problem hiding this comment.
Should the default of fix_surface change? Currently it is ("rho", 1.0)
| quantities on `LinearGrid(rho=rho, theta=Np, zeta=Nt, NFP=1, endpoint=True)` | ||
| and add it to the mesh by `mesh['name'] = value`. Once the mesh is changed, | ||
| Created structured grid object. With this object one can compute more quantities | ||
| and add them to the mesh by `mesh['name'] = value`. Once the mesh is changed, |
There was a problem hiding this comment.
I prefer to keep the default grid info since it needs to be the same if someone wants to add data to the mesh
| del self._inverse_theta_idx | ||
| if hasattr(self, "_inverse_poloidal_idx"): | ||
| self._inverse_x1_idx = self._inverse_poloidal_idx | ||
| del self._inverse_theta_idx |
There was a problem hiding this comment.
| del self._inverse_theta_idx | |
| del self._inverse_poloidal_idx |
| if coordinates[1] == "a": | ||
| period = (np.inf, np.inf, 2 * np.pi / NFP) | ||
| else: | ||
| period(np.inf, 2 * np.pi, 2 * np.pi / NFP) |
There was a problem hiding this comment.
| period(np.inf, 2 * np.pi, 2 * np.pi / NFP) | |
| period = (np.inf, 2 * np.pi, 2 * np.pi / NFP) |
?
| ) = self._find_unique_inverse_nodes() | ||
| self._weights = self._scale_weights() | ||
|
|
||
| def _create_nodes( # noqa: C901 |
There was a problem hiding this comment.
This function and all create_nodes methods of linear grid types are repeated code, right? Would it be better to have some utility functions for theta, zeta parts?
| Biot-Savart. Should NOT include endpoint at 2pi. | ||
| vc_source_grid : LinearGrid | ||
| LinearGrid to use for the singular integral for the virtual casing | ||
| vc_source_grid : LinearGridFlux |
There was a problem hiding this comment.
| vc_source_grid : LinearGridFlux | |
| vc_source_grid : LinearGridToroidalSurface |
| vc_source_grid : LinearGrid | ||
| LinearGrid to use for the singular integral for the virtual casing | ||
| vc_source_grid : LinearGridFlux | ||
| LinearGridFlux to use for the singular integral for the virtual casing |
There was a problem hiding this comment.
| LinearGridFlux to use for the singular integral for the virtual casing | |
| LinearGridToroidalSurface to use for the singular integral for the virtual casing |
| LinearGrid to use for the singular integral for the virtual casing | ||
| ``LinearGridToroidalSurface(M=max(3 * current_potential_field.M_Phi, 30), | ||
| N=max(3 * current_potential_field.N_Phi, 30), NFP=eq.NFP)`` | ||
| vc_source_grid : LinearGridFlux |
There was a problem hiding this comment.
| vc_source_grid : LinearGridFlux | |
| vc_source_grid : LinearGridToroidalSurface |
| default_M = 2 * eq.M if not hasattr(eq, "_M_grid") else eq.M_grid | ||
| default_N = 2 * eq.N if not hasattr(eq, "_M_grid") else eq.N_grid | ||
| plasma_grid = self._plasma_grid or LinearGrid( | ||
| plasma_grid = self._plasma_grid or LinearGridFlux( |
There was a problem hiding this comment.
| plasma_grid = self._plasma_grid or LinearGridFlux( | |
| plasma_grid = self._plasma_grid or LinearGridToroidalSurface( |
|
Github acts buggy for this PR (probably due to high number of changes), I will review the rest later |
There was a problem hiding this comment.
Do we eventually want to always enforce the proper grid type (no matter if the computation is the same for both)? I think that is slightly annoying, because for example, now we have a dedicated curve grid classes but we don't use them for magnetic axis. Or we have a toroidal surface class, but using them doesn't make the computation any different.
If you can explain which grid should be used when, and when it will be enforced in the grid notebook, it would help a lot for other reviewers, too.
Still need to review 40% of the files :)
| else: | ||
| grid = self._grid | ||
|
|
||
| errorif( |
There was a problem hiding this comment.
There will be couple hundred of this error in many places, might consider a helper function
# inside desc.utils or somewhere
def errorif_wrong_grid(grid, type, grid_name="grid"):
errorif(
not isinstance(grid, type),
ValueError,
msg=f"{grid_name} must be of type {type.__name__}, but got type {type(grid)}.",
)| # the sign convention is positive poloidal current flows up through the torus | ||
| # hole | ||
| grid_at_surf = LinearGrid(rho=1.0, M=eq.M_grid, N=eq.N_grid) | ||
| grid_at_surf = LinearGridFlux(rho=1.0, M=eq.M_grid, N=eq.N_grid) |
There was a problem hiding this comment.
| grid_at_surf = LinearGridFlux(rho=1.0, M=eq.M_grid, N=eq.N_grid) | |
| grid_at_surf = LinearGridToroidalSurface(rho=1.0, M=eq.M_grid, N=eq.N_grid) |
| dphi = phi[1] - phi[0] | ||
|
|
||
| grid = LinearGrid(M=0, L=0, zeta=phi, NFP=nfp) | ||
| grid = LinearGridFlux(M=0, L=0, zeta=phi, NFP=nfp) |
There was a problem hiding this comment.
| grid = LinearGridFlux(M=0, L=0, zeta=phi, NFP=nfp) | |
| grid = LinearGridCurve(M=0, L=0, zeta=phi, NFP=nfp) |
?
| Zbasis_sin = FourierSeries(N=N, NFP=nfp, sym=False) | ||
|
|
||
| grid = LinearGrid(M=0, L=0, zeta=phi, NFP=nfp) | ||
| grid = LinearGridFlux(M=0, L=0, zeta=phi, NFP=nfp) |
There was a problem hiding this comment.
| grid = LinearGridFlux(M=0, L=0, zeta=phi, NFP=nfp) | |
| grid = LinearGridCurve(M=0, L=0, zeta=phi, NFP=nfp) |
?
| bases["Zbasis_sin"] = Zbasis_sin | ||
|
|
||
| grid = LinearGrid(M=0, L=0, zeta=phi, NFP=nfp) | ||
| grid = LinearGridFlux(M=0, L=0, zeta=phi, NFP=nfp) |
There was a problem hiding this comment.
| grid = LinearGridFlux(M=0, L=0, zeta=phi, NFP=nfp) | |
| grid = LinearGridCurve(M=0, L=0, zeta=phi, NFP=nfp) |
?
| # need some sensible default grid | ||
| if self._grid is None: | ||
| grid = LinearGrid(M=eq.M_grid, N=eq.N_grid, NFP=eq.NFP, sym=eq.sym) | ||
| grid = LinearGridFlux(M=eq.M_grid, N=eq.N_grid, NFP=eq.NFP, sym=eq.sym) |
There was a problem hiding this comment.
These are also better be LienarGridToroidalSurface
| eq, | ||
| eval_grid=LinearGrid(M=20, N=20, NFP=eq.NFP, sym=True), | ||
| source_grid=LinearGrid(M=40, N=40, NFP=eq.NFP), | ||
| eval_grid=LinearGridFlux(M=20, N=20, NFP=eq.NFP, sym=True), |
There was a problem hiding this comment.
| eval_grid=LinearGridFlux(M=20, N=20, NFP=eq.NFP, sym=True), | |
| eval_grid=LinearGridToroidalSurface(M=20, N=20, NFP=eq.NFP, sym=True), |
| eq, | ||
| eval_grid=LinearGrid(M=M_egrid, N=N_egrid, NFP=eq.NFP, sym=True), | ||
| source_grid=LinearGrid(M=M_sgrid, N=N_sgrid, NFP=eq.NFP), | ||
| eval_grid=LinearGridFlux(M=M_egrid, N=N_egrid, NFP=eq.NFP, sym=True), |
There was a problem hiding this comment.
| eval_grid=LinearGridFlux(M=M_egrid, N=N_egrid, NFP=eq.NFP, sym=True), | |
| eval_grid=LinearGridToroidalSurface(M=M_egrid, N=N_egrid, NFP=eq.NFP, sym=True), |
| eq, | ||
| eval_grid=LinearGrid(M=M_egrid, N=N_egrid, NFP=eq.NFP, sym=True), | ||
| source_grid=LinearGrid(M=M_sgrid, N=N_sgrid, NFP=eq.NFP), | ||
| eval_grid=LinearGridFlux(M=M_egrid, N=N_egrid, NFP=eq.NFP, sym=True), |
There was a problem hiding this comment.
| eval_grid=LinearGridFlux(M=M_egrid, N=N_egrid, NFP=eq.NFP, sym=True), | |
| eval_grid=LinearGridToroidalSurface(M=M_egrid, N=N_egrid, NFP=eq.NFP, sym=True), |
| eq, | ||
| eval_grid=LinearGrid(M=M_egrid, N=N_egrid, NFP=eq.NFP, sym=True), | ||
| source_grid=LinearGrid(M=M_sgrid, N=N_sgrid, NFP=eq.NFP), | ||
| eval_grid=LinearGridFlux(M=M_egrid, N=N_egrid, NFP=eq.NFP, sym=True), |
There was a problem hiding this comment.
| eval_grid=LinearGridFlux(M=M_egrid, N=N_egrid, NFP=eq.NFP, sym=True), | |
| eval_grid=LinearGridToroidalSurface(M=M_egrid, N=N_egrid, NFP=eq.NFP, sym=True), |
Resolves #1840
Restructures and generalizes the Grid classes. The new ABC$\rho,\theta,\zeta$ ) coordinates and is the parent class of all existing grid classes in flux coordinates. Most of the changes involved moving existing code into one of these new ABCs.
AbstractGridthat all other grids inherit from does not assume a particular coordinate system. The new ABCAbstractGridFluxis specific to (The goal is to allow for new grid classes in the future that represent other coordinate systems, without changing the existing public API.
To-Do:
Basisdimensions (no references to flux coords)isinstance(grid, AbstractGridCurve)checks wherever appropriateCurveobjectsFourierRZToroidalSurfaceobjectsGrid->CustomGridFlux, etc. (do not deprecate)