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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 148 - (hide annotations)
Tue Aug 23 01:24:31 2005 UTC (14 years, 1 month ago) by jgs
Original Path: trunk/esys2/escript/src/Data/escriptcpp.cpp
File size: 10485 byte(s)
Merge of development branch dev-02 back to main trunk on 2005-08-23

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26