How correct redeclare of Medium in OpenModelica? - simulation

I used OpenModelica 1.9.4~dev-675-gb524b08
And try to create model for simulate gas plant.
When I try to redeclare a Medium according examples
model Block_Prep_ASIDGAS
import Modelica.Fluid.Interfaces;
import SI=Modelica.SIunits;
redeclare replaceable package Medium = Modelica.Media.Water.ConstantPropertyLiquidWater constrainedby Modelica.Media.Interfaces.PartialMedium "Medium in the component" annotation(choicesAllMatching = true);
Interfaces.FluidPort_a port_a (redeclare package Medium = Medium) "Порт ввода газа" annotation(Placement(visible = true, transformation(origin = {-584, 42}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {-100, 10}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Interfaces.FluidPort_b port_b annotation(Placement(visible = true, transformation(origin = {586, 46}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {102, 10}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
annotation(Icon(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2, 2}), graphics = {Text(origin = {-92, 91}, extent = {{190, 1}, {-8, -1}}, textString = "Блок подготовки кислого газа", fontSize = 40), Rectangle(lineThickness = 2, borderPattern = BorderPattern.Engraved, extent = {{-100, 98}, {100, -98}}, radius = 2), Text(origin = {-8, -3}, lineColor = {255, 0, 0}, extent = {{-70, 79}, {96, -77}}, textString = "B_PAG", fontSize = 200)}), Diagram(coordinateSystem(extent = {{-600, -400}, {600, 400}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2, 2})), experiment(StartTime = 0, StopTime = 10, Tolerance = 1e-06, Interval = 0.02));
end Block_Prep_ASIDGAS;
I got errors:
[1] Translation Error
[Seneca.BlockModels.Block_Prep_ASIDGAS.Medium: 10:26-10:92]: Illegal redeclare of element Medium, no inherited element with that name exists.
[2] Translation Error
Error occurred while flattening model Seneca.BlockModels.Block_Prep_ASIDGAS
I find two request in OpenModelica trac #2959 and #2079
Advice me how to correct my model for correct simulation in OpenModelica?

It should work as you do it but without a full model is hard to debug and see where the problem is.

you missed redeclaring the package in port_b, the rest seems to be ok.

Related

OpenModelica suction side pressure loss

I want to model the positioning of a pump with only little available NPSH with PumpMonitoringNPSH in MSL/Fluid. But simulation always fails, when I add a suction side pressure loss. It does not matter how large the suction side pressure of a tank or source or how big of a diameter I choose. The moment I comment out the monitoring and switch to ConstantPropertyLiquidWater the simulation works.
The full model is available here.
version: OpenModellica 1.20.0~dev-250-gb17e1a0
model PumpenTeststand
// monitor
Modelica.Units.NonSI.Pressure_bar p_r;
// system
inner Modelica.Fluid.System system annotation(
Placement(visible = true, transformation(origin = {-90, 90}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
// media
replaceable package Medium = Modelica.Media.Water.StandardWater;
//Modelica.Media.Water.ConstantPropertyLiquidWater;
// aggregate
Modelica.Fluid.Machines.PrescribedPump pumpe(
redeclare package Medium = Medium,
m_flow_start = 1,
redeclare function flowCharacteristic = Modelica.Fluid.Machines.BaseClasses.PumpCharacteristics.quadraticFlow(
V_flow_nominal={0.0556,0.1665,0.2778},
head_nominal={3.75e1,3e1,1.9e1}),
redeclare model Monitoring = Modelica.Fluid.Machines.BaseClasses.PumpMonitoring.PumpMonitoringNPSH,
N_nominal = 1482,
p_a_start = 1e5,
p_b_start = 1e5) annotation(
Placement(visible = true, transformation(origin = {-10, -10}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
// leitungen
Modelica.Fluid.Pipes.StaticPipe leitung(
redeclare package Medium = Medium,
diameter = 0.4,
length = 0.1,
nParallel = 1) annotation(
Placement(visible = true, transformation(origin = {-50, -10}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
// grenzen
Modelica.Fluid.Sources.FixedBoundary quelle(
redeclare package Medium = Medium,
nPorts = 1,
p = system.p_ambient) annotation(
Placement(visible = true, transformation(origin = {-90, -10}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.Fluid.Sources.Boundary_pT senke(
redeclare package Medium = Medium,
p = system.p_ambient,
T=system.T_ambient,
use_p_in=true, nPorts = 1) annotation(
Placement(visible = true, transformation(origin = {70, -10}, extent = {{-10, 10}, {10, -10}}, rotation = 180)));
// regelung
Modelica.Blocks.Sources.Ramp rampe(duration = 10, height = 5e5, offset = 1e5) annotation(
Placement(visible = true, transformation(origin = {50, 30}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
equation
p_r = Modelica.Units.Conversions.to_bar(pumpe.port_b.p - pumpe.port_a.p);
connect(rampe.y, senke.p_in) annotation(
Line(points = {{62, 30}, {92, 30}, {92, -2}, {82, -2}}, color = {0, 0, 127}));
connect(pumpe.port_b, senke.ports[1]) annotation(
Line(points = {{0, -10}, {60, -10}}, color = {0, 127, 255}));
connect(quelle.ports[1], leitung.port_a) annotation(
Line(points = {{-80, -10}, {-60, -10}}, color = {0, 127, 255}));
connect(leitung.port_b, pumpe.port_a) annotation(
Line(points = {{-40, -10}, {-20, -10}}, color = {0, 127, 255}));
annotation(experiment(StopTime=10));
end PumpenTeststand;
/tmp/OpenModelica_dh/OMEdit/Druckverlust.PumpenTeststand/PumpenTeststand -port=38349 -logFormat=xmltcp -override=startTime=0,stopTime=10,stepSize=0.02,tolerance=1e-06,solver=dassl,outputFormat=mat,variableFilter=.* -r=/tmp/OpenModelica_dh/OMEdit/Druckverlust.PumpenTeststand/PumpenTeststand_res.mat -w -lv=LOG_STATS -inputPath=/tmp/OpenModelica_dh/OMEdit/Druckverlust.PumpenTeststand -outputPath=/tmp/OpenModelica_dh/OMEdit/Druckverlust.PumpenTeststand
IF97 medium function tsat called with too low pressure
p = -161336 Pa <= 611.657 Pa (triple point pressure)
Failed to solve the initialization problem with global homotopy with equidistant step size.
Unable to solve initialization problem.
simulation terminated by an assertion at initialization
Simulation process failed. Exited with code 255.

Modelica Coding Standards / Modelica When Statement

Greeting Everyone,
Happy New Year 2020
I am using Openmodelica 1.14 release version on 64 bit windows 7 system.
I am facing some trouble with ‘when’ statement in OMSimulator. While searching for solution, I came across a closed ticket #2664 in Openmodelica. I can still see the reported issue in the current release version of Openmodelica.
I am including the relevant files of ticket # 2664.
model SimpleTest "just a simple model - Compilation etc."
Modelica.Blocks.Interfaces.IntegerInput u annotation(Placement(visible = true, transformation(origin = {-100, 40}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {-80, 40}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.Blocks.Interfaces.IntegerOutput y annotation(Placement(visible = true, transformation(origin = {100, 20}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {100, 20}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
algorithm
when change(u) then
y := y + 2;
end when;
annotation(Icon(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2, 2})), Diagram(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2, 2}), graphics = {Rectangle(origin = {-6.15, 2.93}, fillColor = {0, 133, 199}, fillPattern = FillPattern.HorizontalCylinder, extent = {{-77.89, 83.75}, {88.14, -92.53}})}));
end SimpleTest;
Is SimpleTest.mo as per Modelica standards?
While compilation of SimpleTest.mo , it throws a Translation Warning
Assuming fixed start value for the following 1 variables:
y:DISCRETE(flow=false fixed = false ) SimpleTest type: Integer
How to avoid this error?
It is just a warning. When you define a discrete variable like this such that it depends on it's previous value in a when condition, it has to have a fixed start value. Just providing a start value kind of is a guess value for the compiler, when you fix it you tell the compiler that it has to use this value for the initialization.
If you don't provide a start value it is set to zero, if you don't fix it, the compiler fixes it automatically (resulting in the warning).
Simple example:
Integer y(start=0, fixed=true);
Applied on your model:
model SimpleTest "just a simple model - Compilation etc."
Modelica.Blocks.Interfaces.IntegerInput u annotation(Placement(visible = true, transformation(origin = {-100, 40}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {-80, 40}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.Blocks.Interfaces.IntegerOutput y(start=0, fixed=true) annotation(Placement(visible = true, transformation(origin = {100, 20}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {100, 20}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
algorithm
when change(u) then
y := y + 2;
end when;
annotation(Icon(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2, 2})), Diagram(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2, 2}), graphics = {Rectangle(origin = {-6.15, 2.93}, fillColor = {0, 133, 199}, fillPattern = FillPattern.HorizontalCylinder, extent = {{-77.89, 83.75}, {88.14, -92.53}})}));
end SimpleTest;

Wrong simulation results when connecting an inverter with a smpm in Modelica

I'm using SystemModeler from Wolfram to investigate the system behaviour of an inverter connected to a permanent magnet synchronous machine.
Unfortunately I get wrong simulation results eventhough I only used components from the Modelica Standard Library.
I tried several settings so far with my model below.
model InverterSMPM
import Modelica.Constants.pi;
parameter Integer m = 3 "Number of phases";
parameter Modelica.SIunits.Frequency f = 1000 "Switching frequency";
parameter Modelica.SIunits.Frequency f1 = 50 "Fundamental wave AC frequency";
parameter Modelica.SIunits.Torque TLoad = 181.4 "Nominal load torque";
parameter Modelica.SIunits.Inertia JLoad = 0.29 "Load's moment of inertia";
Modelica.Electrical.Analog.Sources.ConstantVoltage constantVoltage_n(V = 50) annotation(Placement(transformation(extent = {{-10, -10}, {10, 10}}, rotation = 270, origin = {-105, 4}), visible = true));
Modelica.Electrical.PowerConverters.DCAC.MultiPhase2Level inverter(useHeatPort = false, m = m) annotation(Placement(transformation(extent = {{-50, 20}, {-30, 40}}, origin = {-35, -6}, rotation = 0), visible = true));
Modelica.Electrical.Analog.Basic.Ground ground annotation(Placement(transformation(extent = {{-10, -10}, {10, 10}}, rotation = 180, origin = {-125, 34}), visible = true));
Modelica.Electrical.PowerConverters.DCDC.Control.SignalPWM signalPWM[m](each useConstantDutyCycle = false, each f = f) annotation(Placement(transformation(extent = {{-10, -10}, {10, 10}}, origin = {-75, -26}, rotation = 0), visible = true));
Modelica.Electrical.Analog.Sources.ConstantVoltage constantVoltage_p(V = 50) annotation(Placement(transformation(extent = {{-10, -10}, {10, 10}}, rotation = 270, origin = {-105, 44}), visible = true));
Modelica.Blocks.Sources.Sine sine[m](phase = -Modelica.Electrical.MultiPhase.Functions.symmetricOrientation(m), startTime = zeros(m), amplitude = fill(0.5, m), offset = fill(0.5, m), freqHz = fill(f1, m)) annotation(Placement(transformation(extent = {{-30, -64}, {-50, -44}}, origin = {-35, -6}, rotation = 0), visible = true));
Modelica.Electrical.Machines.BasicMachines.SynchronousInductionMachines.SM_PermanentMagnet smpm(Jr = 0.29, p = 8, fsNominal = f1, VsOpenCircuit = 100, TsOperational = 293.15, TrOperational = 293.15, Rs = 4.7, TsRef = 293.15, alpha20s = Modelica.Electrical.Machines.Thermal.Constants.alpha20Aluminium, Lssigma = 0.001, Lmd = 0.0133, Lmq = 0.0133, useDamperCage = false) annotation(Placement(visible = true, transformation(origin = {5, -15}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.Electrical.Machines.Utilities.TerminalBox terminalBox1(terminalConnection = "Y") annotation(Placement(visible = true, transformation(origin = {5, 2.209}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.Mechanics.Rotational.Components.Inertia inertia1(J = JLoad) annotation(Placement(visible = true, transformation(origin = {35, -15}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.Mechanics.Rotational.Sources.TorqueStep torqueStep1(stepTorque = -TLoad, offsetTorque = 0, startTime = 2, useSupport = false) annotation(Placement(visible = true, transformation(origin = {76.657, -15}, extent = {{10, -10}, {-10, 10}}, rotation = 0)));
Modelica.Mechanics.Rotational.Sensors.SpeedSensor speedSensor1 annotation(Placement(visible = true, transformation(origin = {35, 20}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
equation
connect(constantVoltage_p.n, constantVoltage_n.p) annotation(Line(points = {{-70, 40}, {-70, 20}}, color = {10, 90, 224}, visible = true, origin = {-35, -6}));
connect(constantVoltage_p.p, inverter.dc_p) annotation(Line(points = {{-70, 60}, {-50, 60}, {-50, 40}}, color = {10, 90, 224}, visible = true, origin = {-35, -6}));
connect(constantVoltage_n.n, inverter.dc_n) annotation(Line(points = {{-70, -0}, {-50, 0}, {-50, 20}}, color = {10, 90, 224}, visible = true, origin = {-35, -6}));
connect(ground.p, constantVoltage_p.n) annotation(Line(points = {{-90, 30}, {-70, 30}, {-70, 40}}, color = {10, 90, 224}, visible = true, origin = {-35, -6}));
connect(sine.y, signalPWM.dutyCycle) annotation(Line(points = {{-51, -54}, {-60, -54}, {-60, -20}, {-52, -20}}, color = {1, 37, 163}, visible = true, origin = {-35, -6}));
connect(signalPWM.fire, inverter.fire_p) annotation(Line(points = {{-46, -9}, {-46, 18}}, color = {190, 52, 178}, visible = true, origin = {-35, -6}));
connect(signalPWM.notFire, inverter.fire_n) annotation(Line(points = {{-34, -9}, {-34, 18}}, color = {190, 52, 178}, visible = true, origin = {-35, -6}));
connect(terminalBox1.plug_sn, smpm.plug_sn) annotation(Line(visible = true, origin = {-1, -4.396}, points = {{0, 0.604}, {0, -0.604}}, color = {10, 90, 224}));
connect(terminalBox1.plug_sp, smpm.plug_sp) annotation(Line(visible = true, origin = {11, -4.396}, points = {{0, 0.604}, {0, -0.604}}, color = {10, 90, 224}));
connect(smpm.flange, inertia1.flange_a) annotation(Line(visible = true, origin = {20, -15}, points = {{-5, 0}, {5, 0}}, color = {64, 64, 64}));
connect(inertia1.flange_b, torqueStep1.flange) annotation(Line(visible = true, origin = {55.828, -15}, points = {{-10.828, 0}, {10.828, 0}}, color = {64, 64, 64}));
connect(speedSensor1.flange, smpm.flange) annotation(Line(visible = true, origin = {20, 2.5}, points = {{5, 17.5}, {0, 17.5}, {0, -17.5}, {-5, -17.5}}, color = {64, 64, 64}));
connect(inverter.ac, terminalBox1.plugSupply) annotation(Line(visible = true, origin = {-18.333, 15.403}, points = {{-46.667, 8.597}, {23.333, 8.597}, {23.333, -17.194}}, color = {10, 90, 224}));
annotation(experiment(StartTime = 0.00, StopTime = 5, NumberOfIntervals = 5000, __Wolfram_Algorithm = "dassl", Tolerance = 1e-6, __Wolfram_SynchronizeWithRealTime = false), Diagram(coordinateSystem(extent = {{-150, -90}, {150, 90}}, preserveAspectRatio = true, initialScale = 0.1, grid = {5, 5})));
end InverterSMPM;
One setting is: JLoad=0 and TLoad=0
I would expect the motor to run freely and with idle speed. Instead the speed sensor shows a sine wave with amplitudes [-0.46;0.46]
Another setting: JLoad=0.29 and TLoad=-180
The motor has speed=0 and decreases and gets negative values from t=2s when I apply the torque step.
Can someone may tell me what I'm doing wrong with my model and why the simulation results are wrong?
I also tried some examples from the library but they never use an inverter together with a motor. But I want to investigate on the PWM and don't want to work with ideal sine voltages and currents as in the examples...
Thank you for any help!!
What you are trying to do in you model is, to let a synchronous machine operate at nominal electrical frequency directly from standstill. This will make the machine "fall out of step", which is the reason for the machine not to operate as you would expect, but just oscillate in a seemingly random manner.
Try to reduce sine[*].freqHz to fill(0.01*f1, m) and you will see that there it will - after some oscillations - start to operate at one percent of its nominal frequency. It's just that the machine cannot overcome the oscillations for the jump to the nominal frequency.
There are multiple possibilities to work around that issue:
Initialize the machine properly: This can be done by setting at least smpm.wMechancial.start and smpm.phiMechancial.start to the correct values. Additionally it would be good to also initialize the phase currents correctly. This can be pretty tedious to do. But gives the advantage that you don't have to ramp up the speed.
It's likely easier to copy parts of the example Modelica.Electrical.Machines.Examples.SynchronousInductionMachines.SMPM_Inverter, where a voltage-frequency-controller is used to start the machine.
Many synchronous machines are actually controlled (e.g. by field-orientation or direct-torque control). For this some clues can be taken from Modelica.Electrical.Machines.Examples.SynchronousInductionMachines.SMPM_CurrentSource and Modelica.Electrical.Machines.Examples.SynchronousInductionMachines.SMPM_VoltageSource.
Additionally I would suggest to first try to get your example running with a continuous inverter like in Modelica.Electrical.Machines.Examples.SynchronousInductionMachines.SMPM_Inverter. If that works asexpected, move on the switched one.
Some things that look suspicious to me:
smpm.Rs seems pretty big to me with 4.7 Ohms especially when considering the inertias smpm.Jr (with 0.29 kg.m2) and inertia1.J (with 0.29 kg.m2).
For testing, try to increase the switching frequency above 1kHz. This is a bit low for a fundamental wave frequency of 50Hz (although it should work).

How do I fix the error, "Model is structurally singular, error found sorting equations"

This is one of the most common errors I receive when working with OpenModelica Software.
I already understand how this error is usually triggered, when system parameters are conflicting and disagree with one another.
I've already tried omitting system parameters that I've deemed not an necessity to my system however nothing seems to fix the error.
My system is already very simple to begin with. Currently, I'm working on a sub-assembly verification process in order to correctly build a working Rankine Power model. The sub assembly focuses on a (1) of (2) heat exchangers that would be used in a dual HX system incorporating a reheat process inbetween the High Pressure and Low Pressure turbines.
This sub assembly is trying to describe water coming from a pump at a condensed liquid state where it will travel through a heat exchanger "super heater" where it will change the state from a compressed liquid to a superheated vapor. This vapor will then be fed into the High Pressure turbine and return into a Pressure Sink.
I've already completed a hand calculated thermodynamic analysis of my system and know outlet temperatures and enthalpies. However, these outlet parameters are some of which I chose to remove for I felt I would let the system solve for them instead of telling it what it should calculate. Removing these values to solve the error did not work as well.
If you have any thoughts, advice or considerations please let me know! Below I've posted the code to what I have been working on. Thanks again!
CODE:
model HX_Pump_2_Superheater_2_HPTurbine
//Heat Exchanger - Steam entering HX (compressed liquid) --> Steam exiting
HX (super heated vapor)//
//Steam Turbine - High Pressure Turbine and is (1) of (2) in series with one
another. Exit pressure should be intermediate pressure level before being
reheated and directed towards Low Pressure Turbine//
ThermoPower.PowerPlants.HRSG.Components.HE HX(
FluidPhaseStart = ThermoPower.Choices.FluidPhase.FluidPhases.Liquid,
Tstartbar_G (displayUnit = "K") = 787.87,
dpnom_F(displayUnit = "Pa") = 0,
dpnom_G = 0,
exchSurface_F = 4.739,
exchSurface_G = 4.739,
extSurfaceTub = 9.479,
fluidNomFlowRate = 26.397,
fluidNomPressure = 8e+06,
fluidVol = 0.0296,
gasNomFlowRate = 169.755,
gasNomPressure = 101325,
gasVol = 0.0296,
lambda = 20,
metalVol = 5,
pstart_F = 8e+06,
pstart_G = 101325,
rhomcm = 1,
rhonom_F(displayUnit = "kg/m3") = 0.6,
rhonom_G(displayUnit = "kg/m3") = 0.33) annotation(
Placement(visible = true, transformation(origin = {-1.9984e-15, 14}, extent
= {{-20, -20}, {20, 20}}, rotation = 0)));
ThermoPower.Gas.SinkPressure sinkPressure1(
redeclare package Medium = ThermoPower.Media.FlueGas,
T = 106.86 + 273,
p0 = 101325) annotation(
Placement(visible = true, transformation(origin = {92, 14}, extent = {{-10,
-10}, {10, 10}}, rotation = 0)));
ThermoPower.Gas.SensT sensT1(
redeclare package Medium = ThermoPower.Media.FlueGas,
allowFlowReversal = false) annotation(
Placement(visible = true, transformation(origin = {-50, 18}, extent = {{-10,
-10}, {10, 10}}, rotation = 0)));
ThermoPower.Gas.SensT sensT2(
redeclare package Medium = ThermoPower.Media.FlueGas,
allowFlowReversal = false) annotation(
Placement(visible = true, transformation(origin = {50, 18}, extent = {{-10,
-10}, {10, 10}}, rotation = 0)));
ThermoPower.Water.SinkPressure sinkPressure2(
redeclare package Medium = ThermoPower.Water.StandardWater,
T = 165 + 273,
h = 2536.2092e5,
p0 = 7.0e5) annotation(
Placement(visible = true, transformation(origin = {92, -60}, extent = {{-10,
-10}, {10, 10}}, rotation = 0)));
ThermoPower.Water.SensT sensT3(
redeclare package Medium = ThermoPower.Water.StandardWater) annotation(
Placement(visible = true, transformation(origin = {4, 64}, extent = {{-10,
-10}, {10, 10}}, rotation = -90)));
ThermoPower.Water.SensT sensT4(
redeclare package Medium = ThermoPower.Water.StandardWater,
allowFlowReversal = false) annotation(
Placement(visible = true, transformation(origin = {4, -32}, extent = {{-10,
-10}, {10, 10}}, rotation = -90)));
inner ThermoPower.System system annotation(
Placement(visible = true, transformation(origin = {-90, 90}, extent = {{-10,
-10}, {10, 10}}, rotation = 0)));
ThermoPower.Gas.SourceMassFlow sourceMassFlow1(
redeclare package Medium = ThermoPower.Media.FlueGas,
T = 514 + 273,
p0 = 101325,
w0 = 169.755) annotation(
Placement(visible = true, transformation(origin = {-90, 14}, extent = {{-10,
-10}, {10, 10}}, rotation = 0)));
ThermoPower.Water.SourceMassFlow sourceMassFlow2(
redeclare package Medium = ThermoPower.Water.StandardWater,
T = 42.88 + 273,
h = 183.1e3,
p0 = 80e5,
use_T = true,
w0 = 26.397) annotation(
Placement(visible = true, transformation(origin = {2, 92}, extent = {{-10,
-10}, {10, 10}}, rotation = -90)));
ThermoPower.Water.SteamTurbineStodola steamTurbineStodola1(
Kt = 0.01328,
PRstart = 11.43,
explicitIsentropicEnthalpy = false,
pnom = 80.0e5,
pout(fixed = false),
w(fixed = false),
wnom = 26.397,
wstart = 26.397) annotation(
Placement(visible = true, transformation(origin = {12, -72}, extent = {{-14,
-14}, {14, 14}}, rotation = 0)));
equation
connect(sensT2.outlet, sinkPressure1.flange) annotation(
Line(points = {{56, 14}, {82, 14}}, color = {159, 159, 223}));
connect(steamTurbineStodola1.outlet, sinkPressure2.flange) annotation(
Line(points = {{24, -60}, {82, -60}, {82, -60}, {82, -60}}, color = {0, 0,
255}));
connect(sensT4.outlet, steamTurbineStodola1.inlet) annotation(
Line(points = {{0, -38}, {0, -38}, {0, -60}, {0, -60}}, color = {0, 0,
255}));
connect(HX.waterOut, sensT4.inlet) annotation(
Line(points = {{0, -6}, {0, -26}}, color = {0, 0, 255}));
connect(sourceMassFlow1.flange, sensT1.inlet) annotation(
Line(points = {{-80, 14}, {-56, 14}}, color = {159, 159, 223}));
connect(sensT3.outlet, HX.waterIn) annotation(
Line(points = {{0, 58}, {0, 58}, {0, 34}, {0, 34}}, color = {0, 0, 255}));
connect(sourceMassFlow2.flange, sensT3.inlet) annotation(
Line(points = {{0, 82}, {0, 70}}, color = {0, 0, 255}));
connect(HX.gasOut, sensT2.inlet) annotation(
Line(points = {{20, 14}, {44, 14}, {44, 14}, {44, 14}}, color = {159, 159,
223}));
connect(sensT1.outlet, HX.gasIn) annotation(
Line(points = {{-44, 14}, {-20, 14}, {-20, 14}, {-20, 14}}, color = {159,
159, 223}));
annotation(
uses(ThermoPower(version = "3.1"), Modelica(version = "3.2.3")));end
HX_Pump_2_Superheater_2_HPTurbine;
The error message in Dymola says:
The model HX_Pump_2_Superheater_2_HPTurbine is structurally singular.
The problem is structurally singular for the element type Real.
The number of scalar Real unknown elements are 93. The number of
scalar Real equation elements are 93.
The following variables are considered as unknowns, but are not
appearing in the equations. steamTurbineStodola1.phi
Part of the problem for Real elements is overdetermined. There are 1
scalar equations too many in the set:
...
The important part is that steamTurbineStodola1.phi does not appear in the equations. That is the angle of turbine shaft, and it indicates that the turbine-shaft is just "free floating".
Adding an inertia and connecting it to the shaft avoids that problem:
public
Modelica.Mechanics.Rotational.Components.Inertia inertia
annotation (Placement(transformation(extent={{28,-82},{48,-62}})));
equation
connect(steamTurbineStodola1.shaft_b, inertia.flange_a)
annotation (Line(points={{20.96,-72},{28,-72}}, color={0,0,0}));
but then there are other issues related to low pressure etc.
Obviously adding just an inertia with default inertia isn't the correct model - but I believe it indicates what to do.

Modelica Flow Simulation says divide by zero

I am trying to simulate the flow in a pipe that starts out partially full, and gradually fills up. Once it is full, the flow equation needs to change. I have tried the following code, but I get a divide by zero error once the pipe is full. TestTrap1 is a demo that shows the problem. It seems that some equation is not correct once the pipe is full.
I am using openmodelica to run this.
package FlowPackage
package Interfaces
extends Modelica.Icons.InterfacesPackage;
//Use this for a inlet outlet device
connector Fitting "Inlet port"
flow Modelica.SIunits.MassFlowRate q "Flow rate [Kg/s]";
Modelica.SIunits.Pressure P "Pressure";
annotation(defaultComponentName = "fitting", Icon(coordinateSystem(preserveAspectRatio = true, extent = {{-100, -100}, {100, 100}}), graphics = {Rectangle(extent = {{-100, 100}, {100, -100}}, lineColor = {0, 0, 255}, fillColor = {0, 0, 255}, fillPattern = FillPattern.Solid)}), Diagram(coordinateSystem(preserveAspectRatio = true, extent = {{-100, -100}, {100, 100}}), graphics = {Rectangle(extent = {{-40, 40}, {40, -40}}, lineColor = {0, 0, 255}, fillColor = {0, 0, 255}, fillPattern = FillPattern.Solid), Text(extent = {{-160, 110}, {40, 50}}, lineColor = {0, 0, 255}, textString = "%name")}));
end Fitting;
end Interfaces;
model SourceConstant
parameter Modelica.SIunits.MassFlowRate q = 0.015 "Flow rate [Kg/s]";
Interfaces.Fitting fitting annotation(Placement(visible = true, transformation(origin = {100, -6}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {100, -6}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
equation
-fitting.q = q;
annotation(Icon(graphics = {Rectangle(origin = {-3, 30}, extent = {{-93, 60}, {93, -60}}), Rectangle(origin = {0, 15}, fillColor = {0, 0, 255}, fillPattern = FillPattern.Solid, extent = {{-90, 45}, {90, -45}})}), Diagram);
end SourceConstant;
model ZeroP
parameter Modelica.SIunits.Pressure p = 0.00 "Pressure";
Interfaces.Fitting fitting annotation(Placement(visible = true, transformation(origin = {100, -6}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {100, -6}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
equation
fitting.P = p;
annotation(Icon(graphics = {Rectangle(origin = {-1, 2}, extent = {{-95, 94}, {95, -94}})}), Diagram);
end ZeroP;
model TestTrap1
TrapTemp trap1 ( level(start = 0.0509)) annotation(Placement(visible = true, transformation(origin = {10, 8}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
SourceConstant sourceConstant1(q = 0.03) annotation(Placement(visible = true, transformation(origin = {-50, 26}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
ZeroP zeroP1 (p = 101000) annotation(Placement(visible = true, transformation(origin = {64, 8}, extent = {{10, -10}, {-10, 10}}, rotation = 0)));
equation
connect(sourceConstant1.fitting, trap1.fitting_in) annotation(Line(points = {{-40, 26}, {-18, 26}, {-18, 8}, {0, 8}, {0, 8}}, color = {0, 0, 255}));
connect(trap1.fitting_out, zeroP1.fitting) annotation(Line(points = {{20, 8}, {54, 8}, {54, 8}, {54, 8}}, color = {0, 0, 255}));
annotation(Icon, Diagram, experiment(StartTime = 0, StopTime = 1450, Tolerance = 1e-6, Interval = 2.9));
end TestTrap1;
model TrapTemp
//Calculate the velocity for pipe segments
Interfaces.Fitting fitting_in annotation(Placement(visible = true, transformation(origin = {-100, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {-100, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Interfaces.Fitting fitting_out annotation(Placement(visible = true, transformation(origin = {98, -2}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {98, -2}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
import m = Modelica.Math;
parameter Modelica.SIunits.Length L = 25000 "pipe length (m)";
parameter Modelica.SIunits.Radius R = 0.10194 / 2.0 "pipe inner radius (m)";
parameter Modelica.SIunits.Height roughness = 6.0e-5 "Average height of surface asperities (default: smooth steel pipe)";
/*Values below are liquid at 300K*/
parameter Modelica.SIunits.DynamicViscosity mu = 0.092977 "Dynamic Viscocity (cp)";
parameter Modelica.SIunits.Density row = 501.22 "Density (kg/m^3)";
Modelica.SIunits.Area A;
Modelica.SIunits.Length s(start = 0.158) "wetted perimeter";
Modelica.SIunits.Length rh "hydraulic radius";
Modelica.SIunits.Diameter De(start = 0.1) "eqivalent diameter [m]";
Modelica.SIunits.ReynoldsNumber Re(start = 3000);
Modelica.SIunits.Velocity v(start = 0.0001);
Modelica.SIunits.Length hf "Friction head loss";
Modelica.SIunits.Acceleration g = Modelica.Constants.g_n;
Modelica.SIunits.Acceleration a "Acceleration of flow";
Modelica.SIunits.CoefficientOfFriction f;
Real relative_roughness;
Real percent_full "Fraction of pipe is full [%]";
Modelica.SIunits.Mass mass;
Real percent_full "Fraction of pipe is full [%]";
Modelica.SIunits.Height level "Liquid level (m)";
equation
percent_full = level / R * 100.0;
relative_roughness = roughness / De;
a = der(v);
s = 2 * level + R;
rh = A / s;
De = 4 * rh;
//Protect against negative Re:
Re = De * abs(v) * row / mu;
//Head loss due to friction. Corrected for direction
hf = sign(v) * f * L * v ^ 2 / (2 * De * g);
f = 64 / Re ;
mass = A * row * L;
fitting_in.q + fitting_out.q = der(mass);
fitting_out.q = -v * A * row;
mass * a = A * (fitting_in.P - fitting_out.P - hf * row * g ) ;
A = R * level;
if noEvent(level >= R) then
//full pipe
fitting_in.q = -fitting_out.q;
else
//partially full pipe
fitting_in.P = fitting_out.P;
end if;
annotation(Icon, Diagram);
end TrapTemp;
annotation(Icon, Diagram);
end FlowPackage;
Any suggestions about why this doesn't work, or how to fix it would be greatly appreciated.
firstly, you need to define what is what you want, I mean, if you want to start storing fluid within the pipe before transferring it, you need to define the set of mass and energy equations to store liquid, i.e: if you want to store liquid you cannot calculate Re, because v=0, and once is filled, swap the model as you did with one conditional and define the navier-stokes equations to define the momentum of the fluid.
Anyway, I think you should try connecting one mass flow rate source, one tank, one valve (define the opening law for the valve in function of the level of the tank), one pipe and one sink with the Modelica Standard library components.