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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 122 - (show annotations)
Thu Jun 9 05:38:05 2005 UTC (14 years, 3 months ago) by jgs
Original Path: trunk/esys2/escript/src/Data/escriptcpp.cpp
File size: 10327 byte(s)
Merge of development branch back to main trunk on 2005-06-09

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("toString",&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("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("archiveData",&escript::Data::archiveData)
151 .def("extractData",&escript::Data::extractData)
152 .def("integrate",&escript::Data::integrate)
153 .def("transpose",&escript::Data::transpose)
154 .def("trace",&escript::Data::trace)
155 .def("sin",&escript::Data::sin)
156 .def("cos",&escript::Data::cos)
157 .def("tan",&escript::Data::tan)
158 .def("log",&escript::Data::log)
159 .def("ln",&escript::Data::ln)
160 .def("Lsup",&escript::Data::Lsup)
161 .def("Linf",&escript::Data::Lsup)
162 .def("sup",&escript::Data::sup)
163 .def("inf",&escript::Data::inf)
164 .def("__abs__",&escript::Data::abs)
165 .def("abs",&escript::Data::abs)
166 .def("exp",&escript::Data::exp)
167 .def("sqrt",&escript::Data::sqrt)
168 .def("maxval",&escript::Data::maxval)
169 .def("minval",&escript::Data::minval)
170 .def("mindp",&escript::Data::mindp)
171 .def("length",&escript::Data::length)
172 .def("sign",&escript::Data::sign)
173 // following implements the python "-" negation operator
174 .def("__neg__",&escript::Data::neg)
175 .def("neg",&escript::Data::neg)
176 // following implements the python "+" identity operator
177 .def("__pos__",&escript::Data::pos)
178 .def("pos",&escript::Data::pos)
179 // following two functions implement the python [] operator
180 .def("__getitem__",&escript::Data::getItem)
181 .def("__setitem__",&escript::Data::setItemO)
182 .def("__setitem__",&escript::Data::setItemD)
183 // following two functions implement the python ** operator
184 .def("__pow__",&escript::Data::powO)
185 .def("__pow__",&escript::Data::powD)
186 // NOTE:: The order of these declarations is important. Anything
187 // declared before the generic declaration isn't found so the generic
188 // version will be called.
189 .def(self += other<object>())
190 .def(self += self)
191 .def(self + other<object>())
192 .def(other<object>() + self)
193 .def(self + self)
194 .def(self -= other<object>())
195 .def(self -= self)
196 .def(self - other<object>())
197 .def(other<object>() - self)
198 .def(self - self)
199 .def(self *= other<object>())
200 .def(self *= self)
201 .def(self * other<object>())
202 .def(other<object>() * self)
203 .def(self * self)
204 .def(self /= other<object>())
205 .def(self /= self)
206 .def(self / other<object>())
207 .def(other<object>() / self)
208 .def(self / self)
209 // Need scope resolution due to a bug either in the compiler or
210 // the boost code. This calls operator << for Data.
211 .def(self_ns::str(self));
212
213 //
214 // Factory methods for function space
215 //
216 def("ContinuousFunction",escript::continuousFunction);
217 def("Function",escript::function);
218 def("FunctionOnBoundary",escript::functionOnBoundary);
219 def("FunctionOnContactZero",escript::functionOnContactZero);
220 def("FunctionOnContactOne",escript::functionOnContactOne);
221 def("Solution",escript::solution);
222 def("ReducedSolution",escript::reducedSolution);
223 def("DiracDeltaFunction",escript::diracDeltaFunction);
224
225 //
226 // Factory methods for Data
227 //
228 def("Scalar",escript::Scalar,
229 (arg("value")=0.0,
230 arg("what")=escript::FunctionSpace(),
231 arg("expanded")=false));
232 def("Vector",escript::Vector,
233 (arg("value")=0.0,
234 arg("what")=escript::FunctionSpace(),
235 arg("expanded")=false));
236 def("Tensor",escript::Tensor,
237 (arg("value")=0.0,
238 arg("what")=escript::FunctionSpace(),
239 arg("expanded")=false));
240 def("Tensor3",escript::Tensor3,
241 (arg("value")=0.0,
242 arg("what")=escript::FunctionSpace(),
243 arg("expanded")=false));
244 def("Tensor4",escript::Tensor4,
245 (arg("value")=0.0,
246 arg("what")=escript::FunctionSpace(),
247 arg("expanded")=false));
248
249 //
250 // Interface for AbstractSystemMatrix
251 //
252 class_<escript::AbstractSystemMatrix>("Operator",init<>())
253 .def("isEmpty",&escript::AbstractSystemMatrix::isEmpty)
254 .def("solve",&escript::AbstractSystemMatrix::solve)
255 .def("of",&escript::AbstractSystemMatrix::vectorMultiply)
256 .def("saveMM",&escript::AbstractSystemMatrix::saveMM)
257 .def("setValue",&escript::AbstractSystemMatrix::setValue)
258 .def("resetSolver",&escript::AbstractSystemMatrix::resetSolver)
259 .def(self*other<escript::Data>());
260
261 //
262 // Register esysExceptionTranslator
263 //
264 register_exception_translator<esysUtils::EsysException>(&esysUtils::esysExceptionTranslator);
265
266 }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26