Skip to content

Commit 7443aa6

Browse files
jtgrasbcmichelenstroferrgcoedtgaebemichaelcdevin
committed
Pioneer tutorial updates (empirical impedance model and nonlinear spring) (sandialabs#362)
* Update CONTRIBUTING.md to indicate PRs should be to the new `dev` branch * Update RELEASING.md to reflect new workflow with the `dev` branch * Set Default uniform_shift to False (sandialabs#313) * Make uniform shift default false and fix test_core * Allow for non-uniform shift for impedance * update docstrings (sandialabs#326) * damping naming and consistently change radiation damping (sandialabs#328) * run CI + codeQL on dev PRs/pushses * Fix test failures (sandialabs#330) * fix tests * fix pioneer * actually test power solution for irregular wave (sandialabs#327) * Update test_integration with new scaling (sandialabs#333) * Phase Realizations Demo and Docs (sandialabs#315) * Pioneer tutorial realizations demo Add frequency array and realization study to beginning of pioneer tutorial * Update pioneer * Clean pioneer and update docs * remove print * Units * Update pioneer plots * Waves before frequencies * Explain less frequencies * Minor updates * Update pioneer * Merge branch 'dev' of https://github.com/sandialabs/WecOptTool into phases_demo * issue 321 fd_to_td() bug (sandialabs#329) * bug bix : DC and Nyquist frequency should not be devided by two before ifft * Changed td_to_fd to scale single sided frequency components rather than TD signal * minor bug fix from issue332 sandialabs#332 * nodf -> ndof (sandialabs#334) * add DOI for Daniel's paper (sandialabs#336) * Tutorial cleanup (sandialabs#339) * run CI on PRs against dev branch * revamped tutorial 1, including fix for sandialabs#293 * more tutorial cleanup and editorial changes * more cleanup and incorporated changes in sandialabs#315 * fixed tutorial 2 colormaps * finishing touches * reverted a few accidental changes * fixes as per Jeff's review comments --------- Co-authored-by: Ryan Coe <[email protected]> * Utils dev - replaces old utilities PR (sandialabs#343) * run CI on PRs against dev branch * coppied fundamental utility files * import utilities module * added utilities funtions to tut1 * added bem plot from utils * added bem plot from utils * updated sankey plot * updated check_radiation_damping * cleared outputs * corrected bug * changed Zi to hydro_impedance to be consistent with our variables name python convention * PR review edits * add grid to plots * removed draft functions in utilities.py * typo * Fixed one more typo I found while reviewing Daniel's changes --------- Co-authored-by: Ryan Coe <[email protected]> Co-authored-by: Michael Devin <[email protected]> * Post process docstrings; use loops for multiple realizations (sandialabs#337) * post_processing docstrings - examples - parameters (order) * handle multiple phase realizations internally * Update wecopttool/core.py * making outputs lists * Update implementation to function with tutorial 1 for now * Update tutorials * Update LUPA * Make sure same WEC is passed in * Add test_utilities Revert "Add test_utilities" This reverts commit 27399f0. * Update utilities module * Update utilities * Update test_utilities * Update tutorial 1 utilities call --------- Co-authored-by: Carlos A. Michelén Ströfer <[email protected]> Co-authored-by: Carlos A. Michelén Ströfer <[email protected]> Co-authored-by: jtgrasb <[email protected]> Co-authored-by: jtgrasb <[email protected]> * v3.0.0 * Lower tolerance for new test to fix CI failing occasionally * hyperlinks no longer have formatting, plus other small adjustments (sandialabs#348) * Merge to dev, not main (sandialabs#349) * Dev version of documentation site (sandialabs#347) * added initial file changes based on sphinx_multiversion docs and WEC-Sim implementation * removed sphinx-multiversion since it is no longer supported and made manual multiversion * now uses absolute paths, commented out linkcheck for debugging * fixed docstring errors in utilities module * updating files again that somehow got reverted * fixing path in conf.py * don't run tutorials (will revert later) * handle file moves correctly, fixed if statement to make other versions appear * fixed two bugs in versions template * reverted temp changes, changes latest to main * switched latest to main * main branch now in root directory of pages * fixed URLs with change from last commit * make other branches visible before building * switched main branch tag for more testing * fixed typo * switched dev branch to an existing branch * renamed main to latest, changed version.html file name to avoid confusion * added prints about moving files so Sphinx output isn't misleading * fixed typo with quotations * changed versions.html name back because that broke things I guess * modified contributing documentation to reflect changes * add logic to remove duplicate 'latest' branch * Fixed pathing when already on latest * remove typo * Troubleshooting complete, switching back to correct branches for deployment * Removed extra word in docstring * removed redundant function * fixed pathing so returns to same file (and fixes tutorial/API docs) * changed latest branch for demonstration * switched back latest branch for deployment * updated with new Capytaine docs URL * Add warnings when adding inertia and hydrostatic stiffness automatically (sandialabs#346) * Add data and update tutorial 4 * CI workflow cleanup (sandialabs#352) * removed conda environment from workflows since newer capytaine/wavespectra work with Windows * fixed unnecessary capitalization * still create CI conda environment to fix Mac environment failures * added conda env fully back in, push workflow deploys docs, split PR workflow * conda environment activates again * mambaforge instead of miniforge * manual cache reset * reset to older version of setup-miniconda to troubleshoot * Specify NumPy version <2.0 since it breaks autograd * v3.0.1 (sandialabs#360) * Revert "v3.0.1 (sandialabs#360)" (sandialabs#361) This reverts commit f79ff8b. * Update pyproject.toml * Update pioneer tutorial with nl spring and empirical model * Clear outputs * Consolidate empirical data and fix small issues * Remove consolidation file --------- Co-authored-by: Carlos A. Michelén Ströfer <[email protected]> Co-authored-by: Ryan Coe <[email protected]> Co-authored-by: Daniel Gaebele <[email protected]> Co-authored-by: Michael Devin <[email protected]> Co-authored-by: Carlos A. Michelén Ströfer <[email protected]> Co-authored-by: mcdevin <[email protected]>
1 parent 7ad5ffb commit 7443aa6

File tree

3 files changed

+27
-41
lines changed

3 files changed

+27
-41
lines changed
18.2 KB
Binary file not shown.

examples/tutorial_4_Pioneer.ipynb

Lines changed: 21 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
"from scipy.linalg import block_diag\n",
4242
"import xarray as xr\n",
4343
"from math import comb\n",
44-
"from wavespectra.construct.frequency import pierson_moskowitz\n",
4544
"\n",
4645
"import wecopttool as wot\n",
4746
"\n",
@@ -76,11 +75,9 @@
7675
"fend = 1.875\n",
7776
"nfreq_irreg = 150\n",
7877
"f1_irreg = fend / nfreq_irreg\n",
79-
"freq_irreg = wot.frequency(f1_irreg, nfreq_irreg, False) # False -> no zero frequency\n",
8078
"\n",
8179
"f1_reg = .325/2\n",
82-
"nfreq_reg = 12\n",
83-
"freq_reg = wot.frequency(f1_reg, nfreq_reg, False) # False -> no zero frequency"
80+
"nfreq_reg = 12"
8481
]
8582
},
8683
{
@@ -100,7 +97,8 @@
10097
"nrealizations = 2\n",
10198
"\n",
10299
"fp = 1/Tp\n",
103-
"efth = pierson_moskowitz(freq=freq_irreg, hs=Hs, fp=fp)\n",
100+
"spectrum = lambda f: wot.waves.pierson_moskowitz_spectrum(f, fp, Hs)\n",
101+
"efth = wot.waves.omnidirectional_spectrum(f1_irreg, nfreq_irreg, spectrum, \"Pierson-Moskowitz\")\n",
104102
"waves_irregular = wot.waves.long_crested_wave(efth, nrealizations=nrealizations)"
105103
]
106104
},
@@ -280,9 +278,14 @@
280278
"outputs": [],
281279
"source": [
282280
"rho = 1025. # kg/m^3\n",
281+
"freq_reg = wot.frequency(f1_reg, nfreq_reg, False) # False -> no zero frequency\n",
283282
"bem_data_reg = wot.run_bem(pnr_fb, freq_reg)\n",
284283
"omega_reg = bem_data_reg.omega.values\n",
285284
"\n",
285+
"freq_irreg = wot.frequency(f1_irreg, nfreq_irreg, False) # False -> no zero frequency\n",
286+
"bem_data_irreg = wot.run_bem(pnr_fb, freq_irreg)\n",
287+
"omega_irreg = bem_data_irreg.omega.values\n",
288+
"\n",
286289
"bem_data_irreg = wot.run_bem(pnr_fb, freq_irreg)\n",
287290
"omega_irreg = bem_data_irreg.omega.values\n",
288291
"\n",
@@ -307,19 +310,12 @@
307310
"outputs": [],
308311
"source": [
309312
"# load in the empirical data\n",
310-
"datafile = 'data/pioneer_empirical_data.npz'\n",
311-
"\n",
312-
"with np.load(datafile) as empirical_data:\n",
313-
" # Access the data within the 'with' block\n",
314-
" omega_data = empirical_data['omega_data']\n",
315-
" exc_coeff_data = empirical_data['exc_coeff_data']\n",
316-
" Zi_data = empirical_data['Zi_data']\n",
317-
" Zi_stiffness = empirical_data['Zi_stiffness']\n",
318-
"\n",
319-
"dof_names = [\"Pitch\"]\n",
320-
"directions = [0]\n",
313+
"datafile = 'data/pioneer_empirical_data.nc'\n",
314+
"empirical_data = xr.load_dataset(datafile)\n",
321315
"\n",
322-
"exc_coeff_data, Zi_data = wot.utilities.create_dataarray(Zi_data, exc_coeff_data, omega_data, directions, dof_names)\n",
316+
"exc_coeff_data = empirical_data.exc_coeff_data_real + 1j*empirical_data.exc_coeff_data_imag\n",
317+
"Zi_data = empirical_data.Zi_data_real + 1j*empirical_data.Zi_data_imag\n",
318+
"Zi_stiffness = empirical_data.Zi_stiffness\n",
323319
"\n",
324320
"# here extrapolation for impedance and padding with zeros for the excitation\n",
325321
"exc_coeff_intrp_reg = exc_coeff_data.interp(omega = omega_reg, method='linear', kwargs={\"fill_value\": 0})\n",
@@ -503,12 +499,7 @@
503499
"pto_impedance = np.array([[pto_impedance_11, pto_impedance_12],\n",
504500
" [pto_impedance_21, pto_impedance_22]])\n",
505501
"\n",
506-
"pto = wot.pto.PTO(ndof, \n",
507-
" kinematics=[1], \n",
508-
" controller=wot.controllers.unstructured_controller(), \n",
509-
" impedance=pto_impedance, \n",
510-
" loss=None, \n",
511-
" names=None)\n"
502+
"pto = wot.pto.PTO(ndof, kinematics=[1], controller=None, impedance=pto_impedance, loss=None, names=None)\n"
512503
]
513504
},
514505
{
@@ -856,7 +847,7 @@
856847
"outputs": [],
857848
"source": [
858849
"fig, ax = plt.subplots(nrows=5, sharex=True, figsize=(12, 12))\n",
859-
"t = wec_tdom.sel(realization=0).time.values\n",
850+
"t = wec_tdom[0].time.values\n",
860851
"\n",
861852
"# Positions\n",
862853
"ax[0].plot(t, fw_pos*180/np.pi, label='Flywheel', c='k')\n",
@@ -881,7 +872,7 @@
881872
"ax1 = ax[1].twinx()\n",
882873
"ax1.tick_params(axis='y', labelcolor='b')\n",
883874
"# when using an impedance model, the excitation force cannot be split up into Froude-Krylov and diffraction\n",
884-
"wec_tdom.sel(realization=0)['force'].sel(type='excitation').plot(ax=ax1, c='b') \n",
875+
"wec_tdom[0]['force'].sel(type='excitation').plot(ax=ax1, c='b') \n",
885876
"ax1.set_ylabel('Excitation torque [N-m]', color='b')\n",
886877
"ax1.set_title('Torque')\n",
887878
"\n",
@@ -937,8 +928,8 @@
937928
"Zi = Zi_intrp_reg\n",
938929
"Rad_res = np.real(Zi.squeeze())\n",
939930
"\n",
940-
"Fex = wec_fdom.sel(realization=0).force.sel(type=['excitation'])\n",
941-
"Vel = wec_fdom.sel(realization=0).vel\n",
931+
"Fex = wec_fdom[0].force.sel(type=['excitation'])\n",
932+
"Vel = wec_fdom[0].vel\n",
942933
"\n",
943934
"P_max_absorbable = (np.abs(Fex)**2/(8*Rad_res) ).squeeze().sum('omega').item() # after Falnes Eq. 6.10\n",
944935
"P_opt_excitation = 2*P_max_absorbable # after Falnes Eq. 6.10\n",
@@ -1043,12 +1034,7 @@
10431034
"pto_impedance = np.array([[pto_impedance_11, pto_impedance_12],\n",
10441035
" [pto_impedance_21, pto_impedance_22]])\n",
10451036
"\n",
1046-
"pto = wot.pto.PTO(ndof, \n",
1047-
" kinematics=[1], \n",
1048-
" controller=wot.controllers.unstructured_controller(), \n",
1049-
" impedance=pto_impedance, \n",
1050-
" loss=None, \n",
1051-
" names=None)\n",
1037+
"pto = wot.pto.PTO(ndof, kinematics=[1], controller=None, impedance=pto_impedance, loss=None, names=None)\n",
10521038
"\n",
10531039
"wec_lin = wot.WEC.from_impedance(freq_irreg, \n",
10541040
" Zi_intrp_irreg,\n",
@@ -1135,7 +1121,7 @@
11351121
"outputs": [],
11361122
"source": [
11371123
"fig, ax = plt.subplots(nrows=5, sharex=True, figsize=(12, 12))\n",
1138-
"t = wec_tdom.sel(realization=0).time.values\n",
1124+
"t = wec_tdom[0].time.values\n",
11391125
"\n",
11401126
"# Positions\n",
11411127
"ax[0].plot(t, fw_pos*180/np.pi, label='Flywheel', c='k')\n",
@@ -1159,7 +1145,7 @@
11591145
"\n",
11601146
"ax1 = ax[1].twinx()\n",
11611147
"ax1.tick_params(axis='y', labelcolor='b')\n",
1162-
"wec_tdom.sel(realization=0)['force'].sel(type=['excitation']).plot(ax=ax1, c='b')\n",
1148+
"wec_tdom[0]['force'].sel(type=['excitation']).plot(ax=ax1, c='b')\n",
11631149
"ax1.set_ylabel('Excitation torque [N-m]', color='b')\n",
11641150
"ax1.set_title('Torque')\n",
11651151
"\n",

wecopttool/utilities.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,14 +153,14 @@ def plot_bode_impedance(impedance: DataArray,
153153
influenced_dofs = impedance.influenced_dof.values
154154
mag = 20.0 * np.log10(np.abs(impedance))
155155
phase = np.rad2deg(np.unwrap(np.angle(impedance)))
156-
freq = impedance.omega.values/2/np.pi
156+
freq = impedance.omega.values/2/np.pi
157157
if fig_axes is None:
158158
fig, axes = plt.subplots(
159-
2*len(radiating_dofs),
159+
2*len(radiating_dofs),
160160
len(influenced_dofs),
161-
tight_layout=True,
162-
sharex=True,
163-
figsize=(3*len(radiating_dofs), 3*len(influenced_dofs)),
161+
tight_layout=True,
162+
sharex=True,
163+
figsize=(3*len(radiating_dofs), 3*len(influenced_dofs)),
164164
squeeze=False
165165
)
166166
else:
@@ -276,7 +276,7 @@ def calculate_power_flows(wec,
276276
return power_flows
277277

278278

279-
def plot_power_flow(power_flows: dict[str, float],
279+
def plot_power_flow(power_flows: dict[str, float],
280280
tolerance: Optional[float] = None,
281281
)-> tuple(Figure, Axes):
282282
"""Plot power flow through a WEC as Sankey diagram.

0 commit comments

Comments
 (0)