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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 121 - (show annotations)
Fri May 6 04:26:16 2005 UTC (14 years, 8 months ago) by jgs
Original Path: trunk/esys2/escript/src/Data/escriptcpp.cpp
File size: 9742 byte(s)
Merge of development branch back to main trunk on 2005-05-06

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26