Related
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
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.
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.
I get a warning when I model with Modelica on Twin builder. Warning is: The component m_flow_start is declared multiple times and can not be verified to be identical to other declaration(s) with the same name. Even though this warning seems not so important for my model, I would like to learn why this warning occurs and how to avoid it.
Do you know how to deal with this warning?
model Hochdruckreiniger3
//Declaration(s)
Real V_max = 2506e-6;
Real V_tod = 3765e-6;
Real N = 2800;
Real opening_NP;
Real opening_HP;
Real dp_nominal_ND = (0.7*rho_ND*0.01135*0.01135)/(3600/(2*N*N));
Real dp_nominal_HD = (0.7*rho_HD*0.01135*0.01135)/(3600/(2*N*N));
Real rho_ND = 998.388;
Real rho_HD = 1019.921;
Real m_flow_ND = rho_ND*0.000113097*0.01135*N/60;
Real m_flow_HD = rho_HD*0.000113097*0.01135*N/60;
//Component(s)
Modelica.Fluid.Machines.SweptVolume Swept1 (
pistonCrossArea = 0.0001131,
clearance = 0.00000250621,
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;
Modelica.Mechanics.Translational.Sources.Position Posit1 (exact = true, useSupport = false);
Modelica.Blocks.Sources.Sine Sine1 (
amplitude = 0.005567,
freqHz = 16.66,
offset = 0.005567,
phase = -Modelica.Constants.pi/4);
Modelica.Fluid.Sources.FixedBoundary boundary (p = 4e5, redeclare package Medium = Modelica.Media.Water.StandardWater, nPorts = 1);
Modelica.Fluid.Pipes.DynamicPipe pipe1 (
length = 0.5,
diameter = 0.03,
redeclare package Medium = Modelica.Media.Water.StandardWater,
modelStructure = Modelica.Fluid.Types.ModelStructure.av_b);
Modelica.Fluid.Valves.ValveIncompressible Niederdruckventile (
dp_nominal = dp_nominal_ND,
m_flow_nominal = m_flow_ND,
rho_nominal = rho_ND,
opening = opening_NP,
redeclare package Medium = Modelica.Media.Water.StandardWater);
Modelica.Fluid.Pipes.DynamicPipe pipe2 (
length = 0.002,
diameter = 0.011,
redeclare package Medium = Modelica.Media.Water.StandardWater,
modelStructure = Modelica.Fluid.Types.ModelStructure.av_b);
Modelica.Fluid.Pipes.DynamicPipe pipe3 (
length = 0.019,
diameter = 0.0055,
redeclare package Medium = Modelica.Media.Water.StandardWater,
modelStructure = Modelica.Fluid.Types.ModelStructure.a_vb);
Modelica.Fluid.Valves.ValveIncompressible Hochdruckventile (
dp_nominal = dp_nominal_HD,
m_flow_nominal = m_flow_HD,
rho_nominal = rho_HD,
opening = opening_HP,
redeclare package Medium = Modelica.Media.Water.StandardWater);
Modelica.Fluid.Pipes.DynamicPipe pipe4 (
length = 0.5,
diameter = 0.03,
redeclare package Medium = Modelica.Media.Water.StandardWater,
modelStructure = Modelica.Fluid.Types.ModelStructure.a_vb);
Modelica.Fluid.Sources.FixedBoundary boundary1 (p = 5e5, redeclare package Medium = Modelica.Media.Water.StandardWater, nPorts = 1);
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(Niederdruckventile.port_b, pipe2.port_a);
connect(pipe2.port_b, Swept1.ports[1]);
connect(boundary.ports[1], pipe1.port_a);
connect(pipe1.port_b, Niederdruckventile.port_a);
connect(Swept1.ports[2], pipe3.port_a);
connect(pipe3.port_b, Hochdruckventile.port_a);
connect(Hochdruckventile.port_b, pipe4.port_a);
connect(pipe4.port_b, boundary1.ports[1]);
end Hochdruckreiniger3;
Thanks in advance!
I believe you can just ignore it.
As far as I could see internally in Dymola the issue is in Modelica.Fluid.Pipes.BaseClasses.FlowModels.PartialStaggeredFlowModel inheriting from Modelica.Fluid.Interfaces.PartialDistributedFlow, and both contain definitions of m_flow_start that differ slightly in MSL 3.2.3 - but only in terms of the parameter-dialog:
parameter Medium.MassFlowRate m_flow_start=system.m_flow_start
"Start value of mass flow rates"
annotation(Dialog(tab="Internal Interface",enable=false,group = "Initialization"));
vs.
parameter Medium.MassFlowRate m_flow_start=system.m_flow_start
"Start value of mass flow rates"
annotation(Dialog(tab="Initialization"));
BTW: The model has a number of issues with lack of parameter it should be:
parameter Real V_max = 2506e-6;
parameter Real V_tod = 3765e-6;
parameter Real N = 2800;
Real opening_NP;
Real opening_HP;
parameter Real dp_nominal_ND = (0.7*rho_ND*0.01135*0.01135)/(3600/(2*N*N));
parameter Real dp_nominal_HD = (0.7*rho_HD*0.01135*0.01135)/(3600/(2*N*N));
parameter Real rho_ND = 998.388;
parameter Real rho_HD = 1019.921;
parameter Real m_flow_ND = rho_ND*0.000113097*0.01135*N/60;
parameter Real m_flow_HD = rho_HD*0.000113097*0.01135*N/60;
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.