- Index
- » Usage and Applications
- » OpenModelica Usage and Applications
- » Specific M_transformer
Specific M_transformer
Specific M_transformer
I'm trying to build with Modelica matrix component like M_Transformer. But here I need a matrix inductance where each term is not necessary a parameter. For instance some terms could depend on a real variable. I tried to use the M_Transformer in the example below.
Code:
model M_Transfo
parameter Real W=314.1592;
Modelica.Electrical.Analog.Sources.SineVoltage E1(
V=1000.0*sqrt(2),
phase = 0,
freqHz = W/2.0/Modelica.Constants.pi);
Modelica.Electrical.Analog.Sources.SineVoltage E2(
V = 1000.0*sqrt(2),
phase = -2.0*Modelica.Constants.pi/3.0,
freqHz = W/2.0/Modelica.Constants.pi);
Modelica.Electrical.Analog.Sources.SineVoltage E3(
V=1000.0*sqrt(2),
phase = -4.0*Modelica.Constants.pi/3.0,
freqHz = W/2.0/Modelica.Constants.pi);
Modelica.Electrical.Analog.Basic.Resistor R1(R=0.1);
Modelica.Electrical.Analog.Basic.Resistor R2(R=0.1);
Modelica.Electrical.Analog.Basic.Resistor R3(R=0.1);
Modelica.Electrical.Analog.Basic.Inductor L1(L=0.01);
Modelica.Electrical.Analog.Basic.Inductor L2(L=0.01);
Modelica.Electrical.Analog.Basic.Inductor L3(L=0.01);
Modelica.Electrical.Analog.Basic.Resistor RAS(R=1.0);
Modelica.Electrical.Analog.Basic.Resistor RBS(R=1.0);
Modelica.Electrical.Analog.Basic.Resistor RCS(R=1.0);
Modelica.Electrical.Analog.Basic.Ground g;
Modelica.Electrical.Analog.Basic.M_Transformer Mind;
Modelica.Electrical.Analog.Basic.Resistor RLINK(R=1.0e5);
equation
connect(E1.n,g.p);
connect(E2.n,g.p);
connect(E3.n,g.p);
connect(E1.p,R1.n);
connect(E2.p,R2.n);
connect(E3.p,R3.n);
connect(R1.p,L1.n);
connect(R2.p,L2.n);
connect(R3.p,L3.n);
connect(L1.p,RAS.n);
connect(RAS.p,Mind.n[1]);
connect(L2.p,RBS.n);
connect(RBS.p,Mind.n[2]);
connect(L3.p,RCS.n);
connect(RCS.p,Mind.n[3]);
connect(Mind.p[1],RLINK.n);
connect(Mind.p[2],RLINK.n);
connect(Mind.p[3],RLINK.n);
connect(RLINK.p,g.p);
end M_Transfo;
With OMShell, the command "simulate(M_Transfo,stopTime=0.1,outputFormat="csv")" gave the following warnings :
record SimulationResult
resultFile = "C:/DOCUME~1/DUCREU~1/LOCALS~1/Temp/M_Transfo_res.csv",
simulationOptions = "startTime = 0.0, stopTime = 0.1, numberOfIntervals = 500, tolerance = 0.000001, method = 'dassl', fileNamePrefix = 'M_Transfo', options = '', outputFormat = 'csv', variableFilter = '.*', measureTime = false, cflags = '', simflags = ''",
messages = "",
timeFrontend = 0.422195837739154,
timeBackend = 0.04046408132877223,
timeSimCode = 0.01800731657235766,
timeTemplates = 0.13097502615555887,
timeCompile = 3.4024824384104684,
timeSimulation = 0.5404206400534146,
timeTotal = 4.554931702213549
end SimulationResult;
[C:\OpenModelica1.9.1\lib\omlibrary\Modelica 3.2.1\Electrical\Analog\Basic.mo:597:47-597:57:writable] Warning: Non-array modification 'true' for array component, possibly due to missing 'each'.
It seems that the last warning concerns Modelica library so, I can't do anything to avoid this message.
This first step was successfull. Then, as a second step, I tried to build my own M_Transformer using the model in Modelica library. Nothing else changed in the whole model as shown in the script here :
Code:
model VM_ind
class VM_Transformer
parameter Integer N(final min=1)=3 "number of inductors";
protected
parameter Integer dimL=div(N*(N+1),2);
public
parameter Modelica.SIunits.Inductance L[dimL]={1,0.1,0.2,2,0.3,3}
"inductances and coupling inductances";
Modelica.Electrical.Analog.Interfaces.PositivePin p[N] "Positive pin"
annotation (Placement(transformation(
extent={{-80,-40},{-62,40}}, rotation=0)));
Modelica.Electrical.Analog.Interfaces.NegativePin n[N] "Negative pin"
annotation (Placement(transformation(
extent={{62,-40},{80,40}}, rotation=0)));
Modelica.SIunits.Voltage v[N];
Modelica.SIunits.Current i[N](each start=0.0);
Modelica.SIunits.Inductance Lm[N,N];
algorithm
for s in 1:N loop
for z in 1:N loop
Lm[z,s]:= if (z>=s) then L[(s-1)*N+z-div((s-1)*s,2)] else
Lm[s,z];
end for;
end for;
equation
for j in 1:N loop
v[j] = p[j].v - n[j].v;
0 = p[j].i + n[j].i;
i[j] = p[j].i;
end for;
v =Lm*der(i);
end VM_Transformer;
VM_Transformer Mind;
parameter Real W=314.1592;
Modelica.Electrical.Analog.Sources.SineVoltage E1(
V=1000.0*sqrt(2),
phase = 0,
freqHz = W/2.0/Modelica.Constants.pi);
Modelica.Electrical.Analog.Sources.SineVoltage E2(
V = 1000.0*sqrt(2),
phase = -2.0*Modelica.Constants.pi/3.0,
freqHz = W/2.0/Modelica.Constants.pi);
Modelica.Electrical.Analog.Sources.SineVoltage E3(
V=1000.0*sqrt(2),
phase = -4.0*Modelica.Constants.pi/3.0,
freqHz = W/2.0/Modelica.Constants.pi);
Modelica.Electrical.Analog.Basic.Resistor R1(R=0.1);
Modelica.Electrical.Analog.Basic.Resistor R2(R=0.1);
Modelica.Electrical.Analog.Basic.Resistor R3(R=0.1);
Modelica.Electrical.Analog.Basic.Inductor L1(L=0.01);
Modelica.Electrical.Analog.Basic.Inductor L2(L=0.01);
Modelica.Electrical.Analog.Basic.Inductor L3(L=0.01);
Modelica.Electrical.Analog.Basic.Resistor RAS(R=1.0);
Modelica.Electrical.Analog.Basic.Resistor RBS(R=1.0);
Modelica.Electrical.Analog.Basic.Resistor RCS(R=1.0);
Modelica.Electrical.Analog.Basic.Ground g;
Modelica.Electrical.Analog.Basic.Resistor RLINK(R=1.0e5);
equation
connect(E1.n,g.p);
connect(E2.n,g.p);
connect(E3.n,g.p);
connect(E1.p,R1.n);
connect(E2.p,R2.n);
connect(E3.p,R3.n);
connect(R1.p,L1.n);
connect(R2.p,L2.n);
connect(R3.p,L3.n);
connect(L1.p,RAS.n);
connect(RAS.p,Mind.n[1]);
connect(L2.p,RBS.n);
connect(RBS.p,Mind.n[2]);
connect(L3.p,RCS.n);
connect(RCS.p,Mind.n[3]);
connect(Mind.p[1],RLINK.n);
connect(Mind.p[2],RLINK.n);
connect(Mind.p[3],RLINK.n);
connect(RLINK.p,g.p);
end VM_ind;
In OMShell, the command "simulate(VM_ind,stopTime=0.1,outputFormat="csv")" gave the following errors :
[indent]record SimulationResult
resultFile = "",
simulationOptions = "startTime = 0.0, stopTime = 0.1, numberOfIntervals = 500, tolerance = 0.000001, method = 'dassl', fileNamePrefix = 'VM_ind', options = '', outputFormat = 'csv', variableFilter = '.*', measureTime = false, cflags = '', simflags = ''",
messages = "Simulation failed for model: VM_ind
Warning: The initial conditions are not fully specified. Use +d=initialization for more information.
Error: Error building simulator. Build log: gcc -falign-functions -msse2 -mfpmath=sse -I\"C:/OpenModelica1.9.1//include/omc\" -I. -DOPENMODELICA_XML_FROM_FILE_AT_RUNTIME -c -o VM_ind.o VM_ind.c
gcc -falign-functions -msse2 -mfpmath=sse -I\"C:/OpenModelica1.9.1//include/omc\" -I. -DOPENMODELICA_XML_FROM_FILE_AT_RUNTIME -c -o VM_ind_functions.o VM_ind_functions.c
gcc -falign-functions -msse2 -mfpmath=sse -I\"C:/OpenModelica1.9.1//include/omc\" -I. -DOPENMODELICA_XML_FROM_FILE_AT_RUNTIME -c -o VM_ind_records.o VM_ind_records.c
gcc -falign-functions -msse2 -mfpmath=sse -I\"C:/OpenModelica1.9.1//include/omc\" -I. -DOPENMODELICA_XML_FROM_FILE_AT_RUNTIME -c -o VM_ind_01exo.o VM_ind_01exo.c
gcc -falign-functions -msse2 -mfpmath=sse -I\"C:/OpenModelica1.9.1//include/omc\" -I. -DOPENMODELICA_XML_FROM_FILE_AT_RUNTIME -c -o VM_ind_02nls.o VM_ind_02nls.c
gcc -falign-functions -msse2 -mfpmath=sse -I\"C:/OpenModelica1.9.1//include/omc\" -I. -DOPENMODELICA_XML_FROM_FILE_AT_RUNTIME -c -o VM_ind_03lsy.o VM_ind_03lsy.c
gcc -falign-functions -msse2 -mfpmath=sse -I\"C:/OpenModelica1.9.1//include/omc\" -I. -DOPENMODELICA_XML_FROM_FILE_AT_RUNTIME -c -o VM_ind_04set.o VM_ind_04set.c
gcc -falign-functions -msse2 -mfpmath=sse -I\"C:/OpenModelica1.9.1//include/omc\" -I. -DOPENMODELICA_XML_FROM_FILE_AT_RUNTIME -c -o VM_ind_05evt.o VM_ind_05evt.c
VM_ind_05evt.c: In function 'function_ZeroCrossings':
VM_ind_05evt.c:62: error: '$Ps' undeclared (first use in this function)
VM_ind_05evt.c:62: error: (Each undeclared identifier is reported only once
VM_ind_05evt.c:62: error: for each function it appears in.)
VM_ind_05evt.c: In function 'function_updateRelations':
VM_ind_05evt.c:102: error: '$Ps' undeclared (first use in this function)
mingw32-make: *** [VM_ind_05evt.o] Error 1
",
timeFrontend = 0.0,
timeBackend = 0.0,
timeSimCode = 0.0,
timeTemplates = 0.0,
timeCompile = 0.0,
timeSimulation = 0.0,
timeTotal = 0.0
end SimulationResult;
I don't understand where I could make a mistake. I'm using [OpenModelica 1.9.1+dev(r17770) on Windows Vista and and Windows8 with the same occuring problem. Any help will be greatly appreciated.
Regards,
Jean-Pierre
Re: Specific M_transformer
Hi,
Congratulations! You discovered a bug
It seems we're missing the declaration for the index s in the for loop in the algorithm for the zero crossing given by z>=s.
As a workaround for now use this line instead (add noEvent in the if condition here):
Code:
Lm[z,s]:= if noEvent(z>=s) then L[(s-1)*N+z-div((s-1)*s,2)] else Lm[s,z];
Cheers,
Adrian Pop/
- adrpo
- 885 Posts
- Index
- » Usage and Applications
- » OpenModelica Usage and Applications
- » Specific M_transformer