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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2005 - (show annotations)
Mon Nov 10 01:21:39 2008 UTC (10 years, 11 months ago) by jfenwick
File size: 14626 byte(s)
Bringing all changes across from schroedinger.
(Note this does not mean development is done, just that it will happen
on the trunk for now).
If anyone notices any problems please contact me.


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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26