- Index
- » Users
- » jcm
- » Profile
Posts
Posts
Hey,
I try to assign values to an array in a connector. What happens is, that the simulation fails without a compiler error message.
If I change the equation section to an algorithm section (with the necessary syntax changes) I suddenly have too many equations (42 eqs for 22 vars).
Code:
class Test
iElement ie;
Module m;
equation
connect(m.oe, ie);
end Test;
class Module
oElement oe;
Integer pos(start=1);
equation
when sample(0,1) then
for i in 1:10 loop
if i==pos then
oe.r[i]=2.2;
oe.int[i]=3;
else
oe.r[i]=pre(oe.r[i]);
oe.int[i]=pre(oe.int[i]);
end if;
end for;
pos=pre(pos)+1;
end when;
end Module;
connector oElement
output Real r[10];
output Integer int[10];
end oElement;
connector iElement
input Real r[10];
input Integer int[10];
end iElement;
Can anyone give any hints as to how to solve the issue? Thanks in advance!
jcm
Actually I just found out, that in OMNotebook the fact that having an unequal number of flow and non-flow variables inside a connector leads to an error, whereas in OMEdit this only gives a warning, but compilation works otherwise. I'll use this for now.
Hey,
I installed version 1.8.1 and now the script runs correctly. Thank you for your help!
However, since I upgraded from a really old version it seems, I now have some problems in other parts of my model. This concerns Connectors: I am using them to transmit signals between classes, but since in 1.8.1 I am forced to have equal number of flow and non-flow variables in connectors I used the input/output variation. My quastion is now how to assign or change the value of such a variable?
Code:
connector Port_in
input Boolean Signal (start=false);
end Port_in;
and this line
Code:
instanceOfPort_in.Signal := true;
gives me the following error message:
Error: Trying to assign to input component.
Thanks again, jcm
Hey,
if I run your OMNotebook file I get the same error as with my code when running the second "simulate()". The exact message is:
Code:
messages = "Simulation execution failed for model: Test
Error, input data file does not match model.
nx in initfile: 1 from model code :1
ny in initfile: 0 from model code :0
np in initfile: 0 from model code :0
npint in initfile: 0 from model code: 0
nyint in initfile: 0 from model code: 0
npbool in initfile: 0 from model code: 0
nybool in initfile: 0 from model code: 0
npstr in initfile: 0 from model code: 0
nystr in initfile: 2 from model code: 3
",
I have OMNotebook version 3.0 with OMC 1.7.0 running under Windows XP.
I tried the same thing with an integer instead of String and then there is no error, so maybe this has something to do with it.
Thanks for your help!
Hey everyone,
I found some weird behavior when looking for a bug in my code. I managed to break it down to this. If you have any idea where this comes from or why modelica behaves this way, please let me know.
I am using OMNotebook to simulate the "Test" class by calling
Code:
simulate(Test)
So the following Model can be simulated without a problem:
Code:
class Pool
AClass ac;
end Pool;
class AClass
BClass bc;
end AClass;
class BClass
String description;
end BClass;
class Test
AClass aclass;
BClass b1(description="skdjfhg");
Pool pool;
equation
pool.ac = aclass;
aclass.bc = b1;
end Test;
whereas the next one gives an error about the number of input variables between the model and init file ("Error, input data file does not match model"). Notice that the only difference is the order between the two lines in the equation section:
Code:
class Test
AClass aclass;
BClass b1(description="skdjfhg");
Pool pool;
equation
aclass.bc = b1;
pool.ac = aclass;
end Test;
Thanks for your ideas. For now i will simply use the first way, but I found it interesting that this happens, while in the Modelica specifications it is clearly written that the order of equations does not matter.
Hello everyone,
I have a problem with a simulation of a computer. The idea is to model the software and the processor as classes. The software can issue a command that switches off the processor. Since the software needs the processor "on" to run, it thereby kills itself. All this is based on state machines of the processor and the software. Both can be in one of the three modes "first", "on" or "off". The communication between the two classes is done via connectors that only transport a boolean signal (on/off).
When executing this in DRModelica I get a windows acces violation error which is due to the fact that at the moment of the switch-off of the processor, the software's port pc_state changes value and hence the if-condition inside the
Code:
when sample() then
clause changes as well.
I already tried several things to circumvent the issue, like delaying the processor switch off after the reception of the command. Or using
Code:
pre(pc_state.Signal)
, none of which seem to work.
Here are the three classes (SW, processor and a simple connector) plus a test class that is used to send the commands in the first place. Btw. please don't get distracted by the rather complicated state machine implementation.
Code:
connector Port
Boolean Signal;
end Port;
class SW
Port out_switchoff(Signal.start=false),out_switchon(Signal.start=false);
Port in_Proc_Off, in_Proc_On;
Port pc_state;
Boolean state_ON(start=true), state_OFF(start=false),init, first;
algorithm
//State machine initialisation
init:=true;
when {init} then
first:=true;
end when;
if first then
state_ON:=true;
first:=false;
state_OFF:=false;
end if;
//SW function
when sample(0.2,1) then
if pc_state.Signal then
out_switchoff.Signal := in_Proc_Off.Signal;
out_switchon.Signal := in_Proc_On.Signal;
end if;
end when;
end SW;
class Processor
Port in_switchoff , in_switchon;
Port pc_state;
Boolean state_ON(start=true), state_OFF(start=false),init, first;
algorithm
//State machine initialisation
init:=true;
when {init} then
first:=true;
end when;
if first then
state_ON:=true;
state_OFF:=false;
first:=false;
end if;
//reaction to switching signals
when in_switchoff.Signal then
state_OFF:=true;
state_ON:=false;
end when;
when in_switchon.Signal then
state_OFF:=false;
state_ON:=true;
end when;
//send info to SW
if state_ON then
pc_state.Signal:=true;
else
pc_state.Signal:=false;
end if;
end Processor;
class Test
Port out_Proc_Off,out_Proc_On;
SW sw;
Processor pc;
equation
connect(out_Proc_Off, sw.in_Proc_Off);
connect(sw.out_switchoff, pc.in_switchoff);
connect(sw.pc_state, pc.pc_state);
connect(sw.out_switchon, pc.in_switchon);
connect(out_Proc_On, sw.in_Proc_On);
when time>=4 then
out_Proc_Off.Signal=true;
out_Proc_On.Signal=false;
elsewhen time>=1 then
out_Proc_Off.Signal=false;
out_Proc_On.Signal=true; //both SW and PC are already ON, just to be sure
end when;
end Test;
Thank you already for your help. I hope we can work this out!
- Index
- » Users
- » jcm
- » Profile