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
6e218cb3
Commit
6e218cb3
authored
May 03, 2017
by
Georg Martin Reinke
Browse files
restructure external interface a bit
Former-commit-id:
87e56509
parent
075b0d50
Changes
4
Show whitespace changes
Inline
Side-by-side
Source/ExternalInterface.cpp
0 → 100644
View file @
6e218cb3
#include
"ExternalInterface.h"
using
namespace
DPsim
;
void
ExternalInterface
::
registerVoltageSource
(
ExternalVoltageSource
*
evs
,
int
num
)
{
int
sz
=
mExtComponents
.
size
();
if
(
num
>=
sz
)
{
mExtComponents
.
reserve
(
num
+
1
);
for
(
int
i
=
sz
;
i
<
num
;
i
++
)
mExtComponents
[
i
]
=
NULL
;
}
mExtComponents
[
num
]
=
evs
;
}
void
ExternalInterface
::
registerCurrentSource
(
ExternalCurrentSource
*
ecs
,
int
num
)
{
int
sz
=
mExtComponents
.
size
();
if
(
num
>=
sz
)
{
mExtComponents
.
reserve
(
num
+
1
);
for
(
int
i
=
sz
;
i
<
num
;
i
++
)
mExtComponents
[
i
]
=
NULL
;
}
mExtComponents
[
num
]
=
ecs
;
}
Source/ExternalInterface.h
View file @
6e218cb3
#pragma once
#include
<vector>
#include
"Components/ExternalCurrentSource.h"
#include
"Components/ExternalVoltageSource.h"
namespace
DPsim
{
/** Abstract base class for interfacing the simulator with other data sources or sinks.
* After an ExternalInterface is created, components that should use values
...
...
@@ -9,7 +14,11 @@ namespace DPsim {
* components.
*/
class
ExternalInterface
{
protected:
std
::
vector
<
BaseComponent
*>
mExtComponents
;
public:
void
registerVoltageSource
(
ExternalVoltageSource
*
evs
,
int
num
);
void
registerCurrentSource
(
ExternalCurrentSource
*
ecs
,
int
num
);
virtual
void
readValues
()
=
0
;
virtual
~
ExternalInterface
()
{};
};
...
...
Source/VillasInterface.cpp
View file @
6e218cb3
...
...
@@ -21,14 +21,6 @@ VillasInterface::~VillasInterface() {
shmem_shared_close
(
mShmem
,
mBase
);
}
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
;
...
...
@@ -38,19 +30,22 @@ void VillasInterface::readValues() {
std
::
cerr
<<
"Fatal error: failed to read sample from shmem interface"
<<
std
::
endl
;
std
::
exit
(
1
);
}
for
(
auto
it
=
mExtComponents
.
begin
();
it
!
=
mExtComponents
.
end
();
++
it
)
{
if
(
sample
->
length
<
=
it
->
first
)
{
int
sz
=
mExtComponents
.
size
();
if
(
sample
->
length
<
mExtComponents
.
size
()
)
{
std
::
cerr
<<
"Warning: missing data in received sample"
<<
std
::
endl
;
continue
;
sz
=
sample
->
length
;
}
for
(
int
i
=
0
;
i
<
sz
;
i
++
)
{
// TODO integer format?
ExternalVoltageSource
*
evs
=
dynamic_cast
<
ExternalVoltageSource
*>
(
it
->
second
);
if
(
i
<
mExtComponents
.
size
())
{
ExternalVoltageSource
*
evs
=
dynamic_cast
<
ExternalVoltageSource
*>
(
mExtComponents
[
i
]);
if
(
evs
)
evs
->
setVoltage
(
sample
->
data
[
i
t
->
first
].
f
);
evs
->
setVoltage
(
sample
->
data
[
i
].
f
);
ExternalCurrentSource
*
ecs
=
dynamic_cast
<
ExternalCurrentSource
*>
(
it
->
second
);
ExternalCurrentSource
*
ecs
=
dynamic_cast
<
ExternalCurrentSource
*>
(
mExtComponents
[
i
]
);
if
(
ecs
)
ecs
->
setCurrent
(
sample
->
data
[
it
->
first
].
f
);
ecs
->
setCurrent
(
sample
->
data
[
i
].
f
);
}
sample_put
(
sample
);
}
}
Source/VillasInterface.h
View file @
6e218cb3
...
...
@@ -17,12 +17,9 @@ namespace DPsim {
struct
shmem_shared
*
mShmem
;
void
*
mBase
;
std
::
unordered_map
<
int
,
BaseComponent
*>
mExtComponents
;
public:
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