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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1897 - (show annotations)
Mon Oct 20 00:32:30 2008 UTC (11 years 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
2 /*******************************************************
3 *
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
14
15 #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 #include "AbstractSystemMatrix.h"
23 #include "AbstractTransportProblem.h"
24 #include "DataVector.h"
25 #include "paso/Paso_MPI.h"
26 #include "EscriptParams.h"
27
28
29
30 extern "C" {
31 #include "escript/blocktimer.h"
32 }
33
34 #include "esysUtils/esysExceptionTranslator.h"
35
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 #include <boost/python/numeric.hpp>
42 #include <boost/smart_ptr.hpp>
43
44 using namespace boost::python;
45
46 /*! \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 * - <a href=http://iservo.edu.au/esys/epydoc/index.html>Python module documentation (epydoc generated)</a>
57 *
58 */
59
60 /*! \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
80 BOOST_PYTHON_MODULE(escriptcpp)
81 {
82 def("setNumberOfThreads",escript::setNumberOfThreads);
83 def("getNumberOfThreads",escript::getNumberOfThreads);
84 def("releaseUnusedMemory",escript::releaseUnusedMemory);
85 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 def("getVersion",escript::getSvnVersion);
91 def("printParallelThreadCounts",escript::printParallelThreadCnt);
92 def("getMPISizeWorld",escript::getMPISizeWorld);
93 def("getMPIRankWorld",escript::getMPIRankWorld);
94
95
96 //
97 // Interface for AbstractDomain
98 //
99 class_<escript::AbstractDomain, escript::Domain_ptr>("Domain",no_init)
100 .def("setTagMap",&escript::AbstractDomain::setTagMap)
101 .def("getTag",&escript::AbstractDomain::getTag)
102 .def("isValidTagName",&escript::AbstractDomain::isValidTagName)
103 .def("showTagNames",&escript::AbstractDomain::showTagNames)
104 .def("getX",&escript::AbstractDomain::getX)
105 .def("getDim",&escript::AbstractDomain::getDim)
106 .def("getNormal",&escript::AbstractDomain::getNormal)
107 .def("getSize",&escript::AbstractDomain::getSize)
108 .def("saveVTK",&escript::AbstractDomain::saveVTK)
109 .def("saveDX",&escript::AbstractDomain::saveDX)
110 .def("getMPISize",&escript::AbstractDomain::getMPISize)
111 .def("getMPIRank",&escript::AbstractDomain::getMPIRank)
112 .def("MPIBarrier",&escript::AbstractDomain::MPIBarrier)
113 .def("onMasterProcessor",&escript::AbstractDomain::onMasterProcessor)
114
115 .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 .def("getSystemMatrixTypeId",&escript::AbstractContinuousDomain::getSystemMatrixTypeId)
123 .def("getTransportTypeId",&escript::AbstractContinuousDomain::getTransportTypeId);
124
125 //
126 // Interface for FunctionSpace
127 //
128 class_<escript::FunctionSpace> fs_definer("FunctionSpace",init<>());
129 fs_definer.def("getDim",&escript::FunctionSpace::getDim);
130 // fs_definer.def("getDomain",&escript::FunctionSpace::getDomain,
131 // return_internal_reference<>());
132 fs_definer.def("getDomain",&escript::FunctionSpace::getDomainPython);
133 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 fs_definer.def("getReferenceIDFromDataPointNo", &escript::FunctionSpace::getReferenceIDFromDataPointNo);
140 fs_definer.def("getListOfTags",&escript::FunctionSpace::getListOfTags);
141 fs_definer.def("__str__", &escript::FunctionSpace::toString);
142 fs_definer.def(self == self);
143 fs_definer.def(self != self);
144 //
145 // Interface for Data
146 //
147 class_<escript::Data>("Data","TEST DOCUMENTATION",init<>() )
148 // 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 .def("__str__",&escript::Data::toString)
157 // .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 .def("isEmpty",&escript::Data::isEmpty)
161 .def("isProtected",&escript::Data::isProtected)
162 .def("setProtection",&escript::Data::setProtection)
163 .def("getShape",&escript::Data::getShapeTuple)
164 .def("getRank",&escript::Data::getDataPointRank)
165 .def("dump",&escript::Data::dump)
166 .def("copyWithMask",&escript::Data::copyWithMask)
167 .def("setTaggedValue",&escript::Data::setTaggedValue)
168 .def("setTaggedValue",&escript::Data::setTaggedValueByName)
169 .def("getNumberOfDataPoints",&escript::Data::getNumDataPoints)
170 .def("isExpanded",&escript::Data::isExpanded)
171 .def("isTagged",&escript::Data::isTagged)
172 .def("expand",&escript::Data::expand)
173 .def("tag",&escript::Data::tag)
174 .def("copy",&escript::Data::copy)
175 .def("copy",&escript::Data::copySelf,return_value_policy<manage_new_object>())
176 .def("setValueOfDataPoint",&escript::Data::setValueOfDataPointToPyObject)
177 .def("setValueOfDataPoint",&escript::Data::setValueOfDataPointToArray)
178 .def("setValueOfDataPoint",&escript::Data::setValueOfDataPoint)
179 .def("getValueOfDataPoint",&escript::Data::getValueOfDataPoint)
180 .def("getValueOfGlobalDataPoint",&escript::Data::getValueOfGlobalDataPoint)
181 .def("setToZero",&escript::Data::setToZero)
182 .def("interpolate",&escript::Data::interpolate)
183 .def("minGlobalDataPoint",&escript::Data::minGlobalDataPoint)
184 .def("saveDX",&escript::Data::saveDX)
185 .def("saveVTK",&escript::Data::saveVTK)
186 .def("getTagNumber",&escript::Data::getTagNumber)
187 // 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 .def("_wherePositive",&escript::Data::wherePositive)
196 .def("_whereNegative",&escript::Data::whereNegative)
197 .def("_whereNonNegative",&escript::Data::whereNonNegative)
198 .def("_whereNonPositive",&escript::Data::whereNonPositive)
199 .def("_whereZero",&escript::Data::whereZero,(arg("tol")=0.0))
200 .def("_whereNonZero",&escript::Data::whereNonZero,(arg("tol")=0.0))
201 .def("_erf",&escript::Data::erf)
202 .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 .def("_symmetric",&escript::Data::symmetric)
220 .def("_nonsymmetric",&escript::Data::nonsymmetric)
221 .def("_trace",&escript::Data::trace)
222 .def("_swap_axes",&escript::Data::swapaxes)
223 .def("_eigenvalues",&escript::Data::eigenvalues)
224 .def("_eigenvalues_and_eigenvectors",&escript::Data::eigenvalues_and_eigenvectors,(arg("tol")=1.e-13))
225 // 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 .def("__abs__",&escript::Data::abs)
233 // 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 .def("__rpow__",&escript::Data::rpowO)
245 // 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 .def(self += other<object>())
252 .def(self += self)
253
254 .def(self - other<object>())
255 .def(other<object>() - self)
256 .def(self - self)
257 .def(self -= other<object>())
258 .def(self -= self)
259
260 .def(self * other<object>())
261 .def(other<object>() * self)
262 .def(self * self)
263 .def(self *= other<object>())
264 .def(self *= self)
265
266 .def(self / other<object>())
267 .def(other<object>() / self)
268 .def(self / self)
269 .def(self /= other<object>())
270 .def(self /= self)
271 // 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 def("ReducedContinuousFunction",escript::reducedContinuousFunction);
280 def("Function",escript::function);
281 def("ReducedFunction",escript::reducedFunction);
282 def("FunctionOnBoundary",escript::functionOnBoundary);
283 def("ReducedFunctionOnBoundary",escript::reducedFunctionOnBoundary);
284 def("FunctionOnContactZero",escript::functionOnContactZero);
285 def("ReducedFunctionOnContactZero",escript::reducedFunctionOnContactZero);
286 def("FunctionOnContactOne",escript::functionOnContactOne);
287 def("ReducedFunctionOnContactOne",escript::reducedFunctionOnContactOne);
288 def("Solution",escript::solution);
289 def("ReducedSolution",escript::reducedSolution);
290 def("DiracDeltaFunction",escript::diracDeltaFunction);
291
292 //
293 // Factory methods for Data
294 //
295 def("load",escript::load);
296 def("loadIsConfigured",escript::loadConfigured);
297 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 // 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 // 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 .def("saveHB",&escript::AbstractSystemMatrix::saveHB)
336 .def("resetValues",&escript::AbstractSystemMatrix::resetValues)
337 .def(self*other<escript::Data>());
338 //
339 // Interface for AbstractTransportProblem
340 //
341 class_<escript::AbstractTransportProblem>("TransportProblem",init<>())
342 .def("isEmpty",&escript::AbstractTransportProblem::isEmpty)
343 .def("solve",&escript::AbstractTransportProblem::solve)
344 .def("setInitialValue",&escript::AbstractTransportProblem::setInitialValue)
345 .def("insertConstraint",&escript::AbstractTransportProblem::insertConstraint)
346 .def("reset",&escript::AbstractTransportProblem::resetTransport)
347 .def("resetValues",&escript::AbstractTransportProblem::resetTransport)
348 .def("getSafeTimeStepSize",&escript::AbstractTransportProblem::getSafeTimeStepSize)
349 .def("getUnlimitedTimeStepSize",&escript::AbstractTransportProblem::getUnlimitedTimeStepSize);
350
351 // 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 //
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