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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1805 - (hide annotations)
Wed Sep 24 23:39:00 2008 UTC (10 years, 11 months ago) by ksteube
File size: 13601 byte(s)
Added python-level methods getMPISizeWorld() and getMPIRankWorld() for MPI process info.
Test suite run_inputOutput.py runs on any number of cores now, hybrid may still be a problem.

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26