- Index
- » Programming
- » Modelica Language
- » Connections between nested and top...
Connections between nested and top classes
Connections between nested and top classes
Hello,
Can anyone give an advice on connections between nested and top classes? I am a bit confused how it works. I have two models for comparison:
1. vehicle and its motor as two separate classes
2. motor as a nested class of the vehicle class
I use the standard mechanical connectors, Flange_a and Flange_b for communication between these classes.
In the first case it works perfectly fine. However, the second one, it returns either an error of structural singularity or an error of overdetermined model. I tried to encapsulate the motor class, but it did not work either.
Can anyone help me with this, please?
Here are simplified models:
1. vehicle and its motor as two separate classes
model test_model
vehicle test_vehicle;
motor test_motor;
equation
connect(test_vehicle.vehicle_connector, test_motor.motor_connector);
end test_model;
class vehicle
Real velocity,displacement (start=0);
parameter Real mass = 170;
Flange_a vehicle_connector;
equation
velocity = der(displacement);
mass*der(velocity) = -vehicle_connector.f; // vehicle is powered by a motor
vehicle_connector.s = displacement;
end vehicle;
class motor
Real speed;
Flange_b motor_connector;
equation
speed = der (motor_connector.s);
motor_connector.f = 100+0.2*speed;
end motor;
connector Flange_a
Real s;
flow Real f;
end Flange_a;
connector Flange_b
Real s;
flow Real f;
end Flange_b;
2. motor as a nested class of the vehicle class
class vehicle
Real velocity,displacement (start=0);
parameter Real mass = 170;
Flange_a vehicle_connector;
motor testmotor;
equation
connect(vehicle_connector, testmotor.motor_connector);
velocity = der(displacement);
mass*der(velocity) = -vehicle_connector.f; // vehicle is powered by a motor
vehicle_connector.s = displacement;
end vehicle;
class motor
Real speed;
Flange_b motor_connector;
equation
speed = der (motor_connector.s);
motor_connector.f = 100+0.2*speed;
end motor;
connector Flange_a
Real s;
flow Real f;
end Flange_a;
connector Flange_b
Real s;
flow Real f;
end Flange_b;
Any advice is highly appreciated.
Many thanks,
Ivan
PS: My system: WinXP Pro, OpenModelica 1.5 RC2
Re: Connections between nested and top classes
You could probably use inner/outer, see Modelica Specification for more information.
Make vehicle_connector an inner in the vehicle class and outer in the motor class, and connect it to the motor in the motor class.
Cheers,
Adrian Pop/
- adrpo
- 885 Posts
- Index
- » Programming
- » Modelica Language
- » Connections between nested and top...