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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 149 - (hide annotations)
Thu Sep 1 03:31:39 2005 UTC (14 years, 1 month ago) by jgs
Original Path: trunk/esys2/escript/src/Data/escriptcpp.cpp
File size: 10579 byte(s)
Merge of development branch dev-02 back to main trunk on 2005-09-01

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26