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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1044 - (hide annotations)
Mon Mar 19 07:29:31 2007 UTC (12 years, 7 months ago) by gross
File size: 11596 byte(s)
clear name tagging is supported now.
1 jgs 102 //$Id$
2 elspeth 615 /*
3     ************************************************************
4     * Copyright 2006 by ACcESS MNRF *
5     * *
6     * http://www.access.edu.au *
7     * Primary Business: Queensland, Australia *
8     * Licensed under the Open Software License version 3.0 *
9     * http://www.opensource.org/licenses/osl-3.0.php *
10     * *
11     ************************************************************
12     */
13 jgs 102
14 jgs 474 #include "Data.h"
15     #include "FunctionSpace.h"
16     #include "FunctionSpaceFactory.h"
17     #include "DataFactory.h"
18     #include "AbstractContinuousDomain.h"
19     #include "AbstractDomain.h"
20     #include "Utils.h"
21 jgs 480 #include "AbstractSystemMatrix.h"
22 gross 797 #include "DataVector.h"
23 jgs 474
24 robwdcock 682 #include "esysUtils/esysExceptionTranslator.h"
25 jgs 102
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 gross 285 #include <boost/python/numeric.hpp>
32    
33 jgs 102 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 cochrane 358 * - <a href=http://iservo.edu.au/esys/epydoc/index.html>Python module documentation (epydoc generated)</a>
46 jgs 122 *
47 jgs 121 */
48 jgs 102
49 jgs 121 /*! \page escript Escript
50     * Escript is the python module that contains the interfaces
51     * to the C++ side of escript.
52     *
53     * \version 1.0.0
54     *
55     * \section class_desc Class Description:
56     * Data
57     *
58     * \section class_limits Class Limitations:
59     * None
60     *
61     * \section class_conds Class Conditions of Use:
62     * None
63     *
64     * \section class_throws Throws:
65     * None
66     *
67     */
68 jgs 102
69     BOOST_PYTHON_MODULE(escriptcpp)
70     {
71 gross 391 def("setNumberOfThreads",escript::setNumberOfThreads);
72     def("getNumberOfThreads",escript::getNumberOfThreads);
73 gross 797 def("releaseUnusedMemory",escript::releaseUnusedMemory);
74 jgs 102
75 gross 797
76 jgs 102 //
77     // Interface for AbstractDomain
78     //
79     class_<escript::AbstractDomain>("Domain",no_init)
80 gross 1044 .def("setTagMap",&escript::AbstractDomain::setTagMap)
81     .def("getTag",&escript::AbstractDomain::getTag)
82     .def("isValidTagName",&escript::AbstractDomain::isValidTagName)
83     .def("showTagNames",&escript::AbstractDomain::showTagNames)
84 jgs 102 .def("getX",&escript::AbstractDomain::getX)
85     .def("getNormal",&escript::AbstractDomain::getNormal)
86     .def("getSize",&escript::AbstractDomain::getSize)
87 jgs 153 .def("saveVTK",&escript::AbstractDomain::saveVTK)
88     .def("saveDX",&escript::AbstractDomain::saveDX)
89 jgs 102 .def(self == self)
90     .def(self != self);
91    
92     //
93     // Interface for AbstractContinuousDomain
94     //
95     class_<escript::AbstractContinuousDomain, bases<escript::AbstractDomain> >("ContinuousDomain",no_init)
96     .def("getSystemMatrixTypeId",&escript::AbstractContinuousDomain::getSystemMatrixTypeId);
97    
98     //
99     // Interface for FunctionSpace
100     //
101     class_<escript::FunctionSpace>("FunctionSpace",init<>())
102     .def("getDim",&escript::FunctionSpace::getDim)
103 jgs 153 .def("getDomain",&escript::FunctionSpace::getDomain,return_internal_reference<>())
104 jgs 102 .def("getX",&escript::FunctionSpace::getX)
105     .def("getNormal",&escript::FunctionSpace::getNormal)
106     .def("getSize",&escript::FunctionSpace::getSize)
107 gross 767 .def("setTags",&escript::FunctionSpace::setTags)
108 jgs 149 .def("getTagFromDataPointNo",&escript::FunctionSpace::getTagFromDataPointNo)
109 jgs 147 .def("__str__",&escript::FunctionSpace::toString)
110 jgs 102 .def(self == self)
111     .def(self != self);
112     //
113     // 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 gross 285 .def("__str__",&escript::Data::toString)
125 jgs 102 .def("getDomain",&escript::Data::getDomain,return_internal_reference<>())
126     .def("getFunctionSpace",&escript::Data::getFunctionSpace,return_internal_reference<>())
127     .def("isEmpty",&escript::Data::isEmpty)
128 gross 783 .def("isProtected",&escript::Data::isProtected)
129     .def("setProtection",&escript::Data::setProtection)
130 jgs 102 .def("getShape",&escript::Data::getShapeTuple)
131     .def("getRank",&escript::Data::getDataPointRank)
132 gross 950 .def("dump",&escript::Data::dump)
133 jgs 102 .def("copyWithMask",&escript::Data::copyWithMask)
134     .def("setTaggedValue",&escript::Data::setTaggedValue)
135 gross 1044 .def("setTaggedValue",&escript::Data::setTaggedValueByName)
136 gross 921 .def("getNumberOfDataPoints",&escript::Data::getNumDataPoints)
137 jgs 119 .def("expand",&escript::Data::expand)
138     .def("tag",&escript::Data::tag)
139 jgs 126 .def("copy",&escript::Data::copy)
140 gross 1034 .def("setValueOfDataPoint",&escript::Data::setValueOfDataPointToPyObject)
141     .def("setValueOfDataPoint",&escript::Data::setValueOfDataPointToArray)
142 gross 921 .def("setValueOfDataPoint",&escript::Data::setValueOfDataPoint)
143     .def("getValueOfDataPoint",&escript::Data::getValueOfDataPoint)
144     .def("getValueOfGlobalDataPoint",&escript::Data::getValueOfGlobalDataPoint)
145 gross 285 .def("interpolate",&escript::Data::interpolate)
146 gross 921 .def("minGlobalDataPoint",&escript::Data::minGlobalDataPoint)
147 gross 285 .def("saveDX",&escript::Data::saveDX)
148     .def("saveVTK",&escript::Data::saveVTK)
149 jgs 149 .def("getTagNumber",&escript::Data::getTagNumber)
150 jgs 119 .def("archiveData",&escript::Data::archiveData)
151     .def("extractData",&escript::Data::extractData)
152 gross 285 // Unary functions for Data
153     .def("_interpolate",&escript::Data::interpolate)
154     .def("_grad",&escript::Data::gradOn)
155     .def("_grad",&escript::Data::grad)
156     .def("_transpose",&escript::Data::transpose)
157     .def("_trace",&escript::Data::trace)
158     .def("_maxval",&escript::Data::maxval)
159     .def("_minval",&escript::Data::minval)
160 gross 698 .def("_wherePositive",&escript::Data::wherePositive)
161     .def("_whereNegative",&escript::Data::whereNegative)
162     .def("_whereNonNegative",&escript::Data::whereNonNegative)
163     .def("_whereNonPositive",&escript::Data::whereNonPositive)
164 jgs 571 .def("_whereZero",&escript::Data::whereZero,(arg("tol")=0.0))
165     .def("_whereNonZero",&escript::Data::whereNonZero,(arg("tol")=0.0))
166 ksteube 876 .def("_erf",&escript::Data::erf)
167 gross 285 .def("_sin",&escript::Data::sin)
168     .def("_cos",&escript::Data::cos)
169     .def("_tan",&escript::Data::tan)
170     .def("_asin",&escript::Data::asin)
171     .def("_acos",&escript::Data::acos)
172     .def("_atan",&escript::Data::atan)
173     .def("_sinh",&escript::Data::sinh)
174     .def("_cosh",&escript::Data::cosh)
175     .def("_tanh",&escript::Data::tanh)
176     .def("_asinh",&escript::Data::asinh)
177     .def("_acosh",&escript::Data::acosh)
178     .def("_atanh",&escript::Data::atanh)
179     .def("_exp",&escript::Data::exp)
180     .def("_sqrt",&escript::Data::sqrt)
181     .def("_log10",&escript::Data::log10)
182     .def("_log",&escript::Data::log)
183     .def("_sign",&escript::Data::sign)
184 ksteube 775 .def("_symmetric",&escript::Data::symmetric)
185     .def("_nonsymmetric",&escript::Data::nonsymmetric)
186 gross 800 .def("_trace",&escript::Data::trace)
187 gross 804 .def("_swap_axes",&escript::Data::swapaxes)
188 gross 576 .def("_eigenvalues",&escript::Data::eigenvalues)
189     .def("_eigenvalues_and_eigenvectors",&escript::Data::eigenvalues_and_eigenvectors,(arg("tol")=1.e-13))
190 gross 285 // functions returning a single real number:
191     .def("_Lsup",&escript::Data::Lsup)
192     .def("_sup",&escript::Data::sup)
193     .def("_inf",&escript::Data::inf)
194     .def("_integrate",&escript::Data::integrate)
195    
196     // following implements the python abs operator
197 jgs 108 .def("__abs__",&escript::Data::abs)
198 jgs 102 // following implements the python "-" negation operator
199     .def("__neg__",&escript::Data::neg)
200     // following implements the python "+" identity operator
201     .def("__pos__",&escript::Data::pos)
202     // following two functions implement the python [] operator
203     .def("__getitem__",&escript::Data::getItem)
204     .def("__setitem__",&escript::Data::setItemO)
205     .def("__setitem__",&escript::Data::setItemD)
206     // following two functions implement the python ** operator
207     .def("__pow__",&escript::Data::powO)
208     .def("__pow__",&escript::Data::powD)
209 gross 699 .def("__rpow__",&escript::Data::rpowO)
210 jgs 102 // NOTE:: The order of these declarations is important. Anything
211     // declared before the generic declaration isn't found so the generic
212     // version will be called.
213     .def(self + other<object>())
214     .def(other<object>() + self)
215     .def(self + self)
216 gross 285 .def(self += other<object>())
217     .def(self += self)
218    
219 jgs 102 .def(self - other<object>())
220     .def(other<object>() - self)
221     .def(self - self)
222 gross 285 .def(self -= other<object>())
223     .def(self -= self)
224    
225 jgs 102 .def(self * other<object>())
226     .def(other<object>() * self)
227     .def(self * self)
228 gross 285 .def(self *= other<object>())
229     .def(self *= self)
230    
231 jgs 102 .def(self / other<object>())
232     .def(other<object>() / self)
233     .def(self / self)
234 gross 285 .def(self /= other<object>())
235     .def(self /= self)
236 jgs 102 // Need scope resolution due to a bug either in the compiler or
237     // the boost code. This calls operator << for Data.
238     .def(self_ns::str(self));
239    
240     //
241     // Factory methods for function space
242     //
243     def("ContinuousFunction",escript::continuousFunction);
244     def("Function",escript::function);
245     def("FunctionOnBoundary",escript::functionOnBoundary);
246     def("FunctionOnContactZero",escript::functionOnContactZero);
247     def("FunctionOnContactOne",escript::functionOnContactOne);
248     def("Solution",escript::solution);
249     def("ReducedSolution",escript::reducedSolution);
250     def("DiracDeltaFunction",escript::diracDeltaFunction);
251    
252     //
253     // Factory methods for Data
254     //
255 gross 950 def("load",escript::load);
256 gross 1023 def("loadIsConfigured",escript::loadConfigured);
257 jgs 102 def("Scalar",escript::Scalar,
258     (arg("value")=0.0,
259     arg("what")=escript::FunctionSpace(),
260     arg("expanded")=false));
261     def("Vector",escript::Vector,
262     (arg("value")=0.0,
263     arg("what")=escript::FunctionSpace(),
264     arg("expanded")=false));
265     def("Tensor",escript::Tensor,
266     (arg("value")=0.0,
267     arg("what")=escript::FunctionSpace(),
268     arg("expanded")=false));
269     def("Tensor3",escript::Tensor3,
270     (arg("value")=0.0,
271     arg("what")=escript::FunctionSpace(),
272     arg("expanded")=false));
273     def("Tensor4",escript::Tensor4,
274     (arg("value")=0.0,
275     arg("what")=escript::FunctionSpace(),
276     arg("expanded")=false));
277    
278     //
279 ksteube 813 // Binary operators
280     //
281     def("C_GeneralTensorProduct",escript::C_GeneralTensorProduct,
282     (arg("arg0")=escript::Data(),
283     arg("arg1")=escript::Data(),
284     arg("axis_offset")=0,
285     arg("transpose")=0));
286    
287     //
288 jgs 102 // Interface for AbstractSystemMatrix
289     //
290     class_<escript::AbstractSystemMatrix>("Operator",init<>())
291     .def("isEmpty",&escript::AbstractSystemMatrix::isEmpty)
292     .def("solve",&escript::AbstractSystemMatrix::solve)
293     .def("of",&escript::AbstractSystemMatrix::vectorMultiply)
294     .def("saveMM",&escript::AbstractSystemMatrix::saveMM)
295 jgs 123 .def("saveHB",&escript::AbstractSystemMatrix::saveHB)
296 jgs 149 .def("resetValues",&escript::AbstractSystemMatrix::resetValues)
297 jgs 102 .def(self*other<escript::Data>());
298    
299     //
300     // Register esysExceptionTranslator
301     //
302     register_exception_translator<esysUtils::EsysException>(&esysUtils::esysExceptionTranslator);
303    
304     }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26