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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1561 - (show annotations)
Wed May 21 06:58:52 2008 UTC (11 years, 5 months ago) by ksteube
File size: 13440 byte(s)
Added python method printParallelThreadCounts() to tell how many MPI CPUs and OpenMP threads we are using (for testing hybrid runs)

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26