I am getting started with WISDEM and have set up a basic optimization problem based on the ExpicitComponent “PlantFinance” in plant_finance.py.
The object variable is the PlantFinance output “lcoe”, and the only design variable is the input “turbine_aep”. The PlantFinance input “tcc_per_kW” is the “turbine_cost_kW” output of a subsystem/instance of the ExplicitComponent “TurbineCostAdder2015” in nrel_csm_cost_2015.py, so “tcc_per_kW” and “turbine_cost_kW” are connected together. The remaining inputs of PlantFinance are input at the problem setup, or are kept at their default values in PlantFinance. This is the code:
import numpy as np
import openmdao.api as om
from wisdem.inputs import load_yaml
from wisdem.plant_financese.plant_finance import PlantFinance
from wisdem.nrelcsm.nrel_csm_cost_2015 import TurbineCostAdder2015, RotorCostAdder2015, BladeCost2015
from wisdem.nrelcsm.nrel_csm_mass_2015 import BladeMass
#==============================================================================
# =============================================================================
class call_to_group(om.Group):
# def initialize(self):
#
# pass
def setup(self):
self.add_subsystem("bladeMass_calc", BladeMass(),
promotes_inputs=['rotor_diameter'],
promotes_outputs=['blade_mass']
)
self.add_subsystem('bladeCost_calc', BladeCost2015(),
promotes_inputs=['blade_mass'],
promotes_outputs=['blade_cost']
)
self.add_subsystem("rotorCostAndMass_calc", RotorCostAdder2015(),
promotes_inputs=['blade_cost', 'blade_mass'],
promotes_outputs=['rotor_cost', 'rotor_mass_tcc']
)
self.add_subsystem("turbineCapitalCosts_calc", TurbineCostAdder2015(),
promotes_inputs=['rotor_cost', 'rotor_mass_tcc', 'machine_rating'] #,
# promotes_outputs=['turbine_cost_kW']
)
#
inputsToPlantFinance = [
"machine_rating",
"turbine_number",
"bos_per_kW",
"opex_per_kW",
"turbine_aep",
]
self.add_subsystem('LCoE_calc', PlantFinance(verbosity=False),
promotes_inputs=inputsToPlantFinance,
promotes_outputs=["lcoe"])
self.connect('turbineCapitalCosts_calc.turbine_cost_kW', 'LCoE_calc.tcc_per_kW')
# ============================入力============================================
design_options = load_yaml('windTurbine_design_options.yaml')
##
rotorDiameter = design_options["assembly"]["rotor_diameter"] # [m]
#
machine_rating = design_options["assembly"]["rated_power"] # [W] !!!
machine_rating /=1e3 # [kW] kWが必要だから。
turbine_number = design_options["costs"]["turbine_number"]
print(' turbine number=', turbine_number, '\n')
#----------- call to group---------------------------------
case = om.Problem()
case.model = call_to_group()#
case.driver = om.ScipyOptimizeDriver()
case.driver.options['optimizer'] = 'SLSQP' # this is not the cause of the optimization failure
case.model.add_design_var('turbine_aep', lower=1e6, upper=1.55e6) # , scaler=1e-1
case.model.add_objective('lcoe', scaler=1) # netAEPの最大化
#+++++++++++++++++++++#
+ Area 1
#+++++++++++++++++++++#
case.setup()
#+++++++++++++++++++++#
+ Area 2
#+++++++++++++++++++++#
case.check_partials(compact_print=True)
I am running check_partials before the optimization problem, but the check fails in the following manners:
- if, in Area 1 of the code, I set the inputs to the subsystem/instance of PlantFinance as
case.model.set_input_defaults('turbine_number', val=turbine_number) # case.model.set_input_defaults('machine_rating', val=machine_rating) # case.model.set_input_defaults('tcc_per_kW', val=500.0) # case.model.set_input_defaults('bos_per_kW', val=500.0) # case.model.set_input_defaults('opex_per_kW', val=5.0) case.model.set_input_defaults('rotor_diameter', val=rotorDiameter, units='m' ) case.model.set_input_defaults('turbine_aep', val=1e6, units="kW*h") #
I get the following error:
- if, in addition to the set_input_defaults lines in Area 1, I use set_val in Area 2 of the code as:
case.set_val('turbine_number', turbine_number)
case.set_val('tcc_per_kW', 500.0)
case.set_val('bos_per_kW', 500.0)
case.set_val('opex_per_kW', 5.0)
case.set_val('rotor_diameter', rotorDiameter)
case.set_val('machine_rating', machine_rating)
I get the following error:
If I comment out the line “case.set_val(‘tcc_per_kW’, 500.0)” the error becomes:
- If I comment out all the set_input_defaults in Area 1 of the code and keep only set_val in Area 2, nothing changes respect to point (2)
So I have understood that the value of “tcc_per_kW” must be initialized even if the variable is connected to the output of another subsystem, but set_input_defaults and/or set_val do not find “tcc_per_kW”.
What am I missing and/or mistaking?
Thank you for your time and attention