Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _setup_design_parameters(self):
"""
Adds an IndepVarComp if necessary and issues appropriate connections based
on transcription.
"""
if self.design_parameter_options:
indep = self.add_subsystem('design_params', subsys=om.IndepVarComp(),
promotes_outputs=['*'])
for name, options in self.design_parameter_options.items():
if options['opt']:
lb = -INF_BOUND if options['lower'] is None else options['lower']
ub = INF_BOUND if options['upper'] is None else options['upper']
self.add_design_var(name='design_parameters:{0}'.format(name),
lower=lb,
upper=ub,
scaler=options['scaler'],
adder=options['adder'],
ref0=options['ref0'],
ref=options['ref'])
indep.add_output(name='design_parameters:{0}'.format(name),
val=options['val'],
shape=(1, np.prod(options['shape'])),
units=options['units'])
tgts = options['targets']
for name, options in self.options['polynomial_control_options'].items():
num_input_nodes = options['order'] + 1
shape = options['shape']
if options['opt']:
ivc.add_output('polynomial_controls:{0}'.format(name),
val=np.ones((num_input_nodes,) + shape),
units=options['units'])
desvar_indices = list(range(num_input_nodes))
if options['fix_initial']:
desvar_indices.pop(0)
if options['fix_final']:
desvar_indices.pop()
lb = -INF_BOUND if options['lower'] is None else options['lower']
ub = INF_BOUND if options['upper'] is None else options['upper']
self.add_design_var('polynomial_controls:{0}'.format(name),
lower=lb,
upper=ub,
ref=options['ref'],
ref0=options['ref0'],
adder=options['adder'],
scaler=options['scaler'],
indices=desvar_indices)
linear : bool
True if the *total* derivative of the constrained variable is linear, otherwise False.
res_ref : float
Scaling parameter. The value in the user-defined res_units of this output's residual
when the scaled value is 1. Default is 1.
type_ : str
The kind of variable be constrained, as returned by classify_var.
distributed : bool
If True, this variable is distributed across multiple processes.
"""
src_all = var_class in ['time', 'time_phase', 'indep_control', 'input_control',
'control_rate', 'control_rate2', 'indep_polynomial_control',
'input_polynomial_control', 'polynomial_control_rate',
'polynomial_control_rate2', 'design_parameter', 'input_parameter']
lower = -INF_BOUND if upper is not None and lower is None else lower
upper = INF_BOUND if lower is not None and upper is None else upper
kwargs = {'shape': shape, 'units': units, 'res_units': res_units, 'desc': desc,
'indices': indices, 'lower': lower, 'upper': upper, 'equals': equals,
'scaler': scaler, 'adder': adder, 'ref': ref, 'ref0': ref0, 'linear': linear,
'src_all': src_all, 'res_ref': res_ref, 'distributed': distributed,
'type_': type_}
self._path_constraints.append((name, kwargs))
idxs_to_fix = np.where(np.asarray(options['fix_initial']))[0]
for idx_to_fix in reversed(sorted(idxs_to_fix)):
del desvar_indices[idx_to_fix]
else:
del desvar_indices[:size]
if len(desvar_indices) > 0:
coerce_desvar_option = CoerceDesvar(num_state_input_nodes, desvar_indices,
options)
lb = np.zeros_like(desvar_indices, dtype=float)
lb[:] = -INF_BOUND if coerce_desvar_option('lower') is None else \
coerce_desvar_option('lower')
ub = np.zeros_like(desvar_indices, dtype=float)
ub[:] = INF_BOUND if coerce_desvar_option('upper') is None else \
coerce_desvar_option('upper')
if options['initial_bounds'] is not None:
lb[0] = options['initial_bounds'][0]
ub[0] = options['initial_bounds'][-1]
self.add_design_var(name='states:{0}'.format(state_name),
lower=lb,
upper=ub,
scaler=coerce_desvar_option('scaler'),
adder=coerce_desvar_option('adder'),
ref0=coerce_desvar_option('ref0'),
ref=coerce_desvar_option('ref'),
indices=desvar_indices)
def _setup_design_parameters(self):
"""
Adds an IndepVarComp if necessary and issues appropriate connections based
on transcription.
"""
if self.design_parameter_options:
indep = self.add_subsystem('design_params', subsys=om.IndepVarComp(),
promotes_outputs=['*'])
for name, options in self.design_parameter_options.items():
if options['opt']:
lb = -INF_BOUND if options['lower'] is None else options['lower']
ub = INF_BOUND if options['upper'] is None else options['upper']
self.add_design_var(name='design_parameters:{0}'.format(name),
lower=lb,
upper=ub,
scaler=options['scaler'],
adder=options['adder'],
ref0=options['ref0'],
ref=options['ref'])
indep.add_output(name='design_parameters:{0}'.format(name),
val=options['val'],
shape=(1, np.prod(options['shape'])),
units=options['units'])
tgts = options['targets']
# setup the design variable for optimization.
for name, options in self.options['polynomial_control_options'].items():
num_input_nodes = options['order'] + 1
shape = options['shape']
if options['opt']:
ivc.add_output('polynomial_controls:{0}'.format(name),
val=np.ones((num_input_nodes,) + shape),
units=options['units'])
desvar_indices = list(range(num_input_nodes))
if options['fix_initial']:
desvar_indices.pop(0)
if options['fix_final']:
desvar_indices.pop()
lb = -INF_BOUND if options['lower'] is None else options['lower']
ub = INF_BOUND if options['upper'] is None else options['upper']
self.add_design_var('polynomial_controls:{0}'.format(name),
lower=lb,
upper=ub,
ref=options['ref'],
ref0=options['ref0'],
adder=options['adder'],
scaler=options['scaler'],
indices=desvar_indices)
if not (time_options['input_initial'] or time_options['fix_initial']):
lb, ub = time_options['initial_bounds']
lb = -INF_BOUND if lb is None else lb
ub = INF_BOUND if ub is None else ub
phase.add_design_var('t_initial',
lower=lb,
upper=ub,
scaler=time_options['initial_scaler'],
adder=time_options['initial_adder'],
ref0=time_options['initial_ref0'],
ref=time_options['initial_ref'])
if not (time_options['input_duration'] or time_options['fix_duration']):
lb, ub = time_options['duration_bounds']
lb = -INF_BOUND if lb is None else lb
ub = INF_BOUND if ub is None else ub
phase.add_design_var('t_duration',
lower=lb,
upper=ub,
scaler=time_options['duration_scaler'],
adder=time_options['duration_adder'],
ref0=time_options['duration_ref0'],
ref=time_options['duration_ref'])
del desvar_indices[:size]
if options['fix_final']:
raise ValueError('Cannot specify \'fix_final=True\' in '
'RungeKuttaPhase'.format(state_name))
if options['final_bounds'] is not None:
raise ValueError('Cannot specify \'final_bounds\' in RungeKuttaPhase '
'(state {0})'.format(state_name))
if len(desvar_indices) > 0:
coerce_desvar_option = CoerceDesvar(num_state_input_nodes, desvar_indices,
options)
lb = np.zeros_like(desvar_indices, dtype=float)
lb[:] = -INF_BOUND if coerce_desvar_option('lower') is None else \
coerce_desvar_option('lower')
ub = np.zeros_like(desvar_indices, dtype=float)
ub[:] = INF_BOUND if coerce_desvar_option('upper') is None else \
coerce_desvar_option('upper')
if options['initial_bounds'] is not None:
lb[0] = options['initial_bounds'][0]
ub[0] = options['initial_bounds'][-1]
phase.add_design_var(name='states:{0}'.format(state_name),
lower=lb,
upper=ub,
scaler=coerce_desvar_option('scaler'),
adder=coerce_desvar_option('adder'),
ref0=coerce_desvar_option('ref0'),
externals.append('t_duration')
else:
indeps.append('t_duration')
if indeps:
indep = om.IndepVarComp()
for var in indeps:
indep.add_output(var, val=default_vals[var], units=time_units)
phase.add_subsystem('time_extents', indep, promotes_outputs=['*'])
comps += ['time_extents']
if not (time_options['input_initial'] or time_options['fix_initial']):
lb, ub = time_options['initial_bounds']
lb = -INF_BOUND if lb is None else lb
ub = INF_BOUND if ub is None else ub
phase.add_design_var('t_initial',
lower=lb,
upper=ub,
scaler=time_options['initial_scaler'],
adder=time_options['initial_adder'],
ref0=time_options['initial_ref0'],
ref=time_options['initial_ref'])
if not (time_options['input_duration'] or time_options['fix_duration']):
lb, ub = time_options['duration_bounds']
lb = -INF_BOUND if lb is None else lb
ub = INF_BOUND if ub is None else ub
phase.add_design_var('t_duration',
A multiplicative scaler on the constraint value for the optimizer.
adder : float or None
A parameter which is added to the value before scaler is applied to produce
the value seen by the optimizer.
ref : float or None
Scaling parameter. The value in the user-defined units of this output variable when
the scaled value is 1. Default is 1.
ref0 : float or None
Scaling parameter. The value in the user-defined units of this output variable when
the scaled value is 0. Default is 0.
linear : bool
True if the *total* derivative of the constrained variable is linear, otherwise False.
distributed : bool
If True, this variable is distributed across multiple processes.
"""
lower = -INF_BOUND if upper is not None and lower is None else lower
upper = INF_BOUND if lower is not None and upper is None else upper
kwargs = {'units': units, 'res_units': res_units, 'desc': desc,
'shape': shape, 'indices': indices, 'flat_indices': flat_indices,
'lower': lower, 'upper': upper, 'equals': equals,
'scaler': scaler, 'adder': adder, 'ref': ref, 'ref0': ref0, 'linear': linear,
'res_ref': res_ref, 'distributed': distributed}
self._constraints.append((name, kwargs))