-
Notifications
You must be signed in to change notification settings - Fork 24
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
Set a different starting frequency. Closes #223 #292
Draft
cmichelenstrofer
wants to merge
15
commits into
sandialabs:main
Choose a base branch
from
cmichelenstrofer:fmin
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cmichelenstrofer
force-pushed
the
fmin
branch
from
November 22, 2023 17:55
00b1c51
to
9a36dca
Compare
Pull Request Test Coverage Report for Build 6961134641
💛 - Coveralls |
Status:
As part of debugging we tried the following in the main code:
|
@cmichelenstrofer I expanded some on this using the code below: Python codeimport autograd.numpy as np
import capytaine as cpy
import wecopttool as wot
# Frequencies
wavefreq = 0.6 # Hz
f1 = wavefreq/2
nfreq = 10
freq = wot.frequency(f1, nfreq, False) # False -> no zero frequency
# Waves
amplitude = 0.0625 # m
phase = 30 # degrees
wavedir = 0 # degrees
waves = wot.waves.regular_wave(f1, nfreq, wavefreq, amplitude, phase, wavedir)
extra_initial_freqs = 1
extra_initial_comps = extra_initial_freqs * 2
print(f'Wave elevations for each frequency: {np.abs(waves.loc[:,0,0])}')
# Geometry (WaveBot)
wb = wot.geom.WaveBot() # use standard dimensions
mesh_size_factor = 0.5 # 1.0 for default, smaller to refine mesh
mesh = wb.mesh(mesh_size_factor)
fb = cpy.FloatingBody.from_meshio(mesh, name="WaveBot")
fb.add_translation_dof(name="Heave")
ndof = fb.nb_dofs
# BEM
bem_data = wot.run_bem(fb, freq)
# PTO
name = ["PTO_Heave",]
kinematics = np.eye(ndof)
controller = None
loss = None
pto_impedance = None
pto = wot.pto.PTO(ndof, kinematics, controller, pto_impedance, loss, name)
f_add = {'PTO': pto.force_on_wec}
f_max = 750.0
nsubsteps = 4
# Constraints
tol = 1e-8
def const_zero_xw_ineq(wec, x_wec, x_opt, waves):
return tol - np.abs(x_wec[1:extra_initial_comps+1])
def const_zero_xo_ineq(wec, x_wec, x_opt, waves):
return tol - np.abs(x_opt[1:extra_initial_comps+1])
def const_zero_xw_eq(wec, x_wec, x_opt, waves):
return x_wec[1:extra_initial_comps+1]
def const_zero_xo_eq(wec, x_wec, x_opt, waves):
return x_opt[1:extra_initial_comps+1]
constraints_firstfreqzero_ineq = [
{'type': 'ineq', 'fun': const_zero_xw_ineq},
{'type': 'ineq', 'fun': const_zero_xo_ineq},
]
constraints_firstfreqzero_eq = [
{'type': 'eq', 'fun': const_zero_xw_eq},
{'type': 'eq', 'fun': const_zero_xo_eq},
]
# WEC object
wec = wot.WEC.from_bem(
bem_data,
constraints=None,
f_add=f_add,
)
wec_firstfreqzero_ineq = wot.WEC.from_bem(
bem_data,
constraints=constraints_firstfreqzero_ineq,
f_add=f_add,
)
wec_firstfreqzero_eq = wot.WEC.from_bem(
bem_data,
constraints=constraints_firstfreqzero_eq,
f_add=f_add,
)
# Objective function
obj_fun = pto.mechanical_average_power
nstate_opt = 2*nfreq
x_wec_0 = np.random.randn(wec.nstate_wec)
x_opt_0 = np.random.randn(nstate_opt)
options = {'maxiter': 200}
scale_x_wec = 1e1
scale_x_opt = 1e-3
scale_obj = 1e-2
# Reference case
results = wec.solve(
waves,
obj_fun,
nstate_opt,
optim_options=options,
x_wec_0=x_wec_0,
x_opt_0=x_opt_0,
scale_x_wec=scale_x_wec,
scale_x_opt=scale_x_opt,
scale_obj=scale_obj,
)
print('============================\nREFERENCE:\n============================')
print(f'Optimal average mechanical power: {results[0].fun} W')
print(f'Optimal state vector: {results[0].x}')
# Inequality constraint case
results_ffz_ineq = wec_firstfreqzero_ineq.solve(
waves,
obj_fun,
nstate_opt,
optim_options=options,
x_wec_0=x_wec_0,
x_opt_0=x_opt_0,
scale_x_wec=scale_x_wec,
scale_x_opt=scale_x_opt,
scale_obj=scale_obj,
)
print('============================\nWITH INEQUALITY CONSTRAINTS:\n============================')
print(f'Optimal average mechanical power: {results_ffz_ineq[0].fun} W')
print(f'Optimal state vector: {results_ffz_ineq[0].x}')
# Equality constraint case
results_ffz_eq = wec_firstfreqzero_eq.solve(
waves,
obj_fun,
nstate_opt,
optim_options=options,
x_wec_0=x_wec_0,
x_opt_0=x_opt_0,
scale_x_wec=scale_x_wec,
scale_x_opt=scale_x_opt,
scale_obj=scale_obj,
)
opt_power_ffz_eq = results_ffz_eq[0].fun
print('============================\nWITH EQUALITY CONSTRAINTS:\n============================')
print(f'Optimal average mechanical power: {opt_power_ffz_eq} W')
print(f'Optimal state vector: {results_ffz_eq[0].x}') Relevant output
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #223