1 |
|
2 |
/******************************************************* |
3 |
* |
4 |
* Copyright (c) 2003-2008 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 |
|
15 |
#include "Data.h" |
16 |
#include "FunctionSpace.h" |
17 |
#include "FunctionSpaceFactory.h" |
18 |
#include "DataFactory.h" |
19 |
#include "AbstractContinuousDomain.h" |
20 |
#include "AbstractDomain.h" |
21 |
#include "Utils.h" |
22 |
#include "AbstractSystemMatrix.h" |
23 |
#include "AbstractTransportProblem.h" |
24 |
#include "DataVector.h" |
25 |
#include "paso/Paso_MPI.h" |
26 |
|
27 |
|
28 |
extern "C" { |
29 |
#include "escript/blocktimer.h" |
30 |
} |
31 |
|
32 |
#include "esysUtils/esysExceptionTranslator.h" |
33 |
|
34 |
#include <boost/python.hpp> |
35 |
#include <boost/python/module.hpp> |
36 |
#include <boost/python/def.hpp> |
37 |
#include <boost/python/object.hpp> |
38 |
#include <boost/python/tuple.hpp> |
39 |
#include <boost/python/numeric.hpp> |
40 |
#include <boost/smart_ptr.hpp> |
41 |
|
42 |
using namespace boost::python; |
43 |
|
44 |
/*! \mainpage Esys Documentation |
45 |
* |
46 |
* \version 1.0.0 |
47 |
* |
48 |
* - \ref escript |
49 |
* |
50 |
* - \ref esys_exception "Esys Exception" |
51 |
* |
52 |
* - \ref finley |
53 |
* |
54 |
* - <a href=http://iservo.edu.au/esys/epydoc/index.html>Python module documentation (epydoc generated)</a> |
55 |
* |
56 |
*/ |
57 |
|
58 |
/*! \page escript Escript |
59 |
* Escript is the python module that contains the interfaces |
60 |
* to the C++ side of escript. |
61 |
* |
62 |
* \version 1.0.0 |
63 |
* |
64 |
* \section class_desc Class Description: |
65 |
* Data |
66 |
* |
67 |
* \section class_limits Class Limitations: |
68 |
* None |
69 |
* |
70 |
* \section class_conds Class Conditions of Use: |
71 |
* None |
72 |
* |
73 |
* \section class_throws Throws: |
74 |
* None |
75 |
* |
76 |
*/ |
77 |
|
78 |
BOOST_PYTHON_MODULE(escriptcpp) |
79 |
{ |
80 |
def("setNumberOfThreads",escript::setNumberOfThreads); |
81 |
def("getNumberOfThreads",escript::getNumberOfThreads); |
82 |
def("releaseUnusedMemory",escript::releaseUnusedMemory); |
83 |
def("blocktimer_initialize",blocktimer_initialize); |
84 |
def("blocktimer_reportSortByName",blocktimer_reportSortByName); |
85 |
def("blocktimer_reportSortByTime",blocktimer_reportSortByTime); |
86 |
def("blocktimer_increment",blocktimer_increment); |
87 |
def("blocktimer_time",blocktimer_time); |
88 |
def("getVersion",escript::getSvnVersion); |
89 |
def("printParallelThreadCounts",escript::printParallelThreadCnt); |
90 |
def("getMPISizeWorld",escript::getMPISizeWorld); |
91 |
def("getMPIRankWorld",escript::getMPIRankWorld); |
92 |
|
93 |
|
94 |
// |
95 |
// Interface for AbstractDomain |
96 |
// |
97 |
class_<escript::AbstractDomain, escript::Domain_ptr>("Domain",no_init) |
98 |
.def("setTagMap",&escript::AbstractDomain::setTagMap) |
99 |
.def("getTag",&escript::AbstractDomain::getTag) |
100 |
.def("isValidTagName",&escript::AbstractDomain::isValidTagName) |
101 |
.def("showTagNames",&escript::AbstractDomain::showTagNames) |
102 |
.def("getX",&escript::AbstractDomain::getX) |
103 |
.def("getDim",&escript::AbstractDomain::getDim) |
104 |
.def("getNormal",&escript::AbstractDomain::getNormal) |
105 |
.def("getSize",&escript::AbstractDomain::getSize) |
106 |
.def("saveVTK",&escript::AbstractDomain::saveVTK) |
107 |
.def("saveDX",&escript::AbstractDomain::saveDX) |
108 |
.def("getMPISize",&escript::AbstractDomain::getMPISize) |
109 |
.def("getMPIRank",&escript::AbstractDomain::getMPIRank) |
110 |
|
111 |
.def(self == self) |
112 |
.def(self != self); |
113 |
|
114 |
// |
115 |
// Interface for AbstractContinuousDomain |
116 |
// |
117 |
class_<escript::AbstractContinuousDomain, bases<escript::AbstractDomain> >("ContinuousDomain",no_init) |
118 |
.def("getSystemMatrixTypeId",&escript::AbstractContinuousDomain::getSystemMatrixTypeId); |
119 |
|
120 |
// |
121 |
// Interface for FunctionSpace |
122 |
// |
123 |
class_<escript::FunctionSpace> fs_definer("FunctionSpace",init<>()); |
124 |
fs_definer.def("getDim",&escript::FunctionSpace::getDim); |
125 |
// fs_definer.def("getDomain",&escript::FunctionSpace::getDomain, |
126 |
// return_internal_reference<>()); |
127 |
fs_definer.def("getDomain",&escript::FunctionSpace::getDomainPython); |
128 |
fs_definer.def("getX",&escript::FunctionSpace::getX); |
129 |
fs_definer.def("getNormal",&escript::FunctionSpace::getNormal); |
130 |
fs_definer.def("getSize",&escript::FunctionSpace::getSize); |
131 |
fs_definer.def("setTags",&escript::FunctionSpace::setTags); |
132 |
fs_definer.def("getTagFromDataPointNo", |
133 |
&escript::FunctionSpace::getTagFromDataPointNo); |
134 |
fs_definer.def("getReferenceIDFromDataPointNo", &escript::FunctionSpace::getReferenceIDFromDataPointNo); |
135 |
fs_definer.def("getListOfTags",&escript::FunctionSpace::getListOfTags); |
136 |
fs_definer.def("__str__", &escript::FunctionSpace::toString); |
137 |
fs_definer.def(self == self); |
138 |
fs_definer.def(self != self); |
139 |
// |
140 |
// Interface for Data |
141 |
// |
142 |
class_<escript::Data>("Data","TEST DOCUMENTATION",init<>() ) |
143 |
// various constructors for Data objects |
144 |
.def(init<const numeric::array&, optional<const escript::FunctionSpace&, bool> >(args("value","what","expand"))) |
145 |
.def(init<const object&, optional<const escript::FunctionSpace&, bool> >(args("value","what","expand"))) |
146 |
.def(init<const double, const tuple&, optional<const escript::FunctionSpace&, bool> >(args("value","shape","what","expand"))) |
147 |
.def(init<const escript::Data&, const escript::FunctionSpace&>(args("value","what"))) |
148 |
.def(init<const escript::Data&>()) |
149 |
// Note for Lutz, Need to specify the call policy in order to return a |
150 |
// reference. In this case return_internal_reference. |
151 |
.def("__str__",&escript::Data::toString) |
152 |
// .def("getDomain",&escript::Data::getDomain,return_internal_reference<>()) |
153 |
.def("getDomain",&escript::Data::getDomainPython) |
154 |
.def("getFunctionSpace",&escript::Data::getFunctionSpace,return_value_policy<copy_const_reference>()) |
155 |
.def("isEmpty",&escript::Data::isEmpty) |
156 |
.def("isProtected",&escript::Data::isProtected) |
157 |
.def("setProtection",&escript::Data::setProtection) |
158 |
.def("getShape",&escript::Data::getShapeTuple) |
159 |
.def("getRank",&escript::Data::getDataPointRank) |
160 |
.def("dump",&escript::Data::dump) |
161 |
.def("copyWithMask",&escript::Data::copyWithMask) |
162 |
.def("setTaggedValue",&escript::Data::setTaggedValue) |
163 |
.def("setTaggedValue",&escript::Data::setTaggedValueByName) |
164 |
.def("getNumberOfDataPoints",&escript::Data::getNumDataPoints) |
165 |
.def("isExpanded",&escript::Data::isExpanded) |
166 |
.def("isTagged",&escript::Data::isTagged) |
167 |
.def("isConstant",&escript::Data::isConstant) |
168 |
.def("isLazy",&escript::Data::isLazy) |
169 |
.def("isReady",&escript::Data::isReady) |
170 |
.def("expand",&escript::Data::expand) |
171 |
.def("tag",&escript::Data::tag) |
172 |
.def("copy",&escript::Data::copy) |
173 |
.def("copy",&escript::Data::copySelf,return_value_policy<manage_new_object>()) |
174 |
.def("delay",&escript::Data::delay) |
175 |
.def("setValueOfDataPoint",&escript::Data::setValueOfDataPointToPyObject) |
176 |
.def("setValueOfDataPoint",&escript::Data::setValueOfDataPointToArray) |
177 |
.def("setValueOfDataPoint",&escript::Data::setValueOfDataPoint) |
178 |
.def("getValueOfDataPoint",&escript::Data::getValueOfDataPoint) |
179 |
.def("getValueOfGlobalDataPoint",&escript::Data::getValueOfGlobalDataPoint) |
180 |
.def("setToZero",&escript::Data::setToZero) |
181 |
.def("interpolate",&escript::Data::interpolate) |
182 |
.def("minGlobalDataPoint",&escript::Data::minGlobalDataPoint) |
183 |
.def("saveDX",&escript::Data::saveDX) |
184 |
.def("saveVTK",&escript::Data::saveVTK) |
185 |
.def("getTagNumber",&escript::Data::getTagNumber) |
186 |
// Unary functions for Data |
187 |
.def("_interpolate",&escript::Data::interpolate) |
188 |
.def("_grad",&escript::Data::gradOn) |
189 |
.def("_grad",&escript::Data::grad) |
190 |
.def("_transpose",&escript::Data::transpose) |
191 |
.def("_trace",&escript::Data::trace) |
192 |
.def("_maxval",&escript::Data::maxval) |
193 |
.def("_minval",&escript::Data::minval) |
194 |
.def("_wherePositive",&escript::Data::wherePositive) |
195 |
.def("_whereNegative",&escript::Data::whereNegative) |
196 |
.def("_whereNonNegative",&escript::Data::whereNonNegative) |
197 |
.def("_whereNonPositive",&escript::Data::whereNonPositive) |
198 |
.def("_whereZero",&escript::Data::whereZero,(arg("tol")=0.0)) |
199 |
.def("_whereNonZero",&escript::Data::whereNonZero,(arg("tol")=0.0)) |
200 |
.def("_erf",&escript::Data::erf) |
201 |
.def("_sin",&escript::Data::sin) |
202 |
.def("_cos",&escript::Data::cos) |
203 |
.def("_tan",&escript::Data::tan) |
204 |
.def("_asin",&escript::Data::asin) |
205 |
.def("_acos",&escript::Data::acos) |
206 |
.def("_atan",&escript::Data::atan) |
207 |
.def("_sinh",&escript::Data::sinh) |
208 |
.def("_cosh",&escript::Data::cosh) |
209 |
.def("_tanh",&escript::Data::tanh) |
210 |
.def("_asinh",&escript::Data::asinh) |
211 |
.def("_acosh",&escript::Data::acosh) |
212 |
.def("_atanh",&escript::Data::atanh) |
213 |
.def("_exp",&escript::Data::exp) |
214 |
.def("_sqrt",&escript::Data::sqrt) |
215 |
.def("_log10",&escript::Data::log10) |
216 |
.def("_log",&escript::Data::log) |
217 |
.def("_sign",&escript::Data::sign) |
218 |
.def("_symmetric",&escript::Data::symmetric) |
219 |
.def("_nonsymmetric",&escript::Data::nonsymmetric) |
220 |
.def("_trace",&escript::Data::trace) |
221 |
.def("_swap_axes",&escript::Data::swapaxes) |
222 |
.def("_eigenvalues",&escript::Data::eigenvalues) |
223 |
.def("_eigenvalues_and_eigenvectors",&escript::Data::eigenvalues_and_eigenvectors,(arg("tol")=1.e-13)) |
224 |
// functions returning a single real number: |
225 |
.def("_Lsup",&escript::Data::Lsup) |
226 |
.def("_sup",&escript::Data::sup) |
227 |
.def("_inf",&escript::Data::inf) |
228 |
.def("_integrate",&escript::Data::integrate) |
229 |
|
230 |
// following implements the python abs operator |
231 |
.def("__abs__",&escript::Data::abs) |
232 |
// following implements the python "-" negation operator |
233 |
.def("__neg__",&escript::Data::neg) |
234 |
// following implements the python "+" identity operator |
235 |
.def("__pos__",&escript::Data::pos) |
236 |
// following two functions implement the python [] operator |
237 |
.def("__getitem__",&escript::Data::getItem) |
238 |
.def("__setitem__",&escript::Data::setItemO) |
239 |
.def("__setitem__",&escript::Data::setItemD) |
240 |
// following two functions implement the python ** operator |
241 |
.def("__pow__",&escript::Data::powO) |
242 |
.def("__pow__",&escript::Data::powD) |
243 |
.def("__rpow__",&escript::Data::rpowO) |
244 |
// NOTE:: The order of these declarations is important. Anything |
245 |
// declared before the generic declaration isn't found so the generic |
246 |
// version will be called. |
247 |
.def(self + other<object>()) |
248 |
.def(other<object>() + self) |
249 |
.def(self + self) |
250 |
.def(self += other<object>()) |
251 |
.def(self += self) |
252 |
|
253 |
.def(self - other<object>()) |
254 |
.def(other<object>() - self) |
255 |
.def(self - self) |
256 |
.def(self -= other<object>()) |
257 |
.def(self -= self) |
258 |
|
259 |
.def(self * other<object>()) |
260 |
.def(other<object>() * self) |
261 |
.def(self * self) |
262 |
.def(self *= other<object>()) |
263 |
.def(self *= self) |
264 |
|
265 |
.def(self / other<object>()) |
266 |
.def(other<object>() / self) |
267 |
.def(self / self) |
268 |
.def(self /= other<object>()) |
269 |
.def(self /= self) |
270 |
// Need scope resolution due to a bug either in the compiler or |
271 |
// the boost code. This calls operator << for Data. |
272 |
.def(self_ns::str(self)); |
273 |
|
274 |
// |
275 |
// Factory methods for function space |
276 |
// |
277 |
def("ContinuousFunction",escript::continuousFunction); |
278 |
def("ReducedContinuousFunction",escript::reducedContinuousFunction); |
279 |
def("Function",escript::function); |
280 |
def("ReducedFunction",escript::reducedFunction); |
281 |
def("FunctionOnBoundary",escript::functionOnBoundary); |
282 |
def("ReducedFunctionOnBoundary",escript::reducedFunctionOnBoundary); |
283 |
def("FunctionOnContactZero",escript::functionOnContactZero); |
284 |
def("ReducedFunctionOnContactZero",escript::reducedFunctionOnContactZero); |
285 |
def("FunctionOnContactOne",escript::functionOnContactOne); |
286 |
def("ReducedFunctionOnContactOne",escript::reducedFunctionOnContactOne); |
287 |
def("Solution",escript::solution); |
288 |
def("ReducedSolution",escript::reducedSolution); |
289 |
def("DiracDeltaFunction",escript::diracDeltaFunction); |
290 |
|
291 |
// |
292 |
// Factory methods for Data |
293 |
// |
294 |
def("load",escript::load); |
295 |
def("loadIsConfigured",escript::loadConfigured); |
296 |
def("Scalar",escript::Scalar, |
297 |
(arg("value")=0.0, |
298 |
arg("what")=escript::FunctionSpace(), |
299 |
arg("expanded")=false)); |
300 |
def("Vector",escript::Vector, |
301 |
(arg("value")=0.0, |
302 |
arg("what")=escript::FunctionSpace(), |
303 |
arg("expanded")=false)); |
304 |
def("Tensor",escript::Tensor, |
305 |
(arg("value")=0.0, |
306 |
arg("what")=escript::FunctionSpace(), |
307 |
arg("expanded")=false)); |
308 |
def("Tensor3",escript::Tensor3, |
309 |
(arg("value")=0.0, |
310 |
arg("what")=escript::FunctionSpace(), |
311 |
arg("expanded")=false)); |
312 |
def("Tensor4",escript::Tensor4, |
313 |
(arg("value")=0.0, |
314 |
arg("what")=escript::FunctionSpace(), |
315 |
arg("expanded")=false)); |
316 |
|
317 |
// |
318 |
// Binary operators |
319 |
// |
320 |
def("C_GeneralTensorProduct",escript::C_GeneralTensorProduct, |
321 |
(arg("arg0")=escript::Data(), |
322 |
arg("arg1")=escript::Data(), |
323 |
arg("axis_offset")=0, |
324 |
arg("transpose")=0)); |
325 |
|
326 |
// |
327 |
// Interface for AbstractSystemMatrix |
328 |
// |
329 |
class_<escript::AbstractSystemMatrix>("Operator",init<>()) |
330 |
.def("isEmpty",&escript::AbstractSystemMatrix::isEmpty) |
331 |
.def("solve",&escript::AbstractSystemMatrix::solve) |
332 |
.def("of",&escript::AbstractSystemMatrix::vectorMultiply) |
333 |
.def("saveMM",&escript::AbstractSystemMatrix::saveMM) |
334 |
.def("saveHB",&escript::AbstractSystemMatrix::saveHB) |
335 |
.def("resetValues",&escript::AbstractSystemMatrix::resetValues) |
336 |
.def(self*other<escript::Data>()); |
337 |
// |
338 |
// Interface for AbstractTransportProblem |
339 |
// |
340 |
class_<escript::AbstractTransportProblem>("TransportProblem",init<>()) |
341 |
.def("isEmpty",&escript::AbstractTransportProblem::isEmpty) |
342 |
.def("solve",&escript::AbstractTransportProblem::solve) |
343 |
.def("setInitialValue",&escript::AbstractTransportProblem::setInitialValue) |
344 |
.def("insertConstraint",&escript::AbstractTransportProblem::insertConstraint) |
345 |
.def("reset",&escript::AbstractTransportProblem::resetTransport) |
346 |
.def("resetValues",&escript::AbstractTransportProblem::resetTransport) |
347 |
.def("getSafeTimeStepSize",&escript::AbstractTransportProblem::getSafeTimeStepSize); |
348 |
|
349 |
// |
350 |
// Register esysExceptionTranslator |
351 |
// |
352 |
register_exception_translator<esysUtils::EsysException>(&esysUtils::esysExceptionTranslator); |
353 |
|
354 |
} |