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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2453 - (show annotations)
Tue Jun 2 22:54:20 2009 UTC (9 years, 8 months ago) by jfenwick
File size: 15620 byte(s)
Removing NONUMARRAY defines

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26