Search code examples
modelicadymola

How to find the variables selected by the tearing algorithm in Dymola


I'd like to find the set of variables selected by the tearing algorithm in Dymola. so that I could know which variables link different parts of the system together. But I am not sure how to show these variables in Dymola. I checked the help document of Dymola but didn't find anything related to how to show these variables. enter image description here


Solution

  • You should be able to see it in dsmodel.mof, which is created after setting Advanced.OutputModelicaCode = true; or activating it in the UI using "Simulation Setup -> Translation -> Generate listing of translated Modelica code in dsmodel.mof".

    Dymola will generate the relevant code in the // Torn part. Searching for this in dsmodel.mof is a good option as the file can get pretty big.

    The exact code will depend on the type of problem. Two examples:

    (1) A rather simple electrical like this RLC-circuit with algebraic loop will be solved symbolically, with the resulting code:

    ...
    // Linear system of equations
    // Tag: simulation.linear[1]
      // Symbolic solution
        /*  Original equation
        resistor1.v = constantVoltage.V-resistor.v-capacitor.v;
        */
        resistor1.p.i :=  -(capacitor.v-constantVoltage.V+resistor.R_actual*
          inductor.i)/(resistor.R_actual+resistor1.R_actual);
      // Torn part
        resistor.p.i := inductor.i+resistor1.p.i;
        resistor.v := resistor.R_actual*resistor.p.i;
        resistor1.v := resistor1.R_actual*resistor1.p.i;
    // End of linear system of equations
    ...
    

    In this case the tearing variable is resistor1.p.i, with the equation to compute it stated directly there.

    (2) Translating Modelica.Thermal.FluidHeatFlow.Examples.TwoMass will give you a non-nonlinear case, i.e. when an iteration is needed to solve the system of equations. You should find something like:

    ...
      // Start values for iteration variables of non-linear system of 1 equations: 
      //   pipe2.V_flow(start = 0)
    algorithm // Torn part
      pipe2.flowPort_a.m_flow := pipe2.V_flow*pipe2.medium.rho;
      pipe1.flowPort_a.m_flow :=  -(pipe2.flowPort_a.m_flow+ambient1.flowPort.m_flow);
    ...
    

    The tearing variable is pipe2.V_flow in this case, with the start value for the iteration.