Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F64368632
python.cc
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sun, May 26, 10:23
Size
2 KB
Mime Type
text/x-c++
Expires
Tue, May 28, 10:23 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
17890721
Attached To
rLIBMULTISCALE LibMultiScale
python.cc
View Options
#include "lm_common.hh"
#include "lm_python_bindings.hh"
#include <pybind11/eigen.h>
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
namespace
py
=
pybind11
;
using
namespace
libmultiscale
;
std
::
vector
<
std
::
string
>
fake_argv
;
std
::
vector
<
char
*>
c_argv
;
extern
std
::
map
<
std
::
string
,
std
::
vector
<
std
::
string
>>
getKeyWordList
();
void
loadModules
()
{
// auto sys = py::module::import("sys");
// auto argv = sys.attr("argv");
// fake_argv = py::cast<std::vector<std::string>>(argv);
// std::cout << "AAAA " << fake_argv.size() << std::endl;
// for (auto &&v : fake_argv) {
// std::cout << "AAAA " << &v[0] << std::endl;
// c_argv.push_back(&v[0]);
// }
// loadModules(c_argv.size(), c_argv.data());
loadModules
(
0
,
nullptr
);
create_seg_fault
=
false
;
}
extern
std
::
string
lm_release_info
;
template
<
typename
T2
,
typename
T
>
void
ModuleProperty
(
py
::
module
&
m
,
const
char
*
n
,
T
&
var
)
{
// setting a property
// import the builtins and get the "property" python class
auto
property
=
py
::
module
::
import
(
"builtins"
).
attr
(
"property"
);
m
.
attr
(
n
)
=
property
(
py
::
cpp_function
([
&
]()
{
return
var
;
}),
py
::
cpp_function
([
&
](
T2
&
a
)
{
var
=
a
;
}));
}
PYBIND11_MODULE
(
pylibmultiscale
,
m
)
{
m
.
doc
()
=
"LibMultiScale python module"
;
ModuleProperty
<
int
>
(
m
,
"current_step"
,
current_step
);
ModuleProperty
<
int
>
(
m
,
"lm_my_proc_id"
,
lm_my_proc_id
);
ModuleProperty
<
IntegrationSchemeStage
>
(
m
,
"current_stage"
,
current_stage
);
ModuleProperty
<
UInt
>
(
m
,
"spatial_dimension"
,
spatial_dimension
);
ModuleProperty
<
bool
>
(
m
,
"print_trace"
,
print_trace
);
m
.
def
(
"loadModules"
,
&::
loadModules
,
"Load all the module dependencies of libmultiscale"
);
m
.
def
(
"closeModules"
,
&
closeModules
,
"close all the module dependencies of libmultiscale"
);
m
.
attr
(
"release_info"
)
=
py
::
cast
(
lm_release_info
);
m
.
def
(
"getKeyWordList"
,
&
getKeyWordList
);
makeBindings
(
m
);
static
py
::
exception
<
LibMultiScaleException
>
lm_exception
(
m
,
"LibMultiScaleException"
);
py
::
register_exception_translator
([](
std
::
exception_ptr
p
)
{
try
{
if
(
p
)
std
::
rethrow_exception
(
p
);
}
catch
(
LibMultiScaleException
&
e
)
{
if
(
print_trace
)
{
std
::
cerr
<<
"AAAA "
<<
print_trace
<<
std
::
endl
;
lm_exception
(
e
.
messageWithTrace
().
c_str
());
}
else
lm_exception
(
e
.
what
());
}
});
}
Event Timeline
Log In to Comment