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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26