/[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 4828 by sshaw, Wed Apr 2 07:01:38 2014 UTC
# 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__")());
181      int numtags=extract<int>(pytags.attr("__len__")());      int numtags=extract<int>(pytags.attr("__len__")());
182        if (numtags != numpts)
183            throw RipleyException("Number of tags does not match number of points.");
184      std::vector<double> points;      std::vector<double> points;
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 220  escript::Domain_ptr _brick(double _n0, d Line 223  escript::Domain_ptr _brick(double _n0, d
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__")());
260      int numtags=extract<int>(pytags.attr("__len__")());      int numtags=extract<int>(pytags.attr("__len__")());
261        if (numtags != numpts)
262            throw RipleyException("Number of tags does not match number of points.");
263      std::vector<double> points;      std::vector<double> points;
264      std::vector<int> tags;      std::vector<int> tags;
265      tags.resize(numtags, -1);      tags.resize(numtags, -1);
266      for (int i=0;i<numpts;++i) {      for (int i=0;i<numpts;++i) {
267          boost::python::object temp=pypoints[i];          tuple temp = extract<tuple>(pypoints[i]);
268          int l=extract<int>(temp.attr("__len__")());          int l=extract<int>(temp.attr("__len__")());
269            if (l != 2)
270                throw RipleyException("Number of coordinates for each dirac point must match dimensions.");
271          for (int k=0;k<l;++k) {          for (int k=0;k<l;++k) {
272              points.push_back(extract<double>(temp[k]));              points.push_back(extract<double>(temp[k]));
273          }          }
# 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.4828

  ViewVC Help
Powered by ViewVC 1.1.26