0

Firstly I am a relatively new user.I am trying to correlate a physical test data with the model I built using Dymola/Modelica. In this model "variable 1" has a initial value based on which "variable 2,3 and 4" are calculated and these variables(2,3 & 4) are used to re-calculate "variable 1" and this value of "variable 1" has to be used for the next time step and subsequent recalculations has to be done.

I am not sure how to pass this "updated variable 1" as an input to the model every time step?Can someone please help me on how to approach this problem?

Thanks.

sananthk
  • 45
  • 4

1 Answers1

0

If I understood well the question you have an equation system which you want to solve de-coupled, i.e. solve one set of equations using some initial values or values of the system at previous time step, let's call this equation set A, then with its results as an input solve equation set B at the next time step and so on. Below an example of a decoupled system that is discrete, in which the decoupling is obtained with a clock period shift: enter image description here And then the same system that is solved in a coupled way, so at every time instant, all the equations are solved synchronously: enter image description here

To reply to your comment you can also implement your model into equation section inside a when statement using the pre operator that is used to refer to last value of a discrete variable during an event.

model test
  parameter Real timeStep = 0.1;
  Real T_i[4];
  Real K[4];
  Real M[4];
initial equation 
  T_i = {1,2,3,4}; //starting value of a T  
  K = T_i .* 1.1 .+ 4;
  M = K .* 1.1 .+ 4;
equation 
  when sample(timeStep,timeStep) then
      K = T_i .* 10 .+ 4;
      M = K .* 10 .+ 4;
      T_i = pre(M) + pre(K);
  end when;
end test;

I hope this helps

Marco Romanoni
  • 471
  • 2
  • 9
  • Hi Marco, Just to clarify my question, please have a look at the model code below: algorithm T_i = [some array]; //starting value of a T K = f(T_i); M = f(K); T_i+1 = f(M,T_i); //recalculating T T_i+1 = T_i; // re-initializing T_i to T_i+1 end; In this function there is a start value for “T_i”, based on this value I am calculating K and M. With these values of K and M, I am re-calculating a new value for T which is “T_i+1”. Basically I want to use this new value “T_i+1” as “T_i” for the next time step. Kindly advise on how to implement this in Modelica. Thanks. – sananthk Feb 23 '16 at 13:30