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
  • Index
  • » Users
  • » Leonard
  • » Profile

Posts

Posts

Nov-16-17 15:29:35
Time variable in algorithm section loses its value between cycles
Category: Programming

Thank you!

I was looking for the chapter in which the variable initialization description is written, but i couldn't really find it.
In the actual Modelica Specification (3.4), I can read the following.

Chapter 8.4. point 1: "All variables keep their actual values until these values are explicitly changed. Variable values can be
accessed at any time instant during continuous integration and at event instants."

and

Chapter 8.6. point 2: "For all non-discrete (that is continuous-time) Real variables vc, the equation pre(vc) = vc is added to the
initialization equations."

Which tells me the opposite of the expected behavior.

I really have got my problems with Modelica and I think that I maybe didn't understand some fundamental aspects of the language. But those descriptions make it hard to understand how the language works, because they can be understood as a contradiction to actual behavior.

I've got a question to the quotes i listed. Are those quotes referring to the problem I had the with initialization of discrete and continous variables or do they describe something else?


Best regards,

Leonard

Hi!

your Connector in the tank model is missing an annotation. If you drag the connector Connecter from the library into the tank model then you can use it as desired.
You can add the input from the connector to a variable like this:

Code:


  EasyHydraulics.Setup.Connecter C
  Modelica.SIunits.Pressure P;
equation
  P = C.P;

Nov-15-17 14:02:57
Time variable in algorithm section loses its value between cycles
Category: Programming

Hello,

i've got a problem with variables in an algorithm section that are depending on the simulation time. At an event I want to set the current simulation time to a variable, which I want to use in the next cycles. But this variable resets to 0 at the next step. I tried to initialize the variable at the beginning of a cycle with "var := pre(var)", which led to errors during compilation.
The following code section contains a minimal example of the problem. If you compare the variables "state" and "timeVar" you can see that "state" changes its value and holds it between cycles but timeVar is always 0.

Code:


model TimeVarTest
  Modelica.SIunits.Time timeVar(start = 0);
  Modelica.SIunits.Time timeOut(start = 0);
  Modelica.Blocks.Tables.CombiTable1Ds tableVar(table = [0,0;1,0.5]);
  Integer state(start = 0);
algorithm
  if state == 0 then
    // Action
    tableVar.u := time-timeVar;
    // Transition
    if time - timeVar > 1 then
      state := 1;
      timeVar := time;
    end if;
end if;

if state == 1 then
  // Action
  tableVar.u := 1;
  // Transition
  if time - timeVar > 2 then
    state := 0;
    timeVar := time;
  end if;
end if;
equation
  timeOut = tableVar.y[1];
annotation(
    experiment(StartTime = 0, StopTime = 10, Tolerance = 1e-06, Interval = 0.1));
end TimeVarTest;

Im using windows 10 and OpenModelica v1.12.0 (64-bit).

Thank you very much for your help,

Leo

  • Index
  • » Users
  • » Leonard
  • » Profile
You are here: