wecopttool.core.WEC.solve
- WEC.solve(waves, obj_fun, nstate_opt, x_wec_0=None, x_opt_0=None, scale_x_wec=None, scale_x_opt=1.0, scale_obj=1.0, optim_options={}, use_grad=True, maximize=False, bounds_wec=None, bounds_opt=None, callback=None)[source]
Simulate WEC dynamics using a pseudo-spectral solution method and returns the raw results dictionary produced by
scipy.optimize.minimize()
.- Parameters:
waves (Dataset) –
xarray.Dataset
with the structure and elements shown bywecopttool.waves
.obj_fun (StateFunction) – Objective function to minimize for pseudo-spectral solution, must have signature
fun(wec, x_wec, x_opt, waves)
and return a scalar.nstate_opt (int) – Length of the optimization (controls) state vector.
x_wec_0 (ndarray | None) – Initial guess for the WEC dynamics state. If
None
it is randomly initiated.x_opt_0 (ndarray | None) – Initial guess for the optimization (control) state. If
None
it is randomly initiated.scale_x_wec (list | None) – Factor(s) to scale each DOF in
x_wec
by, to improve convergence. A single float or an array of sizendof
.scale_x_opt (FloatOrArray | None) – Factor(s) to scale
x_opt
by, to improve convergence. A single float or an array of sizenstate_opt
.scale_obj (float | None) – Factor to scale
obj_fun
by, to improve convergence.optim_options (Mapping[str, Any] | None) – Optimization options passed to the optimizer. See
scipy.optimize.minimize()
.use_grad (bool | None) – If
True
, optimization will utilize autograd for gradients.maximize (bool | None) – Whether to maximize the objective function. The default is to minimize the objective function.
bounds_wec (Bounds | None) – Bounds on the WEC components of the decision variable. See
scipy.optimize.minimize()
.bounds_opt (Bounds | None) – Bounds on the optimization (control) components of the decision variable. See
scipy.optimize.minimize()
.callback (StateFunction | None) – Function called after each iteration, must have signature
fun(wec, x_wec, x_opt, waves)
. The default provides status reports at each iteration via logging at the INFO level.
- Raises:
ValueError – If
scale_x_opt
is a scalar andnstate_opt
is not provided.Exception – If the optimizer fails for any reason other than maximum number of states, i.e. for exit modes other than 0 or 9. See
scipy.optimize
for exit mode details.
- Return type:
list[OptimizeResult]
Examples
The
wecopttool.WEC.solve()
method only returns the raw results dictionary produced byscipy.optimize.minimize()
.>>> res_opt = wec.solve(waves=wave, obj_fun=pto.average_power, nstate_opt=2*nfreq+1)
To get the post-processed results for the
wecopttool.WEC
andwecopttool.pto.PTO
for a single realization, you may call>>> realization = 0 # realization index >>> res_wec_fd, res_wec_td = wec.post_process(wec,res_opt,wave,nsubsteps) >>> res_pto_fd, res_pto_td = pto.post_process(wec,res_opt,wave,nsubsteps)
See also
wecopttool.waves
,wecopttool.core.wec.post_process
,wecopttool.core.pto.post_process