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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 150 - (show annotations)
Thu Sep 15 03:44:45 2005 UTC (14 years, 1 month ago) by jgs
Original Path: trunk/esys2/escript/src/Data/escriptcpp.cpp
File size: 10779 byte(s)
Merge of development branch dev-02 back to main trunk on 2005-09-15

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(self == self)
80 .def(self != self);
81
82 //
83 // Interface for AbstractContinuousDomain
84 //
85 class_<escript::AbstractContinuousDomain, bases<escript::AbstractDomain> >("ContinuousDomain",no_init)
86 .def("getSystemMatrixTypeId",&escript::AbstractContinuousDomain::getSystemMatrixTypeId);
87
88 //
89 // Interface for FunctionSpace
90 //
91 class_<escript::FunctionSpace>("FunctionSpace",init<>())
92 .def("getDim",&escript::FunctionSpace::getDim)
93 .def("getX",&escript::FunctionSpace::getX)
94 .def("getNormal",&escript::FunctionSpace::getNormal)
95 .def("getSize",&escript::FunctionSpace::getSize)
96 .def("getTagFromDataPointNo",&escript::FunctionSpace::getTagFromDataPointNo)
97 .def("__str__",&escript::FunctionSpace::toString)
98 .def(self == self)
99 .def(self != self);
100
101 //
102 // Interface for DataVariable
103 //
104 class_<escript::DataVariable>("DataVariable",init<>())
105 .def(init<escript::Data*>())
106 .def("evaluate",&escript::DataVariable::evaluate)
107 .def("sum",&escript::DataVariable::sum)
108 .def("diff",&escript::DataVariable::diff);
109
110 //
111 // Interface for Data
112 //
113 class_<escript::Data>("Data","TEST DOCUMENTATION",init<>())
114 // various constructors for Data objects
115 .def(init<const numeric::array&, optional<const escript::FunctionSpace&, bool> >(args("value","what","expand")))
116 .def(init<const object&, optional<const escript::FunctionSpace&, bool> >(args("value","what","expand")))
117 .def(init<const double, const tuple&, optional<const escript::FunctionSpace&, bool> >(args("value","shape","what","expand")))
118 .def(init<const escript::Data&, const escript::FunctionSpace&>(args("value","what")))
119 .def(init<const escript::Data&>())
120 // Note for Lutz, Need to specify the call policy in order to return a
121 // reference. In this case return_internal_reference.
122 .def("toString",&escript::Data::toString)
123 .def("getDomain",&escript::Data::getDomain,return_internal_reference<>())
124 .def("getFunctionSpace",&escript::Data::getFunctionSpace,return_internal_reference<>())
125 .def("isEmpty",&escript::Data::isEmpty)
126 .def("getShape",&escript::Data::getShapeTuple)
127 .def("getRank",&escript::Data::getDataPointRank)
128 .def("copyWithMask",&escript::Data::copyWithMask)
129 .def("setTaggedValue",&escript::Data::setTaggedValue)
130 .def("setRefValue",&escript::Data::setRefValue)
131 .def("getRefValue",&escript::Data::getRefValue)
132 .def("expand",&escript::Data::expand)
133 .def("tag",&escript::Data::tag)
134 .def("copy",&escript::Data::copy)
135 .def("saveDX",&escript::Data::saveDX)
136 .def("saveVTK",&escript::Data::saveVTK)
137 .def("wherePositive",&escript::Data::wherePositive)
138 .def("whereNegative",&escript::Data::whereNegative)
139 .def("whereNonNegative",&escript::Data::whereNonNegative)
140 .def("whereNonPositive",&escript::Data::whereNonPositive)
141 .def("whereZero",&escript::Data::whereZero)
142 .def("whereNonZero",&escript::Data::whereNonZero)
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("convertToNumArray",&escript::Data::convertToNumArray)
148 .def("convertToNumArrayFromSampleNo",&escript::Data::convertToNumArrayFromSampleNo)
149 .def("convertToNumArrayFromDPNo",&escript::Data::convertToNumArrayFromDPNo)
150 .def("fillFromNumArray",&escript::Data::fillFromNumArray)
151 .def("getTagNumber",&escript::Data::getTagNumber)
152 .def("archiveData",&escript::Data::archiveData)
153 .def("extractData",&escript::Data::extractData)
154 .def("integrate",&escript::Data::integrate)
155 .def("transpose",&escript::Data::transpose)
156 .def("trace",&escript::Data::trace)
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("log",&escript::Data::log)
170 .def("ln",&escript::Data::ln)
171 .def("Lsup",&escript::Data::Lsup)
172 .def("Linf",&escript::Data::Lsup)
173 .def("sup",&escript::Data::sup)
174 .def("inf",&escript::Data::inf)
175 .def("__abs__",&escript::Data::abs)
176 .def("abs",&escript::Data::abs)
177 .def("exp",&escript::Data::exp)
178 .def("sqrt",&escript::Data::sqrt)
179 .def("maxval",&escript::Data::maxval)
180 .def("minval",&escript::Data::minval)
181 .def("mindp",&escript::Data::mindp)
182 .def("length",&escript::Data::length)
183 .def("sign",&escript::Data::sign)
184 // following implements the python "-" negation operator
185 .def("__neg__",&escript::Data::neg)
186 .def("neg",&escript::Data::neg)
187 // following implements the python "+" identity operator
188 .def("__pos__",&escript::Data::pos)
189 .def("pos",&escript::Data::pos)
190 // following two functions implement the python [] operator
191 .def("__getitem__",&escript::Data::getItem)
192 .def("__setitem__",&escript::Data::setItemO)
193 .def("__setitem__",&escript::Data::setItemD)
194 // following two functions implement the python ** operator
195 .def("__pow__",&escript::Data::powO)
196 .def("__pow__",&escript::Data::powD)
197 // NOTE:: The order of these declarations is important. Anything
198 // declared before the generic declaration isn't found so the generic
199 // version will be called.
200 .def(self += other<object>())
201 .def(self += self)
202 .def(self + other<object>())
203 .def(other<object>() + self)
204 .def(self + self)
205 .def(self -= other<object>())
206 .def(self -= self)
207 .def(self - other<object>())
208 .def(other<object>() - self)
209 .def(self - self)
210 .def(self *= other<object>())
211 .def(self *= self)
212 .def(self * other<object>())
213 .def(other<object>() * self)
214 .def(self * self)
215 .def(self /= other<object>())
216 .def(self /= self)
217 .def(self / other<object>())
218 .def(other<object>() / self)
219 .def(self / self)
220 // Need scope resolution due to a bug either in the compiler or
221 // the boost code. This calls operator << for Data.
222 .def(self_ns::str(self));
223
224 //
225 // Factory methods for function space
226 //
227 def("ContinuousFunction",escript::continuousFunction);
228 def("Function",escript::function);
229 def("FunctionOnBoundary",escript::functionOnBoundary);
230 def("FunctionOnContactZero",escript::functionOnContactZero);
231 def("FunctionOnContactOne",escript::functionOnContactOne);
232 def("Solution",escript::solution);
233 def("ReducedSolution",escript::reducedSolution);
234 def("DiracDeltaFunction",escript::diracDeltaFunction);
235
236 //
237 // Factory methods for Data
238 //
239 def("Scalar",escript::Scalar,
240 (arg("value")=0.0,
241 arg("what")=escript::FunctionSpace(),
242 arg("expanded")=false));
243 def("Vector",escript::Vector,
244 (arg("value")=0.0,
245 arg("what")=escript::FunctionSpace(),
246 arg("expanded")=false));
247 def("Tensor",escript::Tensor,
248 (arg("value")=0.0,
249 arg("what")=escript::FunctionSpace(),
250 arg("expanded")=false));
251 def("Tensor3",escript::Tensor3,
252 (arg("value")=0.0,
253 arg("what")=escript::FunctionSpace(),
254 arg("expanded")=false));
255 def("Tensor4",escript::Tensor4,
256 (arg("value")=0.0,
257 arg("what")=escript::FunctionSpace(),
258 arg("expanded")=false));
259
260 //
261 // Interface for AbstractSystemMatrix
262 //
263 class_<escript::AbstractSystemMatrix>("Operator",init<>())
264 .def("isEmpty",&escript::AbstractSystemMatrix::isEmpty)
265 .def("solve",&escript::AbstractSystemMatrix::solve)
266 .def("of",&escript::AbstractSystemMatrix::vectorMultiply)
267 .def("saveMM",&escript::AbstractSystemMatrix::saveMM)
268 .def("saveHB",&escript::AbstractSystemMatrix::saveHB)
269 .def("resetValues",&escript::AbstractSystemMatrix::resetValues)
270 .def(self*other<escript::Data>());
271
272 //
273 // Register esysExceptionTranslator
274 //
275 register_exception_translator<esysUtils::EsysException>(&esysUtils::esysExceptionTranslator);
276
277 }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26