Search code examples
modelica

Discrete iteration, how can I make this possible?


enter image description here

I want to decompose a part like this, into an array of x rows and y columns, and then do the operations. Mainly use the loop statement (for). Do you guys have a similar example? thank you all very much.

just be like:

equation
    for i in 1:n-1 loop
      for j in 1:m-1 loop
//equations
         T[i+1,j] = T[i,j]+something+...;
         T[i,j+1] = ...;
      end for;
  end for;

Solution

  • The best example I could find is the following: Modelica.Electrical.Analog.Basic.M_Transformer, although the loop is "only" in the initial equation section.

    What is more common, is to use loops in connect statements, like in Modelica.Electrical.Batteries.BaseClasses.BaseStackWithSensors. But that will likely not be a good fit for your task.

    Some general advise:

    • A good read to start with the topic is: https://mbe.modelica.university/behavior/arrays/looping/
    • For complex for/if-statements it is often simpler to formulate them in an algorithm section. Those can be placed in a function and "ease" some of the pretty strict requirements of the equation section, like allowing a multiple assignments for a single variable. It will be more like a coding in a procedural programming language.
    • If you prefer to write the statements in the equation section (which can make sense performance-wise) you need to make sure, that every unknown needs exactly one equation to compute it.