/[escript]/trunk/ripley/src/ripleycpp.cpp
ViewVC logotype

Diff of /trunk/ripley/src/ripleycpp.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 4738 by sshaw, Wed Mar 12 01:32:36 2014 UTC revision 4942 by sshaw, Thu May 15 03:42:28 2014 UTC
# Line 18  Line 18 
18  #include <ripley/Rectangle.h>  #include <ripley/Rectangle.h>
19  #include <esysUtils/esysExceptionTranslator.h>  #include <esysUtils/esysExceptionTranslator.h>
20    
21  #include <boost/python.hpp>  #include <boost/python.hpp>
22  #include <boost/python/module.hpp>  #include <boost/python/module.hpp>
23  #include <boost/python/def.hpp>  #include <boost/python/def.hpp>
24  #include <boost/python/detail/defaults_gen.hpp>  #include <boost/python/detail/defaults_gen.hpp>
25  #include <boost/version.hpp>  #include <boost/version.hpp>
26    
27    #include "escript/SubWorld.h"
28    
29  using namespace boost::python;  using namespace boost::python;
30    
31  namespace ripley {  namespace ripley {
# Line 136  escript::Data readNcGrid(std::string fil Line 138  escript::Data readNcGrid(std::string fil
138  // truediv  // truediv
139  escript::Domain_ptr _brick(double _n0, double _n1, double _n2, const object& l0,  escript::Domain_ptr _brick(double _n0, double _n1, double _n2, const object& l0,
140                   const object& l1, const object& l2, int d0, int d1, int d2,                   const object& l1, const object& l2, int d0, int d1, int d2,
141                   const object& objpoints, const object& objtags)                   const object& objpoints, const object& objtags, escript::SubWorld_ptr world)
142  {  {
143      int n0=static_cast<int>(_n0), n1=static_cast<int>(_n1), n2=static_cast<int>(_n2);      int n0=static_cast<int>(_n0), n1=static_cast<int>(_n1), n2=static_cast<int>(_n2);
144      double x0=0., x1=1., y0=0., y1=1., z0=0., z1=1.;      double x0=0., x1=1., y0=0., y1=1., z0=0., z1=1.;
# Line 175  escript::Domain_ptr _brick(double _n0, d Line 177  escript::Domain_ptr _brick(double _n0, d
177          z1=extract<double>(l2);          z1=extract<double>(l2);
178      } else      } else
179          throw RipleyException("Argument l2 must be a float or 2-tuple");          throw RipleyException("Argument l2 must be a float or 2-tuple");
   
180      boost::python::list pypoints=extract<boost::python::list>(objpoints);      boost::python::list pypoints=extract<boost::python::list>(objpoints);
181      boost::python::list pytags=extract<boost::python::list>(objtags);      boost::python::list pytags=extract<boost::python::list>(objtags);
182      int numpts=extract<int>(pypoints.attr("__len__")());      int numpts=extract<int>(pypoints.attr("__len__")());
# Line 184  escript::Domain_ptr _brick(double _n0, d Line 185  escript::Domain_ptr _brick(double _n0, d
185      std::vector<int> tags;      std::vector<int> tags;
186      tags.resize(numtags, -1);      tags.resize(numtags, -1);
187      for (int i=0;i<numpts;++i) {      for (int i=0;i<numpts;++i) {
188          boost::python::object temp=pypoints[i];          tuple temp = extract<tuple>(pypoints[i]);
189          int l=extract<int>(temp.attr("__len__")());          int l=extract<int>(temp.attr("__len__")());
190            if (l != 3)
191                throw RipleyException("Number of coordinates for each dirac point must match dimensions.");
192          for (int k=0;k<l;++k) {          for (int k=0;k<l;++k) {
193              points.push_back(extract<double>(temp[k]));              points.push_back(extract<double>(temp[k]));
194          }          }
# Line 216  escript::Domain_ptr _brick(double _n0, d Line 219  escript::Domain_ptr _brick(double _n0, d
219              throw RipleyException("Error - Unable to extract tag value.");              throw RipleyException("Error - Unable to extract tag value.");
220          }          }
221      }      }
222        if (numtags != numpts)
223            throw RipleyException("Number of tags does not match number of points.");
224      return escript::Domain_ptr(new Brick(n0,n1,n2, x0,y0,z0, x1,y1,z1, d0,d1,d2,      return escript::Domain_ptr(new Brick(n0,n1,n2, x0,y0,z0, x1,y1,z1, d0,d1,d2,
225                                              points, tags, tagstonames));                                              points, tags, tagstonames, world));
226  }  }
227    
228  const int _q[]={0x61686969,0x746c4144,0x79616e43};  //const int _q[]={0x61686969,0x746c4144,0x79616e43};
229    const int _q[]={0x62207363, 0x6574735F, 0x2020214e};
230  escript::Domain_ptr _rectangle(double _n0, double _n1, const object& l0,  escript::Domain_ptr _rectangle(double _n0, double _n1, const object& l0,
231                                 const object& l1, int d0, int d1,                                 const object& l1, int d0, int d1,
232                                 const object& objpoints, const object& objtags)                                 const object& objpoints, const object& objtags,
233                      escript::SubWorld_ptr world
234                      )
235  {  {
236      int n0=static_cast<int>(_n0), n1=static_cast<int>(_n1);      int n0=static_cast<int>(_n0), n1=static_cast<int>(_n1);
237      double x0=0., x1=1., y0=0., y1=1.;      double x0=0., x1=1., y0=0., y1=1.;
# Line 250  escript::Domain_ptr _rectangle(double _n Line 258  escript::Domain_ptr _rectangle(double _n
258          y1=extract<double>(l1);          y1=extract<double>(l1);
259      } else      } else
260          throw RipleyException("Argument l1 must be a float or 2-tuple");          throw RipleyException("Argument l1 must be a float or 2-tuple");
           
261      boost::python::list pypoints=extract<boost::python::list>(objpoints);      boost::python::list pypoints=extract<boost::python::list>(objpoints);
262      boost::python::list pytags=extract<boost::python::list>(objtags);      boost::python::list pytags=extract<boost::python::list>(objtags);
263      int numpts=extract<int>(pypoints.attr("__len__")());      int numpts=extract<int>(pypoints.attr("__len__")());
# Line 259  escript::Domain_ptr _rectangle(double _n Line 266  escript::Domain_ptr _rectangle(double _n
266      std::vector<int> tags;      std::vector<int> tags;
267      tags.resize(numtags, -1);      tags.resize(numtags, -1);
268      for (int i=0;i<numpts;++i) {      for (int i=0;i<numpts;++i) {
269          boost::python::object temp=pypoints[i];          tuple temp = extract<tuple>(pypoints[i]);
270          int l=extract<int>(temp.attr("__len__")());          int l=extract<int>(temp.attr("__len__")());
271            if (l != 2)
272                throw RipleyException("Number of coordinates for each dirac point must match dimensions.");
273          for (int k=0;k<l;++k) {          for (int k=0;k<l;++k) {
274              points.push_back(extract<double>(temp[k]));              points.push_back(extract<double>(temp[k]));
275          }          }
# Line 291  escript::Domain_ptr _rectangle(double _n Line 300  escript::Domain_ptr _rectangle(double _n
300              throw RipleyException("Error - Unable to extract tag value.");              throw RipleyException("Error - Unable to extract tag value.");
301          }          }
302      }      }
303        if (numtags != numpts)
304            throw RipleyException("Number of tags does not match number of points.");
305      return escript::Domain_ptr(new Rectangle(n0,n1, x0,y0, x1,y1, d0,d1,      return escript::Domain_ptr(new Rectangle(n0,n1, x0,y0, x1,y1, d0,d1,
306                                               points, tags, tagstonames));                                               points, tags, tagstonames, world));
307  }  }
308  std::string _who(){int a[]={_q[0]^42,_q[1]^42,_q[2]^42,0};return (char*)&a[0];}  std::string _who(){int a[]={_q[0]^42,_q[1]^42,_q[2]^42,0};return (char*)&a[0];}
309    
# Line 307  BOOST_PYTHON_MODULE(ripleycpp) Line 318  BOOST_PYTHON_MODULE(ripleycpp)
318      docstring_options docopt(true, true, false);      docstring_options docopt(true, true, false);
319  #endif  #endif
320    
321      register_exception_translator<ripley::RipleyException>(&(esysUtils::esysExceptionTranslator));      register_exception_translator<ripley::RipleyException>(&(esysUtils::RuntimeErrorTranslator));
322    
323      scope().attr("__doc__") = "To use this module, please import esys.ripley";      scope().attr("__doc__") = "To use this module, please import esys.ripley";
324      scope().attr("BYTEORDER_NATIVE") = (int)ripley::BYTEORDER_NATIVE;      scope().attr("BYTEORDER_NATIVE") = (int)ripley::BYTEORDER_NATIVE;
# Line 317  BOOST_PYTHON_MODULE(ripleycpp) Line 328  BOOST_PYTHON_MODULE(ripleycpp)
328      scope().attr("DATATYPE_FLOAT32") = (int)ripley::DATATYPE_FLOAT32;      scope().attr("DATATYPE_FLOAT32") = (int)ripley::DATATYPE_FLOAT32;
329      scope().attr("DATATYPE_FLOAT64") = (int)ripley::DATATYPE_FLOAT64;      scope().attr("DATATYPE_FLOAT64") = (int)ripley::DATATYPE_FLOAT64;
330    
331      def("Brick", ripley::_brick, (arg("n0"),arg("n1"),arg("n2"),arg("l0")=1.0,arg("l1")=1.0,arg("l2")=1.0,arg("d0")=-1,arg("d1")=-1,arg("d2")=-1,arg("diracPoints")=list(),arg("diracTags")=list()),      def("Brick", ripley::_brick, (arg("n0"),arg("n1"),arg("n2"),arg("l0")=1.0,arg("l1")=1.0,arg("l2")=1.0,
332            arg("d0")=-1,arg("d1")=-1,arg("d2")=-1,arg("diracPoints")=list(),arg("diracTags")=list(), arg("escriptworld")=escript::SubWorld_ptr()),
333  "Creates a hexagonal mesh with n0 x n1 x n2 elements over the brick [0,l0] x [0,l1] x [0,l2].\n\n"  "Creates a hexagonal mesh with n0 x n1 x n2 elements over the brick [0,l0] x [0,l1] x [0,l2].\n\n"
334  ":param n0: number of elements in direction 0\n:type n0: ``int``\n"  ":param n0: number of elements in direction 0\n:type n0: ``int``\n"
335  ":param n1: number of elements in direction 1\n:type n1: ``int``\n"  ":param n1: number of elements in direction 1\n:type n1: ``int``\n"
# Line 329  BOOST_PYTHON_MODULE(ripleycpp) Line 341  BOOST_PYTHON_MODULE(ripleycpp)
341  ":param d1: number of subdivisions in direction 1\n:type d1: ``int``\n"  ":param d1: number of subdivisions in direction 1\n:type d1: ``int``\n"
342  ":param d2: number of subdivisions in direction 2\n:type d2: ``int``");  ":param d2: number of subdivisions in direction 2\n:type d2: ``int``");
343    
344      def("Rectangle", ripley::_rectangle, (arg("n0"),arg("n1"),arg("l0")=1.0,arg("l1")=1.0,arg("d0")=-1,arg("d1")=-1,arg("diracPoints")=list(),arg("diracTags")=list()),      def("Rectangle", ripley::_rectangle, (arg("n0"),arg("n1"),arg("l0")=1.0,arg("l1")=1.0,arg("d0")=-1,arg("d1")=-1,arg("diracPoints")=list(),arg("diracTags")=list(), arg("escriptworld")=escript::SubWorld_ptr()),
345  "Creates a rectangular mesh with n0 x n1 elements over the rectangle [0,l0] x [0,l1].\n\n"  "Creates a rectangular mesh with n0 x n1 elements over the rectangle [0,l0] x [0,l1].\n\n"
346  ":param n0: number of elements in direction 0\n:type n0: ``int``\n"  ":param n0: number of elements in direction 0\n:type n0: ``int``\n"
347  ":param n1: number of elements in direction 1\n:type n1: ``int``\n"  ":param n1: number of elements in direction 1\n:type n1: ``int``\n"
# Line 385  BOOST_PYTHON_MODULE(ripleycpp) Line 397  BOOST_PYTHON_MODULE(ripleycpp)
397              ":param mat:\n:type mat: `OperatorAdapter`\n"              ":param mat:\n:type mat: `OperatorAdapter`\n"
398              ":param rhs:\n:type rhs: `Data`\n"              ":param rhs:\n:type rhs: `Data`\n"
399              ":param data:\ntype data: `list`")              ":param data:\ntype data: `list`")
         .def("addPDEToSystem",&ripley::RipleyDomain::addPDEToSystem,  
 args("mat", "rhs", "A", "B", "C", "D", "X", "Y", "d", "y", "d_contact", "y_contact"),  
 "adds a PDE onto the stiffness matrix mat and a rhs\n\n"  
 ":param mat:\n:type mat: `OperatorAdapter`\n:param rhs:\n:type rhs: `Data`\n"  
 ":param A:\n:type A: `Data`\n"  
 ":param B:\n:type B: `Data`\n"  
 ":param C:\n:type C: `Data`\n"  
 ":param D:\n:type D: `Data`\n"  
 ":param X:\n:type X: `Data`\n"  
 ":param Y:\n:type Y: `Data`\n"  
 ":param d:\n:type d: `Data`\n"  
 ":param d_contact:\n:type d_contact: `Data`\n"  
 ":param y_contact:\n:type y_contact: `Data`"  
 )  
   
         .def("addPDEToRHS",&ripley::RipleyDomain::addPDEToRHS,  
 args("rhs", "X", "Y", "y", "y_contact"),  
 "adds a PDE onto the stiffness matrix mat and a rhs\n\n"  
 ":param rhs:\n:type rhs: `Data`\n"  
 ":param X:\n:type X: `Data`\n"  
 ":param Y:\n:type Y: `Data`\n"  
 ":param y:\n:type y: `Data`\n"  
 ":param y_contact:\n:type y_contact: `Data`"  
 )  
400          .def("addToRHS",&ripley::RipleyDomain::addToRHSFromPython,          .def("addToRHS",&ripley::RipleyDomain::addToRHSFromPython,
401              args("rhs", "data"),              args("rhs", "data"),
402              "adds a PDE onto the stiffness matrix mat and a rhs, "              "adds a PDE onto the stiffness matrix mat and a rhs, "
403              "results depends on domain\n\n"              "results depends on domain\n\n"
404              ":param rhs:\n:type rhs: `Data`\n"              ":param rhs:\n:type rhs: `Data`\n"
405              ":param data:\ntype data: `list`")              ":param data:\ntype data: `list`")
406          .def("setAssembler", &ripley::RipleyDomain::setAssemblerFromPython,          .def("createAssembler", &ripley::RipleyDomain::createAssemblerFromPython,
407              args("typename", "options"),              args("typename", "options"),
408              "sets the domain to use the named assembler, if supported, using"              "request from the domain an assembler of the specified type, if "
409              "the options if provided"              "supported, using the supplied options (if provided)"
410              ":param typename:\n:type typename: `string`\n"              ":param typename:\n:type typename: `string`\n"
411              ":param options:\n:type options: `list`\n")              ":param options:\n:type options: `list`\n")
412          .def("addPDEToTransportProblem",&ripley::RipleyDomain::addPDEToTransportProblem,          .def("addPDEToTransportProblem",&ripley::RipleyDomain::addPDEToTransportProblemFromPython,
413  args( "tp", "source", "M", "A", "B", "C", "D", "X", "Y", "d", "y", "d_contact", "y_contact"),              args("tp", "source", "data"),
414  ":param tp:\n:type tp: `TransportProblemAdapter`\n"              ":param tp:\n:type tp: `TransportProblemAdapter`\n"
415  ":param source:\n:type source: `Data`\n"              ":param source:\n:type source: `Data`\n"
416  ":param M:\n:type M: `Data`\n"              ":param data:\ntype data: `list`")
 ":param A:\n:type A: `Data`\n"  
 ":param B:\n:type B: `Data`\n"  
 ":param C:\n:type C: `Data`\n"  
 ":param D:\n:type D: `Data`\n"  
 ":param X:\n:type X: `Data`\n"  
 ":param Y:\n:type Y: `Data`\n"  
 ":param d:\n:type d: `Data`\n"  
 ":param y:\n:type y: `Data`\n"  
 ":param d_contact:\n:type d_contact: `Data`\n"  
 ":param y_contact:\n:type y_contact: `Data`"  
 )  
417          .def("newOperator",&ripley::RipleyDomain::newSystemMatrix,          .def("newOperator",&ripley::RipleyDomain::newSystemMatrix,
418  args("row_blocksize", "row_functionspace", "column_blocksize", "column_functionspace", "type"),  args("row_blocksize", "row_functionspace", "column_blocksize", "column_functionspace", "type"),
419  "creates a SystemMatrixAdapter stiffness matrix and initializes it with zeros\n\n"  "creates a SystemMatrixAdapter stiffness matrix and initializes it with zeros\n\n"
# Line 491  args("solver", "preconditioner", "packag Line 468  args("solver", "preconditioner", "packag
468          .def("getMPIRank",&ripley::RipleyDomain::getMPIRank,":return: the rank of this process\n:rtype: ``int``")          .def("getMPIRank",&ripley::RipleyDomain::getMPIRank,":return: the rank of this process\n:rtype: ``int``")
469          .def("MPIBarrier",&ripley::RipleyDomain::MPIBarrier,"Wait until all processes have reached this point")          .def("MPIBarrier",&ripley::RipleyDomain::MPIBarrier,"Wait until all processes have reached this point")
470          .def("onMasterProcessor",&ripley::RipleyDomain::onMasterProcessor,":return: True if this code is executing on the master process\n:rtype: `bool`");          .def("onMasterProcessor",&ripley::RipleyDomain::onMasterProcessor,":return: True if this code is executing on the master process\n:rtype: `bool`");
471        /* These two class exports are necessary to ensure that the extra methods added by ripley make it to python.
472         * This change became necessary when the Brick and Rectangle constructors turned into factories instead of classes */
473      class_<ripley::Brick, bases<ripley::RipleyDomain> >("RipleyBrick", "", no_init);      class_<ripley::Brick, bases<ripley::RipleyDomain> >("RipleyBrick", "", no_init);
 /*      
     .def("randomFill", &ripley::Brick::randomFill,":return: random data\n:rtype: `Data`\n:param seed: pass zero to use system generated seed\n:type seed: `int`\n"  
 ":param details: more info about the type of randomness\nCurrently, the only acceptable value for this tuple is ('gaussian', r, s) where r is the radius of the"  
 "guassian blur and s is the sigma parameter."  
     );  
 */      
474      class_<ripley::Rectangle, bases<ripley::RipleyDomain> >("RipleyRectangle", "", no_init);      class_<ripley::Rectangle, bases<ripley::RipleyDomain> >("RipleyRectangle", "", no_init);
 /*      
     .def("randomFill", &ripley::Rectangle::randomFill,":return: random data\n:rtype: `Data`\n:param seed: pass zero to use system generated seed\n:type seed: `int`\n"  
 ":param details: more info about the type of randomness\nCurrently, the only acceptable value for this tuple is ('gaussian', r, s) where r is the radius of the"  
 "guassian blur and s is the sigma parameter."  
     );  
 */      
475  }  }
476    

Legend:
Removed from v.4738  
changed lines
  Added in v.4942

  ViewVC Help
Powered by ViewVC 1.1.26