ESyS-Particle  2.3.4
ListConverter.h
Go to the documentation of this file.
1 // //
3 // Copyright (c) 2003-2017 by The University of Queensland //
4 // Centre for Geoscience Computing //
5 // http://earth.uq.edu.au/centre-geoscience-computing //
6 // //
7 // Primary Business: Brisbane, Queensland, Australia //
8 // Licensed under the Open Software License version 3.0 //
9 // http://www.apache.org/licenses/LICENSE-2.0 //
10 // //
12 
13 
14 #ifndef ESYS_LSM_BPULISTCONVERTER_H
15 #define ESYS_LSM_BPULISTCONVERTER_H
16 
17 #include <boost/python.hpp>
18 
20 
21 #include <vector>
22 
23 namespace esys
24 {
25  namespace lsm
26  {
27  namespace bpu
28  {
29  template <typename TmplValueType>
31  {
32  public:
33  typedef TmplValueType value_type;
34 
35  value_type operator()(const boost::python::object &pyObject) const
36  {
37  return boost::python::extract<value_type>(pyObject);
38  }
39  };
40 
41  template<typename TmplValue>
42  std::vector<TmplValue> listToVector(const boost::python::list &pythonList)
43  {
45  std::vector<TmplValue> vec;
46  const int numElements = esys::lsm::bpu::len(pythonList);
47  vec.reserve(numElements);
48  for (int i = 0; i < numElements; i++)
49  {
50  vec.push_back(extractor(pythonList[i]));
51  }
52  return vec;
53  }
54 
55  template<typename TmplValue>
56  std::vector<TmplValue> tupleToVector(const boost::python::tuple &pythonTulple)
57  {
59  std::vector<TmplValue> vec;
60  const int numElements = esys::lsm::bpu::len(pythonTulple);
61  vec.reserve(numElements);
62  for (int i = 0; i < numElements; i++)
63  {
64  vec.push_back(extractor(pythonTulple[i]));
65  }
66  return vec;
67  }
68 
69  template<typename TmplValue, typename TmplExtractor>
70  std::vector<TmplValue> listToVector(const boost::python::list &pythonList, TmplExtractor extractor=TmplExtractor())
71  {
72  std::vector<TmplValue> vec;
73  const int numElements = esys::lsm::bpu::len(pythonList);
74  vec.reserve(numElements);
75  for (int i = 0; i < numElements; i++)
76  {
77  vec.push_back(extractor(pythonList[i]));
78  }
79  return vec;
80  }
81 
82  template <typename TmplVector>
83  boost::python::list vectorToList(const TmplVector &vec)
84  {
85  boost::python::list pythonList;
86  for (
87  typename TmplVector::const_iterator it = vec.begin();
88  it != vec.end();
89  it++
90  )
91  {
92  pythonList.append(*it);
93  }
94  return pythonList;
95  }
96  }
97  }
98 }
99 
100 #endif
Util.h
esys::lsm::bpu::tupleToVector
std::vector< TmplValue > tupleToVector(const boost::python::tuple &pythonTulple)
Definition: ListConverter.h:56
test_group_comm
bool test_group_comm(TML_Comm *comm, int rank)
Definition: test_comm.cpp:367
esys::lsm::bpu::len
int len(const boost::python::object &pyOb)
Definition: Util.h:30
CBasicParticle::setRad
void setRad(double r)
Definition: BasicParticle.h:70
test_cart.h
pp_array.h
test_sc.h
TML_PackedMessageInterface::pop_int
virtual int pop_int()=0
ParallelParticleArray::forAllParticlesGet
void forAllParticlesGet(P &, typename P::value_type(T::*rdf)() const)
Definition: pp_array.hpp:642
ParallelParticleArray::forParticle
void forParticle(int, void(T::*rdf)())
Definition: pp_array.hpp:456
Vec3::X
VEC3_INLINE double & X()
Definition: vec3.h:119
esys
Definition: CheckPointable.cpp:17
comm_world.h
ParallelParticleArray
parrallel particle storage array with neighborsearch and variable exchange
Definition: pp_array.h:75
TML_PackedMessageInterface::pop_double
virtual double pop_double()=0
Vec3::Z
VEC3_INLINE double & Z()
Definition: vec3.h:121
esys::lsm::bpu::DefaultExtractor::value_type
TmplValueType value_type
Definition: ListConverter.h:33
TML_Comm::rank
int rank() const
Definition: comm.cpp:56
test_group_pack
bool test_group_pack(TML_Comm *comm, int rank)
Definition: test_pack.cpp:258
main
int main(int argc, char **argv)
Definition: test.cpp:27
packed_message_interface.h
ParallelParticleArray::rebuild
void rebuild()
Definition: pp_array.hpp:242
TML_PackedMessageInterface::append
virtual void append(int)=0
Vec3::Y
VEC3_INLINE double & Y()
Definition: vec3.h:120
esys::lsm::bpu::DefaultExtractor
Definition: ListConverter.h:31
test_group_sc
bool test_group_sc(TML_Comm *comm, int rank)
Definition: tesp_sc.cpp:46
Vec3
Definition: vec3.h:47
esys::lsm::bpu::iter
boost::python::object iter(const boost::python::object &pyOb)
Definition: Util.h:25
esys::lsm::bpu::DefaultExtractor::operator()
value_type operator()(const boost::python::object &pyObject) const
Definition: ListConverter.h:35
ListConverter.h
ParallelParticleArray::forAllParticles
void forAllParticles(void(T::*rdf)())
Definition: pp_array.hpp:570
test_pack.h
TML_CommWorld
abstract base class for communicator
Definition: comm_world.h:31
esys::lsm::bpu::listToVector
std::vector< TmplValue > listToVector(const boost::python::list &pythonList)
Definition: ListConverter.h:42
CBasicParticle::getID
int getID() const
Definition: BasicParticle.h:65
CBasicParticle::getRad
double getRad() const
Definition: BasicParticle.h:64
test_comm.h
esys::lsm::bpu::vectorToList
boost::python::list vectorToList(const TmplVector &vec)
Definition: ListConverter.h:83
CBasicParticle::getPos
Vec3 getPos() const
Definition: BasicParticle.h:62
test_group_cart
bool test_group_cart(TML_Comm *comm, int rank)
Definition: test_cart.cpp:122
CBasicParticle
Basic Particle class. Contains only the "geometric part" of the particle, i.e. position and radius,...
Definition: BasicParticle.h:45
TML_Comm::size
int size()
Definition: comm.cpp:69