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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6141 - (show annotations)
Wed Apr 6 03:51:30 2016 UTC (2 years, 8 months ago) by caltinay
File size: 32623 byte(s)
more namespacing of defines.

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

  ViewVC Help
Powered by ViewVC 1.1.26