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

Access initial variables of subclass

Access initial variables of subclass

Hello,
I am trying to access the initial condition of the variable in a sub class. The code is as given below.

Code:

class MainClass001

  class SubClass001
    Modelica.Blocks.Interfaces.RealInput u annotation(
      Placement(visible = true, transformation(origin = {-106, 0}, extent = {{-20, -20}, {20, 20}}, rotation = 0), iconTransformation(origin = {-106, 0}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
    Modelica.Blocks.Interfaces.RealOutput y annotation(
      Placement(visible = true, transformation(origin = {106, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {106, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); 
    Modelica.SIunits.Angle phi(start=0) "phi";   
  equation
    der(phi) = u;
    y = phi; 
  end SubClass001;
  class SubClass002
    Modelica.Blocks.Interfaces.RealInput u annotation(
      Placement(visible = true, transformation(origin = {-108, 0}, extent = {{-20, -20}, {20, 20}}, rotation = 0), iconTransformation(origin = {-108, 0}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
    Modelica.Blocks.Interfaces.RealOutput y annotation(
      Placement(visible = true, transformation(origin = {100, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {100, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
  MainClass001.SubClass001 subClass0011 annotation(
      Placement(visible = true, transformation(origin = {0, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
    parameter Real initial_condition "Initial condition for phi";   
    equation
    subClass0011.phi.start = initial_condition;
    connect(subClass0011.u,u);
    connect(subClass0011.y,y); 
  end SubClass002;
  annotation(
    uses(Modelica(version = "3.2.2")));
end MainClass001;

I am getting the following error.

Code:

[1] 19:07:32 Translation Error

[MainClass001: 26:5-26:47]: Variable subClass0011.phi.start not found in scope MainClass001.SubClass002.

[2] 19:07:32 Translation Error
Error occurred while flattening model MainClass001.SubClass002

Please let me know how to resolve this issue. It would be a great help if I could get through this.
Thanks in advance!!

Re: Access initial variables of subclass

You cannot access variable attributes by dot-notation

Re: Access initial variables of subclass

Thanks for the prompt reply.
Is there any other way, that I can assign values to the variable attributes?

Re: Access initial variables of subclass

Only via modification on variable declaration:

Code:


MainClass001.SubClass001 subClass0011(phi(start = initial_condition));

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