Skip to content

Commit 563e24c

Browse files
author
otter
committed
#1890 further improved (Complex matrix vector multiplication added in MSL trunk)
As suggested, introduced function MatrixVectorProduct and used it. This works in Dymola. git-svn-id: https://svn.modelica.org/projects/Modelica/trunk@9051 7ce873d0-865f-4ce7-a662-4bb36ea78beb
1 parent 7d7f4ee commit 563e24c

File tree

3 files changed

+29
-10
lines changed

3 files changed

+29
-10
lines changed

Modelica/ComplexMath.mo

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,15 @@ to the original vector are given, such that sorted_v = v[indices].
316316
</html>"));
317317
end sort;
318318

319+
function matrixVectorProduct "Returns M*v of a Complex matrix M and a Complex vector v"
320+
extends Modelica.Icons.Function;
321+
input Complex M[:,:] "Complex matrix";
322+
input Complex v[size(M,2)] "Complex vector";
323+
output Complex result[size(M,1)] "Complex result vector M*v";
324+
algorithm
325+
result:={Modelica.ComplexMath.'sum'({M[j,k]*v[k] for k in 1:size(M,2)}) for j in 1:size(M,1)};
326+
annotation(Inline=true);
327+
end matrixVectorProduct;
319328
annotation(Documentation(info="<html>
320329
<p>
321330
This library provides functions operating on vectors

Modelica/Electrical/QuasiStationary/MultiPhase.mo

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2018,17 +2018,21 @@ This block determines the continuous quasi <a href=\"Modelica://Modelica.Blocks.
20182018

20192019
block SymmetricalComponents
20202020
"Creates symmetrical components from signals representing quasi static phasors"
2021+
import Modelica.ComplexMath.Vectors.matrixVectorProduct;
20212022
extends Modelica.ComplexBlocks.Interfaces.ComplexMIMO(final nin=m,final nout=m);
20222023
parameter Integer m=3 "Number of phases";
20232024
protected
20242025
final parameter Complex sTM[m, m]=
20252026
Modelica.Electrical.MultiPhase.Functions.symmetricTransformationMatrix(m);
20262027
equation
20272028
// Symmetrical components (preferred): y = sTM*u;
2028-
for j in 1:m loop
2029-
y[j] = Complex(sum({sTM[j,k].re*u[k].re - sTM[j,k].im*u[k].im for k in 1:m}),
2030-
sum({sTM[j,k].re*u[k].im + sTM[j,k].im*u[k].re for k in 1:m}));
2031-
end for;
2029+
/*
2030+
for j in 1:m loop
2031+
y[j] = Complex(sum({sTM[j,k].re*u[k].re - sTM[j,k].im*u[k].im for k in 1:m}),
2032+
sum({sTM[j,k].re*u[k].im + sTM[j,k].im*u[k].re for k in 1:m}));
2033+
end for;
2034+
*/
2035+
y = matrixVectorProduct(sTM,u);
20322036
annotation ( Icon(coordinateSystem(
20332037
preserveAspectRatio=false, extent={{-100,-100},{100,100}}),
20342038
graphics={

Modelica/Magnetic/QuasiStatic/FundamentalWave.mo

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3103,6 +3103,7 @@ relationship of the voltage and current space phasor.
31033103
model MultiPhaseElectroMagneticConverter
31043104
"Multi phase electro magnetic converter"
31053105
import Modelica.Constants.pi;
3106+
import Modelica.ComplexMath.Vectors.matrixVectorProduct;
31063107
constant Complex j=Complex(0, 1);
31073108
Modelica.Electrical.QuasiStationary.MultiPhase.Interfaces.PositivePlug
31083109
plug_p(final m=m) "Positive plug" annotation (Placement(transformation(
@@ -3185,12 +3186,17 @@ relationship of the voltage and current space phasor.
31853186
"Indices of all positive sequence components";
31863187
equation
31873188
// Symmetrical components (preferred): vSymmetricalComponent = sTM*v; iSymmetricalComponent = sTM*i;
3188-
for j in 1:m loop
3189-
vSymmetricalComponent[j] = Complex(sum({sTM[j,k].re*v[k].re - sTM[j,k].im*v[k].im for k in 1:m}),
3190-
sum({sTM[j,k].re*v[k].im + sTM[j,k].im*v[k].re for k in 1:m}));
3191-
iSymmetricalComponent[j] = Complex(sum({sTM[j,k].re*i[k].re - sTM[j,k].im*i[k].im for k in 1:m}),
3192-
sum({sTM[j,k].re*i[k].im + sTM[j,k].im*i[k].re for k in 1:m}));
3193-
end for;
3189+
/*
3190+
for j in 1:m loop
3191+
vSymmetricalComponent[j] = Complex(sum({sTM[j,k].re*v[k].re - sTM[j,k].im*v[k].im for k in 1:m}),
3192+
sum({sTM[j,k].re*v[k].im + sTM[j,k].im*v[k].re for k in 1:m}));
3193+
iSymmetricalComponent[j] = Complex(sum({sTM[j,k].re*i[k].re - sTM[j,k].im*i[k].im for k in 1:m}),
3194+
sum({sTM[j,k].re*i[k].im + sTM[j,k].im*i[k].re for k in 1:m}));
3195+
end for;
3196+
*/
3197+
vSymmetricalComponent = matrixVectorProduct(sTM,v);
3198+
iSymmetricalComponent = matrixVectorProduct(sTM,i);
3199+
31943200
// Magnetic flux and flux balance of the magnetic ports
31953201
port_p.Phi = Phi;
31963202
port_p.Phi + port_n.Phi = Complex(0, 0);

0 commit comments

Comments
 (0)