/[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 5148 by caltinay, Mon Sep 15 01:25:23 2014 UTC
# Line 14  Line 14 
14  *  *
15  *****************************************************************************/  *****************************************************************************/
16    
17    #include <ripley/AbstractAssembler.h>
18  #include <ripley/Brick.h>  #include <ripley/Brick.h>
19  #include <ripley/Rectangle.h>  #include <ripley/Rectangle.h>
20  #include <esysUtils/esysExceptionTranslator.h>  #include <esysUtils/esysExceptionTranslator.h>
21    
22  #include <boost/python.hpp>  #include <boost/python.hpp>
23  #include <boost/python/module.hpp>  #include <boost/python/module.hpp>
24  #include <boost/python/def.hpp>  #include <boost/python/def.hpp>
25  #include <boost/python/detail/defaults_gen.hpp>  #include <boost/python/detail/defaults_gen.hpp>
26  #include <boost/version.hpp>  #include <boost/version.hpp>
27    
28    #include "escript/SubWorld.h"
29    
30  using namespace boost::python;  using namespace boost::python;
31    
32  namespace ripley {  namespace ripley {
# Line 136  escript::Data readNcGrid(std::string fil Line 139  escript::Data readNcGrid(std::string fil
139  // truediv  // truediv
140  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,
141                   const object& l1, const object& l2, int d0, int d1, int d2,                   const object& l1, const object& l2, int d0, int d1, int d2,
142                   const object& objpoints, const object& objtags)                   const object& objpoints, const object& objtags, escript::SubWorld_ptr world)
143  {  {
144      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);
145      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 178  escript::Domain_ptr _brick(double _n0, d
178          z1=extract<double>(l2);          z1=extract<double>(l2);
179      } else      } else
180          throw RipleyException("Argument l2 must be a float or 2-tuple");          throw RipleyException("Argument l2 must be a float or 2-tuple");
   
181      boost::python::list pypoints=extract<boost::python::list>(objpoints);      boost::python::list pypoints=extract<boost::python::list>(objpoints);
182      boost::python::list pytags=extract<boost::python::list>(objtags);      boost::python::list pytags=extract<boost::python::list>(objtags);
183      int numpts=extract<int>(pypoints.attr("__len__")());      int numpts=extract<int>(pypoints.attr("__len__")());
# Line 184  escript::Domain_ptr _brick(double _n0, d Line 186  escript::Domain_ptr _brick(double _n0, d
186      std::vector<int> tags;      std::vector<int> tags;
187      tags.resize(numtags, -1);      tags.resize(numtags, -1);
188      for (int i=0;i<numpts;++i) {      for (int i=0;i<numpts;++i) {
189          boost::python::object temp=pypoints[i];          tuple temp = extract<tuple>(pypoints[i]);
190          int l=extract<int>(temp.attr("__len__")());          int l=extract<int>(temp.attr("__len__")());
191            if (l != 3)
192                throw RipleyException("Number of coordinates for each dirac point must match dimensions.");
193          for (int k=0;k<l;++k) {          for (int k=0;k<l;++k) {
194              points.push_back(extract<double>(temp[k]));              points.push_back(extract<double>(temp[k]));
195          }          }
# Line 216  escript::Domain_ptr _brick(double _n0, d Line 220  escript::Domain_ptr _brick(double _n0, d
220              throw RipleyException("Error - Unable to extract tag value.");              throw RipleyException("Error - Unable to extract tag value.");
221          }          }
222      }      }
223        if (numtags != numpts)
224            throw RipleyException("Number of tags does not match number of points.");
225      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,
226                                              points, tags, tagstonames));                                              points, tags, tagstonames, world));
227  }  }
228    
229  const int _q[]={0x61686969,0x746c4144,0x79616e43};  //const int _q[]={0x61686969,0x746c4144,0x79616e43};
230    const int _q[]={0x62207363, 0x6574735F, 0x2020214e};
231  escript::Domain_ptr _rectangle(double _n0, double _n1, const object& l0,  escript::Domain_ptr _rectangle(double _n0, double _n1, const object& l0,
232                                 const object& l1, int d0, int d1,                                 const object& l1, int d0, int d1,
233                                 const object& objpoints, const object& objtags)                                 const object& objpoints, const object& objtags,
234                      escript::SubWorld_ptr world
235                      )
236  {  {
237      int n0=static_cast<int>(_n0), n1=static_cast<int>(_n1);      int n0=static_cast<int>(_n0), n1=static_cast<int>(_n1);
238      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 259  escript::Domain_ptr _rectangle(double _n
259          y1=extract<double>(l1);          y1=extract<double>(l1);
260      } else      } else
261          throw RipleyException("Argument l1 must be a float or 2-tuple");          throw RipleyException("Argument l1 must be a float or 2-tuple");
           
262      boost::python::list pypoints=extract<boost::python::list>(objpoints);      boost::python::list pypoints=extract<boost::python::list>(objpoints);
263      boost::python::list pytags=extract<boost::python::list>(objtags);      boost::python::list pytags=extract<boost::python::list>(objtags);
264      int numpts=extract<int>(pypoints.attr("__len__")());      int numpts=extract<int>(pypoints.attr("__len__")());
# Line 259  escript::Domain_ptr _rectangle(double _n Line 267  escript::Domain_ptr _rectangle(double _n
267      std::vector<int> tags;      std::vector<int> tags;
268      tags.resize(numtags, -1);      tags.resize(numtags, -1);
269      for (int i=0;i<numpts;++i) {      for (int i=0;i<numpts;++i) {
270          boost::python::object temp=pypoints[i];          tuple temp = extract<tuple>(pypoints[i]);
271          int l=extract<int>(temp.attr("__len__")());          int l=extract<int>(temp.attr("__len__")());
272            if (l != 2)
273                throw RipleyException("Number of coordinates for each dirac point must match dimensions.");
274          for (int k=0;k<l;++k) {          for (int k=0;k<l;++k) {
275              points.push_back(extract<double>(temp[k]));              points.push_back(extract<double>(temp[k]));
276          }          }
# Line 291  escript::Domain_ptr _rectangle(double _n Line 301  escript::Domain_ptr _rectangle(double _n
301              throw RipleyException("Error - Unable to extract tag value.");              throw RipleyException("Error - Unable to extract tag value.");
302          }          }
303      }      }
304        if (numtags != numpts)
305            throw RipleyException("Number of tags does not match number of points.");
306      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,
307                                               points, tags, tagstonames));                                               points, tags, tagstonames, world));
308  }  }
309  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];}
310    
# Line 307  BOOST_PYTHON_MODULE(ripleycpp) Line 319  BOOST_PYTHON_MODULE(ripleycpp)
319      docstring_options docopt(true, true, false);      docstring_options docopt(true, true, false);
320  #endif  #endif
321    
322      register_exception_translator<ripley::RipleyException>(&(esysUtils::esysExceptionTranslator));      register_exception_translator<ripley::RipleyException>(&(esysUtils::RuntimeErrorTranslator));
323    
324      scope().attr("__doc__") = "To use this module, please import esys.ripley";      scope().attr("__doc__") = "To use this module, please import esys.ripley";
325      scope().attr("BYTEORDER_NATIVE") = (int)ripley::BYTEORDER_NATIVE;      scope().attr("BYTEORDER_NATIVE") = (int)ripley::BYTEORDER_NATIVE;
# Line 317  BOOST_PYTHON_MODULE(ripleycpp) Line 329  BOOST_PYTHON_MODULE(ripleycpp)
329      scope().attr("DATATYPE_FLOAT32") = (int)ripley::DATATYPE_FLOAT32;      scope().attr("DATATYPE_FLOAT32") = (int)ripley::DATATYPE_FLOAT32;
330      scope().attr("DATATYPE_FLOAT64") = (int)ripley::DATATYPE_FLOAT64;      scope().attr("DATATYPE_FLOAT64") = (int)ripley::DATATYPE_FLOAT64;
331    
332      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,
333            arg("d0")=-1,arg("d1")=-1,arg("d2")=-1,arg("diracPoints")=list(),arg("diracTags")=list(), arg("escriptworld")=escript::SubWorld_ptr()),
334  "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"
335  ":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"
336  ":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 342  BOOST_PYTHON_MODULE(ripleycpp)
342  ":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"
343  ":param d2: number of subdivisions in direction 2\n:type d2: ``int``");  ":param d2: number of subdivisions in direction 2\n:type d2: ``int``");
344    
345      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()),
346  "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"
347  ":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"
348  ":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 339  BOOST_PYTHON_MODULE(ripleycpp) Line 352  BOOST_PYTHON_MODULE(ripleycpp)
352  ":param d1: number of subdivisions in direction 1\n:type d1: ``int``");  ":param d1: number of subdivisions in direction 1\n:type d1: ``int``");
353      def("_theculprit_", ripley::_who);      def("_theculprit_", ripley::_who);
354    
355      def("_readBinaryGrid", &ripley::readBinaryGrid, (arg("filename"),      def("readBinaryGrid", &ripley::readBinaryGrid, (arg("filename"),
356                  arg("functionspace"), arg("shape"), arg("fill")=0.,                  arg("functionspace"), arg("shape"), arg("fill")=0.,
357                  arg("byteOrder"), arg("dataType"), arg("first"),                  arg("byteOrder"), arg("dataType"), arg("first"),
358                  arg("numValues"), arg("multiplier"), arg("reverse")),                  arg("numValues"), arg("multiplier"), arg("reverse")),
# Line 385  BOOST_PYTHON_MODULE(ripleycpp) Line 398  BOOST_PYTHON_MODULE(ripleycpp)
398              ":param mat:\n:type mat: `OperatorAdapter`\n"              ":param mat:\n:type mat: `OperatorAdapter`\n"
399              ":param rhs:\n:type rhs: `Data`\n"              ":param rhs:\n:type rhs: `Data`\n"
400              ":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`"  
 )  
401          .def("addToRHS",&ripley::RipleyDomain::addToRHSFromPython,          .def("addToRHS",&ripley::RipleyDomain::addToRHSFromPython,
402              args("rhs", "data"),              args("rhs", "data"),
403              "adds a PDE onto the stiffness matrix mat and a rhs, "              "adds a PDE onto the stiffness matrix mat and a rhs, "
404              "results depends on domain\n\n"              "results depends on domain\n\n"
405              ":param rhs:\n:type rhs: `Data`\n"              ":param rhs:\n:type rhs: `Data`\n"
406              ":param data:\ntype data: `list`")              ":param data:\ntype data: `list`")
407          .def("setAssembler", &ripley::RipleyDomain::setAssemblerFromPython,          .def("createAssembler", &ripley::RipleyDomain::createAssemblerFromPython,
408              args("typename", "options"),              args("typename", "options"),
409              "sets the domain to use the named assembler, if supported, using"              "request from the domain an assembler of the specified type, if "
410              "the options if provided"              "supported, using the supplied options (if provided)"
411              ":param typename:\n:type typename: `string`\n"              ":param typename:\n:type typename: `string`\n"
412              ":param options:\n:type options: `list`\n")              ":param options:\n:type options: `list`\n")
413          .def("addPDEToTransportProblem",&ripley::RipleyDomain::addPDEToTransportProblem,          .def("addPDEToTransportProblem",&ripley::RipleyDomain::addPDEToTransportProblemFromPython,
414  args( "tp", "source", "M", "A", "B", "C", "D", "X", "Y", "d", "y", "d_contact", "y_contact"),              args("tp", "source", "data"),
415  ":param tp:\n:type tp: `TransportProblemAdapter`\n"              ":param tp:\n:type tp: `TransportProblemAdapter`\n"
416  ":param source:\n:type source: `Data`\n"              ":param source:\n:type source: `Data`\n"
417  ":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`"  
 )  
418          .def("newOperator",&ripley::RipleyDomain::newSystemMatrix,          .def("newOperator",&ripley::RipleyDomain::newSystemMatrix,
419  args("row_blocksize", "row_functionspace", "column_blocksize", "column_functionspace", "type"),  args("row_blocksize", "row_functionspace", "column_blocksize", "column_functionspace", "type"),
420  "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 455  args("theta", "blocksize", "functionspac Line 433  args("theta", "blocksize", "functionspac
433  ":param type:\n:type type: ``int``"  ":param type:\n:type type: ``int``"
434  )  )
435          .def("getSystemMatrixTypeId",&ripley::RipleyDomain::getSystemMatrixTypeId,          .def("getSystemMatrixTypeId",&ripley::RipleyDomain::getSystemMatrixTypeId,
436  args("solver", "preconditioner", "package", "symmetry"),  args("options"),
437  ":return: the identifier of the matrix type to be used for the global stiffness matrix when a particular solver, package, preconditioner, and symmetric matrix is used.\n"  ":return: the identifier of the matrix type to be used for the global stiffness matrix when particular solver options are used.\n"
438  ":rtype: ``int``\n"  ":rtype: ``int``\n"
439  ":param solver:\n:type solver: ``int``\n"  ":param options:\n:type options: `SolverBuddy`\n"
 ":param preconditioner:\n:type preconditioner: ``int``\n"  
 ":param package:\n:type package: ``int``\n"  
 ":param symmetry:\n:type symmetry: ``int``"  
440  )  )
441          .def("getTransportTypeId",&ripley::RipleyDomain::getTransportTypeId,          .def("getTransportTypeId",&ripley::RipleyDomain::getTransportTypeId,
442  args("solver", "preconditioner", "package", "symmetry"),  args("solver", "preconditioner", "package", "symmetry"),
# Line 491  args("solver", "preconditioner", "packag Line 466  args("solver", "preconditioner", "packag
466          .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``")
467          .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")
468          .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`");
469        /* These two class exports are necessary to ensure that the extra methods added by ripley make it to python.
470         * This change became necessary when the Brick and Rectangle constructors turned into factories instead of classes */
471      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."  
     );  
 */      
472      class_<ripley::Rectangle, bases<ripley::RipleyDomain> >("RipleyRectangle", "", no_init);      class_<ripley::Rectangle, bases<ripley::RipleyDomain> >("RipleyRectangle", "", no_init);
473  /*          class_<ripley::AbstractAssembler, ripley::Assembler_ptr, boost::noncopyable >
474      .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"          ("AbstractAssembler", "", no_init);
 ":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.5148

  ViewVC Help
Powered by ViewVC 1.1.26