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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2061 - (hide annotations)
Wed Nov 19 03:40:21 2008 UTC (11 years 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 jgs 102
2 ksteube 1312 /*******************************************************
3 ksteube 1811 *
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 ksteube 1312
14 ksteube 1811
15 jgs 474 #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 jgs 480 #include "AbstractSystemMatrix.h"
23 gross 1364 #include "AbstractTransportProblem.h"
24 gross 797 #include "DataVector.h"
25 ksteube 1800 #include "paso/Paso_MPI.h"
26 jfenwick 1897 #include "EscriptParams.h"
27 jgs 474
28 jfenwick 1872
29 ksteube 1312 extern "C" {
30     #include "escript/blocktimer.h"
31     }
32    
33 robwdcock 682 #include "esysUtils/esysExceptionTranslator.h"
34 jgs 102
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 gross 285 #include <boost/python/numeric.hpp>
41 jfenwick 1872 #include <boost/smart_ptr.hpp>
42 gross 285
43 jgs 102 using namespace boost::python;
44    
45 jgs 121 /*! \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 cochrane 358 * - <a href=http://iservo.edu.au/esys/epydoc/index.html>Python module documentation (epydoc generated)</a>
56 jgs 122 *
57 jgs 121 */
58 jgs 102
59 jgs 121 /*! \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 jgs 102
79     BOOST_PYTHON_MODULE(escriptcpp)
80     {
81 jfenwick 2061 // params are: bool show_user_defined, bool show_py_signatures, bool show_cpp_signatures
82     docstring_options docopt(true, true, false);
83    
84    
85 gross 391 def("setNumberOfThreads",escript::setNumberOfThreads);
86     def("getNumberOfThreads",escript::getNumberOfThreads);
87 gross 797 def("releaseUnusedMemory",escript::releaseUnusedMemory);
88 ksteube 1312 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 ksteube 1247 def("getVersion",escript::getSvnVersion);
94 ksteube 1561 def("printParallelThreadCounts",escript::printParallelThreadCnt);
95 ksteube 1805 def("getMPISizeWorld",escript::getMPISizeWorld);
96     def("getMPIRankWorld",escript::getMPIRankWorld);
97 jgs 102
98 gross 797
99 jgs 102 //
100     // Interface for AbstractDomain
101     //
102 jfenwick 2061 class_<escript::AbstractDomain, escript::Domain_ptr>("Domain","Base class for all domains.",no_init)
103 gross 1044 .def("setTagMap",&escript::AbstractDomain::setTagMap)
104     .def("getTag",&escript::AbstractDomain::getTag)
105     .def("isValidTagName",&escript::AbstractDomain::isValidTagName)
106     .def("showTagNames",&escript::AbstractDomain::showTagNames)
107 jgs 102 .def("getX",&escript::AbstractDomain::getX)
108 jfenwick 1803 .def("getDim",&escript::AbstractDomain::getDim)
109 jgs 102 .def("getNormal",&escript::AbstractDomain::getNormal)
110     .def("getSize",&escript::AbstractDomain::getSize)
111 jgs 153 .def("saveVTK",&escript::AbstractDomain::saveVTK)
112     .def("saveDX",&escript::AbstractDomain::saveDX)
113 ksteube 1312 .def("getMPISize",&escript::AbstractDomain::getMPISize)
114     .def("getMPIRank",&escript::AbstractDomain::getMPIRank)
115 ksteube 1877 .def("MPIBarrier",&escript::AbstractDomain::MPIBarrier)
116     .def("onMasterProcessor",&escript::AbstractDomain::onMasterProcessor)
117 ksteube 1312
118 jgs 102 .def(self == self)
119     .def(self != self);
120    
121     //
122     // Interface for AbstractContinuousDomain
123     //
124 jfenwick 2061 class_<escript::AbstractContinuousDomain, bases<escript::AbstractDomain> >("ContinuousDomain","Class representing continuous domains",no_init)
125 gross 1859 .def("getSystemMatrixTypeId",&escript::AbstractContinuousDomain::getSystemMatrixTypeId)
126     .def("getTransportTypeId",&escript::AbstractContinuousDomain::getTransportTypeId);
127 jgs 102
128     //
129     // Interface for FunctionSpace
130     //
131 jfenwick 2061 class_<escript::FunctionSpace> fs_definer("FunctionSpace","",init<>()); // Doco goes in the empty string param
132 trankine 1426 fs_definer.def("getDim",&escript::FunctionSpace::getDim);
133 jfenwick 1872 // fs_definer.def("getDomain",&escript::FunctionSpace::getDomain,
134     // return_internal_reference<>());
135     fs_definer.def("getDomain",&escript::FunctionSpace::getDomainPython);
136 trankine 1426 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 gross 1718 fs_definer.def("getReferenceIDFromDataPointNo", &escript::FunctionSpace::getReferenceIDFromDataPointNo);
143 gross 1716 fs_definer.def("getListOfTags",&escript::FunctionSpace::getListOfTags);
144 phornby 1628 fs_definer.def("__str__", &escript::FunctionSpace::toString);
145 trankine 1426 fs_definer.def(self == self);
146     fs_definer.def(self != self);
147 jgs 102 //
148     // Interface for Data
149     //
150 jfenwick 2061 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 jgs 102 // 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 ksteube 1312 .def("__str__",&escript::Data::toString)
160 jfenwick 1872 // .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 jgs 102 .def("isEmpty",&escript::Data::isEmpty)
164 gross 783 .def("isProtected",&escript::Data::isProtected)
165     .def("setProtection",&escript::Data::setProtection)
166 jgs 102 .def("getShape",&escript::Data::getShapeTuple)
167     .def("getRank",&escript::Data::getDataPointRank)
168 gross 950 .def("dump",&escript::Data::dump)
169 jgs 102 .def("copyWithMask",&escript::Data::copyWithMask)
170     .def("setTaggedValue",&escript::Data::setTaggedValue)
171 gross 1044 .def("setTaggedValue",&escript::Data::setTaggedValueByName)
172 gross 921 .def("getNumberOfDataPoints",&escript::Data::getNumDataPoints)
173 gross 1141 .def("isExpanded",&escript::Data::isExpanded)
174     .def("isTagged",&escript::Data::isTagged)
175 jfenwick 2005 .def("isConstant",&escript::Data::isConstant)
176     .def("isLazy",&escript::Data::isLazy)
177     .def("isReady",&escript::Data::isReady)
178 jgs 119 .def("expand",&escript::Data::expand)
179     .def("tag",&escript::Data::tag)
180 jfenwick 2005 .def("resolve",&escript::Data::resolve)
181 jgs 126 .def("copy",&escript::Data::copy)
182 jfenwick 1799 .def("copy",&escript::Data::copySelf,return_value_policy<manage_new_object>())
183 jfenwick 2005 .def("delay",&escript::Data::delay)
184 gross 1034 .def("setValueOfDataPoint",&escript::Data::setValueOfDataPointToPyObject)
185     .def("setValueOfDataPoint",&escript::Data::setValueOfDataPointToArray)
186 gross 921 .def("setValueOfDataPoint",&escript::Data::setValueOfDataPoint)
187     .def("getValueOfDataPoint",&escript::Data::getValueOfDataPoint)
188     .def("getValueOfGlobalDataPoint",&escript::Data::getValueOfGlobalDataPoint)
189 gross 1118 .def("setToZero",&escript::Data::setToZero)
190 gross 285 .def("interpolate",&escript::Data::interpolate)
191 gross 921 .def("minGlobalDataPoint",&escript::Data::minGlobalDataPoint)
192 gross 285 .def("saveDX",&escript::Data::saveDX)
193     .def("saveVTK",&escript::Data::saveVTK)
194 jgs 149 .def("getTagNumber",&escript::Data::getTagNumber)
195 gross 285 // 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 gross 698 .def("_wherePositive",&escript::Data::wherePositive)
204     .def("_whereNegative",&escript::Data::whereNegative)
205     .def("_whereNonNegative",&escript::Data::whereNonNegative)
206     .def("_whereNonPositive",&escript::Data::whereNonPositive)
207 jgs 571 .def("_whereZero",&escript::Data::whereZero,(arg("tol")=0.0))
208     .def("_whereNonZero",&escript::Data::whereNonZero,(arg("tol")=0.0))
209 ksteube 876 .def("_erf",&escript::Data::erf)
210 gross 285 .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 ksteube 775 .def("_symmetric",&escript::Data::symmetric)
228     .def("_nonsymmetric",&escript::Data::nonsymmetric)
229 gross 800 .def("_trace",&escript::Data::trace)
230 gross 804 .def("_swap_axes",&escript::Data::swapaxes)
231 gross 576 .def("_eigenvalues",&escript::Data::eigenvalues)
232     .def("_eigenvalues_and_eigenvectors",&escript::Data::eigenvalues_and_eigenvectors,(arg("tol")=1.e-13))
233 gross 285 // 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 jgs 108 .def("__abs__",&escript::Data::abs)
241 jgs 102 // 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 gross 699 .def("__rpow__",&escript::Data::rpowO)
253 jgs 102 // 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 gross 285 .def(self += other<object>())
260     .def(self += self)
261    
262 jgs 102 .def(self - other<object>())
263     .def(other<object>() - self)
264     .def(self - self)
265 gross 285 .def(self -= other<object>())
266     .def(self -= self)
267    
268 jgs 102 .def(self * other<object>())
269     .def(other<object>() * self)
270     .def(self * self)
271 gross 285 .def(self *= other<object>())
272     .def(self *= self)
273    
274 jgs 102 .def(self / other<object>())
275     .def(other<object>() / self)
276     .def(self / self)
277 gross 285 .def(self /= other<object>())
278     .def(self /= self)
279 jgs 102 // 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 gross 1062 def("ReducedContinuousFunction",escript::reducedContinuousFunction);
288 jgs 102 def("Function",escript::function);
289 gross 1062 def("ReducedFunction",escript::reducedFunction);
290 jgs 102 def("FunctionOnBoundary",escript::functionOnBoundary);
291 gross 1062 def("ReducedFunctionOnBoundary",escript::reducedFunctionOnBoundary);
292 jgs 102 def("FunctionOnContactZero",escript::functionOnContactZero);
293 gross 1062 def("ReducedFunctionOnContactZero",escript::reducedFunctionOnContactZero);
294 jgs 102 def("FunctionOnContactOne",escript::functionOnContactOne);
295 gross 1062 def("ReducedFunctionOnContactOne",escript::reducedFunctionOnContactOne);
296 jgs 102 def("Solution",escript::solution);
297     def("ReducedSolution",escript::reducedSolution);
298     def("DiracDeltaFunction",escript::diracDeltaFunction);
299    
300     //
301     // Factory methods for Data
302     //
303 gross 950 def("load",escript::load);
304 gross 1023 def("loadIsConfigured",escript::loadConfigured);
305 jgs 102 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 ksteube 813 // 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 jgs 102 // Interface for AbstractSystemMatrix
337     //
338 jfenwick 2061 class_<escript::AbstractSystemMatrix>("Operator","",init<>()) // Doco goes in the empty string param
339 jgs 102 .def("isEmpty",&escript::AbstractSystemMatrix::isEmpty)
340     .def("solve",&escript::AbstractSystemMatrix::solve)
341     .def("of",&escript::AbstractSystemMatrix::vectorMultiply)
342     .def("saveMM",&escript::AbstractSystemMatrix::saveMM)
343 jgs 123 .def("saveHB",&escript::AbstractSystemMatrix::saveHB)
344 jgs 149 .def("resetValues",&escript::AbstractSystemMatrix::resetValues)
345 jgs 102 .def(self*other<escript::Data>());
346 gross 1364 //
347     // Interface for AbstractTransportProblem
348     //
349 jfenwick 2061 class_<escript::AbstractTransportProblem>("TransportProblem","",init<>()) // Doco goes in the empty string param
350 gross 1364 .def("isEmpty",&escript::AbstractTransportProblem::isEmpty)
351     .def("solve",&escript::AbstractTransportProblem::solve)
352 gross 1370 .def("setInitialValue",&escript::AbstractTransportProblem::setInitialValue)
353 gross 1417 .def("insertConstraint",&escript::AbstractTransportProblem::insertConstraint)
354     .def("reset",&escript::AbstractTransportProblem::resetTransport)
355 gross 1841 .def("resetValues",&escript::AbstractTransportProblem::resetTransport)
356 gross 1859 .def("getSafeTimeStepSize",&escript::AbstractTransportProblem::getSafeTimeStepSize)
357     .def("getUnlimitedTimeStepSize",&escript::AbstractTransportProblem::getUnlimitedTimeStepSize);
358 jgs 102
359 jfenwick 1897 // 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 jgs 102 //
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