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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1897 - (hide annotations)
Mon Oct 20 00:32:30 2008 UTC (11 years, 1 month ago) by jfenwick
File size: 14407 byte(s)
Modified Data::toString() so it doesn't throw on DataEmpty.
Added setEscriptParamInt and getEscriptParamInt as free functions.
At the moment all they do is allow you to set the param TOO_MANY_LINES.
This is used to determine when printing a Data object will show you the 
points and when it will print a summary.

I've set the default value back to 80 lines.
If you need to see more lines use (in python):

setEscriptParamInt("TOO_MANY_LINES",80000)


1 jgs 102
2 ksteube 1312 /*******************************************************
3 ksteube 1811 *
4     * Copyright (c) 2003-2008 by University of Queensland
5     * Earth Systems Science Computational Center (ESSCC)
6     * http://www.uq.edu.au/esscc
7     *
8     * Primary Business: Queensland, Australia
9     * Licensed under the Open Software License version 3.0
10     * http://www.opensource.org/licenses/osl-3.0.php
11     *
12     *******************************************************/
13 ksteube 1312
14 ksteube 1811
15 jgs 474 #include "Data.h"
16     #include "FunctionSpace.h"
17     #include "FunctionSpaceFactory.h"
18     #include "DataFactory.h"
19     #include "AbstractContinuousDomain.h"
20     #include "AbstractDomain.h"
21     #include "Utils.h"
22 jgs 480 #include "AbstractSystemMatrix.h"
23 gross 1364 #include "AbstractTransportProblem.h"
24 gross 797 #include "DataVector.h"
25 ksteube 1800 #include "paso/Paso_MPI.h"
26 jfenwick 1897 #include "EscriptParams.h"
27 jgs 474
28 jfenwick 1872
29    
30 ksteube 1312 extern "C" {
31     #include "escript/blocktimer.h"
32     }
33    
34 robwdcock 682 #include "esysUtils/esysExceptionTranslator.h"
35 jgs 102
36     #include <boost/python.hpp>
37     #include <boost/python/module.hpp>
38     #include <boost/python/def.hpp>
39     #include <boost/python/object.hpp>
40     #include <boost/python/tuple.hpp>
41 gross 285 #include <boost/python/numeric.hpp>
42 jfenwick 1872 #include <boost/smart_ptr.hpp>
43 gross 285
44 jgs 102 using namespace boost::python;
45    
46 jgs 121 /*! \mainpage Esys Documentation
47     *
48     * \version 1.0.0
49     *
50     * - \ref escript
51     *
52     * - \ref esys_exception "Esys Exception"
53     *
54     * - \ref finley
55     *
56 cochrane 358 * - <a href=http://iservo.edu.au/esys/epydoc/index.html>Python module documentation (epydoc generated)</a>
57 jgs 122 *
58 jgs 121 */
59 jgs 102
60 jgs 121 /*! \page escript Escript
61     * Escript is the python module that contains the interfaces
62     * to the C++ side of escript.
63     *
64     * \version 1.0.0
65     *
66     * \section class_desc Class Description:
67     * Data
68     *
69     * \section class_limits Class Limitations:
70     * None
71     *
72     * \section class_conds Class Conditions of Use:
73     * None
74     *
75     * \section class_throws Throws:
76     * None
77     *
78     */
79 jgs 102
80     BOOST_PYTHON_MODULE(escriptcpp)
81     {
82 gross 391 def("setNumberOfThreads",escript::setNumberOfThreads);
83     def("getNumberOfThreads",escript::getNumberOfThreads);
84 gross 797 def("releaseUnusedMemory",escript::releaseUnusedMemory);
85 ksteube 1312 def("blocktimer_initialize",blocktimer_initialize);
86     def("blocktimer_reportSortByName",blocktimer_reportSortByName);
87     def("blocktimer_reportSortByTime",blocktimer_reportSortByTime);
88     def("blocktimer_increment",blocktimer_increment);
89     def("blocktimer_time",blocktimer_time);
90 ksteube 1247 def("getVersion",escript::getSvnVersion);
91 ksteube 1561 def("printParallelThreadCounts",escript::printParallelThreadCnt);
92 ksteube 1805 def("getMPISizeWorld",escript::getMPISizeWorld);
93     def("getMPIRankWorld",escript::getMPIRankWorld);
94 jgs 102
95 gross 797
96 jgs 102 //
97     // Interface for AbstractDomain
98     //
99 jfenwick 1872 class_<escript::AbstractDomain, escript::Domain_ptr>("Domain",no_init)
100 gross 1044 .def("setTagMap",&escript::AbstractDomain::setTagMap)
101     .def("getTag",&escript::AbstractDomain::getTag)
102     .def("isValidTagName",&escript::AbstractDomain::isValidTagName)
103     .def("showTagNames",&escript::AbstractDomain::showTagNames)
104 jgs 102 .def("getX",&escript::AbstractDomain::getX)
105 jfenwick 1803 .def("getDim",&escript::AbstractDomain::getDim)
106 jgs 102 .def("getNormal",&escript::AbstractDomain::getNormal)
107     .def("getSize",&escript::AbstractDomain::getSize)
108 jgs 153 .def("saveVTK",&escript::AbstractDomain::saveVTK)
109     .def("saveDX",&escript::AbstractDomain::saveDX)
110 ksteube 1312 .def("getMPISize",&escript::AbstractDomain::getMPISize)
111     .def("getMPIRank",&escript::AbstractDomain::getMPIRank)
112 ksteube 1877 .def("MPIBarrier",&escript::AbstractDomain::MPIBarrier)
113     .def("onMasterProcessor",&escript::AbstractDomain::onMasterProcessor)
114 ksteube 1312
115 jgs 102 .def(self == self)
116     .def(self != self);
117    
118     //
119     // Interface for AbstractContinuousDomain
120     //
121     class_<escript::AbstractContinuousDomain, bases<escript::AbstractDomain> >("ContinuousDomain",no_init)
122 gross 1859 .def("getSystemMatrixTypeId",&escript::AbstractContinuousDomain::getSystemMatrixTypeId)
123     .def("getTransportTypeId",&escript::AbstractContinuousDomain::getTransportTypeId);
124 jgs 102
125     //
126     // Interface for FunctionSpace
127     //
128 trankine 1426 class_<escript::FunctionSpace> fs_definer("FunctionSpace",init<>());
129     fs_definer.def("getDim",&escript::FunctionSpace::getDim);
130 jfenwick 1872 // fs_definer.def("getDomain",&escript::FunctionSpace::getDomain,
131     // return_internal_reference<>());
132     fs_definer.def("getDomain",&escript::FunctionSpace::getDomainPython);
133 trankine 1426 fs_definer.def("getX",&escript::FunctionSpace::getX);
134     fs_definer.def("getNormal",&escript::FunctionSpace::getNormal);
135     fs_definer.def("getSize",&escript::FunctionSpace::getSize);
136     fs_definer.def("setTags",&escript::FunctionSpace::setTags);
137     fs_definer.def("getTagFromDataPointNo",
138     &escript::FunctionSpace::getTagFromDataPointNo);
139 gross 1718 fs_definer.def("getReferenceIDFromDataPointNo", &escript::FunctionSpace::getReferenceIDFromDataPointNo);
140 gross 1716 fs_definer.def("getListOfTags",&escript::FunctionSpace::getListOfTags);
141 phornby 1628 fs_definer.def("__str__", &escript::FunctionSpace::toString);
142 trankine 1426 fs_definer.def(self == self);
143     fs_definer.def(self != self);
144 jgs 102 //
145     // Interface for Data
146     //
147 jfenwick 1872 class_<escript::Data>("Data","TEST DOCUMENTATION",init<>() )
148 jgs 102 // various constructors for Data objects
149     .def(init<const numeric::array&, optional<const escript::FunctionSpace&, bool> >(args("value","what","expand")))
150     .def(init<const object&, optional<const escript::FunctionSpace&, bool> >(args("value","what","expand")))
151     .def(init<const double, const tuple&, optional<const escript::FunctionSpace&, bool> >(args("value","shape","what","expand")))
152     .def(init<const escript::Data&, const escript::FunctionSpace&>(args("value","what")))
153     .def(init<const escript::Data&>())
154     // Note for Lutz, Need to specify the call policy in order to return a
155     // reference. In this case return_internal_reference.
156 ksteube 1312 .def("__str__",&escript::Data::toString)
157 jfenwick 1872 // .def("getDomain",&escript::Data::getDomain,return_internal_reference<>())
158     .def("getDomain",&escript::Data::getDomainPython)
159     .def("getFunctionSpace",&escript::Data::getFunctionSpace,return_value_policy<copy_const_reference>())
160 jgs 102 .def("isEmpty",&escript::Data::isEmpty)
161 gross 783 .def("isProtected",&escript::Data::isProtected)
162     .def("setProtection",&escript::Data::setProtection)
163 jgs 102 .def("getShape",&escript::Data::getShapeTuple)
164     .def("getRank",&escript::Data::getDataPointRank)
165 gross 950 .def("dump",&escript::Data::dump)
166 jgs 102 .def("copyWithMask",&escript::Data::copyWithMask)
167     .def("setTaggedValue",&escript::Data::setTaggedValue)
168 gross 1044 .def("setTaggedValue",&escript::Data::setTaggedValueByName)
169 gross 921 .def("getNumberOfDataPoints",&escript::Data::getNumDataPoints)
170 gross 1141 .def("isExpanded",&escript::Data::isExpanded)
171     .def("isTagged",&escript::Data::isTagged)
172 jgs 119 .def("expand",&escript::Data::expand)
173     .def("tag",&escript::Data::tag)
174 jgs 126 .def("copy",&escript::Data::copy)
175 jfenwick 1799 .def("copy",&escript::Data::copySelf,return_value_policy<manage_new_object>())
176 gross 1034 .def("setValueOfDataPoint",&escript::Data::setValueOfDataPointToPyObject)
177     .def("setValueOfDataPoint",&escript::Data::setValueOfDataPointToArray)
178 gross 921 .def("setValueOfDataPoint",&escript::Data::setValueOfDataPoint)
179     .def("getValueOfDataPoint",&escript::Data::getValueOfDataPoint)
180     .def("getValueOfGlobalDataPoint",&escript::Data::getValueOfGlobalDataPoint)
181 gross 1118 .def("setToZero",&escript::Data::setToZero)
182 gross 285 .def("interpolate",&escript::Data::interpolate)
183 gross 921 .def("minGlobalDataPoint",&escript::Data::minGlobalDataPoint)
184 gross 285 .def("saveDX",&escript::Data::saveDX)
185     .def("saveVTK",&escript::Data::saveVTK)
186 jgs 149 .def("getTagNumber",&escript::Data::getTagNumber)
187 gross 285 // Unary functions for Data
188     .def("_interpolate",&escript::Data::interpolate)
189     .def("_grad",&escript::Data::gradOn)
190     .def("_grad",&escript::Data::grad)
191     .def("_transpose",&escript::Data::transpose)
192     .def("_trace",&escript::Data::trace)
193     .def("_maxval",&escript::Data::maxval)
194     .def("_minval",&escript::Data::minval)
195 gross 698 .def("_wherePositive",&escript::Data::wherePositive)
196     .def("_whereNegative",&escript::Data::whereNegative)
197     .def("_whereNonNegative",&escript::Data::whereNonNegative)
198     .def("_whereNonPositive",&escript::Data::whereNonPositive)
199 jgs 571 .def("_whereZero",&escript::Data::whereZero,(arg("tol")=0.0))
200     .def("_whereNonZero",&escript::Data::whereNonZero,(arg("tol")=0.0))
201 ksteube 876 .def("_erf",&escript::Data::erf)
202 gross 285 .def("_sin",&escript::Data::sin)
203     .def("_cos",&escript::Data::cos)
204     .def("_tan",&escript::Data::tan)
205     .def("_asin",&escript::Data::asin)
206     .def("_acos",&escript::Data::acos)
207     .def("_atan",&escript::Data::atan)
208     .def("_sinh",&escript::Data::sinh)
209     .def("_cosh",&escript::Data::cosh)
210     .def("_tanh",&escript::Data::tanh)
211     .def("_asinh",&escript::Data::asinh)
212     .def("_acosh",&escript::Data::acosh)
213     .def("_atanh",&escript::Data::atanh)
214     .def("_exp",&escript::Data::exp)
215     .def("_sqrt",&escript::Data::sqrt)
216     .def("_log10",&escript::Data::log10)
217     .def("_log",&escript::Data::log)
218     .def("_sign",&escript::Data::sign)
219 ksteube 775 .def("_symmetric",&escript::Data::symmetric)
220     .def("_nonsymmetric",&escript::Data::nonsymmetric)
221 gross 800 .def("_trace",&escript::Data::trace)
222 gross 804 .def("_swap_axes",&escript::Data::swapaxes)
223 gross 576 .def("_eigenvalues",&escript::Data::eigenvalues)
224     .def("_eigenvalues_and_eigenvectors",&escript::Data::eigenvalues_and_eigenvectors,(arg("tol")=1.e-13))
225 gross 285 // functions returning a single real number:
226     .def("_Lsup",&escript::Data::Lsup)
227     .def("_sup",&escript::Data::sup)
228     .def("_inf",&escript::Data::inf)
229     .def("_integrate",&escript::Data::integrate)
230    
231     // following implements the python abs operator
232 jgs 108 .def("__abs__",&escript::Data::abs)
233 jgs 102 // following implements the python "-" negation operator
234     .def("__neg__",&escript::Data::neg)
235     // following implements the python "+" identity operator
236     .def("__pos__",&escript::Data::pos)
237     // following two functions implement the python [] operator
238     .def("__getitem__",&escript::Data::getItem)
239     .def("__setitem__",&escript::Data::setItemO)
240     .def("__setitem__",&escript::Data::setItemD)
241     // following two functions implement the python ** operator
242     .def("__pow__",&escript::Data::powO)
243     .def("__pow__",&escript::Data::powD)
244 gross 699 .def("__rpow__",&escript::Data::rpowO)
245 jgs 102 // NOTE:: The order of these declarations is important. Anything
246     // declared before the generic declaration isn't found so the generic
247     // version will be called.
248     .def(self + other<object>())
249     .def(other<object>() + self)
250     .def(self + self)
251 gross 285 .def(self += other<object>())
252     .def(self += self)
253    
254 jgs 102 .def(self - other<object>())
255     .def(other<object>() - self)
256     .def(self - self)
257 gross 285 .def(self -= other<object>())
258     .def(self -= self)
259    
260 jgs 102 .def(self * other<object>())
261     .def(other<object>() * self)
262     .def(self * self)
263 gross 285 .def(self *= other<object>())
264     .def(self *= self)
265    
266 jgs 102 .def(self / other<object>())
267     .def(other<object>() / self)
268     .def(self / self)
269 gross 285 .def(self /= other<object>())
270     .def(self /= self)
271 jgs 102 // Need scope resolution due to a bug either in the compiler or
272     // the boost code. This calls operator << for Data.
273     .def(self_ns::str(self));
274    
275     //
276     // Factory methods for function space
277     //
278     def("ContinuousFunction",escript::continuousFunction);
279 gross 1062 def("ReducedContinuousFunction",escript::reducedContinuousFunction);
280 jgs 102 def("Function",escript::function);
281 gross 1062 def("ReducedFunction",escript::reducedFunction);
282 jgs 102 def("FunctionOnBoundary",escript::functionOnBoundary);
283 gross 1062 def("ReducedFunctionOnBoundary",escript::reducedFunctionOnBoundary);
284 jgs 102 def("FunctionOnContactZero",escript::functionOnContactZero);
285 gross 1062 def("ReducedFunctionOnContactZero",escript::reducedFunctionOnContactZero);
286 jgs 102 def("FunctionOnContactOne",escript::functionOnContactOne);
287 gross 1062 def("ReducedFunctionOnContactOne",escript::reducedFunctionOnContactOne);
288 jgs 102 def("Solution",escript::solution);
289     def("ReducedSolution",escript::reducedSolution);
290     def("DiracDeltaFunction",escript::diracDeltaFunction);
291    
292     //
293     // Factory methods for Data
294     //
295 gross 950 def("load",escript::load);
296 gross 1023 def("loadIsConfigured",escript::loadConfigured);
297 jgs 102 def("Scalar",escript::Scalar,
298     (arg("value")=0.0,
299     arg("what")=escript::FunctionSpace(),
300     arg("expanded")=false));
301     def("Vector",escript::Vector,
302     (arg("value")=0.0,
303     arg("what")=escript::FunctionSpace(),
304     arg("expanded")=false));
305     def("Tensor",escript::Tensor,
306     (arg("value")=0.0,
307     arg("what")=escript::FunctionSpace(),
308     arg("expanded")=false));
309     def("Tensor3",escript::Tensor3,
310     (arg("value")=0.0,
311     arg("what")=escript::FunctionSpace(),
312     arg("expanded")=false));
313     def("Tensor4",escript::Tensor4,
314     (arg("value")=0.0,
315     arg("what")=escript::FunctionSpace(),
316     arg("expanded")=false));
317    
318     //
319 ksteube 813 // Binary operators
320     //
321     def("C_GeneralTensorProduct",escript::C_GeneralTensorProduct,
322     (arg("arg0")=escript::Data(),
323     arg("arg1")=escript::Data(),
324     arg("axis_offset")=0,
325     arg("transpose")=0));
326    
327     //
328 jgs 102 // Interface for AbstractSystemMatrix
329     //
330     class_<escript::AbstractSystemMatrix>("Operator",init<>())
331     .def("isEmpty",&escript::AbstractSystemMatrix::isEmpty)
332     .def("solve",&escript::AbstractSystemMatrix::solve)
333     .def("of",&escript::AbstractSystemMatrix::vectorMultiply)
334     .def("saveMM",&escript::AbstractSystemMatrix::saveMM)
335 jgs 123 .def("saveHB",&escript::AbstractSystemMatrix::saveHB)
336 jgs 149 .def("resetValues",&escript::AbstractSystemMatrix::resetValues)
337 jgs 102 .def(self*other<escript::Data>());
338 gross 1364 //
339     // Interface for AbstractTransportProblem
340     //
341     class_<escript::AbstractTransportProblem>("TransportProblem",init<>())
342     .def("isEmpty",&escript::AbstractTransportProblem::isEmpty)
343     .def("solve",&escript::AbstractTransportProblem::solve)
344 gross 1370 .def("setInitialValue",&escript::AbstractTransportProblem::setInitialValue)
345 gross 1417 .def("insertConstraint",&escript::AbstractTransportProblem::insertConstraint)
346     .def("reset",&escript::AbstractTransportProblem::resetTransport)
347 gross 1841 .def("resetValues",&escript::AbstractTransportProblem::resetTransport)
348 gross 1859 .def("getSafeTimeStepSize",&escript::AbstractTransportProblem::getSafeTimeStepSize)
349     .def("getUnlimitedTimeStepSize",&escript::AbstractTransportProblem::getUnlimitedTimeStepSize);
350 jgs 102
351 jfenwick 1897 // Functions to modify global parameters
352     def("setEscriptParamInt",escript::setEscriptParamInt,
353     (arg("value")=0));
354     def("getEscriptParamInt",escript::getEscriptParamInt,
355     (arg("sentinel")=0));
356    
357    
358 jgs 102 //
359     // Register esysExceptionTranslator
360     //
361     register_exception_translator<esysUtils::EsysException>(&esysUtils::esysExceptionTranslator);
362    
363     }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26