/[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 4622 by sshaw, Fri Jan 17 04:55:41 2014 UTC revision 5593 by jfenwick, Fri Apr 24 01:36:26 2015 UTC
# Line 1  Line 1 
1    
2  /*****************************************************************************  /*****************************************************************************
3  *  *
4  * Copyright (c) 2003-2013 by University of Queensland  * Copyright (c) 2003-2015 by The University of Queensland
5  * http://www.uq.edu.au  * http://www.uq.edu.au
6  *  *
7  * Primary Business: Queensland, Australia  * Primary Business: Queensland, Australia
# Line 9  Line 9 
9  * http://www.opensource.org/licenses/osl-3.0.php  * http://www.opensource.org/licenses/osl-3.0.php
10  *  *
11  * Development until 2012 by Earth Systems Science Computational Center (ESSCC)  * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12  * Development since 2012 by School of Earth Sciences  * Development 2012-2013 by School of Earth Sciences
13    * Development from 2014 by Centre for Geoscience Computing (GeoComp)
14  *  *
15  *****************************************************************************/  *****************************************************************************/
16    
17    #define ESNEEDPYTHON
18    #include "esysUtils/first.h"
19    
20    #include <ripley/AbstractAssembler.h>
21  #include <ripley/Brick.h>  #include <ripley/Brick.h>
22    #include <ripley/MultiBrick.h>
23  #include <ripley/Rectangle.h>  #include <ripley/Rectangle.h>
24    #include <ripley/MultiRectangle.h>
25  #include <esysUtils/esysExceptionTranslator.h>  #include <esysUtils/esysExceptionTranslator.h>
26    
27  #include <boost/python.hpp>  #include <boost/python.hpp>
28  #include <boost/python/module.hpp>  #include <boost/python/module.hpp>
29  #include <boost/python/def.hpp>  #include <boost/python/def.hpp>
30  #include <boost/python/detail/defaults_gen.hpp>  #include <boost/python/detail/defaults_gen.hpp>
31  #include <boost/version.hpp>  #include <boost/version.hpp>
32    
33    #include "escript/SubWorld.h"
34    
35  using namespace boost::python;  using namespace boost::python;
36    
37  namespace ripley {  namespace ripley {
# Line 61  escript::Data readBinaryGrid(std::string Line 70  escript::Data readBinaryGrid(std::string
70      int dim=fs.getDim();      int dim=fs.getDim();
71      ReaderParameters params;      ReaderParameters params;
72    
73      params.first = extractPyArray<int>(pyFirst, "first", dim);      params.first = extractPyArray<dim_t>(pyFirst, "first", dim);
74      params.numValues = extractPyArray<int>(pyNum, "numValues", dim);      params.numValues = extractPyArray<dim_t>(pyNum, "numValues", dim);
75      params.multiplier = extractPyArray<int>(pyMultiplier, "multiplier", dim);      params.multiplier = extractPyArray<int>(pyMultiplier, "multiplier", dim);
76      params.reverse = extractPyArray<int>(pyReverse, "reverse", dim);      params.reverse = extractPyArray<int>(pyReverse, "reverse", dim);
77      params.byteOrder = byteOrder;      params.byteOrder = byteOrder;
# Line 78  escript::Data readBinaryGrid(std::string Line 87  escript::Data readBinaryGrid(std::string
87      return res;      return res;
88  }  }
89    
90    #ifdef USE_BOOSTIO
91    escript::Data readBinaryGridFromZipped(std::string filename, escript::FunctionSpace fs,
92            const object& pyShape, double fill, int byteOrder, int dataType,
93            const object& pyFirst, const object& pyNum, const object& pyMultiplier,
94            const object& pyReverse)
95    {
96        int dim=fs.getDim();
97        ReaderParameters params;
98    
99        params.first = extractPyArray<dim_t>(pyFirst, "first", dim);
100        params.numValues = extractPyArray<dim_t>(pyNum, "numValues", dim);
101        params.multiplier = extractPyArray<int>(pyMultiplier, "multiplier", dim);
102        params.reverse = extractPyArray<int>(pyReverse, "reverse", dim);
103        params.byteOrder = byteOrder;
104        params.dataType = dataType;
105        std::vector<int> shape(extractPyArray<int>(pyShape, "shape"));
106    
107        const RipleyDomain* dom=dynamic_cast<const RipleyDomain*>(fs.getDomain().get());
108        if (!dom)
109            throw RipleyException("Function space must be on a ripley domain");
110    
111        escript::Data res(fill, shape, fs, true);
112        dom->readBinaryGridFromZipped(res, filename, params);
113        return res;
114    }
115    #endif
116    
117  escript::Data readNcGrid(std::string filename, std::string varname,  escript::Data readNcGrid(std::string filename, std::string varname,
118          escript::FunctionSpace fs, const object& pyShape, double fill,          escript::FunctionSpace fs, const object& pyShape, double fill,
119          const object& pyFirst, const object& pyNum, const object& pyMultiplier,          const object& pyFirst, const object& pyNum, const object& pyMultiplier,
# Line 86  escript::Data readNcGrid(std::string fil Line 122  escript::Data readNcGrid(std::string fil
122      int dim=fs.getDim();      int dim=fs.getDim();
123      ReaderParameters params;      ReaderParameters params;
124    
125      params.first = extractPyArray<int>(pyFirst, "first", dim);      params.first = extractPyArray<dim_t>(pyFirst, "first", dim);
126      params.numValues = extractPyArray<int>(pyNum, "numValues", dim);      params.numValues = extractPyArray<dim_t>(pyNum, "numValues", dim);
127      params.multiplier = extractPyArray<int>(pyMultiplier, "multiplier", dim);      params.multiplier = extractPyArray<int>(pyMultiplier, "multiplier", dim);
128      params.reverse = extractPyArray<int>(pyReverse, "reverse", dim);      params.reverse = extractPyArray<int>(pyReverse, "reverse", dim);
129      std::vector<int> shape(extractPyArray<int>(pyShape, "shape"));      std::vector<int> shape(extractPyArray<int>(pyShape, "shape"));
# Line 108  escript::Data readNcGrid(std::string fil Line 144  escript::Data readNcGrid(std::string fil
144  // truediv  // truediv
145  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,
146                   const object& l1, const object& l2, int d0, int d1, int d2,                   const object& l1, const object& l2, int d0, int d1, int d2,
147                   const object& objpoints, const object& objtags)                   const object& objpoints, const object& objtags, escript::SubWorld_ptr world)
148  {  {
149      int n0=static_cast<int>(_n0), n1=static_cast<int>(_n1), n2=static_cast<int>(_n2);      dim_t n0=static_cast<dim_t>(_n0), n1=static_cast<dim_t>(_n1), n2=static_cast<dim_t>(_n2);
150      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.;
151      if (extract<tuple>(l0).check()) {      if (extract<tuple>(l0).check()) {
152          tuple x=extract<tuple>(l0);          tuple x=extract<tuple>(l0);
# Line 147  escript::Domain_ptr _brick(double _n0, d Line 183  escript::Domain_ptr _brick(double _n0, d
183          z1=extract<double>(l2);          z1=extract<double>(l2);
184      } else      } else
185          throw RipleyException("Argument l2 must be a float or 2-tuple");          throw RipleyException("Argument l2 must be a float or 2-tuple");
   
186      boost::python::list pypoints=extract<boost::python::list>(objpoints);      boost::python::list pypoints=extract<boost::python::list>(objpoints);
187      boost::python::list pytags=extract<boost::python::list>(objtags);      boost::python::list pytags=extract<boost::python::list>(objtags);
188      int numpts=extract<int>(pypoints.attr("__len__")());      int numpts=extract<int>(pypoints.attr("__len__")());
# Line 156  escript::Domain_ptr _brick(double _n0, d Line 191  escript::Domain_ptr _brick(double _n0, d
191      std::vector<int> tags;      std::vector<int> tags;
192      tags.resize(numtags, -1);      tags.resize(numtags, -1);
193      for (int i=0;i<numpts;++i) {      for (int i=0;i<numpts;++i) {
194          boost::python::object temp=pypoints[i];          tuple temp = extract<tuple>(pypoints[i]);
195          int l=extract<int>(temp.attr("__len__")());          int l=extract<int>(temp.attr("__len__")());
196            if (l != 3)
197                throw RipleyException("Number of coordinates for each dirac point must match dimensions.");
198          for (int k=0;k<l;++k) {          for (int k=0;k<l;++k) {
199              points.push_back(extract<double>(temp[k]));              points.push_back(extract<double>(temp[k]));
200          }          }
# Line 188  escript::Domain_ptr _brick(double _n0, d Line 225  escript::Domain_ptr _brick(double _n0, d
225              throw RipleyException("Error - Unable to extract tag value.");              throw RipleyException("Error - Unable to extract tag value.");
226          }          }
227      }      }
228        if (numtags != numpts)
229            throw RipleyException("Number of tags does not match number of points.");
230      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,
231                                              points, tags, tagstonames));                                              points, tags, tagstonames, world));
232    }
233    
234    escript::Domain_ptr _multibrick(double _n0, double _n1, double _n2, const object& l0,
235                     const object& l1, const object& l2, int d0, int d1, int d2,
236                     const object& objpoints, const object& objtags, escript::SubWorld_ptr world,
237                     unsigned int multiplier)
238    {
239        dim_t n0=static_cast<dim_t>(_n0), n1=static_cast<dim_t>(_n1), n2=static_cast<dim_t>(_n2);
240        double x0=0., x1=1., y0=0., y1=1., z0=0., z1=1.;
241        if (extract<tuple>(l0).check()) {
242            tuple x=extract<tuple>(l0);
243            if (len(x)==2) {
244                x0=extract<double>(x[0]);
245                x1=extract<double>(x[1]);
246            } else
247                throw RipleyException("Argument l0 must be a float or 2-tuple");
248        } else if (extract<double>(l0).check()) {
249            x1=extract<double>(l0);
250        } else
251            throw RipleyException("Argument l0 must be a float or 2-tuple");
252    
253        if (extract<tuple>(l1).check()) {
254            tuple y=extract<tuple>(l1);
255            if (len(y)==2) {
256                y0=extract<double>(y[0]);
257                y1=extract<double>(y[1]);
258            } else
259                throw RipleyException("Argument l1 must be a float or 2-tuple");
260        } else if (extract<double>(l1).check()) {
261            y1=extract<double>(l1);
262        } else
263            throw RipleyException("Argument l1 must be a float or 2-tuple");
264    
265        if (extract<tuple>(l2).check()) {
266            tuple z=extract<tuple>(l2);
267            if (len(z)==2) {
268                z0=extract<double>(z[0]);
269                z1=extract<double>(z[1]);
270            } else
271                throw RipleyException("Argument l2 must be a float or 2-tuple");
272        } else if (extract<double>(l2).check()) {
273            z1=extract<double>(l2);
274        } else
275            throw RipleyException("Argument l2 must be a float or 2-tuple");
276        boost::python::list pypoints=extract<boost::python::list>(objpoints);
277        boost::python::list pytags=extract<boost::python::list>(objtags);
278        int numpts=extract<int>(pypoints.attr("__len__")());
279        int numtags=extract<int>(pytags.attr("__len__")());
280        std::vector<double> points;
281        std::vector<int> tags;
282        tags.resize(numtags, -1);
283        for (int i=0;i<numpts;++i) {
284            tuple temp = extract<tuple>(pypoints[i]);
285            int l=extract<int>(temp.attr("__len__")());
286            if (l != 3)
287                throw RipleyException("Number of coordinates for each dirac point must match dimensions.");
288            for (int k=0;k<l;++k) {
289                points.push_back(extract<double>(temp[k]));
290            }
291        }
292        std::map<std::string, int> tagstonames;
293        int curmax=40;
294        // but which order to assign tags to names?????
295        for (int i=0;i<numtags;++i) {
296            extract<int> ex_int(pytags[i]);
297            extract<std::string> ex_str(pytags[i]);
298            if (ex_int.check()) {
299                tags[i]=ex_int();
300                if (tags[i]>= curmax) {
301                    curmax=tags[i]+1;
302                }
303            } else if (ex_str.check()) {
304                std::string s=ex_str();
305                std::map<std::string, int>::iterator it=tagstonames.find(s);
306                if (it!=tagstonames.end()) {
307                    // we have the tag already so look it up
308                    tags[i]=it->second;
309                } else {
310                    tagstonames[s]=curmax;
311                    tags[i]=curmax;
312                    curmax++;
313                }
314            } else {
315                throw RipleyException("Error - Unable to extract tag value.");
316            }
317        }
318        if (numtags != numpts)
319            throw RipleyException("Number of tags does not match number of points.");
320        return escript::Domain_ptr(new MultiBrick(n0,n1,n2, x0,y0,z0, x1,y1,z1, d0,d1,d2,
321                                                points, tags, tagstonames, world,
322                                                multiplier));
323    }
324    
325    escript::Domain_ptr _multirectangle(double _n0, double _n1, const object& l0,
326                                   const object& l1, int d0, int d1,
327                                   const object& objpoints, const object& objtags,
328                                   escript::SubWorld_ptr world,
329                                   unsigned int multiplier)
330    {
331        dim_t n0=static_cast<dim_t>(_n0), n1=static_cast<dim_t>(_n1);
332        double x0=0., x1=1., y0=0., y1=1.;
333        if (extract<tuple>(l0).check()) {
334            tuple x=extract<tuple>(l0);
335            if (len(x)==2) {
336                x0=extract<double>(x[0]);
337                x1=extract<double>(x[1]);
338            } else
339                throw RipleyException("Argument l0 must be a float or 2-tuple");
340        } else if (extract<double>(l0).check()) {
341            x1=extract<double>(l0);
342        } else
343            throw RipleyException("Argument l0 must be a float or 2-tuple");
344    
345        if (extract<tuple>(l1).check()) {
346            tuple y=extract<tuple>(l1);
347            if (len(y)==2) {
348                y0=extract<double>(y[0]);
349                y1=extract<double>(y[1]);
350            } else
351                throw RipleyException("Argument l1 must be a float or 2-tuple");
352        } else if (extract<double>(l1).check()) {
353            y1=extract<double>(l1);
354        } else
355            throw RipleyException("Argument l1 must be a float or 2-tuple");
356        boost::python::list pypoints=extract<boost::python::list>(objpoints);
357        boost::python::list pytags=extract<boost::python::list>(objtags);
358        int numpts=extract<int>(pypoints.attr("__len__")());
359        int numtags=extract<int>(pytags.attr("__len__")());
360        std::vector<double> points;
361        std::vector<int> tags;
362        tags.resize(numtags, -1);
363        for (int i=0;i<numpts;++i) {
364            tuple temp = extract<tuple>(pypoints[i]);
365            int l=extract<int>(temp.attr("__len__")());
366            if (l != 2)
367                throw RipleyException("Number of coordinates for each dirac point must match dimensions.");
368            for (int k=0;k<l;++k) {
369                points.push_back(extract<double>(temp[k]));
370            }
371        }
372        std::map<std::string, int> tagstonames;
373        int curmax=40;
374        // but which order to assign tags to names?????
375        for (int i=0;i<numtags;++i) {
376            extract<int> ex_int(pytags[i]);
377            extract<std::string> ex_str(pytags[i]);
378            if (ex_int.check()) {
379                tags[i]=ex_int();
380                if (tags[i] >= curmax) {
381                    curmax=tags[i]+1;
382                }
383            } else if (ex_str.check()) {
384                std::string s=ex_str();
385                std::map<std::string, int>::iterator it=tagstonames.find(s);
386                if (it!=tagstonames.end()) {
387                    // we have the tag already so look it up
388                    tags[i]=it->second;
389                } else {
390                    tagstonames[s]=curmax;
391                    tags[i]=curmax;
392                    curmax++;
393                }
394            } else {
395                throw RipleyException("Error - Unable to extract tag value.");
396            }
397        }
398        if (numtags != numpts)
399            throw RipleyException("Number of tags does not match number of points.");
400        return escript::Domain_ptr(new MultiRectangle(n0,n1, x0,y0, x1,y1, d0,d1,
401                                     points, tags, tagstonames, world, multiplier));
402  }  }
403    
 const int _q[]={0x61686969,0x746c4144,0x79616e43};  
404  escript::Domain_ptr _rectangle(double _n0, double _n1, const object& l0,  escript::Domain_ptr _rectangle(double _n0, double _n1, const object& l0,
405                                 const object& l1, int d0, int d1,                                 const object& l1, int d0, int d1,
406                                 const object& objpoints, const object& objtags)                                 const object& objpoints, const object& objtags,
407                      escript::SubWorld_ptr world
408                      )
409  {  {
410      int n0=static_cast<int>(_n0), n1=static_cast<int>(_n1);      dim_t n0=static_cast<dim_t>(_n0), n1=static_cast<dim_t>(_n1);
411      double x0=0., x1=1., y0=0., y1=1.;      double x0=0., x1=1., y0=0., y1=1.;
412      if (extract<tuple>(l0).check()) {      if (extract<tuple>(l0).check()) {
413          tuple x=extract<tuple>(l0);          tuple x=extract<tuple>(l0);
# Line 222  escript::Domain_ptr _rectangle(double _n Line 432  escript::Domain_ptr _rectangle(double _n
432          y1=extract<double>(l1);          y1=extract<double>(l1);
433      } else      } else
434          throw RipleyException("Argument l1 must be a float or 2-tuple");          throw RipleyException("Argument l1 must be a float or 2-tuple");
           
435      boost::python::list pypoints=extract<boost::python::list>(objpoints);      boost::python::list pypoints=extract<boost::python::list>(objpoints);
436      boost::python::list pytags=extract<boost::python::list>(objtags);      boost::python::list pytags=extract<boost::python::list>(objtags);
437      int numpts=extract<int>(pypoints.attr("__len__")());      int numpts=extract<int>(pypoints.attr("__len__")());
# Line 231  escript::Domain_ptr _rectangle(double _n Line 440  escript::Domain_ptr _rectangle(double _n
440      std::vector<int> tags;      std::vector<int> tags;
441      tags.resize(numtags, -1);      tags.resize(numtags, -1);
442      for (int i=0;i<numpts;++i) {      for (int i=0;i<numpts;++i) {
443          boost::python::object temp=pypoints[i];          tuple temp = extract<tuple>(pypoints[i]);
444          int l=extract<int>(temp.attr("__len__")());          int l=extract<int>(temp.attr("__len__")());
445            if (l != 2)
446                throw RipleyException("Number of coordinates for each dirac point must match dimensions.");
447          for (int k=0;k<l;++k) {          for (int k=0;k<l;++k) {
448              points.push_back(extract<double>(temp[k]));              points.push_back(extract<double>(temp[k]));
449          }          }
# Line 245  escript::Domain_ptr _rectangle(double _n Line 456  escript::Domain_ptr _rectangle(double _n
456          extract<std::string> ex_str(pytags[i]);          extract<std::string> ex_str(pytags[i]);
457          if (ex_int.check()) {          if (ex_int.check()) {
458              tags[i]=ex_int();              tags[i]=ex_int();
459              if (tags[i]>= curmax) {              if (tags[i] >= curmax) {
460                  curmax=tags[i]+1;                  curmax=tags[i]+1;
461              }              }
462          } else if (ex_str.check()) {          } else if (ex_str.check()) {
# Line 263  escript::Domain_ptr _rectangle(double _n Line 474  escript::Domain_ptr _rectangle(double _n
474              throw RipleyException("Error - Unable to extract tag value.");              throw RipleyException("Error - Unable to extract tag value.");
475          }          }
476      }      }
477        if (numtags != numpts)
478            throw RipleyException("Number of tags does not match number of points.");
479      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,
480                                               points, tags, tagstonames));                                               points, tags, tagstonames, world));
481  }  }
 std::string _who(){int a[]={_q[0]^42,_q[1]^42,_q[2]^42,0};return (char*)&a[0];}  
482    
483  } // end of namespace ripley  } // end of namespace ripley
484    
# Line 279  BOOST_PYTHON_MODULE(ripleycpp) Line 491  BOOST_PYTHON_MODULE(ripleycpp)
491      docstring_options docopt(true, true, false);      docstring_options docopt(true, true, false);
492  #endif  #endif
493    
494      register_exception_translator<ripley::RipleyException>(&(esysUtils::esysExceptionTranslator));      register_exception_translator<ripley::RipleyException>(&(esysUtils::RuntimeErrorTranslator));
495    
496      scope().attr("__doc__") = "To use this module, please import esys.ripley";      scope().attr("__doc__") = "To use this module, please import esys.ripley";
497      scope().attr("BYTEORDER_NATIVE") = (int)ripley::BYTEORDER_NATIVE;      scope().attr("BYTEORDER_NATIVE") = (int)ripley::BYTEORDER_NATIVE;
# Line 289  BOOST_PYTHON_MODULE(ripleycpp) Line 501  BOOST_PYTHON_MODULE(ripleycpp)
501      scope().attr("DATATYPE_FLOAT32") = (int)ripley::DATATYPE_FLOAT32;      scope().attr("DATATYPE_FLOAT32") = (int)ripley::DATATYPE_FLOAT32;
502      scope().attr("DATATYPE_FLOAT64") = (int)ripley::DATATYPE_FLOAT64;      scope().attr("DATATYPE_FLOAT64") = (int)ripley::DATATYPE_FLOAT64;
503    
504      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,
505  "Creates a hexagonal mesh with n0 x n1 x n2 elements over the brick [0,l0] x [0,l1] x [0,l2].\n\n"          arg("l1")=1.0,arg("l2")=1.0,arg("d0")=-1,arg("d1")=-1,arg("d2")=-1,
506  ":param n0: number of elements in direction 0\n:type n0: ``int``\n"          arg("diracPoints")=list(),arg("diracTags")=list(),
507  ":param n1: number of elements in direction 1\n:type n1: ``int``\n"          arg("escriptworld")=escript::SubWorld_ptr()),
508  ":param n2: number of elements in direction 2\n:type n2: ``int``\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"
509  ":param l0: length of side 0 or coordinate range of side 0\n:type l0: ``float`` or ``tuple``\n"          ":param n0: number of elements in direction 0\n:type n0: ``int``\n"
510  ":param l1: length of side 1 or coordinate range of side 1\n:type l1: ``float`` or ``tuple``\n"          ":param n1: number of elements in direction 1\n:type n1: ``int``\n"
511  ":param l2: length of side 2 or coordinate range of side 2\n:type l2: ``float`` or ``tuple``\n"          ":param n2: number of elements in direction 2\n:type n2: ``int``\n"
512  ":param d0: number of subdivisions in direction 0\n:type d0: ``int``\n"          ":param l0: length of side 0 or coordinate range of side 0\n:type l0: ``float`` or ``tuple``\n"
513  ":param d1: number of subdivisions in direction 1\n:type d1: ``int``\n"          ":param l1: length of side 1 or coordinate range of side 1\n:type l1: ``float`` or ``tuple``\n"
514  ":param d2: number of subdivisions in direction 2\n:type d2: ``int``");          ":param l2: length of side 2 or coordinate range of side 2\n:type l2: ``float`` or ``tuple``\n"
515            ":param d0: number of subdivisions in direction 0\n:type d0: ``int``\n"
516      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()),          ":param d1: number of subdivisions in direction 1\n:type d1: ``int``\n"
517  "Creates a rectangular mesh with n0 x n1 elements over the rectangle [0,l0] x [0,l1].\n\n"          ":param d2: number of subdivisions in direction 2\n:type d2: ``int``");
518  ":param n0: number of elements in direction 0\n:type n0: ``int``\n"  
519  ":param n1: number of elements in direction 1\n:type n1: ``int``\n"      def("Rectangle", ripley::_rectangle, (arg("n0"),arg("n1"),arg("l0")=1.0,
520  ":param l0: length of side 0 or coordinate range of side 0\n:type l0: ``float`` or ``tuple``\n"          arg("l1")=1.0,arg("d0")=-1,arg("d1")=-1,arg("diracPoints")=list(),
521  ":param l1: length of side 1 or coordinate range of side 1\n:type l1: ``float`` or ``tuple``\n"          arg("diracTags")=list(), arg("escriptworld")=escript::SubWorld_ptr()),
522  ":param d0: number of subdivisions in direction 0\n:type d0: ``int``\n"          "Creates a rectangular mesh with n0 x n1 elements over the rectangle [0,l0] x [0,l1].\n\n"
523  ":param d1: number of subdivisions in direction 1\n:type d1: ``int``");          ":param n0: number of elements in direction 0\n:type n0: ``int``\n"
524      def("_theculprit_", ripley::_who);          ":param n1: number of elements in direction 1\n:type n1: ``int``\n"
525            ":param l0: length of side 0 or coordinate range of side 0\n:type l0: ``float`` or ``tuple``\n"
526            ":param l1: length of side 1 or coordinate range of side 1\n:type l1: ``float`` or ``tuple``\n"
527            ":param d0: number of subdivisions in direction 0\n:type d0: ``int``\n"
528            ":param d1: number of subdivisions in direction 1\n:type d1: ``int``");
529    
530        def("MultiRectangle", ripley::_multirectangle, (arg("n0"),arg("n1"),
531            arg("l0")=1.0,arg("l1")=1.0,arg("d0")=-1,arg("d1")=-1,
532            arg("diracPoints")=list(),arg("diracTags")=list(),
533            arg("escriptworld")=escript::SubWorld_ptr(), arg("multiplier")=1),
534            "Creates a rectangular mesh with n0 x n1 parent elements over the "
535            "rectangle [0,l0] x [0,l1], each parent element is divided ``multiplier`` times.\n\n"
536            ":param n0: number of elements in direction 0\n:type n0: ``int``\n"
537            ":param n1: number of elements in direction 1\n:type n1: ``int``\n"
538            ":param l0: length of side 0 or coordinate range of side 0\n:type l0: ``float`` or ``tuple``\n"
539            ":param l1: length of side 1 or coordinate range of side 1\n:type l1: ``float`` or ``tuple``\n"
540            ":param d0: number of subdivisions in direction 0\n:type d0: ``int``\n"
541            ":param d1: number of subdivisions in direction 1\n:type d1: ``int``\n"
542            ":param multiplier: size of overlap\n:type multiplier: ``unsigned int``");
543    
544        def("MultiBrick", ripley::_multibrick, (arg("n0"),arg("n1"),arg("n2"),
545            arg("l0")=1.0,arg("l1")=1.0,arg("l2")=1.0,arg("d0")=-1,arg("d1")=-1,
546            arg("d2")=-1,arg("diracPoints")=list(),arg("diracTags")=list(),
547            arg("escriptworld")=escript::SubWorld_ptr(), arg("multiplier")=1),
548            "Creates a hexagonal mesh with n0 x n1 x n2 parent elements over the "
549            "brick [0,l0] x [0,l1] x [0,l2], each parent element is divided ``multiplier`` times.\n\n"
550            ":param n0: number of elements in direction 0\n:type n0: ``int``\n"
551            ":param n1: number of elements in direction 1\n:type n1: ``int``\n"
552            ":param n2: number of elements in direction 2\n:type n2: ``int``\n"
553            ":param l0: length of side 0 or coordinate range of side 0\n:type l0: ``float`` or ``tuple``\n"
554            ":param l1: length of side 1 or coordinate range of side 1\n:type l1: ``float`` or ``tuple``\n"
555            ":param l2: length of side 2 or coordinate range of side 2\n:type l2: ``float`` or ``tuple``\n"
556            ":param d0: number of subdivisions in direction 0\n:type d0: ``int``\n"
557            ":param d1: number of subdivisions in direction 1\n:type d1: ``int``\n"
558            ":param d2: number of subdivisions in direction 2\n:type d2: ``int``"
559            ":param multiplier: size of overlap\n:type multiplier: ``unsigned int``");
560    
561      def("_readBinaryGrid", &ripley::readBinaryGrid, (arg("filename"),      def("readBinaryGrid", &ripley::readBinaryGrid, (arg("filename"),
562                  arg("functionspace"), arg("shape"), arg("fill")=0.,                  arg("functionspace"), arg("shape"), arg("fill")=0.,
563                  arg("byteOrder"), arg("dataType"), arg("first"),                  arg("byteOrder"), arg("dataType"), arg("first"),
564                  arg("numValues"), arg("multiplier"), arg("reverse")),                  arg("numValues"), arg("multiplier"), arg("reverse")),
565  "Reads a binary Grid");              "Reads a binary Grid");
566    #ifdef USE_BOOSTIO
567        def("_readBinaryGridFromZipped", &ripley::readBinaryGridFromZipped, (arg("filename"),
568                    arg("functionspace"), arg("shape"), arg("fill")=0.,
569                    arg("byteOrder"), arg("dataType"), arg("first"),
570                    arg("numValues"), arg("multiplier"), arg("reverse")),
571                "Reads a binary Grid");
572    #endif
573      def("_readNcGrid", &ripley::readNcGrid, (arg("filename"), arg("varname"),      def("_readNcGrid", &ripley::readNcGrid, (arg("filename"), arg("varname"),
574                  arg("functionspace"), arg("shape"), arg("fill"), arg("first"),                  arg("functionspace"), arg("shape"), arg("fill"), arg("first"),
575                  arg("numValues"), arg("multiplier"), arg("reverse")),                  arg("numValues"), arg("multiplier"), arg("reverse")),
576  "Reads a grid from a netCDF file");              "Reads a grid from a netCDF file");
577    
578      class_<ripley::RipleyDomain, bases<escript::AbstractContinuousDomain>, boost::noncopyable >      class_<ripley::RipleyDomain, bases<escript::AbstractContinuousDomain>, boost::noncopyable >
579          ("RipleyDomain", "", no_init)          ("RipleyDomain", "", no_init)
# Line 332  BOOST_PYTHON_MODULE(ripleycpp) Line 585  BOOST_PYTHON_MODULE(ripleycpp)
585          .def("dump", &ripley::RipleyDomain::dump, args("filename"),          .def("dump", &ripley::RipleyDomain::dump, args("filename"),
586                  "Dumps the mesh to a file with the given name.")                  "Dumps the mesh to a file with the given name.")
587          .def("getGridParameters", &ripley::RipleyDomain::getGridParameters,          .def("getGridParameters", &ripley::RipleyDomain::getGridParameters,
588  "Returns the tuple (origin, spacing, elements) where the entries are tuples:\n"              "Returns the tuple (origin, spacing, elements) where the entries are tuples containing\n"
589  "``origin``=the coordinates of the domain's global origin,\n"              "    ``origin``  the coordinates of the domain's global origin,\n"
590  "``spacing``=the element size (=node spacing) of the domain,\n"              "    ``spacing``  the element size (node spacing) of the domain,\n"
591  "``elements``=the global number of elements in all dimensions\n\n"              "    ``elements``  the global number of elements in all dimensions\n\n"
592  ":rtype: ``tuple``")              ":rtype: ``tuple``")
593          .def("getDescription", &ripley::RipleyDomain::getDescription,          .def("getDescription", &ripley::RipleyDomain::getDescription,
594  ":return: a description for this domain\n:rtype: ``string``")              ":return: a description for this domain\n:rtype: ``string``")
595          .def("getDim", &ripley::RipleyDomain::getDim, ":rtype: ``int``")          .def("getDim", &ripley::RipleyDomain::getDim, ":rtype: ``int``")
596          .def("getDataShape", &ripley::RipleyDomain::getDataShape, args("functionSpaceCode"),          .def("getDataShape", &ripley::RipleyDomain::getDataShape, args("functionSpaceCode"),
597  ":return: a pair (dps, ns) where dps=the number of data points per sample, and ns=the number of samples\n:rtype: ``tuple``")              ":return: a pair (dps, ns) where dps is the number of data points per sample, and ns is the number of samples\n"
598                ":rtype: ``tuple``")
599          .def("getNumDataPointsGlobal", &ripley::RipleyDomain::getNumDataPointsGlobal,          .def("getNumDataPointsGlobal", &ripley::RipleyDomain::getNumDataPointsGlobal,
600  ":return: the number of data points summed across all MPI processes\n"              ":return: the number of data points summed across all MPI processes\n"
601  ":rtype: ``int``")              ":rtype: ``int``")
602          .def("addToSystem",&ripley::RipleyDomain::addToSystemFromPython,          .def("addToSystem",&ripley::RipleyDomain::addToSystemFromPython,
603              args("mat", "rhs", "data"),              args("mat", "rhs", "data"),
604              "adds a PDE to the system, results depend on domain\n\n"              "adds a PDE to the system, results depend on domain\n\n"
605              ":param mat:\n:type mat: `OperatorAdapter`\n"              ":param mat:\n:type mat: `OperatorAdapter`\n"
606              ":param rhs:\n:type rhs: `Data`\n"              ":param rhs:\n:type rhs: `Data`\n"
607              ":param data:\ntype data: `list`")              ":param data:\n:type data: `list`\n")
         .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`"  
 )  
608          .def("addToRHS",&ripley::RipleyDomain::addToRHSFromPython,          .def("addToRHS",&ripley::RipleyDomain::addToRHSFromPython,
609              args("rhs", "data"),              args("rhs", "data"),
610              "adds a PDE onto the stiffness matrix mat and a rhs, "              "adds a PDE onto the stiffness matrix mat and a rhs, "
611              "results depends on domain\n\n"              "results depends on domain\n\n"
612              ":param rhs:\n:type rhs: `Data`\n"              ":param rhs:\n:type rhs: `Data`\n"
613              ":param data:\ntype data: `list`")              ":param data:\n:type data: `list`\n")
614          .def("setAssembler", &ripley::RipleyDomain::setAssemblerFromPython,          .def("createAssembler", &ripley::RipleyDomain::createAssemblerFromPython,
615              args("typename", "options"),              args("typename", "options"),
616              "sets the domain to use the named assembler, if supported, using"              "request from the domain an assembler of the specified type, if "
617              "the options if provided"              "supported, using the supplied options (if provided)"
618              ":param typename:\n:type typename: `string`\n"              ":param typename:\n:type typename: `string`\n"
619              ":param options:\n:type options: `list`\n")              ":param options:\n:type options: `list`\n")
620          .def("addPDEToTransportProblem",&ripley::RipleyDomain::addPDEToTransportProblem,          .def("addPDEToTransportProblem",&ripley::RipleyDomain::addPDEToTransportProblemFromPython,
621  args( "tp", "source", "M", "A", "B", "C", "D", "X", "Y", "d", "y", "d_contact", "y_contact"),              args("tp", "source", "data"),
622  ":param tp:\n:type tp: `TransportProblemAdapter`\n"              ":param tp:\n:type tp: `TransportProblemAdapter`\n"
623  ":param source:\n:type source: `Data`\n"              ":param source:\n:type source: `Data`\n"
624  ":param M:\n:type M: `Data`\n"              ":param data:\n:type data: `list`\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 y:\n:type y: `Data`\n"  
 ":param d_contact:\n:type d_contact: `Data`\n"  
 ":param y_contact:\n:type y_contact: `Data`"  
 )  
625          .def("newOperator",&ripley::RipleyDomain::newSystemMatrix,          .def("newOperator",&ripley::RipleyDomain::newSystemMatrix,
626  args("row_blocksize", "row_functionspace", "column_blocksize", "column_functionspace", "type"),              args("row_blocksize", "row_functionspace", "column_blocksize", "column_functionspace", "type"),
627  "creates a SystemMatrixAdapter stiffness matrix and initializes it with zeros\n\n"              "creates a SystemMatrixAdapter stiffness matrix and initializes it with zeros\n\n"
628  ":param row_blocksize:\n:type row_blocksize: ``int``\n"              ":param row_blocksize:\n:type row_blocksize: ``int``\n"
629  ":param row_functionspace:\n:type row_functionspace: `FunctionSpace`\n"              ":param row_functionspace:\n:type row_functionspace: `FunctionSpace`\n"
630  ":param column_blocksize:\n:type column_blocksize: ``int``\n"              ":param column_blocksize:\n:type column_blocksize: ``int``\n"
631  ":param column_functionspace:\n:type column_functionspace: `FunctionSpace`\n"              ":param column_functionspace:\n:type column_functionspace: `FunctionSpace`\n"
632  ":param type:\n:type type: ``int``"              ":param type:\n:type type: ``int``"
633  )              )
634          .def("newTransportProblem",&ripley::RipleyDomain::newTransportProblem,          .def("newTransportProblem",&ripley::RipleyDomain::newTransportProblem,
635  args("theta", "blocksize", "functionspace", "type"),              args("theta", "blocksize", "functionspace", "type"),
636  "creates a TransportProblemAdapter\n\n"              "creates a TransportProblemAdapter\n\n"
637  ":param theta:\n:type theta: ``float``\n"              ":param theta:\n:type theta: ``float``\n"
638  ":param blocksize:\n:type blocksize: ``int``\n"              ":param blocksize:\n:type blocksize: ``int``\n"
639  ":param functionspace:\n:type functionspace: `FunctionSpace`\n"              ":param functionspace:\n:type functionspace: `FunctionSpace`\n"
640  ":param type:\n:type type: ``int``"              ":param type:\n:type type: ``int``"
641  )              )
642          .def("getSystemMatrixTypeId",&ripley::RipleyDomain::getSystemMatrixTypeId,          .def("getSystemMatrixTypeId",&ripley::RipleyDomain::getSystemMatrixTypeId,
643  args("solver", "preconditioner", "package", "symmetry"),              args("options"),
644  ":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"
645  ":rtype: ``int``\n"              ":rtype: ``int``\n"
646  ":param solver:\n:type solver: ``int``\n"              ":param options:\n:type options: `SolverBuddy`\n"
647  ":param preconditioner:\n:type preconditioner: ``int``\n"              )
 ":param package:\n:type package: ``int``\n"  
 ":param symmetry:\n:type symmetry: ``int``"  
 )  
648          .def("getTransportTypeId",&ripley::RipleyDomain::getTransportTypeId,          .def("getTransportTypeId",&ripley::RipleyDomain::getTransportTypeId,
649  args("solver", "preconditioner", "package", "symmetry"),              args("solver", "preconditioner", "package", "symmetry"),
650  ":return: the identifier of the transport problem type to be used when a particular solver, preconditioner, package and symmetric matrix is used.\n"              ":return: the identifier of the transport problem type to be used when a particular solver, preconditioner, package and symmetric matrix is used.\n"
651  ":rtype: ``int``\n"              ":rtype: ``int``\n"
652  ":param solver:\n:type solver: ``int``\n"              ":param solver:\n:type solver: ``int``\n"
653  ":param preconditioner:\n:type preconditioner: ``int``\n"              ":param preconditioner:\n:type preconditioner: ``int``\n"
654  ":param package:\n:type package: ``int``\n"              ":param package:\n:type package: ``int``\n"
655  ":param symmetry:\n:type symmetry: ``int``"              ":param symmetry:\n:type symmetry: ``int``"
656  )              )
657          .def("getX",&ripley::RipleyDomain::getX, ":return: locations in the FEM nodes\n\n"          .def("getX",&ripley::RipleyDomain::getX, ":return: locations in the FEM nodes\n\n"
658  ":rtype: `Data`")              ":rtype: `Data`")
659          .def("getNormal",&ripley::RipleyDomain::getNormal,          .def("getNormal",&ripley::RipleyDomain::getNormal,
660  ":return: boundary normals at the quadrature point on the face elements\n"              ":return: boundary normals at the quadrature point on the face elements\n"
661  ":rtype: `Data`")              ":rtype: `Data`")
662          .def("getSize",&ripley::RipleyDomain::getSize,":return: the element size\n"          .def("getSize",&ripley::RipleyDomain::getSize,":return: the element size\n"
663  ":rtype: `Data`")              ":rtype: `Data`")
664          .def("setTagMap",&ripley::RipleyDomain::setTagMap,args("name","tag"),          .def("setTagMap",&ripley::RipleyDomain::setTagMap,args("name","tag"),
665  "Give a tag number a name.\n\n:param name: Name for the tag\n:type name: ``string``\n"              "Give a tag number a name.\n\n:param name: Name for the tag\n:type name: ``string``\n"
666  ":param tag: numeric id\n:type tag: ``int``\n:note: Tag names must be unique within a domain")              ":param tag: numeric id\n:type tag: ``int``\n:note: Tag names must be unique within a domain")
667          .def("getTag",&ripley::RipleyDomain::getTag,args("name"),":return: tag id for "          .def("getTag",&ripley::RipleyDomain::getTag,args("name"),":return: tag id for "
668  "``name``\n:rtype: ``string``")              "``name``\n:rtype: ``string``")
669          .def("isValidTagName",&ripley::RipleyDomain::isValidTagName,args("name"),          .def("isValidTagName",&ripley::RipleyDomain::isValidTagName,args("name"),
670  ":return: True if ``name`` corresponds to a tag, otherwise False\n:rtype: ``bool``")              ":return: True if ``name`` corresponds to a tag, otherwise False\n:rtype: ``bool``")
671          .def("showTagNames",&ripley::RipleyDomain::showTagNames,":return: A space separated list of tag names\n:rtype: ``string``")          .def("showTagNames",&ripley::RipleyDomain::showTagNames,":return: A space separated list of tag names\n:rtype: ``string``")
672          .def("getMPISize",&ripley::RipleyDomain::getMPISize,":return: the number of processes used for this `Domain`\n:rtype: ``int``")          .def("getMPISize",&ripley::RipleyDomain::getMPISize,":return: the number of processes used for this `Domain`\n:rtype: ``int``")
673          .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``")
674          .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")
675          .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`");
676        /* These two class exports are necessary to ensure that the extra methods added by ripley make it to python.
677         * This change became necessary when the Brick and Rectangle constructors turned into factories instead of classes */
678      class_<ripley::Brick, bases<ripley::RipleyDomain> >("RipleyBrick", "", no_init);      class_<ripley::Brick, bases<ripley::RipleyDomain> >("RipleyBrick", "", no_init);
679      class_<ripley::Rectangle, bases<ripley::RipleyDomain> >("RipleyRectangle", "", no_init)      class_<ripley::Rectangle, bases<ripley::RipleyDomain> >("RipleyRectangle", "", no_init);
680      .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"      class_<ripley::MultiRectangle, bases<ripley::RipleyDomain> >("RipleyMultiRectangle", "", no_init);
681  ":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"      class_<ripley::MultiBrick, bases<ripley::RipleyDomain> >("RipleyMultiBrick", "", no_init);
682  "guassian blur and s is the sigma parameter."      class_<ripley::AbstractAssembler, ripley::Assembler_ptr, boost::noncopyable >
683      );          ("AbstractAssembler", "", no_init);
684  }  }
685    

Legend:
Removed from v.4622  
changed lines
  Added in v.5593

  ViewVC Help
Powered by ViewVC 1.1.26