Classes in Modelica - modelica

I have a complex model in Modelica. As I have lots of components in my model, I want to define classes and include some components inside the classes to reduce the complexity of the model. Since I couldn`t find online an example of the use of classes which are used in Modelica, could you give an idea how to define classes in Modelica?
The code is as follows;
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;

You are already using classes.
From the [doc][1]:
The keyword class is used to define general classes (without any restrictions). It is identical to the keyword model. In most cases, it is recommended to use specialized classes as connector, model, block, package, record, function, type. "class" should be used to define ExternalObjects, and can be used for classes merely containing documentation and/or graphics.
In your example, e.g. the models Modelica.Fluid.Pipes.DynamicPipe, Modelica.Fluid.Vessels.ClosedVolume are reusable classes/models. If you have a reocurring set of pipes, volumes and valves, you may put them into one model to later reuse it.
[1]: https://doc.modelica.org/ModelicaReference%203.2.3/Resources/helpDymola/ModelicaReference_Classes.html#ModelicaReference.Classes

Related

Simulation of a hydraulic system

I try to simulate a hydraulic machine in Ansys Twinbuilder 2021 R1 with Modelica language.
The whole system is in the following image;
Firstly I tried to divide the whole system into the subsystems. And I simulated the subsystems of pumpraum-1, pumpraum-2, pumpraum-3, outlet-components. And the subsystems work individually without any problem. Then I tried to compile the subsystems into the whole system. Then the simulation doesn`t proceed smoothly. It stops at any timestep and doesnt continue to the end of the simulation. What could be reason of that? How can I understand where is the problem in my whole system?
The code of my model is as follows;
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_CV_HD_1 (
length = 0.005,
diameter = 0.002,
redeclare package Medium = medium,
roughness = 2.5E-5);
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.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.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.Vessels.ClosedVolume volume2 (
V = 3.13e-6,
nPorts = 4,
redeclare package Medium = medium,
use_portsData = false);
Modelica.Fluid.Pipes.StaticPipe pipe (length = 0.001, diameter = 0.002, redeclare package Medium = medium);
Modelica.Fluid.Pipes.StaticPipe pipe6 (length = 0.001, diameter = 0.002, redeclare package Medium = medium);
Modelica.Fluid.Pipes.StaticPipe pipe7 (length = 0.001, diameter = 0.002, redeclare package Medium = medium);
Modelica.Fluid.Pipes.DynamicPipe pipe10_steig (
length = 0.003,
diameter = 0.002721,
redeclare package Medium = medium,
roughness = 2.5E-5,
nNodes = 1,
modelStructure = Modelica.Fluid.Types.ModelStructure.av_b);
Modelica.Fluid.Pipes.DynamicPipe pipe9_steig (
length = 0.008,
diameter = 0.00598,
redeclare package Medium = medium,
roughness = 2.5E-5,
nNodes = 1,
modelStructure = Modelica.Fluid.Types.ModelStructure.av_b);
Modelica.Fluid.Pipes.DynamicPipe pipe8 (
length = 5,
diameter = 0.0057,
redeclare package Medium = medium,
roughness = 2.5E-5,
nNodes = 1,
modelStructure = Modelica.Fluid.Types.ModelStructure.av_b);
Modelica.Fluid.Fittings.SimpleGenericOrifice orifice4 (diameter = 0.00452, zeta = 3.5, redeclare package Medium = medium);
Modelica.Fluid.Pipes.DynamicPipe Duese_2 (
length = 0.0082,
diameter = 0.0042,
redeclare package Medium = medium,
roughness = 2.5E-5,
nNodes = 1,
modelStructure = Modelica.Fluid.Types.ModelStructure.av_b);
Modelica.Fluid.Pipes.DynamicPipe Duese_3 (
length = 0.018,
diameter = 0.00452,
redeclare package Medium = medium,
roughness = 2.5E-5,
nNodes = 1,
modelStructure = Modelica.Fluid.Types.ModelStructure.av_b);
Modelica.Fluid.Pipes.DynamicPipe Duese_4 (
length = 0.0002,
diameter = 0.0005,
redeclare package Medium = medium,
roughness = 2.5E-5,
nNodes = 1,
modelStructure = Modelica.Fluid.Types.ModelStructure.av_b);
Modelica.Fluid.Pipes.DynamicPipe Duese_1 (
length = 0.393,
diameter = 0.0074,
redeclare package Medium = medium,
roughness = 2.5E-5,
nNodes = 1,
modelStructure = Modelica.Fluid.Types.ModelStructure.av_b);
Modelica.Fluid.Pipes.DynamicPipe pistole_3 (
length = 0.02,
diameter = 0.004,
redeclare package Medium = medium,
roughness = 2.5E-5,
nNodes = 1,
modelStructure = Modelica.Fluid.Types.ModelStructure.av_b);
Modelica.Fluid.Fittings.SimpleGenericOrifice orifice2 (diameter = 0.005, zeta = 0.98, redeclare package Medium = medium);
Modelica.Fluid.Pipes.DynamicPipe pistole_1 (
length = 0.041,
diameter = 0.0057,
redeclare package Medium = medium,
roughness = 2.5E-5,
nNodes = 1,
modelStructure = Modelica.Fluid.Types.ModelStructure.av_b);
Modelica.Fluid.Fittings.SimpleGenericOrifice orifice1 (diameter = 0.005, zeta = 1, redeclare package Medium = medium);
Modelica.Fluid.Pipes.DynamicPipe pistole_2 (
length = 0.269,
diameter = 0.0069,
redeclare package Medium = medium,
roughness = 2.5E-5,
nNodes = 1,
modelStructure = Modelica.Fluid.Types.ModelStructure.av_b);
Modelica.Fluid.Pipes.DynamicPipe pipe9 (
length = 0.24,
diameter = 0.005,
redeclare package Medium = medium,
roughness = 2.5E-5,
modelStructure = Modelica.Fluid.Types.ModelStructure.av_b,
nNodes = 1);
Modelica.Fluid.Sources.FixedBoundary Auslass (p = patm, redeclare package Medium = medium, nPorts = 1);
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_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(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(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_ND_CV_1.port_b, ClosedVolume1.ports[2]);
connect(pipe_CV_HD_1.port_a, ClosedVolume1.ports[3]);
connect(pipe_ND_CV_2.port_b, ClosedVolume2.ports[2]);
connect(pipe_CV_HD_2.port_a, ClosedVolume2.ports[3]);
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(Kolben1.ports[1], pipe.port_a);
connect(pipe.port_b, ClosedVolume1.ports[1]);
connect(Kolben2.ports[1], pipe6.port_a);
connect(pipe6.port_b, ClosedVolume2.ports[1]);
connect(Kolben3.ports[1], pipe7.port_a);
connect(pipe7.port_b, ClosedVolume3.ports[1]);
connect(pipe10_steig.port_a, Duese_3.port_b);
connect(pipe9_steig.port_b, Duese_2.port_a);
connect(pipe9_steig.port_a, Duese_1.port_b);
connect(pipe10_steig.port_b, orifice4.port_a);
connect(pistole_3.port_a, pistole_2.port_b);
connect(pistole_1.port_b, pistole_2.port_a);
connect(pipe8.port_b, pistole_1.port_a);
connect(pipe8.port_a, orifice2.port_b);
connect(orifice4.port_b, Duese_4.port_a);
connect(Duese_2.port_b, Duese_3.port_a);
connect(Duese_4.port_b, Auslass.ports[1]);
connect(Duese_1.port_a, orifice1.port_b);
connect(pistole_3.port_b, orifice1.port_a);
connect(orifice2.port_a, pipe9.port_b);
connect(pipe9.port_a, volume2.ports[4]);
end HD_3Kolben_bsp;
//----------------------------------------------------------------------------
Using Dymola, and after reducing the relative tolerance of the solver, I'm getting this:
Model error - differentiated if-then-else was not continuous: (if
time < 0.050724637681159424 then 0 else Sine2.amplitudesin(289.02652413026095(time-0.050724637681159424)+Sine2.phase))
Value jumped from 0 to 0.00556683.
This error can be overcome by setting Posit2.exact = false. But then a follow-up error emerges, likely due to the quick change or an inconsistent overall system. This is difficult to judge without knowing the model in detail. So I'll leave that to somebody else to solve.
Besides that there are some issues with initialization, but they seem to be rather minor:
IF97 medium function called with too low pressure p = -35428.5 Pa <= 611.657 Pa (triple point pressure)
Failed condition: p > 611.657
Regarding the second comment:
The initialization issue should be solvable by setting (the important) variables from the following list. The list actually contains variables for which the simulation environment has to guess initial values, as they are not specified.
Assuming fixed start value for the continuous states:
ClosedVolume1.medium.h(start = ClosedVolume1.h_start)
ClosedVolume1.medium.p(start = 101325.0)
ClosedVolume2.medium.h(start = ClosedVolume2.h_start)
ClosedVolume2.medium.p(start = 101325.0)
ClosedVolume3.medium.h(start = ClosedVolume3.h_start)
ClosedVolume3.medium.p(start = 101325.0)
Duese_1.mediums[1].h(start = Duese_1.h_start)
Duese_1.mediums[1].p(start = Duese_1.ps_start[1])
Duese_2.mediums[1].h(start = Duese_2.h_start)
Duese_2.mediums[1].p(start = Duese_2.ps_start[1])
Duese_3.mediums[1].h(start = Duese_3.h_start)
Duese_3.mediums[1].p(start = Duese_3.ps_start[1])
Duese_4.mediums[1].h(start = Duese_4.h_start)
Duese_4.mediums[1].p(start = Duese_4.ps_start[1])
Kolben1.medium.h(start = Kolben1.h_start)
Kolben1.medium.p(start = 101325.0)
Kolben2.medium.h(start = Kolben2.h_start)
Kolben2.medium.p(start = 101325.0)
Kolben3.medium.h(start = Kolben3.h_start)
Kolben3.medium.p(start = 101325.0)
pipe1.mediums[1].h(start = pipe1.h_start)
pipe1.mediums[2].h(start = pipe1.h_start)
pipe1.mediums[2].p(start = pipe1.ps_start[2])
pipe2.mediums[1].h(start = pipe2.h_start)
pipe2.mediums[2].h(start = pipe2.h_start)
pipe2.mediums[2].p(start = pipe2.ps_start[2])
pipe3.mediums[1].h(start = pipe3.h_start)
pipe3.mediums[1].p(start = pipe3.ps_start[1])
pipe3.mediums[2].h(start = pipe3.h_start)
pipe3.mediums[2].p(start = pipe3.ps_start[2])
pipe4.mediums[1].h(start = pipe4.h_start)
pipe4.mediums[1].p(start = pipe4.ps_start[1])
pipe4.mediums[2].h(start = pipe4.h_start)
pipe4.mediums[2].p(start = pipe4.ps_start[2])
pipe5.mediums[1].h(start = pipe5.h_start)
pipe5.mediums[1].p(start = pipe5.ps_start[1])
pipe5.mediums[2].h(start = pipe5.h_start)
pipe5.mediums[2].p(start = pipe5.ps_start[2])
pipe8.mediums[1].h(start = pipe8.h_start)
pipe8.mediums[1].p(start = pipe8.ps_start[1])
pipe9.mediums[1].h(start = pipe9.h_start)
pipe9_steig.mediums[1].h(start = pipe9_steig.h_start)
pipe9_steig.mediums[1].p(start = pipe9_steig.ps_start[1])
pipe10_steig.mediums[1].h(start = pipe10_steig.h_start)
pipe10_steig.mediums[1].p(start = pipe10_steig.ps_start[1])
pipe_CV_HD_1.mediums[1].h(start = pipe_CV_HD_1.h_start)
pipe_CV_HD_1.mediums[2].h(start = pipe_CV_HD_1.h_start)
pipe_CV_HD_1.mediums[2].p(start = pipe_CV_HD_1.ps_start[2])
pipe_CV_HD_2.mediums[1].h(start = pipe_CV_HD_2.h_start)
pipe_CV_HD_2.mediums[2].h(start = pipe_CV_HD_2.h_start)
pipe_CV_HD_2.mediums[2].p(start = pipe_CV_HD_2.ps_start[2])
pipe_CV_HD_3.mediums[1].h(start = pipe_CV_HD_3.h_start)
pipe_CV_HD_3.mediums[2].h(start = pipe_CV_HD_3.h_start)
pipe_CV_HD_3.mediums[2].p(start = pipe_CV_HD_3.ps_start[2])
pipe_Ein_ND.mediums[1].h(start = pipe_Ein_ND.h_start)
pipe_Ein_ND.mediums[2].h(start = pipe_Ein_ND.h_start)
pipe_Ein_ND.mediums[2].p(start = pipe_Ein_ND.ps_start[2])
pipe_ND_CV_1.mediums[1].h(start = pipe_ND_CV_1.h_start)
pipe_ND_CV_1.mediums[1].p(start = pipe_ND_CV_1.ps_start[1])
pipe_ND_CV_1.mediums[2].h(start = pipe_ND_CV_1.h_start)
pipe_ND_CV_2.mediums[1].h(start = pipe_ND_CV_2.h_start)
pipe_ND_CV_2.mediums[1].p(start = pipe_ND_CV_2.ps_start[1])
pipe_ND_CV_2.mediums[2].h(start = pipe_ND_CV_2.h_start)
pipe_ND_CV_3.mediums[1].h(start = pipe_ND_CV_3.h_start)
pipe_ND_CV_3.mediums[1].p(start = pipe_ND_CV_3.ps_start[1])
pipe_ND_CV_3.mediums[2].h(start = pipe_ND_CV_3.h_start)
pistole_1.mediums[1].h(start = pistole_1.h_start)
pistole_1.mediums[1].p(start = pistole_1.ps_start[1])
pistole_2.mediums[1].h(start = pistole_2.h_start)
pistole_2.mediums[1].p(start = pistole_2.ps_start[1])
pistole_3.mediums[1].h(start = pistole_3.h_start)
pistole_3.mediums[1].p(start = pistole_3.ps_start[1])
volume2.medium.h(start = volume2.h_start)
volume2.medium.p(start = 101325.0)

Effect of the pipe diameter in speed of the simulation - Modelica

I use Ansys TwinBuilder R2.4 for Modelica simulations. I modeled a hydraulic system in Modelica which can be simulated in certain conditions, e.g. when the diameter of the pipe, which is located before the "Auslass" boundary condition, is 5 mm, when I change it to 8 mm, simulation doesn´t proceed. It slows down the progress of the simulation considerably. What can be reason of the difference in speed of the simulation only if the diameter of the pipe is changed? I added block diagram and the code of the model.
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 = 5,
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 = 5, redeclare package Medium = medium);
Modelica.Fluid.Pipes.DynamicPipe pipe7 (
length = 0.005,
diameter = 0.005,
redeclare package Medium = medium,
roughness = 2.5E-5);
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(pipe7.port_b, Auslass.ports[1]);
end HD_3Kolben_bsp;
Best regards
This can be a number of things. From a screenshot it is only possible to give very general advice. As it is "only" a parameter the system's structure shouldn't change. Therefore it is likely related to dynamics of the system. I would take a look at the solver log first, starting with the number of computed steps or the step-size. If that changed in an order of magnitude of the slow-down you experience this is a good starting point.
Another issue could be chattering, which could be judged with knowledge about the number of events that happened. These should also be visible from the solver log.
Some additional information that would help:
Which Modelica-Tool are you using?
The model itself (with which all of the below can be generated)
The solver log (before and after the parameter change)
The translation log incl. system properties like the sizes of equation systems (before and after the parameter change)
I'm afraid without any additional information you will not get utterly helpful advice...
It seems to me that you have used the default flowModel to calculate the pressure drop. This model depends on the pipe diameter (flow regime turbulent/laminar).
For a further detailed answer, I would need the information my colleague asks for in his answer above.

Pressure inside the Sweptvolume component in Modelica

I model a system in Modelica, in which a fluid should be compressed from 4 bar to 500 bar. I give as boundary conditions 4 bar inlet pressure and 500 bar outlet pressure. I want to realize this compression by movement of a piston. The system can simulate when outlet pressure is defined as 10 bar. But it is not able to simulate at 500 bar outlet pressure. When outlet boundary condition is 500 bar then pressure inside the piston chamber is not higher than 500 bar. So I get negative massflow and pressure inside the piston chamber. Therefore simulation doesnt continue. When I look at pressure inside the chamber, it simply assumes medium pressure as the pressure which is defined at the ports of the piston. Compression movement of piston doesnt affect the pressure inside the piston, as pressure in piston given by the pressure at the ports of the piston. Do you know how to increase pressure inside the piston so that I can have a pressure level greater than 500 bar inside the piston?
I add the code and blockdiagram. Any help will be appreciated! Thanks a lot!
//----------------------------------------------------------------------------
// Name of Model: Hochdruckreiniger3
// Date: 11/15/20 21:16:37
// Generated from Modelica Diagram Editor
//----------------------------------------------------------------------------
model Hochdruckreiniger3
//Declaration(s)
Real V_max = 0.000003;
Real V_tod = 0.000002;
Real N = 2800;
Real opening_NP;
Real opening_HP;
replaceable package medium = Modelica.Media.Water.StandardWater( );
//Component(s)
Modelica.Fluid.Machines.SweptVolume Swept1 (
pistonCrossArea = 0.003131,
clearance = 0.000250621,
redeclare package Medium = medium,
nPorts = 3,
use_portsData = false,
p_start = system.p_start,
use_T_start = true,
T_start = 293.15);
inner Modelica.Fluid.System system;
Modelica.Mechanics.Translational.Sources.Position Posit1 (exact = true, useSupport = false);
Modelica.Blocks.Sources.Sine Sine1 (
amplitude = 0.005567,
freqHz = 46.66,
offset = 0.005567,
phase = -Modelica.Constants.pi/2);
Modelica.Fluid.Sources.FixedBoundary boundary (p = 500e5, redeclare package Medium = medium, nPorts = 1);
Modelica.Fluid.Pipes.DynamicPipe pipe2 (
length = 0.5,
diameter = 0.03,
redeclare package Medium = medium,
momentumDynamics = system.momentumDynamics,
massDynamics = Modelica.Fluid.Types.Dynamics.DynamicFreeInitial,
energyDynamics = system.energyDynamics,
allowFlowReversal = system.allowFlowReversal,
modelStructure = Modelica.Fluid.Types.ModelStructure.av_b);
Modelica.Fluid.Pipes.DynamicPipe pipe3 (
length = 0.5,
diameter = 0.03,
redeclare package Medium = medium,
momentumDynamics = system.momentumDynamics,
massDynamics = Modelica.Fluid.Types.Dynamics.DynamicFreeInitial,
energyDynamics = system.energyDynamics,
allowFlowReversal = system.allowFlowReversal,
modelStructure = Modelica.Fluid.Types.ModelStructure.a_vb);
Modelica.Fluid.Pipes.DynamicPipe pipe4 (
length = 0.5,
diameter = 0.03,
redeclare package Medium = medium,
momentumDynamics = system.momentumDynamics,
massDynamics = Modelica.Fluid.Types.Dynamics.DynamicFreeInitial,
energyDynamics = system.energyDynamics,
allowFlowReversal = system.allowFlowReversal,
modelStructure = Modelica.Fluid.Types.ModelStructure.a_vb);
Modelica.Fluid.Sources.FixedBoundary boundary1 (p = 500e5, redeclare package Medium = medium, nPorts = 1);
Modelica.Fluid.Pipes.DynamicPipe pipe5 (
length = 0.5,
diameter = 0.3,
redeclare package Medium = medium,
momentumDynamics = system.momentumDynamics,
massDynamics = Modelica.Fluid.Types.Dynamics.DynamicFreeInitial,
energyDynamics = system.energyDynamics,
allowFlowReversal = system.allowFlowReversal,
modelStructure = Modelica.Fluid.Types.ModelStructure.av_b);
Modelica.Blocks.Sources.Pulse Puls1 (period = 0.02142, width = 45.331);
Modelica.Blocks.Sources.Pulse Puls2 (period = 0.02142, startTime = 0.01071, width = 45.331);
Modelica.Fluid.Valves.ValveLinear NDVentile (dp_nominal = 94.35, m_flow_nominal = 0.05867441, redeclare package Medium = medium);
Modelica.Fluid.Valves.ValveLinear HDVentile (dp_nominal = 95, m_flow_nominal = 0.05867441, redeclare package Medium = medium);
Modelica.Fluid.Sensors.Pressure pressureamSweptvolume (redeclare package Medium = medium);
Modelica.Fluid.Sensors.Pressure PressureanderPipe (redeclare package Medium = medium);
Modelica.Fluid.Sensors.Pressure PressureanBeginnderHochdruckventile (redeclare package Medium = medium);
Modelica.Fluid.Sensors.Pressure Pressure_amEndederHDVentile (redeclare package Medium = medium);
Modelica.Fluid.Pipes.DynamicPipe pipe1 (
length = 0.5,
diameter = 0.03,
redeclare package Medium = medium,
momentumDynamics = system.momentumDynamics,
massDynamics = Modelica.Fluid.Types.Dynamics.DynamicFreeInitial,
energyDynamics = system.energyDynamics,
allowFlowReversal = system.allowFlowReversal,
modelStructure = Modelica.Fluid.Types.ModelStructure.a_vb);
Modelica.Fluid.Vessels.ClosedVolume volume (
V = 7e-9,
nPorts = 2,
use_portsData = false,
redeclare package Medium = medium,
p_start = 26.5e5);
equation
if der(Sine1.y)>=0 then
opening_NP=1;
opening_HP=0;
else
opening_NP=0;
opening_HP=1;
end if;
//Connection(s)
connect(Posit1.flange, Swept1.flange);
connect(Sine1.y, Posit1.s_ref);
connect(pipe2.port_b, Swept1.ports[1]);
connect(Swept1.ports[2], pipe3.port_a);
connect(pipe4.port_b, boundary1.ports[1]);
connect(boundary.ports[1], pipe5.port_a);
connect(pipe5.port_b, NDVentile.port_a);
connect(NDVentile.port_b, pipe2.port_a);
connect(NDVentile.opening, Puls1.y);
connect(Puls2.y, HDVentile.opening);
connect(pipe3.port_b, HDVentile.port_a);
connect(pressureamSweptvolume.port, Swept1.ports[3]);
connect(PressureanderPipe.port, pipe3.port_a);
connect(PressureanBeginnderHochdruckventile.port, HDVentile.port_b);
connect(Pressure_amEndederHDVentile.port, HDVentile.port_a);
connect(pipe1.port_a, PressureanBeginnderHochdruckventile.port);
connect(pipe1.port_b, volume.ports[1]);
connect(volume.ports[2], pipe4.port_a);
end Hochdruckreiniger3;
you can view the annotations by clicking on the down-arrows at the bar with the line numbers on the left side unless you have used the graphical editor to model your model.

Error: Sizes do not match in connection - Sweptvolume and ClosedVolume -Modelica

I try to a model in which when the pressure inside the ClosedVolume exceed a certain pressure level, then HDVentile opens and the fluid flows into the boundary1 component. I defined the nports=1 in sweptvolume and nPorts =2 in ClosedVolume. In this case it throws an error saying
Sizes do not match in connection, size of 'ClosedVolume.ports' is [2] and size of 'Swept1.ports' is
If I set the nports=2 in sweptvolume and nPorts =2 in ClosedVolume, then it throws an error saying:
Assertion failed: each ports[i] of volume can at most be connected to one component. If two or more connections are present, ideal mixing takes place with these connections, which is usually not the intention of the modeller. Increase nPorts to add an additional port
Do you know how to handle this error? Thanks in advance!
model modelmitclosedvolume
//Declaration(s)
Real V_max = 0.000003;
Real V_tod = 0.000002;
Real N = 2800;
replaceable package medium = Modelica.Media.Water.StandardWater( );
//Component(s)
Modelica.Fluid.Machines.SweptVolume Swept1 (
pistonCrossArea = 0.0001131,
clearance = 0.000000250621,
redeclare package Medium = Modelica.Media.Water.StandardWater,
nPorts = 2,
use_portsData = false,
p_start = 1e5,
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 = 46.66,
offset = 0.005567,
phase = -Modelica.Constants.pi/4);
Modelica.Fluid.Pipes.DynamicPipe pipe3 (
length = 0.5,
diameter = 0.03,
redeclare package Medium = Modelica.Media.Water.StandardWater,
momentumDynamics = system.momentumDynamics,
massDynamics = Modelica.Fluid.Types.Dynamics.DynamicFreeInitial,
energyDynamics = system.energyDynamics,
allowFlowReversal = system.allowFlowReversal,
modelStructure = Modelica.Fluid.Types.ModelStructure.a_vb);
Modelica.Fluid.Valves.ValveLinear HDVentile (dp_nominal = 95, m_flow_nominal = 0.05867441, redeclare package Medium = medium);
Modelica.Fluid.Pipes.DynamicPipe pipe4 (
length = 0.5,
diameter = 0.03,
redeclare package Medium = Modelica.Media.Water.StandardWater,
momentumDynamics = system.momentumDynamics,
massDynamics = Modelica.Fluid.Types.Dynamics.DynamicFreeInitial,
energyDynamics = system.energyDynamics,
allowFlowReversal = system.allowFlowReversal,
modelStructure = Modelica.Fluid.Types.ModelStructure.a_vb);
Modelica.Fluid.Sources.FixedBoundary boundary1 (p = 500e5, redeclare package Medium = Modelica.Media.Water.StandardWater, nPorts = 1);
Modelica.Fluid.Vessels.ClosedVolume ClosedVolume (
V = 0.005/6,
nPorts = 2,
portsData = {Modelica.Fluid.Vessels.BaseClasses.VesselPortsData(diameter=0.001),Modelica.Fluid.Vessels.BaseClasses.VesselPortsData(diameter=0.001)},
redeclare package Medium = medium);
equation
//Connection(s)
connect(Posit1.flange, Swept1.flange);
connect(Sine1.y, Posit1.s_ref);
connect(pipe3.port_b, HDVentile.port_a);
connect(HDVentile.port_b, pipe4.port_a);
connect(pipe4.port_b, boundary1.ports[1]);
connect(ClosedVolume.ports[1], pipe3.port_a);
connect(ClosedVolume.ports, Swept1.ports);
end modelmitclosedvolume;
I think the last connect should be
connect(ClosedVolume.ports[2], Swept1.ports[1]);
and for Swept1 it should be nPorts = 1.
If you then add an input to HDVentile e.g. using
HDVentile.opening = 0;
the system should work.
Background: nports corresponds to the number of connections to the component. Then you usually only connect a single line to each port. Therefore you need two for the ClosedVolume and single one for Swept1.

Hydraulic system(Valve, Sweeping Volume, Pipe)- Modelica

This is a follow-up question. I am able to solve the simplified case. Now I make it more complicated. I insert valves( High pressure and low-pressure valve). The opening of these valves is dependent on the movement of sweeping volume. if sweeping volume increases, the low-pressure valve opens, if it decreases, high-pressure valve opens.
In this image, it is seen the left system and it works. But when I add another part (high-pressure valve and high-pressure boundary condition) it gives an error when I try to solve.
In this second image, you can see the whole system.
These are the errors that I get when I try to solve
Error occurred when entering initialization mode on Hochdruckreiniger3_1
Error encountered in the Initialize function of the user model.
Error encountered while initializing the simulators
This is the code.
model Hochdruckreiniger2
//Declaration(s)
Real V_max = 0.000003;
Real V_tod = 0.000002;
Real N = 2800;
Real f;
Real opening_NP;
Real opening_HP;
import Modelica.Constants.pi;
//Component(s)
Modelica.Fluid.Machines.SweptVolume Swept1 (
pistonCrossArea = 0.0001131,
clearance = 0.00000250621,
portsData = {Modelica.Fluid.Vessels.BaseClasses.VesselPortsData(diameter = 0.012), Modelica.Fluid.Vessels.BaseClasses.VesselPortsData(diameter=
0.012)},
redeclare package Medium = Modelica.Media.Water.StandardWater,
nPorts = 2,
use_portsData = true,
use_T_start = true,
T_start = 293.15);
inner Modelica.Fluid.System system;
Modelica.Mechanics.Translational.Sources.Position Posit1 (exact = true, useSupport = false);
Modelica.Fluid.Valves.ValveIncompressible Hochdruckventile (
dp_nominal = 96.38,
m_flow_nominal = 0.05867441,
rho_nominal = 1019.921,
opening = opening_HP,
redeclare package Medium = Modelica.Media.Water.StandardWater);
Modelica.Fluid.Valves.ValveIncompressible Niederdruckventile (
dp_nominal = 94.35,
m_flow_nominal = 0.05867441,
rho_nominal = 998.388,
opening = opening_NP,
redeclare package Medium = Modelica.Media.Water.StandardWater);
Modelica.Blocks.Sources.Sine Sine1 (
amplitude = 0.005567,
freqHz = 46.72,
offset = 0.005567,
phase = -pi/2);
Modelica.Fluid.Sources.FixedBoundary boundary (p = 4e5, redeclare package Medium = Modelica.Media.Water.StandardWater, nPorts = 1);
Modelica.Fluid.Sources.FixedBoundary boundary1 (p = 10e5, redeclare package Medium = Modelica.Media.Water.StandardWater, nPorts = 1);
Modelica.Fluid.Pipes.DynamicPipe pipe (
length = 0.5,
diameter = 0.03,
redeclare package Medium = Modelica.Media.Water.StandardWater,
modelStructure = Modelica.Fluid.Types.ModelStructure.a_vb);
Modelica.Fluid.Pipes.DynamicPipe pipe1 (
length = 0.5,
diameter = 0.03,
redeclare package Medium = Modelica.Media.Water.StandardWater,
modelStructure = Modelica.Fluid.Types.ModelStructure.a_vb);
Modelica.Fluid.Pipes.DynamicPipe pipe2 (
length = 0.5,
diameter = 0.03,
redeclare package Medium = Modelica.Media.Water.StandardWater,
modelStructure = Modelica.Fluid.Types.ModelStructure.a_vb);
Modelica.Fluid.Pipes.DynamicPipe pipe3 (
length = 0.5,
diameter = 0.03,
redeclare package Medium = Modelica.Media.Water.StandardWater,
modelStructure = Modelica.Fluid.Types.ModelStructure.a_vb);
equation
//T_per=pi/(180*3600*N/60);//Radian
f=(((V_max-V_tod)/2)*sin(2*pi*time*(60/N)))+V_tod+(V_max-V_tod)/2;
if der(f)>=0 then
opening_NP=1;
opening_HP=0;
else
opening_NP=0;
opening_HP=1;
end if;
//Connection(s)
connect(Posit1.flange, Swept1.flange);
connect(Sine1.y, Posit1.s_ref);
connect(boundary.ports[1], pipe.port_a);
connect(pipe.port_b, Niederdruckventile.port_a);
connect(Niederdruckventile.port_b, pipe1.port_a);
connect(pipe1.port_b, Swept1.ports[1]);
connect(Swept1.ports[2], pipe2.port_a);
connect(pipe2.port_b, Hochdruckventile.port_a);
connect(Hochdruckventile.port_b, pipe3.port_a);
connect(pipe3.port_b, boundary1.ports[1]);
end Hochdruckreiniger2;
If you can help me it would be great. Thanks in advance!