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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1385 - (show annotations)
Fri Jan 11 07:33:30 2008 UTC (13 years, 1 month ago) by trankine
File size: 12572 byte(s)
This is a commit to the trunk of the current windows version undergoing debugging.
This trunk will shortly be moved to the branches area
of the repository, and the saved trunk version currently over in branches restored to the trunk.

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26