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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1247 - (hide annotations)
Tue Aug 14 01:29:20 2007 UTC (12 years, 3 months ago) by ksteube
File size: 12170 byte(s)
New python method getVersion() which returns the Subversion revision
from which escript was compiled

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26