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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26