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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6001 - (show annotations)
Tue Mar 1 05:01:49 2016 UTC (3 years, 1 month ago) by caltinay
File size: 32574 byte(s)
Bye bye esysUtils.
Also removed first.h as escript/DataTypes.h is now required everywhere
and fulfills that role by including a boost python header first.

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 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 #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 #ifdef USE_BOOSTIO
88 escript::Data readBinaryGridFromZipped(std::string filename, escript::FunctionSpace fs,
89 const object& pyShape, double fill, int byteOrder, int dataType,
90 const object& pyFirst, const object& pyNum, const object& pyMultiplier,
91 const object& pyReverse)
92 {
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 }
112 #endif
113
114 escript::Data readNcGrid(std::string filename, std::string varname,
115 escript::FunctionSpace fs, const object& pyShape, double fill,
116 const object& pyFirst, const object& pyNum, const object& pyMultiplier,
117 const object& pyReverse)
118 {
119 int dim=fs.getDim();
120 ReaderParameters params;
121
122 params.first = extractPyArray<dim_t>(pyFirst, "first", dim);
123 params.numValues = extractPyArray<dim_t>(pyNum, "numValues", dim);
124 params.multiplier = extractPyArray<int>(pyMultiplier, "multiplier", dim);
125 params.reverse = extractPyArray<int>(pyReverse, "reverse", dim);
126 std::vector<int> shape(extractPyArray<int>(pyShape, "shape"));
127
128 const RipleyDomain* dom=dynamic_cast<const RipleyDomain*>(fs.getDomain().get());
129 if (!dom)
130 throw RipleyException("Function space must be on a ripley domain");
131
132 escript::Data res(fill, shape, fs, true);
133 dom->readNcGrid(res, filename, varname, params);
134 return res;
135 }
136
137 // These wrappers are required to make the shared pointers work through the
138 // Python wrapper
139
140 // The double for n? is just to keep python happy when people need to deal with
141 // truediv
142 escript::Domain_ptr _brick(double _n0, double _n1, double _n2, const object& l0,
143 const object& l1, const object& l2, int d0, int d1, int d2,
144 const object& objpoints, const object& objtags, escript::SubWorld_ptr world)
145 {
146 dim_t n0=static_cast<dim_t>(_n0), n1=static_cast<dim_t>(_n1), n2=static_cast<dim_t>(_n2);
147 double x0=0., x1=1., y0=0., y1=1., z0=0., z1=1.;
148 if (extract<tuple>(l0).check()) {
149 tuple x=extract<tuple>(l0);
150 if (len(x)==2) {
151 x0=extract<double>(x[0]);
152 x1=extract<double>(x[1]);
153 } else
154 throw RipleyException("Argument l0 must be a float or 2-tuple");
155 } else if (extract<double>(l0).check()) {
156 x1=extract<double>(l0);
157 } else
158 throw RipleyException("Argument l0 must be a float or 2-tuple");
159
160 if (extract<tuple>(l1).check()) {
161 tuple y=extract<tuple>(l1);
162 if (len(y)==2) {
163 y0=extract<double>(y[0]);
164 y1=extract<double>(y[1]);
165 } else
166 throw RipleyException("Argument l1 must be a float or 2-tuple");
167 } else if (extract<double>(l1).check()) {
168 y1=extract<double>(l1);
169 } else
170 throw RipleyException("Argument l1 must be a float or 2-tuple");
171
172 if (extract<tuple>(l2).check()) {
173 tuple z=extract<tuple>(l2);
174 if (len(z)==2) {
175 z0=extract<double>(z[0]);
176 z1=extract<double>(z[1]);
177 } else
178 throw RipleyException("Argument l2 must be a float or 2-tuple");
179 } else if (extract<double>(l2).check()) {
180 z1=extract<double>(l2);
181 } else
182 throw RipleyException("Argument l2 must be a float or 2-tuple");
183 boost::python::list pypoints=extract<boost::python::list>(objpoints);
184 boost::python::list pytags=extract<boost::python::list>(objtags);
185 int numpts=extract<int>(pypoints.attr("__len__")());
186 int numtags=extract<int>(pytags.attr("__len__")());
187 std::vector<double> points;
188 std::vector<int> tags;
189 tags.resize(numtags, -1);
190 for (int i=0;i<numpts;++i) {
191 tuple temp = extract<tuple>(pypoints[i]);
192 int l=extract<int>(temp.attr("__len__")());
193 if (l != 3)
194 throw RipleyException("Number of coordinates for each dirac point must match dimensions.");
195 for (int k=0;k<l;++k) {
196 points.push_back(extract<double>(temp[k]));
197 }
198 }
199 std::map<std::string, int> tagstonames;
200 int curmax=40;
201 // but which order to assign tags to names?????
202 for (int i=0;i<numtags;++i) {
203 extract<int> ex_int(pytags[i]);
204 extract<std::string> ex_str(pytags[i]);
205 if (ex_int.check()) {
206 tags[i]=ex_int();
207 if (tags[i]>= curmax) {
208 curmax=tags[i]+1;
209 }
210 } else if (ex_str.check()) {
211 std::string s=ex_str();
212 std::map<std::string, int>::iterator it=tagstonames.find(s);
213 if (it!=tagstonames.end()) {
214 // we have the tag already so look it up
215 tags[i]=it->second;
216 } else {
217 tagstonames[s]=curmax;
218 tags[i]=curmax;
219 curmax++;
220 }
221 } else {
222 throw RipleyException("Error - Unable to extract tag value.");
223 }
224 }
225 if (numtags != numpts)
226 throw RipleyException("Number of tags does not match number of points.");
227 return escript::Domain_ptr(new Brick(n0,n1,n2, x0,y0,z0, x1,y1,z1, d0,d1,d2,
228 points, tags, tagstonames, world));
229 }
230
231 escript::Domain_ptr _multibrick(double _n0, double _n1, double _n2, const object& l0,
232 const object& l1, const object& l2, int d0, int d1, int d2,
233 const object& objpoints, const object& objtags, escript::SubWorld_ptr world,
234 unsigned int multiplier)
235 {
236 dim_t n0=static_cast<dim_t>(_n0), n1=static_cast<dim_t>(_n1), n2=static_cast<dim_t>(_n2);
237 double x0=0., x1=1., y0=0., y1=1., z0=0., z1=1.;
238 if (extract<tuple>(l0).check()) {
239 tuple x=extract<tuple>(l0);
240 if (len(x)==2) {
241 x0=extract<double>(x[0]);
242 x1=extract<double>(x[1]);
243 } else
244 throw RipleyException("Argument l0 must be a float or 2-tuple");
245 } else if (extract<double>(l0).check()) {
246 x1=extract<double>(l0);
247 } else
248 throw RipleyException("Argument l0 must be a float or 2-tuple");
249
250 if (extract<tuple>(l1).check()) {
251 tuple y=extract<tuple>(l1);
252 if (len(y)==2) {
253 y0=extract<double>(y[0]);
254 y1=extract<double>(y[1]);
255 } else
256 throw RipleyException("Argument l1 must be a float or 2-tuple");
257 } else if (extract<double>(l1).check()) {
258 y1=extract<double>(l1);
259 } else
260 throw RipleyException("Argument l1 must be a float or 2-tuple");
261
262 if (extract<tuple>(l2).check()) {
263 tuple z=extract<tuple>(l2);
264 if (len(z)==2) {
265 z0=extract<double>(z[0]);
266 z1=extract<double>(z[1]);
267 } else
268 throw RipleyException("Argument l2 must be a float or 2-tuple");
269 } else if (extract<double>(l2).check()) {
270 z1=extract<double>(l2);
271 } else
272 throw RipleyException("Argument l2 must be a float or 2-tuple");
273 boost::python::list pypoints=extract<boost::python::list>(objpoints);
274 boost::python::list pytags=extract<boost::python::list>(objtags);
275 int numpts=extract<int>(pypoints.attr("__len__")());
276 int numtags=extract<int>(pytags.attr("__len__")());
277 std::vector<double> points;
278 std::vector<int> tags;
279 tags.resize(numtags, -1);
280 for (int i=0;i<numpts;++i) {
281 tuple temp = extract<tuple>(pypoints[i]);
282 int l=extract<int>(temp.attr("__len__")());
283 if (l != 3)
284 throw RipleyException("Number of coordinates for each dirac point must match dimensions.");
285 for (int k=0;k<l;++k) {
286 points.push_back(extract<double>(temp[k]));
287 }
288 }
289 std::map<std::string, int> tagstonames;
290 int curmax=40;
291 // but which order to assign tags to names?????
292 for (int i=0;i<numtags;++i) {
293 extract<int> ex_int(pytags[i]);
294 extract<std::string> ex_str(pytags[i]);
295 if (ex_int.check()) {
296 tags[i]=ex_int();
297 if (tags[i]>= curmax) {
298 curmax=tags[i]+1;
299 }
300 } else if (ex_str.check()) {
301 std::string s=ex_str();
302 std::map<std::string, int>::iterator it=tagstonames.find(s);
303 if (it!=tagstonames.end()) {
304 // we have the tag already so look it up
305 tags[i]=it->second;
306 } else {
307 tagstonames[s]=curmax;
308 tags[i]=curmax;
309 curmax++;
310 }
311 } else {
312 throw RipleyException("Error - Unable to extract tag value.");
313 }
314 }
315 if (numtags != numpts)
316 throw RipleyException("Number of tags does not match number of points.");
317 return escript::Domain_ptr(new MultiBrick(n0,n1,n2, x0,y0,z0, x1,y1,z1, d0,d1,d2,
318 points, tags, tagstonames, world,
319 multiplier));
320 }
321
322 escript::Domain_ptr _multirectangle(double _n0, double _n1, const object& l0,
323 const object& l1, int d0, int d1,
324 const object& objpoints, const object& objtags,
325 escript::SubWorld_ptr world,
326 unsigned int multiplier)
327 {
328 dim_t n0=static_cast<dim_t>(_n0), n1=static_cast<dim_t>(_n1);
329 double x0=0., x1=1., y0=0., y1=1.;
330 if (extract<tuple>(l0).check()) {
331 tuple x=extract<tuple>(l0);
332 if (len(x)==2) {
333 x0=extract<double>(x[0]);
334 x1=extract<double>(x[1]);
335 } else
336 throw RipleyException("Argument l0 must be a float or 2-tuple");
337 } else if (extract<double>(l0).check()) {
338 x1=extract<double>(l0);
339 } else
340 throw RipleyException("Argument l0 must be a float or 2-tuple");
341
342 if (extract<tuple>(l1).check()) {
343 tuple y=extract<tuple>(l1);
344 if (len(y)==2) {
345 y0=extract<double>(y[0]);
346 y1=extract<double>(y[1]);
347 } else
348 throw RipleyException("Argument l1 must be a float or 2-tuple");
349 } else if (extract<double>(l1).check()) {
350 y1=extract<double>(l1);
351 } else
352 throw RipleyException("Argument l1 must be a float or 2-tuple");
353 boost::python::list pypoints=extract<boost::python::list>(objpoints);
354 boost::python::list pytags=extract<boost::python::list>(objtags);
355 int numpts=extract<int>(pypoints.attr("__len__")());
356 int numtags=extract<int>(pytags.attr("__len__")());
357 std::vector<double> points;
358 std::vector<int> tags;
359 tags.resize(numtags, -1);
360 for (int i=0;i<numpts;++i) {
361 tuple temp = extract<tuple>(pypoints[i]);
362 int l=extract<int>(temp.attr("__len__")());
363 if (l != 2)
364 throw RipleyException("Number of coordinates for each dirac point must match dimensions.");
365 for (int k=0;k<l;++k) {
366 points.push_back(extract<double>(temp[k]));
367 }
368 }
369 std::map<std::string, int> tagstonames;
370 int curmax=40;
371 // but which order to assign tags to names?????
372 for (int i=0;i<numtags;++i) {
373 extract<int> ex_int(pytags[i]);
374 extract<std::string> ex_str(pytags[i]);
375 if (ex_int.check()) {
376 tags[i]=ex_int();
377 if (tags[i] >= curmax) {
378 curmax=tags[i]+1;
379 }
380 } else if (ex_str.check()) {
381 std::string s=ex_str();
382 std::map<std::string, int>::iterator it=tagstonames.find(s);
383 if (it!=tagstonames.end()) {
384 // we have the tag already so look it up
385 tags[i]=it->second;
386 } else {
387 tagstonames[s]=curmax;
388 tags[i]=curmax;
389 curmax++;
390 }
391 } else {
392 throw RipleyException("Error - Unable to extract tag value.");
393 }
394 }
395 if (numtags != numpts)
396 throw RipleyException("Number of tags does not match number of points.");
397 return escript::Domain_ptr(new MultiRectangle(n0,n1, x0,y0, x1,y1, d0,d1,
398 points, tags, tagstonames, world, multiplier));
399 }
400
401 escript::Domain_ptr _rectangle(double _n0, double _n1, const object& l0,
402 const object& l1, int d0, int d1,
403 const object& objpoints, const object& objtags,
404 escript::SubWorld_ptr world
405 )
406 {
407 dim_t n0=static_cast<dim_t>(_n0), n1=static_cast<dim_t>(_n1);
408 double x0=0., x1=1., y0=0., y1=1.;
409 if (extract<tuple>(l0).check()) {
410 tuple x=extract<tuple>(l0);
411 if (len(x)==2) {
412 x0=extract<double>(x[0]);
413 x1=extract<double>(x[1]);
414 } else
415 throw RipleyException("Argument l0 must be a float or 2-tuple");
416 } else if (extract<double>(l0).check()) {
417 x1=extract<double>(l0);
418 } else
419 throw RipleyException("Argument l0 must be a float or 2-tuple");
420
421 if (extract<tuple>(l1).check()) {
422 tuple y=extract<tuple>(l1);
423 if (len(y)==2) {
424 y0=extract<double>(y[0]);
425 y1=extract<double>(y[1]);
426 } else
427 throw RipleyException("Argument l1 must be a float or 2-tuple");
428 } else if (extract<double>(l1).check()) {
429 y1=extract<double>(l1);
430 } else
431 throw RipleyException("Argument l1 must be a float or 2-tuple");
432 boost::python::list pypoints=extract<boost::python::list>(objpoints);
433 boost::python::list pytags=extract<boost::python::list>(objtags);
434 int numpts=extract<int>(pypoints.attr("__len__")());
435 int numtags=extract<int>(pytags.attr("__len__")());
436 std::vector<double> points;
437 std::vector<int> tags;
438 tags.resize(numtags, -1);
439 for (int i=0;i<numpts;++i) {
440 tuple temp = extract<tuple>(pypoints[i]);
441 int l=extract<int>(temp.attr("__len__")());
442 if (l != 2)
443 throw RipleyException("Number of coordinates for each dirac point must match dimensions.");
444 for (int k=0;k<l;++k) {
445 points.push_back(extract<double>(temp[k]));
446 }
447 }
448 std::map<std::string, int> tagstonames;
449 int curmax=40;
450 // but which order to assign tags to names?????
451 for (int i=0;i<numtags;++i) {
452 extract<int> ex_int(pytags[i]);
453 extract<std::string> ex_str(pytags[i]);
454 if (ex_int.check()) {
455 tags[i]=ex_int();
456 if (tags[i] >= curmax) {
457 curmax=tags[i]+1;
458 }
459 } else if (ex_str.check()) {
460 std::string s=ex_str();
461 std::map<std::string, int>::iterator it=tagstonames.find(s);
462 if (it!=tagstonames.end()) {
463 // we have the tag already so look it up
464 tags[i]=it->second;
465 } else {
466 tagstonames[s]=curmax;
467 tags[i]=curmax;
468 curmax++;
469 }
470 } else {
471 throw RipleyException("Error - Unable to extract tag value.");
472 }
473 }
474 if (numtags != numpts)
475 throw RipleyException("Number of tags does not match number of points.");
476 return escript::Domain_ptr(new Rectangle(n0,n1, x0,y0, x1,y1, d0,d1,
477 points, tags, tagstonames, world));
478 }
479
480 } // end of namespace ripley
481
482
483 BOOST_PYTHON_MODULE(ripleycpp)
484 {
485 // This feature was added in boost v1.34
486 #if ((BOOST_VERSION/100)%1000 > 34) || (BOOST_VERSION/100000 >1)
487 // params are: bool show_user_defined, bool show_py_signatures, bool show_cpp_signatures
488 docstring_options docopt(true, true, false);
489 #endif
490
491 // register escript's default translators
492 REGISTER_ESCRIPT_EXCEPTION_TRANSLATORS;
493 register_exception_translator<ripley::RipleyException>(&escript::RuntimeErrorTranslator);
494
495 scope().attr("__doc__") = "To use this module, please import esys.ripley";
496 scope().attr("BYTEORDER_NATIVE") = (int)ripley::BYTEORDER_NATIVE;
497 scope().attr("BYTEORDER_LITTLE_ENDIAN") = (int)ripley::BYTEORDER_LITTLE_ENDIAN;
498 scope().attr("BYTEORDER_BIG_ENDIAN") = (int)ripley::BYTEORDER_BIG_ENDIAN;
499 scope().attr("DATATYPE_INT32") = (int)ripley::DATATYPE_INT32;
500 scope().attr("DATATYPE_FLOAT32") = (int)ripley::DATATYPE_FLOAT32;
501 scope().attr("DATATYPE_FLOAT64") = (int)ripley::DATATYPE_FLOAT64;
502
503 def("Brick", ripley::_brick, (arg("n0"),arg("n1"),arg("n2"),arg("l0")=1.0,
504 arg("l1")=1.0,arg("l2")=1.0,arg("d0")=-1,arg("d1")=-1,arg("d2")=-1,
505 arg("diracPoints")=list(),arg("diracTags")=list(),
506 arg("escriptworld")=escript::SubWorld_ptr()),
507 "Creates a hexagonal mesh with n0 x n1 x n2 elements over the brick [0,l0] x [0,l1] x [0,l2].\n\n"
508 ":param n0: number of elements in direction 0\n:type n0: ``int``\n"
509 ":param n1: number of elements in direction 1\n:type n1: ``int``\n"
510 ":param n2: number of elements in direction 2\n:type n2: ``int``\n"
511 ":param l0: length of side 0 or coordinate range of side 0\n:type l0: ``float`` or ``tuple``\n"
512 ":param l1: length of side 1 or coordinate range of side 1\n:type l1: ``float`` or ``tuple``\n"
513 ":param l2: length of side 2 or coordinate range of side 2\n:type l2: ``float`` or ``tuple``\n"
514 ":param d0: number of subdivisions in direction 0\n:type d0: ``int``\n"
515 ":param d1: number of subdivisions in direction 1\n:type d1: ``int``\n"
516 ":param d2: number of subdivisions in direction 2\n:type d2: ``int``");
517
518 def("Rectangle", ripley::_rectangle, (arg("n0"),arg("n1"),arg("l0")=1.0,
519 arg("l1")=1.0,arg("d0")=-1,arg("d1")=-1,arg("diracPoints")=list(),
520 arg("diracTags")=list(), arg("escriptworld")=escript::SubWorld_ptr()),
521 "Creates a rectangular mesh with n0 x n1 elements over the rectangle [0,l0] x [0,l1].\n\n"
522 ":param n0: number of elements in direction 0\n:type n0: ``int``\n"
523 ":param n1: number of elements in direction 1\n:type n1: ``int``\n"
524 ":param l0: length of side 0 or coordinate range of side 0\n:type l0: ``float`` or ``tuple``\n"
525 ":param l1: length of side 1 or coordinate range of side 1\n:type l1: ``float`` or ``tuple``\n"
526 ":param d0: number of subdivisions in direction 0\n:type d0: ``int``\n"
527 ":param d1: number of subdivisions in direction 1\n:type d1: ``int``");
528
529 def("MultiRectangle", ripley::_multirectangle, (arg("n0"),arg("n1"),
530 arg("l0")=1.0,arg("l1")=1.0,arg("d0")=-1,arg("d1")=-1,
531 arg("diracPoints")=list(),arg("diracTags")=list(),
532 arg("escriptworld")=escript::SubWorld_ptr(), arg("multiplier")=1),
533 "Creates a rectangular mesh with n0 x n1 parent elements over the "
534 "rectangle [0,l0] x [0,l1], each parent element is divided ``multiplier`` times.\n\n"
535 ":param n0: number of elements in direction 0\n:type n0: ``int``\n"
536 ":param n1: number of elements in direction 1\n:type n1: ``int``\n"
537 ":param l0: length of side 0 or coordinate range of side 0\n:type l0: ``float`` or ``tuple``\n"
538 ":param l1: length of side 1 or coordinate range of side 1\n:type l1: ``float`` or ``tuple``\n"
539 ":param d0: number of subdivisions in direction 0\n:type d0: ``int``\n"
540 ":param d1: number of subdivisions in direction 1\n:type d1: ``int``\n"
541 ":param multiplier: size of overlap\n:type multiplier: ``unsigned int``");
542
543 def("MultiBrick", ripley::_multibrick, (arg("n0"),arg("n1"),arg("n2"),
544 arg("l0")=1.0,arg("l1")=1.0,arg("l2")=1.0,arg("d0")=-1,arg("d1")=-1,
545 arg("d2")=-1,arg("diracPoints")=list(),arg("diracTags")=list(),
546 arg("escriptworld")=escript::SubWorld_ptr(), arg("multiplier")=1),
547 "Creates a hexagonal mesh with n0 x n1 x n2 parent elements over the "
548 "brick [0,l0] x [0,l1] x [0,l2], each parent element is divided ``multiplier`` times.\n\n"
549 ":param n0: number of elements in direction 0\n:type n0: ``int``\n"
550 ":param n1: number of elements in direction 1\n:type n1: ``int``\n"
551 ":param n2: number of elements in direction 2\n:type n2: ``int``\n"
552 ":param l0: length of side 0 or coordinate range of side 0\n:type l0: ``float`` or ``tuple``\n"
553 ":param l1: length of side 1 or coordinate range of side 1\n:type l1: ``float`` or ``tuple``\n"
554 ":param l2: length of side 2 or coordinate range of side 2\n:type l2: ``float`` or ``tuple``\n"
555 ":param d0: number of subdivisions in direction 0\n:type d0: ``int``\n"
556 ":param d1: number of subdivisions in direction 1\n:type d1: ``int``\n"
557 ":param d2: number of subdivisions in direction 2\n:type d2: ``int``"
558 ":param multiplier: size of overlap\n:type multiplier: ``unsigned int``");
559
560 def("readBinaryGrid", &ripley::readBinaryGrid, (arg("filename"),
561 arg("functionspace"), arg("shape"), arg("fill")=0.,
562 arg("byteOrder"), arg("dataType"), arg("first"),
563 arg("numValues"), arg("multiplier"), arg("reverse")),
564 "Reads a binary Grid");
565 #ifdef USE_BOOSTIO
566 def("_readBinaryGridFromZipped", &ripley::readBinaryGridFromZipped, (arg("filename"),
567 arg("functionspace"), arg("shape"), arg("fill")=0.,
568 arg("byteOrder"), arg("dataType"), arg("first"),
569 arg("numValues"), arg("multiplier"), arg("reverse")),
570 "Reads a binary Grid");
571 #endif
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