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
b88d1b0a
Commit
b88d1b0a
authored
Jul 15, 2019
by
Steffen Vogel
🎅🏼
Browse files
python: allow changing of final_time attribute on simulation instances
parent
5e5f41e7
Changes
3
Hide whitespace changes
Inline
Side-by-side
Include/dpsim/Python/Simulation.h
View file @
b88d1b0a
...
...
@@ -111,6 +111,9 @@ namespace Python {
static
PyObject
*
removeEventFD
(
Simulation
*
self
,
PyObject
*
args
);
static
PyObject
*
setScheduler
(
Simulation
*
self
,
PyObject
*
args
,
PyObject
*
kwargs
);
// Setters
static
int
setFinalTime
(
Simulation
*
self
,
PyObject
*
val
,
void
*
ctx
);
// Getters
static
PyObject
*
getState
(
Simulation
*
self
,
void
*
ctx
);
static
PyObject
*
name
(
Simulation
*
self
,
void
*
ctx
);
...
...
Source/Python/Simulation.cpp
View file @
b88d1b0a
...
...
@@ -701,6 +701,18 @@ PyObject* Python::Simulation::avgStepTime(Simulation *self, void *ctx)
return
Py_BuildValue
(
"f"
,
avg
);
}
int
Python
::
Simulation
::
setFinalTime
(
Simulation
*
self
,
PyObject
*
val
,
void
*
ctx
)
{
std
::
unique_lock
<
std
::
mutex
>
lk
(
*
self
->
mut
);
if
(
val
==
nullptr
)
return
-
1
;
self
->
sim
->
attribute
<
Real
>
(
"final_time"
)
->
fromPyObject
(
val
);
return
0
;
}
// TODO: for everything but state, we could use read-only Attributes and a getattro
// implementation that locks the mutex before access
PyGetSetDef
Python
::
Simulation
::
getset
[]
=
{
...
...
@@ -708,7 +720,7 @@ PyGetSetDef Python::Simulation::getset[] = {
{(
char
*
)
"name"
,
(
getter
)
Python
::
Simulation
::
name
,
nullptr
,
(
char
*
)
Python
::
Simulation
::
docName
,
nullptr
},
{(
char
*
)
"steps"
,
(
getter
)
Python
::
Simulation
::
steps
,
nullptr
,
nullptr
,
nullptr
},
{(
char
*
)
"time"
,
(
getter
)
Python
::
Simulation
::
time
,
nullptr
,
nullptr
,
nullptr
},
{(
char
*
)
"final_time"
,
(
getter
)
Python
::
Simulation
::
finalTime
,
nullptr
,
nullptr
,
nullptr
},
{(
char
*
)
"final_time"
,
(
getter
)
Python
::
Simulation
::
finalTime
,
(
setter
)
Python
::
Simulation
::
setFinalTime
,
nullptr
,
nullptr
},
{(
char
*
)
"avg_step_time"
,
(
getter
)
Python
::
Simulation
::
avgStepTime
,
nullptr
,
nullptr
,
nullptr
},
{
nullptr
,
nullptr
,
nullptr
,
nullptr
,
nullptr
}
};
...
...
Source/Simulation.cpp
View file @
b88d1b0a
...
...
@@ -47,7 +47,7 @@ Simulation::Simulation(String name, Logger::Level logLevel) :
mName
(
name
),
mLogLevel
(
logLevel
)
{
addAttribute
<
String
>
(
"name"
,
&
mName
,
Flags
::
read
);
addAttribute
<
Real
>
(
"final_time"
,
&
mFinalTime
,
Flags
::
read
);
addAttribute
<
Real
>
(
"final_time"
,
&
mFinalTime
,
Flags
::
read
|
Flags
::
write
);
Eigen
::
setNbThreads
(
1
);
// Logging
...
...
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