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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3781 - (show annotations)
Mon Jan 23 22:18:49 2012 UTC (7 years, 7 months ago) by caltinay
Original Path: branches/ripleygmg_from_3668/ripley/src/ripleycpp.cpp
File size: 12749 byte(s)
Since setX() is not supported the constructors now take location and extent.
Python wrapper allows construction the old way with l0,l1 or with
tuples (x0,x1),(y0,y1).

1
2 /*******************************************************
3 *
4 * Copyright (c) 2003-2012 by University of Queensland
5 * Earth Systems Science Computational Center (ESSCC)
6 * http://www.uq.edu.au/esscc
7 *
8 * Primary Business: Queensland, Australia
9 * Licensed under the Open Software License version 3.0
10 * http://www.opensource.org/licenses/osl-3.0.php
11 *
12 *******************************************************/
13
14 #include <ripley/Brick.h>
15 #include <ripley/Rectangle.h>
16 #include <esysUtils/esysExceptionTranslator.h>
17
18 #include <boost/python.hpp>
19 #include <boost/python/module.hpp>
20 #include <boost/python/def.hpp>
21 #include <boost/python/detail/defaults_gen.hpp>
22 #include <boost/version.hpp>
23
24 using namespace boost::python;
25
26 namespace ripley {
27
28 // These wrappers are required to make the shared pointers work through the
29 // Python wrapper
30
31 escript::Domain_ptr _brick(int n0, int n1, int n2, const object& l0,
32 const object& l1, const object& l2, int d0, int d1, int d2)
33 {
34 double x0=0., x1=1., y0=0., y1=1., z0=0., z1=1.;
35 if (extract<tuple>(l0).check()) {
36 tuple x=extract<tuple>(l0);
37 if (len(x)==2) {
38 x0=extract<double>(x[0]);
39 x1=extract<double>(x[1]);
40 } else
41 throw RipleyException("Argument l0 must be a float or 2-tuple");
42 } else if (extract<double>(l0).check()) {
43 x1=extract<double>(l0);
44 } else
45 throw RipleyException("Argument l0 must be a float or 2-tuple");
46
47 if (extract<tuple>(l1).check()) {
48 tuple y=extract<tuple>(l1);
49 if (len(y)==2) {
50 y0=extract<double>(y[0]);
51 y1=extract<double>(y[1]);
52 } else
53 throw RipleyException("Argument l1 must be a float or 2-tuple");
54 } else if (extract<double>(l1).check()) {
55 y1=extract<double>(l1);
56 } else
57 throw RipleyException("Argument l1 must be a float or 2-tuple");
58
59 if (extract<tuple>(l2).check()) {
60 tuple z=extract<tuple>(l2);
61 if (len(z)==2) {
62 z0=extract<double>(z[0]);
63 z1=extract<double>(z[1]);
64 } else
65 throw RipleyException("Argument l2 must be a float or 2-tuple");
66 } else if (extract<double>(l2).check()) {
67 z1=extract<double>(l2);
68 } else
69 throw RipleyException("Argument l2 must be a float or 2-tuple");
70
71 return escript::Domain_ptr(new Brick(n0, n1, n2, x0, y0, z0, x1, y1, z1, d0, d1, d2));
72 }
73
74 escript::Domain_ptr _rectangle(int n0, int n1, const object& l0,
75 const object& l1, int d0, int d1)
76 {
77 double x0=0., x1=1., y0=0., y1=1.;
78 if (extract<tuple>(l0).check()) {
79 tuple x=extract<tuple>(l0);
80 if (len(x)==2) {
81 x0=extract<double>(x[0]);
82 x1=extract<double>(x[1]);
83 } else
84 throw RipleyException("Argument l0 must be a float or 2-tuple");
85 } else if (extract<double>(l0).check()) {
86 x1=extract<double>(l0);
87 } else
88 throw RipleyException("Argument l0 must be a float or 2-tuple");
89
90 if (extract<tuple>(l1).check()) {
91 tuple y=extract<tuple>(l1);
92 if (len(y)==2) {
93 y0=extract<double>(y[0]);
94 y1=extract<double>(y[1]);
95 } else
96 throw RipleyException("Argument l1 must be a float or 2-tuple");
97 } else if (extract<double>(l1).check()) {
98 y1=extract<double>(l1);
99 } else
100 throw RipleyException("Argument l1 must be a float or 2-tuple");
101
102 return escript::Domain_ptr(new Rectangle(n0, n1, x0, y0, x1, y1, d0, d1));
103 }
104
105 }
106
107 /**
108 \page ripley Ripley
109 Ripley is the python module name that contains the interfaces
110 to the C++ wrapper to ripley.
111 */
112
113 BOOST_PYTHON_MODULE(ripleycpp)
114 {
115 // This feature was added in boost v1.34
116 #if ((BOOST_VERSION/100)%1000 > 34) || (BOOST_VERSION/100000 >1)
117 // params are: bool show_user_defined, bool show_py_signatures, bool show_cpp_signatures
118 docstring_options docopt(true, true, false);
119 #endif
120
121 register_exception_translator<ripley::RipleyException>(&(esysUtils::esysExceptionTranslator));
122
123 def("Brick", ripley::_brick, (arg("n0"),arg("n1"),arg("n2"),arg("l0")=1.0,arg("l1")=1.0,arg("l2")=1.0,arg("d0")=1,arg("d1")=1,arg("d2")=1),
124 "Creates a hexagonal mesh with n0 x n1 x n2 elements over the brick [0,l0] x [0,l1] x [0,l2].\n\n"
125 ":param n0: number of elements in direction 0\n:type n0: ``int``\n"
126 ":param n1: number of elements in direction 1\n:type n1: ``int``\n"
127 ":param n2: number of elements in direction 2\n:type n2: ``int``\n"
128 ":param l0: length of side 0 or coordinate range of side 0\n:type l0: ``float`` or ``tuple``\n"
129 ":param l1: length of side 1 or coordinate range of side 1\n:type l1: ``float`` or ``tuple``\n"
130 ":param l2: length of side 2 or coordinate range of side 2\n:type l2: ``float`` or ``tuple``\n"
131 ":param d0: number of subdivisions in direction 0\n:type d0: ``int``\n"
132 ":param d1: number of subdivisions in direction 1\n:type d1: ``int``\n"
133 ":param d2: number of subdivisions in direction 2\n:type d2: ``int``");
134
135 def("Rectangle", ripley::_rectangle, (arg("n0"),arg("n1"),arg("l0")=1.0,arg("l1")=1.0,arg("d0")=1,arg("d1")=1),
136 "Creates a rectangular mesh with n0 x n1 elements over the rectangle [0,l0] x [0,l1].\n\n"
137 ":param n0: number of elements in direction 0\n:type n0: ``int``\n"
138 ":param n1: number of elements in direction 1\n:type n1: ``int``\n"
139 ":param l0: length of side 0 or coordinate range of side 0\n:type l0: ``float`` or ``tuple``\n"
140 ":param l1: length of side 1 or coordinate range of side 1\n:type l1: ``float`` or ``tuple``\n"
141 ":param d0: number of subdivisions in direction 0\n:type d0: ``int``\n"
142 ":param d1: number of subdivisions in direction 1\n:type d1: ``int``");
143
144 def("LoadMesh", ripley::RipleyDomain::loadMesh, (arg("filename")),
145 "Loads a ripley domain from a dump file" ":rtype: `Domain`");
146
147 def("ReadMesh", ripley::RipleyDomain::readMesh, (arg("filename")),
148 "Reads a ripley domain from a file created by write().\n\n"
149 ":rtype: `RipleyDomain`\n:param filename:\n:type filename: ``string``\n");
150
151 class_<ripley::RipleyDomain, bases<escript::AbstractContinuousDomain> >
152 ("RipleyDomain", "", no_init)
153 .def("write", &ripley::RipleyDomain::write, args("filename"),
154 "Writes the current mesh to a file with the given name. It can subsequently be recovered using ReadMesh().")
155 .def("print_mesh_info", &ripley::RipleyDomain::Print_Mesh_Info, (arg("full")=false),
156 "Prints out a summary about the mesh.\n"
157 ":param full: whether to output additional data\n:type full: ``bool``")
158 .def("dump", &ripley::RipleyDomain::dump, args("filename"),
159 "Dumps the mesh to a file with the given name.")
160 .def("getDescription", &ripley::RipleyDomain::getDescription,
161 ":return: a description for this domain\n:rtype: ``string``")
162 .def("getDim", &ripley::RipleyDomain::getDim, ":rtype: ``int``")
163 .def("getDataShape", &ripley::RipleyDomain::getDataShape, args("functionSpaceCode"),
164 ":return: a pair (dps, ns) where dps=the number of data points per sample, and ns=the number of samples\n:rtype: ``tuple``")
165 .def("getNumDataPointsGlobal", &ripley::RipleyDomain::getNumDataPointsGlobal,
166 ":return: the number of data points summed across all MPI processes\n"
167 ":rtype: ``int``")
168 .def("addPDEToSystem",&ripley::RipleyDomain::addPDEToSystem,
169 args("mat", "rhs", "A", "B", "C", "D", "X", "Y", "d", "y", "d_contact", "y_contact"),
170 "adds a PDE onto the stiffness matrix mat and a rhs\n\n"
171 ":param mat:\n:type mat: `OperatorAdapter`\n:param rhs:\n:type rhs: `Data`\n"
172 ":param A:\n:type A: `Data`\n"
173 ":param B:\n:type B: `Data`\n"
174 ":param C:\n:type C: `Data`\n"
175 ":param D:\n:type D: `Data`\n"
176 ":param X:\n:type X: `Data`\n"
177 ":param Y:\n:type Y: `Data`\n"
178 ":param d:\n:type d: `Data`\n"
179 ":param d_contact:\n:type d_contact: `Data`\n"
180 ":param y_contact:\n:type y_contact: `Data`\n"
181 )
182 .def("addPDEToRHS",&ripley::RipleyDomain::addPDEToRHS,
183 args("rhs", "X", "Y", "y", "y_contact"),
184 "adds a PDE onto the stiffness matrix mat and a rhs\n\n"
185 ":param rhs:\n:type rhs: `Data`\n"
186 ":param X:\n:type X: `Data`\n"
187 ":param Y:\n:type Y: `Data`\n"
188 ":param y:\n:type y: `Data`\n"
189 ":param y_contact:\n:type y_contact: `Data`"
190 )
191 .def("addPDEToTransportProblem",&ripley::RipleyDomain::addPDEToTransportProblem,
192 args( "tp", "source", "M", "A", "B", "C", "D", "X", "Y", "d", "y", "d_contact", "y_contact"),
193 ":param tp:\n:type tp: `TransportProblemAdapter`\n"
194 ":param source:\n:type source: `Data`\n"
195 ":param M:\n:type M: `Data`\n"
196 ":param A:\n:type A: `Data`\n"
197 ":param B:\n:type B: `Data`\n"
198 ":param C:\n:type C: `Data`\n"
199 ":param D:\n:type D: `Data`\n"
200 ":param X:\n:type X: `Data`\n"
201 ":param Y:\n:type Y: `Data`\n"
202 ":param d:\n:type d: `Data`\n"
203 ":param y:\n:type y: `Data`\n"
204 ":param d_contact:\n:type d_contact: `Data`\n"
205 ":param y_contact:\n:type y_contact: `Data`\n"
206 )
207 .def("newOperator",&ripley::RipleyDomain::newSystemMatrix,
208 args("row_blocksize", "row_functionspace", "column_blocksize", "column_functionspace", "type"),
209 "creates a SystemMatrixAdapter stiffness matrix and initializes it with zeros\n\n"
210 ":param row_blocksize:\n:type row_blocksize: ``int``\n"
211 ":param row_functionspace:\n:type row_functionspace: `FunctionSpace`\n"
212 ":param column_blocksize:\n:type column_blocksize: ``int``\n"
213 ":param column_functionspace:\n:type column_functionspace: `FunctionSpace`\n"
214 ":param type:\n:type type: ``int``\n"
215 )
216 .def("newTransportProblem",&ripley::RipleyDomain::newTransportProblem,
217 args("theta", "blocksize", "functionspace", "type"),
218 "creates a TransportProblemAdapter\n\n"
219 ":param theta:\n:type theta: ``float``\n"
220 ":param blocksize:\n:type blocksize: ``int``\n"
221 ":param functionspace:\n:type functionspace: `FunctionSpace`\n"
222 ":param type:\n:type type: ``int``\n"
223 )
224 .def("getSystemMatrixTypeId",&ripley::RipleyDomain::getSystemMatrixTypeId,
225 args("solver", "preconditioner", "package", "symmetry"),
226 ":return: the identifier of the matrix type to be used for the global stiffness matrix when a particular solver, package, preconditioner, and symmetric matrix is used.\n"
227 ":rtype: ``int``\n"
228 ":param solver:\n:type solver: ``int``\n"
229 ":param preconditioner:\n:type preconditioner: ``int``\n"
230 ":param package:\n:type package: ``int``\n"
231 ":param symmetry:\n:type symmetry: ``int``\n"
232 )
233 .def("getTransportTypeId",&ripley::RipleyDomain::getTransportTypeId,
234 args("solver", "preconditioner", "package", "symmetry"),
235 ":return: the identifier of the transport problem type to be used when a particular solver, preconditioner, package and symmetric matrix is used.\n"
236 ":rtype: ``int``\n"
237 ":param solver:\n:type solver: ``int``\n"
238 ":param preconditioner:\n:type preconditioner: ``int``\n"
239 ":param package:\n:type package: ``int``\n"
240 ":param symmetry:\n:type symmetry: ``int``\n"
241 )
242 // .def("setX",&ripley::RipleyDomain::setNewX,
243 //args("arg"), "assigns new location to the domain\n\n:param arg:\n:type arg: `Data`")
244 .def("getX",&ripley::RipleyDomain::getX, ":return: locations in the FEM nodes\n\n"
245 ":rtype: `Data`")
246 .def("getNormal",&ripley::RipleyDomain::getNormal,
247 ":return: boundary normals at the quadrature point on the face elements\n"
248 ":rtype: `Data`")
249 .def("getSize",&ripley::RipleyDomain::getSize,":return: the element size\n"
250 ":rtype: `Data`")
251 .def("setTagMap",&ripley::RipleyDomain::setTagMap,args("name","tag"),
252 "Give a tag number a name.\n\n:param name: Name for the tag\n:type name: ``string``\n"
253 ":param tag: numeric id\n:type tag: ``int``\n:note: Tag names must be unique within a domain")
254 .def("getTag",&ripley::RipleyDomain::getTag,args("name"),":return: tag id for "
255 "``name``\n:rtype: ``string``")
256 .def("isValidTagName",&ripley::RipleyDomain::isValidTagName,args("name"),
257 ":return: True if ``name`` corresponds to a tag, otherwise False\n:rtype: ``bool``")
258 .def("showTagNames",&ripley::RipleyDomain::showTagNames,":return: A space separated list of tag names\n:rtype: ``string``")
259 .def("getMPISize",&ripley::RipleyDomain::getMPISize,":return: the number of processes used for this `Domain`\n:rtype: ``int``")
260 .def("getMPIRank",&ripley::RipleyDomain::getMPIRank,":return: the rank of this process\n:rtype: ``int``")
261 .def("MPIBarrier",&ripley::RipleyDomain::MPIBarrier,"Wait until all processes have reached this point")
262 .def("onMasterProcessor",&ripley::RipleyDomain::onMasterProcessor,":return: True if this code is executing on the master process\n:rtype: `bool`");
263
264 class_<ripley::Brick, bases<ripley::RipleyDomain> >("RipleyBrick", "", no_init);
265
266 class_<ripley::Rectangle, bases<ripley::RipleyDomain> >("RipleyRectangle", "", no_init);
267
268 }
269

  ViewVC Help
Powered by ViewVC 1.1.26