-
Notifications
You must be signed in to change notification settings - Fork 26
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
Integrate on boundary to compute length scale quantities #1094
base: master
Are you sure you want to change the base?
Changes from all commits
56ead44
504cdfc
27a6fcb
f1c7634
2694e8c
69fa9ce
93c710b
7970177
be11015
80feb38
c31abcd
acf0486
9974137
3ea229d
1f6c8ce
8c778fa
5912c79
1659fc0
4222b74
cf81a3c
1bc81ae
b6bb3ce
167156f
780ddb3
a93b98b
66b402a
01e212f
d7c6d26
3fb1ccf
c21913e
6adaa96
cd2c25a
340f4a8
5914a8a
d88f47c
f23b97f
e8c8ca9
77c9992
cace498
c88a7a7
7cacd7e
2771487
3e51e5c
eb8b50c
fd8454f
9d6f4f2
7ee3fdb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -982,7 +982,6 @@ def need_src(name): | |
# Warn if best way to compute accurately is increasing resolution. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adjusted logic to be more self-consistent. Will raise all warnings raised previously and covers some additional cases. |
||
for dep in deps: | ||
req = data_index[p][dep]["resolution_requirement"] | ||
coords = data_index[p][dep]["coordinates"] | ||
msg = lambda direction: ( | ||
f"Dependency {dep} may require more {direction}" | ||
" resolution to compute accurately." | ||
|
@@ -991,23 +990,34 @@ def need_src(name): | |
# if need more radial resolution | ||
"r" in req and grid.L < self.L_grid | ||
# and won't override grid to one with more radial resolution | ||
and not (override_grid and coords in {"z", ""}), | ||
and not ( | ||
override_grid and (is_1dz_tor_grid(dep) or is_0d_vol_grid(dep)) | ||
), | ||
ResolutionWarning, | ||
msg("radial") + f" got L_grid={grid.L} < {self._L_grid}.", | ||
) | ||
warnif( | ||
# if need more poloidal resolution | ||
"t" in req and grid.M < self.M_grid | ||
# and won't override grid to one with more poloidal resolution | ||
and not (override_grid and coords in {"r", "z", ""}), | ||
and not ( | ||
override_grid | ||
and ( | ||
is_1dr_rad_grid(dep) | ||
or is_1dz_tor_grid(dep) | ||
or is_0d_vol_grid(dep) | ||
) | ||
), | ||
ResolutionWarning, | ||
msg("poloidal") + f" got M_grid={grid.M} < {self._M_grid}.", | ||
) | ||
warnif( | ||
# if need more toroidal resolution | ||
"z" in req and grid.N < self.N_grid | ||
# and won't override grid to one with more toroidal resolution | ||
and not (override_grid and coords in {"r", ""}), | ||
and not ( | ||
override_grid and (is_1dr_rad_grid(dep) or is_0d_vol_grid(dep)) | ||
), | ||
ResolutionWarning, | ||
msg("toroidal") + f" got N_grid={grid.N} < {self._N_grid}.", | ||
) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These changes were made to pass the elongation test after relaxing the dependencies of a_major/a_minor to |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,6 @@ | |
from matplotlib import cycler, rcParams | ||
from mpl_toolkits.axes_grid1 import make_axes_locatable | ||
from pylatexenc.latex2text import LatexNodes2Text | ||
from termcolor import colored | ||
|
||
from desc.backend import sign | ||
from desc.basis import fourier, zernike_radial_poly | ||
|
@@ -187,15 +186,12 @@ | |
return plt.gcf(), ax | ||
else: | ||
ax = np.atleast_1d(ax) | ||
if isinstance(ax.flatten()[0], matplotlib.axes.Axes): | ||
return plt.gcf(), ax | ||
else: | ||
raise TypeError( | ||
colored( | ||
"ax argument must be None or an axis instance or array of axes", | ||
"red", | ||
) | ||
) | ||
errorif( | ||
not isinstance(ax.flatten()[0], matplotlib.axes.Axes), | ||
TypeError, | ||
"ax argument must be None or an axis instance or array of axes", | ||
) | ||
return plt.gcf(), ax | ||
|
||
|
||
def _get_grid(**kwargs): | ||
|
@@ -278,11 +274,10 @@ | |
|
||
""" | ||
parameterization = _parse_parameterization(eq) | ||
if name not in data_index[parameterization]: | ||
raise ValueError( | ||
f"Unrecognized value '{name}' for " | ||
+ f"parameterization {parameterization}." | ||
) | ||
errorif( | ||
name not in data_index[parameterization], | ||
msg=f"Unrecognized value '{name}' for parameterization {parameterization}.", | ||
) | ||
assert component in [ | ||
None, | ||
"R", | ||
|
@@ -294,9 +289,7 @@ | |
|
||
label = data_index[parameterization][name]["label"] | ||
|
||
with warnings.catch_warnings(): | ||
warnings.simplefilter("ignore") | ||
data = eq.compute(name, grid=grid)[name] | ||
data = eq.compute(name, grid=grid)[name] | ||
|
||
if data_index[parameterization][name]["dim"] > 1: | ||
if component is None: | ||
|
@@ -520,47 +513,50 @@ | |
grid_kwargs = {"L": default_L, "N": default_N, "NFP": NFP} | ||
grid = _get_grid(**grid_kwargs) | ||
plot_axes = _get_plot_axes(grid) | ||
|
||
data, ylabel = _compute( | ||
eq, name, grid, kwargs.pop("component", None), reshape=False | ||
) | ||
|
||
# reshape data to 1D | ||
if len(plot_axes) != 1: | ||
return ValueError(colored("Grid must be 1D", "red")) | ||
surface_label = {"r": "rho", "t": "theta", "z": "zeta"}.get( | ||
data_index[parameterization][name]["coordinates"], None | ||
) | ||
axis = {"r": 0, "t": 1, "z": 2}.get( | ||
data_index[parameterization][name]["coordinates"], None | ||
) | ||
errorif( | ||
surface_label is None or axis is None, | ||
NotImplementedError, | ||
msg="Grid must be 1D", | ||
) | ||
data = grid.compress(data, surface_label=surface_label) | ||
nodes = grid.compress(grid.nodes[:, axis], surface_label=surface_label) | ||
else: | ||
axis = plot_axes[0] | ||
data = data.ravel() | ||
nodes = grid.nodes[:, axis] | ||
|
||
data, ylabel = _compute(eq, name, grid, kwargs.pop("component", None)) | ||
label = kwargs.pop("label", None) | ||
|
||
fig, ax = _format_ax(ax, figsize=kwargs.pop("figsize", None)) | ||
|
||
# reshape data to 1D | ||
data = data.flatten() | ||
linecolor = kwargs.pop("linecolor", colorblind_colors[0]) | ||
ls = kwargs.pop("ls", "-") | ||
lw = kwargs.pop("lw", 1) | ||
if log: | ||
data = np.abs(data) # ensure data is positive for log plot | ||
ax.semilogy( | ||
grid.nodes[:, plot_axes[0]], | ||
data, | ||
label=label, | ||
color=linecolor, | ||
ls=ls, | ||
lw=lw, | ||
) | ||
ax.semilogy(nodes, data, label=label, color=linecolor, ls=ls, lw=lw) | ||
else: | ||
ax.plot( | ||
grid.nodes[:, plot_axes[0]], | ||
data, | ||
label=label, | ||
color=linecolor, | ||
ls=ls, | ||
lw=lw, | ||
) | ||
ax.plot(nodes, data, label=label, color=linecolor, ls=ls, lw=lw) | ||
xlabel_fontsize = kwargs.pop("xlabel_fontsize", None) | ||
ylabel_fontsize = kwargs.pop("ylabel_fontsize", None) | ||
|
||
assert len(kwargs) == 0, f"plot_1d got unexpected keyword argument: {kwargs.keys()}" | ||
xlabel = _AXIS_LABELS_RTZ[plot_axes[0]] | ||
xlabel = _AXIS_LABELS_RTZ[axis] | ||
ax.set_xlabel(xlabel, fontsize=xlabel_fontsize) | ||
ax.set_ylabel(ylabel, fontsize=ylabel_fontsize) | ||
_set_tight_layout(fig) | ||
plot_data = {xlabel.strip("$").strip("\\"): grid.nodes[:, plot_axes[0]], name: data} | ||
plot_data = {xlabel.strip("$").strip("\\"): nodes, name: data} | ||
|
||
if label is not None: | ||
ax.legend() | ||
|
@@ -641,8 +637,7 @@ | |
grid_kwargs = {"M": 33, "N": 33, "NFP": eq.NFP, "axis": False} | ||
grid = _get_grid(**grid_kwargs) | ||
plot_axes = _get_plot_axes(grid) | ||
if len(plot_axes) != 2: | ||
return ValueError(colored("Grid must be 2D", "red")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (should be raising not returning error) |
||
errorif(len(plot_axes) != 2, msg="Grid must be 2D") | ||
component = kwargs.pop("component", None) | ||
if name != "B*n": | ||
data, label = _compute( | ||
|
@@ -655,14 +650,12 @@ | |
field = kwargs.pop("field", None) | ||
errorif( | ||
field is None, | ||
ValueError, | ||
"If B*n is entered as the variable to plot, a magnetic field" | ||
msg="If B*n is entered as the variable to plot, a magnetic field" | ||
" must be provided.", | ||
) | ||
errorif( | ||
not np.all(np.isclose(grid.nodes[:, 0], 1)), | ||
ValueError, | ||
"If B*n is entered as the variable to plot, " | ||
msg="If B*n is entered as the variable to plot, " | ||
"the grid nodes must be at rho=1.", | ||
) | ||
|
||
|
@@ -947,14 +940,12 @@ | |
field = kwargs.pop("field", None) | ||
errorif( | ||
field is None, | ||
ValueError, | ||
"If B*n is entered as the variable to plot, a magnetic field" | ||
msg="If B*n is entered as the variable to plot, a magnetic field" | ||
" must be provided.", | ||
) | ||
errorif( | ||
not np.all(np.isclose(grid.nodes[:, 0], 1)), | ||
ValueError, | ||
"If B*n is entered as the variable to plot, " | ||
msg="If B*n is entered as the variable to plot, " | ||
"the grid nodes must be at rho=1.", | ||
) | ||
|
||
|
@@ -985,8 +976,7 @@ | |
|
||
errorif( | ||
len(kwargs) != 0, | ||
ValueError, | ||
f"plot_3d got unexpected keyword argument: {kwargs.keys()}", | ||
msg=f"plot_3d got unexpected keyword argument: {kwargs.keys()}", | ||
) | ||
with warnings.catch_warnings(): | ||
warnings.simplefilter("ignore") | ||
|
@@ -2497,8 +2487,7 @@ | |
showaxislabels = kwargs.pop("showaxislabels", True) | ||
errorif( | ||
len(kwargs) != 0, | ||
ValueError, | ||
f"plot_coils got unexpected keyword argument: {kwargs.keys()}", | ||
msg=f"plot_coils got unexpected keyword argument: {kwargs.keys()}", | ||
) | ||
errorif( | ||
not isinstance(coils, _Coil), | ||
|
@@ -2925,7 +2914,7 @@ | |
iota = grid_compute.compress(data["iota"]) | ||
else: # OmnigenousField | ||
iota = kwargs.pop("iota", None) | ||
errorif(iota is None, ValueError, "iota must be supplied for OmnigenousField") | ||
errorif(iota is None, msg="iota must be supplied for OmnigenousField") | ||
with warnings.catch_warnings(): | ||
warnings.simplefilter("ignore") | ||
data = thing.compute( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#1094 (comment)