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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26