Skip to content

Commit

Permalink
#1890 further improved (Complex matrix vector multiplication added in…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
otter committed Feb 18, 2016
1 parent 7d7f4ee commit 563e24c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 10 deletions.
9 changes: 9 additions & 0 deletions Modelica/ComplexMath.mo
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,15 @@ to the original vector are given, such that sorted_v = v[indices].
</html>"));
end sort;

function matrixVectorProduct "Returns M*v of a Complex matrix M and a Complex vector v"
extends Modelica.Icons.Function;
input Complex M[:,:] "Complex matrix";
input Complex v[size(M,2)] "Complex vector";
output Complex result[size(M,1)] "Complex result vector M*v";
algorithm
result:={Modelica.ComplexMath.'sum'({M[j,k]*v[k] for k in 1:size(M,2)}) for j in 1:size(M,1)};
annotation(Inline=true);
end matrixVectorProduct;
annotation(Documentation(info="<html>
<p>
This library provides functions operating on vectors
Expand Down
12 changes: 8 additions & 4 deletions Modelica/Electrical/QuasiStationary/MultiPhase.mo
Original file line number Diff line number Diff line change
Expand Up @@ -2018,17 +2018,21 @@ This block determines the continuous quasi <a href=\"Modelica://Modelica.Blocks.

block SymmetricalComponents
"Creates symmetrical components from signals representing quasi static phasors"
import Modelica.ComplexMath.Vectors.matrixVectorProduct;
extends Modelica.ComplexBlocks.Interfaces.ComplexMIMO(final nin=m,final nout=m);
parameter Integer m=3 "Number of phases";
protected
final parameter Complex sTM[m, m]=
Modelica.Electrical.MultiPhase.Functions.symmetricTransformationMatrix(m);
equation
// Symmetrical components (preferred): y = sTM*u;
for j in 1:m loop
y[j] = Complex(sum({sTM[j,k].re*u[k].re - sTM[j,k].im*u[k].im for k in 1:m}),
sum({sTM[j,k].re*u[k].im + sTM[j,k].im*u[k].re for k in 1:m}));
end for;
/*
for j in 1:m loop
y[j] = Complex(sum({sTM[j,k].re*u[k].re - sTM[j,k].im*u[k].im for k in 1:m}),
sum({sTM[j,k].re*u[k].im + sTM[j,k].im*u[k].re for k in 1:m}));
end for;
*/
y = matrixVectorProduct(sTM,u);
annotation ( Icon(coordinateSystem(
preserveAspectRatio=false, extent={{-100,-100},{100,100}}),
graphics={
Expand Down
18 changes: 12 additions & 6 deletions Modelica/Magnetic/QuasiStatic/FundamentalWave.mo
Original file line number Diff line number Diff line change
Expand Up @@ -3103,6 +3103,7 @@ relationship of the voltage and current space phasor.
model MultiPhaseElectroMagneticConverter
"Multi phase electro magnetic converter"
import Modelica.Constants.pi;
import Modelica.ComplexMath.Vectors.matrixVectorProduct;
constant Complex j=Complex(0, 1);
Modelica.Electrical.QuasiStationary.MultiPhase.Interfaces.PositivePlug
plug_p(final m=m) "Positive plug" annotation (Placement(transformation(
Expand Down Expand Up @@ -3185,12 +3186,17 @@ relationship of the voltage and current space phasor.
"Indices of all positive sequence components";
equation
// Symmetrical components (preferred): vSymmetricalComponent = sTM*v; iSymmetricalComponent = sTM*i;
for j in 1:m loop
vSymmetricalComponent[j] = Complex(sum({sTM[j,k].re*v[k].re - sTM[j,k].im*v[k].im for k in 1:m}),
sum({sTM[j,k].re*v[k].im + sTM[j,k].im*v[k].re for k in 1:m}));
iSymmetricalComponent[j] = Complex(sum({sTM[j,k].re*i[k].re - sTM[j,k].im*i[k].im for k in 1:m}),
sum({sTM[j,k].re*i[k].im + sTM[j,k].im*i[k].re for k in 1:m}));
end for;
/*
for j in 1:m loop
vSymmetricalComponent[j] = Complex(sum({sTM[j,k].re*v[k].re - sTM[j,k].im*v[k].im for k in 1:m}),
sum({sTM[j,k].re*v[k].im + sTM[j,k].im*v[k].re for k in 1:m}));
iSymmetricalComponent[j] = Complex(sum({sTM[j,k].re*i[k].re - sTM[j,k].im*i[k].im for k in 1:m}),
sum({sTM[j,k].re*i[k].im + sTM[j,k].im*i[k].re for k in 1:m}));
end for;
*/
vSymmetricalComponent = matrixVectorProduct(sTM,v);
iSymmetricalComponent = matrixVectorProduct(sTM,i);

// Magnetic flux and flux balance of the magnetic ports
port_p.Phi = Phi;
port_p.Phi + port_n.Phi = Complex(0, 0);
Expand Down

0 comments on commit 563e24c

Please sign in to comment.