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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 922 - (show annotations)
Fri Jan 5 04:23:05 2007 UTC (12 years, 8 months ago) by gross
File size: 11320 byte(s)
setValueOfDataPoint accepts double value as argument now
1 //$Id$
2 /*
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
14 #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 #include "AbstractSystemMatrix.h"
22 #include "DataVector.h"
23
24 #include "esysUtils/esysExceptionTranslator.h"
25
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 #include <boost/python/numeric.hpp>
32
33 using namespace boost::python;
34
35 /*! \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 * - <a href=http://iservo.edu.au/esys/epydoc/index.html>Python module documentation (epydoc generated)</a>
46 *
47 */
48
49 /*! \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
69 BOOST_PYTHON_MODULE(escriptcpp)
70 {
71 def("setNumberOfThreads",escript::setNumberOfThreads);
72 def("getNumberOfThreads",escript::getNumberOfThreads);
73 def("releaseUnusedMemory",escript::releaseUnusedMemory);
74
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("setTags",&escript::FunctionSpace::setTags)
104 .def("getTagFromDataPointNo",&escript::FunctionSpace::getTagFromDataPointNo)
105 .def("__str__",&escript::FunctionSpace::toString)
106 .def(self == self)
107 .def(self != self);
108 //
109 // Interface for Data
110 //
111 class_<escript::Data>("Data","TEST DOCUMENTATION",init<>())
112 // various constructors for Data objects
113 .def(init<const numeric::array&, optional<const escript::FunctionSpace&, bool> >(args("value","what","expand")))
114 .def(init<const object&, optional<const escript::FunctionSpace&, bool> >(args("value","what","expand")))
115 .def(init<const double, const tuple&, optional<const escript::FunctionSpace&, bool> >(args("value","shape","what","expand")))
116 .def(init<const escript::Data&, const escript::FunctionSpace&>(args("value","what")))
117 .def(init<const escript::Data&>())
118 // Note for Lutz, Need to specify the call policy in order to return a
119 // reference. In this case return_internal_reference.
120 .def("__str__",&escript::Data::toString)
121 .def("getDomain",&escript::Data::getDomain,return_internal_reference<>())
122 .def("getFunctionSpace",&escript::Data::getFunctionSpace,return_internal_reference<>())
123 .def("isEmpty",&escript::Data::isEmpty)
124 .def("isProtected",&escript::Data::isProtected)
125 .def("setProtection",&escript::Data::setProtection)
126 .def("getShape",&escript::Data::getShapeTuple)
127 .def("getRank",&escript::Data::getDataPointRank)
128 .def("copyWithMask",&escript::Data::copyWithMask)
129 .def("setTaggedValue",&escript::Data::setTaggedValue)
130 .def("setRefValue",&escript::Data::setRefValue)
131 .def("getRefValue",&escript::Data::getRefValue)
132 .def("getNumberOfDataPoints",&escript::Data::getNumDataPoints)
133 .def("expand",&escript::Data::expand)
134 .def("tag",&escript::Data::tag)
135 .def("copy",&escript::Data::copy)
136 .def("convertToNumArray",&escript::Data::convertToNumArray)
137 .def("fillFromNumArray",&escript::Data::fillFromNumArray)
138 .def("setValueOfDataPoint",&escript::Data::setValueOfDataPoint)
139 .def("setValueOfDataPoint",&escript::Data::setValueOfDataPointToArray)
140 .def("getValueOfDataPoint",&escript::Data::getValueOfDataPoint)
141 .def("getValueOfGlobalDataPoint",&escript::Data::getValueOfGlobalDataPoint)
142 .def("interpolate",&escript::Data::interpolate)
143 .def("minGlobalDataPoint",&escript::Data::minGlobalDataPoint)
144 .def("saveDX",&escript::Data::saveDX)
145 .def("saveVTK",&escript::Data::saveVTK)
146 .def("getTagNumber",&escript::Data::getTagNumber)
147 .def("archiveData",&escript::Data::archiveData)
148 .def("extractData",&escript::Data::extractData)
149 // Unary functions for Data
150 .def("_interpolate",&escript::Data::interpolate)
151 .def("_grad",&escript::Data::gradOn)
152 .def("_grad",&escript::Data::grad)
153 .def("_transpose",&escript::Data::transpose)
154 .def("_trace",&escript::Data::trace)
155 .def("_maxval",&escript::Data::maxval)
156 .def("_minval",&escript::Data::minval)
157 .def("_wherePositive",&escript::Data::wherePositive)
158 .def("_whereNegative",&escript::Data::whereNegative)
159 .def("_whereNonNegative",&escript::Data::whereNonNegative)
160 .def("_whereNonPositive",&escript::Data::whereNonPositive)
161 .def("_whereZero",&escript::Data::whereZero,(arg("tol")=0.0))
162 .def("_whereNonZero",&escript::Data::whereNonZero,(arg("tol")=0.0))
163 .def("_erf",&escript::Data::erf)
164 .def("_sin",&escript::Data::sin)
165 .def("_cos",&escript::Data::cos)
166 .def("_tan",&escript::Data::tan)
167 .def("_asin",&escript::Data::asin)
168 .def("_acos",&escript::Data::acos)
169 .def("_atan",&escript::Data::atan)
170 .def("_sinh",&escript::Data::sinh)
171 .def("_cosh",&escript::Data::cosh)
172 .def("_tanh",&escript::Data::tanh)
173 .def("_asinh",&escript::Data::asinh)
174 .def("_acosh",&escript::Data::acosh)
175 .def("_atanh",&escript::Data::atanh)
176 .def("_exp",&escript::Data::exp)
177 .def("_sqrt",&escript::Data::sqrt)
178 .def("_log10",&escript::Data::log10)
179 .def("_log",&escript::Data::log)
180 .def("_sign",&escript::Data::sign)
181 .def("_symmetric",&escript::Data::symmetric)
182 .def("_nonsymmetric",&escript::Data::nonsymmetric)
183 .def("_trace",&escript::Data::trace)
184 .def("_swap_axes",&escript::Data::swapaxes)
185 .def("_eigenvalues",&escript::Data::eigenvalues)
186 .def("_eigenvalues_and_eigenvectors",&escript::Data::eigenvalues_and_eigenvectors,(arg("tol")=1.e-13))
187 // functions returning a single real number:
188 .def("_Lsup",&escript::Data::Lsup)
189 .def("_sup",&escript::Data::sup)
190 .def("_inf",&escript::Data::inf)
191 .def("_integrate",&escript::Data::integrate)
192
193 // following implements the python abs operator
194 .def("__abs__",&escript::Data::abs)
195 // following implements the python "-" negation operator
196 .def("__neg__",&escript::Data::neg)
197 // following implements the python "+" identity operator
198 .def("__pos__",&escript::Data::pos)
199 // following two functions implement the python [] operator
200 .def("__getitem__",&escript::Data::getItem)
201 .def("__setitem__",&escript::Data::setItemO)
202 .def("__setitem__",&escript::Data::setItemD)
203 // following two functions implement the python ** operator
204 .def("__pow__",&escript::Data::powO)
205 .def("__pow__",&escript::Data::powD)
206 .def("__rpow__",&escript::Data::rpowO)
207 // NOTE:: The order of these declarations is important. Anything
208 // declared before the generic declaration isn't found so the generic
209 // version will be called.
210 .def(self + other<object>())
211 .def(other<object>() + self)
212 .def(self + self)
213 .def(self += other<object>())
214 .def(self += self)
215
216 .def(self - other<object>())
217 .def(other<object>() - self)
218 .def(self - self)
219 .def(self -= other<object>())
220 .def(self -= self)
221
222 .def(self * other<object>())
223 .def(other<object>() * self)
224 .def(self * self)
225 .def(self *= other<object>())
226 .def(self *= self)
227
228 .def(self / other<object>())
229 .def(other<object>() / self)
230 .def(self / self)
231 .def(self /= other<object>())
232 .def(self /= self)
233 // Need scope resolution due to a bug either in the compiler or
234 // the boost code. This calls operator << for Data.
235 .def(self_ns::str(self));
236
237 //
238 // Factory methods for function space
239 //
240 def("ContinuousFunction",escript::continuousFunction);
241 def("Function",escript::function);
242 def("FunctionOnBoundary",escript::functionOnBoundary);
243 def("FunctionOnContactZero",escript::functionOnContactZero);
244 def("FunctionOnContactOne",escript::functionOnContactOne);
245 def("Solution",escript::solution);
246 def("ReducedSolution",escript::reducedSolution);
247 def("DiracDeltaFunction",escript::diracDeltaFunction);
248
249 //
250 // Factory methods for Data
251 //
252 def("Scalar",escript::Scalar,
253 (arg("value")=0.0,
254 arg("what")=escript::FunctionSpace(),
255 arg("expanded")=false));
256 def("Vector",escript::Vector,
257 (arg("value")=0.0,
258 arg("what")=escript::FunctionSpace(),
259 arg("expanded")=false));
260 def("Tensor",escript::Tensor,
261 (arg("value")=0.0,
262 arg("what")=escript::FunctionSpace(),
263 arg("expanded")=false));
264 def("Tensor3",escript::Tensor3,
265 (arg("value")=0.0,
266 arg("what")=escript::FunctionSpace(),
267 arg("expanded")=false));
268 def("Tensor4",escript::Tensor4,
269 (arg("value")=0.0,
270 arg("what")=escript::FunctionSpace(),
271 arg("expanded")=false));
272
273 //
274 // Binary operators
275 //
276 def("C_GeneralTensorProduct",escript::C_GeneralTensorProduct,
277 (arg("arg0")=escript::Data(),
278 arg("arg1")=escript::Data(),
279 arg("axis_offset")=0,
280 arg("transpose")=0));
281
282 //
283 // Interface for AbstractSystemMatrix
284 //
285 class_<escript::AbstractSystemMatrix>("Operator",init<>())
286 .def("isEmpty",&escript::AbstractSystemMatrix::isEmpty)
287 .def("solve",&escript::AbstractSystemMatrix::solve)
288 .def("of",&escript::AbstractSystemMatrix::vectorMultiply)
289 .def("saveMM",&escript::AbstractSystemMatrix::saveMM)
290 .def("saveHB",&escript::AbstractSystemMatrix::saveHB)
291 .def("resetValues",&escript::AbstractSystemMatrix::resetValues)
292 .def(self*other<escript::Data>());
293
294 //
295 // Register esysExceptionTranslator
296 //
297 register_exception_translator<esysUtils::EsysException>(&esysUtils::esysExceptionTranslator);
298
299 }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26