-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathrun_sequential_opt.py
70 lines (53 loc) · 1.85 KB
/
run_sequential_opt.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import numpy as np
import openmdao.api as om
from components.compute_pitch_angles import ComputePitchAngles
from components.design_airfoil import DesignAirfoil
from components.compute_modified_power import ComputeModifiedPower
wind_speeds = [4.0, 6.0, 8.0, 10.0]
P_rated = 500.0
prob1 = om.Problem()
prob1.model.add_subsystem(
"design_airfoil",
DesignAirfoil(size=len(wind_speeds)),
promotes=["*"],
)
prob1.model.add_subsystem(
"compute_modified_power",
ComputeModifiedPower(size=len(wind_speeds)),
promotes=["*"],
)
prob1.driver = om.ScipyOptimizeDriver()
prob1.driver.options["optimizer"] = "SLSQP"
prob1.model.approx_totals(method="fd")
prob1.model.add_design_var("airfoil_design", lower=6.0, upper=15.0)
prob1.model.add_objective("modified_power")
prob1.setup()
prob1.set_val("wind_speeds", wind_speeds)
prob2 = om.Problem()
prob2.model.add_subsystem(
"compute_pitch_angles",
ComputePitchAngles(size=len(wind_speeds), P_rated=P_rated),
promotes=["*"],
)
prob2.model.add_subsystem(
"compute_modified_power",
ComputeModifiedPower(size=len(wind_speeds)),
promotes=["*"],
)
prob2.driver = om.ScipyOptimizeDriver()
prob2.driver.options["optimizer"] = "SLSQP"
prob2.model.approx_totals(method="fd")
prob2.model.add_design_var("drag_modifier", lower=6.0, upper=15.0)
prob2.model.add_constraint("powers", lower=-P_rated)
prob2.model.add_objective("modified_power")
prob2.setup()
prob2.set_val("wind_speeds", wind_speeds)
for i in range(10):
prob1.set_val("powers", prob2["powers"])
prob1.run_driver()
prob1.model.list_inputs()
prob1.model.list_outputs(print_arrays=True)
prob2.set_val("aerodynamic_efficiency", prob1["aerodynamic_efficiency"])
prob2.run_driver()
prob2.model.list_inputs()
prob2.model.list_outputs(print_arrays=True)