Commit ad65d4af authored by Jesse VanderWees's avatar Jesse VanderWees 🐘 Committed by Tjerk Vreeken

Don't set nan constant inputs in modelica mixin

Modelica mixin was masking missing timeseries detection by setting
timeseries full of NaN. This was causing hard-to-debug
InvalidNumberDetected solver errors.
parent b9a30ca4
......@@ -215,11 +215,19 @@ class ModelicaMixin(OptimizationProblem):
constant_input_names = {sym.name() for sym in self.__mx['constant_inputs']}
for v in self.__pymoca_model.inputs:
if v.symbol.name() in constant_input_names:
constant_inputs[v.symbol.name()] = Timeseries(
times, np.full_like(times, v.value))
if logger.getEffectiveLevel() == logging.DEBUG:
logger.debug("Read constant input {} = {} from Modelica model".format(
v.symbol.name(), v.value))
# NOTE: v.value can be a DM. Cast to float to make sure the
# isnan call succeeds.
value = float(v.value)
if not np.isnan(value):
constant_inputs[v.symbol.name()] = Timeseries(
times, np.full_like(times, value))
if logger.getEffectiveLevel() == logging.DEBUG:
logger.debug(
"Read constant input {} = {} from Modelica model".format(
v.symbol.name(), value
)
)
return constant_inputs
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment