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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 667 - (show annotations)
Fri Mar 24 13:25:00 2006 UTC (15 years, 1 month ago) by robwdcock
File size: 10455 byte(s)
+ OUCH ARGHH
+ Okay the wizzy linkHack doesn't work. Not sure why but py_tests fail
when the shared library is on the link line directly (without a -l)

+ Unfortunately we can't figure out how to use -l without it prepending
a lib prefix. Hence all the shareable objects in python now need to be
called libblah.so (and lib will need to be prepended on windows!!!!).
This is not the python way and its very annoying. Why do we have this
problem? Because the C++ shared libraries link with each other.


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 "DataVariable.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
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(libescriptcpp)
70 {
71 def("setNumberOfThreads",escript::setNumberOfThreads);
72 def("getNumberOfThreads",escript::getNumberOfThreads);
73
74 //
75 // Interface for AbstractDomain
76 //
77 class_<escript::AbstractDomain>("Domain",no_init)
78 .def("getX",&escript::AbstractDomain::getX)
79 .def("getNormal",&escript::AbstractDomain::getNormal)
80 .def("getSize",&escript::AbstractDomain::getSize)
81 .def("saveVTK",&escript::AbstractDomain::saveVTK)
82 .def("saveDX",&escript::AbstractDomain::saveDX)
83 .def(self == self)
84 .def(self != self);
85
86 //
87 // Interface for AbstractContinuousDomain
88 //
89 class_<escript::AbstractContinuousDomain, bases<escript::AbstractDomain> >("ContinuousDomain",no_init)
90 .def("getSystemMatrixTypeId",&escript::AbstractContinuousDomain::getSystemMatrixTypeId);
91
92 //
93 // Interface for FunctionSpace
94 //
95 class_<escript::FunctionSpace>("FunctionSpace",init<>())
96 .def("getDim",&escript::FunctionSpace::getDim)
97 .def("getDomain",&escript::FunctionSpace::getDomain,return_internal_reference<>())
98 .def("getX",&escript::FunctionSpace::getX)
99 .def("getNormal",&escript::FunctionSpace::getNormal)
100 .def("getSize",&escript::FunctionSpace::getSize)
101 .def("getTagFromDataPointNo",&escript::FunctionSpace::getTagFromDataPointNo)
102 .def("__str__",&escript::FunctionSpace::toString)
103 .def(self == self)
104 .def(self != self);
105 //
106 // Interface for Data
107 //
108 class_<escript::Data>("Data","TEST DOCUMENTATION",init<>())
109 // various constructors for Data objects
110 .def(init<const numeric::array&, optional<const escript::FunctionSpace&, bool> >(args("value","what","expand")))
111 .def(init<const object&, optional<const escript::FunctionSpace&, bool> >(args("value","what","expand")))
112 .def(init<const double, const tuple&, optional<const escript::FunctionSpace&, bool> >(args("value","shape","what","expand")))
113 .def(init<const escript::Data&, const escript::FunctionSpace&>(args("value","what")))
114 .def(init<const escript::Data&>())
115 // Note for Lutz, Need to specify the call policy in order to return a
116 // reference. In this case return_internal_reference.
117 .def("__str__",&escript::Data::toString)
118 .def("getDomain",&escript::Data::getDomain,return_internal_reference<>())
119 .def("getFunctionSpace",&escript::Data::getFunctionSpace,return_internal_reference<>())
120 .def("isEmpty",&escript::Data::isEmpty)
121 .def("getShape",&escript::Data::getShapeTuple)
122 .def("getRank",&escript::Data::getDataPointRank)
123 .def("copyWithMask",&escript::Data::copyWithMask)
124 .def("setTaggedValue",&escript::Data::setTaggedValue)
125 .def("setRefValue",&escript::Data::setRefValue)
126 .def("getRefValue",&escript::Data::getRefValue)
127 .def("expand",&escript::Data::expand)
128 .def("tag",&escript::Data::tag)
129 .def("copy",&escript::Data::copy)
130 .def("convertToNumArray",&escript::Data::convertToNumArray)
131 .def("convertToNumArrayFromSampleNo",&escript::Data::convertToNumArrayFromSampleNo)
132 .def("convertToNumArrayFromDPNo",&escript::Data::convertToNumArrayFromDPNo)
133 .def("fillFromNumArray",&escript::Data::fillFromNumArray)
134 .def("interpolate",&escript::Data::interpolate)
135 .def("mindp",&escript::Data::mindp)
136 .def("saveDX",&escript::Data::saveDX)
137 .def("saveVTK",&escript::Data::saveVTK)
138 .def("getTagNumber",&escript::Data::getTagNumber)
139 .def("archiveData",&escript::Data::archiveData)
140 .def("extractData",&escript::Data::extractData)
141 // Unary functions for Data
142 .def("_interpolate",&escript::Data::interpolate)
143 .def("_grad",&escript::Data::gradOn)
144 .def("_grad",&escript::Data::grad)
145 .def("_transpose",&escript::Data::transpose)
146 .def("_trace",&escript::Data::trace)
147 .def("_maxval",&escript::Data::maxval)
148 .def("_minval",&escript::Data::minval)
149 .def("_wherePositive",&escript::Data::wherePositive,(arg("tol")=0.0))
150 .def("_whereNegative",&escript::Data::whereNegative,(arg("tol")=0.0))
151 .def("_whereNonNegative",&escript::Data::whereNonNegative,(arg("tol")=0.0))
152 .def("_whereNonPositive",&escript::Data::whereNonPositive,(arg("tol")=0.0))
153 .def("_whereZero",&escript::Data::whereZero,(arg("tol")=0.0))
154 .def("_whereNonZero",&escript::Data::whereNonZero,(arg("tol")=0.0))
155 .def("_sin",&escript::Data::sin)
156 .def("_cos",&escript::Data::cos)
157 .def("_tan",&escript::Data::tan)
158 .def("_asin",&escript::Data::asin)
159 .def("_acos",&escript::Data::acos)
160 .def("_atan",&escript::Data::atan)
161 .def("_sinh",&escript::Data::sinh)
162 .def("_cosh",&escript::Data::cosh)
163 .def("_tanh",&escript::Data::tanh)
164 .def("_asinh",&escript::Data::asinh)
165 .def("_acosh",&escript::Data::acosh)
166 .def("_atanh",&escript::Data::atanh)
167 .def("_exp",&escript::Data::exp)
168 .def("_sqrt",&escript::Data::sqrt)
169 .def("_log10",&escript::Data::log10)
170 .def("_log",&escript::Data::log)
171 .def("_sign",&escript::Data::sign)
172 .def("_eigenvalues",&escript::Data::eigenvalues)
173 .def("_eigenvalues_and_eigenvectors",&escript::Data::eigenvalues_and_eigenvectors,(arg("tol")=1.e-13))
174 // functions returning a single real number:
175 .def("_Lsup",&escript::Data::Lsup)
176 .def("_sup",&escript::Data::sup)
177 .def("_inf",&escript::Data::inf)
178 .def("_integrate",&escript::Data::integrate)
179
180 // following implements the python abs operator
181 .def("__abs__",&escript::Data::abs)
182 // following implements the python "-" negation operator
183 .def("__neg__",&escript::Data::neg)
184 // following implements the python "+" identity operator
185 .def("__pos__",&escript::Data::pos)
186 // following two functions implement the python [] operator
187 .def("__getitem__",&escript::Data::getItem)
188 .def("__setitem__",&escript::Data::setItemO)
189 .def("__setitem__",&escript::Data::setItemD)
190 // following two functions implement the python ** operator
191 .def("__pow__",&escript::Data::powO)
192 .def("__pow__",&escript::Data::powD)
193 // NOTE:: The order of these declarations is important. Anything
194 // declared before the generic declaration isn't found so the generic
195 // version will be called.
196 .def(self + other<object>())
197 .def(other<object>() + self)
198 .def(self + self)
199 .def(self += other<object>())
200 .def(self += self)
201
202 .def(self - other<object>())
203 .def(other<object>() - self)
204 .def(self - self)
205 .def(self -= other<object>())
206 .def(self -= self)
207
208 .def(self * other<object>())
209 .def(other<object>() * self)
210 .def(self * self)
211 .def(self *= other<object>())
212 .def(self *= self)
213
214 .def(self / other<object>())
215 .def(other<object>() / self)
216 .def(self / self)
217 .def(self /= other<object>())
218 .def(self /= self)
219 // Need scope resolution due to a bug either in the compiler or
220 // the boost code. This calls operator << for Data.
221 .def(self_ns::str(self));
222
223 //
224 // Factory methods for function space
225 //
226 def("ContinuousFunction",escript::continuousFunction);
227 def("Function",escript::function);
228 def("FunctionOnBoundary",escript::functionOnBoundary);
229 def("FunctionOnContactZero",escript::functionOnContactZero);
230 def("FunctionOnContactOne",escript::functionOnContactOne);
231 def("Solution",escript::solution);
232 def("ReducedSolution",escript::reducedSolution);
233 def("DiracDeltaFunction",escript::diracDeltaFunction);
234
235 //
236 // Factory methods for Data
237 //
238 def("Scalar",escript::Scalar,
239 (arg("value")=0.0,
240 arg("what")=escript::FunctionSpace(),
241 arg("expanded")=false));
242 def("Vector",escript::Vector,
243 (arg("value")=0.0,
244 arg("what")=escript::FunctionSpace(),
245 arg("expanded")=false));
246 def("Tensor",escript::Tensor,
247 (arg("value")=0.0,
248 arg("what")=escript::FunctionSpace(),
249 arg("expanded")=false));
250 def("Tensor3",escript::Tensor3,
251 (arg("value")=0.0,
252 arg("what")=escript::FunctionSpace(),
253 arg("expanded")=false));
254 def("Tensor4",escript::Tensor4,
255 (arg("value")=0.0,
256 arg("what")=escript::FunctionSpace(),
257 arg("expanded")=false));
258
259 //
260 // Interface for AbstractSystemMatrix
261 //
262 class_<escript::AbstractSystemMatrix>("Operator",init<>())
263 .def("isEmpty",&escript::AbstractSystemMatrix::isEmpty)
264 .def("solve",&escript::AbstractSystemMatrix::solve)
265 .def("of",&escript::AbstractSystemMatrix::vectorMultiply)
266 .def("saveMM",&escript::AbstractSystemMatrix::saveMM)
267 .def("saveHB",&escript::AbstractSystemMatrix::saveHB)
268 .def("resetValues",&escript::AbstractSystemMatrix::resetValues)
269 .def(self*other<escript::Data>());
270
271 //
272 // Register esysExceptionTranslator
273 //
274 register_exception_translator<esysUtils::EsysException>(&esysUtils::esysExceptionTranslator);
275
276 }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26