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