/[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 4906 by sshaw, Tue Apr 29 05:27:34 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>
# Line 175  escript::Domain_ptr _brick(double _n0, d Line 175  escript::Domain_ptr _brick(double _n0, d
175          z1=extract<double>(l2);          z1=extract<double>(l2);
176      } else      } else
177          throw RipleyException("Argument l2 must be a float or 2-tuple");          throw RipleyException("Argument l2 must be a float or 2-tuple");
   
178      boost::python::list pypoints=extract<boost::python::list>(objpoints);      boost::python::list pypoints=extract<boost::python::list>(objpoints);
179      boost::python::list pytags=extract<boost::python::list>(objtags);      boost::python::list pytags=extract<boost::python::list>(objtags);
180      int numpts=extract<int>(pypoints.attr("__len__")());      int numpts=extract<int>(pypoints.attr("__len__")());
# Line 184  escript::Domain_ptr _brick(double _n0, d Line 183  escript::Domain_ptr _brick(double _n0, d
183      std::vector<int> tags;      std::vector<int> tags;
184      tags.resize(numtags, -1);      tags.resize(numtags, -1);
185      for (int i=0;i<numpts;++i) {      for (int i=0;i<numpts;++i) {
186          boost::python::object temp=pypoints[i];          tuple temp = extract<tuple>(pypoints[i]);
187          int l=extract<int>(temp.attr("__len__")());          int l=extract<int>(temp.attr("__len__")());
188            if (l != 3)
189                throw RipleyException("Number of coordinates for each dirac point must match dimensions.");
190          for (int k=0;k<l;++k) {          for (int k=0;k<l;++k) {
191              points.push_back(extract<double>(temp[k]));              points.push_back(extract<double>(temp[k]));
192          }          }
# Line 216  escript::Domain_ptr _brick(double _n0, d Line 217  escript::Domain_ptr _brick(double _n0, d
217              throw RipleyException("Error - Unable to extract tag value.");              throw RipleyException("Error - Unable to extract tag value.");
218          }          }
219      }      }
220        if (numtags != numpts)
221            throw RipleyException("Number of tags does not match number of points.");
222      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,
223                                              points, tags, tagstonames));                                              points, tags, tagstonames));
224  }  }
225    
226  const int _q[]={0x61686969,0x746c4144,0x79616e43};  //const int _q[]={0x61686969,0x746c4144,0x79616e43};
227    const int _q[]={0x62207363, 0x6574735F, 0x2020214e};
228  escript::Domain_ptr _rectangle(double _n0, double _n1, const object& l0,  escript::Domain_ptr _rectangle(double _n0, double _n1, const object& l0,
229                                 const object& l1, int d0, int d1,                                 const object& l1, int d0, int d1,
230                                 const object& objpoints, const object& objtags)                                 const object& objpoints, const object& objtags)
# Line 250  escript::Domain_ptr _rectangle(double _n Line 254  escript::Domain_ptr _rectangle(double _n
254          y1=extract<double>(l1);          y1=extract<double>(l1);
255      } else      } else
256          throw RipleyException("Argument l1 must be a float or 2-tuple");          throw RipleyException("Argument l1 must be a float or 2-tuple");
           
257      boost::python::list pypoints=extract<boost::python::list>(objpoints);      boost::python::list pypoints=extract<boost::python::list>(objpoints);
258      boost::python::list pytags=extract<boost::python::list>(objtags);      boost::python::list pytags=extract<boost::python::list>(objtags);
259      int numpts=extract<int>(pypoints.attr("__len__")());      int numpts=extract<int>(pypoints.attr("__len__")());
# Line 259  escript::Domain_ptr _rectangle(double _n Line 262  escript::Domain_ptr _rectangle(double _n
262      std::vector<int> tags;      std::vector<int> tags;
263      tags.resize(numtags, -1);      tags.resize(numtags, -1);
264      for (int i=0;i<numpts;++i) {      for (int i=0;i<numpts;++i) {
265          boost::python::object temp=pypoints[i];          tuple temp = extract<tuple>(pypoints[i]);
266          int l=extract<int>(temp.attr("__len__")());          int l=extract<int>(temp.attr("__len__")());
267            if (l != 2)
268                throw RipleyException("Number of coordinates for each dirac point must match dimensions.");
269          for (int k=0;k<l;++k) {          for (int k=0;k<l;++k) {
270              points.push_back(extract<double>(temp[k]));              points.push_back(extract<double>(temp[k]));
271          }          }
# Line 291  escript::Domain_ptr _rectangle(double _n Line 296  escript::Domain_ptr _rectangle(double _n
296              throw RipleyException("Error - Unable to extract tag value.");              throw RipleyException("Error - Unable to extract tag value.");
297          }          }
298      }      }
299        if (numtags != numpts)
300            throw RipleyException("Number of tags does not match number of points.");
301      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,
302                                               points, tags, tagstonames));                                               points, tags, tagstonames));
303  }  }
# Line 307  BOOST_PYTHON_MODULE(ripleycpp) Line 314  BOOST_PYTHON_MODULE(ripleycpp)
314      docstring_options docopt(true, true, false);      docstring_options docopt(true, true, false);
315  #endif  #endif
316    
317      register_exception_translator<ripley::RipleyException>(&(esysUtils::esysExceptionTranslator));      register_exception_translator<ripley::RipleyException>(&(esysUtils::RuntimeErrorTranslator));
318    
319      scope().attr("__doc__") = "To use this module, please import esys.ripley";      scope().attr("__doc__") = "To use this module, please import esys.ripley";
320      scope().attr("BYTEORDER_NATIVE") = (int)ripley::BYTEORDER_NATIVE;      scope().attr("BYTEORDER_NATIVE") = (int)ripley::BYTEORDER_NATIVE;
# Line 491  args("solver", "preconditioner", "packag Line 498  args("solver", "preconditioner", "packag
498          .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``")
499          .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")
500          .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`");
501        /* These two class exports are necessary to ensure that the extra methods added by ripley make it to python.
502         * This change became necessary when the Brick and Rectangle constructors turned into factories instead of classes */
503      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."  
     );  
 */      
504      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."  
     );  
 */      
505  }  }
506    

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

  ViewVC Help
Powered by ViewVC 1.1.26