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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1312 - (hide annotations)
Mon Sep 24 06:18:44 2007 UTC (12 years ago) by ksteube
File size: 12514 byte(s)
The MPI branch is hereby closed. All future work should be in trunk.

Previously in revision 1295 I merged the latest changes to trunk into trunk-mpi-branch.
In this revision I copied all files from trunk-mpi-branch over the corresponding
trunk files. I did not use 'svn merge', it was a copy.

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26