Классы в Modelica

#modelica

#modelica

Вопрос:

У меня сложная модель в Modelica. Поскольку в моей модели много компонентов, я хочу определить классы и включить некоторые компоненты внутри классов, чтобы уменьшить сложность модели. Поскольку я не смог найти в Интернете пример использования классов, которые используются в Modelica, не могли бы вы дать представление о том, как определять классы в Modelica?

Код выглядит следующим образом;

 
model HD_3Kolben_bsp
    //Declaration(s)
    Real V_max = 0.000003;
    Real V_tod = 0.000002;
    Real N = 2800;
    replaceable package medium = Modelica.Media.Water.StandardWater( );
    Real opening_HP;
    Real opening_LP;
    constant Modelica.SIunits.AbsolutePressure patm = 1e5;
    Real opening_HP_2;
    Real opening_LP_2;
    Real opening_HP_3;
    Real opening_LP_3;
    constant Modelica.SIunits.Frequency freq = 46;
    //Component(s)
    Modelica.Fluid.Machines.SweptVolume Kolben1 (
        pistonCrossArea = 0.0001131,
        clearance = 0.00000250621,
        redeclare package Medium = Modelica.Media.Water.StandardWater,
        nPorts = 1,
        use_portsData = false,
        use_T_start = true,
        T_start = 293.15,
        V(start = 0.005),
        m(start = 0.005));
    inner Modelica.Fluid.System system (p_ambient = 101325);
    Modelica.Mechanics.Translational.Sources.Position Posit1 (exact = true, useSupport = false);
    Modelica.Blocks.Sources.Sine Sine1 (
        amplitude = 0.005567,
        freqHz = freq,
        offset = 0.005567,
        phase =  Modelica.Constants.pi/2.01,
        startTime = 0);
    Modelica.Fluid.Vessels.ClosedVolume ClosedVolume1 (
        V = 0.000005/2,
        nPorts = 3,
        redeclare package Medium = medium,
        use_portsData = false);
    Modelica.Fluid.Pipes.DynamicPipe pipe_Swept_CV_1 (
        length = 0.005,
        diameter = 0.002,
        redeclare package Medium = medium,
        roughness = 2.5E-5);
    Modelica.Fluid.Pipes.DynamicPipe pipe_CV_HD_1 (
        length = 0.005,
        diameter = 0.002,
        redeclare package Medium = medium,
        roughness = 2.5E-5);
    Modelica.Fluid.Sources.FixedBoundary Auslass (p = patm, redeclare package Medium = medium, nPorts = 1);
    Modelica.Fluid.Valves.ValveLinear HDVentile1 (
        dp_nominal = 95,
        m_flow_nominal = 0.05867441,
        redeclare package Medium = medium,
        opening = opening_HP);
    Modelica.Fluid.Pipes.DynamicPipe pipe_ND_CV_1 (
        length = 0.005,
        diameter = 0.002,
        redeclare package Medium = medium,
        roughness = 2.5E-5);
    Modelica.Fluid.Valves.ValveLinear NDVentile1 (
        dp_nominal = 94.35,
        m_flow_nominal = 0.05867441,
        redeclare package Medium = medium,
        opening = opening_LP);
    Modelica.Fluid.Pipes.DynamicPipe pipe_Ein_ND (
        length = 0.005,
        diameter = 0.002,
        redeclare package Medium = medium,
        roughness = 2.5E-5);
    Modelica.Fluid.Sources.FixedBoundary Einlass (p = 4e5, redeclare package Medium = Modelica.Media.Water.StandardWater, nPorts = 1);
    Modelica.Mechanics.Translational.Sensors.PositionSensor Position;
    Modelica.Mechanics.Translational.Sensors.PositionSensor Position2;
    Modelica.Fluid.Valves.ValveLinear NDVentile2 (
        dp_nominal = 94.35,
        m_flow_nominal = 0.05867441,
        redeclare package Medium = medium,
        opening = opening_LP_2);
    Modelica.Fluid.Pipes.DynamicPipe pipe_ND_CV_2 (
        length = 0.005,
        diameter = 0.002,
        redeclare package Medium = medium,
        roughness = 2.5E-5);
    Modelica.Fluid.Valves.ValveLinear HDVentile2 (
        dp_nominal = 95,
        m_flow_nominal = 0.05867441,
        redeclare package Medium = medium,
        opening = opening_HP_2);
    Modelica.Fluid.Pipes.DynamicPipe pipe_CV_HD_2 (
        length = 0.005,
        diameter = 0.002,
        redeclare package Medium = medium,
        roughness = 2.5E-5);
    Modelica.Fluid.Pipes.DynamicPipe pipe_Swept_CV_2 (
        length = 0.005,
        diameter = 0.002,
        redeclare package Medium = medium,
        roughness = 2.5E-5);
    Modelica.Fluid.Vessels.ClosedVolume ClosedVolume2 (
        V = 0.000005/2,
        nPorts = 3,
        redeclare package Medium = medium,
        use_portsData = false);
    Modelica.Blocks.Sources.Sine Sine2 (
        amplitude = 0.005567,
        freqHz = freq,
        offset = 0.005567,
        phase =  Modelica.Constants.pi/2.01,
        startTime = 7/(3*freq));
    Modelica.Mechanics.Translational.Sources.Position Posit2 (exact = true, useSupport = false);
    Modelica.Fluid.Machines.SweptVolume Kolben2 (
        pistonCrossArea = 0.0001131,
        clearance = 0.00000250621,
        redeclare package Medium = Modelica.Media.Water.StandardWater,
        nPorts = 1,
        use_portsData = false,
        use_T_start = true,
        T_start = 293.15,
        V(start = 0.005),
        m(start = 0.005));
    Modelica.Mechanics.Translational.Sensors.PositionSensor Position3;
    Modelica.Fluid.Valves.ValveLinear NDVentile3 (
        dp_nominal = 94.35,
        m_flow_nominal = 0.05867441,
        redeclare package Medium = medium,
        opening = opening_LP_3);
    Modelica.Fluid.Pipes.DynamicPipe pipe_ND_CV_3 (
        length = 0.005,
        diameter = 0.002,
        redeclare package Medium = medium,
        roughness = 2.5E-5);
    Modelica.Fluid.Valves.ValveLinear HDVentile3 (
        dp_nominal = 95,
        m_flow_nominal = 0.05867441,
        redeclare package Medium = medium,
        opening = opening_HP_3);
    Modelica.Fluid.Pipes.DynamicPipe pipe_CV_HD_3 (
        length = 0.005,
        diameter = 0.002,
        redeclare package Medium = medium,
        roughness = 2.5E-5);
    Modelica.Fluid.Pipes.DynamicPipe pipe_Swept_CV_3 (
        length = 0.005,
        diameter = 0.002,
        redeclare package Medium = medium,
        roughness = 2.5E-5);
    Modelica.Fluid.Vessels.ClosedVolume ClosedVolume3 (
        V = 0.000005/2,
        nPorts = 3,
        redeclare package Medium = medium,
        use_portsData = false);
    Modelica.Blocks.Sources.Sine Sine3 (
        amplitude = 0.005567,
        freqHz = freq,
        offset = 0.005567,
        phase =  Modelica.Constants.pi/2.01,
        startTime = 14/(3*freq));
    Modelica.Mechanics.Translational.Sources.Position Posit3 (exact = true, useSupport = false);
    Modelica.Fluid.Machines.SweptVolume Kolben3 (
        pistonCrossArea = 0.0001131,
        clearance = 0.00000250621,
        redeclare package Medium = Modelica.Media.Water.StandardWater,
        nPorts = 1,
        use_portsData = false,
        use_T_start = true,
        T_start = 293.15,
        V(start = 0.005),
        m(start = 0.005));
    Modelica.Fluid.Sources.FixedBoundary boundary1 (p = 4e5, redeclare package Medium = Modelica.Media.Water.StandardWater, nPorts = 1);
    Modelica.Fluid.Pipes.DynamicPipe pipe1 (
        length = 0.005,
        diameter = 0.002,
        redeclare package Medium = medium,
        roughness = 2.5E-5);
    Modelica.Fluid.Sources.FixedBoundary boundary2 (p = 4e5, redeclare package Medium = Modelica.Media.Water.StandardWater, nPorts = 1);
    Modelica.Fluid.Pipes.DynamicPipe pipe2 (
        length = 0.005,
        diameter = 0.002,
        redeclare package Medium = medium,
        roughness = 2.5E-5);
    Modelica.Fluid.Pipes.DynamicPipe pipe3 (
        length = 0.005,
        diameter = 0.0055,
        redeclare package Medium = medium,
        roughness = 2.5E-5,
        modelStructure = Modelica.Fluid.Types.ModelStructure.av_b);
    Modelica.Fluid.Pipes.DynamicPipe pipe4 (
        length = 0.005,
        diameter = 0.0055,
        redeclare package Medium = medium,
        roughness = 2.5E-5,
        modelStructure = Modelica.Fluid.Types.ModelStructure.av_b);
    Modelica.Fluid.Pipes.DynamicPipe pipe5 (
        length = 0.005,
        diameter = 0.0055,
        redeclare package Medium = medium,
        roughness = 2.5E-5,
        modelStructure = Modelica.Fluid.Types.ModelStructure.av_b);
    Modelica.Fluid.Pipes.DynamicPipe pipe6 (
        length = 0.24,
        diameter = 0.005,
        redeclare package Medium = medium,
        roughness = 2.5E-5,
        modelStructure = Modelica.Fluid.Types.ModelStructure.a_vb);
    Modelica.Fluid.Vessels.ClosedVolume volume2 (
        V = 3.13e-6,
        nPorts = 4,
        redeclare package Medium = medium,
        use_portsData = false);
    Modelica.Fluid.Fittings.SimpleGenericOrifice orifice (diameter = 0.005, zeta = 0.98, redeclare package Medium = medium);
    Modelica.Fluid.Pipes.DynamicPipe pipe7 (
        length = 0.005,
        diameter = 0.005,
        redeclare package Medium = medium,
        roughness = 2.5E-5);
    Modelica.Fluid.Sensors.VolumeFlowRate Volum1 (redeclare package Medium = medium);


equation
    if der(Position.s)>=0 then 
           opening_LP=1;  
           opening_HP=0; 
     else 
           opening_LP=0;
           opening_HP=1;
     end if; 
    if der(Position2.s)>=0 then 
           opening_LP_2=1;  
           opening_HP_2=0; 
     else 
           opening_LP_2=0;
           opening_HP_2=1;
     end if;
     if der(Position3.s)>=0 then 
           opening_LP_3=1;  
           opening_HP_3=0; 
     else 
           opening_LP_3=0;
           opening_HP_3=1;
     end if;
    //Connection(s)
    connect(Posit1.flange, Kolben1.flange);
    connect(Sine1.y, Posit1.s_ref);
    connect(pipe_Swept_CV_1.port_a, Kolben1.ports[1]);
    connect(pipe_CV_HD_1.port_b, HDVentile1.port_a);
    connect(NDVentile1.port_b, pipe_ND_CV_1.port_a);
    connect(Einlass.ports[1], pipe_Ein_ND.port_a);
    connect(Posit1.flange, Position.flange);
    connect(Position2.flange, Posit2.flange);
    connect(NDVentile2.port_b, pipe_ND_CV_2.port_a);
    connect(HDVentile2.port_a, pipe_CV_HD_2.port_b);
    connect(pipe_Swept_CV_2.port_a, Kolben2.ports[1]);
    connect(Sine2.y, Posit2.s_ref);
    connect(Posit2.flange, Kolben2.flange);
    connect(Position3.flange, Posit3.flange);
    connect(NDVentile3.port_b, pipe_ND_CV_3.port_a);
    connect(HDVentile3.port_a, pipe_CV_HD_3.port_b);
    connect(pipe_Swept_CV_3.port_a, Kolben3.ports[1]);
    connect(Sine3.y, Posit3.s_ref);
    connect(Posit3.flange, Kolben3.flange);
    connect(boundary1.ports[1], pipe1.port_a);
    connect(boundary2.ports[1], pipe2.port_a);
    connect(pipe_Ein_ND.port_b, NDVentile1.port_a);
    connect(pipe1.port_b, NDVentile2.port_a);
    connect(pipe2.port_b, NDVentile3.port_a);
    connect(HDVentile1.port_b, pipe3.port_a);
    connect(HDVentile2.port_b, pipe4.port_a);
    connect(HDVentile3.port_b, pipe5.port_a);
    connect(pipe_Swept_CV_1.port_b, ClosedVolume1.ports[1]);
    connect(pipe_ND_CV_1.port_b, ClosedVolume1.ports[2]);
    connect(pipe_CV_HD_1.port_a, ClosedVolume1.ports[3]);
    connect(pipe_Swept_CV_2.port_b, ClosedVolume2.ports[1]);
    connect(pipe_ND_CV_2.port_b, ClosedVolume2.ports[2]);
    connect(pipe_CV_HD_2.port_a, ClosedVolume2.ports[3]);
    connect(pipe_Swept_CV_3.port_b, ClosedVolume3.ports[1]);
    connect(pipe_ND_CV_3.port_b, ClosedVolume3.ports[2]);
    connect(pipe_CV_HD_3.port_a, ClosedVolume3.ports[3]);
    connect(pipe3.port_b, volume2.ports[1]);
    connect(pipe4.port_b, volume2.ports[2]);
    connect(pipe5.port_b, volume2.ports[3]);
    connect(volume2.ports[4], pipe6.port_a);
    connect(orifice.port_a, pipe6.port_b);
    connect(orifice.port_b, pipe7.port_a);
    connect(Volum1.port_b, Auslass.ports[1]);
    connect(Volum1.port_a, pipe7.port_b);
end  HD_3Kolben_bsp;

 

Комментарии:

1. Что вы подразумеваете под классами? вы хотели бы разделить свою систему на несколько подсистем?

2. Да, я имею в виду подсистемы под классами.

3. Какой инструмент вы используете? Дымола?

4. Я использую TwinBuilder 2020 R2.4

5. Не могли бы вы добавить все аннотации в код? Если это так, я мог бы что-то предложить.

Ответ №1:

Вы уже используете классы. Из [документа][1]:

Ключевое слово class используется для определения общих классов (без каких-либо ограничений). Он идентичен модели ключевого слова. В большинстве случаев рекомендуется использовать специализированные классы, такие как connector, model, block, package, record, function, type. «класс» должен использоваться для определения ExternalObjects и может использоваться для классов, содержащих только документацию и / или графику.

В вашем примере, например, модели Modelica.Fluid.Pipes.DynamicPipe , Modelica.Fluid.Vessels.ClosedVolume являются повторно используемыми классами / моделями. Если у вас есть повторно используемый набор труб, объемов и клапанов, вы можете поместить их в одну модель для последующего ее повторного использования. [1]: https://doc.modelica.org/ModelicaReference 3.2.3/Resources/helpDymola/ModelicaReference_Classes.html#ModelicaReference.Классы