/[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 4277 by caltinay, Wed Mar 6 01:30:41 2013 UTC revision 5464 by jfenwick, Sat Feb 14 00:25:03 2015 UTC
# Line 1  Line 1 
1    
2  /*****************************************************************************  /*****************************************************************************
3  *  *
4  * Copyright (c) 2003-2013 by University of Queensland  * Copyright (c) 2003-2015 by 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/Rectangle.h>  #include <ripley/Rectangle.h>
23  #include <esysUtils/esysExceptionTranslator.h>  #include <esysUtils/esysExceptionTranslator.h>
24    
25  #include <boost/python.hpp>  #include <boost/python.hpp>
26  #include <boost/python/module.hpp>  #include <boost/python/module.hpp>
27  #include <boost/python/def.hpp>  #include <boost/python/def.hpp>
28  #include <boost/python/detail/defaults_gen.hpp>  #include <boost/python/detail/defaults_gen.hpp>
29  #include <boost/version.hpp>  #include <boost/version.hpp>
30    
31    #include "escript/SubWorld.h"
32    
33  using namespace boost::python;  using namespace boost::python;
34    
35  namespace ripley {  namespace ripley {
36    
37    template<typename T>
38    std::vector<T> extractPyArray(const object& obj, const std::string& name,
39                                  int expectedLength=0)
40    {
41        std::vector<T> result;
42        if (extract<tuple>(obj).check() || extract<list>(obj).check()) {
43            if (expectedLength==0 || len(obj)==expectedLength) {
44                for (int i=0; i<len(obj); i++) {
45                    result.push_back(extract<T>(obj[i]));
46                }
47            } else {
48                std::stringstream ssError;
49                ssError << "argument '" << name << "' has wrong length";
50                std::string error(ssError.str());
51                throw RipleyException(error.c_str());
52            }
53        } else {
54            std::stringstream ssError;
55            ssError << "argument '" << name << "' must be a tuple or list";
56            std::string error(ssError.str());
57            throw RipleyException(error.c_str());
58        }
59    
60        return result;
61    }
62    
63  escript::Data readBinaryGrid(std::string filename, escript::FunctionSpace fs,  escript::Data readBinaryGrid(std::string filename, escript::FunctionSpace fs,
64            const object& pyShape, double fill, int byteOrder, int dataType,
65          const object& pyFirst, const object& pyNum, const object& pyMultiplier,          const object& pyFirst, const object& pyNum, const object& pyMultiplier,
66          const object& pyShape, double fill=0.)          const object& pyReverse)
67  {  {
68      int dim=fs.getDim();      int dim=fs.getDim();
69      std::vector<int> first(dim), numValues(dim), multiplier(dim), shape;      ReaderParameters params;
70    
71      if (extract<tuple>(pyFirst).check() || extract<list>(pyFirst).check()) {      params.first = extractPyArray<dim_t>(pyFirst, "first", dim);
72          if (len(pyFirst)==dim) {      params.numValues = extractPyArray<dim_t>(pyNum, "numValues", dim);
73              for (int i=0; i<dim; i++) {      params.multiplier = extractPyArray<int>(pyMultiplier, "multiplier", dim);
74                  first[i]=extract<int>(pyFirst[i]);      params.reverse = extractPyArray<int>(pyReverse, "reverse", dim);
75              }      params.byteOrder = byteOrder;
76          } else      params.dataType = dataType;
77              throw RipleyException("Argument 'first' has wrong length");      std::vector<int> shape(extractPyArray<int>(pyShape, "shape"));
     } else  
         throw RipleyException("Argument 'first' must be a tuple or list");  
78    
79      if (extract<tuple>(pyNum).check() || extract<list>(pyNum).check()) {      const RipleyDomain* dom=dynamic_cast<const RipleyDomain*>(fs.getDomain().get());
80          if (len(pyNum)==dim) {      if (!dom)
81              for (int i=0; i<dim; i++) {          throw RipleyException("Function space must be on a ripley domain");
                 numValues[i]=extract<int>(pyNum[i]);  
             }  
         } else  
             throw RipleyException("Argument 'numValues' has wrong length");  
     } else  
         throw RipleyException("Argument 'numValues' must be a tuple or list");  
82    
83      if (extract<tuple>(pyShape).check() || extract<list>(pyShape).check()) {      escript::Data res(fill, shape, fs, true);
84          for (int i=0; i<len(pyShape); i++) {      dom->readBinaryGrid(res, filename, params);
85              shape.push_back(extract<int>(pyShape[i]));      return res;
86          }  }
     } else  
         throw RipleyException("Argument 'shape' must be a tuple or list");  
87    
88      if (extract<tuple>(pyMultiplier).check() || extract<list>(pyMultiplier).check()) {  #ifdef USE_BOOSTIO
89          if (len(pyMultiplier)==dim) {  escript::Data readBinaryGridFromZipped(std::string filename, escript::FunctionSpace fs,
90              for (int i=0; i<dim; i++) {          const object& pyShape, double fill, int byteOrder, int dataType,
91                  multiplier[i]=extract<int>(pyMultiplier[i]);          const object& pyFirst, const object& pyNum, const object& pyMultiplier,
92              }          const object& pyReverse)
93          } else  {
94              throw RipleyException("Argument 'multiplier' has wrong length");      int dim=fs.getDim();
95      } else      ReaderParameters params;
96          throw RipleyException("Argument 'multiplier' must be a tuple or list");  
97        params.first = extractPyArray<dim_t>(pyFirst, "first", dim);
98        params.numValues = extractPyArray<dim_t>(pyNum, "numValues", dim);
99        params.multiplier = extractPyArray<int>(pyMultiplier, "multiplier", dim);
100        params.reverse = extractPyArray<int>(pyReverse, "reverse", dim);
101        params.byteOrder = byteOrder;
102        params.dataType = dataType;
103        std::vector<int> shape(extractPyArray<int>(pyShape, "shape"));
104    
105      const RipleyDomain* dom=dynamic_cast<const RipleyDomain*>(fs.getDomain().get());      const RipleyDomain* dom=dynamic_cast<const RipleyDomain*>(fs.getDomain().get());
106      if (!dom)      if (!dom)
107          throw RipleyException("Function space must be on a ripley domain");          throw RipleyException("Function space must be on a ripley domain");
108    
   
109      escript::Data res(fill, shape, fs, true);      escript::Data res(fill, shape, fs, true);
110        dom->readBinaryGridFromZipped(res, filename, params);
     dom->readBinaryGrid(res, filename, first, numValues, multiplier);  
111      return res;      return res;
112  }  }
113    #endif
114    
115  escript::Data readNcGrid(std::string filename, std::string varname,  escript::Data readNcGrid(std::string filename, std::string varname,
116          escript::FunctionSpace fs, const object& pyFirst, const object& pyNum,          escript::FunctionSpace fs, const object& pyShape, double fill,
117          const object& pyMultiplier, const object& pyShape, double fill=0.)          const object& pyFirst, const object& pyNum, const object& pyMultiplier,
118            const object& pyReverse)
119  {  {
120      int dim=fs.getDim();      int dim=fs.getDim();
121      std::vector<int> first(dim), numValues(dim), multiplier(dim), shape;      ReaderParameters params;
   
     if (extract<tuple>(pyFirst).check() || extract<list>(pyFirst).check()) {  
         if (len(pyFirst)==dim) {  
             for (int i=0; i<dim; i++) {  
                 first[i]=extract<int>(pyFirst[i]);  
             }  
         } else  
             throw RipleyException("Argument 'first' has wrong length");  
     } else  
         throw RipleyException("Argument 'first' must be a tuple or list");  
   
     if (extract<tuple>(pyNum).check() || extract<list>(pyNum).check()) {  
         if (len(pyNum)==dim) {  
             for (int i=0; i<dim; i++) {  
                 numValues[i]=extract<int>(pyNum[i]);  
             }  
         } else  
             throw RipleyException("Argument 'numValues' has wrong length");  
     } else  
         throw RipleyException("Argument 'numValues' must be a tuple or list");  
   
     if (extract<tuple>(pyMultiplier).check() || extract<list>(pyMultiplier).check()) {  
         if (len(pyMultiplier)==dim) {  
             for (int i=0; i<dim; i++) {  
                 multiplier[i]=extract<int>(pyMultiplier[i]);  
             }  
         } else  
             throw RipleyException("Argument 'multiplier' has wrong length");  
     } else  
         throw RipleyException("Argument 'multiplier' must be a tuple or list");  
122    
123      if (extract<tuple>(pyShape).check() || extract<list>(pyShape).check()) {      params.first = extractPyArray<dim_t>(pyFirst, "first", dim);
124          for (int i=0; i<len(pyShape); i++) {      params.numValues = extractPyArray<dim_t>(pyNum, "numValues", dim);
125              shape.push_back(extract<int>(pyShape[i]));      params.multiplier = extractPyArray<int>(pyMultiplier, "multiplier", dim);
126          }      params.reverse = extractPyArray<int>(pyReverse, "reverse", dim);
127      } else      std::vector<int> shape(extractPyArray<int>(pyShape, "shape"));
         throw RipleyException("Argument 'shape' must be a tuple or list");  
128    
129      const RipleyDomain* dom=dynamic_cast<const RipleyDomain*>(fs.getDomain().get());      const RipleyDomain* dom=dynamic_cast<const RipleyDomain*>(fs.getDomain().get());
130      if (!dom)      if (!dom)
131          throw RipleyException("Function space must be on a ripley domain");          throw RipleyException("Function space must be on a ripley domain");
132    
   
133      escript::Data res(fill, shape, fs, true);      escript::Data res(fill, shape, fs, true);
134        dom->readNcGrid(res, filename, varname, params);
     dom->readNcGrid(res, filename, varname, first, numValues, multiplier);  
135      return res;      return res;
136  }  }
137    
# Line 143  escript::Data readNcGrid(std::string fil Line 141  escript::Data readNcGrid(std::string fil
141  // The double for n? is just to keep python happy when people need to deal with  // The double for n? is just to keep python happy when people need to deal with
142  // truediv  // truediv
143  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,
144                   const object& l1, const object& l2, int d0, int d1, int d2)                   const object& l1, const object& l2, int d0, int d1, int d2,
145                     const object& objpoints, const object& objtags, escript::SubWorld_ptr world)
146  {  {
147      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);
148      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.;
149      if (extract<tuple>(l0).check()) {      if (extract<tuple>(l0).check()) {
150          tuple x=extract<tuple>(l0);          tuple x=extract<tuple>(l0);
# Line 182  escript::Domain_ptr _brick(double _n0, d Line 181  escript::Domain_ptr _brick(double _n0, d
181          z1=extract<double>(l2);          z1=extract<double>(l2);
182      } else      } else
183          throw RipleyException("Argument l2 must be a float or 2-tuple");          throw RipleyException("Argument l2 must be a float or 2-tuple");
184        boost::python::list pypoints=extract<boost::python::list>(objpoints);
185      return escript::Domain_ptr(new Brick(n0,n1,n2, x0,y0,z0, x1,y1,z1, d0,d1,d2));      boost::python::list pytags=extract<boost::python::list>(objtags);
186        int numpts=extract<int>(pypoints.attr("__len__")());
187        int numtags=extract<int>(pytags.attr("__len__")());
188        std::vector<double> points;
189        std::vector<int> tags;
190        tags.resize(numtags, -1);
191        for (int i=0;i<numpts;++i) {
192            tuple temp = extract<tuple>(pypoints[i]);
193            int l=extract<int>(temp.attr("__len__")());
194            if (l != 3)
195                throw RipleyException("Number of coordinates for each dirac point must match dimensions.");
196            for (int k=0;k<l;++k) {
197                points.push_back(extract<double>(temp[k]));
198            }
199        }
200        std::map<std::string, int> tagstonames;
201        int curmax=40;
202        // but which order to assign tags to names?????
203        for (int i=0;i<numtags;++i) {
204            extract<int> ex_int(pytags[i]);
205            extract<std::string> ex_str(pytags[i]);
206            if (ex_int.check()) {
207                tags[i]=ex_int();
208                if (tags[i]>= curmax) {
209                    curmax=tags[i]+1;
210                }
211            } else if (ex_str.check()) {
212                std::string s=ex_str();
213                std::map<std::string, int>::iterator it=tagstonames.find(s);
214                if (it!=tagstonames.end()) {
215                    // we have the tag already so look it up
216                    tags[i]=it->second;
217                } else {
218                    tagstonames[s]=curmax;
219                    tags[i]=curmax;
220                    curmax++;
221                }
222            } else {
223                throw RipleyException("Error - Unable to extract tag value.");
224            }
225        }
226        if (numtags != numpts)
227            throw RipleyException("Number of tags does not match number of points.");
228        return escript::Domain_ptr(new Brick(n0,n1,n2, x0,y0,z0, x1,y1,z1, d0,d1,d2,
229                                                points, tags, tagstonames, world));
230  }  }
231    
232  const int _q[]={0x61686969,0x746c4144,0x79616e43};  //const int _q[]={0x61686969,0x746c4144,0x79616e43};
233    const int _q[]={0x62207363, 0x6574735F, 0x2020214e};
234  escript::Domain_ptr _rectangle(double _n0, double _n1, const object& l0,  escript::Domain_ptr _rectangle(double _n0, double _n1, const object& l0,
235                                 const object& l1, int d0, int d1)                                 const object& l1, int d0, int d1,
236                                   const object& objpoints, const object& objtags,
237                      escript::SubWorld_ptr world
238                      )
239  {  {
240      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);
241      double x0=0., x1=1., y0=0., y1=1.;      double x0=0., x1=1., y0=0., y1=1.;
242      if (extract<tuple>(l0).check()) {      if (extract<tuple>(l0).check()) {
243          tuple x=extract<tuple>(l0);          tuple x=extract<tuple>(l0);
# Line 215  escript::Domain_ptr _rectangle(double _n Line 262  escript::Domain_ptr _rectangle(double _n
262          y1=extract<double>(l1);          y1=extract<double>(l1);
263      } else      } else
264          throw RipleyException("Argument l1 must be a float or 2-tuple");          throw RipleyException("Argument l1 must be a float or 2-tuple");
265        boost::python::list pypoints=extract<boost::python::list>(objpoints);
266      return escript::Domain_ptr(new Rectangle(n0,n1, x0,y0, x1,y1, d0,d1));      boost::python::list pytags=extract<boost::python::list>(objtags);
267        int numpts=extract<int>(pypoints.attr("__len__")());
268        int numtags=extract<int>(pytags.attr("__len__")());
269        std::vector<double> points;
270        std::vector<int> tags;
271        tags.resize(numtags, -1);
272        for (int i=0;i<numpts;++i) {
273            tuple temp = extract<tuple>(pypoints[i]);
274            int l=extract<int>(temp.attr("__len__")());
275            if (l != 2)
276                throw RipleyException("Number of coordinates for each dirac point must match dimensions.");
277            for (int k=0;k<l;++k) {
278                points.push_back(extract<double>(temp[k]));
279            }
280        }
281        std::map<std::string, int> tagstonames;
282        int curmax=40;
283        // but which order to assign tags to names?????
284        for (int i=0;i<numtags;++i) {
285            extract<int> ex_int(pytags[i]);
286            extract<std::string> ex_str(pytags[i]);
287            if (ex_int.check()) {
288                tags[i]=ex_int();
289                if (tags[i] >= curmax) {
290                    curmax=tags[i]+1;
291                }
292            } else if (ex_str.check()) {
293                std::string s=ex_str();
294                std::map<std::string, int>::iterator it=tagstonames.find(s);
295                if (it!=tagstonames.end()) {
296                    // we have the tag already so look it up
297                    tags[i]=it->second;
298                } else {
299                    tagstonames[s]=curmax;
300                    tags[i]=curmax;
301                    curmax++;
302                }
303            } else {
304                throw RipleyException("Error - Unable to extract tag value.");
305            }
306        }
307        if (numtags != numpts)
308            throw RipleyException("Number of tags does not match number of points.");
309        return escript::Domain_ptr(new Rectangle(n0,n1, x0,y0, x1,y1, d0,d1,
310                                                 points, tags, tagstonames, world));
311  }  }
312  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];}
313    
314  } // end of namespace  } // end of namespace ripley
315    
316    
317  BOOST_PYTHON_MODULE(ripleycpp)  BOOST_PYTHON_MODULE(ripleycpp)
# Line 231  BOOST_PYTHON_MODULE(ripleycpp) Line 322  BOOST_PYTHON_MODULE(ripleycpp)
322      docstring_options docopt(true, true, false);      docstring_options docopt(true, true, false);
323  #endif  #endif
324    
325      register_exception_translator<ripley::RipleyException>(&(esysUtils::esysExceptionTranslator));      register_exception_translator<ripley::RipleyException>(&(esysUtils::RuntimeErrorTranslator));
326    
327      scope().attr("__doc__") = "To use this module, please import esys.ripley";      scope().attr("__doc__") = "To use this module, please import esys.ripley";
328        scope().attr("BYTEORDER_NATIVE") = (int)ripley::BYTEORDER_NATIVE;
329        scope().attr("BYTEORDER_LITTLE_ENDIAN") = (int)ripley::BYTEORDER_LITTLE_ENDIAN;
330        scope().attr("BYTEORDER_BIG_ENDIAN") = (int)ripley::BYTEORDER_BIG_ENDIAN;
331        scope().attr("DATATYPE_INT32") = (int)ripley::DATATYPE_INT32;
332        scope().attr("DATATYPE_FLOAT32") = (int)ripley::DATATYPE_FLOAT32;
333        scope().attr("DATATYPE_FLOAT64") = (int)ripley::DATATYPE_FLOAT64;
334    
335      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),      def("Brick", ripley::_brick, (arg("n0"),arg("n1"),arg("n2"),arg("l0")=1.0,arg("l1")=1.0,arg("l2")=1.0,
336            arg("d0")=-1,arg("d1")=-1,arg("d2")=-1,arg("diracPoints")=list(),arg("diracTags")=list(), arg("escriptworld")=escript::SubWorld_ptr()),
337  "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"
338  ":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"
339  ":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 247  BOOST_PYTHON_MODULE(ripleycpp) Line 345  BOOST_PYTHON_MODULE(ripleycpp)
345  ":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"
346  ":param d2: number of subdivisions in direction 2\n:type d2: ``int``");  ":param d2: number of subdivisions in direction 2\n:type d2: ``int``");
347    
348      def("Rectangle", ripley::_rectangle, (arg("n0"),arg("n1"),arg("l0")=1.0,arg("l1")=1.0,arg("d0")=-1,arg("d1")=-1),      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()),
349  "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"
350  ":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"
351  ":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 256  BOOST_PYTHON_MODULE(ripleycpp) Line 354  BOOST_PYTHON_MODULE(ripleycpp)
354  ":param d0: number of subdivisions in direction 0\n:type d0: ``int``\n"  ":param d0: number of subdivisions in direction 0\n:type d0: ``int``\n"
355  ":param d1: number of subdivisions in direction 1\n:type d1: ``int``");  ":param d1: number of subdivisions in direction 1\n:type d1: ``int``");
356      def("_theculprit_", ripley::_who);      def("_theculprit_", ripley::_who);
     def("LoadMesh", ripley::RipleyDomain::loadMesh, (arg("filename")),  
            "Loads a ripley domain from a dump file" ":rtype: `Domain`");  
357    
358      def("ReadMesh", ripley::RipleyDomain::readMesh, (arg("filename")),      def("readBinaryGrid", &ripley::readBinaryGrid, (arg("filename"),
359              "Reads a ripley domain from a file created by write().\n\n"                  arg("functionspace"), arg("shape"), arg("fill")=0.,
360              ":rtype: `RipleyDomain`\n:param filename:\n:type filename: ``string``\n");                  arg("byteOrder"), arg("dataType"), arg("first"),
361                    arg("numValues"), arg("multiplier"), arg("reverse")),
362      def("_readBinaryGrid", &ripley::readBinaryGrid, (arg("filename"), arg("functionspace"), arg("first"), arg("numValues"), arg("multiplier"), arg("shape"), arg("fill")=0.));  "Reads a binary Grid");
363    #ifdef USE_BOOSTIO
364      def("_readNcGrid", &ripley::readNcGrid, (arg("filename"), arg("varname"), arg("functionspace"), arg("first"), arg("numValues"), arg("multiplier"), arg("shape"), arg("fill")=0.));      def("_readBinaryGridFromZipped", &ripley::readBinaryGridFromZipped, (arg("filename"),
365                    arg("functionspace"), arg("shape"), arg("fill")=0.,
366                    arg("byteOrder"), arg("dataType"), arg("first"),
367                    arg("numValues"), arg("multiplier"), arg("reverse")),
368    "Reads a binary Grid");
369    #endif
370        def("_readNcGrid", &ripley::readNcGrid, (arg("filename"), arg("varname"),
371                    arg("functionspace"), arg("shape"), arg("fill"), arg("first"),
372                    arg("numValues"), arg("multiplier"), arg("reverse")),
373    "Reads a grid from a netCDF file");
374    
375      class_<ripley::RipleyDomain, bases<escript::AbstractContinuousDomain>, boost::noncopyable >      class_<ripley::RipleyDomain, bases<escript::AbstractContinuousDomain>, boost::noncopyable >
376          ("RipleyDomain", "", no_init)          ("RipleyDomain", "", no_init)
         .def("write", &ripley::RipleyDomain::write, args("filename"),  
                 "Writes the current mesh to a file with the given name. It can subsequently be recovered using ReadMesh().")  
377          .def("print_mesh_info", &ripley::RipleyDomain::Print_Mesh_Info, (arg("full")=false),          .def("print_mesh_info", &ripley::RipleyDomain::Print_Mesh_Info, (arg("full")=false),
378                  "Prints out a summary about the mesh.\n"                  "Prints out a summary about the mesh.\n"
379                  ":param full: whether to output additional data\n:type full: ``bool``")                  ":param full: whether to output additional data\n:type full: ``bool``")
380            .def("writeBinaryGrid", &ripley::RipleyDomain::writeBinaryGrid)
381    
382          .def("dump", &ripley::RipleyDomain::dump, args("filename"),          .def("dump", &ripley::RipleyDomain::dump, args("filename"),
383                  "Dumps the mesh to a file with the given name.")                  "Dumps the mesh to a file with the given name.")
384            .def("getGridParameters", &ripley::RipleyDomain::getGridParameters,
385    "Returns the tuple (origin, spacing, elements) where the entries are tuples:\n"
386    "``origin``=the coordinates of the domain's global origin,\n"
387    "``spacing``=the element size (=node spacing) of the domain,\n"
388    "``elements``=the global number of elements in all dimensions\n\n"
389    ":rtype: ``tuple``")
390          .def("getDescription", &ripley::RipleyDomain::getDescription,          .def("getDescription", &ripley::RipleyDomain::getDescription,
391  ":return: a description for this domain\n:rtype: ``string``")  ":return: a description for this domain\n:rtype: ``string``")
392          .def("getDim", &ripley::RipleyDomain::getDim, ":rtype: ``int``")          .def("getDim", &ripley::RipleyDomain::getDim, ":rtype: ``int``")
# Line 284  BOOST_PYTHON_MODULE(ripleycpp) Line 395  BOOST_PYTHON_MODULE(ripleycpp)
395          .def("getNumDataPointsGlobal", &ripley::RipleyDomain::getNumDataPointsGlobal,          .def("getNumDataPointsGlobal", &ripley::RipleyDomain::getNumDataPointsGlobal,
396  ":return: the number of data points summed across all MPI processes\n"  ":return: the number of data points summed across all MPI processes\n"
397  ":rtype: ``int``")  ":rtype: ``int``")
398          .def("addPDEToSystem",&ripley::RipleyDomain::addPDEToSystem,          .def("addToSystem",&ripley::RipleyDomain::addToSystemFromPython,
399  args("mat", "rhs", "A", "B", "C", "D", "X", "Y", "d", "y", "d_contact", "y_contact"),              args("mat", "rhs", "data"),
400  "adds a PDE onto the stiffness matrix mat and a rhs\n\n"              "adds a PDE to the system, results depend on domain\n\n"
401  ":param mat:\n:type mat: `OperatorAdapter`\n:param rhs:\n:type rhs: `Data`\n"              ":param mat:\n:type mat: `OperatorAdapter`\n"
402  ":param A:\n:type A: `Data`\n"              ":param rhs:\n:type rhs: `Data`\n"
403  ":param B:\n:type B: `Data`\n"              ":param data:\ntype data: `list`")
404  ":param C:\n:type C: `Data`\n"          .def("addToRHS",&ripley::RipleyDomain::addToRHSFromPython,
405  ":param D:\n:type D: `Data`\n"              args("rhs", "data"),
406  ":param X:\n:type X: `Data`\n"              "adds a PDE onto the stiffness matrix mat and a rhs, "
407  ":param Y:\n:type Y: `Data`\n"              "results depends on domain\n\n"
408  ":param d:\n:type d: `Data`\n"              ":param rhs:\n:type rhs: `Data`\n"
409  ":param d_contact:\n:type d_contact: `Data`\n"              ":param data:\ntype data: `list`")
410  ":param y_contact:\n:type y_contact: `Data`"          .def("createAssembler", &ripley::RipleyDomain::createAssemblerFromPython,
411  )              args("typename", "options"),
412          .def("addPDEToRHS",&ripley::RipleyDomain::addPDEToRHS,              "request from the domain an assembler of the specified type, if "
413  args("rhs", "X", "Y", "y", "y_contact"),              "supported, using the supplied options (if provided)"
414  "adds a PDE onto the stiffness matrix mat and a rhs\n\n"              ":param typename:\n:type typename: `string`\n"
415  ":param rhs:\n:type rhs: `Data`\n"              ":param options:\n:type options: `list`\n")
416  ":param X:\n:type X: `Data`\n"          .def("addPDEToTransportProblem",&ripley::RipleyDomain::addPDEToTransportProblemFromPython,
417  ":param Y:\n:type Y: `Data`\n"              args("tp", "source", "data"),
418  ":param y:\n:type y: `Data`\n"              ":param tp:\n:type tp: `TransportProblemAdapter`\n"
419  ":param y_contact:\n:type y_contact: `Data`"              ":param source:\n:type source: `Data`\n"
420  )              ":param data:\ntype data: `list`")
         .def("addPDEToTransportProblem",&ripley::RipleyDomain::addPDEToTransportProblem,  
 args( "tp", "source", "M", "A", "B", "C", "D", "X", "Y", "d", "y", "d_contact", "y_contact"),  
 ":param tp:\n:type tp: `TransportProblemAdapter`\n"  
 ":param source:\n:type source: `Data`\n"  
 ":param M:\n:type M: `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 y:\n:type y: `Data`\n"  
 ":param d_contact:\n:type d_contact: `Data`\n"  
 ":param y_contact:\n:type y_contact: `Data`"  
 )  
421          .def("newOperator",&ripley::RipleyDomain::newSystemMatrix,          .def("newOperator",&ripley::RipleyDomain::newSystemMatrix,
422  args("row_blocksize", "row_functionspace", "column_blocksize", "column_functionspace", "type"),  args("row_blocksize", "row_functionspace", "column_blocksize", "column_functionspace", "type"),
423  "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 341  args("theta", "blocksize", "functionspac Line 436  args("theta", "blocksize", "functionspac
436  ":param type:\n:type type: ``int``"  ":param type:\n:type type: ``int``"
437  )  )
438          .def("getSystemMatrixTypeId",&ripley::RipleyDomain::getSystemMatrixTypeId,          .def("getSystemMatrixTypeId",&ripley::RipleyDomain::getSystemMatrixTypeId,
439  args("solver", "preconditioner", "package", "symmetry"),  args("options"),
440  ":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"
441  ":rtype: ``int``\n"  ":rtype: ``int``\n"
442  ":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``"  
443  )  )
444          .def("getTransportTypeId",&ripley::RipleyDomain::getTransportTypeId,          .def("getTransportTypeId",&ripley::RipleyDomain::getTransportTypeId,
445  args("solver", "preconditioner", "package", "symmetry"),  args("solver", "preconditioner", "package", "symmetry"),
# Line 377  args("solver", "preconditioner", "packag Line 469  args("solver", "preconditioner", "packag
469          .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``")
470          .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")
471          .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`");
472        /* These two class exports are necessary to ensure that the extra methods added by ripley make it to python.
473         * This change became necessary when the Brick and Rectangle constructors turned into factories instead of classes */
474      class_<ripley::Brick, bases<ripley::RipleyDomain> >("RipleyBrick", "", no_init);      class_<ripley::Brick, bases<ripley::RipleyDomain> >("RipleyBrick", "", no_init);
475      class_<ripley::Rectangle, bases<ripley::RipleyDomain> >("RipleyRectangle", "", no_init);      class_<ripley::Rectangle, bases<ripley::RipleyDomain> >("RipleyRectangle", "", no_init);
476        class_<ripley::AbstractAssembler, ripley::Assembler_ptr, boost::noncopyable >
477            ("AbstractAssembler", "", no_init);
478  }  }
479    

Legend:
Removed from v.4277  
changed lines
  Added in v.5464

  ViewVC Help
Powered by ViewVC 1.1.26