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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1421 - (hide annotations)
Tue Feb 26 10:17:33 2008 UTC (12 years, 5 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 jgs 102
2 ksteube 1312 /* $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 jgs 474 #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 jgs 480 #include "AbstractSystemMatrix.h"
24 gross 1364 #include "AbstractTransportProblem.h"
25 gross 797 #include "DataVector.h"
26 jgs 474
27 robwdcock 682 #include "esysUtils/esysExceptionTranslator.h"
28 jgs 102
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 gross 285 #include <boost/python/numeric.hpp>
35    
36 jgs 102 using namespace boost::python;
37    
38 jgs 121 /*! \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 cochrane 358 * - <a href=http://iservo.edu.au/esys/epydoc/index.html>Python module documentation (epydoc generated)</a>
49 jgs 122 *
50 jgs 121 */
51 jgs 102
52 jgs 121 /*! \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 jgs 102
72     BOOST_PYTHON_MODULE(escriptcpp)
73     {
74 gross 391 def("setNumberOfThreads",escript::setNumberOfThreads);
75     def("getNumberOfThreads",escript::getNumberOfThreads);
76 gross 797 def("releaseUnusedMemory",escript::releaseUnusedMemory);
77 ksteube 1247 def("getVersion",escript::getSvnVersion);
78 jgs 102
79 gross 797
80 jgs 102 //
81     // Interface for AbstractDomain
82     //
83     class_<escript::AbstractDomain>("Domain",no_init)
84 gross 1044 .def("setTagMap",&escript::AbstractDomain::setTagMap)
85     .def("getTag",&escript::AbstractDomain::getTag)
86     .def("isValidTagName",&escript::AbstractDomain::isValidTagName)
87     .def("showTagNames",&escript::AbstractDomain::showTagNames)
88 jgs 102 .def("getX",&escript::AbstractDomain::getX)
89     .def("getNormal",&escript::AbstractDomain::getNormal)
90     .def("getSize",&escript::AbstractDomain::getSize)
91 jgs 153 .def("saveVTK",&escript::AbstractDomain::saveVTK)
92     .def("saveDX",&escript::AbstractDomain::saveDX)
93 ksteube 1312 .def("getMPISize",&escript::AbstractDomain::getMPISize)
94     .def("getMPIRank",&escript::AbstractDomain::getMPIRank)
95    
96 jgs 102 .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 trankine 1421 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 jgs 102 //
128     // Interface for Data
129     //
130 jgs 149 class_<escript::Data>("Data","TEST DOCUMENTATION",init<>())
131 jgs 102 // 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 ksteube 1312 .def("__str__",&escript::Data::toString)
140 jgs 102 .def("getDomain",&escript::Data::getDomain,return_internal_reference<>())
141     .def("getFunctionSpace",&escript::Data::getFunctionSpace,return_internal_reference<>())
142     .def("isEmpty",&escript::Data::isEmpty)
143 gross 783 .def("isProtected",&escript::Data::isProtected)
144     .def("setProtection",&escript::Data::setProtection)
145 jgs 102 .def("getShape",&escript::Data::getShapeTuple)
146     .def("getRank",&escript::Data::getDataPointRank)
147 gross 950 .def("dump",&escript::Data::dump)
148 jgs 102 .def("copyWithMask",&escript::Data::copyWithMask)
149     .def("setTaggedValue",&escript::Data::setTaggedValue)
150 gross 1044 .def("setTaggedValue",&escript::Data::setTaggedValueByName)
151 gross 921 .def("getNumberOfDataPoints",&escript::Data::getNumDataPoints)
152 gross 1141 .def("isExpanded",&escript::Data::isExpanded)
153     .def("isTagged",&escript::Data::isTagged)
154 jgs 119 .def("expand",&escript::Data::expand)
155     .def("tag",&escript::Data::tag)
156 jgs 126 .def("copy",&escript::Data::copy)
157 gross 1034 .def("setValueOfDataPoint",&escript::Data::setValueOfDataPointToPyObject)
158     .def("setValueOfDataPoint",&escript::Data::setValueOfDataPointToArray)
159 gross 921 .def("setValueOfDataPoint",&escript::Data::setValueOfDataPoint)
160     .def("getValueOfDataPoint",&escript::Data::getValueOfDataPoint)
161     .def("getValueOfGlobalDataPoint",&escript::Data::getValueOfGlobalDataPoint)
162 gross 1118 .def("setToZero",&escript::Data::setToZero)
163 gross 285 .def("interpolate",&escript::Data::interpolate)
164 gross 921 .def("minGlobalDataPoint",&escript::Data::minGlobalDataPoint)
165 gross 285 .def("saveDX",&escript::Data::saveDX)
166     .def("saveVTK",&escript::Data::saveVTK)
167 jgs 149 .def("getTagNumber",&escript::Data::getTagNumber)
168 jgs 119 .def("archiveData",&escript::Data::archiveData)
169     .def("extractData",&escript::Data::extractData)
170 gross 285 // 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 gross 698 .def("_wherePositive",&escript::Data::wherePositive)
179     .def("_whereNegative",&escript::Data::whereNegative)
180     .def("_whereNonNegative",&escript::Data::whereNonNegative)
181     .def("_whereNonPositive",&escript::Data::whereNonPositive)
182 jgs 571 .def("_whereZero",&escript::Data::whereZero,(arg("tol")=0.0))
183     .def("_whereNonZero",&escript::Data::whereNonZero,(arg("tol")=0.0))
184 ksteube 876 .def("_erf",&escript::Data::erf)
185 gross 285 .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 ksteube 775 .def("_symmetric",&escript::Data::symmetric)
203     .def("_nonsymmetric",&escript::Data::nonsymmetric)
204 gross 800 .def("_trace",&escript::Data::trace)
205 gross 804 .def("_swap_axes",&escript::Data::swapaxes)
206 gross 576 .def("_eigenvalues",&escript::Data::eigenvalues)
207     .def("_eigenvalues_and_eigenvectors",&escript::Data::eigenvalues_and_eigenvectors,(arg("tol")=1.e-13))
208 gross 285 // 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 jgs 108 .def("__abs__",&escript::Data::abs)
216 jgs 102 // 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 gross 699 .def("__rpow__",&escript::Data::rpowO)
228 jgs 102 // 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 gross 285 .def(self += other<object>())
235     .def(self += self)
236    
237 jgs 102 .def(self - other<object>())
238     .def(other<object>() - self)
239     .def(self - self)
240 gross 285 .def(self -= other<object>())
241     .def(self -= self)
242    
243 jgs 102 .def(self * other<object>())
244     .def(other<object>() * self)
245     .def(self * self)
246 gross 285 .def(self *= other<object>())
247     .def(self *= self)
248    
249 jgs 102 .def(self / other<object>())
250     .def(other<object>() / self)
251     .def(self / self)
252 gross 285 .def(self /= other<object>())
253     .def(self /= self)
254 jgs 102 // 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 gross 1062 def("ReducedContinuousFunction",escript::reducedContinuousFunction);
263 jgs 102 def("Function",escript::function);
264 gross 1062 def("ReducedFunction",escript::reducedFunction);
265 jgs 102 def("FunctionOnBoundary",escript::functionOnBoundary);
266 gross 1062 def("ReducedFunctionOnBoundary",escript::reducedFunctionOnBoundary);
267 jgs 102 def("FunctionOnContactZero",escript::functionOnContactZero);
268 gross 1062 def("ReducedFunctionOnContactZero",escript::reducedFunctionOnContactZero);
269 jgs 102 def("FunctionOnContactOne",escript::functionOnContactOne);
270 gross 1062 def("ReducedFunctionOnContactOne",escript::reducedFunctionOnContactOne);
271 jgs 102 def("Solution",escript::solution);
272     def("ReducedSolution",escript::reducedSolution);
273     def("DiracDeltaFunction",escript::diracDeltaFunction);
274    
275     //
276     // Factory methods for Data
277     //
278 gross 950 def("load",escript::load);
279 gross 1023 def("loadIsConfigured",escript::loadConfigured);
280 jgs 102 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 ksteube 813 // 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 jgs 102 // 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 jgs 123 .def("saveHB",&escript::AbstractSystemMatrix::saveHB)
319 jgs 149 .def("resetValues",&escript::AbstractSystemMatrix::resetValues)
320 jgs 102 .def(self*other<escript::Data>());
321 gross 1364 //
322     // Interface for AbstractTransportProblem
323     //
324     class_<escript::AbstractTransportProblem>("TransportProblem",init<>())
325     .def("isEmpty",&escript::AbstractTransportProblem::isEmpty)
326     .def("solve",&escript::AbstractTransportProblem::solve)
327 gross 1370 .def("setInitialValue",&escript::AbstractTransportProblem::setInitialValue)
328 gross 1364 .def("resetTransport",&escript::AbstractTransportProblem::resetTransport);
329 jgs 102
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