/[escript]/trunk/ripley/src/ripleycpp.cpp
ViewVC logotype

Annotation of /trunk/ripley/src/ripleycpp.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5575 - (hide annotations)
Wed Apr 1 03:17:22 2015 UTC (4 years ago) by sshaw
File size: 32529 byte(s)
sphinx now builds python doco including module-level docstrings and class __init__ docstrings, also cleared up some doco errors and added multires documentation
1 caltinay 3670
2 jfenwick 3981 /*****************************************************************************
3 caltinay 3670 *
4 jfenwick 5448 * Copyright (c) 2003-2015 by University of Queensland
5 jfenwick 3981 * http://www.uq.edu.au
6 caltinay 3670 *
7     * Primary Business: Queensland, Australia
8     * Licensed under the Open Software License version 3.0
9     * http://www.opensource.org/licenses/osl-3.0.php
10     *
11 jfenwick 3981 * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 jfenwick 4657 * Development 2012-2013 by School of Earth Sciences
13     * Development from 2014 by Centre for Geoscience Computing (GeoComp)
14 jfenwick 3981 *
15     *****************************************************************************/
16 caltinay 3670
17 jfenwick 5464 #define ESNEEDPYTHON
18     #include "esysUtils/first.h"
19    
20 sshaw 4943 #include <ripley/AbstractAssembler.h>
21 caltinay 3691 #include <ripley/Brick.h>
22 sshaw 5528 #include <ripley/MultiBrick.h>
23 caltinay 3691 #include <ripley/Rectangle.h>
24 sshaw 5528 #include <ripley/MultiRectangle.h>
25 caltinay 3670 #include <esysUtils/esysExceptionTranslator.h>
26    
27 sshaw 4906 #include <boost/python.hpp>
28 caltinay 3670 #include <boost/python/module.hpp>
29     #include <boost/python/def.hpp>
30     #include <boost/python/detail/defaults_gen.hpp>
31     #include <boost/version.hpp>
32    
33 jfenwick 4934 #include "escript/SubWorld.h"
34    
35 caltinay 3670 using namespace boost::python;
36    
37 caltinay 3691 namespace ripley {
38 caltinay 3670
39 caltinay 4616 template<typename T>
40     std::vector<T> extractPyArray(const object& obj, const std::string& name,
41     int expectedLength=0)
42     {
43     std::vector<T> result;
44     if (extract<tuple>(obj).check() || extract<list>(obj).check()) {
45     if (expectedLength==0 || len(obj)==expectedLength) {
46     for (int i=0; i<len(obj); i++) {
47     result.push_back(extract<T>(obj[i]));
48     }
49     } else {
50     std::stringstream ssError;
51     ssError << "argument '" << name << "' has wrong length";
52     std::string error(ssError.str());
53     throw RipleyException(error.c_str());
54     }
55     } else {
56     std::stringstream ssError;
57     ssError << "argument '" << name << "' must be a tuple or list";
58     std::string error(ssError.str());
59     throw RipleyException(error.c_str());
60     }
61    
62     return result;
63     }
64    
65 caltinay 3971 escript::Data readBinaryGrid(std::string filename, escript::FunctionSpace fs,
66 caltinay 4616 const object& pyShape, double fill, int byteOrder, int dataType,
67 caltinay 4277 const object& pyFirst, const object& pyNum, const object& pyMultiplier,
68 caltinay 4616 const object& pyReverse)
69 caltinay 3971 {
70     int dim=fs.getDim();
71 caltinay 4618 ReaderParameters params;
72 caltinay 3971
73 caltinay 5187 params.first = extractPyArray<dim_t>(pyFirst, "first", dim);
74     params.numValues = extractPyArray<dim_t>(pyNum, "numValues", dim);
75 caltinay 4616 params.multiplier = extractPyArray<int>(pyMultiplier, "multiplier", dim);
76     params.reverse = extractPyArray<int>(pyReverse, "reverse", dim);
77     params.byteOrder = byteOrder;
78     params.dataType = dataType;
79     std::vector<int> shape(extractPyArray<int>(pyShape, "shape"));
80 caltinay 3971
81     const RipleyDomain* dom=dynamic_cast<const RipleyDomain*>(fs.getDomain().get());
82     if (!dom)
83     throw RipleyException("Function space must be on a ripley domain");
84    
85     escript::Data res(fill, shape, fs, true);
86 caltinay 4615 dom->readBinaryGrid(res, filename, params);
87 caltinay 3971 return res;
88     }
89    
90 sshaw 4738 #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 caltinay 5187 params.first = extractPyArray<dim_t>(pyFirst, "first", dim);
100     params.numValues = extractPyArray<dim_t>(pyNum, "numValues", dim);
101 sshaw 4738 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 caltinay 4013 escript::Data readNcGrid(std::string filename, std::string varname,
118 caltinay 4616 escript::FunctionSpace fs, const object& pyShape, double fill,
119     const object& pyFirst, const object& pyNum, const object& pyMultiplier,
120     const object& pyReverse)
121 caltinay 4013 {
122     int dim=fs.getDim();
123 caltinay 4618 ReaderParameters params;
124 caltinay 4013
125 caltinay 5187 params.first = extractPyArray<dim_t>(pyFirst, "first", dim);
126     params.numValues = extractPyArray<dim_t>(pyNum, "numValues", dim);
127 caltinay 4616 params.multiplier = extractPyArray<int>(pyMultiplier, "multiplier", dim);
128     params.reverse = extractPyArray<int>(pyReverse, "reverse", dim);
129     std::vector<int> shape(extractPyArray<int>(pyShape, "shape"));
130 caltinay 4013
131     const RipleyDomain* dom=dynamic_cast<const RipleyDomain*>(fs.getDomain().get());
132     if (!dom)
133     throw RipleyException("Function space must be on a ripley domain");
134    
135     escript::Data res(fill, shape, fs, true);
136 caltinay 4615 dom->readNcGrid(res, filename, varname, params);
137 caltinay 4013 return res;
138     }
139    
140 caltinay 3691 // These wrappers are required to make the shared pointers work through the
141     // Python wrapper
142 caltinay 3670
143 jfenwick 3892 // The double for n? is just to keep python happy when people need to deal with
144 caltinay 3971 // truediv
145 jfenwick 3892 escript::Domain_ptr _brick(double _n0, double _n1, double _n2, const object& l0,
146 sshaw 4622 const object& l1, const object& l2, int d0, int d1, int d2,
147 jfenwick 4934 const object& objpoints, const object& objtags, escript::SubWorld_ptr world)
148 caltinay 3691 {
149 caltinay 5187 dim_t n0=static_cast<dim_t>(_n0), n1=static_cast<dim_t>(_n1), n2=static_cast<dim_t>(_n2);
150 caltinay 3781 double x0=0., x1=1., y0=0., y1=1., z0=0., z1=1.;
151     if (extract<tuple>(l0).check()) {
152     tuple x=extract<tuple>(l0);
153     if (len(x)==2) {
154     x0=extract<double>(x[0]);
155     x1=extract<double>(x[1]);
156     } else
157     throw RipleyException("Argument l0 must be a float or 2-tuple");
158     } else if (extract<double>(l0).check()) {
159     x1=extract<double>(l0);
160     } else
161     throw RipleyException("Argument l0 must be a float or 2-tuple");
162    
163     if (extract<tuple>(l1).check()) {
164     tuple y=extract<tuple>(l1);
165     if (len(y)==2) {
166     y0=extract<double>(y[0]);
167     y1=extract<double>(y[1]);
168     } else
169     throw RipleyException("Argument l1 must be a float or 2-tuple");
170     } else if (extract<double>(l1).check()) {
171     y1=extract<double>(l1);
172     } else
173     throw RipleyException("Argument l1 must be a float or 2-tuple");
174    
175     if (extract<tuple>(l2).check()) {
176     tuple z=extract<tuple>(l2);
177     if (len(z)==2) {
178     z0=extract<double>(z[0]);
179     z1=extract<double>(z[1]);
180     } else
181     throw RipleyException("Argument l2 must be a float or 2-tuple");
182     } else if (extract<double>(l2).check()) {
183     z1=extract<double>(l2);
184     } else
185     throw RipleyException("Argument l2 must be a float or 2-tuple");
186 sshaw 4622 boost::python::list pypoints=extract<boost::python::list>(objpoints);
187     boost::python::list pytags=extract<boost::python::list>(objtags);
188     int numpts=extract<int>(pypoints.attr("__len__")());
189     int numtags=extract<int>(pytags.attr("__len__")());
190     std::vector<double> points;
191     std::vector<int> tags;
192     tags.resize(numtags, -1);
193     for (int i=0;i<numpts;++i) {
194 sshaw 4828 tuple temp = extract<tuple>(pypoints[i]);
195 sshaw 4622 int l=extract<int>(temp.attr("__len__")());
196 sshaw 4828 if (l != 3)
197     throw RipleyException("Number of coordinates for each dirac point must match dimensions.");
198 sshaw 4622 for (int k=0;k<l;++k) {
199     points.push_back(extract<double>(temp[k]));
200     }
201     }
202     std::map<std::string, int> tagstonames;
203     int curmax=40;
204     // but which order to assign tags to names?????
205     for (int i=0;i<numtags;++i) {
206     extract<int> ex_int(pytags[i]);
207     extract<std::string> ex_str(pytags[i]);
208     if (ex_int.check()) {
209     tags[i]=ex_int();
210     if (tags[i]>= curmax) {
211     curmax=tags[i]+1;
212     }
213     } else if (ex_str.check()) {
214     std::string s=ex_str();
215     std::map<std::string, int>::iterator it=tagstonames.find(s);
216     if (it!=tagstonames.end()) {
217     // we have the tag already so look it up
218     tags[i]=it->second;
219     } else {
220     tagstonames[s]=curmax;
221     tags[i]=curmax;
222     curmax++;
223     }
224     } else {
225     throw RipleyException("Error - Unable to extract tag value.");
226     }
227     }
228 sshaw 4872 if (numtags != numpts)
229     throw RipleyException("Number of tags does not match number of points.");
230 sshaw 4622 return escript::Domain_ptr(new Brick(n0,n1,n2, x0,y0,z0, x1,y1,z1, d0,d1,d2,
231 jfenwick 4934 points, tags, tagstonames, world));
232 caltinay 3691 }
233 caltinay 3670
234 sshaw 5528 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    
404 jfenwick 3892 escript::Domain_ptr _rectangle(double _n0, double _n1, const object& l0,
405 sshaw 4622 const object& l1, int d0, int d1,
406 jfenwick 4934 const object& objpoints, const object& objtags,
407     escript::SubWorld_ptr world
408     )
409 caltinay 3691 {
410 caltinay 5187 dim_t n0=static_cast<dim_t>(_n0), n1=static_cast<dim_t>(_n1);
411 caltinay 3781 double x0=0., x1=1., y0=0., y1=1.;
412     if (extract<tuple>(l0).check()) {
413     tuple x=extract<tuple>(l0);
414     if (len(x)==2) {
415     x0=extract<double>(x[0]);
416     x1=extract<double>(x[1]);
417     } else
418     throw RipleyException("Argument l0 must be a float or 2-tuple");
419     } else if (extract<double>(l0).check()) {
420     x1=extract<double>(l0);
421     } else
422     throw RipleyException("Argument l0 must be a float or 2-tuple");
423    
424     if (extract<tuple>(l1).check()) {
425     tuple y=extract<tuple>(l1);
426     if (len(y)==2) {
427     y0=extract<double>(y[0]);
428     y1=extract<double>(y[1]);
429     } else
430     throw RipleyException("Argument l1 must be a float or 2-tuple");
431     } else if (extract<double>(l1).check()) {
432     y1=extract<double>(l1);
433     } else
434     throw RipleyException("Argument l1 must be a float or 2-tuple");
435 sshaw 4622 boost::python::list pypoints=extract<boost::python::list>(objpoints);
436     boost::python::list pytags=extract<boost::python::list>(objtags);
437     int numpts=extract<int>(pypoints.attr("__len__")());
438     int numtags=extract<int>(pytags.attr("__len__")());
439     std::vector<double> points;
440     std::vector<int> tags;
441     tags.resize(numtags, -1);
442     for (int i=0;i<numpts;++i) {
443 sshaw 4828 tuple temp = extract<tuple>(pypoints[i]);
444 sshaw 4622 int l=extract<int>(temp.attr("__len__")());
445 sshaw 4828 if (l != 2)
446     throw RipleyException("Number of coordinates for each dirac point must match dimensions.");
447 sshaw 4622 for (int k=0;k<l;++k) {
448     points.push_back(extract<double>(temp[k]));
449     }
450     }
451     std::map<std::string, int> tagstonames;
452     int curmax=40;
453     // but which order to assign tags to names?????
454     for (int i=0;i<numtags;++i) {
455     extract<int> ex_int(pytags[i]);
456     extract<std::string> ex_str(pytags[i]);
457     if (ex_int.check()) {
458     tags[i]=ex_int();
459 caltinay 5187 if (tags[i] >= curmax) {
460 sshaw 4622 curmax=tags[i]+1;
461     }
462     } else if (ex_str.check()) {
463     std::string s=ex_str();
464     std::map<std::string, int>::iterator it=tagstonames.find(s);
465     if (it!=tagstonames.end()) {
466     // we have the tag already so look it up
467     tags[i]=it->second;
468     } else {
469     tagstonames[s]=curmax;
470     tags[i]=curmax;
471     curmax++;
472     }
473     } else {
474     throw RipleyException("Error - Unable to extract tag value.");
475     }
476     }
477 sshaw 4872 if (numtags != numpts)
478     throw RipleyException("Number of tags does not match number of points.");
479 sshaw 4622 return escript::Domain_ptr(new Rectangle(n0,n1, x0,y0, x1,y1, d0,d1,
480 jfenwick 4934 points, tags, tagstonames, world));
481 caltinay 3691 }
482 caltinay 3670
483 caltinay 4357 } // end of namespace ripley
484 caltinay 3670
485    
486     BOOST_PYTHON_MODULE(ripleycpp)
487     {
488     // This feature was added in boost v1.34
489     #if ((BOOST_VERSION/100)%1000 > 34) || (BOOST_VERSION/100000 >1)
490 caltinay 3691 // params are: bool show_user_defined, bool show_py_signatures, bool show_cpp_signatures
491     docstring_options docopt(true, true, false);
492 caltinay 3670 #endif
493    
494 sshaw 4821 register_exception_translator<ripley::RipleyException>(&(esysUtils::RuntimeErrorTranslator));
495 caltinay 3670
496 caltinay 4174 scope().attr("__doc__") = "To use this module, please import esys.ripley";
497 caltinay 4357 scope().attr("BYTEORDER_NATIVE") = (int)ripley::BYTEORDER_NATIVE;
498     scope().attr("BYTEORDER_LITTLE_ENDIAN") = (int)ripley::BYTEORDER_LITTLE_ENDIAN;
499     scope().attr("BYTEORDER_BIG_ENDIAN") = (int)ripley::BYTEORDER_BIG_ENDIAN;
500     scope().attr("DATATYPE_INT32") = (int)ripley::DATATYPE_INT32;
501     scope().attr("DATATYPE_FLOAT32") = (int)ripley::DATATYPE_FLOAT32;
502     scope().attr("DATATYPE_FLOAT64") = (int)ripley::DATATYPE_FLOAT64;
503 caltinay 4174
504 sshaw 5575 def("Brick", ripley::_brick, (arg("n0"),arg("n1"),arg("n2"),arg("l0")=1.0,
505     arg("l1")=1.0,arg("l2")=1.0,arg("d0")=-1,arg("d1")=-1,arg("d2")=-1,
506     arg("diracPoints")=list(),arg("diracTags")=list(),
507     arg("escriptworld")=escript::SubWorld_ptr()),
508     "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 n0: number of elements in direction 0\n:type n0: ``int``\n"
510     ":param n1: number of elements in direction 1\n:type n1: ``int``\n"
511     ":param n2: number of elements in direction 2\n:type n2: ``int``\n"
512     ":param l0: length of side 0 or coordinate range of side 0\n:type l0: ``float`` or ``tuple``\n"
513     ":param l1: length of side 1 or coordinate range of side 1\n:type l1: ``float`` or ``tuple``\n"
514     ":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     ":param d1: number of subdivisions in direction 1\n:type d1: ``int``\n"
517     ":param d2: number of subdivisions in direction 2\n:type d2: ``int``");
518 caltinay 3670
519 sshaw 5575 def("Rectangle", ripley::_rectangle, (arg("n0"),arg("n1"),arg("l0")=1.0,
520     arg("l1")=1.0,arg("d0")=-1,arg("d1")=-1,arg("diracPoints")=list(),
521     arg("diracTags")=list(), arg("escriptworld")=escript::SubWorld_ptr()),
522     "Creates a rectangular mesh with n0 x n1 elements over the rectangle [0,l0] x [0,l1].\n\n"
523     ":param n0: number of elements in direction 0\n:type n0: ``int``\n"
524     ":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 caltinay 3670
530 sshaw 5575 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 sshaw 5528
544 sshaw 5575 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 sshaw 5528
561 caltinay 5077 def("readBinaryGrid", &ripley::readBinaryGrid, (arg("filename"),
562 caltinay 4616 arg("functionspace"), arg("shape"), arg("fill")=0.,
563     arg("byteOrder"), arg("dataType"), arg("first"),
564     arg("numValues"), arg("multiplier"), arg("reverse")),
565 sshaw 5575 "Reads a binary Grid");
566 sshaw 4738 #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 sshaw 5575 "Reads a binary Grid");
572 sshaw 4738 #endif
573 caltinay 4616 def("_readNcGrid", &ripley::readNcGrid, (arg("filename"), arg("varname"),
574     arg("functionspace"), arg("shape"), arg("fill"), arg("first"),
575     arg("numValues"), arg("multiplier"), arg("reverse")),
576 sshaw 5575 "Reads a grid from a netCDF file");
577 caltinay 4013
578 jfenwick 4242 class_<ripley::RipleyDomain, bases<escript::AbstractContinuousDomain>, boost::noncopyable >
579 caltinay 3691 ("RipleyDomain", "", no_init)
580     .def("print_mesh_info", &ripley::RipleyDomain::Print_Mesh_Info, (arg("full")=false),
581     "Prints out a summary about the mesh.\n"
582     ":param full: whether to output additional data\n:type full: ``bool``")
583 caltinay 4357 .def("writeBinaryGrid", &ripley::RipleyDomain::writeBinaryGrid)
584    
585 caltinay 3691 .def("dump", &ripley::RipleyDomain::dump, args("filename"),
586     "Dumps the mesh to a file with the given name.")
587 caltinay 4340 .def("getGridParameters", &ripley::RipleyDomain::getGridParameters,
588 sshaw 5575 "Returns the tuple (origin, spacing, elements) where the entries are tuples containing\n"
589     " ``origin`` the coordinates of the domain's global origin,\n"
590     " ``spacing`` the element size (node spacing) of the domain,\n"
591     " ``elements`` the global number of elements in all dimensions\n\n"
592     ":rtype: ``tuple``")
593 caltinay 3691 .def("getDescription", &ripley::RipleyDomain::getDescription,
594 sshaw 5575 ":return: a description for this domain\n:rtype: ``string``")
595 caltinay 3691 .def("getDim", &ripley::RipleyDomain::getDim, ":rtype: ``int``")
596     .def("getDataShape", &ripley::RipleyDomain::getDataShape, args("functionSpaceCode"),
597 sshaw 5575 ":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 caltinay 3691 .def("getNumDataPointsGlobal", &ripley::RipleyDomain::getNumDataPointsGlobal,
600 sshaw 5575 ":return: the number of data points summed across all MPI processes\n"
601     ":rtype: ``int``")
602 sshaw 4622 .def("addToSystem",&ripley::RipleyDomain::addToSystemFromPython,
603     args("mat", "rhs", "data"),
604     "adds a PDE to the system, results depend on domain\n\n"
605     ":param mat:\n:type mat: `OperatorAdapter`\n"
606     ":param rhs:\n:type rhs: `Data`\n"
607 sshaw 5575 ":param data:\n:type data: `list`\n")
608 sshaw 4622 .def("addToRHS",&ripley::RipleyDomain::addToRHSFromPython,
609     args("rhs", "data"),
610     "adds a PDE onto the stiffness matrix mat and a rhs, "
611     "results depends on domain\n\n"
612     ":param rhs:\n:type rhs: `Data`\n"
613 sshaw 5575 ":param data:\n:type data: `list`\n")
614 sshaw 4942 .def("createAssembler", &ripley::RipleyDomain::createAssemblerFromPython,
615 sshaw 4622 args("typename", "options"),
616 sshaw 4942 "request from the domain an assembler of the specified type, if "
617     "supported, using the supplied options (if provided)"
618 sshaw 4622 ":param typename:\n:type typename: `string`\n"
619     ":param options:\n:type options: `list`\n")
620 sshaw 4942 .def("addPDEToTransportProblem",&ripley::RipleyDomain::addPDEToTransportProblemFromPython,
621     args("tp", "source", "data"),
622     ":param tp:\n:type tp: `TransportProblemAdapter`\n"
623     ":param source:\n:type source: `Data`\n"
624 sshaw 5575 ":param data:\n:type data: `list`\n")
625 caltinay 3691 .def("newOperator",&ripley::RipleyDomain::newSystemMatrix,
626 sshaw 5575 args("row_blocksize", "row_functionspace", "column_blocksize", "column_functionspace", "type"),
627     "creates a SystemMatrixAdapter stiffness matrix and initializes it with zeros\n\n"
628     ":param row_blocksize:\n:type row_blocksize: ``int``\n"
629     ":param row_functionspace:\n:type row_functionspace: `FunctionSpace`\n"
630     ":param column_blocksize:\n:type column_blocksize: ``int``\n"
631     ":param column_functionspace:\n:type column_functionspace: `FunctionSpace`\n"
632     ":param type:\n:type type: ``int``"
633     )
634 caltinay 3691 .def("newTransportProblem",&ripley::RipleyDomain::newTransportProblem,
635 sshaw 5575 args("theta", "blocksize", "functionspace", "type"),
636     "creates a TransportProblemAdapter\n\n"
637     ":param theta:\n:type theta: ``float``\n"
638     ":param blocksize:\n:type blocksize: ``int``\n"
639     ":param functionspace:\n:type functionspace: `FunctionSpace`\n"
640     ":param type:\n:type type: ``int``"
641     )
642 caltinay 3691 .def("getSystemMatrixTypeId",&ripley::RipleyDomain::getSystemMatrixTypeId,
643 sshaw 5575 args("options"),
644     ":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"
646     ":param options:\n:type options: `SolverBuddy`\n"
647     )
648 caltinay 3691 .def("getTransportTypeId",&ripley::RipleyDomain::getTransportTypeId,
649 sshaw 5575 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"
651     ":rtype: ``int``\n"
652     ":param solver:\n:type solver: ``int``\n"
653     ":param preconditioner:\n:type preconditioner: ``int``\n"
654     ":param package:\n:type package: ``int``\n"
655     ":param symmetry:\n:type symmetry: ``int``"
656     )
657 caltinay 3691 .def("getX",&ripley::RipleyDomain::getX, ":return: locations in the FEM nodes\n\n"
658 sshaw 5575 ":rtype: `Data`")
659 caltinay 3691 .def("getNormal",&ripley::RipleyDomain::getNormal,
660 sshaw 5575 ":return: boundary normals at the quadrature point on the face elements\n"
661     ":rtype: `Data`")
662 caltinay 3691 .def("getSize",&ripley::RipleyDomain::getSize,":return: the element size\n"
663 sshaw 5575 ":rtype: `Data`")
664 caltinay 3691 .def("setTagMap",&ripley::RipleyDomain::setTagMap,args("name","tag"),
665 sshaw 5575 "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")
667 caltinay 3691 .def("getTag",&ripley::RipleyDomain::getTag,args("name"),":return: tag id for "
668 sshaw 5575 "``name``\n:rtype: ``string``")
669 caltinay 3691 .def("isValidTagName",&ripley::RipleyDomain::isValidTagName,args("name"),
670 sshaw 5575 ":return: True if ``name`` corresponds to a tag, otherwise False\n:rtype: ``bool``")
671 caltinay 3691 .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``")
673     .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")
675     .def("onMasterProcessor",&ripley::RipleyDomain::onMasterProcessor,":return: True if this code is executing on the master process\n:rtype: `bool`");
676 jfenwick 4825 /* 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 jfenwick 4687 class_<ripley::Brick, bases<ripley::RipleyDomain> >("RipleyBrick", "", no_init);
679     class_<ripley::Rectangle, bases<ripley::RipleyDomain> >("RipleyRectangle", "", no_init);
680 sshaw 5528 class_<ripley::MultiRectangle, bases<ripley::RipleyDomain> >("RipleyMultiRectangle", "", no_init);
681     class_<ripley::MultiBrick, bases<ripley::RipleyDomain> >("RipleyMultiBrick", "", no_init);
682 sshaw 4943 class_<ripley::AbstractAssembler, ripley::Assembler_ptr, boost::noncopyable >
683     ("AbstractAssembler", "", no_init);
684 caltinay 3670 }
685    

  ViewVC Help
Powered by ViewVC 1.1.26