Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register

Modelica is unable to sort equation

Modelica is unable to sort equation

When there is for and if-else in else part of if-else statement equations are not sorted. Please see the "main" in attached model. Why is this happening? Is there any alternative algorithm also if I want to do same thing in equation section. Is that possible?

Thanks.



Code:


package post
  connector conn
    Real P;
  end conn;

  model stage
    conn out annotation(
      Placement(visible = true, transformation(origin = {96, -4}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {96, -4}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
    Real P;
   
    equation
    out.P = P;
  end stage;

  model main
  //last for loop is responsible for problem
    stage Stage[noOfStages];// instantiation of stages
    Boolean boolOut[noOfStages](each start = true);//for selecting stage which is having output
    parameter Integer noOfStages = 3, noOfOut = 1, outStages[noOfOut] = {2}"output stage numbers";
    conn Out[noOfOut]"output connector";//only comes in model if there are outputs since its index can be changed
   
    algorithm
    //for stages having output, boolOut is false
    for i in 1:noOfStages loop
      for j in 1:noOfOut loop
        if i == outStages[j] then
          boolOut[i] := false;
        end if;
      end for;
    end for;
   
    //assigning the values to all stages out
    //When I am running model without this for loop it runs fine but this for loop is making some problem
    for i in 1:noOfStages loop
      if boolOut[i] then
        Stage[i].out.P := 0;
      else
        for j in 1:noOfOut loop
          if i == outStages[j] then
            Stage[i].out.P := Out[j].P;
          end if;
        end for;
      end if;
    end for;
   
    //known output value
    Out[1].P := 20;
       
   
  end main;

post.mo

Edited by: pravin - Jul-31-17 11:09:21
Attachments:
There are 0 guests and 0 other users also viewing this topic
You are here: