/[escript]/branches/windows_from_1383_trunk/escript/src/escriptcpp.cpp
ViewVC logotype

Contents of /branches/windows_from_1383_trunk/escript/src/escriptcpp.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1421 - (show annotations)
Tue Feb 26 10:17:33 2008 UTC (12 years, 4 months ago) by trankine
File size: 12881 byte(s)
In this version

1. with DEBUG_PY_STRINGS not defined, it succeeds to run repeated str(a_fn_space) 50000 times. However it fails run_tests and py_tests in the same way it did previously.
2. with DEBUG_PY_STRINGS it uses toPyString, and almost passes run_tests, and gets far further into py_tests, to a point that looks quite different.
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> fs_definer("FunctionSpace",init<>());
109 fs_definer.def("getDim",&escript::FunctionSpace::getDim);
110 fs_definer.def("getDomain",&escript::FunctionSpace::getDomain,
111 return_internal_reference<>());
112 fs_definer.def("getX",&escript::FunctionSpace::getX);
113 fs_definer.def("getNormal",&escript::FunctionSpace::getNormal);
114 fs_definer.def("getSize",&escript::FunctionSpace::getSize);
115 fs_definer.def("setTags",&escript::FunctionSpace::setTags);
116 fs_definer.def("getTagFromDataPointNo",
117 &escript::FunctionSpace::getTagFromDataPointNo);
118 #ifdef DEBUG_PY_STRINGS
119 fs_definer.def("__str__",&escript::FunctionSpace::toPyString);
120 #else
121 fs_definer.def("__str__",
122 &escript::FunctionSpace::toString,
123 return_value_policy<copy_const_reference>());
124 #endif
125 fs_definer.def(self == self);
126 fs_definer.def(self != self);
127 //
128 // Interface for Data
129 //
130 class_<escript::Data>("Data","TEST DOCUMENTATION",init<>())
131 // various constructors for Data objects
132 .def(init<const numeric::array&, optional<const escript::FunctionSpace&, bool> >(args("value","what","expand")))
133 .def(init<const object&, optional<const escript::FunctionSpace&, bool> >(args("value","what","expand")))
134 .def(init<const double, const tuple&, optional<const escript::FunctionSpace&, bool> >(args("value","shape","what","expand")))
135 .def(init<const escript::Data&, const escript::FunctionSpace&>(args("value","what")))
136 .def(init<const escript::Data&>())
137 // Note for Lutz, Need to specify the call policy in order to return a
138 // reference. In this case return_internal_reference.
139 .def("__str__",&escript::Data::toString)
140 .def("getDomain",&escript::Data::getDomain,return_internal_reference<>())
141 .def("getFunctionSpace",&escript::Data::getFunctionSpace,return_internal_reference<>())
142 .def("isEmpty",&escript::Data::isEmpty)
143 .def("isProtected",&escript::Data::isProtected)
144 .def("setProtection",&escript::Data::setProtection)
145 .def("getShape",&escript::Data::getShapeTuple)
146 .def("getRank",&escript::Data::getDataPointRank)
147 .def("dump",&escript::Data::dump)
148 .def("copyWithMask",&escript::Data::copyWithMask)
149 .def("setTaggedValue",&escript::Data::setTaggedValue)
150 .def("setTaggedValue",&escript::Data::setTaggedValueByName)
151 .def("getNumberOfDataPoints",&escript::Data::getNumDataPoints)
152 .def("isExpanded",&escript::Data::isExpanded)
153 .def("isTagged",&escript::Data::isTagged)
154 .def("expand",&escript::Data::expand)
155 .def("tag",&escript::Data::tag)
156 .def("copy",&escript::Data::copy)
157 .def("setValueOfDataPoint",&escript::Data::setValueOfDataPointToPyObject)
158 .def("setValueOfDataPoint",&escript::Data::setValueOfDataPointToArray)
159 .def("setValueOfDataPoint",&escript::Data::setValueOfDataPoint)
160 .def("getValueOfDataPoint",&escript::Data::getValueOfDataPoint)
161 .def("getValueOfGlobalDataPoint",&escript::Data::getValueOfGlobalDataPoint)
162 .def("setToZero",&escript::Data::setToZero)
163 .def("interpolate",&escript::Data::interpolate)
164 .def("minGlobalDataPoint",&escript::Data::minGlobalDataPoint)
165 .def("saveDX",&escript::Data::saveDX)
166 .def("saveVTK",&escript::Data::saveVTK)
167 .def("getTagNumber",&escript::Data::getTagNumber)
168 .def("archiveData",&escript::Data::archiveData)
169 .def("extractData",&escript::Data::extractData)
170 // Unary functions for Data
171 .def("_interpolate",&escript::Data::interpolate)
172 .def("_grad",&escript::Data::gradOn)
173 .def("_grad",&escript::Data::grad)
174 .def("_transpose",&escript::Data::transpose)
175 .def("_trace",&escript::Data::trace)
176 .def("_maxval",&escript::Data::maxval)
177 .def("_minval",&escript::Data::minval)
178 .def("_wherePositive",&escript::Data::wherePositive)
179 .def("_whereNegative",&escript::Data::whereNegative)
180 .def("_whereNonNegative",&escript::Data::whereNonNegative)
181 .def("_whereNonPositive",&escript::Data::whereNonPositive)
182 .def("_whereZero",&escript::Data::whereZero,(arg("tol")=0.0))
183 .def("_whereNonZero",&escript::Data::whereNonZero,(arg("tol")=0.0))
184 .def("_erf",&escript::Data::erf)
185 .def("_sin",&escript::Data::sin)
186 .def("_cos",&escript::Data::cos)
187 .def("_tan",&escript::Data::tan)
188 .def("_asin",&escript::Data::asin)
189 .def("_acos",&escript::Data::acos)
190 .def("_atan",&escript::Data::atan)
191 .def("_sinh",&escript::Data::sinh)
192 .def("_cosh",&escript::Data::cosh)
193 .def("_tanh",&escript::Data::tanh)
194 .def("_asinh",&escript::Data::asinh)
195 .def("_acosh",&escript::Data::acosh)
196 .def("_atanh",&escript::Data::atanh)
197 .def("_exp",&escript::Data::exp)
198 .def("_sqrt",&escript::Data::sqrt)
199 .def("_log10",&escript::Data::log10)
200 .def("_log",&escript::Data::log)
201 .def("_sign",&escript::Data::sign)
202 .def("_symmetric",&escript::Data::symmetric)
203 .def("_nonsymmetric",&escript::Data::nonsymmetric)
204 .def("_trace",&escript::Data::trace)
205 .def("_swap_axes",&escript::Data::swapaxes)
206 .def("_eigenvalues",&escript::Data::eigenvalues)
207 .def("_eigenvalues_and_eigenvectors",&escript::Data::eigenvalues_and_eigenvectors,(arg("tol")=1.e-13))
208 // functions returning a single real number:
209 .def("_Lsup",&escript::Data::Lsup)
210 .def("_sup",&escript::Data::sup)
211 .def("_inf",&escript::Data::inf)
212 .def("_integrate",&escript::Data::integrate)
213
214 // following implements the python abs operator
215 .def("__abs__",&escript::Data::abs)
216 // following implements the python "-" negation operator
217 .def("__neg__",&escript::Data::neg)
218 // following implements the python "+" identity operator
219 .def("__pos__",&escript::Data::pos)
220 // following two functions implement the python [] operator
221 .def("__getitem__",&escript::Data::getItem)
222 .def("__setitem__",&escript::Data::setItemO)
223 .def("__setitem__",&escript::Data::setItemD)
224 // following two functions implement the python ** operator
225 .def("__pow__",&escript::Data::powO)
226 .def("__pow__",&escript::Data::powD)
227 .def("__rpow__",&escript::Data::rpowO)
228 // NOTE:: The order of these declarations is important. Anything
229 // declared before the generic declaration isn't found so the generic
230 // version will be called.
231 .def(self + other<object>())
232 .def(other<object>() + self)
233 .def(self + self)
234 .def(self += other<object>())
235 .def(self += self)
236
237 .def(self - other<object>())
238 .def(other<object>() - self)
239 .def(self - self)
240 .def(self -= other<object>())
241 .def(self -= self)
242
243 .def(self * other<object>())
244 .def(other<object>() * self)
245 .def(self * self)
246 .def(self *= other<object>())
247 .def(self *= self)
248
249 .def(self / other<object>())
250 .def(other<object>() / self)
251 .def(self / self)
252 .def(self /= other<object>())
253 .def(self /= self)
254 // Need scope resolution due to a bug either in the compiler or
255 // the boost code. This calls operator << for Data.
256 .def(self_ns::str(self));
257
258 //
259 // Factory methods for function space
260 //
261 def("ContinuousFunction",escript::continuousFunction);
262 def("ReducedContinuousFunction",escript::reducedContinuousFunction);
263 def("Function",escript::function);
264 def("ReducedFunction",escript::reducedFunction);
265 def("FunctionOnBoundary",escript::functionOnBoundary);
266 def("ReducedFunctionOnBoundary",escript::reducedFunctionOnBoundary);
267 def("FunctionOnContactZero",escript::functionOnContactZero);
268 def("ReducedFunctionOnContactZero",escript::reducedFunctionOnContactZero);
269 def("FunctionOnContactOne",escript::functionOnContactOne);
270 def("ReducedFunctionOnContactOne",escript::reducedFunctionOnContactOne);
271 def("Solution",escript::solution);
272 def("ReducedSolution",escript::reducedSolution);
273 def("DiracDeltaFunction",escript::diracDeltaFunction);
274
275 //
276 // Factory methods for Data
277 //
278 def("load",escript::load);
279 def("loadIsConfigured",escript::loadConfigured);
280 def("Scalar",escript::Scalar,
281 (arg("value")=0.0,
282 arg("what")=escript::FunctionSpace(),
283 arg("expanded")=false));
284 def("Vector",escript::Vector,
285 (arg("value")=0.0,
286 arg("what")=escript::FunctionSpace(),
287 arg("expanded")=false));
288 def("Tensor",escript::Tensor,
289 (arg("value")=0.0,
290 arg("what")=escript::FunctionSpace(),
291 arg("expanded")=false));
292 def("Tensor3",escript::Tensor3,
293 (arg("value")=0.0,
294 arg("what")=escript::FunctionSpace(),
295 arg("expanded")=false));
296 def("Tensor4",escript::Tensor4,
297 (arg("value")=0.0,
298 arg("what")=escript::FunctionSpace(),
299 arg("expanded")=false));
300
301 //
302 // Binary operators
303 //
304 def("C_GeneralTensorProduct",escript::C_GeneralTensorProduct,
305 (arg("arg0")=escript::Data(),
306 arg("arg1")=escript::Data(),
307 arg("axis_offset")=0,
308 arg("transpose")=0));
309
310 //
311 // Interface for AbstractSystemMatrix
312 //
313 class_<escript::AbstractSystemMatrix>("Operator",init<>())
314 .def("isEmpty",&escript::AbstractSystemMatrix::isEmpty)
315 .def("solve",&escript::AbstractSystemMatrix::solve)
316 .def("of",&escript::AbstractSystemMatrix::vectorMultiply)
317 .def("saveMM",&escript::AbstractSystemMatrix::saveMM)
318 .def("saveHB",&escript::AbstractSystemMatrix::saveHB)
319 .def("resetValues",&escript::AbstractSystemMatrix::resetValues)
320 .def(self*other<escript::Data>());
321 //
322 // Interface for AbstractTransportProblem
323 //
324 class_<escript::AbstractTransportProblem>("TransportProblem",init<>())
325 .def("isEmpty",&escript::AbstractTransportProblem::isEmpty)
326 .def("solve",&escript::AbstractTransportProblem::solve)
327 .def("setInitialValue",&escript::AbstractTransportProblem::setInitialValue)
328 .def("resetTransport",&escript::AbstractTransportProblem::resetTransport);
329
330 //
331 // Register esysExceptionTranslator
332 //
333 register_exception_translator<esysUtils::EsysException>(&esysUtils::esysExceptionTranslator);
334
335 }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26