Open dhblum opened 6 years ago
The error can be traced to the function IBPSA.Utilities.Math.Functions.BaseClasses.smoothTransition
where:
if x < 0 then
y := -y;
end if;
This function is ultimately called because IBPSA.Fluid.HeatExchangers.BaseClasses.PartialEffectiveness.prescribedHeatFlowRate = true
, and therefore IBPSA.Fluid.Interfaces.StaticTwoPortConservationEquation.use_m_flowInv = true
.
Editing to the following relieves the error:
y := if x >= 0 then a + aX*(b + aX*(c + aX*(d + aX*(e + aX*f)))) else
-(a + aX*(b + aX*(c + aX*(d + aX*(e + aX*f)))));
New error is:
RuntimeError: BUG: Unable to evaluate value of mpc_model.hex.cp1_default.
where mpc_model.hex is the instance of the heat exchanger.
The error is given if using either BuildingMpc.Media.DryAir or Buildings.Media.Air.
Editing the parameter declarations of Fluid.HeatExchangers.BaseClasses.PartialEffectiveness
to the following as well as removing the initial equation
section relieves the error:
parameter Modelica.SIunits.SpecificHeatCapacity cp1_default = Medium1.specificHeatCapacityCp(Medium1.setState_pTX(
Medium1.p_default,
Medium1.T_default,
Medium1.X_default))
"Specific heat capacity of medium 1 at default medium state";
parameter Modelica.SIunits.SpecificHeatCapacity cp2_default = Medium2.specificHeatCapacityCp(Medium2.setState_pTX(
Medium2.p_default,
Medium2.T_default,
Medium2.X_default))
"Specific heat capacity of medium 2 at default medium state";
parameter Modelica.SIunits.ThermalConductance CMin_flow_small = min(m1_flow_small*cp1_default, m2_flow_small*cp2_default)
"Small value for smoothing of minimum heat capacity flow rate";
I knew this topic would come in handy: https://github.com/Mathadon/modelica_MPC/issues/2 your first issue is caused by the fact that JModelica does not allow if\else expressions in the main body of the equations. Although, in fact, I thought that your fix would not work either..
The second problem is probably caused because the optimisation requires values that are only computed during an initial equation (e.g. at initialization). However for optimisation problems, the code is never initialised since an FMU is not even being created. Your fix therefore makes sense. However, it would be better if JModelica would simply support such constructs.
Use of IBPSA.Fluid.HeatExchangers.ConstantEffectiveness in JModelica optimization results in the following error: