Plot time signals in Modelica.Electrical.Quasistationary - modelica

I am trying to model a balanced 3 phase star connection (see foto 1)
foto 1 and I want to get this simulation results (see foto 2 )foto 2 : R1.V,R2.V,R3.V. Here are some of the basic equations used foto 3.
I tried many times without success, can someone check and fix my model, so that I can get the same simulation results like foto 2?
model Unnamed
parameter Integer m=3 "Number of phases";
Modelica.Electrical.QuasiStationary.MultiPhase.Basic.Star starS annotation (
Placement(transformation(
extent={{-10,-10},{10,10}},
rotation=180,
origin={-22,70})));
Modelica.Electrical.QuasiStationary.SinglePhase.Basic.Ground groundS
annotation (Placement(transformation(
extent={{-10,-10},{10,10}},
rotation=0,
origin={-56,18})));
Modelica.Electrical.QuasiStationary.MultiPhase.Basic.Resistor resistor(R_ref=
fill(1000, 3))
annotation (Placement(transformation(extent={{42,60},{62,80}})));
Modelica.Electrical.QuasiStationary.MultiPhase.Sources.VoltageSource
voltageSource1(m=m,
f=50,
V=fill(230,m),
phi=-Modelica.Electrical.MultiPhase.Functions.symmetricOrientation(3))
"{(-(j - 1))*2*Modelica.Constants.pi/(m) for j in 1/m}"
annotation (Placement(transformation(extent={{28,60},{8,80}})));
Modelica.Electrical.QuasiStationary.MultiPhase.Basic.Star starS1
annotation (
Placement(transformation(
extent={{-10,-10},{10,10}},
rotation=0,
origin={82,70})));
equation
connect(groundS.pin, starS.pin_n)
annotation (Line(points={{-56,28},{-36,28},{-36,70},{-32,70}},
color={85,170,255}));
connect(starS.plug_p, voltageSource1.plug_n)
annotation (Line(points={{-12,70},{8,70}}, color={85,170,255}));
connect(voltageSource1.plug_p, resistor.plug_p)
annotation (Line(points={{28,70},{42,70}}, color={85,170,255}));
connect(resistor.plug_n, starS1.plug_p)
annotation (Line(points={{62,70},{72,70}}, color={85,170,255}));
connect(starS1.pin_n, groundS.pin) annotation (Line(points={{92,70},{92,26},{-56,
26},{-56,28}}, color={85,170,255}));
annotation (uses(Modelica(version="3.2.2")));
end Unnamed;
Thank you

The Modelica.Electrical.QuasiStationary package is phasor-based and therefore it seems to be a bit difficult to plot the sinusoidal signals - at least I didn't find a straight-forward way...
Therefore: Is there any specific reason to use the QuasiStationary package? The more obvious way would be to use Modelica.Electrical.MultiPhase in my opinion. This could e.g. result in the flowing code, which is copied and modified from Modelica.Electrical.MultiPhase.Examples.TransformerYY:
model ResistorThreephase "Test example with multiphase components"
extends Modelica.Icons.Example;
parameter Integer m=3 "Number of phases";
parameter Modelica.SIunits.Voltage V=230 "Amplitude of Star-Voltage";
parameter Modelica.SIunits.Frequency f=50 "Frequency";
parameter Modelica.SIunits.Resistance RL=1e3 "Load Resistance";
Modelica.Electrical.MultiPhase.Sources.SineVoltage sineVoltage(
V=fill(V, m),
freqHz=fill(f, m),
m=m) annotation (Placement(transformation(
origin={-30,20},
extent={{-10,-10},{10,10}},
rotation=180)));
Modelica.Electrical.MultiPhase.Basic.Star starS(m=m)
annotation (Placement(transformation(
origin={-70,20},
extent={{-10,-10},{10,10}},
rotation=180)));
Modelica.Electrical.Analog.Basic.Ground groundS annotation (Placement(
transformation(extent={{-100,-40},{-80,-20}})));
Modelica.Electrical.MultiPhase.Basic.Resistor loadR(m=m, R=fill(RL, m))
annotation (Placement(transformation(extent={{20,10},{40,30}})));
Modelica.Electrical.MultiPhase.Basic.Star starL(m=m)
annotation (Placement(transformation(
origin={70,20},
extent={{-10,-10},{10,10}},
rotation=0)));
equation
connect(starS.pin_n, groundS.p)
annotation (Line(points={{-80,20},{-90,20},{-90,-20}}, color={0,0,255}));
connect(starS.plug_p, sineVoltage.plug_n)
annotation (Line(points={{-60,20},{-40,20}}, color={0,0,255}));
connect(loadR.plug_n, starL.plug_p)
annotation (Line(points={{40,20},{60,20}}, color={0,0,255}));
connect(sineVoltage.plug_p, loadR.plug_p) annotation (Line(points={{-20,20},{20,20}}, color={0,0,255}));
connect(starL.pin_n, groundS.p) annotation (Line(points={{80,20},{90,20},{90,-20},{-90,-20}}, color={0,0,255}));
annotation (
experiment(StopTime=0.03, __Dymola_Algorithm="Dassl"),
uses(Modelica(version="3.2.3")));
end ResistorThreephase;

Related

How can I encapsulate models of the fluid library of openmodelica?

Problem and Motivation:
the models of the fluid library in openmodelica are very elaborated, with a lot of parameters one has to set correctly to get the model running with acceptable results.
I want to set up an environment for daily engineering calculations, for mechanical and process engineers - no simulation experts.
So the components of my library must be pre-configured and the users shouldn't be forced to edit the code behind the graphical model (eg redeclaration of the Medium).
Idea:
drop the fluid models in own models, configure them properly, redeclare the Medium and provide fluid connectors.
model flowEncapsulateFluid1
inner Modelica.Fluid.System system;
replaceable package Medium = Modelica.Media.Water.ConstantPropertyLiquidWater constrainedby
Modelica.Media.Interfaces.PartialMedium "Medium in the component"
annotation (choicesAllMatching = true);
model myStaticPipe
Modelica.Fluid.Pipes.StaticPipe pipe(redeclare package Medium = Medium, allowFlowReversal = true, height_ab = 2, length = 2, diameter = 0.1);
Modelica.Fluid.Interfaces.FluidPort_a port_a;
Modelica.Fluid.Interfaces.FluidPort_b port_b;
equation
connect(pipe.port_b, port_b);
connect(port_a, pipe.port_a);
model myTank1
Modelica.Fluid.Vessels.OpenTank tank1(crossArea = 1,
redeclare package Medium = Medium, use_portsData = true, height = 12,
level_start = 8, nPorts = 6,
portsData = {Modelica.Fluid.Vessels.BaseClasses.VesselPortsData
(diameter = 0.1)});
Modelica.Fluid.Interfaces.FluidPort_a port_a
(redeclare package Medium = Medium);
Modelica.Fluid.Interfaces.FluidPort_a port_a1
(redeclare package Medium = Medium);
Modelica.Fluid.Interfaces.FluidPort_a port_a2
(redeclare package Medium = Medium);
Modelica.Fluid.Interfaces.FluidPort_a port_a3
(redeclare package Medium = Medium) ;
Modelica.Fluid.Interfaces.FluidPort_a port_a4
(redeclare package Medium = Medium) ;
Modelica.Fluid.Interfaces.FluidPort_b port_b
(redeclare package Medium = Medium);
equation
connect(tank1.ports[6], port_b);
connect(port_a4, tank1.ports[5]);
connect(port_a3, tank1.ports[4]);
connect(port_a2, tank1.ports[3]);
connect(port_a1, tank1.ports[2]);
connect(port_a, tank1.ports[1]);
end myTank1;
package UnitTests
model Test1
flowEncapsulateFluid1.myTank1 myTank11;
myStaticPipe myStaticPipe1;
myTank1 myTank12;
equation
connect(myStaticPipe1.port_b, myTank12.ports_b);
connect(myTank11.ports_b, myStaticPipe1.port_a);
end Test1;
end UnitTests;
annotation(
uses(Modelica(version = "3.2.2")));
end flowEncapsulateFluid1;
I get the message "No corresponding 'inner' declaration found for component .Modelica.Fluid.System tank1.system declared as 'outer '.
The existing 'inner' components are:
There are no 'inner' components defined in the model in any of the parent scopes of 'outer' component's scope: Modelica.Fluid.Vessels.OpenTank$tank1.
Check if you have not misspelled the 'outer' component name.
Please declare an 'inner' component with the same name in the top scope.
Continuing flattening by only considering the 'outer' component declaration."
I don't know how to interpret the message. Any help would be welcome.
Furthermore I would appreciate, if some one could provide me advices or links for this project.
Many thanks in advance.
y4cine,
You could create a library of components that extend from the Modelica.Fluid components and finalize the parameters that you don't want your users to see. For example
model myPipe
extends Modelica.Fluid.Pipes.DynamicPipe(
redeclare package Medium = Modelica.Media.Water.StandardWater,
final height_ab=0,
final isCircular=true);
end myPipe;
When you instantiate the component (shown in Dymola) the parameters are not visible (see screenshot below).
Best regards,
Rene Just Nielsen
In regards to this portion of your question: "No corresponding 'inner' declaration found for component .Modelica.Fluid.System tank1.system declared as 'outer '.
outer and inner are special key words in modelica.
The fluid library defines an "outer" model called "system" located at Modelica.Fluid.System. If you drag that into a model that gives that warning the issue will go away as it will find this outer model. Typically this system model should be at a high level and not at individual components...

Gantt Chart in Matlab

Do you know how to plot a Gantt chart in Matlab without using a third-party software?
At the end I would love to obtain something like this:
What I was able to obtain so far is
using this code:
% Create data for childhood disease cases
measles = [38556 24472 14556 18060 19549 8122 28541 7880 3283 4135 7953 1884]';
mumps = [20178 23536 34561 37395 36072 32237 18597 9408 6005 6268 8963 13882]';
chickenPox = [37140 32169 37533 39103 33244 23269 16737 5411 3435 6052 12825 23332]';
% Create a stacked bar chart using the bar function
fig = figure;
bar(1:12, [measles mumps chickenPox], 0.5, 'stack');
axis([0 13 0 100000]);
title('Childhood diseases by month');
xlabel('Month');
ylabel('Cases (in thousands)');
legend('Measles', 'Mumps', 'Chicken pox');
That is not what I want but, maybe, goes in this direction
Here, I share the solution I have just found (maybe it is not the most elegant one but it works for the purpose I have):
[the main idea is to draw a bar and "delete" the beginning overdrawing up on it another white bar]
Let's say you have two vector:
start =[6907402; 2282194; 4579536; 2300332; 10540; 2307970; 4603492; 0];
stop =[9178344; 9168694;6895050; 4571400; 2280886; 4579044; 6897152 ;2271186];
There are 8 elements in each: every element is a task. In the start array, there is the start time of each task and in stop there is the end of the "execution" of a given task.
barh(stop)
hold on
barh(start,'w')
At the end here you have the Gantt:
UPDATE:
My scripts are evolved of course and, more, on the matlab website, there is more information. Here 2 example more to complete the answer:
Option 1:
Positions=[1,2,3,4];
Gap_Duration=[0,2,5,3,5,3;
3,5,3,5,3,4;
9,3,0,0,12,2;
13,2,2,2,8,3];
barh(Positions,Gap_Duration,'stacked');
Option 2:
Positions=[1,2,3,4];
Gap_Duration=[0,2,5,3,5,3;
3,5,3,5,3,4;
9,3,0,0,12,2;
13,2,2,2,8,3];
barh(Positions,Gap_Duration,'stacked');
set(H([1 3 5]),'Visible','off')

Modelica Standard Library component AbruptAdaptor

Tested with:
MSL Versions:
3.2.1, 2013-08-14, build 2 (2013-08-14 08:44:41Z)
3.2.1, 2013-08-14, build 4 (2015-09-30 09:15:00Z)
Below is a model with 4 components:
Mass flow source (M_bound)
AbruptAdapter (abruptAdapter)
Dynamic Pipe (pipeSmall)
Pressure Source (P_bound)
Two connection cases of the model are also contained in the equation section:
Case #1: M_bound -> abruptAdaptor -> pipeSmall -> P_bound
Case #2: M_bound -> pipeSmall -> abruptAdaptor -> P_bound
Summary: Case #1 simulates fine but Case #2 fails. The error generated is shown below:
The following error was detected at time: 0
Model error - division by zero: (data.zeta1) / ((if data.zeta1_at_a then rho_a_des*A_a^2 else rho_b_des*A_b^2)) = (0.402964) / (0)
The stack of functions is:
Modelica.Fluid.Fittings.BaseClasses.QuadraticTurbulent.pressureLoss_m_flow_totalPressure
Modelica.Fluid.Fittings.BaseClasses.QuadraticTurbulent.pressureLoss_m_flow_totalPressure(
-pipeBig.port_b.m_flow,
abruptAdaptor.state_a.d,
abruptAdaptor.state_b_des.d,
abruptAdaptor.state_b.d,
abruptAdaptor.state_a_nondes.d,
abruptAdaptor.data,
abruptAdaptor.m_flow_small)
First evaluation failed for non-linear solver.
Question: Why does Case #2 fail and recommendations on how to fix it? Any insight would be great. It may even be a bug in the AbruptAdaptor component.
Model Code
model AbruptAdaptor_1Pipe
replaceable package Medium = Modelica.Media.Water.StandardWater;
inner Modelica.Fluid.System system;
Modelica.Fluid.Sources.Boundary_pT P_bound(
redeclare package Medium = Medium,
nPorts=1,
p=system.p_ambient,
T=M_bound.T);
Modelica.Fluid.Sources.MassFlowSource_T M_bound(
redeclare package Medium = Medium,
m_flow=1,
T=300,
nPorts=1);
Modelica.Fluid.Fittings.AbruptAdaptor abruptAdaptor(
redeclare package Medium = Medium,
diameter_a=1,
diameter_b=0.5,
m_flow_nominal=M_bound.m_flow,
m_flow_start=M_bound.m_flow);
Modelica.Fluid.Pipes.DynamicPipe pipeSmall(
redeclare package Medium = Medium,
T_start=M_bound.T,
m_flow_start=M_bound.m_flow,
length=1,
diameter=0.5,
modelStructure=Modelica.Fluid.Types.ModelStructure.av_b); // switch to av_vb with case #2
equation
// Case #1
connect(M_bound.ports[1],abruptAdaptor.port_a);
connect(abruptAdaptor.port_b,pipeSmall.port_a);
connect(pipeSmall.port_b,P_bound.ports[1]);
// Case #2
//connect(M_bound.ports[1],pipeSmall.port_b);
//connect(abruptAdaptor.port_b,pipeSmall.port_a);
//connect(abruptAdaptor.port_a,P_bound.ports[1]);
annotation (uses(Modelica(version="3.2.1")));
end AbruptAdaptor_1Pipe;
your staggered grid is fine, you set volumes where you had to.
Don't worry, it's not your fault, is a debug, I tried to use it several times, and it always fails in one of the ways (I don't know the position of your adaptor, but it doesn't really matter). You can always use orifices where you define the relations dp(Areas_rate), avoiding reversal flows in both cases, so connecting two volumes before and after the orifices (like two valves in parallel).
That should work.

Colored graph isomorphism?

I have two colored graphs. I want to determine if they are isomorphic, with the condition that the isomorphism must preserve vertex color. Is there an algorithm in networkx to do this?
The graphs are undirected and simple.
Check the documentation for is_isomorphic. It takes an optional argument nodes_match which is a function that tests some condition on the two nodes. It is called by node_match(G1.node[n1], G2.node[n2]). So in this case, you want a function that tests whether the colors are matching.
import networkx as nx
def colors_match(n1_attrib,n2_attrib):
'''returns False if either does not have a color or if the colors do not match'''
try:
return n1_attrib['color']==n2_attrib['color']
except KeyError:
return False
G=nx.Graph()
G.add_node(1, color='y')
G.add_node(2, color='b')
H=nx.Graph()
H.add_node('a', color='y')
H.add_node('b', color = 'b')
nx.is_isomorphic(G,H,node_match=colors_match)
>True
H.add_node('c', color='r')
nx.is_isomorphic(G,H,node_match=colors_match)
>False

MapKit multiple pins same coordinates, different info selection

I have the following situation:
- 3 pins with same coordinates but different title and info
- on map there is ony one pin
It is possible to tap multiple times on that pin and the annotation displayed to be:
- first tap -> the annotation for pin 1
- second tap -> the annotation for pin 2
- third tap -> the annotation for pin 3
- fourth tap -> the annotation for pin 1
Do you have any ideas how should I implement it?
You can implement the didSelectAnnotationView delegate method and select the "correct" annotation yourself depending on what the last "correct" selection was.
If you only have these annotations on the map and only one cluster of them, then you can keep one int ivar that remembers what the last selected annotation was and increment it in the delegate method.
For example:
// In .h
int lastAnnotationSelected;
// In .m
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{
int nextAnnotationToSelect = (lastAnnotationSelected + 1)
% mapView.annotations.count;
id<MKAnnotation> nextAnnotation =
[mapView.annotations objectAtIndex:nextAnnotationToSelect];
[mapView selectAnnotation:nextAnnotation animated:YES];
lastAnnotationSelected = nextAnnotationToSelect;
}
If you also have showsUserLocation turned on, then you'll have to add a check for MKUserLocation in that method and skip it (if you want to) and go to the next annotation in the cluster.
Also, if you have multiple clusters of annotations (3 at coordinate A, 5 at coordinate B, 4 at coordinate C, etc), then you'll need to keep track of an array of lastAnnotationSelected ints and in the method, first determine what cluster was selected and get the next annotation to select in that cluster.