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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5528 - (show annotations)
Wed Mar 11 03:48:47 2015 UTC (4 years, 1 month ago) by sshaw
File size: 31391 byte(s)
adding single-process multi-resolution ripley domains
1
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2015 by University of Queensland
5 * http://www.uq.edu.au
6 *
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 * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 * 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>
22 #include <ripley/MultiBrick.h>
23 #include <ripley/Rectangle.h>
24 #include <ripley/MultiRectangle.h>
25 #include <esysUtils/esysExceptionTranslator.h>
26
27 #include <boost/python.hpp>
28 #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 #include "escript/SubWorld.h"
34
35 using namespace boost::python;
36
37 namespace ripley {
38
39 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 escript::Data readBinaryGrid(std::string filename, escript::FunctionSpace fs,
66 const object& pyShape, double fill, int byteOrder, int dataType,
67 const object& pyFirst, const object& pyNum, const object& pyMultiplier,
68 const object& pyReverse)
69 {
70 int dim=fs.getDim();
71 ReaderParameters params;
72
73 params.first = extractPyArray<dim_t>(pyFirst, "first", dim);
74 params.numValues = extractPyArray<dim_t>(pyNum, "numValues", dim);
75 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
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 dom->readBinaryGrid(res, filename, params);
87 return res;
88 }
89
90 #ifdef USE_BOOSTIO
91 escript::Data readBinaryGridFromZipped(std::string filename, escript::FunctionSpace fs,
92 const object& pyShape, double fill, int byteOrder, int dataType,
93 const object& pyFirst, const object& pyNum, const object& pyMultiplier,
94 const object& pyReverse)
95 {
96 int dim=fs.getDim();
97 ReaderParameters params;
98
99 params.first = extractPyArray<dim_t>(pyFirst, "first", dim);
100 params.numValues = extractPyArray<dim_t>(pyNum, "numValues", dim);
101 params.multiplier = extractPyArray<int>(pyMultiplier, "multiplier", dim);
102 params.reverse = extractPyArray<int>(pyReverse, "reverse", dim);
103 params.byteOrder = byteOrder;
104 params.dataType = dataType;
105 std::vector<int> shape(extractPyArray<int>(pyShape, "shape"));
106
107 const RipleyDomain* dom=dynamic_cast<const RipleyDomain*>(fs.getDomain().get());
108 if (!dom)
109 throw RipleyException("Function space must be on a ripley domain");
110
111 escript::Data res(fill, shape, fs, true);
112 dom->readBinaryGridFromZipped(res, filename, params);
113 return res;
114 }
115 #endif
116
117 escript::Data readNcGrid(std::string filename, std::string varname,
118 escript::FunctionSpace fs, const object& pyShape, double fill,
119 const object& pyFirst, const object& pyNum, const object& pyMultiplier,
120 const object& pyReverse)
121 {
122 int dim=fs.getDim();
123 ReaderParameters params;
124
125 params.first = extractPyArray<dim_t>(pyFirst, "first", dim);
126 params.numValues = extractPyArray<dim_t>(pyNum, "numValues", dim);
127 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
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 dom->readNcGrid(res, filename, varname, params);
137 return res;
138 }
139
140 // These wrappers are required to make the shared pointers work through the
141 // Python wrapper
142
143 // The double for n? is just to keep python happy when people need to deal with
144 // truediv
145 escript::Domain_ptr _brick(double _n0, double _n1, double _n2, const object& l0,
146 const object& l1, const object& l2, int d0, int d1, int d2,
147 const object& objpoints, const object& objtags, escript::SubWorld_ptr world)
148 {
149 dim_t n0=static_cast<dim_t>(_n0), n1=static_cast<dim_t>(_n1), n2=static_cast<dim_t>(_n2);
150 double x0=0., x1=1., y0=0., y1=1., z0=0., z1=1.;
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 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 tuple temp = extract<tuple>(pypoints[i]);
195 int l=extract<int>(temp.attr("__len__")());
196 if (l != 3)
197 throw RipleyException("Number of coordinates for each dirac point must match dimensions.");
198 for (int k=0;k<l;++k) {
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 if (numtags != numpts)
229 throw RipleyException("Number of tags does not match number of points.");
230 return escript::Domain_ptr(new Brick(n0,n1,n2, x0,y0,z0, x1,y1,z1, d0,d1,d2,
231 points, tags, tagstonames, world));
232 }
233
234 escript::Domain_ptr _multibrick(double _n0, double _n1, double _n2, const object& l0,
235 const object& l1, const object& l2, int d0, int d1, int d2,
236 const object& objpoints, const object& objtags, escript::SubWorld_ptr world,
237 unsigned int multiplier)
238 {
239 dim_t n0=static_cast<dim_t>(_n0), n1=static_cast<dim_t>(_n1), n2=static_cast<dim_t>(_n2);
240 double x0=0., x1=1., y0=0., y1=1., z0=0., z1=1.;
241 if (extract<tuple>(l0).check()) {
242 tuple x=extract<tuple>(l0);
243 if (len(x)==2) {
244 x0=extract<double>(x[0]);
245 x1=extract<double>(x[1]);
246 } else
247 throw RipleyException("Argument l0 must be a float or 2-tuple");
248 } else if (extract<double>(l0).check()) {
249 x1=extract<double>(l0);
250 } else
251 throw RipleyException("Argument l0 must be a float or 2-tuple");
252
253 if (extract<tuple>(l1).check()) {
254 tuple y=extract<tuple>(l1);
255 if (len(y)==2) {
256 y0=extract<double>(y[0]);
257 y1=extract<double>(y[1]);
258 } else
259 throw RipleyException("Argument l1 must be a float or 2-tuple");
260 } else if (extract<double>(l1).check()) {
261 y1=extract<double>(l1);
262 } else
263 throw RipleyException("Argument l1 must be a float or 2-tuple");
264
265 if (extract<tuple>(l2).check()) {
266 tuple z=extract<tuple>(l2);
267 if (len(z)==2) {
268 z0=extract<double>(z[0]);
269 z1=extract<double>(z[1]);
270 } else
271 throw RipleyException("Argument l2 must be a float or 2-tuple");
272 } else if (extract<double>(l2).check()) {
273 z1=extract<double>(l2);
274 } else
275 throw RipleyException("Argument l2 must be a float or 2-tuple");
276 boost::python::list pypoints=extract<boost::python::list>(objpoints);
277 boost::python::list pytags=extract<boost::python::list>(objtags);
278 int numpts=extract<int>(pypoints.attr("__len__")());
279 int numtags=extract<int>(pytags.attr("__len__")());
280 std::vector<double> points;
281 std::vector<int> tags;
282 tags.resize(numtags, -1);
283 for (int i=0;i<numpts;++i) {
284 tuple temp = extract<tuple>(pypoints[i]);
285 int l=extract<int>(temp.attr("__len__")());
286 if (l != 3)
287 throw RipleyException("Number of coordinates for each dirac point must match dimensions.");
288 for (int k=0;k<l;++k) {
289 points.push_back(extract<double>(temp[k]));
290 }
291 }
292 std::map<std::string, int> tagstonames;
293 int curmax=40;
294 // but which order to assign tags to names?????
295 for (int i=0;i<numtags;++i) {
296 extract<int> ex_int(pytags[i]);
297 extract<std::string> ex_str(pytags[i]);
298 if (ex_int.check()) {
299 tags[i]=ex_int();
300 if (tags[i]>= curmax) {
301 curmax=tags[i]+1;
302 }
303 } else if (ex_str.check()) {
304 std::string s=ex_str();
305 std::map<std::string, int>::iterator it=tagstonames.find(s);
306 if (it!=tagstonames.end()) {
307 // we have the tag already so look it up
308 tags[i]=it->second;
309 } else {
310 tagstonames[s]=curmax;
311 tags[i]=curmax;
312 curmax++;
313 }
314 } else {
315 throw RipleyException("Error - Unable to extract tag value.");
316 }
317 }
318 if (numtags != numpts)
319 throw RipleyException("Number of tags does not match number of points.");
320 return escript::Domain_ptr(new MultiBrick(n0,n1,n2, x0,y0,z0, x1,y1,z1, d0,d1,d2,
321 points, tags, tagstonames, world,
322 multiplier));
323 }
324
325 escript::Domain_ptr _multirectangle(double _n0, double _n1, const object& l0,
326 const object& l1, int d0, int d1,
327 const object& objpoints, const object& objtags,
328 escript::SubWorld_ptr world,
329 unsigned int multiplier)
330 {
331 dim_t n0=static_cast<dim_t>(_n0), n1=static_cast<dim_t>(_n1);
332 double x0=0., x1=1., y0=0., y1=1.;
333 if (extract<tuple>(l0).check()) {
334 tuple x=extract<tuple>(l0);
335 if (len(x)==2) {
336 x0=extract<double>(x[0]);
337 x1=extract<double>(x[1]);
338 } else
339 throw RipleyException("Argument l0 must be a float or 2-tuple");
340 } else if (extract<double>(l0).check()) {
341 x1=extract<double>(l0);
342 } else
343 throw RipleyException("Argument l0 must be a float or 2-tuple");
344
345 if (extract<tuple>(l1).check()) {
346 tuple y=extract<tuple>(l1);
347 if (len(y)==2) {
348 y0=extract<double>(y[0]);
349 y1=extract<double>(y[1]);
350 } else
351 throw RipleyException("Argument l1 must be a float or 2-tuple");
352 } else if (extract<double>(l1).check()) {
353 y1=extract<double>(l1);
354 } else
355 throw RipleyException("Argument l1 must be a float or 2-tuple");
356 boost::python::list pypoints=extract<boost::python::list>(objpoints);
357 boost::python::list pytags=extract<boost::python::list>(objtags);
358 int numpts=extract<int>(pypoints.attr("__len__")());
359 int numtags=extract<int>(pytags.attr("__len__")());
360 std::vector<double> points;
361 std::vector<int> tags;
362 tags.resize(numtags, -1);
363 for (int i=0;i<numpts;++i) {
364 tuple temp = extract<tuple>(pypoints[i]);
365 int l=extract<int>(temp.attr("__len__")());
366 if (l != 2)
367 throw RipleyException("Number of coordinates for each dirac point must match dimensions.");
368 for (int k=0;k<l;++k) {
369 points.push_back(extract<double>(temp[k]));
370 }
371 }
372 std::map<std::string, int> tagstonames;
373 int curmax=40;
374 // but which order to assign tags to names?????
375 for (int i=0;i<numtags;++i) {
376 extract<int> ex_int(pytags[i]);
377 extract<std::string> ex_str(pytags[i]);
378 if (ex_int.check()) {
379 tags[i]=ex_int();
380 if (tags[i] >= curmax) {
381 curmax=tags[i]+1;
382 }
383 } else if (ex_str.check()) {
384 std::string s=ex_str();
385 std::map<std::string, int>::iterator it=tagstonames.find(s);
386 if (it!=tagstonames.end()) {
387 // we have the tag already so look it up
388 tags[i]=it->second;
389 } else {
390 tagstonames[s]=curmax;
391 tags[i]=curmax;
392 curmax++;
393 }
394 } else {
395 throw RipleyException("Error - Unable to extract tag value.");
396 }
397 }
398 if (numtags != numpts)
399 throw RipleyException("Number of tags does not match number of points.");
400 return escript::Domain_ptr(new MultiRectangle(n0,n1, x0,y0, x1,y1, d0,d1,
401 points, tags, tagstonames, world, multiplier));
402 }
403
404 escript::Domain_ptr _rectangle(double _n0, double _n1, const object& l0,
405 const object& l1, int d0, int d1,
406 const object& objpoints, const object& objtags,
407 escript::SubWorld_ptr world
408 )
409 {
410 dim_t n0=static_cast<dim_t>(_n0), n1=static_cast<dim_t>(_n1);
411 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 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 tuple temp = extract<tuple>(pypoints[i]);
444 int l=extract<int>(temp.attr("__len__")());
445 if (l != 2)
446 throw RipleyException("Number of coordinates for each dirac point must match dimensions.");
447 for (int k=0;k<l;++k) {
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 if (tags[i] >= curmax) {
460 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 if (numtags != numpts)
478 throw RipleyException("Number of tags does not match number of points.");
479 return escript::Domain_ptr(new Rectangle(n0,n1, x0,y0, x1,y1, d0,d1,
480 points, tags, tagstonames, world));
481 }
482
483 } // end of namespace ripley
484
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 // params are: bool show_user_defined, bool show_py_signatures, bool show_cpp_signatures
491 docstring_options docopt(true, true, false);
492 #endif
493
494 register_exception_translator<ripley::RipleyException>(&(esysUtils::RuntimeErrorTranslator));
495
496 scope().attr("__doc__") = "To use this module, please import esys.ripley";
497 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
504 def("Brick", ripley::_brick, (arg("n0"),arg("n1"),arg("n2"),arg("l0")=1.0,arg("l1")=1.0,arg("l2")=1.0,
505 arg("d0")=-1,arg("d1")=-1,arg("d2")=-1,arg("diracPoints")=list(),arg("diracTags")=list(), arg("escriptworld")=escript::SubWorld_ptr()),
506 "Creates a hexagonal mesh with n0 x n1 x n2 elements over the brick [0,l0] x [0,l1] x [0,l2].\n\n"
507 ":param n0: number of elements in direction 0\n:type n0: ``int``\n"
508 ":param n1: number of elements in direction 1\n:type n1: ``int``\n"
509 ":param n2: number of elements in direction 2\n:type n2: ``int``\n"
510 ":param l0: length of side 0 or coordinate range of side 0\n:type l0: ``float`` or ``tuple``\n"
511 ":param l1: length of side 1 or coordinate range of side 1\n:type l1: ``float`` or ``tuple``\n"
512 ":param l2: length of side 2 or coordinate range of side 2\n:type l2: ``float`` or ``tuple``\n"
513 ":param d0: number of subdivisions in direction 0\n:type d0: ``int``\n"
514 ":param d1: number of subdivisions in direction 1\n:type d1: ``int``\n"
515 ":param d2: number of subdivisions in direction 2\n:type d2: ``int``");
516
517 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()),
518 "Creates a rectangular mesh with n0 x n1 elements over the rectangle [0,l0] x [0,l1].\n\n"
519 ":param n0: number of elements in direction 0\n:type n0: ``int``\n"
520 ":param n1: number of elements in direction 1\n:type n1: ``int``\n"
521 ":param l0: length of side 0 or coordinate range of side 0\n:type l0: ``float`` or ``tuple``\n"
522 ":param l1: length of side 1 or coordinate range of side 1\n:type l1: ``float`` or ``tuple``\n"
523 ":param d0: number of subdivisions in direction 0\n:type d0: ``int``\n"
524 ":param d1: number of subdivisions in direction 1\n:type d1: ``int``");
525
526 def("MultiRectangle", ripley::_multirectangle, (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(), arg("multiplier")=1),
527 "Creates a rectangular mesh with n0 x n1 elements over the rectangle [0,l0] x [0,l1].\n\n"
528 ":param n0: number of elements in direction 0\n:type n0: ``int``\n"
529 ":param n1: number of elements in direction 1\n:type n1: ``int``\n"
530 ":param l0: length of side 0 or coordinate range of side 0\n:type l0: ``float`` or ``tuple``\n"
531 ":param l1: length of side 1 or coordinate range of side 1\n:type l1: ``float`` or ``tuple``\n"
532 ":param d0: number of subdivisions in direction 0\n:type d0: ``int``\n"
533 ":param d1: number of subdivisions in direction 1\n:type d1: ``int``\n"
534 ":param multiplier: size of overlap\n:type multiplier: ``unsigned int``");
535
536 def("MultiBrick", ripley::_multibrick, (arg("n0"),arg("n1"),arg("n2"),arg("l0")=1.0,arg("l1")=1.0,arg("l2")=1.0,
537 arg("d0")=-1,arg("d1")=-1,arg("d2")=-1,arg("diracPoints")=list(),arg("diracTags")=list(), arg("escriptworld")=escript::SubWorld_ptr(), arg("multiplier")=1),
538 "Creates a hexagonal mesh with n0 x n1 x n2 elements over the brick [0,l0] x [0,l1] x [0,l2].\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 n2: number of elements in direction 2\n:type n2: ``int``\n"
542 ":param l0: length of side 0 or coordinate range of side 0\n:type l0: ``float`` or ``tuple``\n"
543 ":param l1: length of side 1 or coordinate range of side 1\n:type l1: ``float`` or ``tuple``\n"
544 ":param l2: length of side 2 or coordinate range of side 2\n:type l2: ``float`` or ``tuple``\n"
545 ":param d0: number of subdivisions in direction 0\n:type d0: ``int``\n"
546 ":param d1: number of subdivisions in direction 1\n:type d1: ``int``\n"
547 ":param d2: number of subdivisions in direction 2\n:type d2: ``int``"
548 ":param multiplier: size of overlap\n:type multiplier: ``unsigned int``");
549
550 def("readBinaryGrid", &ripley::readBinaryGrid, (arg("filename"),
551 arg("functionspace"), arg("shape"), arg("fill")=0.,
552 arg("byteOrder"), arg("dataType"), arg("first"),
553 arg("numValues"), arg("multiplier"), arg("reverse")),
554 "Reads a binary Grid");
555 #ifdef USE_BOOSTIO
556 def("_readBinaryGridFromZipped", &ripley::readBinaryGridFromZipped, (arg("filename"),
557 arg("functionspace"), arg("shape"), arg("fill")=0.,
558 arg("byteOrder"), arg("dataType"), arg("first"),
559 arg("numValues"), arg("multiplier"), arg("reverse")),
560 "Reads a binary Grid");
561 #endif
562 def("_readNcGrid", &ripley::readNcGrid, (arg("filename"), arg("varname"),
563 arg("functionspace"), arg("shape"), arg("fill"), arg("first"),
564 arg("numValues"), arg("multiplier"), arg("reverse")),
565 "Reads a grid from a netCDF file");
566
567 class_<ripley::RipleyDomain, bases<escript::AbstractContinuousDomain>, boost::noncopyable >
568 ("RipleyDomain", "", no_init)
569 .def("print_mesh_info", &ripley::RipleyDomain::Print_Mesh_Info, (arg("full")=false),
570 "Prints out a summary about the mesh.\n"
571 ":param full: whether to output additional data\n:type full: ``bool``")
572 .def("writeBinaryGrid", &ripley::RipleyDomain::writeBinaryGrid)
573
574 .def("dump", &ripley::RipleyDomain::dump, args("filename"),
575 "Dumps the mesh to a file with the given name.")
576 .def("getGridParameters", &ripley::RipleyDomain::getGridParameters,
577 "Returns the tuple (origin, spacing, elements) where the entries are tuples:\n"
578 "``origin``=the coordinates of the domain's global origin,\n"
579 "``spacing``=the element size (=node spacing) of the domain,\n"
580 "``elements``=the global number of elements in all dimensions\n\n"
581 ":rtype: ``tuple``")
582 .def("getDescription", &ripley::RipleyDomain::getDescription,
583 ":return: a description for this domain\n:rtype: ``string``")
584 .def("getDim", &ripley::RipleyDomain::getDim, ":rtype: ``int``")
585 .def("getDataShape", &ripley::RipleyDomain::getDataShape, args("functionSpaceCode"),
586 ":return: a pair (dps, ns) where dps=the number of data points per sample, and ns=the number of samples\n:rtype: ``tuple``")
587 .def("getNumDataPointsGlobal", &ripley::RipleyDomain::getNumDataPointsGlobal,
588 ":return: the number of data points summed across all MPI processes\n"
589 ":rtype: ``int``")
590 .def("addToSystem",&ripley::RipleyDomain::addToSystemFromPython,
591 args("mat", "rhs", "data"),
592 "adds a PDE to the system, results depend on domain\n\n"
593 ":param mat:\n:type mat: `OperatorAdapter`\n"
594 ":param rhs:\n:type rhs: `Data`\n"
595 ":param data:\ntype data: `list`")
596 .def("addToRHS",&ripley::RipleyDomain::addToRHSFromPython,
597 args("rhs", "data"),
598 "adds a PDE onto the stiffness matrix mat and a rhs, "
599 "results depends on domain\n\n"
600 ":param rhs:\n:type rhs: `Data`\n"
601 ":param data:\ntype data: `list`")
602 .def("createAssembler", &ripley::RipleyDomain::createAssemblerFromPython,
603 args("typename", "options"),
604 "request from the domain an assembler of the specified type, if "
605 "supported, using the supplied options (if provided)"
606 ":param typename:\n:type typename: `string`\n"
607 ":param options:\n:type options: `list`\n")
608 .def("addPDEToTransportProblem",&ripley::RipleyDomain::addPDEToTransportProblemFromPython,
609 args("tp", "source", "data"),
610 ":param tp:\n:type tp: `TransportProblemAdapter`\n"
611 ":param source:\n:type source: `Data`\n"
612 ":param data:\ntype data: `list`")
613 .def("newOperator",&ripley::RipleyDomain::newSystemMatrix,
614 args("row_blocksize", "row_functionspace", "column_blocksize", "column_functionspace", "type"),
615 "creates a SystemMatrixAdapter stiffness matrix and initializes it with zeros\n\n"
616 ":param row_blocksize:\n:type row_blocksize: ``int``\n"
617 ":param row_functionspace:\n:type row_functionspace: `FunctionSpace`\n"
618 ":param column_blocksize:\n:type column_blocksize: ``int``\n"
619 ":param column_functionspace:\n:type column_functionspace: `FunctionSpace`\n"
620 ":param type:\n:type type: ``int``"
621 )
622 .def("newTransportProblem",&ripley::RipleyDomain::newTransportProblem,
623 args("theta", "blocksize", "functionspace", "type"),
624 "creates a TransportProblemAdapter\n\n"
625 ":param theta:\n:type theta: ``float``\n"
626 ":param blocksize:\n:type blocksize: ``int``\n"
627 ":param functionspace:\n:type functionspace: `FunctionSpace`\n"
628 ":param type:\n:type type: ``int``"
629 )
630 .def("getSystemMatrixTypeId",&ripley::RipleyDomain::getSystemMatrixTypeId,
631 args("options"),
632 ":return: the identifier of the matrix type to be used for the global stiffness matrix when particular solver options are used.\n"
633 ":rtype: ``int``\n"
634 ":param options:\n:type options: `SolverBuddy`\n"
635 )
636 .def("getTransportTypeId",&ripley::RipleyDomain::getTransportTypeId,
637 args("solver", "preconditioner", "package", "symmetry"),
638 ":return: the identifier of the transport problem type to be used when a particular solver, preconditioner, package and symmetric matrix is used.\n"
639 ":rtype: ``int``\n"
640 ":param solver:\n:type solver: ``int``\n"
641 ":param preconditioner:\n:type preconditioner: ``int``\n"
642 ":param package:\n:type package: ``int``\n"
643 ":param symmetry:\n:type symmetry: ``int``"
644 )
645 .def("getX",&ripley::RipleyDomain::getX, ":return: locations in the FEM nodes\n\n"
646 ":rtype: `Data`")
647 .def("getNormal",&ripley::RipleyDomain::getNormal,
648 ":return: boundary normals at the quadrature point on the face elements\n"
649 ":rtype: `Data`")
650 .def("getSize",&ripley::RipleyDomain::getSize,":return: the element size\n"
651 ":rtype: `Data`")
652 .def("setTagMap",&ripley::RipleyDomain::setTagMap,args("name","tag"),
653 "Give a tag number a name.\n\n:param name: Name for the tag\n:type name: ``string``\n"
654 ":param tag: numeric id\n:type tag: ``int``\n:note: Tag names must be unique within a domain")
655 .def("getTag",&ripley::RipleyDomain::getTag,args("name"),":return: tag id for "
656 "``name``\n:rtype: ``string``")
657 .def("isValidTagName",&ripley::RipleyDomain::isValidTagName,args("name"),
658 ":return: True if ``name`` corresponds to a tag, otherwise False\n:rtype: ``bool``")
659 .def("showTagNames",&ripley::RipleyDomain::showTagNames,":return: A space separated list of tag names\n:rtype: ``string``")
660 .def("getMPISize",&ripley::RipleyDomain::getMPISize,":return: the number of processes used for this `Domain`\n:rtype: ``int``")
661 .def("getMPIRank",&ripley::RipleyDomain::getMPIRank,":return: the rank of this process\n:rtype: ``int``")
662 .def("MPIBarrier",&ripley::RipleyDomain::MPIBarrier,"Wait until all processes have reached this point")
663 .def("onMasterProcessor",&ripley::RipleyDomain::onMasterProcessor,":return: True if this code is executing on the master process\n:rtype: `bool`");
664 /* These two class exports are necessary to ensure that the extra methods added by ripley make it to python.
665 * This change became necessary when the Brick and Rectangle constructors turned into factories instead of classes */
666 class_<ripley::Brick, bases<ripley::RipleyDomain> >("RipleyBrick", "", no_init);
667 class_<ripley::Rectangle, bases<ripley::RipleyDomain> >("RipleyRectangle", "", no_init);
668 class_<ripley::MultiRectangle, bases<ripley::RipleyDomain> >("RipleyMultiRectangle", "", no_init);
669 class_<ripley::MultiBrick, bases<ripley::RipleyDomain> >("RipleyMultiBrick", "", no_init);
670 class_<ripley::AbstractAssembler, ripley::Assembler_ptr, boost::noncopyable >
671 ("AbstractAssembler", "", no_init);
672 }
673

  ViewVC Help
Powered by ViewVC 1.1.26