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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1828 - (show annotations)
Thu Oct 2 04:52:11 2008 UTC (11 years, 4 months ago) by jfenwick
File size: 15114 byte(s)
Branch commit.
Added getPtr to DataAbstract.
Passes all unit tests.


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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26