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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 595 - (show annotations)
Tue Mar 14 23:52:45 2006 UTC (13 years, 7 months ago) by gross
File size: 10922 byte(s)
test_utilOnFinley fixed (did run the tests that still fail)
1 //$Id$
2 /*=============================================================================
3
4 ******************************************************************************
5 * *
6 * COPYRIGHT ACcESS 2004 - All Rights Reserved *
7 * *
8 * This software is the property of ACcESS. No part of this code *
9 * may be copied in any form or by any means without the expressed written *
10 * consent of ACcESS. Copying, use or modification of this software *
11 * by any unauthorised person is illegal unless that *
12 * person has a software license agreement with ACcESS. *
13 * *
14 ******************************************************************************
15
16 ******************************************************************************/
17
18 #include "Data.h"
19 #include "DataVariable.h"
20 #include "FunctionSpace.h"
21 #include "FunctionSpaceFactory.h"
22 #include "DataFactory.h"
23 #include "AbstractContinuousDomain.h"
24 #include "AbstractDomain.h"
25 #include "Utils.h"
26 #include "AbstractSystemMatrix.h"
27
28 #include "esysExceptionTranslator.h"
29
30 #include <boost/python.hpp>
31 #include <boost/python/module.hpp>
32 #include <boost/python/def.hpp>
33 #include <boost/python/object.hpp>
34 #include <boost/python/tuple.hpp>
35 #include <boost/python/numeric.hpp>
36
37 using namespace boost::python;
38
39 /*! \mainpage Esys Documentation
40 *
41 * \version 1.0.0
42 *
43 * - \ref escript
44 *
45 * - \ref esys_exception "Esys Exception"
46 *
47 * - \ref finley
48 *
49 * - <a href=http://iservo.edu.au/esys/epydoc/index.html>Python module documentation (epydoc generated)</a>
50 *
51 */
52
53 /*! \page escript Escript
54 * Escript is the python module that contains the interfaces
55 * to the C++ side of escript.
56 *
57 * \version 1.0.0
58 *
59 * \section class_desc Class Description:
60 * Data
61 *
62 * \section class_limits Class Limitations:
63 * None
64 *
65 * \section class_conds Class Conditions of Use:
66 * None
67 *
68 * \section class_throws Throws:
69 * None
70 *
71 */
72
73 BOOST_PYTHON_MODULE(escriptcpp)
74 {
75 def("setNumberOfThreads",escript::setNumberOfThreads);
76 def("getNumberOfThreads",escript::getNumberOfThreads);
77
78 //
79 // Interface for AbstractDomain
80 //
81 class_<escript::AbstractDomain>("Domain",no_init)
82 .def("getX",&escript::AbstractDomain::getX)
83 .def("getNormal",&escript::AbstractDomain::getNormal)
84 .def("getSize",&escript::AbstractDomain::getSize)
85 .def("saveVTK",&escript::AbstractDomain::saveVTK)
86 .def("saveDX",&escript::AbstractDomain::saveDX)
87 .def(self == self)
88 .def(self != self);
89
90 //
91 // Interface for AbstractContinuousDomain
92 //
93 class_<escript::AbstractContinuousDomain, bases<escript::AbstractDomain> >("ContinuousDomain",no_init)
94 .def("getSystemMatrixTypeId",&escript::AbstractContinuousDomain::getSystemMatrixTypeId);
95
96 //
97 // Interface for FunctionSpace
98 //
99 class_<escript::FunctionSpace>("FunctionSpace",init<>())
100 .def("getDim",&escript::FunctionSpace::getDim)
101 .def("getDomain",&escript::FunctionSpace::getDomain,return_internal_reference<>())
102 .def("getX",&escript::FunctionSpace::getX)
103 .def("getNormal",&escript::FunctionSpace::getNormal)
104 .def("getSize",&escript::FunctionSpace::getSize)
105 .def("getTagFromDataPointNo",&escript::FunctionSpace::getTagFromDataPointNo)
106 .def("__str__",&escript::FunctionSpace::toString)
107 .def(self == self)
108 .def(self != self);
109 //
110 // Interface for Data
111 //
112 class_<escript::Data>("Data","TEST DOCUMENTATION",init<>())
113 // various constructors for Data objects
114 .def(init<const numeric::array&, optional<const escript::FunctionSpace&, bool> >(args("value","what","expand")))
115 .def(init<const object&, optional<const escript::FunctionSpace&, bool> >(args("value","what","expand")))
116 .def(init<const double, const tuple&, optional<const escript::FunctionSpace&, bool> >(args("value","shape","what","expand")))
117 .def(init<const escript::Data&, const escript::FunctionSpace&>(args("value","what")))
118 .def(init<const escript::Data&>())
119 // Note for Lutz, Need to specify the call policy in order to return a
120 // reference. In this case return_internal_reference.
121 .def("__str__",&escript::Data::toString)
122 .def("getDomain",&escript::Data::getDomain,return_internal_reference<>())
123 .def("getFunctionSpace",&escript::Data::getFunctionSpace,return_internal_reference<>())
124 .def("isEmpty",&escript::Data::isEmpty)
125 .def("getShape",&escript::Data::getShapeTuple)
126 .def("getRank",&escript::Data::getDataPointRank)
127 .def("copyWithMask",&escript::Data::copyWithMask)
128 .def("setTaggedValue",&escript::Data::setTaggedValue)
129 .def("setRefValue",&escript::Data::setRefValue)
130 .def("getRefValue",&escript::Data::getRefValue)
131 .def("expand",&escript::Data::expand)
132 .def("tag",&escript::Data::tag)
133 .def("copy",&escript::Data::copy)
134 .def("convertToNumArray",&escript::Data::convertToNumArray)
135 .def("convertToNumArrayFromSampleNo",&escript::Data::convertToNumArrayFromSampleNo)
136 .def("convertToNumArrayFromDPNo",&escript::Data::convertToNumArrayFromDPNo)
137 .def("fillFromNumArray",&escript::Data::fillFromNumArray)
138 .def("interpolate",&escript::Data::interpolate)
139 .def("mindp",&escript::Data::mindp)
140 .def("saveDX",&escript::Data::saveDX)
141 .def("saveVTK",&escript::Data::saveVTK)
142 .def("getTagNumber",&escript::Data::getTagNumber)
143 .def("archiveData",&escript::Data::archiveData)
144 .def("extractData",&escript::Data::extractData)
145 // Unary functions for Data
146 .def("_interpolate",&escript::Data::interpolate)
147 .def("_grad",&escript::Data::gradOn)
148 .def("_grad",&escript::Data::grad)
149 .def("_transpose",&escript::Data::transpose)
150 .def("_trace",&escript::Data::trace)
151 .def("_maxval",&escript::Data::maxval)
152 .def("_minval",&escript::Data::minval)
153 .def("_wherePositive",&escript::Data::wherePositive,(arg("tol")=0.0))
154 .def("_whereNegative",&escript::Data::whereNegative,(arg("tol")=0.0))
155 .def("_whereNonNegative",&escript::Data::whereNonNegative,(arg("tol")=0.0))
156 .def("_whereNonPositive",&escript::Data::whereNonPositive,(arg("tol")=0.0))
157 .def("_whereZero",&escript::Data::whereZero,(arg("tol")=0.0))
158 .def("_whereNonZero",&escript::Data::whereNonZero,(arg("tol")=0.0))
159 .def("_sin",&escript::Data::sin)
160 .def("_cos",&escript::Data::cos)
161 .def("_tan",&escript::Data::tan)
162 .def("_asin",&escript::Data::asin)
163 .def("_acos",&escript::Data::acos)
164 .def("_atan",&escript::Data::atan)
165 .def("_sinh",&escript::Data::sinh)
166 .def("_cosh",&escript::Data::cosh)
167 .def("_tanh",&escript::Data::tanh)
168 .def("_asinh",&escript::Data::asinh)
169 .def("_acosh",&escript::Data::acosh)
170 .def("_atanh",&escript::Data::atanh)
171 .def("_exp",&escript::Data::exp)
172 .def("_sqrt",&escript::Data::sqrt)
173 .def("_log10",&escript::Data::log10)
174 .def("_log",&escript::Data::log)
175 .def("_sign",&escript::Data::sign)
176 .def("_eigenvalues",&escript::Data::eigenvalues)
177 .def("_eigenvalues_and_eigenvectors",&escript::Data::eigenvalues_and_eigenvectors,(arg("tol")=1.e-13))
178 // functions returning a single real number:
179 .def("_Lsup",&escript::Data::Lsup)
180 .def("_sup",&escript::Data::sup)
181 .def("_inf",&escript::Data::inf)
182 .def("_integrate",&escript::Data::integrate)
183
184 // following implements the python abs operator
185 .def("__abs__",&escript::Data::abs)
186 // following implements the python "-" negation operator
187 .def("__neg__",&escript::Data::neg)
188 // following implements the python "+" identity operator
189 .def("__pos__",&escript::Data::pos)
190 // following two functions implement the python [] operator
191 .def("__getitem__",&escript::Data::getItem)
192 .def("__setitem__",&escript::Data::setItemO)
193 .def("__setitem__",&escript::Data::setItemD)
194 // following two functions implement the python ** operator
195 .def("__pow__",&escript::Data::powO)
196 .def("__pow__",&escript::Data::powD)
197 // NOTE:: The order of these declarations is important. Anything
198 // declared before the generic declaration isn't found so the generic
199 // version will be called.
200 .def(self + other<object>())
201 .def(other<object>() + self)
202 .def(self + self)
203 .def(self += other<object>())
204 .def(self += self)
205
206 .def(self - other<object>())
207 .def(other<object>() - self)
208 .def(self - self)
209 .def(self -= other<object>())
210 .def(self -= self)
211
212 .def(self * other<object>())
213 .def(other<object>() * self)
214 .def(self * self)
215 .def(self *= other<object>())
216 .def(self *= self)
217
218 .def(self / other<object>())
219 .def(other<object>() / self)
220 .def(self / self)
221 .def(self /= other<object>())
222 .def(self /= self)
223 // Need scope resolution due to a bug either in the compiler or
224 // the boost code. This calls operator << for Data.
225 .def(self_ns::str(self));
226
227 //
228 // Factory methods for function space
229 //
230 def("ContinuousFunction",escript::continuousFunction);
231 def("Function",escript::function);
232 def("FunctionOnBoundary",escript::functionOnBoundary);
233 def("FunctionOnContactZero",escript::functionOnContactZero);
234 def("FunctionOnContactOne",escript::functionOnContactOne);
235 def("Solution",escript::solution);
236 def("ReducedSolution",escript::reducedSolution);
237 def("DiracDeltaFunction",escript::diracDeltaFunction);
238
239 //
240 // Factory methods for Data
241 //
242 def("Scalar",escript::Scalar,
243 (arg("value")=0.0,
244 arg("what")=escript::FunctionSpace(),
245 arg("expanded")=false));
246 def("Vector",escript::Vector,
247 (arg("value")=0.0,
248 arg("what")=escript::FunctionSpace(),
249 arg("expanded")=false));
250 def("Tensor",escript::Tensor,
251 (arg("value")=0.0,
252 arg("what")=escript::FunctionSpace(),
253 arg("expanded")=false));
254 def("Tensor3",escript::Tensor3,
255 (arg("value")=0.0,
256 arg("what")=escript::FunctionSpace(),
257 arg("expanded")=false));
258 def("Tensor4",escript::Tensor4,
259 (arg("value")=0.0,
260 arg("what")=escript::FunctionSpace(),
261 arg("expanded")=false));
262
263 //
264 // Interface for AbstractSystemMatrix
265 //
266 class_<escript::AbstractSystemMatrix>("Operator",init<>())
267 .def("isEmpty",&escript::AbstractSystemMatrix::isEmpty)
268 .def("solve",&escript::AbstractSystemMatrix::solve)
269 .def("of",&escript::AbstractSystemMatrix::vectorMultiply)
270 .def("saveMM",&escript::AbstractSystemMatrix::saveMM)
271 .def("saveHB",&escript::AbstractSystemMatrix::saveHB)
272 .def("resetValues",&escript::AbstractSystemMatrix::resetValues)
273 .def(self*other<escript::Data>());
274
275 //
276 // Register esysExceptionTranslator
277 //
278 register_exception_translator<esysUtils::EsysException>(&esysUtils::esysExceptionTranslator);
279
280 }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26