Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F122969362
pypart.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
Wed, Jul 23, 03:17
Size
5 KB
Mime Type
text/x-c
Expires
Fri, Jul 25, 03:17 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
27567089
Attached To
R9484 sp4e-homework-lars-bertil
pypart.cc
View Options
#include <functional>
#include <iostream>
#include <pybind11/pybind11.h>
#include "material_points_factory.hh"
#include "ping_pong_balls_factory.hh"
#include "planets_factory.hh"
#include "compute.hh"
#include "compute_temperature.hh"
#include "compute_gravity.hh"
#include "compute_verlet_integration.hh"
#include "compute_interaction.hh"
#include "csv_writer.hh"
#include "system.hh"
#include "system_evolution.hh"
namespace
py
=
pybind11
;
PYBIND11_MODULE
(
pypart
,
m
)
{
m
.
doc
()
=
"pybind pypart plugin"
;
// optional docstring
// The member functions of the various classes (used in main.py) are exposed to pybind
// Exercise 1 - Question 1, 2, 3
py
::
class_
<
ParticlesFactoryInterface
>
(
m
,
"ParticlesFactoryInterface"
)
.
def
(
"getInstance"
,
&
ParticlesFactoryInterface
::
getInstance
,
py
::
return_value_policy
::
reference
)
.
def
(
"createSimulation"
,(
SystemEvolution
&
(
ParticlesFactoryInterface
::*
)(
const
std
::
string
&
,
Real
))
&
ParticlesFactoryInterface
::
createSimulation
,
py
::
return_value_policy
::
reference
)
.
def
(
"createSimulation"
,
py
::
overload_cast
<
const
std
::
string
&
,
Real
,
py
::
function
>
(
&
ParticlesFactoryInterface
::
createSimulation
<
py
::
function
>
),
py
::
return_value_policy
::
reference
)
//.def("createSimulation", &ParticlesFactoryInterface::createSimulation,py::return_value_policy::reference)
//.def("createSimulation",py::overload_cast<const std::string &, Real,py::function>(&ParticlesFactoryInterface::createSimulation<py::function>),py::return_value_policy::reference)
.
def_property_readonly
(
"system_evolution"
,
&
ParticlesFactoryInterface
::
getSystemEvolution
);
py
::
class_
<
MaterialPointsFactory
,
ParticlesFactoryInterface
>
(
m
,
"MaterialPointsFactory"
)
.
def
(
"getInstance"
,
&
MaterialPointsFactory
::
getInstance
,
py
::
return_value_policy
::
reference
)
.
def
(
"createSimulation"
,
py
::
overload_cast
<
const
std
::
string
&
,
Real
,
py
::
function
>
(
&
ParticlesFactoryInterface
::
createSimulation
<
py
::
function
>
),
py
::
return_value_policy
::
reference
);
//.def("createSimulation",(SystemEvolution & (MaterialPointsFactory::*)(const std::string &, Real))&MaterialPointsFactory::createSimulation, py::return_value_policy::reference);
//.def("createSimulation",py::overload_cast<const std::string &, Real,py::function>(&MaterialPointsFactory::createSimulation<py::function>), py::return_value_policy::reference);
py
::
class_
<
PingPongBallsFactory
,
ParticlesFactoryInterface
>
(
m
,
"PingPongBallsFactory"
)
.
def
(
"getInstance"
,
&
PingPongBallsFactory
::
getInstance
,
py
::
return_value_policy
::
reference
);
//.def("createSimulation",py::overload_cast<const std::string &, Real,
// py::function>(&ParticlesFactoryInterface::createSimulation<py::function>),
// py::return_value_policy::reference);
//.def("createSimulation", &PingPongBallsFactory::createSimulation,py::return_value_policy::reference);
py
::
class_
<
PlanetsFactory
,
ParticlesFactoryInterface
>
(
m
,
"PlanetsFactory"
)
.
def
(
"getInstance"
,
&
PlanetsFactory
::
getInstance
,
py
::
return_value_policy
::
reference
);
//.def("createSimulation",py::overload_cast<const std::string &, Real,
// py::function>(&ParticlesFactoryInterface::createSimulation<py::function>),
// py::return_value_policy::reference);
//.def("createSimulation", &PlanetsFactory::createSimulation,py::return_value_policy::reference);
// Exercise 2 - Question 1, 2, 3
py
::
class_
<
Compute
,
std
::
shared_ptr
<
Compute
>>
(
m
,
"Compute"
);
//To try: for memory conflict problem maybe: std::shared_ptr<Compute> :NO
py
::
class_
<
ComputeInteraction
,
Compute
,
std
::
shared_ptr
<
ComputeInteraction
>>
(
m
,
"ComputeInteraction"
);
py
::
class_
<
ComputeTemperature
,
Compute
,
std
::
shared_ptr
<
ComputeTemperature
>>
(
m
,
"ComputeTemperature"
)
// (tried: py::dynamic_attr())
.
def
(
py
::
init
<>
())
.
def_property_readonly
(
"conductivity"
,
&
ComputeTemperature
::
getConductivity
)
.
def_property_readonly
(
"capacity"
,
&
ComputeTemperature
::
getCapacity
)
.
def_property_readonly
(
"L"
,
&
ComputeTemperature
::
getL
)
.
def_property_readonly
(
"deltat"
,
&
ComputeTemperature
::
getDeltat
);
py
::
class_
<
ComputeGravity
,
Compute
,
std
::
shared_ptr
<
ComputeGravity
>>
(
m
,
"ComputeGravity"
)
.
def
(
py
::
init
<>
())
.
def
(
"setG"
,
&
ComputeGravity
::
setG
);
py
::
class_
<
ComputeVerletIntegration
,
Compute
,
std
::
shared_ptr
<
ComputeVerletIntegration
>>
(
m
,
"ComputeVerletIntegration"
)
.
def
(
py
::
init
<
Real
>
())
.
def
(
"addInteraction"
,
&
ComputeVerletIntegration
::
addInteraction
);
// Exercise 3 - Question 1
py
::
class_
<
CsvWriter
>
(
m
,
"CsvWriter"
)
.
def
(
py
::
init
<
const
std
::
string
&>
())
.
def
(
"write"
,
&
CsvWriter
::
write
);
py
::
class_
<
SystemEvolution
>
(
m
,
"SystemEvolution"
)
// no heritage but referenced : strange ! system_evolution in main.py !?
.
def
(
"evolve"
,
&
SystemEvolution
::
evolve
)
.
def
(
"addCompute"
,
&
SystemEvolution
::
addCompute
)
.
def
(
"getSystem"
,
&
SystemEvolution
::
getSystem
)
.
def
(
"setNSteps"
,
&
SystemEvolution
::
setNSteps
)
.
def
(
"setDumpFreq"
,
&
SystemEvolution
::
setDumpFreq
);
py
::
class_
<
System
>
(
m
,
"System"
);
// not necessary but added for clarity
}
Event Timeline
Log In to Comment