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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 153 - (show annotations)
Tue Oct 25 01:51:20 2005 UTC (13 years, 11 months ago) by jgs
Original Path: trunk/esys2/escript/src/Data/escriptcpp.cpp
File size: 10975 byte(s)
Merge of development branch dev-02 back to main trunk on 2005-10-25

1 //$Id$
2 /*=============================================================================
3
4 ******************************************************************************
5 * *
6 * COPYRIGHT ACcESS 2004 - All Rights Reserved *
7 * *
8 * This software is the property of ACcESS. No part of this code *
9 * may be copied in any form or by any means without the expressed written *
10 * consent of ACcESS. Copying, use or modification of this software *
11 * by any unauthorised person is illegal unless that *
12 * person has a software license agreement with ACcESS. *
13 * *
14 ******************************************************************************
15
16 ******************************************************************************/
17
18 #include "escript/Data/Data.h"
19 #include "escript/Data/DataVariable.h"
20 #include "escript/Data/FunctionSpace.h"
21 #include "escript/Data/FunctionSpaceFactory.h"
22 #include "escript/Data/DataFactory.h"
23 #include "escript/Data/AbstractContinuousDomain.h"
24 #include "escript/Data/AbstractDomain.h"
25 #include "esysUtils/esysExceptionTranslator.h"
26
27 #include <boost/python.hpp>
28 #include <boost/python/module.hpp>
29 #include <boost/python/def.hpp>
30 #include <boost/python/object.hpp>
31 #include <boost/python/tuple.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/esys_python_doc/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
72 //
73 // Interface for AbstractDomain
74 //
75 class_<escript::AbstractDomain>("Domain",no_init)
76 .def("getX",&escript::AbstractDomain::getX)
77 .def("getNormal",&escript::AbstractDomain::getNormal)
78 .def("getSize",&escript::AbstractDomain::getSize)
79 .def("saveVTK",&escript::AbstractDomain::saveVTK)
80 .def("saveDX",&escript::AbstractDomain::saveDX)
81 .def(self == self)
82 .def(self != self);
83
84 //
85 // Interface for AbstractContinuousDomain
86 //
87 class_<escript::AbstractContinuousDomain, bases<escript::AbstractDomain> >("ContinuousDomain",no_init)
88 .def("getSystemMatrixTypeId",&escript::AbstractContinuousDomain::getSystemMatrixTypeId);
89
90 //
91 // Interface for FunctionSpace
92 //
93 class_<escript::FunctionSpace>("FunctionSpace",init<>())
94 .def("getDim",&escript::FunctionSpace::getDim)
95 .def("getDomain",&escript::FunctionSpace::getDomain,return_internal_reference<>())
96 .def("getX",&escript::FunctionSpace::getX)
97 .def("getNormal",&escript::FunctionSpace::getNormal)
98 .def("getSize",&escript::FunctionSpace::getSize)
99 .def("getTagFromDataPointNo",&escript::FunctionSpace::getTagFromDataPointNo)
100 .def("__str__",&escript::FunctionSpace::toString)
101 .def(self == self)
102 .def(self != self);
103
104 //
105 // Interface for DataVariable
106 //
107 class_<escript::DataVariable>("DataVariable",init<>())
108 .def(init<escript::Data*>())
109 .def("evaluate",&escript::DataVariable::evaluate)
110 .def("sum",&escript::DataVariable::sum)
111 .def("diff",&escript::DataVariable::diff);
112
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("toString",&escript::Data::toString)
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("getShape",&escript::Data::getShapeTuple)
130 .def("getRank",&escript::Data::getDataPointRank)
131 .def("copyWithMask",&escript::Data::copyWithMask)
132 .def("setTaggedValue",&escript::Data::setTaggedValue)
133 .def("setRefValue",&escript::Data::setRefValue)
134 .def("getRefValue",&escript::Data::getRefValue)
135 .def("expand",&escript::Data::expand)
136 .def("tag",&escript::Data::tag)
137 .def("copy",&escript::Data::copy)
138 .def("saveDX",&escript::Data::saveDX)
139 .def("saveVTK",&escript::Data::saveVTK)
140 .def("wherePositive",&escript::Data::wherePositive)
141 .def("whereNegative",&escript::Data::whereNegative)
142 .def("whereNonNegative",&escript::Data::whereNonNegative)
143 .def("whereNonPositive",&escript::Data::whereNonPositive)
144 .def("whereZero",&escript::Data::whereZero)
145 .def("whereNonZero",&escript::Data::whereNonZero)
146 // Unary functions for Data
147 .def("interpolate",&escript::Data::interpolate)
148 .def("grad",&escript::Data::gradOn)
149 .def("grad",&escript::Data::grad)
150 .def("convertToNumArray",&escript::Data::convertToNumArray)
151 .def("convertToNumArrayFromSampleNo",&escript::Data::convertToNumArrayFromSampleNo)
152 .def("convertToNumArrayFromDPNo",&escript::Data::convertToNumArrayFromDPNo)
153 .def("fillFromNumArray",&escript::Data::fillFromNumArray)
154 .def("getTagNumber",&escript::Data::getTagNumber)
155 .def("archiveData",&escript::Data::archiveData)
156 .def("extractData",&escript::Data::extractData)
157 .def("integrate",&escript::Data::integrate)
158 .def("transpose",&escript::Data::transpose)
159 .def("trace",&escript::Data::trace)
160 .def("sin",&escript::Data::sin)
161 .def("cos",&escript::Data::cos)
162 .def("tan",&escript::Data::tan)
163 .def("asin",&escript::Data::asin)
164 .def("acos",&escript::Data::acos)
165 .def("atan",&escript::Data::atan)
166 .def("sinh",&escript::Data::sinh)
167 .def("cosh",&escript::Data::cosh)
168 .def("tanh",&escript::Data::tanh)
169 .def("asinh",&escript::Data::asinh)
170 .def("acosh",&escript::Data::acosh)
171 .def("atanh",&escript::Data::atanh)
172 .def("log",&escript::Data::log)
173 .def("ln",&escript::Data::ln)
174 .def("Lsup",&escript::Data::Lsup)
175 .def("Linf",&escript::Data::Lsup)
176 .def("sup",&escript::Data::sup)
177 .def("inf",&escript::Data::inf)
178 .def("__abs__",&escript::Data::abs)
179 .def("abs",&escript::Data::abs)
180 .def("exp",&escript::Data::exp)
181 .def("sqrt",&escript::Data::sqrt)
182 .def("maxval",&escript::Data::maxval)
183 .def("minval",&escript::Data::minval)
184 .def("mindp",&escript::Data::mindp)
185 .def("length",&escript::Data::length)
186 .def("sign",&escript::Data::sign)
187 // following implements the python "-" negation operator
188 .def("__neg__",&escript::Data::neg)
189 .def("neg",&escript::Data::neg)
190 // following implements the python "+" identity operator
191 .def("__pos__",&escript::Data::pos)
192 .def("pos",&escript::Data::pos)
193 // following two functions implement the python [] operator
194 .def("__getitem__",&escript::Data::getItem)
195 .def("__setitem__",&escript::Data::setItemO)
196 .def("__setitem__",&escript::Data::setItemD)
197 // following two functions implement the python ** operator
198 .def("__pow__",&escript::Data::powO)
199 .def("__pow__",&escript::Data::powD)
200 // NOTE:: The order of these declarations is important. Anything
201 // declared before the generic declaration isn't found so the generic
202 // version will be called.
203 .def(self += other<object>())
204 .def(self += self)
205 .def(self + other<object>())
206 .def(other<object>() + self)
207 .def(self + self)
208 .def(self -= other<object>())
209 .def(self -= self)
210 .def(self - other<object>())
211 .def(other<object>() - self)
212 .def(self - self)
213 .def(self *= other<object>())
214 .def(self *= self)
215 .def(self * other<object>())
216 .def(other<object>() * self)
217 .def(self * self)
218 .def(self /= other<object>())
219 .def(self /= self)
220 .def(self / other<object>())
221 .def(other<object>() / self)
222 .def(self / self)
223 // Need scope resolution due to a bug either in the compiler or
224 // the boost code. This calls operator << for Data.
225 .def(self_ns::str(self));
226
227 //
228 // Factory methods for function space
229 //
230 def("ContinuousFunction",escript::continuousFunction);
231 def("Function",escript::function);
232 def("FunctionOnBoundary",escript::functionOnBoundary);
233 def("FunctionOnContactZero",escript::functionOnContactZero);
234 def("FunctionOnContactOne",escript::functionOnContactOne);
235 def("Solution",escript::solution);
236 def("ReducedSolution",escript::reducedSolution);
237 def("DiracDeltaFunction",escript::diracDeltaFunction);
238
239 //
240 // Factory methods for Data
241 //
242 def("Scalar",escript::Scalar,
243 (arg("value")=0.0,
244 arg("what")=escript::FunctionSpace(),
245 arg("expanded")=false));
246 def("Vector",escript::Vector,
247 (arg("value")=0.0,
248 arg("what")=escript::FunctionSpace(),
249 arg("expanded")=false));
250 def("Tensor",escript::Tensor,
251 (arg("value")=0.0,
252 arg("what")=escript::FunctionSpace(),
253 arg("expanded")=false));
254 def("Tensor3",escript::Tensor3,
255 (arg("value")=0.0,
256 arg("what")=escript::FunctionSpace(),
257 arg("expanded")=false));
258 def("Tensor4",escript::Tensor4,
259 (arg("value")=0.0,
260 arg("what")=escript::FunctionSpace(),
261 arg("expanded")=false));
262
263 //
264 // Interface for AbstractSystemMatrix
265 //
266 class_<escript::AbstractSystemMatrix>("Operator",init<>())
267 .def("isEmpty",&escript::AbstractSystemMatrix::isEmpty)
268 .def("solve",&escript::AbstractSystemMatrix::solve)
269 .def("of",&escript::AbstractSystemMatrix::vectorMultiply)
270 .def("saveMM",&escript::AbstractSystemMatrix::saveMM)
271 .def("saveHB",&escript::AbstractSystemMatrix::saveHB)
272 .def("resetValues",&escript::AbstractSystemMatrix::resetValues)
273 .def(self*other<escript::Data>());
274
275 //
276 // Register esysExceptionTranslator
277 //
278 register_exception_translator<esysUtils::EsysException>(&esysUtils::esysExceptionTranslator);
279
280 }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26