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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2607 - (show annotations)
Tue Aug 18 01:02:56 2009 UTC (11 years, 6 months ago) by jfenwick
File size: 16236 byte(s)
Added getMPIWorldSum function to the esys.escript module.
This function takes an integer from each member of the MPIWorld.
This will hopefully address mantis issue 359

Added unit tests for most of the c++ free functions in the module.



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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26