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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1137 - (hide annotations)
Thu May 10 08:11:31 2007 UTC (12 years, 4 months ago) by gross
File size: 12030 byte(s)
This version passes the tests on windows except for 

   * vtk
   * netCDF

The version needs to be tested on altix and linux
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 jgs 102
75 gross 797
76 jgs 102 //
77     // Interface for AbstractDomain
78     //
79     class_<escript::AbstractDomain>("Domain",no_init)
80 gross 1137 .def("__str__",&escript::AbstractDomain::str)
81 gross 1044 .def("setTagMap",&escript::AbstractDomain::setTagMap)
82     .def("getTag",&escript::AbstractDomain::getTag)
83     .def("isValidTagName",&escript::AbstractDomain::isValidTagName)
84     .def("showTagNames",&escript::AbstractDomain::showTagNames)
85 jgs 102 .def("getX",&escript::AbstractDomain::getX)
86     .def("getNormal",&escript::AbstractDomain::getNormal)
87     .def("getSize",&escript::AbstractDomain::getSize)
88 jgs 153 .def("saveVTK",&escript::AbstractDomain::saveVTK)
89     .def("saveDX",&escript::AbstractDomain::saveDX)
90 jgs 102 .def(self == self)
91     .def(self != self);
92    
93     //
94     // Interface for AbstractContinuousDomain
95     //
96     class_<escript::AbstractContinuousDomain, bases<escript::AbstractDomain> >("ContinuousDomain",no_init)
97     .def("getSystemMatrixTypeId",&escript::AbstractContinuousDomain::getSystemMatrixTypeId);
98    
99     //
100     // Interface for FunctionSpace
101     //
102     class_<escript::FunctionSpace>("FunctionSpace",init<>())
103     .def("getDim",&escript::FunctionSpace::getDim)
104 jgs 153 .def("getDomain",&escript::FunctionSpace::getDomain,return_internal_reference<>())
105 jgs 102 .def("getX",&escript::FunctionSpace::getX)
106     .def("getNormal",&escript::FunctionSpace::getNormal)
107     .def("getSize",&escript::FunctionSpace::getSize)
108 gross 767 .def("setTags",&escript::FunctionSpace::setTags)
109 jgs 149 .def("getTagFromDataPointNo",&escript::FunctionSpace::getTagFromDataPointNo)
110 gross 1137 .def("__str__",&escript::FunctionSpace::str)
111 jgs 102 .def(self == self)
112     .def(self != self);
113     //
114     // Interface for Data
115     //
116 jgs 149 class_<escript::Data>("Data","TEST DOCUMENTATION",init<>())
117 jgs 102 // various constructors for Data objects
118     .def(init<const numeric::array&, optional<const escript::FunctionSpace&, bool> >(args("value","what","expand")))
119     .def(init<const object&, optional<const escript::FunctionSpace&, bool> >(args("value","what","expand")))
120     .def(init<const double, const tuple&, optional<const escript::FunctionSpace&, bool> >(args("value","shape","what","expand")))
121     .def(init<const escript::Data&, const escript::FunctionSpace&>(args("value","what")))
122     .def(init<const escript::Data&>())
123     // Note for Lutz, Need to specify the call policy in order to return a
124     // reference. In this case return_internal_reference.
125 gross 1137 .def("__str__",&escript::Data::str)
126 jgs 102 .def("getDomain",&escript::Data::getDomain,return_internal_reference<>())
127     .def("getFunctionSpace",&escript::Data::getFunctionSpace,return_internal_reference<>())
128     .def("isEmpty",&escript::Data::isEmpty)
129 gross 783 .def("isProtected",&escript::Data::isProtected)
130     .def("setProtection",&escript::Data::setProtection)
131 jgs 102 .def("getShape",&escript::Data::getShapeTuple)
132     .def("getRank",&escript::Data::getDataPointRank)
133 gross 950 .def("dump",&escript::Data::dump)
134 jgs 102 .def("copyWithMask",&escript::Data::copyWithMask)
135     .def("setTaggedValue",&escript::Data::setTaggedValue)
136 gross 1044 .def("setTaggedValue",&escript::Data::setTaggedValueByName)
137 gross 921 .def("getNumberOfDataPoints",&escript::Data::getNumDataPoints)
138 jgs 119 .def("expand",&escript::Data::expand)
139     .def("tag",&escript::Data::tag)
140 jgs 126 .def("copy",&escript::Data::copy)
141 gross 1034 .def("setValueOfDataPoint",&escript::Data::setValueOfDataPointToPyObject)
142     .def("setValueOfDataPoint",&escript::Data::setValueOfDataPointToArray)
143 gross 921 .def("setValueOfDataPoint",&escript::Data::setValueOfDataPoint)
144     .def("getValueOfDataPoint",&escript::Data::getValueOfDataPoint)
145     .def("getValueOfGlobalDataPoint",&escript::Data::getValueOfGlobalDataPoint)
146 gross 1118 .def("setToZero",&escript::Data::setToZero)
147 gross 285 .def("interpolate",&escript::Data::interpolate)
148 gross 921 .def("minGlobalDataPoint",&escript::Data::minGlobalDataPoint)
149 gross 285 .def("saveDX",&escript::Data::saveDX)
150     .def("saveVTK",&escript::Data::saveVTK)
151 jgs 149 .def("getTagNumber",&escript::Data::getTagNumber)
152 jgs 119 .def("archiveData",&escript::Data::archiveData)
153     .def("extractData",&escript::Data::extractData)
154 gross 285 // Unary functions for Data
155     .def("_interpolate",&escript::Data::interpolate)
156     .def("_grad",&escript::Data::gradOn)
157     .def("_grad",&escript::Data::grad)
158     .def("_transpose",&escript::Data::transpose)
159     .def("_trace",&escript::Data::trace)
160     .def("_maxval",&escript::Data::maxval)
161     .def("_minval",&escript::Data::minval)
162 gross 698 .def("_wherePositive",&escript::Data::wherePositive)
163     .def("_whereNegative",&escript::Data::whereNegative)
164     .def("_whereNonNegative",&escript::Data::whereNonNegative)
165     .def("_whereNonPositive",&escript::Data::whereNonPositive)
166 jgs 571 .def("_whereZero",&escript::Data::whereZero,(arg("tol")=0.0))
167     .def("_whereNonZero",&escript::Data::whereNonZero,(arg("tol")=0.0))
168 ksteube 876 .def("_erf",&escript::Data::erf)
169 gross 285 .def("_sin",&escript::Data::sin)
170     .def("_cos",&escript::Data::cos)
171     .def("_tan",&escript::Data::tan)
172     .def("_asin",&escript::Data::asin)
173     .def("_acos",&escript::Data::acos)
174     .def("_atan",&escript::Data::atan)
175     .def("_sinh",&escript::Data::sinh)
176     .def("_cosh",&escript::Data::cosh)
177     .def("_tanh",&escript::Data::tanh)
178     .def("_asinh",&escript::Data::asinh)
179     .def("_acosh",&escript::Data::acosh)
180     .def("_atanh",&escript::Data::atanh)
181     .def("_exp",&escript::Data::exp)
182     .def("_sqrt",&escript::Data::sqrt)
183     .def("_log10",&escript::Data::log10)
184     .def("_log",&escript::Data::log)
185     .def("_sign",&escript::Data::sign)
186 ksteube 775 .def("_symmetric",&escript::Data::symmetric)
187     .def("_nonsymmetric",&escript::Data::nonsymmetric)
188 gross 800 .def("_trace",&escript::Data::trace)
189 gross 804 .def("_swap_axes",&escript::Data::swapaxes)
190 gross 576 .def("_eigenvalues",&escript::Data::eigenvalues)
191     .def("_eigenvalues_and_eigenvectors",&escript::Data::eigenvalues_and_eigenvectors,(arg("tol")=1.e-13))
192 gross 285 // functions returning a single real number:
193     .def("_Lsup",&escript::Data::Lsup)
194     .def("_sup",&escript::Data::sup)
195     .def("_inf",&escript::Data::inf)
196     .def("_integrate",&escript::Data::integrate)
197    
198     // following implements the python abs operator
199 jgs 108 .def("__abs__",&escript::Data::abs)
200 jgs 102 // following implements the python "-" negation operator
201     .def("__neg__",&escript::Data::neg)
202     // following implements the python "+" identity operator
203     .def("__pos__",&escript::Data::pos)
204     // following two functions implement the python [] operator
205     .def("__getitem__",&escript::Data::getItem)
206     .def("__setitem__",&escript::Data::setItemO)
207     .def("__setitem__",&escript::Data::setItemD)
208     // following two functions implement the python ** operator
209     .def("__pow__",&escript::Data::powO)
210     .def("__pow__",&escript::Data::powD)
211 gross 699 .def("__rpow__",&escript::Data::rpowO)
212 jgs 102 // NOTE:: The order of these declarations is important. Anything
213     // declared before the generic declaration isn't found so the generic
214     // version will be called.
215     .def(self + other<object>())
216     .def(other<object>() + self)
217     .def(self + self)
218 gross 285 .def(self += other<object>())
219     .def(self += self)
220    
221 jgs 102 .def(self - other<object>())
222     .def(other<object>() - self)
223     .def(self - self)
224 gross 285 .def(self -= other<object>())
225     .def(self -= self)
226    
227 jgs 102 .def(self * other<object>())
228     .def(other<object>() * self)
229     .def(self * self)
230 gross 285 .def(self *= other<object>())
231     .def(self *= self)
232    
233 jgs 102 .def(self / other<object>())
234     .def(other<object>() / self)
235     .def(self / self)
236 gross 285 .def(self /= other<object>())
237     .def(self /= self)
238 jgs 102 // Need scope resolution due to a bug either in the compiler or
239     // the boost code. This calls operator << for Data.
240     .def(self_ns::str(self));
241    
242     //
243     // Factory methods for function space
244     //
245     def("ContinuousFunction",escript::continuousFunction);
246 gross 1062 def("ReducedContinuousFunction",escript::reducedContinuousFunction);
247 jgs 102 def("Function",escript::function);
248 gross 1062 def("ReducedFunction",escript::reducedFunction);
249 jgs 102 def("FunctionOnBoundary",escript::functionOnBoundary);
250 gross 1062 def("ReducedFunctionOnBoundary",escript::reducedFunctionOnBoundary);
251 jgs 102 def("FunctionOnContactZero",escript::functionOnContactZero);
252 gross 1062 def("ReducedFunctionOnContactZero",escript::reducedFunctionOnContactZero);
253 jgs 102 def("FunctionOnContactOne",escript::functionOnContactOne);
254 gross 1062 def("ReducedFunctionOnContactOne",escript::reducedFunctionOnContactOne);
255 jgs 102 def("Solution",escript::solution);
256     def("ReducedSolution",escript::reducedSolution);
257     def("DiracDeltaFunction",escript::diracDeltaFunction);
258    
259     //
260     // Factory methods for Data
261     //
262 gross 950 def("load",escript::load);
263 gross 1023 def("loadIsConfigured",escript::loadConfigured);
264 jgs 102 def("Scalar",escript::Scalar,
265     (arg("value")=0.0,
266     arg("what")=escript::FunctionSpace(),
267     arg("expanded")=false));
268     def("Vector",escript::Vector,
269     (arg("value")=0.0,
270     arg("what")=escript::FunctionSpace(),
271     arg("expanded")=false));
272     def("Tensor",escript::Tensor,
273     (arg("value")=0.0,
274     arg("what")=escript::FunctionSpace(),
275     arg("expanded")=false));
276     def("Tensor3",escript::Tensor3,
277     (arg("value")=0.0,
278     arg("what")=escript::FunctionSpace(),
279     arg("expanded")=false));
280     def("Tensor4",escript::Tensor4,
281     (arg("value")=0.0,
282     arg("what")=escript::FunctionSpace(),
283     arg("expanded")=false));
284    
285     //
286 ksteube 813 // Binary operators
287     //
288     def("C_GeneralTensorProduct",escript::C_GeneralTensorProduct,
289     (arg("arg0")=escript::Data(),
290     arg("arg1")=escript::Data(),
291     arg("axis_offset")=0,
292     arg("transpose")=0));
293    
294     //
295 jgs 102 // Interface for AbstractSystemMatrix
296     //
297     class_<escript::AbstractSystemMatrix>("Operator",init<>())
298     .def("isEmpty",&escript::AbstractSystemMatrix::isEmpty)
299     .def("solve",&escript::AbstractSystemMatrix::solve)
300     .def("of",&escript::AbstractSystemMatrix::vectorMultiply)
301     .def("saveMM",&escript::AbstractSystemMatrix::saveMM)
302 jgs 123 .def("saveHB",&escript::AbstractSystemMatrix::saveHB)
303 jgs 149 .def("resetValues",&escript::AbstractSystemMatrix::resetValues)
304 jgs 102 .def(self*other<escript::Data>());
305    
306     //
307     // Register esysExceptionTranslator
308     //
309     register_exception_translator<esysUtils::EsysException>(&esysUtils::esysExceptionTranslator);
310    
311     }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26