2
votes

I have a local model, which when I check in Dymola claims to have 35 variables and 34 unknowns, while when I check exactly the same model in OMEdit it is balanced at 34/34. In determining what counts as a variable, do all inputs and outputs get included?

Below is my model:

model HeatStorage

  extends PentakomoPlant.Interfaces.StorageFluidHeat;
  parameter SI.Diameter D = 18.667 "Diameter";
  parameter SI.Height H = 20 "Height";
  parameter Boolean enable_losses = false "= true enable thermal losses with environment" 
  parameter SI.CoefficientOfHeatTransfer alpha = 1 "Constant heat transfer coefficient with the ambient"
  parameter Boolean use_L = false "= true to display level as output variable" 
  parameter Real L_start = 0 "Start value of level in %" 
  parameter SI.Temperature T_start = from_degC(300) "Start value of temperature" 
  parameter SI.Temperature T_max = from_degC(550) "Maximum tank temperature" 
  parameter SI.Temperature T_set = from_degC(300) "Tank Heater Temperature Set-Point" 
  parameter SI.Power W_max = 30e8 "Hot Tank Heater Capacity" 
  parameter SI.Efficiency e_ht = 0.99 "Tank Heater Efficiency" 
  SI.Volume V;
  SI.Mass m;
  Medium.BaseProperties medium;
  SI.Area A;
  SI.HeatFlowRate Q_losses;
  Medium.ThermodynamicState state_i = Medium.setState_pTX(medium.p, T_start);
  SI.Power W_net;
  SI.Power W_loss;
  Modelica.Blocks.Interfaces.RealOutput L if use_L "Tank level in %" 
  Modelica.Blocks.Interfaces.RealInput T_amb if enable_losses 
  Modelica.Blocks.Interfaces.RealInput Q_heater 
  SI.HeatFlowRate Q_PB "Heat Flow to PowerBlock";
  SI.HeatFlowRate Q_desal "Heat Flow to Desalination";
protected 
  parameter SI.Volume V_t = H * pi * D ^ 2 / 4;
  Modelica.Blocks.Interfaces.RealOutput L_internal;

initial equation 
  medium.h = Medium.specificEnthalpy(state_i);
  m = Medium.density(state_i) * V_t;

equation 
  if use_L then
    connect(L_internal, L);
  end if;

  if enable_losses then
    connect(T_amb_internal, T_amb);

    Q_losses = -0.939 * exp(to_degC(medium.T) * 0.005111) * 1000;//*5/7;
  else
    T_amb_internal = Medium.T_default;
    Q_losses = 0;
  end if;

  fluid_a.p = medium.p;
  fluid_b.p = medium.p;
  fluid_a.h_outflow = medium.h;
  fluid_b.h_outflow = medium.h;
  der(m) = fluid_a.m_flow + fluid_b.m_flow;
  m * der(medium.h) + der(m) * medium.h = Q_losses + Q_PB + Q_desal + W_net + fluid_a.m_flow * inStream(fluid_a.h_outflow) + fluid_b.m_flow * medium.h;
  V = m / medium.d;
  L_internal = 100 * (max(medium.T, T_set) - T_set) / (T_max - T_set);
  A = 2 * pi * (D / 2) * H;

  W_net = Q_heater;
  W_loss = W_net / e_ht;

  //PowerBlock

  heat_PB.Q_flow = Q_PB;
  heat_DS.Q_flow = Q_desal;
  heat_PB.T = medium.T;
  heat_DS.T = medium.T;

end HeatStorage;

With:

partial model StorageFluidHeat
  extends SolarTherm.Icons.StorageModel;
  Modelica.Fluid.Interfaces.FluidPort_a fluid_a(redeclare package Medium = Medium) 
  Modelica.Fluid.Interfaces.FluidPort_b fluid_b(redeclare package Medium = Medium) 


  replaceable package Medium = SolarTherm.Media.MoltenSalt.MoltenSalt_base
    constrainedby Modelica.Media.Interfaces.PartialMedium
    "Medium in the component"
  Modelica.Thermal.HeatTransfer.Interfaces.HeatPort_b heat_PB 
  Modelica.Thermal.HeatTransfer.Interfaces.HeatPort_b heat_DS 

end StorageFluidHeat;

And (for the base properties of the medium):

  redeclare model extends BaseProperties(final standardOrderComponents=true)
    "Base properties of medium"

  equation 
    d = rho_T(T);
    h = state.h;
    u = h - p/d;
    MM = 0.091438;
    R = 8.3144/MM;
    state.p = p;
    T = T_h(h);
  end BaseProperties;

I am struggling to find where the extra variable may be, or why it might be different when using Dymola/OMEdit.

I have tried following the advice from ELmqvist about balancing models, so in counting variables would I be right in assuming (For this model):

8 x Specialised class variables 3 x Inputs 2 x Output 7 x Medium Base Property Variables 2 x 5 x Fluid port Variables 2 x 2 x Heat port Variables

= 34 variables

Am I missing something?

1

1 Answers

5
votes

The model is not complete with all libraries to enable testing (assumedly there are similar issues with other media), so this will be an incomplete answer.

In addition it seems likely that some equations and variables could be removed to simplify the model.

But there are some concerns with the model:

  • T_amb_internal is unused and undeclared; that looks odd.
  • You normally need equations for two intensive properties for simple medium: e.g. p, h or p, T. Here medium.h is determined due to the differential equations, but not medium.p. (The mass also has a differential equation and can vary.)

Note that testing of a local model can be tricky - and you should preferably include it in a test-circuit as well.