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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1872 - (show annotations)
Mon Oct 13 00:18:55 2008 UTC (10 years, 11 months ago) by jfenwick
File size: 14034 byte(s)
Closing the moreshared branch

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
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
112 .def(self == self)
113 .def(self != self);
114
115 //
116 // Interface for AbstractContinuousDomain
117 //
118 class_<escript::AbstractContinuousDomain, bases<escript::AbstractDomain> >("ContinuousDomain",no_init)
119 .def("getSystemMatrixTypeId",&escript::AbstractContinuousDomain::getSystemMatrixTypeId)
120 .def("getTransportTypeId",&escript::AbstractContinuousDomain::getTransportTypeId);
121
122 //
123 // Interface for FunctionSpace
124 //
125 class_<escript::FunctionSpace> fs_definer("FunctionSpace",init<>());
126 fs_definer.def("getDim",&escript::FunctionSpace::getDim);
127 // fs_definer.def("getDomain",&escript::FunctionSpace::getDomain,
128 // return_internal_reference<>());
129 fs_definer.def("getDomain",&escript::FunctionSpace::getDomainPython);
130 fs_definer.def("getX",&escript::FunctionSpace::getX);
131 fs_definer.def("getNormal",&escript::FunctionSpace::getNormal);
132 fs_definer.def("getSize",&escript::FunctionSpace::getSize);
133 fs_definer.def("setTags",&escript::FunctionSpace::setTags);
134 fs_definer.def("getTagFromDataPointNo",
135 &escript::FunctionSpace::getTagFromDataPointNo);
136 fs_definer.def("getReferenceIDFromDataPointNo", &escript::FunctionSpace::getReferenceIDFromDataPointNo);
137 fs_definer.def("getListOfTags",&escript::FunctionSpace::getListOfTags);
138 fs_definer.def("__str__", &escript::FunctionSpace::toString);
139 fs_definer.def(self == self);
140 fs_definer.def(self != self);
141 //
142 // Interface for Data
143 //
144 class_<escript::Data>("Data","TEST DOCUMENTATION",init<>() )
145 // various constructors for Data objects
146 .def(init<const numeric::array&, optional<const escript::FunctionSpace&, bool> >(args("value","what","expand")))
147 .def(init<const object&, optional<const escript::FunctionSpace&, bool> >(args("value","what","expand")))
148 .def(init<const double, const tuple&, optional<const escript::FunctionSpace&, bool> >(args("value","shape","what","expand")))
149 .def(init<const escript::Data&, const escript::FunctionSpace&>(args("value","what")))
150 .def(init<const escript::Data&>())
151 // Note for Lutz, Need to specify the call policy in order to return a
152 // reference. In this case return_internal_reference.
153 .def("__str__",&escript::Data::toString)
154 // .def("getDomain",&escript::Data::getDomain,return_internal_reference<>())
155 .def("getDomain",&escript::Data::getDomainPython)
156 .def("getFunctionSpace",&escript::Data::getFunctionSpace,return_value_policy<copy_const_reference>())
157 .def("isEmpty",&escript::Data::isEmpty)
158 .def("isProtected",&escript::Data::isProtected)
159 .def("setProtection",&escript::Data::setProtection)
160 .def("getShape",&escript::Data::getShapeTuple)
161 .def("getRank",&escript::Data::getDataPointRank)
162 .def("dump",&escript::Data::dump)
163 .def("copyWithMask",&escript::Data::copyWithMask)
164 .def("setTaggedValue",&escript::Data::setTaggedValue)
165 .def("setTaggedValue",&escript::Data::setTaggedValueByName)
166 .def("getNumberOfDataPoints",&escript::Data::getNumDataPoints)
167 .def("isExpanded",&escript::Data::isExpanded)
168 .def("isTagged",&escript::Data::isTagged)
169 .def("expand",&escript::Data::expand)
170 .def("tag",&escript::Data::tag)
171 .def("copy",&escript::Data::copy)
172 .def("copy",&escript::Data::copySelf,return_value_policy<manage_new_object>())
173 .def("setValueOfDataPoint",&escript::Data::setValueOfDataPointToPyObject)
174 .def("setValueOfDataPoint",&escript::Data::setValueOfDataPointToArray)
175 .def("setValueOfDataPoint",&escript::Data::setValueOfDataPoint)
176 .def("getValueOfDataPoint",&escript::Data::getValueOfDataPoint)
177 .def("getValueOfGlobalDataPoint",&escript::Data::getValueOfGlobalDataPoint)
178 .def("setToZero",&escript::Data::setToZero)
179 .def("interpolate",&escript::Data::interpolate)
180 .def("minGlobalDataPoint",&escript::Data::minGlobalDataPoint)
181 .def("saveDX",&escript::Data::saveDX)
182 .def("saveVTK",&escript::Data::saveVTK)
183 .def("getTagNumber",&escript::Data::getTagNumber)
184 // Unary functions for Data
185 .def("_interpolate",&escript::Data::interpolate)
186 .def("_grad",&escript::Data::gradOn)
187 .def("_grad",&escript::Data::grad)
188 .def("_transpose",&escript::Data::transpose)
189 .def("_trace",&escript::Data::trace)
190 .def("_maxval",&escript::Data::maxval)
191 .def("_minval",&escript::Data::minval)
192 .def("_wherePositive",&escript::Data::wherePositive)
193 .def("_whereNegative",&escript::Data::whereNegative)
194 .def("_whereNonNegative",&escript::Data::whereNonNegative)
195 .def("_whereNonPositive",&escript::Data::whereNonPositive)
196 .def("_whereZero",&escript::Data::whereZero,(arg("tol")=0.0))
197 .def("_whereNonZero",&escript::Data::whereNonZero,(arg("tol")=0.0))
198 .def("_erf",&escript::Data::erf)
199 .def("_sin",&escript::Data::sin)
200 .def("_cos",&escript::Data::cos)
201 .def("_tan",&escript::Data::tan)
202 .def("_asin",&escript::Data::asin)
203 .def("_acos",&escript::Data::acos)
204 .def("_atan",&escript::Data::atan)
205 .def("_sinh",&escript::Data::sinh)
206 .def("_cosh",&escript::Data::cosh)
207 .def("_tanh",&escript::Data::tanh)
208 .def("_asinh",&escript::Data::asinh)
209 .def("_acosh",&escript::Data::acosh)
210 .def("_atanh",&escript::Data::atanh)
211 .def("_exp",&escript::Data::exp)
212 .def("_sqrt",&escript::Data::sqrt)
213 .def("_log10",&escript::Data::log10)
214 .def("_log",&escript::Data::log)
215 .def("_sign",&escript::Data::sign)
216 .def("_symmetric",&escript::Data::symmetric)
217 .def("_nonsymmetric",&escript::Data::nonsymmetric)
218 .def("_trace",&escript::Data::trace)
219 .def("_swap_axes",&escript::Data::swapaxes)
220 .def("_eigenvalues",&escript::Data::eigenvalues)
221 .def("_eigenvalues_and_eigenvectors",&escript::Data::eigenvalues_and_eigenvectors,(arg("tol")=1.e-13))
222 // functions returning a single real number:
223 .def("_Lsup",&escript::Data::Lsup)
224 .def("_sup",&escript::Data::sup)
225 .def("_inf",&escript::Data::inf)
226 .def("_integrate",&escript::Data::integrate)
227
228 // following implements the python abs operator
229 .def("__abs__",&escript::Data::abs)
230 // following implements the python "-" negation operator
231 .def("__neg__",&escript::Data::neg)
232 // following implements the python "+" identity operator
233 .def("__pos__",&escript::Data::pos)
234 // following two functions implement the python [] operator
235 .def("__getitem__",&escript::Data::getItem)
236 .def("__setitem__",&escript::Data::setItemO)
237 .def("__setitem__",&escript::Data::setItemD)
238 // following two functions implement the python ** operator
239 .def("__pow__",&escript::Data::powO)
240 .def("__pow__",&escript::Data::powD)
241 .def("__rpow__",&escript::Data::rpowO)
242 // NOTE:: The order of these declarations is important. Anything
243 // declared before the generic declaration isn't found so the generic
244 // version will be called.
245 .def(self + other<object>())
246 .def(other<object>() + self)
247 .def(self + self)
248 .def(self += other<object>())
249 .def(self += self)
250
251 .def(self - other<object>())
252 .def(other<object>() - self)
253 .def(self - self)
254 .def(self -= other<object>())
255 .def(self -= self)
256
257 .def(self * other<object>())
258 .def(other<object>() * self)
259 .def(self * self)
260 .def(self *= other<object>())
261 .def(self *= self)
262
263 .def(self / other<object>())
264 .def(other<object>() / self)
265 .def(self / self)
266 .def(self /= other<object>())
267 .def(self /= self)
268 // Need scope resolution due to a bug either in the compiler or
269 // the boost code. This calls operator << for Data.
270 .def(self_ns::str(self));
271
272 //
273 // Factory methods for function space
274 //
275 def("ContinuousFunction",escript::continuousFunction);
276 def("ReducedContinuousFunction",escript::reducedContinuousFunction);
277 def("Function",escript::function);
278 def("ReducedFunction",escript::reducedFunction);
279 def("FunctionOnBoundary",escript::functionOnBoundary);
280 def("ReducedFunctionOnBoundary",escript::reducedFunctionOnBoundary);
281 def("FunctionOnContactZero",escript::functionOnContactZero);
282 def("ReducedFunctionOnContactZero",escript::reducedFunctionOnContactZero);
283 def("FunctionOnContactOne",escript::functionOnContactOne);
284 def("ReducedFunctionOnContactOne",escript::reducedFunctionOnContactOne);
285 def("Solution",escript::solution);
286 def("ReducedSolution",escript::reducedSolution);
287 def("DiracDeltaFunction",escript::diracDeltaFunction);
288
289 //
290 // Factory methods for Data
291 //
292 def("load",escript::load);
293 def("loadIsConfigured",escript::loadConfigured);
294 def("Scalar",escript::Scalar,
295 (arg("value")=0.0,
296 arg("what")=escript::FunctionSpace(),
297 arg("expanded")=false));
298 def("Vector",escript::Vector,
299 (arg("value")=0.0,
300 arg("what")=escript::FunctionSpace(),
301 arg("expanded")=false));
302 def("Tensor",escript::Tensor,
303 (arg("value")=0.0,
304 arg("what")=escript::FunctionSpace(),
305 arg("expanded")=false));
306 def("Tensor3",escript::Tensor3,
307 (arg("value")=0.0,
308 arg("what")=escript::FunctionSpace(),
309 arg("expanded")=false));
310 def("Tensor4",escript::Tensor4,
311 (arg("value")=0.0,
312 arg("what")=escript::FunctionSpace(),
313 arg("expanded")=false));
314
315 //
316 // Binary operators
317 //
318 def("C_GeneralTensorProduct",escript::C_GeneralTensorProduct,
319 (arg("arg0")=escript::Data(),
320 arg("arg1")=escript::Data(),
321 arg("axis_offset")=0,
322 arg("transpose")=0));
323
324 //
325 // Interface for AbstractSystemMatrix
326 //
327 class_<escript::AbstractSystemMatrix>("Operator",init<>())
328 .def("isEmpty",&escript::AbstractSystemMatrix::isEmpty)
329 .def("solve",&escript::AbstractSystemMatrix::solve)
330 .def("of",&escript::AbstractSystemMatrix::vectorMultiply)
331 .def("saveMM",&escript::AbstractSystemMatrix::saveMM)
332 .def("saveHB",&escript::AbstractSystemMatrix::saveHB)
333 .def("resetValues",&escript::AbstractSystemMatrix::resetValues)
334 .def(self*other<escript::Data>());
335 //
336 // Interface for AbstractTransportProblem
337 //
338 class_<escript::AbstractTransportProblem>("TransportProblem",init<>())
339 .def("isEmpty",&escript::AbstractTransportProblem::isEmpty)
340 .def("solve",&escript::AbstractTransportProblem::solve)
341 .def("setInitialValue",&escript::AbstractTransportProblem::setInitialValue)
342 .def("insertConstraint",&escript::AbstractTransportProblem::insertConstraint)
343 .def("reset",&escript::AbstractTransportProblem::resetTransport)
344 .def("resetValues",&escript::AbstractTransportProblem::resetTransport)
345 .def("getSafeTimeStepSize",&escript::AbstractTransportProblem::getSafeTimeStepSize)
346 .def("getUnlimitedTimeStepSize",&escript::AbstractTransportProblem::getUnlimitedTimeStepSize);
347
348 //
349 // Register esysExceptionTranslator
350 //
351 register_exception_translator<esysUtils::EsysException>(&esysUtils::esysExceptionTranslator);
352
353 }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26