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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 102 - (show annotations)
Wed Dec 15 07:08:39 2004 UTC (14 years, 10 months ago) by jgs
Original Path: trunk/esys2/escript/src/Data/escriptcpp.cpp
File size: 8711 byte(s)
*** empty log message ***

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26