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
19464677
Commit
19464677
authored
Sep 25, 2018
by
Markus Mirz
Browse files
remove functions not supported in windows
Former-commit-id:
adeae4cc
parent
858f83b8
Changes
7
Hide whitespace changes
Inline
Side-by-side
Include/dpsim/Python/Simulation.h
View file @
19464677
...
...
@@ -38,10 +38,12 @@
#endif
#include
<dpsim/Config.h>
#include
<dpsim/Timer.h>
#include
<dpsim/Simulation.h>
#include
<dpsim/Python/SystemTopology.h>
#include
<dpsim/Simulation.h>
#ifndef _MSC_VER
#include
<dpsim/Python/EventChannel.h>
#include
<dpsim/Timer.h>
#endif
namespace
DPsim
{
namespace
Python
{
...
...
@@ -64,7 +66,9 @@ namespace Python {
DPsim
::
Simulation
::
Ptr
sim
;
Python
::
SystemTopology
*
pySys
;
#ifndef _MSC_VER
Python
::
EventChannel
*
channel
;
#endif
std
::
condition_variable
*
cond
;
std
::
mutex
*
mut
;
...
...
@@ -79,7 +83,9 @@ namespace Python {
bool
failOnOverrun
;
bool
singleStepping
;
/// Debugger like stepping for simulations
#ifndef _MSC_VER
Timer
::
StartTimePoint
startTime
;
#endif
// List of additional objects that aren't directly used from Simulation
// methods, but that a reference has be kept to to avoid them from being
...
...
Include/dpsim/Timer.h
View file @
19464677
...
...
@@ -125,15 +125,21 @@ struct timespec to_timespec(std::chrono::duration<Rep, Period> dur) {
#include
<iostream>
#include
<ctime>
#ifndef _MSC_VER
template
<
typename
Clock
,
typename
Duration
>
std
::
ostream
&
operator
<<
(
std
::
ostream
&
stream
,
const
std
::
chrono
::
time_point
<
Clock
,
Duration
>
&
time_point
)
{
const
time_t
time
=
Clock
::
to_time_t
(
time_point
);
const
std
::
time_t
time
=
Clock
::
to_time_t
(
time_point
);
#if __GNUC__ > 4 || ((__GNUC__ == 4) && __GNUC_MINOR__ > 8 && __GNUC_REVISION__ > 1)
// Maybe the put_time will be implemented later?
struct
tm
tm
;
localtime_r
(
&
time
,
&
tm
);
return
stream
<<
std
::
put_time
(
&
tm
,
"%c"
);
// Print standard date&time
#elif defined _MSC_VER
char
buffer
[
26
];
ctime_s
(
buffer
,
26
,
&
time
);
buffer
[
24
]
=
'\0'
;
// Removes the newline that is added
return
stream
<<
buffer
;
#else
char
buffer
[
26
];
ctime_r
(
&
time
,
buffer
);
...
...
@@ -141,6 +147,7 @@ std::ostream &operator<<(std::ostream &stream,
return
stream
<<
buffer
;
#endif
}
#endif
template
<
typename
Rep
,
typename
Period
>
std
::
ostream
&
operator
<<
(
std
::
ostream
&
stream
,
...
...
Source/Python/CMakeLists.txt
View file @
19464677
execute_process
(
COMMAND
${
PYTHON_EXECUTABLE
}
-c
"import sysconfig; print(sysconfig.get_path('platlib'), end='')"
OUTPUT_VARIABLE PYTHON_PKGPATH
)
execute_process
(
COMMAND
${
PYTHON_EXECUTABLE
}
-c
"import sysconfig; print(sysconfig.get_config_var('EXT_SUFFIX'), end='')"
OUTPUT_VARIABLE PYTHON_EXT_SUFFIX
)
if
(
NOT WIN32
)
list
(
APPEND PYTHON_UNIX_SOURCES
Interface.cpp
EventChannel.cpp
)
elseif
()
endif
()
add_library
(
dpsim_python SHARED
Module.cpp
Simulation.cpp
Component.cpp
Node.cpp
Interface.cpp
Logger.cpp
LoadCim.cpp
SystemTopology.cpp
EventChannel.cpp
Utils.cpp
SystemTopology.cpp
Utils.cpp
${
PYTHON_UNIX_SOURCES
}
${
CMAKE_BINARY_DIR
}
/Include/dpsim/Python/ComponentConstructors.h
)
...
...
Source/Python/Interface.cpp
View file @
19464677
...
...
@@ -363,7 +363,6 @@ int Python::Interface::init(Python::Interface *self, PyObject *args, PyObject *k
}
PyMemberDef
Python
::
Interface
::
members
[]
=
{
#ifdef WITH_SHMEM
{(
char
*
)
"wname"
,
T_STRING
,
offsetof
(
Python
::
Interface
,
wname
),
READONLY
,
nullptr
},
{(
char
*
)
"rname"
,
T_STRING
,
offsetof
(
Python
::
Interface
,
rname
),
READONLY
,
nullptr
},
{(
char
*
)
"queuelen"
,
T_INT
,
offsetof
(
Python
::
Interface
,
conf
.
queuelen
),
READONLY
,
nullptr
},
...
...
@@ -371,7 +370,6 @@ PyMemberDef Python::Interface::members[] = {
{(
char
*
)
"polling"
,
T_INT
,
offsetof
(
Python
::
Interface
,
conf
.
polling
),
READONLY
,
nullptr
},
{(
char
*
)
"exports"
,
T_OBJECT
,
offsetof
(
Python
::
Interface
,
pyExports
),
READONLY
,
nullptr
},
{
nullptr
}
#endif
};
PyMethodDef
Python
::
Interface
::
methods
[]
=
{
...
...
Source/Python/Module.cpp
View file @
19464677
...
...
@@ -34,8 +34,10 @@
#include
<dpsim/Python/Node.h>
#include
<dpsim/Python/SystemTopology.h>
#include
<dpsim/Python/Simulation.h>
#include
<dpsim/Python/Interface.h>
#include
<dpsim/Python/LoadCim.h>
#ifndef _MSC_VER
#include
<dpsim/Python/Interface.h>
#endif
#include
<cps/Components.h>
...
...
@@ -67,8 +69,10 @@ PyMODINIT_FUNC PyInit__dpsim(void) {
return
nullptr
;
if
(
PyType_Ready
(
&
SystemTopology
::
type
)
<
0
)
return
nullptr
;
#ifndef _MSC_VER
if
(
PyType_Ready
(
&
Interface
::
type
)
<
0
)
return
nullptr
;
#endif
m
=
PyModule_Create
(
&
dpsimModule
);
if
(
!
m
)
...
...
@@ -80,8 +84,10 @@ PyMODINIT_FUNC PyInit__dpsim(void) {
PyModule_AddObject
(
m
,
"SystemTopology"
,
(
PyObject
*
)
&
SystemTopology
::
type
);
Py_INCREF
(
&
Component
::
type
);
PyModule_AddObject
(
m
,
"Component"
,
(
PyObject
*
)
&
Component
::
type
);
#ifndef _MSC_VER
Py_INCREF
(
&
Interface
::
type
);
PyModule_AddObject
(
m
,
"Interface"
,
(
PyObject
*
)
&
Interface
::
type
);
#endif
Py_INCREF
(
&
Node
<
CPS
::
Complex
>::
type
);
PyModule_AddObject
(
m
,
"_dp_Node"
,
(
PyObject
*
)
&
Node
<
CPS
::
Complex
>::
type
);
Py_INCREF
(
&
Node
<
CPS
::
Real
>::
type
);
...
...
Source/Python/Simulation.cpp
View file @
19464677
...
...
@@ -25,12 +25,14 @@
#include
<iostream>
#include
<dpsim/Config.h>
#include
<dpsim/RealTimeSimulation.h>
#include
<dpsim/Python/Simulation.h>
#include
<dpsim/Python/Interface.h>
#include
<dpsim/Python/Logger.h>
#include
<dpsim/Python/Component.h>
#ifndef _MSC_VER
#include
<dpsim/Python/Interface.h>
#include
<dpsim/RealTimeSimulation.h>
#endif
#include
<cps/DP/DP_Ph1_Switch.h>
using
namespace
DPsim
;
...
...
@@ -39,22 +41,25 @@ using namespace CPS;
void
Python
::
Simulation
::
newState
(
Python
::
Simulation
*
self
,
Simulation
::
State
newState
)
{
uint32_t
evt
=
static_cast
<
uint32_t
>
(
newState
);
#ifndef _MSC_VER
self
->
channel
->
sendEvent
(
evt
);
#endif
self
->
state
=
newState
;
}
void
Python
::
Simulation
::
threadFunction
(
Python
::
Simulation
*
self
)
{
Real
time
,
finalTime
;
#ifndef _MSC_VER
Timer
timer
(
Timer
::
Flags
::
fail_on_overrun
);
#endif
#ifdef WITH_SHMEM
for
(
auto
ifm
:
self
->
sim
->
interfaces
())
ifm
.
interface
->
open
();
#endif
#ifndef _MSC_VER
// optional start synchronization
if
(
self
->
startSync
)
{
self
->
sim
->
sync
();
...
...
@@ -67,13 +72,14 @@ void Python::Simulation::threadFunction(Python::Simulation *self)
std
::
cout
<<
"Starting simulation at "
<<
self
->
startTime
<<
" (delta_T = "
<<
self
->
startTime
-
Timer
::
StartClock
::
now
()
<<
" seconds)"
<<
std
::
endl
;
}
#endif
finalTime
=
self
->
sim
->
finalTime
();
time
=
0
;
while
(
time
<
finalTime
)
{
time
=
self
->
sim
->
step
();
#ifndef _MSC_VER
if
(
self
->
realTime
)
{
try
{
timer
.
sleep
();
...
...
@@ -87,7 +93,7 @@ void Python::Simulation::threadFunction(Python::Simulation *self)
}
}
}
#endif
if
(
self
->
sim
->
timeStepCount
()
==
1
)
{
std
::
unique_lock
<
std
::
mutex
>
lk
(
*
self
->
mut
);
newState
(
self
,
Simulation
::
State
::
running
);
...
...
@@ -178,13 +184,13 @@ int Python::Simulation::init(Simulation* self, PyObject *args, PyObject *kwds)
self
->
singleStepping
=
st
;
self
->
failOnOverrun
=
failOnOverrun
;
self
->
realTimeStep
=
timestep
/
rtFactor
;
#ifndef _MSC_VER
if
(
startTime
>
0
)
{
self
->
startTime
=
Timer
::
StartClock
::
from_time_t
(
startTime
)
+
std
::
chrono
::
microseconds
(
startTimeUs
);
}
else
self
->
startTime
=
Timer
::
StartClock
::
now
();
#endif
switch
(
s
)
{
case
0
:
domain
=
Domain
::
DP
;
break
;
case
1
:
domain
=
Domain
::
EMT
;
break
;
...
...
@@ -208,12 +214,17 @@ int Python::Simulation::init(Simulation* self, PyObject *args, PyObject *kwds)
Py_INCREF
(
self
->
pySys
);
if
(
self
->
realTime
)
if
(
self
->
realTime
)
{
#ifndef _MSC_VER
self
->
sim
=
std
::
make_shared
<
DPsim
::
RealTimeSimulation
>
(
name
,
*
self
->
pySys
->
sys
,
timestep
,
duration
,
domain
,
solverType
,
logLevel
,
initSteadyState
);
else
#endif
}
else
{
self
->
sim
=
std
::
make_shared
<
DPsim
::
Simulation
>
(
name
,
*
self
->
pySys
->
sys
,
timestep
,
duration
,
domain
,
solverType
,
logLevel
,
initSteadyState
);
}
#ifndef _MSC_VER
self
->
channel
=
new
EventChannel
();
#endif
return
0
;
}
...
...
@@ -235,7 +246,9 @@ void Python::Simulation::dealloc(Python::Simulation* self)
delete
self
->
mut
;
delete
self
->
cond
;
#ifndef _MSC_VER
delete
self
->
channel
;
#endif
for
(
auto
it
:
self
->
refs
)
{
Py_DECREF
(
it
);
...
...
@@ -540,8 +553,9 @@ PyObject * Python::Simulation::getEventFD(Simulation *self, PyObject *args) {
if
(
!
PyArg_ParseTuple
(
args
,
"|ii"
,
&
flags
,
&
coalesce
))
return
nullptr
;
#ifndef _MSC_VER
fd
=
self
->
channel
->
fd
();
#endif
if
(
fd
<
0
)
{
PyErr_SetString
(
PyExc_SystemError
,
"Failed to created event file descriptor"
);
return
nullptr
;
...
...
Tests/CMakeLists.txt
View file @
19464677
set
(
TEST_SRCS
Timer.cpp
)
if
(
NOT WIN32
)
set
(
TEST_SRCS
Timer.cpp
)
endif
()
foreach
(
SOURCE
${
TEST_SRCS
}
)
get_filename_component
(
TARGET
${
SOURCE
}
NAME_WE
)
...
...
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