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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 285 - (hide annotations)
Thu Dec 1 06:40:04 2005 UTC (13 years, 11 months ago) by gross
Original Path: trunk/escript/src/Data/escriptcpp.cpp
File size: 10882 byte(s)
length method is removed as it is too slow. use length in util.py instead
1 jgs 102 //$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 jgs 122 #include "escript/Data/DataVariable.h"
20 jgs 102 #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 gross 285 #include <boost/python/numeric.hpp>
33    
34 jgs 102 using namespace boost::python;
35    
36 jgs 121 /*! \mainpage Esys Documentation
37     *
38     * \version 1.0.0
39     *
40     * - \ref escript
41     *
42     * - \ref esys_exception "Esys Exception"
43     *
44     * - \ref finley
45     *
46 jgs 150 * - <a href=http://iservo.edu.au/esys/esys_python_doc/index.html>Python module documentation (epydoc generated)</a>
47 jgs 122 *
48 jgs 121 */
49 jgs 102
50 jgs 121 /*! \page escript Escript
51     * Escript is the python module that contains the interfaces
52     * to the C++ side of escript.
53     *
54     * \version 1.0.0
55     *
56     * \section class_desc Class Description:
57     * Data
58     *
59     * \section class_limits Class Limitations:
60     * None
61     *
62     * \section class_conds Class Conditions of Use:
63     * None
64     *
65     * \section class_throws Throws:
66     * None
67     *
68     */
69 jgs 102
70     BOOST_PYTHON_MODULE(escriptcpp)
71     {
72    
73     //
74     // Interface for AbstractDomain
75     //
76     class_<escript::AbstractDomain>("Domain",no_init)
77     .def("getX",&escript::AbstractDomain::getX)
78     .def("getNormal",&escript::AbstractDomain::getNormal)
79     .def("getSize",&escript::AbstractDomain::getSize)
80 jgs 153 .def("saveVTK",&escript::AbstractDomain::saveVTK)
81     .def("saveDX",&escript::AbstractDomain::saveDX)
82 jgs 102 .def(self == self)
83     .def(self != self);
84    
85     //
86     // Interface for AbstractContinuousDomain
87     //
88     class_<escript::AbstractContinuousDomain, bases<escript::AbstractDomain> >("ContinuousDomain",no_init)
89     .def("getSystemMatrixTypeId",&escript::AbstractContinuousDomain::getSystemMatrixTypeId);
90    
91     //
92     // Interface for FunctionSpace
93     //
94     class_<escript::FunctionSpace>("FunctionSpace",init<>())
95     .def("getDim",&escript::FunctionSpace::getDim)
96 jgs 153 .def("getDomain",&escript::FunctionSpace::getDomain,return_internal_reference<>())
97 jgs 102 .def("getX",&escript::FunctionSpace::getX)
98     .def("getNormal",&escript::FunctionSpace::getNormal)
99     .def("getSize",&escript::FunctionSpace::getSize)
100 jgs 149 .def("getTagFromDataPointNo",&escript::FunctionSpace::getTagFromDataPointNo)
101 jgs 147 .def("__str__",&escript::FunctionSpace::toString)
102 jgs 102 .def(self == self)
103     .def(self != self);
104    
105     //
106 jgs 122 // Interface for DataVariable
107     //
108     class_<escript::DataVariable>("DataVariable",init<>())
109     .def(init<escript::Data*>())
110     .def("evaluate",&escript::DataVariable::evaluate)
111     .def("sum",&escript::DataVariable::sum)
112     .def("diff",&escript::DataVariable::diff);
113    
114     //
115 jgs 102 // Interface for Data
116     //
117 jgs 149 class_<escript::Data>("Data","TEST DOCUMENTATION",init<>())
118 jgs 102 // various constructors for Data objects
119     .def(init<const numeric::array&, optional<const escript::FunctionSpace&, bool> >(args("value","what","expand")))
120     .def(init<const object&, optional<const escript::FunctionSpace&, bool> >(args("value","what","expand")))
121     .def(init<const double, const tuple&, optional<const escript::FunctionSpace&, bool> >(args("value","shape","what","expand")))
122     .def(init<const escript::Data&, const escript::FunctionSpace&>(args("value","what")))
123     .def(init<const escript::Data&>())
124     // Note for Lutz, Need to specify the call policy in order to return a
125     // reference. In this case return_internal_reference.
126 gross 285 .def("__str__",&escript::Data::toString)
127 jgs 102 .def("getDomain",&escript::Data::getDomain,return_internal_reference<>())
128     .def("getFunctionSpace",&escript::Data::getFunctionSpace,return_internal_reference<>())
129     .def("isEmpty",&escript::Data::isEmpty)
130     .def("getShape",&escript::Data::getShapeTuple)
131     .def("getRank",&escript::Data::getDataPointRank)
132     .def("copyWithMask",&escript::Data::copyWithMask)
133     .def("setTaggedValue",&escript::Data::setTaggedValue)
134 jgs 110 .def("setRefValue",&escript::Data::setRefValue)
135     .def("getRefValue",&escript::Data::getRefValue)
136 jgs 119 .def("expand",&escript::Data::expand)
137     .def("tag",&escript::Data::tag)
138 jgs 126 .def("copy",&escript::Data::copy)
139 jgs 117 .def("convertToNumArray",&escript::Data::convertToNumArray)
140 jgs 121 .def("convertToNumArrayFromSampleNo",&escript::Data::convertToNumArrayFromSampleNo)
141     .def("convertToNumArrayFromDPNo",&escript::Data::convertToNumArrayFromDPNo)
142 jgs 126 .def("fillFromNumArray",&escript::Data::fillFromNumArray)
143 gross 285 .def("interpolate",&escript::Data::interpolate)
144     .def("mindp",&escript::Data::mindp)
145    
146     .def("saveDX",&escript::Data::saveDX)
147     .def("saveVTK",&escript::Data::saveVTK)
148 jgs 149 .def("getTagNumber",&escript::Data::getTagNumber)
149 jgs 119 .def("archiveData",&escript::Data::archiveData)
150     .def("extractData",&escript::Data::extractData)
151 gross 285 // Unary functions for Data
152     .def("_interpolate",&escript::Data::interpolate)
153     .def("_grad",&escript::Data::gradOn)
154     .def("_grad",&escript::Data::grad)
155     .def("_transpose",&escript::Data::transpose)
156     .def("_trace",&escript::Data::trace)
157     .def("_maxval",&escript::Data::maxval)
158     .def("_minval",&escript::Data::minval)
159     .def("_wherePositive",&escript::Data::wherePositive)
160     .def("_whereNegative",&escript::Data::whereNegative)
161     .def("_whereNonNegative",&escript::Data::whereNonNegative)
162     .def("_whereNonPositive",&escript::Data::whereNonPositive)
163     .def("_whereZero",&escript::Data::whereZero)
164     .def("_whereNonZero",&escript::Data::whereNonZero)
165     .def("_sin",&escript::Data::sin)
166     .def("_cos",&escript::Data::cos)
167     .def("_tan",&escript::Data::tan)
168     .def("_asin",&escript::Data::asin)
169     .def("_acos",&escript::Data::acos)
170     .def("_atan",&escript::Data::atan)
171     .def("_sinh",&escript::Data::sinh)
172     .def("_cosh",&escript::Data::cosh)
173     .def("_tanh",&escript::Data::tanh)
174     .def("_asinh",&escript::Data::asinh)
175     .def("_acosh",&escript::Data::acosh)
176     .def("_atanh",&escript::Data::atanh)
177     .def("_exp",&escript::Data::exp)
178     .def("_sqrt",&escript::Data::sqrt)
179     .def("_log10",&escript::Data::log10)
180     .def("_log",&escript::Data::log)
181     .def("_sign",&escript::Data::sign)
182     // functions returning a single real number:
183     .def("_Lsup",&escript::Data::Lsup)
184     .def("_sup",&escript::Data::sup)
185     .def("_inf",&escript::Data::inf)
186     .def("_integrate",&escript::Data::integrate)
187    
188     // following implements the python abs operator
189 jgs 108 .def("__abs__",&escript::Data::abs)
190 jgs 102 // following implements the python "-" negation operator
191     .def("__neg__",&escript::Data::neg)
192     // following implements the python "+" identity operator
193     .def("__pos__",&escript::Data::pos)
194     // following two functions implement the python [] operator
195     .def("__getitem__",&escript::Data::getItem)
196     .def("__setitem__",&escript::Data::setItemO)
197     .def("__setitem__",&escript::Data::setItemD)
198     // following two functions implement the python ** operator
199     .def("__pow__",&escript::Data::powO)
200     .def("__pow__",&escript::Data::powD)
201     // NOTE:: The order of these declarations is important. Anything
202     // declared before the generic declaration isn't found so the generic
203     // version will be called.
204     .def(self + other<object>())
205     .def(other<object>() + self)
206     .def(self + self)
207 gross 285 .def(self += other<object>())
208     .def(self += self)
209    
210 jgs 102 .def(self - other<object>())
211     .def(other<object>() - self)
212     .def(self - self)
213 gross 285 .def(self -= other<object>())
214     .def(self -= self)
215    
216 jgs 102 .def(self * other<object>())
217     .def(other<object>() * self)
218     .def(self * self)
219 gross 285 .def(self *= other<object>())
220     .def(self *= self)
221    
222 jgs 102 .def(self / other<object>())
223     .def(other<object>() / self)
224     .def(self / self)
225 gross 285 .def(self /= other<object>())
226     .def(self /= self)
227 jgs 102 // Need scope resolution due to a bug either in the compiler or
228     // the boost code. This calls operator << for Data.
229     .def(self_ns::str(self));
230    
231     //
232     // Factory methods for function space
233     //
234     def("ContinuousFunction",escript::continuousFunction);
235     def("Function",escript::function);
236     def("FunctionOnBoundary",escript::functionOnBoundary);
237     def("FunctionOnContactZero",escript::functionOnContactZero);
238     def("FunctionOnContactOne",escript::functionOnContactOne);
239     def("Solution",escript::solution);
240     def("ReducedSolution",escript::reducedSolution);
241     def("DiracDeltaFunction",escript::diracDeltaFunction);
242    
243     //
244     // Factory methods for Data
245     //
246     def("Scalar",escript::Scalar,
247     (arg("value")=0.0,
248     arg("what")=escript::FunctionSpace(),
249     arg("expanded")=false));
250     def("Vector",escript::Vector,
251     (arg("value")=0.0,
252     arg("what")=escript::FunctionSpace(),
253     arg("expanded")=false));
254     def("Tensor",escript::Tensor,
255     (arg("value")=0.0,
256     arg("what")=escript::FunctionSpace(),
257     arg("expanded")=false));
258     def("Tensor3",escript::Tensor3,
259     (arg("value")=0.0,
260     arg("what")=escript::FunctionSpace(),
261     arg("expanded")=false));
262     def("Tensor4",escript::Tensor4,
263     (arg("value")=0.0,
264     arg("what")=escript::FunctionSpace(),
265     arg("expanded")=false));
266    
267     //
268     // Interface for AbstractSystemMatrix
269     //
270     class_<escript::AbstractSystemMatrix>("Operator",init<>())
271     .def("isEmpty",&escript::AbstractSystemMatrix::isEmpty)
272     .def("solve",&escript::AbstractSystemMatrix::solve)
273     .def("of",&escript::AbstractSystemMatrix::vectorMultiply)
274     .def("saveMM",&escript::AbstractSystemMatrix::saveMM)
275 jgs 123 .def("saveHB",&escript::AbstractSystemMatrix::saveHB)
276 jgs 149 .def("resetValues",&escript::AbstractSystemMatrix::resetValues)
277 jgs 102 .def(self*other<escript::Data>());
278    
279     //
280     // Register esysExceptionTranslator
281     //
282     register_exception_translator<esysUtils::EsysException>(&esysUtils::esysExceptionTranslator);
283    
284     }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26