/[escript]/trunk/escript/src/escriptcpp.cpp
ViewVC logotype

Contents of /trunk/escript/src/escriptcpp.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1313 - (show annotations)
Tue Sep 25 01:44:26 2007 UTC (12 years, 1 month ago) by ksteube
File size: 12448 byte(s)
Copied a handful of files from trunk-mpi-branch into trunk

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

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.26