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

Problem with array definition

Problem with array definition

Hi there,

i'm just new in programming with Modelica or better if i say i use SimulationX with the Modelica-part. After a few weeks i'm now at a point i can't get on, so i hope you'll help me current/smile
Here is my problem:

I want to connect some parts dynamically. So the user can handle, how much HeatedPipes (a part of the standard library) he want to connect in a row. I define it like
->HeatedPipe[n] , where n is the number of parts.
In addition i'd like to assign some parameters, which should be valid for all lonely parts. For example i add a temperature temp.
-> HeatedPipe[n](T0=temp)
That's the point where the problem is. The failure is that my programm thinks T0 is a n-vector whereat temp is a scalar.

So, i don't know how to handle this. May one of you give me a good hint?

Thank you!

Re: Problem with array definition

Use each to set each parameter in an array of components. Use for-equations to connect multiple components.

Code:


class A
  connector C
    parameter Real x;
    Real o;
  end C;
  parameter Integer n = 25;
  C cs[n](each x = 1.5);
equation
  cs[1].o = 1;
  for i in 1:n-1 loop
    connect(cs[i],cs[i+1]);
  end for;
end A;

Re: Problem with array definition

Thank you very much. I implemented it like you show and this works fine!

Now i got another problem: The compiler deletes some of my equations because he thinks they aren't valid. But if i connect the parts in a row by hand, everything works well. current/sad How can i trace back where this failure occurs?

Re: Problem with array definition

That I cannot help with since I do not use SimulationX. Maybe someone else knows it though...

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