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
d09d1b55
Commit
d09d1b55
authored
Sep 21, 2017
by
Georg Martin Reinke
Browse files
add shmem Python example
Former-commit-id:
905ff699
parent
cfd9a483
Changes
4
Hide whitespace changes
Inline
Side-by-side
Source/Examples/shmem1.py
0 → 100755
View file @
d09d1b55
#!/usr/bin/python3
import
dpsim
comps
=
[
dpsim
.
VoltSourceRes
(
"v_s"
,
1
,
0
,
10000
+
0j
,
1
),
dpsim
.
Inductor
(
"l_1"
,
1
,
2
,
1e-3
)]
evs
=
dpsim
.
ExternalVoltageSource
(
"v_ext"
,
2
,
0
,
0
+
0j
,
1
)
comps
.
append
(
evs
)
intf
=
dpsim
.
ShmemInterface
(
"/dpsim12"
,
"/dpsim21"
,
samplelen
=
2
)
intf
.
register_source
(
evs
,
0
,
1
)
intf
.
export_current
(
evs
,
0
,
1
)
sim
=
dpsim
.
Simulation
(
comps
,
duration
=
1
,
llog
=
"lvector-shmem1.csv"
)
sim
.
add_interface
(
intf
)
sim
.
start
()
sim
.
wait
()
Source/Examples/shmem2.py
0 → 100755
View file @
d09d1b55
#!/usr/bin/python3
import
dpsim
comps
=
[
dpsim
.
LinearResistor
(
"r_1"
,
1
,
0
,
1
)]
ecs
=
dpsim
.
ExternalCurrentSource
(
"i_ext"
,
1
,
0
,
0
+
0j
)
comps
.
append
(
ecs
)
intf
=
dpsim
.
ShmemInterface
(
"/dpsim21"
,
"/dpsim12"
,
samplelen
=
2
)
intf
.
register_source
(
ecs
,
0
,
1
)
intf
.
export_voltage
(
1
,
0
,
0
,
1
)
sim
=
dpsim
.
Simulation
(
comps
,
duration
=
1
,
llog
=
"lvector-shmem2.csv"
)
sim
.
add_interface
(
intf
)
sim
.
start
()
sim
.
wait
()
Source/ShmemInterface.cpp
View file @
d09d1b55
...
...
@@ -13,7 +13,12 @@ using namespace DPsim;
void
ShmemInterface
::
init
(
const
char
*
wname
,
const
char
*
rname
,
struct
shmem_conf
*
conf
)
{
/* using a static shmem_conf as a default argument for the constructor
* doesn't seem to work, so use this as a workaround */
if
(
shmem_int_open
(
wname
,
rname
,
&
this
->
mShmem
,
conf
)
<
0
)
{
// make local copies of the filenames, because shmem_int doesn't make copies
// and needs them for the close function
this
->
wname
=
std
::
string
(
wname
);
this
->
rname
=
std
::
string
(
rname
);
if
(
shmem_int_open
(
this
->
wname
.
c_str
(),
this
->
rname
.
c_str
(),
&
this
->
mShmem
,
conf
)
<
0
)
{
std
::
perror
(
"Failed to open/map shared memory object"
);
std
::
exit
(
1
);
}
...
...
Source/ShmemInterface.h
View file @
d09d1b55
...
...
@@ -22,6 +22,7 @@ namespace DPsim {
struct
shmem_int
mShmem
;
struct
sample
*
mLastSample
;
int
mSeq
;
std
::
string
rname
,
wname
;
void
init
(
const
char
*
wname
,
const
char
*
rname
,
struct
shmem_conf
*
conf
);
...
...
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