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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26