Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
ACS
Public
Power System Simulation and Optimization
DPsim
DPsim
Commits
b1815d60
Commit
b1815d60
authored
Sep 18, 2017
by
Georg Martin Reinke
Browse files
implement complex Python attributes; use Complex more consequently
Former-commit-id:
ad4b3f2d
parent
b15be9d0
Changes
21
Hide whitespace changes
Inline
Side-by-side
Source/CIMReader.cpp
View file @
b1815d60
...
...
@@ -104,7 +104,7 @@ BaseComponent* CIMReader::mapExternalNetworkInjection(ExternalNetworkInjection*
}
std
::
cerr
<<
"IdealVoltageSource "
<<
inj
->
name
<<
" rid="
<<
inj
->
mRID
<<
" node1="
<<
node
<<
" node2=0 "
;
std
::
cerr
<<
" V="
<<
volt
->
v
.
value
<<
"<"
<<
volt
->
angle
.
value
<<
std
::
endl
;
return
new
IdealVoltageSource
(
inj
->
name
,
node
,
0
,
volt
->
v
.
value
,
volt
->
angle
.
value
*
PI
/
180
,
++
mNumVoltageSources
);
return
new
IdealVoltageSource
(
inj
->
name
,
node
,
0
,
Complex
(
volt
->
v
.
value
,
volt
->
angle
.
value
*
PI
/
180
)
,
++
mNumVoltageSources
);
}
BaseComponent
*
CIMReader
::
mapPowerTransformer
(
PowerTransformer
*
trans
)
{
...
...
@@ -145,7 +145,7 @@ BaseComponent* CIMReader::mapSynchronousMachine(SynchronousMachine* machine) {
std
::
cerr
<<
"VoltSourceRes "
<<
machine
->
name
<<
" rid="
<<
machine
->
mRID
<<
" node1="
<<
node
<<
" node2=0 "
;
std
::
cerr
<<
" V="
<<
volt
->
v
.
value
<<
"<"
<<
volt
->
angle
.
value
<<
" R="
<<
machine
->
r
.
value
<<
std
::
endl
;
// TODO is it appropiate to use this resistance here
return
new
VoltSourceRes
(
machine
->
name
,
node
,
0
,
volt
->
v
.
value
,
volt
->
angle
.
value
*
PI
/
180
,
machine
->
r
.
value
);
return
new
VoltSourceRes
(
machine
->
name
,
node
,
0
,
Complex
(
volt
->
v
.
value
,
volt
->
angle
.
value
*
PI
/
180
)
,
machine
->
r
.
value
);
}
BaseComponent
*
CIMReader
::
mapComponent
(
BaseClass
*
obj
)
{
...
...
Source/Components/BaseComponent.h
View file @
b1815d60
...
...
@@ -14,6 +14,7 @@ namespace DPsim {
AttrReal
,
AttrInt
,
AttrString
,
// value should be *std::string, not *char!
AttrComplex
};
struct
CompAttr
{
...
...
Source/Components/CurrentSource.cpp
View file @
b1815d60
...
...
@@ -2,17 +2,17 @@
using
namespace
DPsim
;
CurrentSource
::
CurrentSource
(
std
::
string
name
,
int
src
,
int
dest
,
doub
le
current
,
double
phase
)
:
BaseComponent
(
name
,
src
,
dest
)
{
this
->
c
urrent
r
=
current
*
cos
(
phase
)
;
this
->
current
i
=
current
*
sin
(
phase
)
;
CurrentSource
::
CurrentSource
(
std
::
string
name
,
int
src
,
int
dest
,
Comp
le
x
current
)
:
BaseComponent
(
name
,
src
,
dest
)
{
this
->
mC
urrent
=
current
;
attrMap
[
"
current
"
]
=
{
AttrComplex
,
&
this
->
mCurrent
}
;
};
void
CurrentSource
::
applyRightSideVectorStamp
(
SystemModel
&
system
)
{
if
(
mNode1
>=
0
)
{
system
.
addCompToRightSideVector
(
mNode1
,
c
urrent
r
,
currenti
);
system
.
addCompToRightSideVector
(
mNode1
,
mC
urrent
.
real
(),
mCurrent
.
imag
());
}
if
(
mNode2
>=
0
)
{
system
.
addCompToRightSideVector
(
mNode2
,
-
c
urrent
r
,
-
currenti
);
system
.
addCompToRightSideVector
(
mNode2
,
-
mC
urrent
.
real
(),
mCurrent
.
imag
()
);
}
}
...
...
@@ -21,5 +21,5 @@ void CurrentSource::step(SystemModel& system, Real time) {
}
Complex
CurrentSource
::
getCurrent
(
SystemModel
&
system
)
{
return
Complex
(
currentr
,
currenti
)
;
return
mCurrent
;
}
Source/Components/CurrentSource.h
View file @
b1815d60
...
...
@@ -7,12 +7,11 @@ namespace DPsim {
class
CurrentSource
:
public
BaseComponent
{
protected:
double
currentr
;
double
currenti
;
Complex
mCurrent
;
public:
CurrentSource
()
{
;
};
CurrentSource
(
std
::
string
name
,
int
src
,
int
dest
,
doub
le
current
,
double
phase
);
CurrentSource
(
std
::
string
name
,
int
src
,
int
dest
,
Comp
le
x
current
);
void
init
(
Real
om
,
Real
dt
)
{
}
void
applySystemMatrixStamp
(
SystemModel
&
system
)
{
}
...
...
Source/Components/ExternalCurrentSource.cpp
View file @
b1815d60
...
...
@@ -2,11 +2,10 @@
using
namespace
DPsim
;
ExternalCurrentSource
::
ExternalCurrentSource
(
std
::
string
name
,
int
src
,
int
dest
,
Real
initCurrent
,
Real
initPhase
)
:
CurrentSource
(
name
,
src
,
dest
,
initCurrent
,
initPhase
)
{
ExternalCurrentSource
::
ExternalCurrentSource
(
std
::
string
name
,
int
src
,
int
dest
,
Complex
initCurrent
)
:
CurrentSource
(
name
,
src
,
dest
,
initCurrent
)
{
}
void
ExternalCurrentSource
::
setCurrent
(
Real
real
,
Real
imag
)
{
this
->
currentr
=
real
;
this
->
currenti
=
imag
;
this
->
mCurrent
=
Complex
(
real
,
imag
);
}
Source/Components/ExternalCurrentSource.h
View file @
b1815d60
...
...
@@ -9,7 +9,7 @@ namespace DPsim {
public:
ExternalCurrentSource
()
{};
ExternalCurrentSource
(
std
::
string
name
,
int
src
,
int
dest
,
Real
initCurrent
,
Real
initPhase
);
ExternalCurrentSource
(
std
::
string
name
,
int
src
,
int
dest
,
Complex
current
);
void
setCurrent
(
Real
real
,
Real
imag
);
};
...
...
Source/Components/ExternalVoltageSource.cpp
View file @
b1815d60
...
...
@@ -2,11 +2,10 @@
using
namespace
DPsim
;
ExternalVoltageSource
::
ExternalVoltageSource
(
std
::
string
name
,
int
src
,
int
dest
,
Real
initVoltage
,
Real
initPhas
e
,
int
num
)
:
IdealVoltageSource
(
name
,
src
,
dest
,
initVoltage
,
initPhas
e
,
num
)
{
ExternalVoltageSource
::
ExternalVoltageSource
(
std
::
string
name
,
int
src
,
int
dest
,
Complex
voltag
e
,
int
num
)
:
IdealVoltageSource
(
name
,
src
,
dest
,
voltag
e
,
num
)
{
}
void
ExternalVoltageSource
::
setVoltage
(
Real
real
,
Real
imag
)
{
this
->
mVoltageDiffr
=
real
;
this
->
mVoltageDiffi
=
imag
;
this
->
mVoltage
=
Complex
(
real
,
imag
);
}
Source/Components/ExternalVoltageSource.h
View file @
b1815d60
...
...
@@ -9,7 +9,7 @@ namespace DPsim {
public:
ExternalVoltageSource
()
{};
ExternalVoltageSource
(
std
::
string
name
,
int
src
,
int
dest
,
Real
initVoltage
,
Real
initPhas
e
,
int
num
);
ExternalVoltageSource
(
std
::
string
name
,
int
src
,
int
dest
,
Complex
voltag
e
,
int
num
);
void
setVoltage
(
Real
real
,
Real
imag
);
};
...
...
Source/Components/IdealVoltageSource.cpp
View file @
b1815d60
...
...
@@ -2,10 +2,10 @@
using
namespace
DPsim
;
IdealVoltageSource
::
IdealVoltageSource
(
std
::
string
name
,
int
src
,
int
dest
,
Real
voltage
,
Real
phas
e
,
int
num
)
:
BaseComponent
(
name
,
src
,
dest
)
{
IdealVoltageSource
::
IdealVoltageSource
(
std
::
string
name
,
int
src
,
int
dest
,
Complex
voltag
e
,
int
num
)
:
BaseComponent
(
name
,
src
,
dest
)
{
this
->
number
=
num
;
this
->
mVoltage
Diffr
=
voltage
*
cos
(
phase
)
;
this
->
mVoltageDiffi
=
voltage
*
sin
(
phase
)
;
this
->
mVoltage
=
voltage
;
attrMap
[
"voltage"
]
=
{
AttrComplex
,
&
this
->
mVoltage
}
;
}
void
IdealVoltageSource
::
applySystemMatrixStamp
(
SystemModel
&
system
)
{
...
...
@@ -27,14 +27,14 @@ void IdealVoltageSource::applySystemMatrixStamp(SystemModel& system) {
void
IdealVoltageSource
::
applyRightSideVectorStamp
(
SystemModel
&
system
)
{
// Apply matrix stamp for equivalent current source
system
.
addRealToRightSideVector
(
system
.
getCompOffset
()
-
number
,
mVoltage
Diffr
);
system
.
addRealToRightSideVector
(
2
*
system
.
getCompOffset
()
-
number
,
mVoltage
Diffi
);
system
.
addRealToRightSideVector
(
system
.
getCompOffset
()
-
number
,
mVoltage
.
real
()
);
system
.
addRealToRightSideVector
(
2
*
system
.
getCompOffset
()
-
number
,
mVoltage
.
imag
()
);
}
void
IdealVoltageSource
::
step
(
SystemModel
&
system
,
Real
time
)
{
// Apply matrix stamp for equivalent current source
system
.
addRealToRightSideVector
(
system
.
getCompOffset
()
-
number
,
mVoltage
Diffr
);
system
.
addRealToRightSideVector
(
2
*
system
.
getCompOffset
()
-
number
,
mVoltage
Diffi
);
system
.
addRealToRightSideVector
(
system
.
getCompOffset
()
-
number
,
mVoltage
.
real
()
);
system
.
addRealToRightSideVector
(
2
*
system
.
getCompOffset
()
-
number
,
mVoltage
.
imag
()
);
}
Complex
IdealVoltageSource
::
getCurrent
(
SystemModel
&
system
)
{
...
...
Source/Components/IdealVoltageSource.h
View file @
b1815d60
...
...
@@ -15,9 +15,8 @@ namespace DPsim {
protected:
// ### Ideal Voltage source parameters ###
/// Real and imaginary part of the voltage [V]
Real
mVoltageDiffr
;
Real
mVoltageDiffi
;
/// Complex voltage [V]
Complex
mVoltage
;
Real
mVoltageAtSourcer
;
Real
mVoltageAtSourcei
;
...
...
@@ -33,7 +32,7 @@ namespace DPsim {
IdealVoltageSource
()
{
;
};
/// define paramenters of the voltage source
IdealVoltageSource
(
std
::
string
name
,
int
src
,
int
dest
,
Real
voltage
,
Real
phas
e
,
int
num
);
IdealVoltageSource
(
std
::
string
name
,
int
src
,
int
dest
,
Complex
voltag
e
,
int
num
);
void
init
(
Real
om
,
Real
dt
)
{
}
...
...
Source/Components/VoltSourceRes.cpp
View file @
b1815d60
...
...
@@ -2,16 +2,17 @@
using
namespace
DPsim
;
VoltSourceRes
::
VoltSourceRes
(
std
::
string
name
,
int
src
,
int
dest
,
Real
voltage
,
Real
phase
,
Real
resistance
)
:
BaseComponent
(
name
,
src
,
dest
)
{
this
->
mVoltageDiffr
=
voltage
*
cos
(
phase
);
this
->
mVoltageDiffi
=
voltage
*
sin
(
phase
);
VoltSourceRes
::
VoltSourceRes
(
std
::
string
name
,
int
src
,
int
dest
,
Complex
voltage
,
Real
resistance
)
:
BaseComponent
(
name
,
src
,
dest
)
{
this
->
mVoltage
=
voltage
;
this
->
mResistance
=
resistance
;
this
->
mConductance
=
1.
/
resistance
;
this
->
mCurrentr
=
mVoltageDiffr
/
resistance
;
this
->
mCurrenti
=
mVoltageDiffi
/
resistance
;
attrMap
[
"voltage"
]
=
{
AttrComplex
,
&
this
->
mVoltage
};
attrMap
[
"resistance"
]
=
{
AttrReal
,
&
this
->
mResistance
};
}
void
VoltSourceRes
::
applySystemMatrixStamp
(
SystemModel
&
system
)
{
mConductance
=
1.
/
mResistance
;
mCurrentr
=
mVoltage
.
real
()
/
mResistance
;
mCurrenti
=
mVoltage
.
imag
()
/
mResistance
;
// Apply matrix stamp for equivalent resistance
if
(
mNode1
>=
0
)
{
system
.
addCompToSystemMatrix
(
mNode1
,
mNode1
,
mConductance
,
0
);
...
...
Source/Components/VoltSourceRes.h
View file @
b1815d60
...
...
@@ -14,10 +14,8 @@ namespace DPsim {
protected:
// ### Real Voltage source parameters ###
/// Real part of the voltage [V]
Real
mVoltageDiffr
;
/// Imaginary part of the voltage [V]
Real
mVoltageDiffi
;
/// Complex voltage [V]
Complex
mVoltage
;
/// Resistance [ohm]
Real
mResistance
;
...
...
@@ -34,7 +32,7 @@ namespace DPsim {
VoltSourceRes
()
{
;
};
/// define voltage source paramenters
VoltSourceRes
(
std
::
string
name
,
int
src
,
int
dest
,
Real
voltage
,
Real
phas
e
,
Real
resistance
);
VoltSourceRes
(
std
::
string
name
,
int
src
,
int
dest
,
Complex
voltag
e
,
Real
resistance
);
void
init
(
Real
om
,
Real
dt
)
{
}
...
...
Source/Components/VoltSourceResEMT.cpp
View file @
b1815d60
...
...
@@ -2,16 +2,13 @@
using
namespace
DPsim
;
VoltSourceResEMT
::
VoltSourceResEMT
(
std
::
string
name
,
int
src
,
int
dest
,
Real
voltage
,
Real
phase
,
Real
resistance
)
:
BaseComponent
(
name
,
src
,
dest
)
{
mVoltageAmp
=
voltage
;
mVoltagePhase
=
phase
;
VoltSourceResEMT
::
VoltSourceResEMT
(
std
::
string
name
,
int
src
,
int
dest
,
Complex
voltage
,
Real
resistance
)
:
BaseComponent
(
name
,
src
,
dest
)
{
mVoltage
=
voltage
;
mResistance
=
resistance
;
mVoltageDiff
=
mVoltageAmp
*
cos
(
mVoltagePhase
);
mConductance
=
1.
/
mResistance
;
mCurrent
=
mVoltageDiff
/
mResistance
;
}
void
VoltSourceResEMT
::
applySystemMatrixStamp
(
SystemModel
&
system
)
{
mConductance
=
1.
/
mResistance
;
// Apply matrix stamp for equivalent resistance
if
(
mNode1
>=
0
)
{
system
.
addRealToSystemMatrix
(
mNode1
,
mNode1
,
mConductance
);
...
...
@@ -26,6 +23,7 @@ void VoltSourceResEMT::applySystemMatrixStamp(SystemModel& system) {
}
void
VoltSourceResEMT
::
applyRightSideVectorStamp
(
SystemModel
&
system
)
{
mCurrent
=
mVoltage
.
real
()
/
mResistance
;
// Apply matrix stamp for equivalent current source
if
(
mNode1
>=
0
)
{
system
.
addRealToRightSideVector
(
mNode1
,
mCurrent
);
...
...
@@ -37,7 +35,7 @@ void VoltSourceResEMT::applyRightSideVectorStamp(SystemModel& system) {
void
VoltSourceResEMT
::
step
(
SystemModel
&
system
,
Real
time
)
{
mVoltageDiff
=
mVoltage
Amp
*
cos
(
mVoltage
Phase
+
system
.
getOmega
()
*
time
);
mVoltageDiff
=
std
::
abs
(
mVoltage
)
*
cos
(
std
::
arg
(
mVoltage
)
+
system
.
getOmega
()
*
time
);
mCurrent
=
mVoltageDiff
/
mResistance
;
if
(
mNode1
>=
0
)
{
...
...
Source/Components/VoltSourceResEMT.h
View file @
b1815d60
...
...
@@ -7,6 +7,7 @@ namespace DPsim {
class
VoltSourceResEMT
:
public
BaseComponent
{
protected:
Complex
mVoltage
;
Real
mVoltageAmp
;
Real
mVoltagePhase
;
Real
mVoltageDiff
;
...
...
@@ -16,7 +17,7 @@ namespace DPsim {
public:
VoltSourceResEMT
()
{
;
};
VoltSourceResEMT
(
std
::
string
name
,
int
src
,
int
dest
,
Real
voltage
,
Real
phas
e
,
Real
resistance
);
VoltSourceResEMT
(
std
::
string
name
,
int
src
,
int
dest
,
Complex
voltag
e
,
Real
resistance
);
void
init
(
Real
om
,
Real
dt
)
{
}
void
applySystemMatrixStamp
(
SystemModel
&
system
);
...
...
Source/Examples/ReferenceCircuits.cpp
View file @
b1815d60
...
...
@@ -18,7 +18,7 @@ void DPsim::simulationExample1()
rightVectorLog
(
"Logs/RightVectorLog_"
+
fileName
.
str
()
+
".csv"
);
std
::
vector
<
BaseComponent
*>
circElements0
;
circElements0
.
push_back
(
new
VoltSourceRes
(
"v_in"
,
1
,
0
,
10
,
0
,
1
));
circElements0
.
push_back
(
new
VoltSourceRes
(
"v_in"
,
1
,
0
,
Complex
(
10
,
0
)
,
1
));
circElements0
.
push_back
(
new
Inductor
(
"l_1"
,
1
,
2
,
0.02
));
circElements0
.
push_back
(
new
Inductor
(
"l_2"
,
2
,
0
,
0.1
));
circElements0
.
push_back
(
new
Inductor
(
"l_3"
,
2
,
3
,
0.05
));
...
...
@@ -58,7 +58,7 @@ void DPsim::simulationExample1L2()
rightVectorLog
(
"Logs/RightVectorLog_"
+
fileName
.
str
()
+
".csv"
);
std
::
vector
<
BaseComponent
*>
circElements0
;
circElements0
.
push_back
(
new
VoltSourceRes
(
"v_in"
,
1
,
0
,
10
,
0
,
1
));
circElements0
.
push_back
(
new
VoltSourceRes
(
"v_in"
,
1
,
0
,
Complex
(
10
,
0
)
,
1
));
circElements0
.
push_back
(
new
Inductor
(
"l_1"
,
1
,
2
,
0.02
));
circElements0
.
push_back
(
new
Inductor
(
"l_2"
,
2
,
0
,
0.1
));
circElements0
.
push_back
(
new
Inductor
(
"l_3"
,
2
,
3
,
0.05
));
...
...
@@ -98,7 +98,7 @@ void DPsim::simulationExample2()
rightVectorLog
(
"Logs/RightVectorLog_"
+
fileName
.
str
()
+
".csv"
);
std
::
vector
<
BaseComponent
*>
circElements0
;
circElements0
.
push_back
(
new
VoltSourceRes
(
"v_in"
,
1
,
0
,
10
,
0
,
1
));
circElements0
.
push_back
(
new
VoltSourceRes
(
"v_in"
,
1
,
0
,
Complex
(
10
,
0
)
,
1
));
circElements0
.
push_back
(
new
Inductor
(
"l_1"
,
1
,
2
,
0.02
));
circElements0
.
push_back
(
new
Inductor
(
"l_2"
,
2
,
0
,
0.1
));
...
...
@@ -136,7 +136,7 @@ void DPsim::simulationExample3()
rightVectorLog
(
"Logs/RightVectorLog_"
+
fileName
.
str
()
+
".csv"
);
std
::
vector
<
BaseComponent
*>
circElements0
;
circElements0
.
push_back
(
new
VoltSourceRes
(
"v_in"
,
1
,
0
,
10
,
0
,
1
));
circElements0
.
push_back
(
new
VoltSourceRes
(
"v_in"
,
1
,
0
,
Complex
(
10
,
0
)
,
1
));
circElements0
.
push_back
(
new
Capacitor
(
"c_1"
,
1
,
2
,
0.001
));
circElements0
.
push_back
(
new
Inductor
(
"l_1"
,
2
,
0
,
0.001
));
circElements0
.
push_back
(
new
LinearResistor
(
"r_2"
,
2
,
0
,
1
));
...
...
@@ -175,7 +175,7 @@ void DPsim::simulationExampleIdealVS()
rightVectorLog
(
"Logs/RightVectorLog_"
+
fileName
.
str
()
+
".csv"
);
std
::
vector
<
BaseComponent
*>
circElements0
;
circElements0
.
push_back
(
new
IdealVoltageSource
(
"v_in"
,
1
,
2
,
10
,
0
,
1
));
circElements0
.
push_back
(
new
IdealVoltageSource
(
"v_in"
,
1
,
2
,
Complex
(
10
,
0
)
,
1
));
circElements0
.
push_back
(
new
LinearResistor
(
"r_1"
,
1
,
0
,
1
));
circElements0
.
push_back
(
new
LinearResistor
(
"r_2"
,
2
,
0
,
1
));
circElements0
.
push_back
(
new
LinearResistor
(
"r_3"
,
2
,
0
,
1
));
...
...
@@ -214,7 +214,7 @@ void DPsim::simulationExampleIdealVS2()
rightVectorLog
(
"Logs/RightVectorLog_"
+
fileName
.
str
()
+
".csv"
);
std
::
vector
<
BaseComponent
*>
circElements0
;
circElements0
.
push_back
(
new
IdealVoltageSource
(
"v_in"
,
1
,
0
,
10
,
0
,
1
));
circElements0
.
push_back
(
new
IdealVoltageSource
(
"v_in"
,
1
,
0
,
Complex
(
10
,
0
)
,
1
));
circElements0
.
push_back
(
new
LinearResistor
(
"r_1"
,
1
,
2
,
1
));
circElements0
.
push_back
(
new
Capacitor
(
"c_1"
,
2
,
3
,
0.001
));
circElements0
.
push_back
(
new
Inductor
(
"l_1"
,
3
,
0
,
0.001
));
...
...
@@ -255,13 +255,13 @@ void DPsim::simulationExampleIdealVS3()
rightVectorLog
(
"Logs/RightVectorLog_"
+
fileName
.
str
()
+
".csv"
);
std
::
vector
<
BaseComponent
*>
circElements0
;
circElements0
.
push_back
(
new
IdealVoltageSource
(
"v_1"
,
1
,
0
,
10
,
0
,
1
));
circElements0
.
push_back
(
new
IdealVoltageSource
(
"v_1"
,
1
,
0
,
Complex
(
10
,
0
)
,
1
));
circElements0
.
push_back
(
new
LinearResistor
(
"r_1"
,
1
,
2
,
1
));
circElements0
.
push_back
(
new
LinearResistor
(
"r_2"
,
2
,
0
,
1
));
circElements0
.
push_back
(
new
LinearResistor
(
"r_3"
,
2
,
3
,
1
));
circElements0
.
push_back
(
new
LinearResistor
(
"r_4"
,
3
,
0
,
1
));
circElements0
.
push_back
(
new
LinearResistor
(
"r_5"
,
3
,
4
,
1
));
circElements0
.
push_back
(
new
IdealVoltageSource
(
"v_2"
,
4
,
0
,
20
,
0
,
2
));
circElements0
.
push_back
(
new
IdealVoltageSource
(
"v_2"
,
4
,
0
,
Complex
(
20
,
0
)
,
2
));
...
...
@@ -300,7 +300,7 @@ void DPsim::simulationExampleRXLine()
rightVectorLog
(
"Logs/RightVectorLog_"
+
fileName
.
str
()
+
".csv"
);
std
::
vector
<
BaseComponent
*>
circElements0
;
circElements0
.
push_back
(
new
IdealVoltageSource
(
"v_1"
,
1
,
0
,
10
,
0
,
1
));
circElements0
.
push_back
(
new
IdealVoltageSource
(
"v_1"
,
1
,
0
,
Complex
(
10
,
0
)
,
1
));
circElements0
.
push_back
(
new
RxLine
(
"Line_1"
,
1
,
2
,
3
,
0.1
,
0.001
));
circElements0
.
push_back
(
new
LinearResistor
(
"r_1"
,
2
,
0
,
20
));
...
...
@@ -339,7 +339,7 @@ void DPsim::simulationExampleRXLine2()
rightVectorLog
(
"Logs/RightVectorLog_"
+
fileName
.
str
()
+
".csv"
);
std
::
vector
<
BaseComponent
*>
circElements0
;
circElements0
.
push_back
(
new
IdealVoltageSource
(
"v_1"
,
1
,
0
,
10
,
0
,
1
));
circElements0
.
push_back
(
new
IdealVoltageSource
(
"v_1"
,
1
,
0
,
Complex
(
10
,
0
)
,
1
));
circElements0
.
push_back
(
new
Inductor
(
"l_L"
,
2
,
3
,
0.001
));
circElements0
.
push_back
(
new
LinearResistor
(
"r_L"
,
1
,
2
,
0.1
));
...
...
@@ -380,7 +380,7 @@ void DPsim::simulationExampleRXLine3()
rightVectorLog
(
"Logs/RightVectorLog_"
+
fileName
.
str
()
+
".csv"
);
std
::
vector
<
BaseComponent
*>
circElements0
;
circElements0
.
push_back
(
new
IdealVoltageSource
(
"v_1"
,
1
,
0
,
10
,
0
,
1
));
circElements0
.
push_back
(
new
IdealVoltageSource
(
"v_1"
,
1
,
0
,
Complex
(
10
,
0
)
,
1
));
circElements0
.
push_back
(
new
RxLine
(
"Line_1"
,
1
,
2
,
0.1
,
0.001
));
circElements0
.
push_back
(
new
LinearResistor
(
"r_1"
,
2
,
0
,
20
));
...
...
@@ -419,7 +419,7 @@ void DPsim::simulationExamplePiLine()
rightVectorLog
(
"Logs/RightVectorLog_"
+
fileName
.
str
()
+
".csv"
);
std
::
vector
<
BaseComponent
*>
circElements0
;
circElements0
.
push_back
(
new
IdealVoltageSource
(
"v_1"
,
1
,
0
,
345
,
0
,
1
));
circElements0
.
push_back
(
new
IdealVoltageSource
(
"v_1"
,
1
,
0
,
Complex
(
345
,
0
)
,
1
));
circElements0
.
push_back
(
new
LinearResistor
(
"r1"
,
1
,
2
,
5
));
circElements0
.
push_back
(
new
PiLine
(
"PiLine1"
,
2
,
3
,
4
,
6.4
,
0.186
,
0.004
));
circElements0
.
push_back
(
new
LinearResistor
(
"r_load"
,
3
,
0
,
150
));
...
...
@@ -460,7 +460,7 @@ void DPsim::simulationExamplePiLine2()
rightVectorLog
(
"Logs/RightVectorLog_"
+
fileName
.
str
()
+
".csv"
);
std
::
vector
<
BaseComponent
*>
circElements0
;
circElements0
.
push_back
(
new
IdealVoltageSource
(
"v_1"
,
1
,
0
,
345
,
0
,
1
));
circElements0
.
push_back
(
new
IdealVoltageSource
(
"v_1"
,
1
,
0
,
Complex
(
345
,
0
)
,
1
));
circElements0
.
push_back
(
new
LinearResistor
(
"r1"
,
1
,
2
,
5
));
circElements0
.
push_back
(
new
Capacitor
(
"c_1"
,
2
,
0
,
0.002
));
circElements0
.
push_back
(
new
LinearResistor
(
"r_load"
,
2
,
4
,
6.4
));
...
...
Source/Examples/ShmemTest.cpp
View file @
b1815d60
...
...
@@ -14,7 +14,7 @@ void DPsim::shmemExample()
Logger
log
(
"output.log"
),
llog
(
"lvector.log"
),
rlog
(
"rvector.log"
);
std
::
vector
<
BaseComponent
*>
comps
;
ExternalVoltageSource
*
evs
=
new
ExternalVoltageSource
(
"v_s"
,
1
,
0
,
0
,
0
,
1
);
ExternalVoltageSource
*
evs
=
new
ExternalVoltageSource
(
"v_s"
,
1
,
0
,
Complex
(
0
,
0
)
,
1
);
comps
.
push_back
(
evs
);
comps
.
push_back
(
new
LinearResistor
(
"r_s"
,
1
,
2
,
1
));
comps
.
push_back
(
new
LinearResistor
(
"r_line"
,
2
,
3
,
1
));
...
...
@@ -53,7 +53,7 @@ void DPsim::shmemRTExample()
conf
.
polling
=
false
;
Logger
log
;
ExternalVoltageSource
*
evs
=
new
ExternalVoltageSource
(
"v_s"
,
1
,
0
,
0
,
0
,
1
);
ExternalVoltageSource
*
evs
=
new
ExternalVoltageSource
(
"v_s"
,
1
,
0
,
Complex
(
0
,
0
)
,
1
);
comps
.
push_back
(
evs
);
comps
.
push_back
(
new
LinearResistor
(
"r_s"
,
1
,
2
,
1
));
comps
.
push_back
(
new
LinearResistor
(
"r_line"
,
2
,
3
,
1
));
...
...
@@ -101,15 +101,15 @@ void DPsim::shmemDistributedDirect(int argc, char *argv[])
}
if
(
!
strcmp
(
argv
[
1
],
"0"
))
{
comps
.
push_back
(
new
VoltSourceRes
(
"v_s"
,
1
,
0
,
10000
,
0
,
1
));
comps
.
push_back
(
new
VoltSourceRes
(
"v_s"
,
1
,
0
,
Complex
(
10000
,
0
)
,
1
));
comps
.
push_back
(
new
Inductor
(
"l_1"
,
1
,
2
,
1e-3
));
ExternalVoltageSource
*
evs
=
new
ExternalVoltageSource
(
"v_t"
,
2
,
0
,
0
,
0
,
1
);
ExternalVoltageSource
*
evs
=
new
ExternalVoltageSource
(
"v_t"
,
2
,
0
,
Complex
(
0
,
0
)
,
1
);
comps
.
push_back
(
evs
);
shmem
=
new
ShmemInterface
(
"/dpsim01"
,
"/dpsim10"
,
&
conf
);
shmem
->
registerVoltageSource
(
evs
,
0
,
1
);
shmem
->
registerExportedCurrent
(
evs
,
0
,
1
);
}
else
if
(
!
strcmp
(
argv
[
1
],
"1"
))
{
ExternalCurrentSource
*
ecs
=
new
ExternalCurrentSource
(
"v_s"
,
1
,
0
,
0
,
0
);
ExternalCurrentSource
*
ecs
=
new
ExternalCurrentSource
(
"v_s"
,
1
,
0
,
Complex
(
0
,
0
)
)
;
comps
.
push_back
(
ecs
);
comps
.
push_back
(
new
LinearResistor
(
"r_2"
,
1
,
0
,
1
));
shmem
=
new
ShmemInterface
(
"/dpsim10"
,
"/dpsim01"
,
&
conf
);
...
...
@@ -154,17 +154,17 @@ void DPsim::shmemDistributed(int argc, char *argv[])
if
(
!
strcmp
(
argv
[
1
],
"0"
))
{
logname
=
"lvector0.log"
;
comps
.
push_back
(
new
VoltSourceRes
(
"v_s"
,
1
,
0
,
10000
,
0
,
1
));
comps
.
push_back
(
new
VoltSourceRes
(
"v_s"
,
1
,
0
,
Complex
(
10000
,
0
)
,
1
));
comps
.
push_back
(
new
Inductor
(
"l_1"
,
1
,
2
,
0.1
));
comps
.
push_back
(
new
LinearResistor
(
"r_1"
,
2
,
3
,
1
));
ExternalVoltageSource
*
evs
=
new
ExternalVoltageSource
(
"v_t"
,
3
,
0
,
0
,
0
,
1
);
ExternalVoltageSource
*
evs
=
new
ExternalVoltageSource
(
"v_t"
,
3
,
0
,
Complex
(
0
,
0
)
,
1
);
comps
.
push_back
(
evs
);
shmem
=
new
ShmemInterface
(
"/villas1-in"
,
"/villas1-out"
,
&
conf
);
shmem
->
registerVoltageSource
(
evs
,
0
,
1
);
shmem
->
registerExportedCurrent
(
evs
,
0
,
1
);
}
else
if
(
!
strcmp
(
argv
[
1
],
"1"
))
{
logname
=
"lvector1.log"
;
ExternalCurrentSource
*
ecs
=
new
ExternalCurrentSource
(
"v_s"
,
1
,
0
,
0
,
0
);
ExternalCurrentSource
*
ecs
=
new
ExternalCurrentSource
(
"v_s"
,
1
,
0
,
Complex
(
0
,
0
)
)
;
comps
.
push_back
(
ecs
);
comps
.
push_back
(
new
LinearResistor
(
"r_2"
,
1
,
0
,
10
));
shmem
=
new
ShmemInterface
(
"/villas2-in"
,
"/villas2-out"
,
&
conf
);
...
...
@@ -207,7 +207,7 @@ void DPsim::shmemDistributedRef()
Logger
log
(
"output.log"
),
llog
(
"lvector.log"
),
rlog
(
"rvector.log"
);
std
::
vector
<
BaseComponent
*>
comps
,
comps2
;
comps
.
push_back
(
new
VoltSourceRes
(
"v_s"
,
1
,
0
,
10000
,
0
,
1
));
comps
.
push_back
(
new
VoltSourceRes
(
"v_s"
,
1
,
0
,
Complex
(
10000
,
0
)
,
1
));
comps
.
push_back
(
new
Inductor
(
"l_1"
,
1
,
2
,
0.1
));
comps
.
push_back
(
new
LinearResistor
(
"r_1"
,
2
,
3
,
1
));
comps2
=
comps
;
...
...
Source/Examples/SimpleCircuitTest.cpp
View file @
b1815d60
...
...
@@ -18,7 +18,7 @@ void DPsim::RXLineResLoad() {
// Declare circuit components
std
::
vector
<
BaseComponent
*>
circElements0
,
circElements1
,
circElements2
;
circElements0
.
push_back
(
new
VoltSourceRes
(
"v_s"
,
1
,
0
,
10000
,
0
,
1
));
circElements0
.
push_back
(
new
VoltSourceRes
(
"v_s"
,
1
,
0
,
Complex
(
10000
,
0
)
,
1
));
circElements0
.
push_back
(
new
LinearResistor
(
"r_line"
,
1
,
2
,
1
));
circElements0
.
push_back
(
new
Inductor
(
"l_line"
,
2
,
3
,
1
));
circElements1
=
circElements0
;
...
...
@@ -96,7 +96,7 @@ void DPsim::RXLineResLoadEMT() {
// Declare circuit components
std
::
vector
<
BaseComponent
*>
circElements0
,
circElements1
,
circElements2
;
circElements0
.
push_back
(
new
VoltSourceResEMT
(
"v_s"
,
1
,
0
,
10000
,
0
,
1
));
circElements0
.
push_back
(
new
VoltSourceResEMT
(
"v_s"
,
1
,
0
,
Complex
(
10000
,
0
)
,
1
));
circElements0
.
push_back
(
new
LinearResistorEMT
(
"r_line"
,
1
,
2
,
1
));
circElements0
.
push_back
(
new
InductorEMT
(
"l_line"
,
2
,
3
,
1
));
circElements1
=
circElements0
;
...
...
@@ -215,7 +215,7 @@ void DPsim::RTExample() {
std
::
vector
<
BaseComponent
*>
comps
;
Logger
log
;
comps
.
push_back
(
new
VoltSourceRes
(
"v_s"
,
1
,
0
,
10000
,
0
,
1
));
comps
.
push_back
(
new
VoltSourceRes
(
"v_s"
,
1
,
0
,
Complex
(
10000
,
0
)
,
1
));
comps
.
push_back
(
new
LinearResistor
(
"r_line"
,
1
,
2
,
1
));
comps
.
push_back
(
new
Inductor
(
"l_line"
,
2
,
3
,
1
));
comps
.
push_back
(
new
LinearResistor
(
"r_load"
,
3
,
0
,
1000
));
...
...
Source/PyComponent.cpp
View file @
b1815d60
...
...
@@ -82,6 +82,11 @@ PyObject* PyComponent::getattr(PyComponent* self, char* name) {
return
PyFloat_FromDouble
(
*
((
Real
*
)
attr
.
value
));
case
AttrInt
:
return
PyLong_FromLong
(
*
((
Integer
*
)
attr
.
value
));
case
AttrString
:
return
PyUnicode_FromString
(((
std
::
string
*
)
attr
.
value
)
->
c_str
());
case
AttrComplex
:
Complex
c
=
*
((
Complex
*
)
attr
.
value
);
return
PyComplex_FromDoubles
(
c
.
real
(),
c
.
imag
());
}
PyErr_Format
(
PyExc_SystemError
,
"invalid type in internal attribute map"
);
return
nullptr
;
...
...
@@ -115,6 +120,16 @@ int PyComponent::setattr(PyComponent* self, char* name, PyObject *v) {
return
-
1
;
*
((
Integer
*
)
attr
.
value
)
=
i
;
break
;
case
AttrString
:
if
(
!
PyUnicode_Check
(
v
))
return
-
1
;
*
((
std
::
string
*
)
attr
.
value
)
=
std
::
string
(
PyUnicode_AsUTF8
(
v
));
break
;
case
AttrComplex
:
if
(
!
PyComplex_Check
(
v
))
return
-
1
;
*
((
Complex
*
)
attr
.
value
)
=
Complex
(
PyComplex_RealAsDouble
(
v
),
PyComplex_ImagAsDouble
(
v
));
break
;
default:
PyErr_Format
(
PyExc_SystemError
,
"invalid type in internal attribute map"
);
return
-
1
;
...
...
Source/SystemModel.cpp
View file @
b1815d60
...
...
@@ -37,6 +37,10 @@ void SystemModel::addCompToSystemMatrix(Int row, Int column, Real reValue, Real
mSystemMatrix
(
row
+
mCompOffset
,
column
)
=
mSystemMatrix
(
row
+
mCompOffset
,
column
)
+
imValue
;
}
void
SystemModel
::
addCompToSystemMatrix
(
Int
row
,
Int
column
,
Complex
value
)
{
addCompToSystemMatrix
(
row
,
column
,
value
.
real
(),
value
.
imag
());
}
void
SystemModel
::
addCompToRightSideVector
(
Int
row
,
Real
reValue
,
Real
imValue
)
{
mRightSideVector
(
row
,
0
)
=
mRightSideVector
(
row
,
0
)
+
reValue
;
mRightSideVector
(
row
+
mCompOffset
,
0
)
=
mRightSideVector
(
row
+
mCompOffset
,
0
)
+
imValue
;
...
...
Source/SystemModel.h
View file @
b1815d60
...
...
@@ -77,6 +77,7 @@ namespace DPsim {
void
switchSystemMatrix
(
Int
systemMatrixIndex
);
void
addRealToSystemMatrix
(
Int
row
,
Int
column
,
Real
value
);
void
addCompToSystemMatrix
(
Int
row
,
Int
column
,
Real
reValue
,
Real
imValue
);
void
addCompToSystemMatrix
(
Int
row
,
Int
column
,
Complex
value
);
void
addCompToRightSideVector
(
Int
row
,
Real
reValue
,
Real
imValue
);
void
addRealToRightSideVector
(
Int
row
,
Real
value
);
void
setRightSideVectorToZero
();
...
...
Prev
1
2
Next
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment