Marwan Abugabbara
Marwan Abugabbara

Reputation: 21

Variables interdependency terminates Dymola simulation and produces nonlinear system of equations

I’m developing a model to describe the behavior of a two-pipe network. The network is connected to a tank where heat is injected or extracted from the system depending on external mass flow rates. The mass flow rates for both heating and cooling are arbitrarily assumed to vary over time. The initial value of PipeTemp is associated with the parameter StartTemp. However, at different time points PipeTemp is computed from a max function.

The problem is that because the variable PipeTemp depends on other time varying variables that are computed using the value of PipeTemp, Dymola terminates the simulation and produces the following error: Failed to solve nonlinear system using Newton solver.

This simple model can be easily simulated in Excel because it’s capable of handling interdependency between cell variables. What could be the workaround for this model in Dymola in order to avoid the nonlinear system of equations?

model FullyMixedTemperature

  parameter Real StartTemp = 20;      //Assumed mixed temperature in the pipes
  parameter Real dTpipe = 10;        //Temperature difference between the two pipes
  parameter Real TankVol = 150;      //Total volume
  Real DecreasingTemp;               //Mixed temperature in the pipe due to additional cooling mass flow rate
  Real IncreasingTemp;               //Mixed temperature in the pipe due to additional heating mass flow rate
  Real PipeTemp(start=StartTemp);    //Mixed temperature in the pipe
  Real CoolFlowRate;                 //Additional cooling flow rate from external sources
  Real HeatFlowRate;                 //Additional heating flow rate from external sources

equation 

  CoolFlowRate=0.5*time;
  HeatFlowRate=2*time;
  PipeTemp = max(DecreasingTemp, IncreasingTemp);
  DecreasingTemp= PipeTemp-(dTpipe*CoolFlowRate/TankVol);
  IncreasingTemp= PipeTemp+(dTpipe*HeatFlowRate/TankVol);

end FullyMixedTemperature;

Upvotes: 1

Views: 74

Answers (1)

Hans Olsson
Hans Olsson

Reputation: 12527

The model as written doesn't make sense.

Since dTPipe, HeatFlowRate, CoolFlowRate and TankVol are all non-negative IncreasingTemp is greater than DecreasingTemp, and thus the equation collapses to:

PipeTemp=PipeTemp+dTPipe*HeatFlowRate/TankVol;

and you cannot compute PipeTemp from that.

The closest variant would be that in each sampling point we compute a new PipeTemp, and that would be:

model FullyMixedTemperature

  parameter Real StartTemp = 20;      //Assumed mixed temperature in the pipes
  parameter Real dTpipe = 10;        //Temperature difference between the two pipes
  parameter Real TankVol = 150;      //Total volume
  Real DecreasingTemp;               //Mixed temperature in the pipe due to additional cooling mass flow rate
  Real IncreasingTemp;               //Mixed temperature in the pipe due to additional heating mass flow rate
  Real PipeTemp(start=StartTemp);    //Mixed temperature in the pipe
  Real CoolFlowRate;                 //Additional cooling flow rate from external sources
  Real HeatFlowRate;                 //Additional heating flow rate from external sources

equation 

  CoolFlowRate=0.5*time;
  HeatFlowRate=2*time;
  when sample(1,1) then
    PipeTemp = max(pre(DecreasingTemp), pre(IncreasingTemp));
  end when;
  DecreasingTemp= PipeTemp-(dTpipe*CoolFlowRate/TankVol);
  IncreasingTemp= PipeTemp+(dTpipe*HeatFlowRate/TankVol);

end FullyMixedTemperature;

But to me it seems more likely you want a differential equation where both flows contribute:

model FullyMixedTemperature

  parameter Real StartTemp = 20;      //Assumed mixed temperature in the pipes
  parameter Real dTpipe = 10;        //Temperature difference between the two pipes
  parameter Real TankVol = 150;      //Total volume
  Real PipeTemp(start=StartTemp);    //Mixed temperature in the pipe
  Real CoolFlowRate;                 //Additional cooling flow rate from external sources
  Real HeatFlowRate;                 //Additional heating flow rate from external sources

equation 

  CoolFlowRate=0.5*time;
  HeatFlowRate=2*time;
  der(PipeTemp) =(dTpipe*HeatFlowRate/TankVol)-(dTpipe*CoolFlowRate/TankVol);

end FullyMixedTemperature;

Upvotes: 4

Related Questions