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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2313 - (show annotations)
Tue Mar 17 03:41:17 2009 UTC (10 years, 7 months ago) by gross
File size: 15768 byte(s)
pyvisi is now rejecting to work under MPI with more than 1 processor. Tests for this configuration are dropped now.



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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26