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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 474 - (hide annotations)
Mon Jan 30 04:23:44 2006 UTC (13 years, 7 months ago) by jgs
File size: 10906 byte(s)
restructure escript source tree
move src/Data/* -> src
remove inc
modify #includes and cpppath settings accordingly

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26