Wrong or no simulation results of FFT when StopTime ist too high in OpenModelica - modelica

I'm using the realFFT library with OpenModelica to analyze the frequencies in a PWM signal.
When I analyze frequencies below 10 kHz everything works fine.
But as soon as I set my maximum frequency to more than 10 kHz my simulation either calculates wrong results, crashes or says that it simulated but doesn't show the results.
What I found out so far:
I have a the samplePeriod=8.3us and the number of samples ns=6000 for a max frequency of f_max=12kHz and a resolution of f_res=20Hz which results in a stopTime>=(6000-1)*8.3us --> stopTime>=0.05s (according to the library).
So I simulated with this stopTime and it worked but when I set stopTime=0.1s it doesn't show any results but says that it simulated fine. When I further increased the stopTime to 0.2s it calculated wrong results.
This doesn't make sense to me, why should it fail with an increased stopTime?
Might this be another OpenModelica issue and works fine with Dymola?
Here are my models:
model TestRealFFT
Modelica.Blocks.Sources.Pulse pulse1(amplitude = 1, offset = 0, period = 100e-6, width = 40) annotation(
Placement(visible = true, transformation(origin = {-168, 16}, extent = {{-60, -60}, {60, 60}}, rotation = 0)));
FFTmath fFTmath1(f_max = 12000, f_res = 20) annotation(
Placement(visible = true, transformation(origin = {176, 8}, extent = {{-80, -80}, {80, 80}}, rotation = 0)));
equation
connect(pulse1.y, fFTmath1.u) annotation(
Line(points = {{-102, 16}, {68, 16}, {68, 8}, {80, 8}}, color = {0, 0, 127}));
annotation(
stopTime = 2,
Diagram(coordinateSystem(extent = {{-300, -250}, {300, 250}})),
Icon(coordinateSystem(extent = {{-300, -250}, {300, 250}})),
__OpenModelica_commandLineOptions = "",
experiment(StartTime = 0, StopTime = 0.2, Tolerance = 1e-06, Interval = 8e-06));
end TestRealFFT;
and
model FFTmath
import Modelica.Constants.{pi};
import Modelica.Math.FastFourierTransform.*;
import Modelica.SIunits.*;
Modelica.Blocks.Interfaces.RealInput u annotation(
Placement(visible = true, transformation(origin = {-120, 0}, extent = {{-20, -20}, {20, 20}}, rotation = 0), iconTransformation(origin = {-120, 0}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
parameter Frequency f_max = 12000 "Maximum frequency of interest";
parameter Frequency f_res = 20 "Frequency resolution";
final parameter Integer ns = realFFTsamplePoints(f_max, f_res, f_max_factor = 5) "Number of samples";
final parameter Integer nf = div(ns, 2) + 1 "Number of frequency points";
final parameter Integer nfi = max(1, min(integer(ceil(f_max / f_res)) + 1, nf));
final parameter Frequency f_i[nfi](each fixed = false) "FFT frequencies of interested frequency points";
parameter Time samplePeriod = 1 / (2 * f_res * div(ns, 2));
output Integer info(start = 0, fixed = true) "Information flag from FFT computation";
Integer iTick(start = 0, fixed = true);
discrete Real Buf[ns](start = zeros(ns), each fixed = true) "Input buffer";
Real A_i[nfi](start = zeros(nfi), each fixed = true) "FFT amplitudes";
Real Phi_i[nfi](start = zeros(nfi), each fixed = true) "FFT phases";
Real y(start = 0, fixed = true);
// "Signal from which FFT is computed";
initial equation
for i in 1:nfi loop
f_i[i] = (i - 1) * f_res;
end for;
equation
algorithm
when sample(0, samplePeriod) then
iTick := iTick + 1;
y := u;
if iTick <= ns then
Buf[iTick] := y;
end if;
if iTick == ns then
(info, A_i, Phi_i) := realFFT(Buf, nfi);
end if;
end when;
//3 * sin(2 * pi * f1 * time) + sin(2 * pi * f2 * time);
annotation(
Documentation(Icon(graphics = {Text(origin = {-42, 62}, extent = {{110, -78}, {-30, 18}}, textString = "FFT"), Rectangle(origin = {0, -79}, fillPattern = FillPattern.Solid, extent = {{-80, -1}, {80, 1}}), Rectangle(origin = {-79, -49}, fillPattern = FillPattern.Solid, extent = {{-1, -29}, {1, 29}}), Polygon(origin = {-79, -15}, fillPattern = FillPattern.Solid, points = {{0, -5}, {-6, -5}, {0, 5}, {6, -5}, {6, -5}, {0, -5}}), Polygon(origin = {85, -79}, rotation = -90, fillPattern = FillPattern.Solid, points = {{0, -5}, {-6, -5}, {0, 5}, {6, -5}, {6, -5}, {0, -5}}), Rectangle(origin = {-59, -65}, fillPattern = FillPattern.Solid, extent = {{-1, 23}, {1, -15}}), Ellipse(origin = {-59, -39}, fillPattern = FillPattern.Solid, extent = {{-3, 3}, {3, -3}}, endAngle = 360), Ellipse(origin = {-49, -61}, fillPattern = FillPattern.Solid, extent = {{-3, 3}, {3, -3}}, endAngle = 360), Ellipse(origin = {-19, -53}, fillPattern = FillPattern.Solid, extent = {{-3, 3}, {3, -3}}, endAngle = 360), Ellipse(origin = {25, -67}, fillPattern = FillPattern.Solid, extent = {{-3, 3}, {3, -3}}, endAngle = 360), Ellipse(origin = {31, -49}, fillPattern = FillPattern.Solid, extent = {{-3, 3}, {3, -3}}, endAngle = 360), Rectangle(origin = {-49, -65}, fillPattern = FillPattern.Solid, extent = {{-1, 1}, {1, -15}}), Rectangle(origin = {31, -65}, fillPattern = FillPattern.Solid, extent = {{-1, 15}, {1, -15}}), Rectangle(origin = {-19, -63}, fillPattern = FillPattern.Solid, extent = {{-1, 7}, {1, -15}}), Rectangle(origin = {25, -63}, fillPattern = FillPattern.Solid, extent = {{-1, -5}, {1, -15}}), Ellipse(origin = {-67, -61}, fillPattern = FillPattern.Solid, extent = {{-3, 3}, {3, -3}}, endAngle = 360), Rectangle(origin = {-67, -63}, fillPattern = FillPattern.Solid, extent = {{-1, 1}, {1, -15}}), Rectangle(origin = {37, -63}, fillPattern = FillPattern.Solid, extent = {{-1, -5}, {1, -15}}), Ellipse(origin = {37, -67}, fillPattern = FillPattern.Solid, extent = {{-3, 3}, {3, -3}}, endAngle = 360), Line(points = {{-100, 100}, {100, 100}, {100, -100}, {-100, -100}, {-100, 100}, {-100, 100}}, thickness = 0.5)}),
Diagram,
__OpenModelica_commandLineOptions = "");
end FFTmath;
I'm very thankful for any help!

Looks like a bug in OpenModelica. Please open a ticket about it on trac.openmodelica.org.
Problem 1 Huge result files are breaking
When simulating with OpenModelica (v1.14.0-dev-26633-gd9901afc5b) for 0.05 sec simulation time the result mat-file is already 1.06 GB. For 0.1 sec you get around 2.1 GB and a corrupt header.
Problem 2 Wrong results
When you simulate interval [0, 0.2] the solution is completely wrong. Values of y are somewhere around 1.4e+31 and time goes up to 5e+218. Could be because of the broken result file.
But even if you reduce tolerance and interval it won't simulate correctly, maybe because of the huge amount of events.
Works in Dymola 2019, but needs a lot of time to open the result files.

Related

How to use hierarchical connectors in Modelica

I want to use hierarchical connectors in Modelica. I have level 1 connectors made of RealOutput, level 2 connectors made of arrays of level 1, and level 3 connectors made of arrays of level 2.
I managed to make connectors of level 1 and 2 work, but could not figure out how to make level 3 connectors.
Below is a package that illustrates my attempts.
Models M1 and M2 work but model M3 causes an error in OpenModelica.
[1] 13:25:41 Translation Error
[/var/lib/jenkins2/ws/LINUX_BUILDS/tmp.build/openmodelica-1.19.2~dev.beta1/OMCompiler/Compiler/NFFrontEnd/NFCeval.mo: 1053:9-1053:67]: Internal error NFCeval.evalBinarySub failed to evaluate ‘{2, 5}[i] - {1, 3}[i]‘
within Experiment;
package conn
connector L1
"Level 1 connector"
parameter Integer n;
Modelica.Blocks.Interfaces.RealOutput R[n];
annotation(
Diagram(graphics = {Ellipse(fillColor = {239, 41, 41}, fillPattern = FillPattern.Sphere, extent = {{-60, 60}, {60, -60}})}),
Icon(graphics = {Ellipse(fillColor = {239, 41, 41}, fillPattern = FillPattern.Sphere, extent = {{-60, 60}, {60, -60}})}));
end L1;
connector L2
"Level 2 connector"
parameter Integer r[:];
L1 l1[size(r, 1)](n=r);
annotation(
Icon(graphics = {Ellipse(fillColor = {252, 233, 79}, fillPattern = FillPattern.Sphere, extent = {{-60, 60}, {60, -60}})}),
Diagram(graphics = {Ellipse(fillColor = {252, 233, 79}, fillPattern = FillPattern.Sphere, extent = {{-60, 60}, {60, -60}})}));
end L2;
connector L3
"Level 3 connector"
parameter Integer a[:]; // {2, 3}
parameter Integer r[sum(a)]; // {2, 3, 2, 3, 4}
parameter Integer start[size(a, 1)]; // r start indices {1, 3}
parameter Integer stop[size(a,1)]; // r stop indices {2, 5}
// how to construct connector with a = {2, 3}, r = {2, 3, 2, 3, 4} ?
// to get l2[1] = L2(r={2, 3})
// to get l2[2] = L2(r={2, 3, 4})
L2 l2[size(a,1)](r={r[start[i]:stop[i]] for i in 1:size(a,1)});
annotation(
Diagram(graphics = {Ellipse(fillColor = {138, 226, 52}, fillPattern = FillPattern.Sphere, extent = {{-60, 60}, {60, -60}})}),
Icon(graphics = {Ellipse(fillColor = {138, 226, 52}, fillPattern = FillPattern.Sphere, extent = {{-60, 60}, {60, -60}})}));
end L3;
model M1
"Model with level 1 connector"
Modelica.Blocks.Sources.Constant[5] C(k = {1, 2, 3, 4, 5});
L1 l1(n=5);
equation
connect(C.y, l1.R);
annotation(
Icon(graphics = {Rectangle(fillColor = {239, 41, 41}, fillPattern = FillPattern.Sphere, extent = {{-100, 100}, {100, -100}})}));
end M1;
model M2
"Model with level 2 connector"
Modelica.Blocks.Sources.Constant[5] C(k = {1, 2, 3, 4, 5});
L2 l2(r={2, 3});
equation
connect(C[1:2].y, l2.l1[1].R[1:2]);
connect(C[3:5].y, l2.l1[2].R[1:3]);
annotation(
Icon(graphics = {Rectangle(fillColor = {252, 233, 79}, fillPattern = FillPattern.Sphere, extent = {{-100, 100}, {100, -100}})}));end M2;
model M3
"Model with level 3 connector"
Modelica.Blocks.Sources.Constant[14] C(k = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14});
L3 l3(a={2,3}, r={2, 3, 2, 3, 4}, start={1,3}, stop={2,5});
equation
connect(C[1:2].y, l3.l2[1].l1[1].R[1:2]);
connect(C[3:5].y, l3.l2[1].l1[2].R[1:3]);
connect(C[6:7].y, l3.l2[2].l1[1].R[1:2]);
connect(C[8:10].y, l3.l2[2].l1[2].R[1:3]);
connect(C[11:14].y, l3.l2[3].l1[2].R[1:4]);
annotation(
Icon(graphics = {Rectangle(fillColor = {138, 226, 52}, fillPattern = FillPattern.Sphere, extent = {{-100, 100}, {100, -100}})}));end M3;
end conn;
I managed to get it work following the suggestion here
Here is my solution, model M3 runs without error.
within CASP.Experiment;
package conn1
connector L1
"Level 1 connector"
parameter Integer n;
Modelica.Blocks.Interfaces.RealOutput R[n];
annotation(
Diagram(graphics = {Ellipse(fillColor = {239, 41, 41}, fillPattern = FillPattern.Sphere, extent = {{-60, 60}, {60, -60}})}),
Icon(graphics = {Ellipse(fillColor = {239, 41, 41}, fillPattern = FillPattern.Sphere, extent = {{-60, 60}, {60, -60}})}));
end L1;
connector L2
"Level 2 connector"
parameter R3 r3;
L1 l1[r3.n](n=r3.r);
annotation(
Icon(graphics = {Ellipse(fillColor = {252, 233, 79}, fillPattern = FillPattern.Sphere, extent = {{-60, 60}, {60, -60}})}),
Diagram(graphics = {Ellipse(fillColor = {252, 233, 79}, fillPattern = FillPattern.Sphere, extent = {{-60, 60}, {60, -60}})}));
end L2;
record R3
parameter Integer n;
Integer r[n];
end R3;
connector L3
"Level 3 connector"
parameter R3 r3[:];
// how to construct connector to get
// l3.l2[1] = L2(r={2, 3})
// l3.l2[2] = L2(r={2, 3, 4})
L2 l2[size(r3, 1)](r3=r3);
annotation(
Diagram(graphics = {Ellipse(fillColor = {138, 226, 52}, fillPattern = FillPattern.Sphere, extent = {{-60, 60}, {60, -60}})}),
Icon(graphics = {Ellipse(fillColor = {138, 226, 52}, fillPattern = FillPattern.Sphere, extent = {{-60, 60}, {60, -60}})}));
end L3;
model M1
"Model with level 1 connector"
Modelica.Blocks.Sources.Constant[5] C(k = {1, 2, 3, 4, 5});
L1 l1(n=5);
equation
connect(C.y, l1.R);
annotation(
Icon(graphics = {Rectangle(fillColor = {239, 41, 41}, fillPattern = FillPattern.Sphere, extent = {{-100, 100}, {100, -100}})}));
end M1;
model M2
"Model with level 2 connector"
Modelica.Blocks.Sources.Constant[5] C(k = {1, 2, 3, 4, 5});
L2 l2(r={2, 3});
equation
connect(C[1:2].y, l2.l1[1].R[1:2]);
connect(C[3:5].y, l2.l1[2].R[1:3]);
annotation(
Icon(graphics = {Rectangle(fillColor = {252, 233, 79}, fillPattern = FillPattern.Sphere, extent = {{-100, 100}, {100, -100}})}));
end M2;
model M3
"Model with level 3 connector"
Modelica.Blocks.Sources.Constant[14] C(k = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14});
L3 l3(r3={R3(n=2, r={2, 3}), R3(n=3, r={2, 3, 4})});
equation
connect(C[1:2].y, l3.l2[1].l1[1].R[1:2]);
connect(C[3:5].y, l3.l2[1].l1[2].R[1:3]);
connect(C[6:7].y, l3.l2[2].l1[1].R[1:2]);
connect(C[8:10].y, l3.l2[2].l1[2].R[1:3]);
connect(C[11:14].y, l3.l2[2].l1[3].R[1:4]);
annotation(
Icon(graphics = {Rectangle(fillColor = {138, 226, 52}, fillPattern = FillPattern.Sphere, extent = {{-100, 100}, {100, -100}})}));
end M3;
end conn1;

Modelica - Internal error for overconstrained stewart platform model

OpenModelica v1.17.0 (64-bit)
OMSimulator v2.0.0.post284-gc8ec782-mingw
Modelica Standard Library 3.2.3
Hello,
I'm currently working on the implementation of a dynamic model of a Stewart Platform in OpenModelica similar to the one in https://www.xarg.org/paper/inverse-kine … -platform/ (6RSS parallel robot) and apparently, I'm not able to connect multiple legs to the same platform due to the following error:
[1] 13:08:36 Translation Error
Internal error It is not possible to select continuous time states because Number of Equations 18 greater than number of States 17 to select from.
[2] 13:08:36 Translation Error
Internal error - IndexReduction.dynamicStateSelectionWork failed!
From what I have seen in the documentation of Modelica, this might be caused by some loop in the spanning tree generated during the translation phase of the model where some non-flow equations became dependent on each other resulting in an overconstrained (even if still solvable) system. It follows the source code of the package that I have created in which there are present a base, a platform, and only two RSS legs which create the issue.
package sixRSS_parallelRobot
model platform
import Modelica.SIunits;
import Modelica.Math;
constant SIunits.Length l = 0.7;
constant StateSelect stateSelect = StateSelect.prefer annotation(
Dialog(tab = "Advanced"));
final constant Real pi = 2 * Modelica.Math.asin(1.0);
parameter Boolean useQuat = false;
Modelica.Mechanics.MultiBody.Parts.Body body(enforceStates = stateSelect == StateSelect.always,m = 1, r_0(each fixed = true, start = {0, 0.5, 0}), r_CM = {0, 0, 0}, useQuaternions = useQuat, v_0(each fixed = true, start = {0, 0, 0}), w_a(each fixed = true)) annotation(
Placement(visible = true, transformation(origin = {70, 2}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.Mechanics.MultiBody.Parts.FixedTranslation fixedTranslation1(r = {l * cos(0 * (pi / 180) + (-5) * (pi / 180)), 0, l * sin(0 * (pi / 180) + (-5) * (pi / 180))}) annotation(
Placement(visible = true, transformation(origin = {-18, 68}, extent = {{-10, -10}, {10, 10}}, rotation = 180)));
Modelica.Mechanics.MultiBody.Parts.FixedTranslation fixedTranslation2(r = {l * cos(0 * (pi / 180) + 5 * (pi / 180)), 0, l * sin(0 * (pi / 180) + 5 * (pi / 180))}) annotation(
Placement(visible = true, transformation(origin = {-14, 50}, extent = {{-10, -10}, {10, 10}}, rotation = 180)));
Modelica.Mechanics.MultiBody.Parts.FixedTranslation fixedTranslation3(r = {l * cos(120 * (pi / 180) + (-5) * (pi / 180)), 0, l * sin(120 * (pi / 180) + (-5) * (pi / 180))}) annotation(
Placement(visible = true, transformation(origin = {-18, 24}, extent = {{-10, -10}, {10, 10}}, rotation = 180)));
Modelica.Mechanics.MultiBody.Parts.FixedTranslation fixedTranslation4(r = {l * cos(120 * (pi / 180) + 5 * (pi / 180)), 0, l * sin(120 * (pi / 180) + 5 * (pi / 180))}) annotation(
Placement(visible = true, transformation(origin = {-12, 2}, extent = {{-10, -10}, {10, 10}}, rotation = 180)));
Modelica.Mechanics.MultiBody.Parts.FixedTranslation fixedTranslation5(r = {l * cos(240 * (pi / 180) + (-5) * (pi / 180)), 0, l * sin(240 * (pi / 180) + (-5) * (pi / 180))}) annotation(
Placement(visible = true, transformation(origin = {-14, -24}, extent = {{-10, -10}, {10, 10}}, rotation = 180)));
Modelica.Mechanics.MultiBody.Parts.FixedTranslation fixedTranslation6(r = {l * cos(240 * (pi / 180) + 5 * (pi / 180)), 0, l * sin(240 * (pi / 180) + 5 * (pi / 180))}) annotation(
Placement(visible = true, transformation(origin = {-16, -46}, extent = {{-10, -10}, {10, 10}}, rotation = 180)));
//outer Modelica.Mechanics.MultiBody.World world;
Modelica.Mechanics.MultiBody.Interfaces.Frame_b frame_b[6] annotation(
Placement(visible = true, transformation(origin = {-76, 10}, extent = {{-16, -16}, {16, 16}}, rotation = 0), iconTransformation(origin = {-100, 6}, extent = {{-16, -16}, {16, 16}}, rotation = 0)));
equation
connect(fixedTranslation1.frame_a, body.frame_a) annotation(
Line(points = {{-8, 68}, {30, 68}, {30, 2}, {60, 2}}, color = {95, 95, 95}));
connect(fixedTranslation2.frame_a, body.frame_a) annotation(
Line(points = {{-4, 50}, {30, 50}, {30, 2}, {60, 2}}, color = {95, 95, 95}));
connect(fixedTranslation3.frame_a, body.frame_a) annotation(
Line(points = {{-8, 24}, {30, 24}, {30, 2}, {60, 2}}));
connect(fixedTranslation4.frame_a, body.frame_a) annotation(
Line(points = {{-2, 2}, {60, 2}}));
connect(fixedTranslation5.frame_a, body.frame_a) annotation(
Line(points = {{-4, -24}, {30, -24}, {30, 2}, {60, 2}}, color = {95, 95, 95}));
connect(fixedTranslation6.frame_a, body.frame_a) annotation(
Line(points = {{-6, -46}, {30, -46}, {30, 2}, {60, 2}}, color = {95, 95, 95}));
connect(fixedTranslation2.frame_b, frame_b[2]) annotation(
Line(points = {{-24, 50}, {-56, 50}, {-56, 10}, {-76, 10}}, color = {95, 95, 95}));
connect(fixedTranslation3.frame_b, frame_b[3]) annotation(
Line(points = {{-28, 24}, {-56, 24}, {-56, 10}, {-76, 10}}, color = {95, 95, 95}));
connect(fixedTranslation4.frame_b, frame_b[4]) annotation(
Line(points = {{-22, 2}, {-56, 2}, {-56, 10}, {-76, 10}}, color = {95, 95, 95}));
connect(fixedTranslation5.frame_b, frame_b[5]) annotation(
Line(points = {{-24, -24}, {-56, -24}, {-56, 10}, {-76, 10}}, color = {95, 95, 95}));
connect(fixedTranslation6.frame_b, frame_b[6]) annotation(
Line(points = {{-26, -46}, {-56, -46}, {-56, 10}, {-76, 10}}, color = {95, 95, 95}));
connect(fixedTranslation1.frame_b, frame_b[1]) annotation(
Line(points = {{-28, 68}, {-56, 68}, {-56, 10}, {-76, 10}}, color = {95, 95, 95}));
annotation(
uses(Modelica(version = "3.2.3")));
end platform;
model base
import Modelica.SIunits;
import Modelica.Math;
constant SIunits.Length l = 0.7;
constant StateSelect stateSelect = StateSelect.prefer annotation(
Dialog(tab = "Advanced"));
final constant Real pi = 2 * Modelica.Math.asin(1.0);
parameter Boolean useQuat = false;
Modelica.Mechanics.MultiBody.Parts.Fixed fixed annotation(
Placement(visible = true, transformation(origin = {-16, 12}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.Mechanics.MultiBody.Parts.Fixed fixed1(r = {l * cos(0 * (pi / 180) + (-5) * (pi / 180)), 0, l * sin(0 * (pi / 180) + (-5) * (pi / 180))}) annotation(
Placement(visible = true, transformation(origin = {54, -2}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.Mechanics.MultiBody.Parts.Fixed fixed2(r = {l * cos(0 * (pi / 180) + 5 * (pi / 180)), 0, l * sin(0 * (pi / 180) + 5 * (pi / 180))}) annotation(
Placement(visible = true, transformation(origin = {52, 30}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.Mechanics.MultiBody.Parts.Fixed fixed3(r = {l * cos(120 * (pi / 180) + (-5) * (pi / 180)), 0, l * sin(120 * (pi / 180) + (-5) * (pi / 180))}) annotation(
Placement(visible = true, transformation(origin = {-46, 76}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.Mechanics.MultiBody.Parts.Fixed fixed4(r = {l * cos(120 * (pi / 180) + 5 * (pi / 180)), 0, l * sin(120 * (pi / 180) + 5 * (pi / 180))}) annotation(
Placement(visible = true, transformation(origin = {-74, 50}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.Mechanics.MultiBody.Parts.Fixed fixed5(r = {l * cos(240 * (pi / 180) + (-5) * (pi / 180)), 0, l * sin(240 * (pi / 180) + (-5) * (pi / 180))}) annotation(
Placement(visible = true, transformation(origin = {-68, -26}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.Mechanics.MultiBody.Parts.Fixed fixed6(r = {l * cos(240 * (pi / 180) + 5 * (pi / 180)), 0, l * sin(240 * (pi / 180) + 5 * (pi / 180))}) annotation(
Placement(visible = true, transformation(origin = {-44, -68}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.Mechanics.MultiBody.Parts.Body body(enforceStates = stateSelect == StateSelect.always,m = 5, r_CM = {0, 0, 0}, useQuaternions = useQuat) annotation(
Placement(visible = true, transformation(origin = {12, 12}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
outer Modelica.Mechanics.MultiBody.World world;
Modelica.Mechanics.MultiBody.Interfaces.Frame_a frame_a[6] annotation(
Placement(visible = true, transformation(origin = {104, 16}, extent = {{-16, -16}, {16, 16}}, rotation = 0), iconTransformation(origin = {108, 0}, extent = {{-16, -16}, {16, 16}}, rotation = 0)));
equation
connect(fixed.frame_b, body.frame_a) annotation(
Line(points = {{-6, 12}, {2, 12}}, color = {95, 95, 95}));
connect(fixed1.frame_b, frame_a[1]) annotation(
Line(points = {{64, -2}, {86, -2}, {86, 16}, {104, 16}}));
connect(fixed2.frame_b, frame_a[2]) annotation(
Line(points = {{62, 30}, {86, 30}, {86, 16}, {104, 16}}, color = {95, 95, 95}));
connect(fixed3.frame_b, frame_a[3]) annotation(
Line(points = {{-36, 76}, {86, 76}, {86, 16}, {104, 16}}));
connect(fixed4.frame_b, frame_a[4]) annotation(
Line(points = {{-64, 50}, {86, 50}, {86, 16}, {104, 16}}));
connect(fixed5.frame_b, frame_a[5]) annotation(
Line(points = {{-58, -26}, {86, -26}, {86, 16}, {104, 16}}));
connect(fixed6.frame_b, frame_a[6]) annotation(
Line(points = {{-34, -68}, {86, -68}, {86, 16}, {104, 16}}));
annotation(
uses(Modelica(version = "3.2.3")));
end base;
model fullmodel
inner Modelica.Mechanics.MultiBody.World world annotation(
Placement(visible = true, transformation(origin = {-68, 14}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
sixRSS_parallelRobot.platform platform(useQuat = true) annotation(
Placement(visible = true, transformation(origin = {106, 12}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
sixRSS_parallelRobot.base base(useQuat = true) annotation(
Placement(visible = true, transformation(origin = {-26, 14}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.Mechanics.MultiBody.Joints.Revolute revolute(n = {1, 0, 0}, phi(displayUnit = "rad")) annotation(
Placement(visible = true, transformation(origin = {-1, 29}, extent = {{-7, -7}, {7, 7}}, rotation = 0)));
Modelica.Mechanics.MultiBody.Parts.BodyShape bodyShape(m = 0.01, r = {0, 0, -0.2}, r_CM = {0, 0, -0.1}) annotation(
Placement(visible = true, transformation(origin = {19, 29}, extent = {{-7, -7}, {7, 7}}, rotation = 0)));
Modelica.Mechanics.MultiBody.Joints.Spherical spherical annotation(
Placement(visible = true, transformation(origin = {35, 29}, extent = {{-7, -7}, {7, 7}}, rotation = 0)));
Modelica.Mechanics.MultiBody.Parts.BodyShape bodyShape1(m = 0.002, r = {0, 0.5, 0.2}, r_CM = {0, 0.25, 0.1}) annotation(
Placement(visible = true, transformation(origin = {51, 29}, extent = {{-7, -7}, {7, 7}}, rotation = 0)));
Modelica.Mechanics.MultiBody.Joints.Spherical spherical1 annotation(
Placement(visible = true, transformation(origin = {71, 29}, extent = {{-7, -7}, {7, 7}}, rotation = 0)));
Modelica.Mechanics.MultiBody.Joints.Revolute revolute1(n = {1, 0, 0}, phi(displayUnit = "rad")) annotation(
Placement(visible = true, transformation(origin = {1, -1}, extent = {{-7, -7}, {7, 7}}, rotation = 0)));
Modelica.Mechanics.MultiBody.Parts.BodyShape bodyShape2(m = 0.01, r = {0, 0, 0.2}, r_CM = {0, 0, 0.1}) annotation(
Placement(visible = true, transformation(origin = {21, -1}, extent = {{-7, -7}, {7, 7}}, rotation = 0)));
Modelica.Mechanics.MultiBody.Joints.Spherical spherical2 annotation(
Placement(visible = true, transformation(origin = {37, -1}, extent = {{-7, -7}, {7, 7}}, rotation = 0)));
Modelica.Mechanics.MultiBody.Parts.BodyShape bodyShape3(m = 0.002, r = {0, 0.5, -0.2}, r_CM = {0, 0.25, -0.1}) annotation(
Placement(visible = true, transformation(origin = {53, -1}, extent = {{-7, -7}, {7, 7}}, rotation = 0)));
Modelica.Mechanics.MultiBody.Joints.Spherical spherical3 annotation(
Placement(visible = true, transformation(origin = {73, -1}, extent = {{-7, -7}, {7, 7}}, rotation = 0)));
equation
connect(revolute.frame_b, bodyShape.frame_a) annotation(
Line(points = {{6, 29}, {12, 29}}));
connect(bodyShape.frame_b, spherical.frame_a) annotation(
Line(points = {{26, 29}, {28, 29}}, color = {95, 95, 95}));
connect(spherical.frame_b, bodyShape1.frame_a) annotation(
Line(points = {{42, 29}, {44, 29}}, color = {95, 95, 95}));
connect(bodyShape1.frame_b, spherical1.frame_a) annotation(
Line(points = {{58, 30}, {64, 30}}));
connect(revolute.frame_a, base.frame_a[1]) annotation(
Line(points = {{-8, 30}, {-10, 30}, {-10, 14}, {-16, 14}}));
connect(spherical1.frame_b, platform.frame_b[1]) annotation(
Line(points = {{78, 30}, {88, 30}, {88, 12}, {96, 12}}, color = {95, 95, 95}));
connect(base.frame_a[2], revolute1.frame_a) annotation(
Line(points = {{-16, 14}, {-10, 14}, {-10, 0}, {-6, 0}}, color = {95, 95, 95}));
connect(revolute1.frame_b, bodyShape2.frame_a) annotation(
Line(points = {{8, 0}, {14, 0}}, color = {95, 95, 95}));
connect(bodyShape2.frame_b, spherical2.frame_a) annotation(
Line(points = {{28, 0}, {30, 0}}, color = {95, 95, 95}));
connect(spherical2.frame_b, bodyShape3.frame_a) annotation(
Line(points = {{44, 0}, {46, 0}}, color = {95, 95, 95}));
connect(bodyShape3.frame_b, spherical3.frame_a) annotation(
Line(points = {{60, 0}, {66, 0}}));
connect(spherical3.frame_b, platform.frame_b[2]) annotation(
Line(points = {{80, 0}, {88, 0}, {88, 12}, {96, 12}}));
end fullmodel;
annotation(
uses(Modelica(version = "3.2.3")));
end sixRSS_parallelRobot;
Since I'm new to Modelica, I think I'm missing some basic concepts of modelling multibody mechanics especially when kinematics loops take place. I've already made some tests on the planar loop fourbar example in the Modelica library but I think this is something different. Is there a way to solve this error and finally obtain a working model of the 6RSS parallel robot?
Thank you in advance for your help!
Not actually an answer, I know, but with a comment only, adding the gif below wouldn't be possible.
The model works in Dymola 2022 (after converting to MSL 4.0.0) and Dymola 2020x (with MSL 3.2.3) without any important warning. So, given the result below is what you would expect, then there is no fundamental error within the model. The resulting animation looks like this:
Dymola does dynamic state selection for the model - I'm not sure whether OpenModelica is able to do that as well. Generally I can't really help with OpenModelica unfortunately. But Probably this is already of help for you...

How can I access multiphase connectors in modelica? (FFT model)

I managed to make a FFT model to analyze the frequency of a single phase sine wave voltage source.
Now I'm trying to apply my FFT model to the 3-phase domain to analyze the frequencies of a 3-phase voltage source. This looks like the following:
within MasterarbeitPWM.FrequenzAnalysator;
model FFTmultiphaseTest
MasterarbeitPWM.FrequenzAnalysator.FFTmultiphase fFTmultiphase1 annotation(
Placement(visible = true, transformation(origin = {188, 110}, extent = {{-38, -38}, {38, 38}}, rotation = 0)));
Modelica.Electrical.MultiPhase.Sources.SineVoltage sineVoltage1(V = fill(5, 3), freqHz = fill(2, 3), m = 3) annotation(
Placement(visible = true, transformation(origin = {121, 22}, extent = {{-24, -27}, {24, 27}}, rotation = -90)));
Modelica.Electrical.Analog.Basic.Ground ground1 annotation(
Placement(visible = true, transformation(origin = {121, -71}, extent = {{-19, -19}, {19, 19}}, rotation = 0)));
Modelica.Electrical.MultiPhase.Basic.Star star1 annotation(
Placement(visible = true, transformation(origin = {120, -32}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
equation
connect(sineVoltage1.plug_p, fFTmultiphase1.positivePlug1) annotation(
Line(points = {{122, 46}, {120, 46}, {120, 110}, {146, 110}, {146, 110}}, color = {0, 0, 255}));
connect(star1.plug_p, sineVoltage1.plug_n) annotation(
Line(points = {{120, -22}, {123, -22}, {123, -18}, {120, -18}, {120, 2.98024e-07}, {122, 2.98024e-07}, {122, -4}, {124, -4}, {124, -2}, {122, -2}}, color = {0, 0, 255}));
connect(ground1.p, star1.pin_n) annotation(
Line(points = {{121, -52}, {119, -52}, {119, -42}, {119, -42}}, color = {0, 0, 255}));
annotation(
Diagram(coordinateSystem(extent = {{-300, -200}, {300, 200}})),
Icon(coordinateSystem(extent = {{-300, -200}, {300, 200}})),
__OpenModelica_commandLineOptions = "");end FFTmultiphaseTest;
When I hit "check model" I don't get any errors but when I try to simulate, it gives me the error
The initialization problem is inconsistent due to the following equation: 0 != 4.33013 = $START.fFTmultiphase1.y[2] - fFTmultiphase1.y[2]
Error in initialization. Storing results and exiting.<br>
Use -lv=LOG_INIT -w for more information.
Simulation process failed. Exited with code -1.
and warnings like:
[1] 13:55:08 Translation Warning
It was not possible to determine if the initialization problem is consistent, because of not evaluable parameters/start values during compile time: fFTmultiphase1.y[1] = $START.fFTmultiphase1.y[1] (sineVoltage1.sineVoltage[1].signalSource.offset + (if time < sineVoltage1.sineVoltage[1].signalSource.startTime then 0.0 else sineVoltage1.sineVoltage[1].signalSource.amplitude * sin(6.283185307179586 * sineVoltage1.sineVoltage[1].signalSource.freqHz * (time - sineVoltage1.sineVoltage[1].signalSource.startTime) + sineVoltage1.sineVoltage[1].signalSource.phase)) = $START.fFTmultiphase1.y[1])
This is the model of my FFT:
within MasterarbeitPWM.FrequenzAnalysator;
block FFTmultiphase
import Modelica.Constants.{pi};
import Modelica.Math.FastFourierTransform.*;
import Modelica.SIunits.*;
parameter Frequency f_max = 5 "Maximum frequency of interest";
parameter Frequency f_res = 1 "Frequency resolution";
final parameter Integer ns = realFFTsamplePoints(f_max, f_res, f_max_factor = 5) "Number of samples";
final parameter Integer nf = div(ns, 2) + 1 "Number of frequency points";
final parameter Integer nfi = max(1, min(integer(ceil(f_max / f_res)) + 1, nf));
final parameter Frequency f_i[nfi](each fixed = false) "FFT frequencies of interested frequency points";
parameter Time samplePeriod = 1 / (2 * f_res * div(ns, 2));
output Integer info(start = 0, fixed = true) "Information flag from FFT computation";
Integer iTick(start = 0, fixed = true);
discrete Real Buf[ns](start = zeros(ns), each fixed = true) "Input buffer";
Real A_i[nfi](start = zeros(nfi), each fixed = true) "FFT amplitudes";
Real Phi_i[nfi](start = zeros(nfi), each fixed = true) "FFT phases";
Real y[3](start = fill(0, 3), each fixed = true, each unit = "V");
// "Signal from which FFT is computed";
Modelica.Electrical.MultiPhase.Interfaces.PositivePlug positivePlug1 annotation(
Placement(visible = true, transformation(origin = {-114, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {-110, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
initial equation
for i in 1:nfi loop
f_i[i] = (i - 1) * f_res;
end for;
equation
y = positivePlug1.pin.v;
positivePlug1.pin[1].i = 0.0;
positivePlug1.pin[2].i = 0.0;
positivePlug1.pin[3].i = 0.0;
algorithm
when sample(0, samplePeriod) then
iTick := iTick + 1;
if iTick <= ns then
Buf[iTick] := y[1];
end if;
if iTick == ns then
(info, A_i, Phi_i) := realFFT(Buf, nfi);
end if;
end when;
annotation(
Icon(graphics = {Text(origin = {-42, 62}, extent = {{110, -78}, {-30, 18}}, textString = "FFT"), Rectangle(origin = {0, -79}, fillPattern = FillPattern.Solid, extent = {{-80, -1}, {80, 1}}), Rectangle(origin = {-79, -49}, fillPattern = FillPattern.Solid, extent = {{-1, -29}, {1, 29}}), Polygon(origin = {-79, -15}, fillPattern = FillPattern.Solid, points = {{0, -5}, {-6, -5}, {0, 5}, {6, -5}, {6, -5}, {0, -5}}), Polygon(origin = {85, -79}, rotation = -90, fillPattern = FillPattern.Solid, points = {{0, -5}, {-6, -5}, {0, 5}, {6, -5}, {6, -5}, {0, -5}}), Rectangle(origin = {-59, -65}, fillPattern = FillPattern.Solid, extent = {{-1, 23}, {1, -15}}), Ellipse(origin = {-59, -39}, fillPattern = FillPattern.Solid, extent = {{-3, 3}, {3, -3}}, endAngle = 360), Ellipse(origin = {-49, -61}, fillPattern = FillPattern.Solid, extent = {{-3, 3}, {3, -3}}, endAngle = 360), Ellipse(origin = {-19, -53}, fillPattern = FillPattern.Solid, extent = {{-3, 3}, {3, -3}}, endAngle = 360), Ellipse(origin = {25, -67}, fillPattern = FillPattern.Solid, extent = {{-3, 3}, {3, -3}}, endAngle = 360), Ellipse(origin = {31, -49}, fillPattern = FillPattern.Solid, extent = {{-3, 3}, {3, -3}}, endAngle = 360), Rectangle(origin = {-49, -65}, fillPattern = FillPattern.Solid, extent = {{-1, 1}, {1, -15}}), Rectangle(origin = {31, -65}, fillPattern = FillPattern.Solid, extent = {{-1, 15}, {1, -15}}), Rectangle(origin = {-19, -63}, fillPattern = FillPattern.Solid, extent = {{-1, 7}, {1, -15}}), Rectangle(origin = {25, -63}, fillPattern = FillPattern.Solid, extent = {{-1, -5}, {1, -15}}), Ellipse(origin = {-67, -61}, fillPattern = FillPattern.Solid, extent = {{-3, 3}, {3, -3}}, endAngle = 360), Rectangle(origin = {-67, -63}, fillPattern = FillPattern.Solid, extent = {{-1, 1}, {1, -15}}), Rectangle(origin = {37, -63}, fillPattern = FillPattern.Solid, extent = {{-1, -5}, {1, -15}}), Ellipse(origin = {37, -67}, fillPattern = FillPattern.Solid, extent = {{-3, 3}, {3, -3}}, endAngle = 360), Line(points = {{-100, 100}, {100, 100}, {100, -100}, {-100, -100}, {-100, 100}, {-100, 100}}, thickness = 0.5)}),
Diagram,
__OpenModelica_commandLineOptions = "");
end FFTmultiphase;
As I sad my single phase example works (with some warnings).
I guess I'm doing something wrong with the connection between the voltage source and my FFT model, but I can't figure out what it is.
Can someone may explain to me what I'm doing wrong and how to fix it?
I'm really new to Modelica/OpenModelica so please excuse if it is a silly question.
Many thanks in advance!
Some things I observed (using Dymola) that could cause some troubles:
The block FFTmultiphase has a Multiphase Interface, which is usually not done in Modelica. Blocks only have causal in-/outputs. I've changed the class from a block to a model. You could as well use a Real input to the model using a sensor to measure the voltage.
Your initial set of equations seem to be over-determined due to the fixed=true in Real y[3](start = fill(0, 3), each fixed = true, each unit = "V");. I would try to remove each fixed = true.
The second seems likelier to cause the problems you describe.
The result seems reasonable then giving A_i = {0,0,4.87,0,0,0} (although I guess it should be 5 for the 3rd entry).

Fixing illogical "incompatibility components" error copied from OpenModelica Library

I am trying to model and replicate the "Open Brayton Power Cycle" from the OpenModelica Library and have come across an error message that makes little sense. The error message is the result of incompatibility between sourceMassflow.mo and CombustionChamber.mo, all taken from the modelica library and connected in the same fashion as the library Brayton example has been done.
This error has occurred after completely replicating the "Brayton Power Cycle - Open" from the modelica library.
This is the error I am receiving. This message almost proves that the two components are compatible with one another however I cannot figure out the reason why they are "not working" together.
[11] 14:18:40 Translation Error
[BraytonCycle_First: 49:3-50:84]: Incompatible components in connect statement: connect(sourceMassFlow1.flange, combustionChamber1.inf)
- sourceMassFlow1.flange has components {C_outflow, Xi_outflow, h_outflow, m_flow, p}
- combustionChamber1.inf has components {C_outflow, Xi_outflow, h_outflow, m_flow, p}
I copied all of the library's component parameters into my model and expected this to solve the issue. Nothing I have done fixes this issue, where it seems that these models would be compatible due to the error message above.
Any help or advice would be greatly appreciated.
This model compiles but has issues with simulation. Maybe you can fix those. I changed all the redeclares to use ThermoPower.Media.* mediums.
model BraytonCycleLibraryReplica "Brayton Cycle iterations with re-declared mediums and copied values from Library Plant"
//Figure out the importance of table values//
parameter Real tableEtaC[6, 4]=[0, 95, 100, 105; 1, 82.5e-2, 81e-2,
80.5e-2; 2, 84e-2, 82.9e-2, 82e-2; 3, 83.2e-2, 82.2e-2, 81.5e-2; 4,
82.5e-2, 81.2e-2, 79e-2; 5, 79.5e-2, 78e-2, 76.5e-2];
parameter Real tablePhicC[6, 4]=[0, 95, 100, 105; 1, 38.3e-3, 43e-3,
46.8e-3; 2, 39.3e-3, 43.8e-3, 47.9e-3; 3, 40.6e-3, 45.2e-3, 48.4e-3;
4, 41.6e-3, 46.1e-3, 48.9e-3; 5, 42.3e-3, 46.6e-3, 49.3e-3];
parameter Real tablePR[6, 4]=[0, 95, 100, 105; 1, 22.6, 27, 32; 2, 22,
26.6, 30.8; 3, 20.8, 25.5, 29; 4, 19, 24.3, 27.1; 5, 17, 21.5, 24.2];
parameter Real tablePhicT[5, 4]=[1, 90, 100, 110; 2.36, 4.68e-3, 4.68e-3,
4.68e-3; 2.88, 4.68e-3, 4.68e-3, 4.68e-3; 3.56, 4.68e-3, 4.68e-3,
4.68e-3; 4.46, 4.68e-3, 4.68e-3, 4.68e-3];
parameter Real tableEtaT[5, 4]=[1, 90, 100, 110; 2.36, 89e-2, 89.5e-2,
89.3e-2; 2.88, 90e-2, 90.6e-2, 90.5e-2; 3.56, 90.5e-2, 90.6e-2,
90.5e-2; 4.46, 90.2e-2, 90.3e-2, 90e-2];
ThermoPower.Gas.Turbine turbine1(
redeclare package Medium = ThermoPower.Media.FlueGas,
Ndesign = 157.08,
Table = ThermoPower.Choices.TurboMachinery.TableTypes.matrix,
Tdes_in = 1400,
Tstart_in = 1370,
Tstart_out = 800,
pstart_in = 7.85e5,
pstart_out = 1.52e5, tableEta = tableEtaT, tablePhic = tablePhicT)
annotation(
Placement(visible = true, transformation(origin = {40, -8}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
ThermoPower.Gas.Compressor compressor1(
redeclare package Medium = ThermoPower.Media.Air,
Ndesign = 157.08,
Table = ThermoPower.Choices.TurboMachinery.TableTypes.matrix,
Tdes_in = 244.4,
Tstart_in = 244.4,
Tstart_out = 600.4,
explicitIsentropicEnthalpy = true,
pstart_in = 0.343e5,
pstart_out = 8.3e5, tableEta = tableEtaC, tablePR = tablePR, tablePhic = tablePhicC)
annotation(
Placement(visible = true, transformation(origin = {-40, -8}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
ThermoPower.Gas.CombustionChamber combustionChamber1(
Cm = 1,
HH = 41.6e6,
S = 0.05,
Tstart = 1370,
V = 0.05,
gamma = 1,
initOpt = ThermoPower.Choices.Init.Options.steadyState,
pstart = 8.11e5)
annotation(
Placement(visible = true, transformation(origin = {0, 30}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
ThermoPower.Gas.PressDrop pressDrop1(
redeclare package Medium = ThermoPower.Media.Air, A = 1, FFtype = ThermoPower.Choices.PressDrop.FFtypes.OpPoint, Tstart = 600, dpnom = 19000, pstart = 8.3e5, rhonom = 4.7, wnom = 100)
annotation(
Placement(visible = true, transformation(origin = {-32, 14}, extent = {{-6, -6}, {6, 6}}, rotation = -90)));
ThermoPower.Gas.PressDrop pressDrop2(
redeclare package Medium = ThermoPower.Media.FlueGas,
FFtype = ThermoPower.Choices.PressDrop.FFtypes.OpPoint,
Tstart = 1370,
dpnom = 26000,
pstart = 811000,
rhonom = 2,
wnom = 102)
annotation(
Placement(visible = true, transformation(origin = {32, 14}, extent = {{-6, -6}, {6, 6}}, rotation = -90)));
ThermoPower.Gas.SourceMassFlow sourceMassFlow1(
redeclare package Medium = ThermoPower.Media.NaturalGas, T = 300, p0 = 811000, use_in_w0 = true, w0 = 2.02)
annotation(
Placement(visible = true, transformation(origin = {-44, 40}, extent = {{-6, -6}, {6, 6}}, rotation = 0)));
ThermoPower.Gas.SourcePressure sourcePressure1(
redeclare package Medium = ThermoPower.Media.Air,
T = 244.4,
p0 = 34300)
annotation(
Placement(visible = true, transformation(origin = {-92, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
ThermoPower.PowerPlants.HRSG.Components.StateReader_gas stateReader_gas1(
redeclare package Medium = ThermoPower.Media.Air)
annotation(
Placement(visible = true, transformation(origin = {-22, 30}, extent = {{-8, -8}, {8, 8}}, rotation = 0)));
ThermoPower.PowerPlants.HRSG.Components.StateReader_gas stateReader_gas2(
redeclare package Medium = ThermoPower.Media.FlueGas)
annotation(
Placement(visible = true, transformation(origin = {22, 30}, extent = {{-8, -8}, {8, 8}}, rotation = 0)));
Modelica.Blocks.Continuous.FirstOrder firstOrder1(
T = 4,
initType = Modelica.Blocks.Types.Init.SteadyState,
y_start = 500)
annotation(
Placement(visible = true, transformation(origin = {-85, 51}, extent = {{-5, -5}, {5, 5}}, rotation = 0)));
Modelica.Blocks.Interfaces.RealInput FuelFlowRate
annotation(
Placement(visible = true, transformation(origin = {-142, 18}, extent = {{-20, -20}, {20, 20}}, rotation = 0), iconTransformation(origin = {-142, 18}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
ThermoPower.Gas.SinkPressure sinkPressure1(
redeclare package Medium = ThermoPower.Media.FlueGas,
T = 800,
p0 = 1.52e5)
annotation(
Placement(visible = true, transformation(origin = {66, 20}, extent = {{-6, -6}, {6, 6}}, rotation = 0)));
Modelica.Mechanics.Rotational.Sensors.PowerSensor powerSensor1
annotation(
Placement(visible = true, transformation(origin = {60, -8}, extent = {{-6, -6}, {6, 6}}, rotation = 0)));
ThermoPower.Electrical.Generator generator1(
J = 30,
initOpt = ThermoPower.Choices.Init.Options.steadyState,
shaft(phi(start=0, fixed=true)))
annotation(
Placement(visible = true, transformation(origin = {80, -8}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.Blocks.Continuous.FirstOrder firstOrder2(
T = 1,
initType = Modelica.Blocks.Types.Init.SteadyState,
k = 1,
y_start = 56.8e6)
annotation(
Placement(visible = true, transformation(origin = {80, -36}, extent = {{-6, -6}, {6, 6}}, rotation = 0)));
Modelica.Blocks.Interfaces.RealOutput GeneratedPower
annotation(
Placement(visible = true, transformation(origin = {106, 16}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {106, 16}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
ThermoPower.Electrical.NetworkGrid_Pmax networkGrid_Pmax1(
J = 30000,
Pmax = 10e6,
deltaStart = 0.4,
initOpt = ThermoPower.Choices.Init.Options.steadyState)
annotation(
Placement(visible = true, transformation(origin = {106, -8}, extent = {{-8, -8}, {8, 8}}, rotation = 0)));
inner ThermoPower.System system annotation(
Placement(visible = true, transformation(origin = {-130, 70}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
equation
connect(firstOrder2.y, GeneratedPower) annotation(
Line(points = {{86, -36}, {92, -36}, {92, 16}, {106, 16}, {106, 16}}, color = {0, 0, 127}));
connect(powerSensor1.power, firstOrder2.u) annotation(
Line(points = {{56, -14}, {56, -36}, {73, -36}}, color = {0, 0, 127}));
connect(powerSensor1.flange_b, generator1.shaft) annotation(
Line(points = {{66, -8}, {72, -8}, {72, -8}, {72, -8}}));
connect(turbine1.shaft_b, powerSensor1.flange_a) annotation(
Line(points = {{46, -8}, {54, -8}, {54, -8}, {54, -8}, {54, -8}}));
connect(turbine1.outlet, sinkPressure1.flange) annotation(
Line(points = {{48, 0}, {48, 0}, {48, 20}, {60, 20}, {60, 20}}, color = {159, 159, 223}));
connect(sourcePressure1.flange, compressor1.inlet) annotation(
Line(points = {{-82, 0}, {-48, 0}, {-48, 0}, {-48, 0}}, color = {159, 159, 223}));
connect(firstOrder1.y, sourceMassFlow1.in_w0) annotation(
Line(points = {{-80, 52}, {-48, 52}, {-48, 44}, {-48, 44}, {-48, 44}}, color = {0, 0, 127}));
connect(sourceMassFlow1.flange, combustionChamber1.inf) annotation(
Line(points = {{-38, 40}, {0, 40}, {0, 40}, {0, 40}}, color = {159, 159, 223}));
connect(FuelFlowRate, firstOrder1.u) annotation(
Line(points = {{-142, 18}, {-100, 18}, {-100, 51}, {-91, 51}}, color = {0, 0, 127}));
connect(pressDrop2.outlet, turbine1.inlet) annotation(
Line(points = {{32, 8}, {32, 8}, {32, 0}, {32, 0}}, color = {159, 159, 223}));
connect(pressDrop1.outlet, compressor1.outlet) annotation(
Line(points = {{-32, 8}, {-32, 8}, {-32, 0}, {-32, 0}}, color = {159, 159, 223}));
connect(stateReader_gas2.outlet, pressDrop2.inlet) annotation(
Line(points = {{26, 30}, {32, 30}, {32, 20}, {32, 20}}, color = {159, 159, 223}));
connect(combustionChamber1.out, stateReader_gas2.inlet) annotation(
Line(points = {{10, 30}, {18, 30}, {18, 30}, {18, 30}}, color = {159, 159, 223}));
connect(stateReader_gas1.outlet, combustionChamber1.ina) annotation(
Line(points = {{-18, 30}, {-10, 30}, {-10, 30}, {-10, 30}}, color = {159, 159, 223}));
connect(pressDrop1.inlet, stateReader_gas1.inlet) annotation(
Line(points = {{-32, 20}, {-32, 20}, {-32, 30}, {-26, 30}, {-26, 30}}, color = {159, 159, 223}));
connect(compressor1.shaft_b, turbine1.shaft_a) annotation(
Line(points = {{-34, -8}, {34, -8}}));
annotation(
uses(ThermoPower(version = "3.1"), Modelica(version = "3.2.2")));
end BraytonCycleLibraryReplica;

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.