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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1141 - (show annotations)
Tue May 15 04:24:51 2007 UTC (12 years, 5 months ago) by gross
File size: 12126 byte(s)
Some changes to make things run on windows. There is still a problem with netcdf an long file names on windows but there is the suspicion that this is a bigger problem related to boost (compiler options). In fact runs with large numbers of iteration/time steps tend to create seg faults. 
1 //$Id$
2 /*
3 ************************************************************
4 * Copyright 2006 by ACcESS MNRF *
5 * *
6 * http://www.access.edu.au *
7 * Primary Business: Queensland, Australia *
8 * Licensed under the Open Software License version 3.0 *
9 * http://www.opensource.org/licenses/osl-3.0.php *
10 * *
11 ************************************************************
12 */
13
14 #include "Data.h"
15 #include "FunctionSpace.h"
16 #include "FunctionSpaceFactory.h"
17 #include "DataFactory.h"
18 #include "AbstractContinuousDomain.h"
19 #include "AbstractDomain.h"
20 #include "Utils.h"
21 #include "AbstractSystemMatrix.h"
22 #include "DataVector.h"
23
24 #include "esysUtils/esysExceptionTranslator.h"
25
26 #include <boost/python.hpp>
27 #include <boost/python/module.hpp>
28 #include <boost/python/def.hpp>
29 #include <boost/python/object.hpp>
30 #include <boost/python/tuple.hpp>
31 #include <boost/python/numeric.hpp>
32
33 using namespace boost::python;
34
35 /*! \mainpage Esys Documentation
36 *
37 * \version 1.0.0
38 *
39 * - \ref escript
40 *
41 * - \ref esys_exception "Esys Exception"
42 *
43 * - \ref finley
44 *
45 * - <a href=http://iservo.edu.au/esys/epydoc/index.html>Python module documentation (epydoc generated)</a>
46 *
47 */
48
49 /*! \page escript Escript
50 * Escript is the python module that contains the interfaces
51 * to the C++ side of escript.
52 *
53 * \version 1.0.0
54 *
55 * \section class_desc Class Description:
56 * Data
57 *
58 * \section class_limits Class Limitations:
59 * None
60 *
61 * \section class_conds Class Conditions of Use:
62 * None
63 *
64 * \section class_throws Throws:
65 * None
66 *
67 */
68
69 BOOST_PYTHON_MODULE(escriptcpp)
70 {
71 def("setNumberOfThreads",escript::setNumberOfThreads);
72 def("getNumberOfThreads",escript::getNumberOfThreads);
73 def("releaseUnusedMemory",escript::releaseUnusedMemory);
74
75
76 //
77 // Interface for AbstractDomain
78 //
79 class_<escript::AbstractDomain>("Domain",no_init)
80 .def("__str__",&escript::AbstractDomain::str)
81 .def("setTagMap",&escript::AbstractDomain::setTagMap)
82 .def("getTag",&escript::AbstractDomain::getTag)
83 .def("isValidTagName",&escript::AbstractDomain::isValidTagName)
84 .def("showTagNames",&escript::AbstractDomain::showTagNames)
85 .def("getX",&escript::AbstractDomain::getX)
86 .def("getNormal",&escript::AbstractDomain::getNormal)
87 .def("getSize",&escript::AbstractDomain::getSize)
88 .def("saveVTK",&escript::AbstractDomain::saveVTK)
89 .def("saveDX",&escript::AbstractDomain::saveDX)
90 .def(self == self)
91 .def(self != self);
92
93 //
94 // Interface for AbstractContinuousDomain
95 //
96 class_<escript::AbstractContinuousDomain, bases<escript::AbstractDomain> >("ContinuousDomain",no_init)
97 .def("getSystemMatrixTypeId",&escript::AbstractContinuousDomain::getSystemMatrixTypeId);
98
99 //
100 // Interface for FunctionSpace
101 //
102 class_<escript::FunctionSpace>("FunctionSpace",init<>())
103 .def("getDim",&escript::FunctionSpace::getDim)
104 .def("getDomain",&escript::FunctionSpace::getDomain,return_internal_reference<>())
105 .def("getX",&escript::FunctionSpace::getX)
106 .def("getNormal",&escript::FunctionSpace::getNormal)
107 .def("getSize",&escript::FunctionSpace::getSize)
108 .def("setTags",&escript::FunctionSpace::setTags)
109 .def("getTagFromDataPointNo",&escript::FunctionSpace::getTagFromDataPointNo)
110 .def("__str__",&escript::FunctionSpace::str)
111 .def(self == self)
112 .def(self != self);
113 //
114 // Interface for Data
115 //
116 class_<escript::Data>("Data","TEST DOCUMENTATION",init<>())
117 // various constructors for Data objects
118 .def(init<const numeric::array&, optional<const escript::FunctionSpace&, bool> >(args("value","what","expand")))
119 .def(init<const object&, optional<const escript::FunctionSpace&, bool> >(args("value","what","expand")))
120 .def(init<const double, const tuple&, optional<const escript::FunctionSpace&, bool> >(args("value","shape","what","expand")))
121 .def(init<const escript::Data&, const escript::FunctionSpace&>(args("value","what")))
122 .def(init<const escript::Data&>())
123 // Note for Lutz, Need to specify the call policy in order to return a
124 // reference. In this case return_internal_reference.
125 .def("__str__",&escript::Data::str)
126 .def("getDomain",&escript::Data::getDomain,return_internal_reference<>())
127 .def("getFunctionSpace",&escript::Data::getFunctionSpace,return_internal_reference<>())
128 .def("isEmpty",&escript::Data::isEmpty)
129 .def("isProtected",&escript::Data::isProtected)
130 .def("setProtection",&escript::Data::setProtection)
131 .def("getShape",&escript::Data::getShapeTuple)
132 .def("getRank",&escript::Data::getDataPointRank)
133 .def("dump",&escript::Data::dump)
134 .def("copyWithMask",&escript::Data::copyWithMask)
135 .def("setTaggedValue",&escript::Data::setTaggedValue)
136 .def("setTaggedValue",&escript::Data::setTaggedValueByName)
137 .def("getNumberOfDataPoints",&escript::Data::getNumDataPoints)
138 .def("isExpanded",&escript::Data::isExpanded)
139 .def("isTagged",&escript::Data::isTagged)
140 .def("expand",&escript::Data::expand)
141 .def("tag",&escript::Data::tag)
142 .def("copy",&escript::Data::copy)
143 .def("setValueOfDataPoint",&escript::Data::setValueOfDataPointToPyObject)
144 .def("setValueOfDataPoint",&escript::Data::setValueOfDataPointToArray)
145 .def("setValueOfDataPoint",&escript::Data::setValueOfDataPoint)
146 .def("getValueOfDataPoint",&escript::Data::getValueOfDataPoint)
147 .def("getValueOfGlobalDataPoint",&escript::Data::getValueOfGlobalDataPoint)
148 .def("setToZero",&escript::Data::setToZero)
149 .def("interpolate",&escript::Data::interpolate)
150 .def("minGlobalDataPoint",&escript::Data::minGlobalDataPoint)
151 .def("saveDX",&escript::Data::saveDX)
152 .def("saveVTK",&escript::Data::saveVTK)
153 .def("getTagNumber",&escript::Data::getTagNumber)
154 .def("archiveData",&escript::Data::archiveData)
155 .def("extractData",&escript::Data::extractData)
156 // Unary functions for Data
157 .def("_interpolate",&escript::Data::interpolate)
158 .def("_grad",&escript::Data::gradOn)
159 .def("_grad",&escript::Data::grad)
160 .def("_transpose",&escript::Data::transpose)
161 .def("_trace",&escript::Data::trace)
162 .def("_maxval",&escript::Data::maxval)
163 .def("_minval",&escript::Data::minval)
164 .def("_wherePositive",&escript::Data::wherePositive)
165 .def("_whereNegative",&escript::Data::whereNegative)
166 .def("_whereNonNegative",&escript::Data::whereNonNegative)
167 .def("_whereNonPositive",&escript::Data::whereNonPositive)
168 .def("_whereZero",&escript::Data::whereZero,(arg("tol")=0.0))
169 .def("_whereNonZero",&escript::Data::whereNonZero,(arg("tol")=0.0))
170 .def("_erf",&escript::Data::erf)
171 .def("_sin",&escript::Data::sin)
172 .def("_cos",&escript::Data::cos)
173 .def("_tan",&escript::Data::tan)
174 .def("_asin",&escript::Data::asin)
175 .def("_acos",&escript::Data::acos)
176 .def("_atan",&escript::Data::atan)
177 .def("_sinh",&escript::Data::sinh)
178 .def("_cosh",&escript::Data::cosh)
179 .def("_tanh",&escript::Data::tanh)
180 .def("_asinh",&escript::Data::asinh)
181 .def("_acosh",&escript::Data::acosh)
182 .def("_atanh",&escript::Data::atanh)
183 .def("_exp",&escript::Data::exp)
184 .def("_sqrt",&escript::Data::sqrt)
185 .def("_log10",&escript::Data::log10)
186 .def("_log",&escript::Data::log)
187 .def("_sign",&escript::Data::sign)
188 .def("_symmetric",&escript::Data::symmetric)
189 .def("_nonsymmetric",&escript::Data::nonsymmetric)
190 .def("_trace",&escript::Data::trace)
191 .def("_swap_axes",&escript::Data::swapaxes)
192 .def("_eigenvalues",&escript::Data::eigenvalues)
193 .def("_eigenvalues_and_eigenvectors",&escript::Data::eigenvalues_and_eigenvectors,(arg("tol")=1.e-13))
194 // functions returning a single real number:
195 .def("_Lsup",&escript::Data::Lsup)
196 .def("_sup",&escript::Data::sup)
197 .def("_inf",&escript::Data::inf)
198 .def("_integrate",&escript::Data::integrate)
199
200 // following implements the python abs operator
201 .def("__abs__",&escript::Data::abs)
202 // following implements the python "-" negation operator
203 .def("__neg__",&escript::Data::neg)
204 // following implements the python "+" identity operator
205 .def("__pos__",&escript::Data::pos)
206 // following two functions implement the python [] operator
207 .def("__getitem__",&escript::Data::getItem)
208 .def("__setitem__",&escript::Data::setItemO)
209 .def("__setitem__",&escript::Data::setItemD)
210 // following two functions implement the python ** operator
211 .def("__pow__",&escript::Data::powO)
212 .def("__pow__",&escript::Data::powD)
213 .def("__rpow__",&escript::Data::rpowO)
214 // NOTE:: The order of these declarations is important. Anything
215 // declared before the generic declaration isn't found so the generic
216 // version will be called.
217 .def(self + other<object>())
218 .def(other<object>() + self)
219 .def(self + self)
220 .def(self += other<object>())
221 .def(self += self)
222
223 .def(self - other<object>())
224 .def(other<object>() - self)
225 .def(self - self)
226 .def(self -= other<object>())
227 .def(self -= self)
228
229 .def(self * other<object>())
230 .def(other<object>() * self)
231 .def(self * self)
232 .def(self *= other<object>())
233 .def(self *= self)
234
235 .def(self / other<object>())
236 .def(other<object>() / self)
237 .def(self / self)
238 .def(self /= other<object>())
239 .def(self /= self)
240 // Need scope resolution due to a bug either in the compiler or
241 // the boost code. This calls operator << for Data.
242 .def(self_ns::str(self));
243
244 //
245 // Factory methods for function space
246 //
247 def("ContinuousFunction",escript::continuousFunction);
248 def("ReducedContinuousFunction",escript::reducedContinuousFunction);
249 def("Function",escript::function);
250 def("ReducedFunction",escript::reducedFunction);
251 def("FunctionOnBoundary",escript::functionOnBoundary);
252 def("ReducedFunctionOnBoundary",escript::reducedFunctionOnBoundary);
253 def("FunctionOnContactZero",escript::functionOnContactZero);
254 def("ReducedFunctionOnContactZero",escript::reducedFunctionOnContactZero);
255 def("FunctionOnContactOne",escript::functionOnContactOne);
256 def("ReducedFunctionOnContactOne",escript::reducedFunctionOnContactOne);
257 def("Solution",escript::solution);
258 def("ReducedSolution",escript::reducedSolution);
259 def("DiracDeltaFunction",escript::diracDeltaFunction);
260
261 //
262 // Factory methods for Data
263 //
264 def("load",escript::load);
265 def("loadIsConfigured",escript::loadConfigured);
266 def("Scalar",escript::Scalar,
267 (arg("value")=0.0,
268 arg("what")=escript::FunctionSpace(),
269 arg("expanded")=false));
270 def("Vector",escript::Vector,
271 (arg("value")=0.0,
272 arg("what")=escript::FunctionSpace(),
273 arg("expanded")=false));
274 def("Tensor",escript::Tensor,
275 (arg("value")=0.0,
276 arg("what")=escript::FunctionSpace(),
277 arg("expanded")=false));
278 def("Tensor3",escript::Tensor3,
279 (arg("value")=0.0,
280 arg("what")=escript::FunctionSpace(),
281 arg("expanded")=false));
282 def("Tensor4",escript::Tensor4,
283 (arg("value")=0.0,
284 arg("what")=escript::FunctionSpace(),
285 arg("expanded")=false));
286
287 //
288 // Binary operators
289 //
290 def("C_GeneralTensorProduct",escript::C_GeneralTensorProduct,
291 (arg("arg0")=escript::Data(),
292 arg("arg1")=escript::Data(),
293 arg("axis_offset")=0,
294 arg("transpose")=0));
295
296 //
297 // Interface for AbstractSystemMatrix
298 //
299 class_<escript::AbstractSystemMatrix>("Operator",init<>())
300 .def("isEmpty",&escript::AbstractSystemMatrix::isEmpty)
301 .def("solve",&escript::AbstractSystemMatrix::solve)
302 .def("of",&escript::AbstractSystemMatrix::vectorMultiply)
303 .def("saveMM",&escript::AbstractSystemMatrix::saveMM)
304 .def("saveHB",&escript::AbstractSystemMatrix::saveHB)
305 .def("resetValues",&escript::AbstractSystemMatrix::resetValues)
306 .def(self*other<escript::Data>());
307
308 //
309 // Register esysExceptionTranslator
310 //
311 register_exception_translator<esysUtils::EsysException>(&esysUtils::esysExceptionTranslator);
312
313 }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26