/[escript]/trunk/esys2/escript/src/Data/escript.cpp
ViewVC logotype

Contents of /trunk/esys2/escript/src/Data/escript.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 82 - (show annotations)
Tue Oct 26 06:53:54 2004 UTC (14 years, 6 months ago) by jgs
File size: 7502 byte(s)
Initial revision

1 /*=============================================================================
2
3 ******************************************************************************
4 * *
5 * COPYRIGHT ACcESS 2004 - All Rights Reserved *
6 * *
7 * This software is the property of ACcESS. No part of this code *
8 * may be copied in any form or by any means without the expressed written *
9 * consent of ACcESS. Copying, use or modification of this software *
10 * by any unauthorised person is illegal unless that *
11 * person has a software license agreement with ACcESS. *
12 * *
13 ******************************************************************************
14
15 ******************************************************************************/
16
17 #include "escript/Data/Data.h"
18 #include "escript/Data/FunctionSpace.h"
19 #include "escript/Data/FunctionSpaceFactory.h"
20 #include "escript/Data/DataFactory.h"
21 #include "escript/Data/AbstractContinuousDomain.h"
22 #include "escript/Data/AbstractDomain.h"
23 #include "esysUtils/esysExceptionTranslator.h"
24
25 #include <boost/python.hpp>
26 #include <boost/python/module.hpp>
27 #include <boost/python/def.hpp>
28 #include <boost/python/object.hpp>
29 #include <boost/python/tuple.hpp>
30 //#include <boost/python/overloads.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(escript)
58 {
59
60 //
61 // Interface for AbstractDomain
62 //
63 class_<escript::AbstractDomain>("Domain",no_init)
64 .def(self == self)
65 .def(self != self);
66
67 //
68 // Interface for AbstractContinuousDomain
69 //
70 class_<escript::AbstractContinuousDomain, bases<escript::AbstractDomain> >("ContinuousDomain",no_init);
71
72 //
73 // Interface for FunctionSpace
74 //
75 class_<escript::FunctionSpace>("FunctionSpace",init<>())
76 .def("getDim",&escript::FunctionSpace::getDim)
77 .def("getX",&escript::FunctionSpace::getX)
78 .def("getNormal",&escript::FunctionSpace::getNormal)
79 .def("getSize",&escript::FunctionSpace::getSize)
80 .def("toString",&escript::FunctionSpace::toString)
81 .def(self == self)
82 .def(self != self);
83
84 //
85 // Interface for Data
86 //
87 class_<escript::Data>("Data",init<>())
88 .def(init<const numeric::array&, optional<const escript::FunctionSpace&, bool> >(args("value","what","expand")))
89 .def(init<const object&, optional<const escript::FunctionSpace&, bool> >(args("value","what","expand")))
90 .def(init<const double, const tuple&, optional<const escript::FunctionSpace&, bool> >(args("value","shape","what","expand")))
91 .def(init<const escript::Data&, const escript::FunctionSpace&>(args("value","what")))
92 .def(init<const escript::Data&>())
93 // Note for Lutz, Need to specify the call policy in order to return a
94 // reference. In this case return_internal_reference.
95 .def("toString",&escript::Data::toString)
96 .def("getDomain",&escript::Data::getDomain,return_internal_reference<>())
97 .def("getFunctionSpace",&escript::Data::getFunctionSpace,return_internal_reference<>())
98 .def("isEmpty",&escript::Data::isEmpty)
99 .def("getShape",&escript::Data::getShapeTuple)
100 .def("getRank",&escript::Data::getDataPointRank)
101 .def("expand",&escript::Data::expand)
102 .def("interpolate",&escript::Data::interpolate)
103 .def("grad",&escript::Data::gradOn)
104 .def("grad",&escript::Data::grad)
105 .def("integrate",&escript::Data::integrate)
106 .def("wherePositive",&escript::Data::wherePositive)
107 .def("whereNonNegative",&escript::Data::whereNonNegative)
108 .def("whereNegative",&escript::Data::whereNegative)
109 .def("whereZero",&escript::Data::whereZero)
110 .def("copyWithMask",&escript::Data::copyWithMask)
111 .def("setTaggedValue",&escript::Data::setTaggedValue)
112 // Unary functions for Data
113 .def("sin",&escript::Data::sin)
114 .def("cos",&escript::Data::cos)
115 .def("tan",&escript::Data::tan)
116 .def("log",&escript::Data::log)
117 .def("ln",&escript::Data::ln)
118 .def("Lsup",&escript::Data::Lsup)
119 .def("sup",&escript::Data::sup)
120 .def("inf",&escript::Data::inf)
121 .def("__getitem__",&escript::Data::getItem)
122 .def("__setitem__",&escript::Data::setItem)
123 .def("__pow__",&escript::Data::powO)
124 .def("__pow__",&escript::Data::powD)
125 // NOTE:: The order of these declarations is important. Anything
126 // declared before the generic declaration isn't found so the generic
127 // version will be called.
128 .def(self += other<object>())
129 .def(self += self)
130 .def(self + other<object>())
131 .def(other<object>() + self)
132 .def(self + self)
133 .def(self -= other<object>())
134 .def(self -= self)
135 .def(self - other<object>())
136 .def(other<object>() - self)
137 .def(self - self)
138 .def(self *= other<object>())
139 .def(self *= self)
140 .def(self * other<object>())
141 .def(other<object>() * self)
142 .def(self * self)
143 .def(self /= other<object>())
144 .def(self /= self)
145 .def(self / other<object>())
146 .def(other<object>() / self)
147 .def(self / self)
148 // Need scope resolution due to a bug either in the compiler or
149 // the boost code. This calls operator<< for Data.
150 .def(self_ns::str(self));
151
152 //
153 // Factory methods for function space
154 //
155 def("ContinuousFunction",escript::continuousFunction);
156 def("Function",escript::function);
157 def("FunctionOnBoundary",escript::functionOnBoundary);
158 def("FunctionOnContactZero",escript::functionOnContactZero);
159 def("FunctionOnContactOne",escript::functionOnContactOne);
160 def("Solution",escript::solution);
161 def("ReducedSolution",escript::reducedSolution);
162 def("DiracDeltaFunction",escript::diracDeltaFunction);
163
164 //
165 // Factory methods for Data
166 //
167 def("Scalar",escript::Scalar,
168 (arg("value")=0.0,
169 arg("what")=escript::FunctionSpace(),
170 arg("expanded")=false));
171 def("Vector",escript::Vector,
172 (arg("value")=0.0,
173 arg("what")=escript::FunctionSpace(),
174 arg("expanded")=false));
175 def("Tensor",escript::Tensor,
176 (arg("value")=0.0,
177 arg("what")=escript::FunctionSpace(),
178 arg("expanded")=false));
179 def("Tensor3",escript::Tensor3,
180 (arg("value")=0.0,
181 arg("what")=escript::FunctionSpace(),
182 arg("expanded")=false));
183 def("Tensor4",escript::Tensor4,
184 (arg("value")=0.0,
185 arg("what")=escript::FunctionSpace(),
186 arg("expanded")=false));
187
188 //
189 // Interface for AbstractSystemMatrix
190 //
191 class_<escript::AbstractSystemMatrix>("Operator",init<>())
192 .def("isEmpty",&escript::AbstractSystemMatrix::isEmpty)
193 .def("solve",&escript::AbstractSystemMatrix::solve)
194 .def("of",&escript::AbstractSystemMatrix::vectorMultiply)
195 .def("getRowFunctionSpace",&escript::AbstractSystemMatrix::getRowFunctionSpace)
196 .def(self*other<escript::Data>());
197
198 //
199 // Register esysExceptionTranslator
200 //
201 register_exception_translator<esysUtils::EsysException>(&esysUtils::esysExceptionTranslator);
202
203 }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26