I'm working on my first Pyomo DAE project to teach myself how to use it for trajectory optimization. I have generated an atmosphere lookup table with density and speed of sound as a function of altitude. Pyomo will not accept the following code for my concrete model:
# create a model object
m = ConcreteModel()
define the independent variables
m.stage = RangeSet(0,1,bounds=(0,1))
m.tau = ContinuousSet(bounds=(0,1))
m.t = Var(m.stage, m.tau)
define the dependent variables
m.px = Var(m.stage, m.tau)
m.py = Var(m.stage, m.tau)
m.v = Var(m.stage, m.tau, bounds=(vmin, None))
m.g = Var(m.stage, m.tau, bounds=(gmin, gmax))
define internal function to calculate Mach number
def _Mach(alt,v):
sos = np.interp(alt,altTab,sosTab)
return v/sos
define algebraic auxiliary variables
m.Mach = Var(m.stage, m.tau)
m.alg_Mach = Constraint(m.stage, m.tau, rule=lambda m, stage, tau:
m.Mach[stage,tau] == _Mach(m.py[stage,tau],m.v[stage,tau]) )
m.stageis a PyomoRangeSetover [0,1] to represent the two phases of my problem (boost and coast)m.tauis aContinuousSetover [0,1] which is normalized timem.pyis the altitude variablem.vis the airspeed variablealtTabandsosTabare 1Dnumpy.arrayvariables defined using a previous call topyatmos.coesa76, but they could be any arbitrarynumpy.arrays for test purposes.
The error message is:
ERROR: Rule failed when generating expression for Constraint alg_Mach with
index (0, 0): TypeError: Implicit conversion of Pyomo numeric value
(py[0,0]) to float is disabled. This error is often the result of using
Pyomo components as arguments to one of the Python built-in math module
functions when defining expressions. Avoid this error by using Pyomo-
provided math functions or explicitly resolving the numeric value using
the Pyomo value() function.
ERROR: Constructing component 'alg_Mach' from data=None failed: TypeError:
Implicit conversion of Pyomo numeric value (py[0,0]) to float is disabled.
This error is often the result of using Pyomo components as arguments to
one of the Python built-in math module functions when defining
expressions. Avoid this error by using Pyomo-provided math functions or
explicitly resolving the numeric value using the Pyomo value() function.
What's the acceptable way to perform linear interpolation on parameters of a Pyomo DAE problem?
value(m.py[stage,tau]),value(m.v[stage,tau]))it returns three errors:ERROR: evaluating object as numeric value: py[0,0] (object: <class 'pyomo.core.base.var._GeneralVarData'>) No value for uninitialized NumericValue object py[0,0]ERROR: Rule failed when generating expression for Constraint alg_Mach with index (0, 0): ValueError: No value for uninitialized NumericValue object py[0,0]ERROR: Constructing component 'alg_Mach' from data=None failed: ValueError: No value for uninitialized NumericValue object py[0,0]– machalot Oct 02 '22 at 05:42