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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 783 - (show annotations)
Tue Jul 18 01:32:50 2006 UTC (13 years, 2 months ago) by gross
File size: 10720 byte(s)
coordinates, element size and normals returned by corresponding
FunctionSpace mesthods are now protected against updates. So 
+=, -=, *=, /=, setTaggedValue, fillFromNumArray will through an
excpetion.

The FunctionSpace class does nut buffer the oordinates, element size and
normals yet.


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
23 #include "esysUtils/esysExceptionTranslator.h"
24
25 #include <boost/python.hpp>
26 #include <boost/python/module.hpp>
27 #include <boost/python/def.hpp>
28 #include <boost/python/object.hpp>
29 #include <boost/python/tuple.hpp>
30 #include <boost/python/numeric.hpp>
31
32 using namespace boost::python;
33
34 /*! \mainpage Esys Documentation
35 *
36 * \version 1.0.0
37 *
38 * - \ref escript
39 *
40 * - \ref esys_exception "Esys Exception"
41 *
42 * - \ref finley
43 *
44 * - <a href=http://iservo.edu.au/esys/epydoc/index.html>Python module documentation (epydoc generated)</a>
45 *
46 */
47
48 /*! \page escript Escript
49 * Escript is the python module that contains the interfaces
50 * to the C++ side of escript.
51 *
52 * \version 1.0.0
53 *
54 * \section class_desc Class Description:
55 * Data
56 *
57 * \section class_limits Class Limitations:
58 * None
59 *
60 * \section class_conds Class Conditions of Use:
61 * None
62 *
63 * \section class_throws Throws:
64 * None
65 *
66 */
67
68 BOOST_PYTHON_MODULE(escriptcpp)
69 {
70 def("setNumberOfThreads",escript::setNumberOfThreads);
71 def("getNumberOfThreads",escript::getNumberOfThreads);
72
73 //
74 // Interface for AbstractDomain
75 //
76 class_<escript::AbstractDomain>("Domain",no_init)
77 .def("getX",&escript::AbstractDomain::getX)
78 .def("getNormal",&escript::AbstractDomain::getNormal)
79 .def("getSize",&escript::AbstractDomain::getSize)
80 .def("saveVTK",&escript::AbstractDomain::saveVTK)
81 .def("saveDX",&escript::AbstractDomain::saveDX)
82 .def(self == self)
83 .def(self != self);
84
85 //
86 // Interface for AbstractContinuousDomain
87 //
88 class_<escript::AbstractContinuousDomain, bases<escript::AbstractDomain> >("ContinuousDomain",no_init)
89 .def("getSystemMatrixTypeId",&escript::AbstractContinuousDomain::getSystemMatrixTypeId);
90
91 //
92 // Interface for FunctionSpace
93 //
94 class_<escript::FunctionSpace>("FunctionSpace",init<>())
95 .def("getDim",&escript::FunctionSpace::getDim)
96 .def("getDomain",&escript::FunctionSpace::getDomain,return_internal_reference<>())
97 .def("getX",&escript::FunctionSpace::getX)
98 .def("getNormal",&escript::FunctionSpace::getNormal)
99 .def("getSize",&escript::FunctionSpace::getSize)
100 .def("setTags",&escript::FunctionSpace::setTags)
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("isProtected",&escript::Data::isProtected)
122 .def("setProtection",&escript::Data::setProtection)
123 .def("getShape",&escript::Data::getShapeTuple)
124 .def("getRank",&escript::Data::getDataPointRank)
125 .def("copyWithMask",&escript::Data::copyWithMask)
126 .def("setTaggedValue",&escript::Data::setTaggedValue)
127 .def("setRefValue",&escript::Data::setRefValue)
128 .def("getRefValue",&escript::Data::getRefValue)
129 .def("expand",&escript::Data::expand)
130 .def("tag",&escript::Data::tag)
131 .def("copy",&escript::Data::copy)
132 .def("convertToNumArray",&escript::Data::convertToNumArray)
133 .def("convertToNumArrayFromSampleNo",&escript::Data::convertToNumArrayFromSampleNo)
134 .def("convertToNumArrayFromDPNo",&escript::Data::convertToNumArrayFromDPNo)
135 .def("fillFromNumArray",&escript::Data::fillFromNumArray)
136 .def("interpolate",&escript::Data::interpolate)
137 .def("mindp",&escript::Data::mindp)
138 .def("saveDX",&escript::Data::saveDX)
139 .def("saveVTK",&escript::Data::saveVTK)
140 .def("getTagNumber",&escript::Data::getTagNumber)
141 .def("archiveData",&escript::Data::archiveData)
142 .def("extractData",&escript::Data::extractData)
143 // Unary functions for Data
144 .def("_interpolate",&escript::Data::interpolate)
145 .def("_grad",&escript::Data::gradOn)
146 .def("_grad",&escript::Data::grad)
147 .def("_transpose",&escript::Data::transpose)
148 .def("_trace",&escript::Data::trace)
149 .def("_maxval",&escript::Data::maxval)
150 .def("_minval",&escript::Data::minval)
151 .def("_wherePositive",&escript::Data::wherePositive)
152 .def("_whereNegative",&escript::Data::whereNegative)
153 .def("_whereNonNegative",&escript::Data::whereNonNegative)
154 .def("_whereNonPositive",&escript::Data::whereNonPositive)
155 .def("_whereZero",&escript::Data::whereZero,(arg("tol")=0.0))
156 .def("_whereNonZero",&escript::Data::whereNonZero,(arg("tol")=0.0))
157 .def("_sin",&escript::Data::sin)
158 .def("_cos",&escript::Data::cos)
159 .def("_tan",&escript::Data::tan)
160 .def("_asin",&escript::Data::asin)
161 .def("_acos",&escript::Data::acos)
162 .def("_atan",&escript::Data::atan)
163 .def("_sinh",&escript::Data::sinh)
164 .def("_cosh",&escript::Data::cosh)
165 .def("_tanh",&escript::Data::tanh)
166 .def("_asinh",&escript::Data::asinh)
167 .def("_acosh",&escript::Data::acosh)
168 .def("_atanh",&escript::Data::atanh)
169 .def("_exp",&escript::Data::exp)
170 .def("_sqrt",&escript::Data::sqrt)
171 .def("_log10",&escript::Data::log10)
172 .def("_log",&escript::Data::log)
173 .def("_sign",&escript::Data::sign)
174 .def("_symmetric",&escript::Data::symmetric)
175 .def("_nonsymmetric",&escript::Data::nonsymmetric)
176 .def("_matrixtrace",&escript::Data::matrixtrace)
177 .def("_eigenvalues",&escript::Data::eigenvalues)
178 .def("_eigenvalues_and_eigenvectors",&escript::Data::eigenvalues_and_eigenvectors,(arg("tol")=1.e-13))
179 // functions returning a single real number:
180 .def("_Lsup",&escript::Data::Lsup)
181 .def("_sup",&escript::Data::sup)
182 .def("_inf",&escript::Data::inf)
183 .def("_integrate",&escript::Data::integrate)
184
185 // following implements the python abs operator
186 .def("__abs__",&escript::Data::abs)
187 // following implements the python "-" negation operator
188 .def("__neg__",&escript::Data::neg)
189 // following implements the python "+" identity operator
190 .def("__pos__",&escript::Data::pos)
191 // following two functions implement the python [] operator
192 .def("__getitem__",&escript::Data::getItem)
193 .def("__setitem__",&escript::Data::setItemO)
194 .def("__setitem__",&escript::Data::setItemD)
195 // following two functions implement the python ** operator
196 .def("__pow__",&escript::Data::powO)
197 .def("__pow__",&escript::Data::powD)
198 .def("__rpow__",&escript::Data::rpowO)
199 // NOTE:: The order of these declarations is important. Anything
200 // declared before the generic declaration isn't found so the generic
201 // version will be called.
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
220 .def(self / other<object>())
221 .def(other<object>() / self)
222 .def(self / self)
223 .def(self /= other<object>())
224 .def(self /= self)
225 // Need scope resolution due to a bug either in the compiler or
226 // the boost code. This calls operator << for Data.
227 .def(self_ns::str(self));
228
229 //
230 // Factory methods for function space
231 //
232 def("ContinuousFunction",escript::continuousFunction);
233 def("Function",escript::function);
234 def("FunctionOnBoundary",escript::functionOnBoundary);
235 def("FunctionOnContactZero",escript::functionOnContactZero);
236 def("FunctionOnContactOne",escript::functionOnContactOne);
237 def("Solution",escript::solution);
238 def("ReducedSolution",escript::reducedSolution);
239 def("DiracDeltaFunction",escript::diracDeltaFunction);
240
241 //
242 // Factory methods for Data
243 //
244 def("Scalar",escript::Scalar,
245 (arg("value")=0.0,
246 arg("what")=escript::FunctionSpace(),
247 arg("expanded")=false));
248 def("Vector",escript::Vector,
249 (arg("value")=0.0,
250 arg("what")=escript::FunctionSpace(),
251 arg("expanded")=false));
252 def("Tensor",escript::Tensor,
253 (arg("value")=0.0,
254 arg("what")=escript::FunctionSpace(),
255 arg("expanded")=false));
256 def("Tensor3",escript::Tensor3,
257 (arg("value")=0.0,
258 arg("what")=escript::FunctionSpace(),
259 arg("expanded")=false));
260 def("Tensor4",escript::Tensor4,
261 (arg("value")=0.0,
262 arg("what")=escript::FunctionSpace(),
263 arg("expanded")=false));
264
265 //
266 // Interface for AbstractSystemMatrix
267 //
268 class_<escript::AbstractSystemMatrix>("Operator",init<>())
269 .def("isEmpty",&escript::AbstractSystemMatrix::isEmpty)
270 .def("solve",&escript::AbstractSystemMatrix::solve)
271 .def("of",&escript::AbstractSystemMatrix::vectorMultiply)
272 .def("saveMM",&escript::AbstractSystemMatrix::saveMM)
273 .def("saveHB",&escript::AbstractSystemMatrix::saveHB)
274 .def("resetValues",&escript::AbstractSystemMatrix::resetValues)
275 .def(self*other<escript::Data>());
276
277 //
278 // Register esysExceptionTranslator
279 //
280 register_exception_translator<esysUtils::EsysException>(&esysUtils::esysExceptionTranslator);
281
282 }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26