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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26