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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 147 - (show annotations)
Fri Aug 12 01:45:47 2005 UTC (14 years, 2 months ago) by jgs
Original Path: trunk/esys2/escript/src/Data/escriptcpp.cpp
File size: 10486 byte(s)
erge of development branch dev-02 back to main trunk on 2005-08-12

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://www.esscc.uq.edu.au/~cochrane/esys_python_doc/html/index.html>Python module documentation (doxygen generated)</a>
46 *
47 * - <a href=http://www.esscc.uq.edu.au/~cochrane/esys_python_doc/index.html>Python module documentation (epydoc generated)</a>
48 *
49 */
50
51 /*! \page escript Escript
52 * Escript is the python module that contains the interfaces
53 * to the C++ side of escript.
54 *
55 * \version 1.0.0
56 *
57 * \section class_desc Class Description:
58 * Data
59 *
60 * \section class_limits Class Limitations:
61 * None
62 *
63 * \section class_conds Class Conditions of Use:
64 * None
65 *
66 * \section class_throws Throws:
67 * None
68 *
69 */
70
71 BOOST_PYTHON_MODULE(escriptcpp)
72 {
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(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("getX",&escript::FunctionSpace::getX)
96 .def("getNormal",&escript::FunctionSpace::getNormal)
97 .def("getSize",&escript::FunctionSpace::getSize)
98 .def("__str__",&escript::FunctionSpace::toString)
99 .def(self == self)
100 .def(self != self);
101
102 //
103 // Interface for DataVariable
104 //
105 class_<escript::DataVariable>("DataVariable",init<>())
106 .def(init<escript::Data*>())
107 .def("evaluate",&escript::DataVariable::evaluate)
108 .def("sum",&escript::DataVariable::sum)
109 .def("diff",&escript::DataVariable::diff);
110
111 //
112 // Interface for Data
113 //
114 class_<escript::Data>("Data",init<>())
115 // various constructors for Data objects
116 .def(init<const numeric::array&, optional<const escript::FunctionSpace&, bool> >(args("value","what","expand")))
117 .def(init<const object&, optional<const escript::FunctionSpace&, bool> >(args("value","what","expand")))
118 .def(init<const double, const tuple&, optional<const escript::FunctionSpace&, bool> >(args("value","shape","what","expand")))
119 .def(init<const escript::Data&, const escript::FunctionSpace&>(args("value","what")))
120 .def(init<const escript::Data&>())
121 // Note for Lutz, Need to specify the call policy in order to return a
122 // reference. In this case return_internal_reference.
123 .def("toString",&escript::Data::toString)
124 .def("getDomain",&escript::Data::getDomain,return_internal_reference<>())
125 .def("getFunctionSpace",&escript::Data::getFunctionSpace,return_internal_reference<>())
126 .def("isEmpty",&escript::Data::isEmpty)
127 .def("getShape",&escript::Data::getShapeTuple)
128 .def("getRank",&escript::Data::getDataPointRank)
129 .def("copyWithMask",&escript::Data::copyWithMask)
130 .def("setTaggedValue",&escript::Data::setTaggedValue)
131 .def("setRefValue",&escript::Data::setRefValue)
132 .def("getRefValue",&escript::Data::getRefValue)
133 .def("expand",&escript::Data::expand)
134 .def("tag",&escript::Data::tag)
135 .def("copy",&escript::Data::copy)
136
137 .def("saveDX",&escript::Data::saveDX)
138 .def("saveVTK",&escript::Data::saveVTK)
139 .def("wherePositive",&escript::Data::wherePositive)
140 .def("whereNegative",&escript::Data::whereNegative)
141 .def("whereNonNegative",&escript::Data::whereNonNegative)
142 .def("whereNonPositive",&escript::Data::whereNonPositive)
143 .def("whereZero",&escript::Data::whereZero)
144 .def("whereNonZero",&escript::Data::whereNonZero)
145 // Unary functions for Data
146 .def("interpolate",&escript::Data::interpolate)
147 .def("grad",&escript::Data::gradOn)
148 .def("grad",&escript::Data::grad)
149 .def("convertToNumArray",&escript::Data::convertToNumArray)
150 .def("convertToNumArrayFromSampleNo",&escript::Data::convertToNumArrayFromSampleNo)
151 .def("convertToNumArrayFromDPNo",&escript::Data::convertToNumArrayFromDPNo)
152 .def("fillFromNumArray",&escript::Data::fillFromNumArray)
153 .def("archiveData",&escript::Data::archiveData)
154 .def("extractData",&escript::Data::extractData)
155 .def("integrate",&escript::Data::integrate)
156 .def("transpose",&escript::Data::transpose)
157 .def("trace",&escript::Data::trace)
158 .def("sin",&escript::Data::sin)
159 .def("cos",&escript::Data::cos)
160 .def("tan",&escript::Data::tan)
161 .def("log",&escript::Data::log)
162 .def("ln",&escript::Data::ln)
163 .def("Lsup",&escript::Data::Lsup)
164 .def("Linf",&escript::Data::Lsup)
165 .def("sup",&escript::Data::sup)
166 .def("inf",&escript::Data::inf)
167 .def("__abs__",&escript::Data::abs)
168 .def("abs",&escript::Data::abs)
169 .def("exp",&escript::Data::exp)
170 .def("sqrt",&escript::Data::sqrt)
171 .def("maxval",&escript::Data::maxval)
172 .def("minval",&escript::Data::minval)
173 .def("mindp",&escript::Data::mindp)
174 .def("length",&escript::Data::length)
175 .def("sign",&escript::Data::sign)
176 // following implements the python "-" negation operator
177 .def("__neg__",&escript::Data::neg)
178 .def("neg",&escript::Data::neg)
179 // following implements the python "+" identity operator
180 .def("__pos__",&escript::Data::pos)
181 .def("pos",&escript::Data::pos)
182 // following two functions implement the python [] operator
183 .def("__getitem__",&escript::Data::getItem)
184 .def("__setitem__",&escript::Data::setItemO)
185 .def("__setitem__",&escript::Data::setItemD)
186 // following two functions implement the python ** operator
187 .def("__pow__",&escript::Data::powO)
188 .def("__pow__",&escript::Data::powD)
189 // NOTE:: The order of these declarations is important. Anything
190 // declared before the generic declaration isn't found so the generic
191 // version will be called.
192 .def(self += other<object>())
193 .def(self += self)
194 .def(self + other<object>())
195 .def(other<object>() + self)
196 .def(self + self)
197 .def(self -= other<object>())
198 .def(self -= self)
199 .def(self - other<object>())
200 .def(other<object>() - self)
201 .def(self - self)
202 .def(self *= other<object>())
203 .def(self *= self)
204 .def(self * other<object>())
205 .def(other<object>() * self)
206 .def(self * self)
207 .def(self /= other<object>())
208 .def(self /= self)
209 .def(self / other<object>())
210 .def(other<object>() / self)
211 .def(self / self)
212 // Need scope resolution due to a bug either in the compiler or
213 // the boost code. This calls operator << for Data.
214 .def(self_ns::str(self));
215
216 //
217 // Factory methods for function space
218 //
219 def("ContinuousFunction",escript::continuousFunction);
220 def("Function",escript::function);
221 def("FunctionOnBoundary",escript::functionOnBoundary);
222 def("FunctionOnContactZero",escript::functionOnContactZero);
223 def("FunctionOnContactOne",escript::functionOnContactOne);
224 def("Solution",escript::solution);
225 def("ReducedSolution",escript::reducedSolution);
226 def("DiracDeltaFunction",escript::diracDeltaFunction);
227
228 //
229 // Factory methods for Data
230 //
231 def("Scalar",escript::Scalar,
232 (arg("value")=0.0,
233 arg("what")=escript::FunctionSpace(),
234 arg("expanded")=false));
235 def("Vector",escript::Vector,
236 (arg("value")=0.0,
237 arg("what")=escript::FunctionSpace(),
238 arg("expanded")=false));
239 def("Tensor",escript::Tensor,
240 (arg("value")=0.0,
241 arg("what")=escript::FunctionSpace(),
242 arg("expanded")=false));
243 def("Tensor3",escript::Tensor3,
244 (arg("value")=0.0,
245 arg("what")=escript::FunctionSpace(),
246 arg("expanded")=false));
247 def("Tensor4",escript::Tensor4,
248 (arg("value")=0.0,
249 arg("what")=escript::FunctionSpace(),
250 arg("expanded")=false));
251
252 //
253 // Interface for AbstractSystemMatrix
254 //
255 class_<escript::AbstractSystemMatrix>("Operator",init<>())
256 .def("isEmpty",&escript::AbstractSystemMatrix::isEmpty)
257 .def("solve",&escript::AbstractSystemMatrix::solve)
258 .def("of",&escript::AbstractSystemMatrix::vectorMultiply)
259 .def("saveMM",&escript::AbstractSystemMatrix::saveMM)
260 .def("saveHB",&escript::AbstractSystemMatrix::saveHB)
261 .def("setValue",&escript::AbstractSystemMatrix::setValue)
262 .def("resetSolver",&escript::AbstractSystemMatrix::resetSolver)
263 .def(self*other<escript::Data>());
264
265 //
266 // Register esysExceptionTranslator
267 //
268 register_exception_translator<esysUtils::EsysException>(&esysUtils::esysExceptionTranslator);
269
270 }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26