Trapezoidal Integration of nonlinear inductance - modelica

I have modeled the nonlinear inductor with Modelica, but the circuit can not be solved by trapezoidal integration, It is appreciated someone can help me to solve the circuit.
model NonlinearInductor
import Modelica.SIunits.MagneticFlux;
extends Modelica.Electrical.Analog.Interfaces.OnePort;
parameter Real T[:,2]=[-1.0015,-1200;-0.0015,-200;0,0;0.0015,200;1.0015,1200]
"piecewiselinear current versus flux relation";
Integer nbPoints = size(T,1) "Number of interpolation points";
Real L; //Slop of line flux-Current; inductance
MagneticFlux flux( start=0);
equation
v = der(flux); // Faraday's Low
algorithm
// Definition of Piecewise nonlinear inductance
if i < T[2,1] then
L := ((T[1,2] - T[2,2]) / (T[1,1] - T[2,1]));
flux := L * (i-T[1,1]) + T[1,2];
elseif i >= T[nbPoints-1,1] then
L := (( T[nbPoints-1,2] - T[nbPoints,2]) / (T[nbPoints-1,1] - T[nbPoints,1]));
flux := L * (i-T[nbPoints-1,1]) + T[nbPoints-1,2];
else
for iter in 2:(nbPoints-2) loop
if i >= T[iter,1] and i <T[iter+1,1] then
L := (( T[iter,2] - T[iter+1,2]) / (T[iter,1] - T[iter+1,1]));
flux := L * (i-T[iter,1]) + T[iter,2];
end if;
end for;
end if;
end NonlinearInductor;
and I have prepared and example as below:
model NonlinearInductorTest
Modelica.Electrical.Analog.Sources.CosineVoltage cosineVoltage1(V = 25e3 * sqrt(2), freqHz = 50,
phase=1.5707963267949) annotation (
Placement(visible = true, transformation(origin = {-80, 20}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
Modelica.Electrical.Analog.Basic.Resistor resistor1(R = 1000e6) annotation (
Placement(visible = true, transformation(origin = {-14, 20}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
Modelica.Electrical.Analog.Basic.Ground ground1 annotation (
Placement(visible = true, transformation(origin = {-80, -12}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.Electrical.Analog.Basic.Capacitor capacitor1(C=0.4e-9) annotation (
Placement(visible = true, transformation(origin = {-50, 42}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
NonlinearInductor L annotation(
Placement(visible = true, transformation(origin = {28, 20}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
equation
connect(L.n, ground1.p) annotation(
Line(points = {{28, 10}, {28, 10}, {28, -2}, {-80, -2}, {-80, -2}}, color = {0, 0, 255}));
connect(L.p, capacitor1.n) annotation(
Line(points = {{28, 30}, {28, 30}, {28, 42}, {-40, 42}, {-40, 42}}, color = {0, 0, 255}));
connect(capacitor1.p, cosineVoltage1.p) annotation(
Line(points = {{-60, 42}, {-80, 42}, {-80, 30}}, color = {0, 0, 255}));
connect(capacitor1.n, resistor1.p) annotation(
Line(points = {{-40, 42}, {-14, 42}, {-14, 30}}, color = {0, 0, 255}));
connect(resistor1.n, ground1.p) annotation(
Line(points = {{-14, 10}, {-14, -2}, {-80, -2}}, color = {0, 0, 255}));
connect(ground1.p, cosineVoltage1.n) annotation(
Line(points = {{-80, -2}, {-80, 10}}, color = {0, 0, 255}));
annotation (
uses(Modelica(version="3.2.2")),
experiment(StartTime = 0, StopTime = 0.1, Tolerance = 1e-6, Interval = 2e-05));
end NonlinearInductorTest;
Please run the example by solver Trapezoidal, StopTime = 0.1, Interval = 2e-05

Your model can be drastically simplified by using the interpolate function of the MSL.
As far as I understood, your code does the same as this function: using linear interpolation inside the defined interval and linear extrapolation outside.
Here is the updated code:
model NonlinearInductor2
extends Modelica.Electrical.Analog.Interfaces.OnePort;
parameter Real T[:,2]=[-1.0015,-1200;
-0.0015,-200;
0,0;
0.0015,200;
1.0015,1200] "piecewiselinear current versus flux relation";
Modelica.SIunits.MagneticFlux flux( start=0);
protected
final parameter Real[:] i_vec = T[:, 1];
final parameter Real[:] flux_vec = T[:, 2];
equation
v = der(flux); // Faraday's Law
flux = Modelica.Math.Vectors.interpolate(i_vec,flux_vec,i);
end NonlinearInductor2;
Apart from making your model much simpler to understand, the usage of the interpolate function brings also these benefits:
The function has the smoothOrder annotation defined, which allows the Modelica translator to differentiate your flux variable analytically .
(With the annotations smooth and smoothOrder you can define up to which order the derivative is continuous)
Instead of the algorithm section we can use a single equation section.
(You should avoid algorithm sections to describe physical behavior, as it limits the Modelica translator in manipulating your equations to create a solvable system. With algorithm sections you force the code to be evaluated exactly how you have written it, which is against the principle of a-causal physical modeling)
Unfortunately, OpenModelica still has some trouble to simulate the new model with your simulation setup (trapezoidal rule, tolerance=1e-6). By reducing the tolerance to 1e-4 the simulation finishes, but still showing the warning
Restart Kinsol: change linear solver to KINDense.
many many times. Maybe an OpenModelica expert can help on that.
Dymola by the way has no troubles with the new code, regardless of the selected solver.

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.

How can I use the SimpleGenericOrifice of the Modelica Standard Library to impose pressure loss in a pipe?

I would like to model an hydraulic network where I use the Modelica.Fluid.Fittings.SimpleGenericOrifice as a seal so I can impose the pressure loss of a pipe. Using the formula in the documentation, I can calculate the zeta coefficient of the orifice.
Here is a simplified example, here I try to impose a pressure loss of 50 bar inside my pipe1. Because the pressure should be equal at the port, I assume that it should work :
However I don't have any pressure loss in the pipe and in the orifice.
Does anyone know how to make this work ?
Here is the code of the example
model Joints_HD
replaceable package Medium=Modelica.Media.Water.StandardWater constrainedby
Modelica.Media.Interfaces.PartialMedium;
Modelica.Fluid.Pipes.StaticPipe pipe(redeclare package Medium = Medium,diameter = 0.15, length = 1) annotation(
Placement(visible = true, transformation(origin = {-38, 10}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
inner Modelica.Fluid.System system annotation(
Placement(visible = true, transformation(origin = {-70, 42}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.Fluid.Sources.Boundary_pT boundary(redeclare package Medium = Medium,T = 328.15, p = 157e5, nPorts = 1) annotation(
Placement(visible = true, transformation(origin = {-66, 10}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.Fluid.Sources.MassFlowSource_T boundary1(redeclare package Medium = Medium,T = 328.15, m_flow = -0.17, nPorts = 1) annotation(
Placement(visible = true, transformation(origin = {72, 10}, extent = {{10, -10}, {-10, 10}}, rotation = 0)));
Modelica.Fluid.Pipes.StaticPipe pipe2(redeclare package Medium = Medium,diameter = 0.15, length = 1) annotation(
Placement(visible = true, transformation(origin = {44, 10}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.Fluid.Fittings.SimpleGenericOrifice orifice(redeclare package Medium = Medium,diameter = 0.15, dp_nominal = 5e+06, m_flow_nominal = 2.34e-9, use_zeta = false) annotation(
Placement(visible = true, transformation(origin = {2, 10}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.Fluid.Pipes.StaticPipe pipe1(redeclare package Medium = Medium, diameter = 0.15, length = 1) annotation(
Placement(visible = true, transformation(origin = {2, -18}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
equation
connect(boundary.ports[1], pipe.port_a) annotation(
Line(points = {{-56, 10}, {-48, 10}}, color = {0, 127, 255}));
connect(pipe.port_b, orifice.port_a) annotation(
Line(points = {{-28, 10}, {-8, 10}}, color = {0, 127, 255}));
connect(pipe2.port_b, boundary1.ports[1]) annotation(
Line(points = {{54, 10}, {62, 10}}, color = {0, 127, 255}));
connect(orifice.port_b, pipe2.port_a) annotation(
Line(points = {{12, 10}, {34, 10}}, color = {0, 127, 255}));
connect(pipe.port_b, pipe1.port_a) annotation(
Line(points = {{-28, 10}, {-20, 10}, {-20, -18}, {-8, -18}}, color = {0, 127, 255}));
connect(pipe1.port_b, pipe2.port_a) annotation(
Line(points = {{12, -18}, {26, -18}, {26, 10}, {34, 10}}, color = {0, 127, 255}));
annotation(
uses(Modelica(version = "3.2.3")));
end Joints_HD;
Best regards,
Maxime
pipe1 has "wrong" dimensions (diameter, length, roughness etc.) since it only creates a very small pressure drop.
To verify that the rest of the model is okay — and that you can have a pressure drop of 50 bar over pipe1 at the flow set in boundary1 (0.17 kg/s) — temporarilly change pipe1.FlowModel to NominalTurbulentPipeFlow with m_flow_nominal=0.17 and dp_nominal=50 bar.
Subsequently, switch the flow model back to the default (detailed) model and adjust the pipe geometry.
By the way, you should provide a value for orifice.zeta even though it is not used.

Modelica integerChange block not working as intended?

I'm trying to use the integerChange block from the Modelica Standard library
It doesn't seem to work however. What am i doing wrong? I would have expected a spike at each change,but i get a constant "false". I'm using OpenModelica 1.17
Here is the simple model
model integerChangeTest
Modelica.Blocks.Math.IntegerChange integerChange annotation(
Placement(visible = true, transformation(origin = {26, 24}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.Blocks.Math.RealToInteger realToInteger annotation(
Placement(visible = true, transformation(origin = {-6, 24}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.Blocks.Sources.Sine sine(amplitude = 5, freqHz = 5) annotation(
Placement(visible = true, transformation(origin = {-48, 26}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
equation
connect(realToInteger.y, integerChange.u) annotation(
Line(points = {{5, 24}, {13, 24}}, color = {255, 127, 0}));
connect(sine.y, realToInteger.u) annotation(
Line(points = {{-37, 26}, {-19, 26}, {-19, 24}}, color = {0, 0, 127}));
annotation(
uses(Modelica(version = "3.2.3")));
end integerChangeTest;
The block works, but plotting change(x) is complicated in many Modelica tools.
The reason is that at an event there are a number of intermediate values, and to avoid plotting too many values one common solution is to just store the first and last; that also simplifies the implementation since it avoids a callback for storing values during the event iteration. Unfortunately change is only true in intermediate values during event iterations - and thus plotting it becomes meaningless.
I don't know if OpenModelica has some special mode for including them as well.
If you want to see that it changes you can use the code in the comment or graphically add not+OnDelay
model integerChangeTest
Modelica.Blocks.Math.IntegerChange integerChange annotation (
Placement(visible = true, transformation(origin = {26, 24}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.Blocks.Math.RealToInteger realToInteger annotation (
Placement(visible = true, transformation(origin = {-6, 24}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.Blocks.Sources.Sine sine(amplitude = 5, freqHz = 5) annotation (
Placement(visible = true, transformation(origin = {-48, 26}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.Blocks.Logical.Not not1
annotation (Placement(transformation(extent={{46,14},{66,34}})));
Modelica.Blocks.MathBoolean.OnDelay onDelay(delayTime=1e-3)
annotation (Placement(transformation(extent={{82,20},{90,28}})));
equation
connect(realToInteger.y, integerChange.u) annotation (
Line(points={{5,24},{14,24}}, color = {255, 127, 0}));
connect(sine.y, realToInteger.u) annotation (
Line(points={{-37,26},{-18,26},{-18,24}}, color = {0, 0, 127}));
connect(integerChange.y, not1.u)
annotation (Line(points={{37,24},{44,24}}, color={255,0,255}));
connect(onDelay.u, not1.y)
annotation (Line(points={{80.4,24},{67,24}}, color={255,0,255}));
annotation (
uses(Modelica(version="3.2.2")));
end integerChangeTest;

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.