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
075b0d50
Commit
075b0d50
authored
Apr 27, 2017
by
Georg Martin Reinke
Browse files
add support for external current sources
Former-commit-id:
95974fdc
parent
ca60fa47
Changes
5
Hide whitespace changes
Inline
Side-by-side
Source/Components/ExternalCurrentSource.cpp
0 → 100644
View file @
075b0d50
#include
"ExternalCurrentSource.h"
using
namespace
DPsim
;
ExternalCurrentSource
::
ExternalCurrentSource
(
std
::
string
name
,
int
src
,
int
dest
,
Real
current
,
Real
phase
)
:
CurrentSource
(
name
,
src
,
dest
,
current
,
phase
)
{
this
->
mPhase
=
phase
;
}
void
ExternalCurrentSource
::
setCurrent
(
Real
current
)
{
this
->
currentr
=
current
*
cos
(
this
->
mPhase
);
this
->
currenti
=
current
*
sin
(
this
->
mPhase
);
}
Source/Components/ExternalCurrentSource.h
0 → 100644
View file @
075b0d50
#pragma once
#include
"CurrentSource.h"
namespace
DPsim
{
/** Ideal current source, but the current value can be changed between simulation
* steps (for example for interfacing with another simulator) */
class
ExternalCurrentSource
:
public
CurrentSource
{
private:
Real
mPhase
;
public:
ExternalCurrentSource
()
{};
ExternalCurrentSource
(
std
::
string
name
,
int
src
,
int
dest
,
Real
current
,
Real
phase
);
void
setCurrent
(
Real
current
);
};
}
Source/Examples/VillasTest.cpp
View file @
075b0d50
...
...
@@ -7,16 +7,16 @@ using namespace DPsim;
void
DPsim
::
villasExample
()
{
// Very simple test circuit. Just 2 resistors and a
voltage
read from VILLASnode.
// Very simple test circuit. Just 2 resistors and a
current
read from VILLASnode.
Logger
log
,
llog
,
rlog
;
std
::
vector
<
BaseComponent
*>
comps
;
External
Voltage
Source
*
e
v
s
=
new
External
Voltage
Source
(
"
v
1"
,
1
,
0
,
5
,
0
,
1
);
comps
.
push_back
(
e
v
s
);
External
Current
Source
*
e
c
s
=
new
External
Current
Source
(
"
i
1"
,
1
,
0
,
0
,
0
);
comps
.
push_back
(
e
c
s
);
comps
.
push_back
(
new
LinearResistor
(
"r1"
,
1
,
2
,
1
));
comps
.
push_back
(
new
LinearResistor
(
"r
2
"
,
2
,
0
,
1
));
comps
.
push_back
(
new
LinearResistor
(
"r
1
"
,
2
,
0
,
1
));
VillasInterface
*
villas
=
new
VillasInterface
(
"/villas1"
);
villas
->
register
Voltage
Source
(
e
v
s
,
0
);
villas
->
register
Current
Source
(
e
c
s
,
0
);
// Set up simulation
Real
timeStep
=
0.01
;
...
...
Source/VillasInterface.cpp
View file @
075b0d50
...
...
@@ -25,6 +25,10 @@ void VillasInterface::registerVoltageSource(ExternalVoltageSource *evs, int num)
mExtComponents
[
num
]
=
evs
;
}
void
VillasInterface
::
registerCurrentSource
(
ExternalCurrentSource
*
ecs
,
int
num
)
{
mExtComponents
[
num
]
=
ecs
;
}
void
VillasInterface
::
readValues
()
{
struct
sample
*
sample
;
int
ret
=
0
;
...
...
@@ -42,8 +46,11 @@ void VillasInterface::readValues() {
// TODO integer format?
ExternalVoltageSource
*
evs
=
dynamic_cast
<
ExternalVoltageSource
*>
(
it
->
second
);
if
(
evs
)
evs
->
setVoltage
(
sample
->
data
[
0
].
f
);
// TODO other classes
evs
->
setVoltage
(
sample
->
data
[
it
->
first
].
f
);
ExternalCurrentSource
*
ecs
=
dynamic_cast
<
ExternalCurrentSource
*>
(
it
->
second
);
if
(
ecs
)
ecs
->
setCurrent
(
sample
->
data
[
it
->
first
].
f
);
sample_put
(
sample
);
}
}
Source/VillasInterface.h
View file @
075b0d50
...
...
@@ -6,6 +6,7 @@
#include
<villas/shmem.h>
#include
"ExternalInterface.h"
#include
"Components/ExternalCurrentSource.h"
#include
"Components/ExternalVoltageSource.h"
namespace
DPsim
{
...
...
@@ -21,6 +22,7 @@ namespace DPsim {
VillasInterface
(
const
char
*
name
);
~
VillasInterface
();
void
registerVoltageSource
(
ExternalVoltageSource
*
evs
,
int
num
);
void
registerCurrentSource
(
ExternalCurrentSource
*
ecs
,
int
num
);
virtual
void
readValues
();
};
};
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