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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6651 - (hide annotations)
Wed Feb 7 02:12:08 2018 UTC (19 months, 2 weeks ago) by jfenwick
File size: 33216 byte(s)
Make everyone sad by touching all the files

Copyright dates update

1 caltinay 3670
2 jfenwick 3981 /*****************************************************************************
3 caltinay 3670 *
4 jfenwick 6651 * Copyright (c) 2003-2018 by The University of Queensland
5 jfenwick 3981 * http://www.uq.edu.au
6 caltinay 3670 *
7     * Primary Business: Queensland, Australia
8 jfenwick 6112 * Licensed under the Apache License, version 2.0
9     * http://www.apache.org/licenses/LICENSE-2.0
10 caltinay 3670 *
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 sshaw 4943 #include <ripley/AbstractAssembler.h>
18 caltinay 3691 #include <ripley/Brick.h>
19 sshaw 5528 #include <ripley/MultiBrick.h>
20 caltinay 5954 #include <ripley/MultiRectangle.h>
21 caltinay 3691 #include <ripley/Rectangle.h>
22 caltinay 3670
23 caltinay 5954 #include <escript/ExceptionTranslators.h>
24     #include <escript/SubWorld.h>
25    
26 sshaw 4906 #include <boost/python.hpp>
27 caltinay 3670 #include <boost/python/module.hpp>
28     #include <boost/python/def.hpp>
29     #include <boost/python/detail/defaults_gen.hpp>
30     #include <boost/version.hpp>
31    
32     using namespace boost::python;
33    
34 caltinay 3691 namespace ripley {
35 caltinay 3670
36 caltinay 4616 template<typename T>
37     std::vector<T> extractPyArray(const object& obj, const std::string& name,
38     int expectedLength=0)
39     {
40     std::vector<T> result;
41     if (extract<tuple>(obj).check() || extract<list>(obj).check()) {
42     if (expectedLength==0 || len(obj)==expectedLength) {
43     for (int i=0; i<len(obj); i++) {
44     result.push_back(extract<T>(obj[i]));
45     }
46     } else {
47     std::stringstream ssError;
48     ssError << "argument '" << name << "' has wrong length";
49     std::string error(ssError.str());
50     throw RipleyException(error.c_str());
51     }
52     } else {
53     std::stringstream ssError;
54     ssError << "argument '" << name << "' must be a tuple or list";
55     std::string error(ssError.str());
56     throw RipleyException(error.c_str());
57     }
58    
59     return result;
60     }
61    
62 caltinay 3971 escript::Data readBinaryGrid(std::string filename, escript::FunctionSpace fs,
63 caltinay 4616 const object& pyShape, double fill, int byteOrder, int dataType,
64 caltinay 4277 const object& pyFirst, const object& pyNum, const object& pyMultiplier,
65 caltinay 4616 const object& pyReverse)
66 caltinay 3971 {
67     int dim=fs.getDim();
68 caltinay 4618 ReaderParameters params;
69 caltinay 3971
70 caltinay 5187 params.first = extractPyArray<dim_t>(pyFirst, "first", dim);
71     params.numValues = extractPyArray<dim_t>(pyNum, "numValues", dim);
72 caltinay 4616 params.multiplier = extractPyArray<int>(pyMultiplier, "multiplier", dim);
73     params.reverse = extractPyArray<int>(pyReverse, "reverse", dim);
74     params.byteOrder = byteOrder;
75     params.dataType = dataType;
76     std::vector<int> shape(extractPyArray<int>(pyShape, "shape"));
77 caltinay 3971
78     const RipleyDomain* dom=dynamic_cast<const RipleyDomain*>(fs.getDomain().get());
79     if (!dom)
80     throw RipleyException("Function space must be on a ripley domain");
81    
82     escript::Data res(fill, shape, fs, true);
83 caltinay 4615 dom->readBinaryGrid(res, filename, params);
84 caltinay 3971 return res;
85     }
86    
87 sshaw 4738 escript::Data readBinaryGridFromZipped(std::string filename, escript::FunctionSpace fs,
88     const object& pyShape, double fill, int byteOrder, int dataType,
89     const object& pyFirst, const object& pyNum, const object& pyMultiplier,
90     const object& pyReverse)
91     {
92 caltinay 6141 #ifdef ESYS_HAVE_BOOST_IO
93 sshaw 4738 int dim=fs.getDim();
94     ReaderParameters params;
95    
96 caltinay 5187 params.first = extractPyArray<dim_t>(pyFirst, "first", dim);
97     params.numValues = extractPyArray<dim_t>(pyNum, "numValues", dim);
98 sshaw 4738 params.multiplier = extractPyArray<int>(pyMultiplier, "multiplier", dim);
99     params.reverse = extractPyArray<int>(pyReverse, "reverse", dim);
100     params.byteOrder = byteOrder;
101     params.dataType = dataType;
102     std::vector<int> shape(extractPyArray<int>(pyShape, "shape"));
103    
104     const RipleyDomain* dom=dynamic_cast<const RipleyDomain*>(fs.getDomain().get());
105     if (!dom)
106     throw RipleyException("Function space must be on a ripley domain");
107    
108     escript::Data res(fill, shape, fs, true);
109     dom->readBinaryGridFromZipped(res, filename, params);
110     return res;
111 caltinay 6141 #else
112     throw RipleyException("Ripley was not compiled with zip support!");
113     #endif
114 sshaw 4738 }
115    
116 caltinay 4013 escript::Data readNcGrid(std::string filename, std::string varname,
117 caltinay 4616 escript::FunctionSpace fs, const object& pyShape, double fill,
118     const object& pyFirst, const object& pyNum, const object& pyMultiplier,
119     const object& pyReverse)
120 caltinay 4013 {
121     int dim=fs.getDim();
122 caltinay 4618 ReaderParameters params;
123 caltinay 4013
124 caltinay 5187 params.first = extractPyArray<dim_t>(pyFirst, "first", dim);
125     params.numValues = extractPyArray<dim_t>(pyNum, "numValues", dim);
126 caltinay 4616 params.multiplier = extractPyArray<int>(pyMultiplier, "multiplier", dim);
127     params.reverse = extractPyArray<int>(pyReverse, "reverse", dim);
128     std::vector<int> shape(extractPyArray<int>(pyShape, "shape"));
129 caltinay 4013
130     const RipleyDomain* dom=dynamic_cast<const RipleyDomain*>(fs.getDomain().get());
131     if (!dom)
132     throw RipleyException("Function space must be on a ripley domain");
133    
134     escript::Data res(fill, shape, fs, true);
135 caltinay 4615 dom->readNcGrid(res, filename, varname, params);
136 caltinay 4013 return res;
137     }
138    
139 caltinay 6650 void setDecompositionPolicy(int policy)
140     {
141     DecompositionPolicy pol = static_cast<DecompositionPolicy>(policy);
142     RipleyDomain::setDecompositionPolicy(pol);
143     }
144    
145 caltinay 3691 // These wrappers are required to make the shared pointers work through the
146     // Python wrapper
147 caltinay 3670
148 jfenwick 3892 // The double for n? is just to keep python happy when people need to deal with
149 caltinay 3971 // truediv
150 jfenwick 3892 escript::Domain_ptr _brick(double _n0, double _n1, double _n2, const object& l0,
151 sshaw 4622 const object& l1, const object& l2, int d0, int d1, int d2,
152 jfenwick 4934 const object& objpoints, const object& objtags, escript::SubWorld_ptr world)
153 caltinay 3691 {
154 caltinay 5187 dim_t n0=static_cast<dim_t>(_n0), n1=static_cast<dim_t>(_n1), n2=static_cast<dim_t>(_n2);
155 caltinay 3781 double x0=0., x1=1., y0=0., y1=1., z0=0., z1=1.;
156     if (extract<tuple>(l0).check()) {
157     tuple x=extract<tuple>(l0);
158     if (len(x)==2) {
159     x0=extract<double>(x[0]);
160     x1=extract<double>(x[1]);
161     } else
162     throw RipleyException("Argument l0 must be a float or 2-tuple");
163     } else if (extract<double>(l0).check()) {
164     x1=extract<double>(l0);
165     } else
166     throw RipleyException("Argument l0 must be a float or 2-tuple");
167    
168     if (extract<tuple>(l1).check()) {
169     tuple y=extract<tuple>(l1);
170     if (len(y)==2) {
171     y0=extract<double>(y[0]);
172     y1=extract<double>(y[1]);
173     } else
174     throw RipleyException("Argument l1 must be a float or 2-tuple");
175     } else if (extract<double>(l1).check()) {
176     y1=extract<double>(l1);
177     } else
178     throw RipleyException("Argument l1 must be a float or 2-tuple");
179    
180     if (extract<tuple>(l2).check()) {
181     tuple z=extract<tuple>(l2);
182     if (len(z)==2) {
183     z0=extract<double>(z[0]);
184     z1=extract<double>(z[1]);
185     } else
186     throw RipleyException("Argument l2 must be a float or 2-tuple");
187     } else if (extract<double>(l2).check()) {
188     z1=extract<double>(l2);
189     } else
190     throw RipleyException("Argument l2 must be a float or 2-tuple");
191 sshaw 4622 boost::python::list pypoints=extract<boost::python::list>(objpoints);
192     boost::python::list pytags=extract<boost::python::list>(objtags);
193     int numpts=extract<int>(pypoints.attr("__len__")());
194     int numtags=extract<int>(pytags.attr("__len__")());
195     std::vector<double> points;
196     std::vector<int> tags;
197     tags.resize(numtags, -1);
198     for (int i=0;i<numpts;++i) {
199 sshaw 4828 tuple temp = extract<tuple>(pypoints[i]);
200 sshaw 4622 int l=extract<int>(temp.attr("__len__")());
201 sshaw 4828 if (l != 3)
202     throw RipleyException("Number of coordinates for each dirac point must match dimensions.");
203 sshaw 4622 for (int k=0;k<l;++k) {
204     points.push_back(extract<double>(temp[k]));
205     }
206     }
207     std::map<std::string, int> tagstonames;
208     int curmax=40;
209     // but which order to assign tags to names?????
210     for (int i=0;i<numtags;++i) {
211     extract<int> ex_int(pytags[i]);
212     extract<std::string> ex_str(pytags[i]);
213     if (ex_int.check()) {
214     tags[i]=ex_int();
215     if (tags[i]>= curmax) {
216     curmax=tags[i]+1;
217     }
218     } else if (ex_str.check()) {
219     std::string s=ex_str();
220     std::map<std::string, int>::iterator it=tagstonames.find(s);
221     if (it!=tagstonames.end()) {
222     // we have the tag already so look it up
223     tags[i]=it->second;
224     } else {
225     tagstonames[s]=curmax;
226     tags[i]=curmax;
227     curmax++;
228     }
229     } else {
230     throw RipleyException("Error - Unable to extract tag value.");
231     }
232     }
233 sshaw 4872 if (numtags != numpts)
234     throw RipleyException("Number of tags does not match number of points.");
235 sshaw 4622 return escript::Domain_ptr(new Brick(n0,n1,n2, x0,y0,z0, x1,y1,z1, d0,d1,d2,
236 jfenwick 4934 points, tags, tagstonames, world));
237 caltinay 3691 }
238 caltinay 3670
239 sshaw 5528 escript::Domain_ptr _multibrick(double _n0, double _n1, double _n2, const object& l0,
240     const object& l1, const object& l2, int d0, int d1, int d2,
241     const object& objpoints, const object& objtags, escript::SubWorld_ptr world,
242     unsigned int multiplier)
243     {
244     dim_t n0=static_cast<dim_t>(_n0), n1=static_cast<dim_t>(_n1), n2=static_cast<dim_t>(_n2);
245     double x0=0., x1=1., y0=0., y1=1., z0=0., z1=1.;
246     if (extract<tuple>(l0).check()) {
247     tuple x=extract<tuple>(l0);
248     if (len(x)==2) {
249     x0=extract<double>(x[0]);
250     x1=extract<double>(x[1]);
251     } else
252     throw RipleyException("Argument l0 must be a float or 2-tuple");
253     } else if (extract<double>(l0).check()) {
254     x1=extract<double>(l0);
255     } else
256     throw RipleyException("Argument l0 must be a float or 2-tuple");
257    
258     if (extract<tuple>(l1).check()) {
259     tuple y=extract<tuple>(l1);
260     if (len(y)==2) {
261     y0=extract<double>(y[0]);
262     y1=extract<double>(y[1]);
263     } else
264     throw RipleyException("Argument l1 must be a float or 2-tuple");
265     } else if (extract<double>(l1).check()) {
266     y1=extract<double>(l1);
267     } else
268     throw RipleyException("Argument l1 must be a float or 2-tuple");
269    
270     if (extract<tuple>(l2).check()) {
271     tuple z=extract<tuple>(l2);
272     if (len(z)==2) {
273     z0=extract<double>(z[0]);
274     z1=extract<double>(z[1]);
275     } else
276     throw RipleyException("Argument l2 must be a float or 2-tuple");
277     } else if (extract<double>(l2).check()) {
278     z1=extract<double>(l2);
279     } else
280     throw RipleyException("Argument l2 must be a float or 2-tuple");
281     boost::python::list pypoints=extract<boost::python::list>(objpoints);
282     boost::python::list pytags=extract<boost::python::list>(objtags);
283     int numpts=extract<int>(pypoints.attr("__len__")());
284     int numtags=extract<int>(pytags.attr("__len__")());
285     std::vector<double> points;
286     std::vector<int> tags;
287     tags.resize(numtags, -1);
288     for (int i=0;i<numpts;++i) {
289     tuple temp = extract<tuple>(pypoints[i]);
290     int l=extract<int>(temp.attr("__len__")());
291     if (l != 3)
292     throw RipleyException("Number of coordinates for each dirac point must match dimensions.");
293     for (int k=0;k<l;++k) {
294     points.push_back(extract<double>(temp[k]));
295     }
296     }
297     std::map<std::string, int> tagstonames;
298     int curmax=40;
299     // but which order to assign tags to names?????
300     for (int i=0;i<numtags;++i) {
301     extract<int> ex_int(pytags[i]);
302     extract<std::string> ex_str(pytags[i]);
303     if (ex_int.check()) {
304     tags[i]=ex_int();
305     if (tags[i]>= curmax) {
306     curmax=tags[i]+1;
307     }
308     } else if (ex_str.check()) {
309     std::string s=ex_str();
310     std::map<std::string, int>::iterator it=tagstonames.find(s);
311     if (it!=tagstonames.end()) {
312     // we have the tag already so look it up
313     tags[i]=it->second;
314     } else {
315     tagstonames[s]=curmax;
316     tags[i]=curmax;
317     curmax++;
318     }
319     } else {
320     throw RipleyException("Error - Unable to extract tag value.");
321     }
322     }
323     if (numtags != numpts)
324     throw RipleyException("Number of tags does not match number of points.");
325     return escript::Domain_ptr(new MultiBrick(n0,n1,n2, x0,y0,z0, x1,y1,z1, d0,d1,d2,
326     points, tags, tagstonames, world,
327     multiplier));
328     }
329    
330     escript::Domain_ptr _multirectangle(double _n0, double _n1, const object& l0,
331     const object& l1, int d0, int d1,
332     const object& objpoints, const object& objtags,
333     escript::SubWorld_ptr world,
334     unsigned int multiplier)
335     {
336     dim_t n0=static_cast<dim_t>(_n0), n1=static_cast<dim_t>(_n1);
337     double x0=0., x1=1., y0=0., y1=1.;
338     if (extract<tuple>(l0).check()) {
339     tuple x=extract<tuple>(l0);
340     if (len(x)==2) {
341     x0=extract<double>(x[0]);
342     x1=extract<double>(x[1]);
343     } else
344     throw RipleyException("Argument l0 must be a float or 2-tuple");
345     } else if (extract<double>(l0).check()) {
346     x1=extract<double>(l0);
347     } else
348     throw RipleyException("Argument l0 must be a float or 2-tuple");
349    
350     if (extract<tuple>(l1).check()) {
351     tuple y=extract<tuple>(l1);
352     if (len(y)==2) {
353     y0=extract<double>(y[0]);
354     y1=extract<double>(y[1]);
355     } else
356     throw RipleyException("Argument l1 must be a float or 2-tuple");
357     } else if (extract<double>(l1).check()) {
358     y1=extract<double>(l1);
359     } else
360     throw RipleyException("Argument l1 must be a float or 2-tuple");
361     boost::python::list pypoints=extract<boost::python::list>(objpoints);
362     boost::python::list pytags=extract<boost::python::list>(objtags);
363     int numpts=extract<int>(pypoints.attr("__len__")());
364     int numtags=extract<int>(pytags.attr("__len__")());
365     std::vector<double> points;
366     std::vector<int> tags;
367     tags.resize(numtags, -1);
368     for (int i=0;i<numpts;++i) {
369     tuple temp = extract<tuple>(pypoints[i]);
370     int l=extract<int>(temp.attr("__len__")());
371     if (l != 2)
372     throw RipleyException("Number of coordinates for each dirac point must match dimensions.");
373     for (int k=0;k<l;++k) {
374     points.push_back(extract<double>(temp[k]));
375     }
376     }
377     std::map<std::string, int> tagstonames;
378     int curmax=40;
379     // but which order to assign tags to names?????
380     for (int i=0;i<numtags;++i) {
381     extract<int> ex_int(pytags[i]);
382     extract<std::string> ex_str(pytags[i]);
383     if (ex_int.check()) {
384     tags[i]=ex_int();
385     if (tags[i] >= curmax) {
386     curmax=tags[i]+1;
387     }
388     } else if (ex_str.check()) {
389     std::string s=ex_str();
390     std::map<std::string, int>::iterator it=tagstonames.find(s);
391     if (it!=tagstonames.end()) {
392     // we have the tag already so look it up
393     tags[i]=it->second;
394     } else {
395     tagstonames[s]=curmax;
396     tags[i]=curmax;
397     curmax++;
398     }
399     } else {
400     throw RipleyException("Error - Unable to extract tag value.");
401     }
402     }
403     if (numtags != numpts)
404     throw RipleyException("Number of tags does not match number of points.");
405     return escript::Domain_ptr(new MultiRectangle(n0,n1, x0,y0, x1,y1, d0,d1,
406     points, tags, tagstonames, world, multiplier));
407     }
408    
409 jfenwick 3892 escript::Domain_ptr _rectangle(double _n0, double _n1, const object& l0,
410 sshaw 4622 const object& l1, int d0, int d1,
411 jfenwick 4934 const object& objpoints, const object& objtags,
412     escript::SubWorld_ptr world
413     )
414 caltinay 3691 {
415 caltinay 5187 dim_t n0=static_cast<dim_t>(_n0), n1=static_cast<dim_t>(_n1);
416 caltinay 3781 double x0=0., x1=1., y0=0., y1=1.;
417     if (extract<tuple>(l0).check()) {
418     tuple x=extract<tuple>(l0);
419     if (len(x)==2) {
420     x0=extract<double>(x[0]);
421     x1=extract<double>(x[1]);
422     } else
423     throw RipleyException("Argument l0 must be a float or 2-tuple");
424     } else if (extract<double>(l0).check()) {
425     x1=extract<double>(l0);
426     } else
427     throw RipleyException("Argument l0 must be a float or 2-tuple");
428    
429     if (extract<tuple>(l1).check()) {
430     tuple y=extract<tuple>(l1);
431     if (len(y)==2) {
432     y0=extract<double>(y[0]);
433     y1=extract<double>(y[1]);
434     } else
435     throw RipleyException("Argument l1 must be a float or 2-tuple");
436     } else if (extract<double>(l1).check()) {
437     y1=extract<double>(l1);
438     } else
439     throw RipleyException("Argument l1 must be a float or 2-tuple");
440 sshaw 4622 boost::python::list pypoints=extract<boost::python::list>(objpoints);
441     boost::python::list pytags=extract<boost::python::list>(objtags);
442     int numpts=extract<int>(pypoints.attr("__len__")());
443     int numtags=extract<int>(pytags.attr("__len__")());
444     std::vector<double> points;
445     std::vector<int> tags;
446     tags.resize(numtags, -1);
447     for (int i=0;i<numpts;++i) {
448 sshaw 4828 tuple temp = extract<tuple>(pypoints[i]);
449 sshaw 4622 int l=extract<int>(temp.attr("__len__")());
450 sshaw 4828 if (l != 2)
451     throw RipleyException("Number of coordinates for each dirac point must match dimensions.");
452 sshaw 4622 for (int k=0;k<l;++k) {
453     points.push_back(extract<double>(temp[k]));
454     }
455     }
456     std::map<std::string, int> tagstonames;
457     int curmax=40;
458     // but which order to assign tags to names?????
459     for (int i=0;i<numtags;++i) {
460     extract<int> ex_int(pytags[i]);
461     extract<std::string> ex_str(pytags[i]);
462     if (ex_int.check()) {
463     tags[i]=ex_int();
464 caltinay 5187 if (tags[i] >= curmax) {
465 sshaw 4622 curmax=tags[i]+1;
466     }
467     } else if (ex_str.check()) {
468     std::string s=ex_str();
469     std::map<std::string, int>::iterator it=tagstonames.find(s);
470     if (it!=tagstonames.end()) {
471     // we have the tag already so look it up
472     tags[i]=it->second;
473     } else {
474     tagstonames[s]=curmax;
475     tags[i]=curmax;
476     curmax++;
477     }
478     } else {
479     throw RipleyException("Error - Unable to extract tag value.");
480     }
481     }
482 sshaw 4872 if (numtags != numpts)
483     throw RipleyException("Number of tags does not match number of points.");
484 sshaw 4622 return escript::Domain_ptr(new Rectangle(n0,n1, x0,y0, x1,y1, d0,d1,
485 jfenwick 4934 points, tags, tagstonames, world));
486 caltinay 3691 }
487 caltinay 3670
488 caltinay 4357 } // end of namespace ripley
489 caltinay 3670
490    
491     BOOST_PYTHON_MODULE(ripleycpp)
492     {
493     // This feature was added in boost v1.34
494     #if ((BOOST_VERSION/100)%1000 > 34) || (BOOST_VERSION/100000 >1)
495 caltinay 3691 // params are: bool show_user_defined, bool show_py_signatures, bool show_cpp_signatures
496     docstring_options docopt(true, true, false);
497 caltinay 3670 #endif
498    
499 caltinay 5972 // register escript's default translators
500     REGISTER_ESCRIPT_EXCEPTION_TRANSLATORS;
501 caltinay 5954 register_exception_translator<ripley::RipleyException>(&escript::RuntimeErrorTranslator);
502 caltinay 3670
503 caltinay 4174 scope().attr("__doc__") = "To use this module, please import esys.ripley";
504 caltinay 4357 scope().attr("BYTEORDER_NATIVE") = (int)ripley::BYTEORDER_NATIVE;
505     scope().attr("BYTEORDER_LITTLE_ENDIAN") = (int)ripley::BYTEORDER_LITTLE_ENDIAN;
506     scope().attr("BYTEORDER_BIG_ENDIAN") = (int)ripley::BYTEORDER_BIG_ENDIAN;
507     scope().attr("DATATYPE_INT32") = (int)ripley::DATATYPE_INT32;
508     scope().attr("DATATYPE_FLOAT32") = (int)ripley::DATATYPE_FLOAT32;
509     scope().attr("DATATYPE_FLOAT64") = (int)ripley::DATATYPE_FLOAT64;
510 caltinay 4174
511 caltinay 6394 scope().attr("DECOMP_ADD_ELEMENTS") = (int)ripley::DECOMP_ADD_ELEMENTS;
512     scope().attr("DECOMP_EXPAND") = (int)ripley::DECOMP_EXPAND;
513     scope().attr("DECOMP_STRICT") = (int)ripley::DECOMP_STRICT;
514    
515 caltinay 6650 def("setDecompositionPolicy", &ripley::setDecompositionPolicy,
516 caltinay 6394 args("value"),
517     "Sets the automatic domain decomposition policy for new domains.\n\n"
518     ":param value: policy\n:type value: ``int``");
519    
520 sshaw 5575 def("Brick", ripley::_brick, (arg("n0"),arg("n1"),arg("n2"),arg("l0")=1.0,
521     arg("l1")=1.0,arg("l2")=1.0,arg("d0")=-1,arg("d1")=-1,arg("d2")=-1,
522     arg("diracPoints")=list(),arg("diracTags")=list(),
523     arg("escriptworld")=escript::SubWorld_ptr()),
524     "Creates a hexagonal mesh with n0 x n1 x n2 elements over the brick [0,l0] x [0,l1] x [0,l2].\n\n"
525     ":param n0: number of elements in direction 0\n:type n0: ``int``\n"
526     ":param n1: number of elements in direction 1\n:type n1: ``int``\n"
527     ":param n2: number of elements in direction 2\n:type n2: ``int``\n"
528     ":param l0: length of side 0 or coordinate range of side 0\n:type l0: ``float`` or ``tuple``\n"
529     ":param l1: length of side 1 or coordinate range of side 1\n:type l1: ``float`` or ``tuple``\n"
530     ":param l2: length of side 2 or coordinate range of side 2\n:type l2: ``float`` or ``tuple``\n"
531     ":param d0: number of subdivisions in direction 0\n:type d0: ``int``\n"
532     ":param d1: number of subdivisions in direction 1\n:type d1: ``int``\n"
533     ":param d2: number of subdivisions in direction 2\n:type d2: ``int``");
534 caltinay 3670
535 sshaw 5575 def("Rectangle", ripley::_rectangle, (arg("n0"),arg("n1"),arg("l0")=1.0,
536     arg("l1")=1.0,arg("d0")=-1,arg("d1")=-1,arg("diracPoints")=list(),
537     arg("diracTags")=list(), arg("escriptworld")=escript::SubWorld_ptr()),
538     "Creates a rectangular mesh with n0 x n1 elements over the rectangle [0,l0] x [0,l1].\n\n"
539     ":param n0: number of elements in direction 0\n:type n0: ``int``\n"
540     ":param n1: number of elements in direction 1\n:type n1: ``int``\n"
541     ":param l0: length of side 0 or coordinate range of side 0\n:type l0: ``float`` or ``tuple``\n"
542     ":param l1: length of side 1 or coordinate range of side 1\n:type l1: ``float`` or ``tuple``\n"
543     ":param d0: number of subdivisions in direction 0\n:type d0: ``int``\n"
544     ":param d1: number of subdivisions in direction 1\n:type d1: ``int``");
545 caltinay 3670
546 sshaw 5575 def("MultiRectangle", ripley::_multirectangle, (arg("n0"),arg("n1"),
547     arg("l0")=1.0,arg("l1")=1.0,arg("d0")=-1,arg("d1")=-1,
548     arg("diracPoints")=list(),arg("diracTags")=list(),
549     arg("escriptworld")=escript::SubWorld_ptr(), arg("multiplier")=1),
550     "Creates a rectangular mesh with n0 x n1 parent elements over the "
551     "rectangle [0,l0] x [0,l1], each parent element is divided ``multiplier`` times.\n\n"
552     ":param n0: number of elements in direction 0\n:type n0: ``int``\n"
553     ":param n1: number of elements in direction 1\n:type n1: ``int``\n"
554     ":param l0: length of side 0 or coordinate range of side 0\n:type l0: ``float`` or ``tuple``\n"
555     ":param l1: length of side 1 or coordinate range of side 1\n:type l1: ``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 multiplier: size of overlap\n:type multiplier: ``unsigned int``");
559 sshaw 5528
560 sshaw 5575 def("MultiBrick", ripley::_multibrick, (arg("n0"),arg("n1"),arg("n2"),
561     arg("l0")=1.0,arg("l1")=1.0,arg("l2")=1.0,arg("d0")=-1,arg("d1")=-1,
562     arg("d2")=-1,arg("diracPoints")=list(),arg("diracTags")=list(),
563     arg("escriptworld")=escript::SubWorld_ptr(), arg("multiplier")=1),
564     "Creates a hexagonal mesh with n0 x n1 x n2 parent elements over the "
565     "brick [0,l0] x [0,l1] x [0,l2], each parent element is divided ``multiplier`` times.\n\n"
566     ":param n0: number of elements in direction 0\n:type n0: ``int``\n"
567     ":param n1: number of elements in direction 1\n:type n1: ``int``\n"
568     ":param n2: number of elements in direction 2\n:type n2: ``int``\n"
569     ":param l0: length of side 0 or coordinate range of side 0\n:type l0: ``float`` or ``tuple``\n"
570     ":param l1: length of side 1 or coordinate range of side 1\n:type l1: ``float`` or ``tuple``\n"
571     ":param l2: length of side 2 or coordinate range of side 2\n:type l2: ``float`` or ``tuple``\n"
572     ":param d0: number of subdivisions in direction 0\n:type d0: ``int``\n"
573     ":param d1: number of subdivisions in direction 1\n:type d1: ``int``\n"
574     ":param d2: number of subdivisions in direction 2\n:type d2: ``int``"
575     ":param multiplier: size of overlap\n:type multiplier: ``unsigned int``");
576 sshaw 5528
577 caltinay 5077 def("readBinaryGrid", &ripley::readBinaryGrid, (arg("filename"),
578 caltinay 4616 arg("functionspace"), arg("shape"), arg("fill")=0.,
579     arg("byteOrder"), arg("dataType"), arg("first"),
580     arg("numValues"), arg("multiplier"), arg("reverse")),
581 sshaw 5575 "Reads a binary Grid");
582 sshaw 4738 def("_readBinaryGridFromZipped", &ripley::readBinaryGridFromZipped, (arg("filename"),
583     arg("functionspace"), arg("shape"), arg("fill")=0.,
584     arg("byteOrder"), arg("dataType"), arg("first"),
585     arg("numValues"), arg("multiplier"), arg("reverse")),
586 sshaw 5575 "Reads a binary Grid");
587 caltinay 4616 def("_readNcGrid", &ripley::readNcGrid, (arg("filename"), arg("varname"),
588     arg("functionspace"), arg("shape"), arg("fill"), arg("first"),
589     arg("numValues"), arg("multiplier"), arg("reverse")),
590 sshaw 5575 "Reads a grid from a netCDF file");
591 caltinay 4013
592 jfenwick 4242 class_<ripley::RipleyDomain, bases<escript::AbstractContinuousDomain>, boost::noncopyable >
593 caltinay 3691 ("RipleyDomain", "", no_init)
594     .def("print_mesh_info", &ripley::RipleyDomain::Print_Mesh_Info, (arg("full")=false),
595     "Prints out a summary about the mesh.\n"
596     ":param full: whether to output additional data\n:type full: ``bool``")
597 caltinay 4357 .def("writeBinaryGrid", &ripley::RipleyDomain::writeBinaryGrid)
598    
599 caltinay 3691 .def("dump", &ripley::RipleyDomain::dump, args("filename"),
600     "Dumps the mesh to a file with the given name.")
601 caltinay 4340 .def("getGridParameters", &ripley::RipleyDomain::getGridParameters,
602 sshaw 5575 "Returns the tuple (origin, spacing, elements) where the entries are tuples containing\n"
603     " ``origin`` the coordinates of the domain's global origin,\n"
604     " ``spacing`` the element size (node spacing) of the domain,\n"
605     " ``elements`` the global number of elements in all dimensions\n\n"
606     ":rtype: ``tuple``")
607 caltinay 3691 .def("getDescription", &ripley::RipleyDomain::getDescription,
608 sshaw 5575 ":return: a description for this domain\n:rtype: ``string``")
609 caltinay 3691 .def("getDim", &ripley::RipleyDomain::getDim, ":rtype: ``int``")
610     .def("getDataShape", &ripley::RipleyDomain::getDataShape, args("functionSpaceCode"),
611 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"
612     ":rtype: ``tuple``")
613 caltinay 3691 .def("getNumDataPointsGlobal", &ripley::RipleyDomain::getNumDataPointsGlobal,
614 sshaw 5575 ":return: the number of data points summed across all MPI processes\n"
615     ":rtype: ``int``")
616 sshaw 4622 .def("addToSystem",&ripley::RipleyDomain::addToSystemFromPython,
617     args("mat", "rhs", "data"),
618     "adds a PDE to the system, results depend on domain\n\n"
619     ":param mat:\n:type mat: `OperatorAdapter`\n"
620     ":param rhs:\n:type rhs: `Data`\n"
621 sshaw 5575 ":param data:\n:type data: `list`\n")
622 sshaw 4622 .def("addToRHS",&ripley::RipleyDomain::addToRHSFromPython,
623     args("rhs", "data"),
624     "adds a PDE onto the stiffness matrix mat and a rhs, "
625     "results depends on domain\n\n"
626     ":param rhs:\n:type rhs: `Data`\n"
627 sshaw 5575 ":param data:\n:type data: `list`\n")
628 sshaw 4942 .def("createAssembler", &ripley::RipleyDomain::createAssemblerFromPython,
629 sshaw 4622 args("typename", "options"),
630 sshaw 4942 "request from the domain an assembler of the specified type, if "
631     "supported, using the supplied options (if provided)"
632 sshaw 4622 ":param typename:\n:type typename: `string`\n"
633     ":param options:\n:type options: `list`\n")
634 sshaw 4942 .def("addPDEToTransportProblem",&ripley::RipleyDomain::addPDEToTransportProblemFromPython,
635     args("tp", "source", "data"),
636     ":param tp:\n:type tp: `TransportProblemAdapter`\n"
637     ":param source:\n:type source: `Data`\n"
638 sshaw 5575 ":param data:\n:type data: `list`\n")
639 caltinay 3691 .def("newOperator",&ripley::RipleyDomain::newSystemMatrix,
640 sshaw 5575 args("row_blocksize", "row_functionspace", "column_blocksize", "column_functionspace", "type"),
641     "creates a SystemMatrixAdapter stiffness matrix and initializes it with zeros\n\n"
642     ":param row_blocksize:\n:type row_blocksize: ``int``\n"
643     ":param row_functionspace:\n:type row_functionspace: `FunctionSpace`\n"
644     ":param column_blocksize:\n:type column_blocksize: ``int``\n"
645     ":param column_functionspace:\n:type column_functionspace: `FunctionSpace`\n"
646     ":param type:\n:type type: ``int``"
647     )
648 caltinay 3691 .def("newTransportProblem",&ripley::RipleyDomain::newTransportProblem,
649 sshaw 5575 args("theta", "blocksize", "functionspace", "type"),
650     "creates a TransportProblemAdapter\n\n"
651     ":param theta:\n:type theta: ``float``\n"
652     ":param blocksize:\n:type blocksize: ``int``\n"
653     ":param functionspace:\n:type functionspace: `FunctionSpace`\n"
654     ":param type:\n:type type: ``int``"
655     )
656 caltinay 3691 .def("getSystemMatrixTypeId",&ripley::RipleyDomain::getSystemMatrixTypeId,
657 sshaw 5575 args("options"),
658     ":return: the identifier of the matrix type to be used for the global stiffness matrix when particular solver options are used.\n"
659     ":rtype: ``int``\n"
660     ":param options:\n:type options: `SolverBuddy`\n"
661     )
662 caltinay 3691 .def("getTransportTypeId",&ripley::RipleyDomain::getTransportTypeId,
663 sshaw 5575 args("solver", "preconditioner", "package", "symmetry"),
664     ":return: the identifier of the transport problem type to be used when a particular solver, preconditioner, package and symmetric matrix is used.\n"
665     ":rtype: ``int``\n"
666     ":param solver:\n:type solver: ``int``\n"
667     ":param preconditioner:\n:type preconditioner: ``int``\n"
668     ":param package:\n:type package: ``int``\n"
669     ":param symmetry:\n:type symmetry: ``int``"
670     )
671 caltinay 3691 .def("getX",&ripley::RipleyDomain::getX, ":return: locations in the FEM nodes\n\n"
672 sshaw 5575 ":rtype: `Data`")
673 caltinay 3691 .def("getNormal",&ripley::RipleyDomain::getNormal,
674 sshaw 5575 ":return: boundary normals at the quadrature point on the face elements\n"
675     ":rtype: `Data`")
676 caltinay 3691 .def("getSize",&ripley::RipleyDomain::getSize,":return: the element size\n"
677 sshaw 5575 ":rtype: `Data`")
678 caltinay 3691 .def("setTagMap",&ripley::RipleyDomain::setTagMap,args("name","tag"),
679 sshaw 5575 "Give a tag number a name.\n\n:param name: Name for the tag\n:type name: ``string``\n"
680     ":param tag: numeric id\n:type tag: ``int``\n:note: Tag names must be unique within a domain")
681 caltinay 3691 .def("getTag",&ripley::RipleyDomain::getTag,args("name"),":return: tag id for "
682 sshaw 5575 "``name``\n:rtype: ``string``")
683 caltinay 3691 .def("isValidTagName",&ripley::RipleyDomain::isValidTagName,args("name"),
684 sshaw 5575 ":return: True if ``name`` corresponds to a tag, otherwise False\n:rtype: ``bool``")
685 caltinay 3691 .def("showTagNames",&ripley::RipleyDomain::showTagNames,":return: A space separated list of tag names\n:rtype: ``string``")
686     .def("getMPISize",&ripley::RipleyDomain::getMPISize,":return: the number of processes used for this `Domain`\n:rtype: ``int``")
687     .def("getMPIRank",&ripley::RipleyDomain::getMPIRank,":return: the rank of this process\n:rtype: ``int``")
688     .def("MPIBarrier",&ripley::RipleyDomain::MPIBarrier,"Wait until all processes have reached this point")
689     .def("onMasterProcessor",&ripley::RipleyDomain::onMasterProcessor,":return: True if this code is executing on the master process\n:rtype: `bool`");
690 caltinay 5954 // These two class exports are necessary to ensure that the extra methods
691     // added by ripley make it to python. This change became necessary when
692     // the Brick and Rectangle constructors turned into factories instead of
693     // classes
694 jfenwick 4687 class_<ripley::Brick, bases<ripley::RipleyDomain> >("RipleyBrick", "", no_init);
695     class_<ripley::Rectangle, bases<ripley::RipleyDomain> >("RipleyRectangle", "", no_init);
696 sshaw 5528 class_<ripley::MultiRectangle, bases<ripley::RipleyDomain> >("RipleyMultiRectangle", "", no_init);
697     class_<ripley::MultiBrick, bases<ripley::RipleyDomain> >("RipleyMultiBrick", "", no_init);
698 sshaw 4943 class_<ripley::AbstractAssembler, ripley::Assembler_ptr, boost::noncopyable >
699     ("AbstractAssembler", "", no_init);
700 caltinay 3670 }
701    

  ViewVC Help
Powered by ViewVC 1.1.26