1 |
jgs |
102 |
//$Id$ |
2 |
elspeth |
615 |
/* |
3 |
|
|
************************************************************ |
4 |
|
|
* Copyright 2006 by ACcESS MNRF * |
5 |
|
|
* * |
6 |
|
|
* http://www.access.edu.au * |
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 |
|
|
************************************************************ |
12 |
|
|
*/ |
13 |
jgs |
102 |
|
14 |
jgs |
474 |
#include "Data.h" |
15 |
|
|
#include "FunctionSpace.h" |
16 |
|
|
#include "FunctionSpaceFactory.h" |
17 |
|
|
#include "DataFactory.h" |
18 |
|
|
#include "AbstractContinuousDomain.h" |
19 |
|
|
#include "AbstractDomain.h" |
20 |
|
|
#include "Utils.h" |
21 |
jgs |
480 |
#include "AbstractSystemMatrix.h" |
22 |
gross |
797 |
#include "DataVector.h" |
23 |
jgs |
474 |
|
24 |
robwdcock |
682 |
#include "esysUtils/esysExceptionTranslator.h" |
25 |
jgs |
102 |
|
26 |
|
|
#include <boost/python.hpp> |
27 |
|
|
#include <boost/python/module.hpp> |
28 |
|
|
#include <boost/python/def.hpp> |
29 |
|
|
#include <boost/python/object.hpp> |
30 |
|
|
#include <boost/python/tuple.hpp> |
31 |
gross |
285 |
#include <boost/python/numeric.hpp> |
32 |
|
|
|
33 |
jgs |
102 |
using namespace boost::python; |
34 |
|
|
|
35 |
jgs |
121 |
/*! \mainpage Esys Documentation |
36 |
|
|
* |
37 |
|
|
* \version 1.0.0 |
38 |
|
|
* |
39 |
|
|
* - \ref escript |
40 |
|
|
* |
41 |
|
|
* - \ref esys_exception "Esys Exception" |
42 |
|
|
* |
43 |
|
|
* - \ref finley |
44 |
|
|
* |
45 |
cochrane |
358 |
* - <a href=http://iservo.edu.au/esys/epydoc/index.html>Python module documentation (epydoc generated)</a> |
46 |
jgs |
122 |
* |
47 |
jgs |
121 |
*/ |
48 |
jgs |
102 |
|
49 |
jgs |
121 |
/*! \page escript Escript |
50 |
|
|
* Escript is the python module that contains the interfaces |
51 |
|
|
* to the C++ side of escript. |
52 |
|
|
* |
53 |
|
|
* \version 1.0.0 |
54 |
|
|
* |
55 |
|
|
* \section class_desc Class Description: |
56 |
|
|
* Data |
57 |
|
|
* |
58 |
|
|
* \section class_limits Class Limitations: |
59 |
|
|
* None |
60 |
|
|
* |
61 |
|
|
* \section class_conds Class Conditions of Use: |
62 |
|
|
* None |
63 |
|
|
* |
64 |
|
|
* \section class_throws Throws: |
65 |
|
|
* None |
66 |
|
|
* |
67 |
|
|
*/ |
68 |
jgs |
102 |
|
69 |
|
|
BOOST_PYTHON_MODULE(escriptcpp) |
70 |
|
|
{ |
71 |
gross |
391 |
def("setNumberOfThreads",escript::setNumberOfThreads); |
72 |
|
|
def("getNumberOfThreads",escript::getNumberOfThreads); |
73 |
gross |
797 |
def("releaseUnusedMemory",escript::releaseUnusedMemory); |
74 |
jgs |
102 |
|
75 |
gross |
797 |
|
76 |
jgs |
102 |
// |
77 |
|
|
// Interface for AbstractDomain |
78 |
|
|
// |
79 |
|
|
class_<escript::AbstractDomain>("Domain",no_init) |
80 |
|
|
.def("getX",&escript::AbstractDomain::getX) |
81 |
|
|
.def("getNormal",&escript::AbstractDomain::getNormal) |
82 |
|
|
.def("getSize",&escript::AbstractDomain::getSize) |
83 |
jgs |
153 |
.def("saveVTK",&escript::AbstractDomain::saveVTK) |
84 |
|
|
.def("saveDX",&escript::AbstractDomain::saveDX) |
85 |
jgs |
102 |
.def(self == self) |
86 |
|
|
.def(self != self); |
87 |
|
|
|
88 |
|
|
// |
89 |
|
|
// Interface for AbstractContinuousDomain |
90 |
|
|
// |
91 |
|
|
class_<escript::AbstractContinuousDomain, bases<escript::AbstractDomain> >("ContinuousDomain",no_init) |
92 |
|
|
.def("getSystemMatrixTypeId",&escript::AbstractContinuousDomain::getSystemMatrixTypeId); |
93 |
|
|
|
94 |
|
|
// |
95 |
|
|
// Interface for FunctionSpace |
96 |
|
|
// |
97 |
|
|
class_<escript::FunctionSpace>("FunctionSpace",init<>()) |
98 |
|
|
.def("getDim",&escript::FunctionSpace::getDim) |
99 |
jgs |
153 |
.def("getDomain",&escript::FunctionSpace::getDomain,return_internal_reference<>()) |
100 |
jgs |
102 |
.def("getX",&escript::FunctionSpace::getX) |
101 |
|
|
.def("getNormal",&escript::FunctionSpace::getNormal) |
102 |
|
|
.def("getSize",&escript::FunctionSpace::getSize) |
103 |
gross |
767 |
.def("setTags",&escript::FunctionSpace::setTags) |
104 |
jgs |
149 |
.def("getTagFromDataPointNo",&escript::FunctionSpace::getTagFromDataPointNo) |
105 |
jgs |
147 |
.def("__str__",&escript::FunctionSpace::toString) |
106 |
jgs |
102 |
.def(self == self) |
107 |
|
|
.def(self != self); |
108 |
|
|
// |
109 |
|
|
// Interface for Data |
110 |
|
|
// |
111 |
jgs |
149 |
class_<escript::Data>("Data","TEST DOCUMENTATION",init<>()) |
112 |
jgs |
102 |
// various constructors for Data objects |
113 |
|
|
.def(init<const numeric::array&, optional<const escript::FunctionSpace&, bool> >(args("value","what","expand"))) |
114 |
|
|
.def(init<const object&, optional<const escript::FunctionSpace&, bool> >(args("value","what","expand"))) |
115 |
|
|
.def(init<const double, const tuple&, optional<const escript::FunctionSpace&, bool> >(args("value","shape","what","expand"))) |
116 |
|
|
.def(init<const escript::Data&, const escript::FunctionSpace&>(args("value","what"))) |
117 |
|
|
.def(init<const escript::Data&>()) |
118 |
|
|
// Note for Lutz, Need to specify the call policy in order to return a |
119 |
|
|
// reference. In this case return_internal_reference. |
120 |
gross |
285 |
.def("__str__",&escript::Data::toString) |
121 |
jgs |
102 |
.def("getDomain",&escript::Data::getDomain,return_internal_reference<>()) |
122 |
|
|
.def("getFunctionSpace",&escript::Data::getFunctionSpace,return_internal_reference<>()) |
123 |
|
|
.def("isEmpty",&escript::Data::isEmpty) |
124 |
gross |
783 |
.def("isProtected",&escript::Data::isProtected) |
125 |
|
|
.def("setProtection",&escript::Data::setProtection) |
126 |
jgs |
102 |
.def("getShape",&escript::Data::getShapeTuple) |
127 |
|
|
.def("getRank",&escript::Data::getDataPointRank) |
128 |
|
|
.def("copyWithMask",&escript::Data::copyWithMask) |
129 |
|
|
.def("setTaggedValue",&escript::Data::setTaggedValue) |
130 |
jgs |
110 |
.def("setRefValue",&escript::Data::setRefValue) |
131 |
|
|
.def("getRefValue",&escript::Data::getRefValue) |
132 |
jgs |
119 |
.def("expand",&escript::Data::expand) |
133 |
|
|
.def("tag",&escript::Data::tag) |
134 |
jgs |
126 |
.def("copy",&escript::Data::copy) |
135 |
jgs |
117 |
.def("convertToNumArray",&escript::Data::convertToNumArray) |
136 |
jgs |
121 |
.def("convertToNumArrayFromSampleNo",&escript::Data::convertToNumArrayFromSampleNo) |
137 |
|
|
.def("convertToNumArrayFromDPNo",&escript::Data::convertToNumArrayFromDPNo) |
138 |
jgs |
126 |
.def("fillFromNumArray",&escript::Data::fillFromNumArray) |
139 |
gross |
285 |
.def("interpolate",&escript::Data::interpolate) |
140 |
|
|
.def("mindp",&escript::Data::mindp) |
141 |
|
|
.def("saveDX",&escript::Data::saveDX) |
142 |
|
|
.def("saveVTK",&escript::Data::saveVTK) |
143 |
jgs |
149 |
.def("getTagNumber",&escript::Data::getTagNumber) |
144 |
jgs |
119 |
.def("archiveData",&escript::Data::archiveData) |
145 |
|
|
.def("extractData",&escript::Data::extractData) |
146 |
gross |
285 |
// Unary functions for Data |
147 |
|
|
.def("_interpolate",&escript::Data::interpolate) |
148 |
|
|
.def("_grad",&escript::Data::gradOn) |
149 |
|
|
.def("_grad",&escript::Data::grad) |
150 |
|
|
.def("_transpose",&escript::Data::transpose) |
151 |
|
|
.def("_trace",&escript::Data::trace) |
152 |
|
|
.def("_maxval",&escript::Data::maxval) |
153 |
|
|
.def("_minval",&escript::Data::minval) |
154 |
gross |
698 |
.def("_wherePositive",&escript::Data::wherePositive) |
155 |
|
|
.def("_whereNegative",&escript::Data::whereNegative) |
156 |
|
|
.def("_whereNonNegative",&escript::Data::whereNonNegative) |
157 |
|
|
.def("_whereNonPositive",&escript::Data::whereNonPositive) |
158 |
jgs |
571 |
.def("_whereZero",&escript::Data::whereZero,(arg("tol")=0.0)) |
159 |
|
|
.def("_whereNonZero",&escript::Data::whereNonZero,(arg("tol")=0.0)) |
160 |
ksteube |
876 |
.def("_erf",&escript::Data::erf) |
161 |
gross |
285 |
.def("_sin",&escript::Data::sin) |
162 |
|
|
.def("_cos",&escript::Data::cos) |
163 |
|
|
.def("_tan",&escript::Data::tan) |
164 |
|
|
.def("_asin",&escript::Data::asin) |
165 |
|
|
.def("_acos",&escript::Data::acos) |
166 |
|
|
.def("_atan",&escript::Data::atan) |
167 |
|
|
.def("_sinh",&escript::Data::sinh) |
168 |
|
|
.def("_cosh",&escript::Data::cosh) |
169 |
|
|
.def("_tanh",&escript::Data::tanh) |
170 |
|
|
.def("_asinh",&escript::Data::asinh) |
171 |
|
|
.def("_acosh",&escript::Data::acosh) |
172 |
|
|
.def("_atanh",&escript::Data::atanh) |
173 |
|
|
.def("_exp",&escript::Data::exp) |
174 |
|
|
.def("_sqrt",&escript::Data::sqrt) |
175 |
|
|
.def("_log10",&escript::Data::log10) |
176 |
|
|
.def("_log",&escript::Data::log) |
177 |
|
|
.def("_sign",&escript::Data::sign) |
178 |
ksteube |
775 |
.def("_symmetric",&escript::Data::symmetric) |
179 |
|
|
.def("_nonsymmetric",&escript::Data::nonsymmetric) |
180 |
gross |
800 |
.def("_trace",&escript::Data::trace) |
181 |
gross |
804 |
.def("_swap_axes",&escript::Data::swapaxes) |
182 |
gross |
576 |
.def("_eigenvalues",&escript::Data::eigenvalues) |
183 |
|
|
.def("_eigenvalues_and_eigenvectors",&escript::Data::eigenvalues_and_eigenvectors,(arg("tol")=1.e-13)) |
184 |
gross |
285 |
// functions returning a single real number: |
185 |
|
|
.def("_Lsup",&escript::Data::Lsup) |
186 |
|
|
.def("_sup",&escript::Data::sup) |
187 |
|
|
.def("_inf",&escript::Data::inf) |
188 |
|
|
.def("_integrate",&escript::Data::integrate) |
189 |
|
|
|
190 |
|
|
// following implements the python abs operator |
191 |
jgs |
108 |
.def("__abs__",&escript::Data::abs) |
192 |
jgs |
102 |
// following implements the python "-" negation operator |
193 |
|
|
.def("__neg__",&escript::Data::neg) |
194 |
|
|
// following implements the python "+" identity operator |
195 |
|
|
.def("__pos__",&escript::Data::pos) |
196 |
|
|
// following two functions implement the python [] operator |
197 |
|
|
.def("__getitem__",&escript::Data::getItem) |
198 |
|
|
.def("__setitem__",&escript::Data::setItemO) |
199 |
|
|
.def("__setitem__",&escript::Data::setItemD) |
200 |
|
|
// following two functions implement the python ** operator |
201 |
|
|
.def("__pow__",&escript::Data::powO) |
202 |
|
|
.def("__pow__",&escript::Data::powD) |
203 |
gross |
699 |
.def("__rpow__",&escript::Data::rpowO) |
204 |
jgs |
102 |
// NOTE:: The order of these declarations is important. Anything |
205 |
|
|
// declared before the generic declaration isn't found so the generic |
206 |
|
|
// version will be called. |
207 |
|
|
.def(self + other<object>()) |
208 |
|
|
.def(other<object>() + self) |
209 |
|
|
.def(self + self) |
210 |
gross |
285 |
.def(self += other<object>()) |
211 |
|
|
.def(self += self) |
212 |
|
|
|
213 |
jgs |
102 |
.def(self - other<object>()) |
214 |
|
|
.def(other<object>() - self) |
215 |
|
|
.def(self - self) |
216 |
gross |
285 |
.def(self -= other<object>()) |
217 |
|
|
.def(self -= self) |
218 |
|
|
|
219 |
jgs |
102 |
.def(self * other<object>()) |
220 |
|
|
.def(other<object>() * self) |
221 |
|
|
.def(self * self) |
222 |
gross |
285 |
.def(self *= other<object>()) |
223 |
|
|
.def(self *= self) |
224 |
|
|
|
225 |
jgs |
102 |
.def(self / other<object>()) |
226 |
|
|
.def(other<object>() / self) |
227 |
|
|
.def(self / self) |
228 |
gross |
285 |
.def(self /= other<object>()) |
229 |
|
|
.def(self /= self) |
230 |
jgs |
102 |
// Need scope resolution due to a bug either in the compiler or |
231 |
|
|
// the boost code. This calls operator << for Data. |
232 |
|
|
.def(self_ns::str(self)); |
233 |
|
|
|
234 |
|
|
// |
235 |
|
|
// Factory methods for function space |
236 |
|
|
// |
237 |
|
|
def("ContinuousFunction",escript::continuousFunction); |
238 |
|
|
def("Function",escript::function); |
239 |
|
|
def("FunctionOnBoundary",escript::functionOnBoundary); |
240 |
|
|
def("FunctionOnContactZero",escript::functionOnContactZero); |
241 |
|
|
def("FunctionOnContactOne",escript::functionOnContactOne); |
242 |
|
|
def("Solution",escript::solution); |
243 |
|
|
def("ReducedSolution",escript::reducedSolution); |
244 |
|
|
def("DiracDeltaFunction",escript::diracDeltaFunction); |
245 |
|
|
|
246 |
|
|
// |
247 |
|
|
// Factory methods for Data |
248 |
|
|
// |
249 |
|
|
def("Scalar",escript::Scalar, |
250 |
|
|
(arg("value")=0.0, |
251 |
|
|
arg("what")=escript::FunctionSpace(), |
252 |
|
|
arg("expanded")=false)); |
253 |
|
|
def("Vector",escript::Vector, |
254 |
|
|
(arg("value")=0.0, |
255 |
|
|
arg("what")=escript::FunctionSpace(), |
256 |
|
|
arg("expanded")=false)); |
257 |
|
|
def("Tensor",escript::Tensor, |
258 |
|
|
(arg("value")=0.0, |
259 |
|
|
arg("what")=escript::FunctionSpace(), |
260 |
|
|
arg("expanded")=false)); |
261 |
|
|
def("Tensor3",escript::Tensor3, |
262 |
|
|
(arg("value")=0.0, |
263 |
|
|
arg("what")=escript::FunctionSpace(), |
264 |
|
|
arg("expanded")=false)); |
265 |
|
|
def("Tensor4",escript::Tensor4, |
266 |
|
|
(arg("value")=0.0, |
267 |
|
|
arg("what")=escript::FunctionSpace(), |
268 |
|
|
arg("expanded")=false)); |
269 |
|
|
|
270 |
|
|
// |
271 |
ksteube |
813 |
// Binary operators |
272 |
|
|
// |
273 |
|
|
def("C_GeneralTensorProduct",escript::C_GeneralTensorProduct, |
274 |
|
|
(arg("arg0")=escript::Data(), |
275 |
|
|
arg("arg1")=escript::Data(), |
276 |
|
|
arg("axis_offset")=0, |
277 |
|
|
arg("transpose")=0)); |
278 |
|
|
|
279 |
|
|
// |
280 |
jgs |
102 |
// Interface for AbstractSystemMatrix |
281 |
|
|
// |
282 |
|
|
class_<escript::AbstractSystemMatrix>("Operator",init<>()) |
283 |
|
|
.def("isEmpty",&escript::AbstractSystemMatrix::isEmpty) |
284 |
|
|
.def("solve",&escript::AbstractSystemMatrix::solve) |
285 |
|
|
.def("of",&escript::AbstractSystemMatrix::vectorMultiply) |
286 |
|
|
.def("saveMM",&escript::AbstractSystemMatrix::saveMM) |
287 |
jgs |
123 |
.def("saveHB",&escript::AbstractSystemMatrix::saveHB) |
288 |
jgs |
149 |
.def("resetValues",&escript::AbstractSystemMatrix::resetValues) |
289 |
jgs |
102 |
.def(self*other<escript::Data>()); |
290 |
|
|
|
291 |
|
|
// |
292 |
|
|
// Register esysExceptionTranslator |
293 |
|
|
// |
294 |
|
|
register_exception_translator<esysUtils::EsysException>(&esysUtils::esysExceptionTranslator); |
295 |
|
|
|
296 |
|
|
} |