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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26