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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2482 - (show annotations)
Fri Jun 19 05:56:20 2009 UTC (10 years, 5 months ago) by jfenwick
File size: 16004 byte(s)
Added run_data_access.py to unit tests - tests things like toListOfTuples.
Corrected some doco comments.
Added TestDomain class to escript.
This should allow more testing without resorting to finley.
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 #include "TestDomain.h"
28
29
30 extern "C" {
31 #include "esysUtils/blocktimer.h"
32 }
33
34 #include "esysUtils/esysExceptionTranslator.h"
35
36 #include <boost/version.hpp>
37 #include <boost/python.hpp>
38 #include <boost/python/module.hpp>
39 #include <boost/python/def.hpp>
40 #include <boost/python/object.hpp>
41 #include <boost/python/tuple.hpp>
42 #include <boost/python/numeric.hpp>
43 #include <boost/smart_ptr.hpp>
44 #include <boost/version.hpp>
45
46 using namespace boost::python;
47
48 /*! \mainpage Esys Documentation
49 *
50 * \version 2.9.0
51 *
52 * - \ref escript
53 *
54 * - \ref esys_exception "Esys Exception"
55 *
56 * - \ref finley
57 *
58 * - <a href="../../epydoc/index.html">Python module documentation (epydoc generated)</a>
59 *
60 */
61
62 /*! \page escript Escript
63 * Escript is the python module that contains the interfaces
64 * to the C++ side of escript.
65 *
66 *
67 *
68 * \section class_desc Class Description:
69 * Data
70 *
71 * \section class_limits Class Limitations:
72 * None
73 *
74 * \section class_conds Class Conditions of Use:
75 * None
76 *
77 * \section class_throws Throws:
78 * None
79 *
80 */
81
82 BOOST_PYTHON_MODULE(escriptcpp)
83 {
84 // This feature was added in boost v1.34
85 #if ((BOOST_VERSION/100)%1000 > 34) || (BOOST_VERSION/100000 >1)
86 //#if ((BOOST_VERSION/100)%1000) > 34
87 // params are: bool show_user_defined, bool show_py_signatures, bool show_cpp_signatures
88 #if BOOST_VERSION > 103399
89 docstring_options docopt(true, true, false);
90 #endif
91 #endif
92
93 def("setNumberOfThreads",escript::setNumberOfThreads);
94 def("getNumberOfThreads",escript::getNumberOfThreads);
95 def("releaseUnusedMemory",escript::releaseUnusedMemory);
96 def("blocktimer_initialize",blocktimer_initialize);
97 def("blocktimer_reportSortByName",blocktimer_reportSortByName);
98 def("blocktimer_reportSortByTime",blocktimer_reportSortByTime);
99 def("blocktimer_increment",blocktimer_increment);
100 def("blocktimer_time",blocktimer_time);
101 def("getVersion",escript::getSvnVersion);
102 def("printParallelThreadCounts",escript::printParallelThreadCnt);
103 def("getMPISizeWorld",escript::getMPISizeWorld);
104 def("getMPIRankWorld",escript::getMPIRankWorld);
105 def("MPIBarrierWorld",escript::MPIBarrierWorld);
106 def("getMPIWorldMax",escript::getMPIWorldMax);
107 def("getMachinePrecision",escript::getMachinePrecision);
108 def("getMaxFloat",escript::getMaxFloat);
109 //
110 // Interface for AbstractDomain
111 //
112 class_<escript::AbstractDomain, escript::Domain_ptr>("Domain","Base class for all domains.",no_init)
113 .def("setTagMap",&escript::AbstractDomain::setTagMap)
114 .def("getTag",&escript::AbstractDomain::getTag)
115 .def("isValidTagName",&escript::AbstractDomain::isValidTagName)
116 .def("showTagNames",&escript::AbstractDomain::showTagNames)
117 .def("getX",&escript::AbstractDomain::getX)
118 .def("getDim",&escript::AbstractDomain::getDim)
119 .def("getNormal",&escript::AbstractDomain::getNormal)
120 .def("getSize",&escript::AbstractDomain::getSize)
121 .def("saveVTK",&escript::AbstractDomain::saveVTK)
122 .def("dump",&escript::AbstractDomain::dump)
123 .def("saveDX",&escript::AbstractDomain::saveDX)
124 .def("getMPISize",&escript::AbstractDomain::getMPISize)
125 .def("getMPIRank",&escript::AbstractDomain::getMPIRank)
126 .def("MPIBarrier",&escript::AbstractDomain::MPIBarrier)
127 .def("onMasterProcessor",&escript::AbstractDomain::onMasterProcessor)
128
129 .def(self == self)
130 .def(self != self);
131
132 //
133 // Interface for AbstractContinuousDomain
134 //
135 class_<escript::AbstractContinuousDomain, bases<escript::AbstractDomain> >("ContinuousDomain","Class representing continuous domains",no_init)
136 .def("getSystemMatrixTypeId",&escript::AbstractContinuousDomain::getSystemMatrixTypeId)
137 .def("getTransportTypeId",&escript::AbstractContinuousDomain::getTransportTypeId);
138
139
140 //
141 // Interface for TestDomain
142 //
143 class_ <escript::TestDomain, bases<escript::AbstractDomain> >("TestDomain", "Test Class for domains with no structure. May be removed from future releases without notice.", init<int,int>());
144
145 // This is the only python visible way to get a TestDomain
146 def("getTestDomainFunctionSpace",&escript::getTestDomainFunctionSpace, "For testing only. May be removed without notice.");
147
148 //
149 // Interface for FunctionSpace
150 //
151 class_<escript::FunctionSpace> fs_definer("FunctionSpace","",init<>()); // Doco goes in the empty string param
152 fs_definer.def("getDim",&escript::FunctionSpace::getDim);
153 // fs_definer.def("getDomain",&escript::FunctionSpace::getDomain,
154 // return_internal_reference<>());
155 fs_definer.def("getDomain",&escript::FunctionSpace::getDomainPython);
156 fs_definer.def("getX",&escript::FunctionSpace::getX);
157 fs_definer.def("getNormal",&escript::FunctionSpace::getNormal);
158 fs_definer.def("getSize",&escript::FunctionSpace::getSize);
159 fs_definer.def("setTags",&escript::FunctionSpace::setTags);
160 fs_definer.def("getTagFromDataPointNo",
161 &escript::FunctionSpace::getTagFromDataPointNo);
162 fs_definer.def("getReferenceIDFromDataPointNo", &escript::FunctionSpace::getReferenceIDFromDataPointNo);
163 fs_definer.def("getListOfTags",&escript::FunctionSpace::getListOfTags);
164 fs_definer.def("__str__", &escript::FunctionSpace::toString);
165 fs_definer.def(self == self);
166 fs_definer.def(self != self);
167 //
168 // Interface for Data
169 //
170 class_<escript::Data>("Data","Represents a collection of datapoints. It is used to store the values of a function. For more details please consult the c++ class documentation.",init<>() )
171 // various constructors for Data objects
172 .def(init<const object&, optional<const escript::FunctionSpace&, bool> >(args("value","what","expand")))
173 .def(init<const double, const tuple&, optional<const escript::FunctionSpace&, bool> >(args("value","shape","what","expand")))
174 .def(init<const escript::Data&, const escript::FunctionSpace&>(args("value","what")))
175 .def(init<const escript::Data&>())
176 // Note for Lutz, Need to specify the call policy in order to return a
177 // reference. In this case return_internal_reference.
178 .def("__str__",&escript::Data::toString)
179 .def("getDomain",&escript::Data::getDomainPython)
180 .def("getFunctionSpace",&escript::Data::getFunctionSpace,return_value_policy<copy_const_reference>())
181 .def("isEmpty",&escript::Data::isEmpty)
182 .def("isProtected",&escript::Data::isProtected)
183 .def("setProtection",&escript::Data::setProtection)
184 .def("getShape",&escript::Data::getShapeTuple)
185 .def("getRank",&escript::Data::getDataPointRank)
186 .def("dump",&escript::Data::dump)
187 .def("toListOfTuples",&escript::Data::toListOfTuples, (arg("scalarastuple")=true))
188 .def("copyWithMask",&escript::Data::copyWithMask)
189 .def("setTaggedValue",&escript::Data::setTaggedValue)
190 .def("setTaggedValue",&escript::Data::setTaggedValueByName)
191 .def("getNumberOfDataPoints",&escript::Data::getNumDataPoints)
192 .def("isExpanded",&escript::Data::isExpanded)
193 .def("isTagged",&escript::Data::isTagged)
194 .def("isConstant",&escript::Data::isConstant)
195 .def("isLazy",&escript::Data::isLazy)
196 .def("isReady",&escript::Data::isReady)
197 .def("expand",&escript::Data::expand)
198 .def("tag",&escript::Data::tag)
199 .def("resolve",&escript::Data::resolve)
200 .def("copy",&escript::Data::copy)
201 .def("copy",&escript::Data::copySelf)
202 .def("delay",&escript::Data::delay)
203 .def("setValueOfDataPoint",&escript::Data::setValueOfDataPointToPyObject)
204 .def("setValueOfDataPoint",&escript::Data::setValueOfDataPointToArray)
205 .def("setValueOfDataPoint",&escript::Data::setValueOfDataPoint)
206 .def("getTupleForDataPoint",&escript::Data::getValueOfDataPointAsTuple)
207 .def("getTupleForGlobalDataPoint",&escript::Data::getValueOfGlobalDataPointAsTuple)
208 .def("setToZero",&escript::Data::setToZero)
209 .def("interpolate",&escript::Data::interpolate)
210 .def("minGlobalDataPoint",&escript::Data::minGlobalDataPoint)
211 .def("maxGlobalDataPoint",&escript::Data::maxGlobalDataPoint)
212 .def("saveDX",&escript::Data::saveDX)
213 .def("saveVTK",&escript::Data::saveVTK)
214 .def("getTagNumber",&escript::Data::getTagNumber)
215 // Unary functions for Data
216 .def("_interpolate",&escript::Data::interpolate)
217 .def("_grad",&escript::Data::gradOn)
218 .def("_grad",&escript::Data::grad)
219 .def("_transpose",&escript::Data::transpose)
220 .def("_trace",&escript::Data::trace)
221 .def("_maxval",&escript::Data::maxval)
222 .def("_minval",&escript::Data::minval)
223 .def("_wherePositive",&escript::Data::wherePositive)
224 .def("_whereNegative",&escript::Data::whereNegative)
225 .def("_whereNonNegative",&escript::Data::whereNonNegative)
226 .def("_whereNonPositive",&escript::Data::whereNonPositive)
227 .def("_whereZero",&escript::Data::whereZero,(arg("tol")=0.0))
228 .def("_whereNonZero",&escript::Data::whereNonZero,(arg("tol")=0.0))
229 .def("_erf",&escript::Data::erf)
230 .def("_sin",&escript::Data::sin)
231 .def("_cos",&escript::Data::cos)
232 .def("_tan",&escript::Data::tan)
233 .def("_asin",&escript::Data::asin)
234 .def("_acos",&escript::Data::acos)
235 .def("_atan",&escript::Data::atan)
236 .def("_sinh",&escript::Data::sinh)
237 .def("_cosh",&escript::Data::cosh)
238 .def("_tanh",&escript::Data::tanh)
239 .def("_asinh",&escript::Data::asinh)
240 .def("_acosh",&escript::Data::acosh)
241 .def("_atanh",&escript::Data::atanh)
242 .def("_exp",&escript::Data::exp)
243 .def("_sqrt",&escript::Data::sqrt)
244 .def("_log10",&escript::Data::log10)
245 .def("_log",&escript::Data::log)
246 .def("_sign",&escript::Data::sign)
247 .def("_symmetric",&escript::Data::symmetric)
248 .def("_nonsymmetric",&escript::Data::nonsymmetric)
249 .def("_trace",&escript::Data::trace)
250 .def("_swap_axes",&escript::Data::swapaxes)
251 .def("_eigenvalues",&escript::Data::eigenvalues)
252 .def("_eigenvalues_and_eigenvectors",&escript::Data::eigenvalues_and_eigenvectors,(arg("tol")=1.e-13))
253 // functions returning a single real number:
254 .def("_Lsup",&escript::Data::Lsup)
255 .def("_sup",&escript::Data::sup)
256 .def("_inf",&escript::Data::inf)
257 .def("_integrateToTuple",&escript::Data::integrateToTuple)
258
259 // following implements the python abs operator
260 .def("__abs__",&escript::Data::abs)
261 // following implements the python "-" negation operator
262 .def("__neg__",&escript::Data::neg)
263 // following implements the python "+" identity operator
264 .def("__pos__",&escript::Data::pos)
265 // following two functions implement the python [] operator
266 .def("__getitem__",&escript::Data::getItem)
267 .def("__setitem__",&escript::Data::setItemO)
268 .def("__setitem__",&escript::Data::setItemD)
269 // following two functions implement the python ** operator
270 .def("__pow__",&escript::Data::powO)
271 .def("__pow__",&escript::Data::powD)
272 .def("__rpow__",&escript::Data::rpowO)
273 // NOTE:: The order of these declarations is important. Anything
274 // declared before the generic declaration isn't found so the generic
275 // version will be called.
276 .def(self + other<object>())
277 .def(other<object>() + self)
278 .def(self + self)
279 .def(self += other<object>())
280 .def(self += self)
281
282 .def(self - other<object>())
283 .def(other<object>() - self)
284 .def(self - self)
285 .def(self -= other<object>())
286 .def(self -= self)
287
288 .def(self * other<object>())
289 .def(other<object>() * self)
290 .def(self * self)
291 .def(self *= other<object>())
292 .def(self *= self)
293
294 .def(self / other<object>())
295 .def(other<object>() / self)
296 .def(self / self)
297 .def(self /= other<object>())
298 .def(self /= self)
299 // Need scope resolution due to a bug either in the compiler or
300 // the boost code. This calls operator << for Data.
301 .def(self_ns::str(self));
302
303 //
304 // Factory methods for function space
305 //
306 def("ContinuousFunction",escript::continuousFunction);
307 def("ReducedContinuousFunction",escript::reducedContinuousFunction);
308 def("Function",escript::function);
309 def("ReducedFunction",escript::reducedFunction);
310 def("FunctionOnBoundary",escript::functionOnBoundary);
311 def("ReducedFunctionOnBoundary",escript::reducedFunctionOnBoundary);
312 def("FunctionOnContactZero",escript::functionOnContactZero);
313 def("ReducedFunctionOnContactZero",escript::reducedFunctionOnContactZero);
314 def("FunctionOnContactOne",escript::functionOnContactOne);
315 def("ReducedFunctionOnContactOne",escript::reducedFunctionOnContactOne);
316 def("Solution",escript::solution);
317 def("ReducedSolution",escript::reducedSolution);
318 def("DiracDeltaFunction",escript::diracDeltaFunction);
319
320 //
321 // Factory methods for Data
322 //
323 def("load",escript::load);
324 def("loadIsConfigured",escript::loadConfigured);
325 def("Scalar",escript::Scalar,
326 (arg("value")=0.0,
327 arg("what")=escript::FunctionSpace(),
328 arg("expanded")=false));
329 def("Vector",escript::Vector,
330 (arg("value")=0.0,
331 arg("what")=escript::FunctionSpace(),
332 arg("expanded")=false));
333 def("Tensor",escript::Tensor,
334 (arg("value")=0.0,
335 arg("what")=escript::FunctionSpace(),
336 arg("expanded")=false));
337 def("Tensor3",escript::Tensor3,
338 (arg("value")=0.0,
339 arg("what")=escript::FunctionSpace(),
340 arg("expanded")=false));
341 def("Tensor4",escript::Tensor4,
342 (arg("value")=0.0,
343 arg("what")=escript::FunctionSpace(),
344 arg("expanded")=false));
345
346 //
347 // Binary operators
348 //
349 def("C_GeneralTensorProduct",escript::C_GeneralTensorProduct,
350 (arg("arg0")=escript::Data(),
351 arg("arg1")=escript::Data(),
352 arg("axis_offset")=0,
353 arg("transpose")=0));
354
355 //
356 // Interface for AbstractSystemMatrix
357 //
358 class_<escript::AbstractSystemMatrix>("Operator","",init<>()) // Doco goes in the empty string param
359 .def("isEmpty",&escript::AbstractSystemMatrix::isEmpty)
360 .def("solve",&escript::AbstractSystemMatrix::solve)
361 .def("of",&escript::AbstractSystemMatrix::vectorMultiply)
362 .def("saveMM",&escript::AbstractSystemMatrix::saveMM)
363 .def("saveHB",&escript::AbstractSystemMatrix::saveHB)
364 .def("resetValues",&escript::AbstractSystemMatrix::resetValues)
365 .def(self*other<escript::Data>());
366 //
367 // Interface for AbstractTransportProblem
368 //
369 class_<escript::AbstractTransportProblem>("TransportProblem","",init<>()) // Doco goes in the empty string param
370 .def("isEmpty",&escript::AbstractTransportProblem::isEmpty)
371 .def("solve",&escript::AbstractTransportProblem::solve)
372 .def("setInitialValue",&escript::AbstractTransportProblem::setInitialValue)
373 .def("insertConstraint",&escript::AbstractTransportProblem::insertConstraint)
374 .def("reset",&escript::AbstractTransportProblem::resetTransport)
375 .def("resetValues",&escript::AbstractTransportProblem::resetTransport)
376 .def("getSafeTimeStepSize",&escript::AbstractTransportProblem::getSafeTimeStepSize)
377 .def("getUnlimitedTimeStepSize",&escript::AbstractTransportProblem::getUnlimitedTimeStepSize);
378
379 // Functions to modify global parameters
380 def("setEscriptParamInt",escript::setEscriptParamInt,
381 (arg("value")=0));
382 def("getEscriptParamInt",escript::getEscriptParamInt,
383 (arg("sentinel")=0));
384 def("listEscriptParams",escript::listEscriptParams);
385
386 //
387 // Register esysExceptionTranslator
388 //
389 register_exception_translator<esysUtils::EsysException>(&esysUtils::esysExceptionTranslator);
390 }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26