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

String variables, connectors and when equation

String variables, connectors and when equation

Hi,

maybe someone can help me with a little Problem. When i'm trying to simulate this code i'm always getting the messages = "Simulation execution failed for model: Simulator
Error, input data file does not match model.

Code:


class Simulator
  A a;
  B b;

  equation
  connect(a.outPort,b.inPort);
end Simulator;

connector Port
  String Name;
end Port;

class A
  Port outPort;
 
  equation
when time >= 2 then
    outPort.Name="Peter";
end when; 
end A;

class B
  Port inPort;
end B;

It works if i leave the when condition aside. The original Code also works, if i use another variable type like boolean or integer. If i simulate a class like Test the when equation works with the String variables. It would be really nice, if someone could tell me the reason why the execution for the simulation of the code above fails.

Code:


class Test
  String name="Peter";
  String newname;
 
  equation
  when time >=2 then
    newname=name;
    end when;
  end Test;

Re: String variables, connectors and when equation

First of all the code is not valid Modelica:

Code:

[a.mo:9:1-11:9:writable] Error: Connector Port is not balanced: The number of potential variables (1) is not equal to the number of flow variables (0).

In newer OpenModelica, you need to fix your model (by using causal connectors) or use +std=2.x to ignore this error. The model succeeds to simulate for me, which suggests you simply need to update OpenModelica to the latest version.

There are 0 guests and 0 other users also viewing this topic
You are here: