@@ -70,7 +70,7 @@ def bem_data(f1, nfreq, ndof, ndir):
7070 Froude_Krylov_force = np .ones ([nfreq , ndof , ndir ], dtype = complex ) + 1j
7171 inertia_matrix = np .ones ([ndof , ndof ])
7272 hydrostatic_stiffness = np .ones ([ndof , ndof ])
73-
73+
7474 data_vars = {
7575 'added_mass' : (radiation_dims , added_mass ),
7676 'radiation_damping' : (radiation_dims , radiation_damping ),
@@ -160,24 +160,24 @@ def test_plot_hydrodynamic_coefficients(bem_data,ndof):
160160 assert isinstance (fig_ex ,Figure )
161161
162162def test_plot_bode_impedance (intrinsic_impedance , ndof ):
163- fig_Zi , axes_Zi = wot .utilities .plot_bode_impedance (intrinsic_impedance )
164-
163+ fig_Zi , axes_Zi = wot .utilities .plot_bode_impedance (intrinsic_impedance )
164+
165165 assert 2 * ndof * ndof == len (fig_Zi .axes )
166166 assert isinstance (fig_Zi ,Figure )
167167 assert all ([isinstance (ax , Axes ) for ax in np .reshape (axes_Zi ,- 1 )])
168168
169169
170170def test_plot_power_flow (power_flows ):
171- fig_sankey , ax_sankey = wot .utilities .plot_power_flow (power_flows )
172-
171+ fig_sankey , ax_sankey = wot .utilities .plot_power_flow (power_flows )
172+
173173 assert isinstance (fig_sankey , Figure )
174- assert isinstance (ax_sankey , Axes )
174+ assert isinstance (ax_sankey , Axes )
175175
176176def test_calculate_power_flow (wb_bem ,
177177 regular_wave ,
178178 pi_controller_pto ,
179179 wb_hydro_impedance ):
180- """PI controller matches optimal for any regular wave,
180+ """PI controller matches optimal for any regular wave,
181181 thus we check if the radiated power is equal the absorber power
182182 and if the Optimal excitation is equal the actual excitation"""
183183
@@ -196,14 +196,39 @@ def test_calculate_power_flow(wb_bem,
196196 bounds_opt = ((- 1e4 , 0 ), (0 , 2e4 ),)
197197 )
198198
199- pflows = wot .utilities .calculate_power_flows (wec ,
200- pi_controller_pto ,
201- res ,
202- regular_wave ,
199+ pflows = wot .utilities .calculate_power_flows (wec ,
200+ pi_controller_pto ,
201+ res ,
202+ regular_wave ,
203203 wb_hydro_impedance )
204204
205205 assert pflows ['Absorbed' ] == approx (pflows ['Radiated' ], rel = 1e-4 )
206206 assert pflows ['Optimal Excitation' ] == approx (pflows ['Actual Excitation' ], rel = 1e-4 )
207207
208-
209-
208+ def test_linear_solve (wb_bem , regular_wave ):
209+ omega = wb_bem .omega .values
210+ gear_ratio = 12.0
211+ torque_constant = 6.7
212+ winding_resistance = 0.5
213+ winding_inductance = 0.0
214+ drivetrain_inertia = 2.0
215+ drivetrain_friction = 1.0
216+ drivetrain_stiffness = 0.0
217+
218+ drivetrain_impedance = (1j * omega * drivetrain_inertia +
219+ drivetrain_friction +
220+ 1 / (1j * omega )* drivetrain_stiffness )
221+
222+ winding_impedance = winding_resistance + 1j * omega * winding_inductance
223+
224+
225+ pto_impedance_11 = - 1 * gear_ratio ** 2 * drivetrain_impedance
226+ off_diag = np .sqrt (3.0 / 2.0 ) * torque_constant * gear_ratio
227+ pto_impedance_12 = - 1 * (off_diag + 0j ) * np .ones (omega .shape )
228+ pto_impedance_21 = - 1 * (off_diag + 0j ) * np .ones (omega .shape )
229+ pto_impedance_22 = winding_impedance
230+ pto_impedance = np .array ([[pto_impedance_11 , pto_impedance_12 ],
231+ [pto_impedance_21 , pto_impedance_22 ]])
232+
233+ power , _ , _ , _ = wot .utilities .linear_solve (wb_bem , pto_impedance , regular_wave .isel (realization = 0 ), np .eye (1 ))
234+ assert power == approx (- 29.2 , abs = 0.05 )
0 commit comments