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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

trunk/esys2/escript/src/Data/escriptcpp.cpp revision 102 by jgs, Wed Dec 15 07:08:39 2004 UTC trunk/escript/src/Data/escriptcpp.cpp revision 391 by gross, Tue Dec 20 05:36:50 2005 UTC
# Line 16  Line 16 
16  ******************************************************************************/  ******************************************************************************/
17    
18  #include "escript/Data/Data.h"  #include "escript/Data/Data.h"
19    #include "escript/Data/DataVariable.h"
20  #include "escript/Data/FunctionSpace.h"  #include "escript/Data/FunctionSpace.h"
21  #include "escript/Data/FunctionSpaceFactory.h"  #include "escript/Data/FunctionSpaceFactory.h"
22  #include "escript/Data/DataFactory.h"  #include "escript/Data/DataFactory.h"
23  #include "escript/Data/AbstractContinuousDomain.h"  #include "escript/Data/AbstractContinuousDomain.h"
24  #include "escript/Data/AbstractDomain.h"  #include "escript/Data/AbstractDomain.h"
25    #include "escript/Data/Utils.h"
26  #include "esysUtils/esysExceptionTranslator.h"  #include "esysUtils/esysExceptionTranslator.h"
27    
28  #include <boost/python.hpp>  #include <boost/python.hpp>
# Line 28  Line 30 
30  #include <boost/python/def.hpp>  #include <boost/python/def.hpp>
31  #include <boost/python/object.hpp>  #include <boost/python/object.hpp>
32  #include <boost/python/tuple.hpp>  #include <boost/python/tuple.hpp>
33                                                                                                                                              #include <boost/python/numeric.hpp>
 using namespace boost::python;  
   
 /**  
    @memo  
    escript is the python module that contains the interfaces  
    to the C++ side of escript.  
   
    @version 1.0.0  
   
    @doc  
   
    Class Description:  
    Data  
34    
35     Class Limitations:  using namespace boost::python;
    None  
   
    Class Conditions of Use:  
    None  
   
    Throws:  
    None  
36    
37  */  /*! \mainpage Esys Documentation
38     *
39     * \version 1.0.0
40     *
41     * - \ref escript
42     *
43     * - \ref esys_exception "Esys Exception"
44     *
45     * - \ref finley
46     *
47     * - <a href=http://iservo.edu.au/esys/epydoc/index.html>Python module documentation (epydoc generated)</a>
48     *
49     */
50    
51    /*! \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    
71  BOOST_PYTHON_MODULE(escriptcpp)  BOOST_PYTHON_MODULE(escriptcpp)
72  {  {
73      def("setNumberOfThreads",escript::setNumberOfThreads);
74      def("getNumberOfThreads",escript::getNumberOfThreads);
75    
76    //    //
77    // Interface for AbstractDomain    // Interface for AbstractDomain
# Line 64  BOOST_PYTHON_MODULE(escriptcpp) Line 80  BOOST_PYTHON_MODULE(escriptcpp)
80       .def("getX",&escript::AbstractDomain::getX)       .def("getX",&escript::AbstractDomain::getX)
81       .def("getNormal",&escript::AbstractDomain::getNormal)       .def("getNormal",&escript::AbstractDomain::getNormal)
82       .def("getSize",&escript::AbstractDomain::getSize)       .def("getSize",&escript::AbstractDomain::getSize)
83         .def("saveVTK",&escript::AbstractDomain::saveVTK)
84         .def("saveDX",&escript::AbstractDomain::saveDX)
85       .def(self == self)       .def(self == self)
86       .def(self != self);       .def(self != self);
87    
# Line 78  BOOST_PYTHON_MODULE(escriptcpp) Line 96  BOOST_PYTHON_MODULE(escriptcpp)
96    //    //
97    class_<escript::FunctionSpace>("FunctionSpace",init<>())    class_<escript::FunctionSpace>("FunctionSpace",init<>())
98       .def("getDim",&escript::FunctionSpace::getDim)       .def("getDim",&escript::FunctionSpace::getDim)
99         .def("getDomain",&escript::FunctionSpace::getDomain,return_internal_reference<>())
100       .def("getX",&escript::FunctionSpace::getX)       .def("getX",&escript::FunctionSpace::getX)
101       .def("getNormal",&escript::FunctionSpace::getNormal)       .def("getNormal",&escript::FunctionSpace::getNormal)
102       .def("getSize",&escript::FunctionSpace::getSize)       .def("getSize",&escript::FunctionSpace::getSize)
103       .def("toString",&escript::FunctionSpace::toString)       .def("getTagFromDataPointNo",&escript::FunctionSpace::getTagFromDataPointNo)
104         .def("__str__",&escript::FunctionSpace::toString)
105       .def(self == self)       .def(self == self)
106       .def(self != self);       .def(self != self);
107    
108    //    //
109      // Interface for DataVariable
110      //
111      class_<escript::DataVariable>("DataVariable",init<>())
112        .def(init<escript::Data*>())
113        .def("evaluate",&escript::DataVariable::evaluate)
114        .def("sum",&escript::DataVariable::sum)
115        .def("diff",&escript::DataVariable::diff);
116    
117      //
118    // Interface for Data    // Interface for Data
119    //    //
120    class_<escript::Data>("Data",init<>())    class_<escript::Data>("Data","TEST DOCUMENTATION",init<>())
121      // various constructors for Data objects      // various constructors for Data objects
122      .def(init<const numeric::array&, optional<const escript::FunctionSpace&, bool> >(args("value","what","expand")))      .def(init<const numeric::array&, optional<const escript::FunctionSpace&, bool> >(args("value","what","expand")))
123      .def(init<const object&, optional<const escript::FunctionSpace&, bool> >(args("value","what","expand")))      .def(init<const object&, optional<const escript::FunctionSpace&, bool> >(args("value","what","expand")))
# Line 97  BOOST_PYTHON_MODULE(escriptcpp) Line 126  BOOST_PYTHON_MODULE(escriptcpp)
126      .def(init<const escript::Data&>())      .def(init<const escript::Data&>())
127      // Note for Lutz, Need to specify the call policy in order to return a      // Note for Lutz, Need to specify the call policy in order to return a
128      // reference. In this case return_internal_reference.      // reference. In this case return_internal_reference.
129      .def("toString",&escript::Data::toString)      .def("__str__",&escript::Data::toString)
130      .def("getDomain",&escript::Data::getDomain,return_internal_reference<>())      .def("getDomain",&escript::Data::getDomain,return_internal_reference<>())
131      .def("getFunctionSpace",&escript::Data::getFunctionSpace,return_internal_reference<>())      .def("getFunctionSpace",&escript::Data::getFunctionSpace,return_internal_reference<>())
132      .def("isEmpty",&escript::Data::isEmpty)      .def("isEmpty",&escript::Data::isEmpty)
# Line 105  BOOST_PYTHON_MODULE(escriptcpp) Line 134  BOOST_PYTHON_MODULE(escriptcpp)
134      .def("getRank",&escript::Data::getDataPointRank)      .def("getRank",&escript::Data::getDataPointRank)
135      .def("copyWithMask",&escript::Data::copyWithMask)      .def("copyWithMask",&escript::Data::copyWithMask)
136      .def("setTaggedValue",&escript::Data::setTaggedValue)      .def("setTaggedValue",&escript::Data::setTaggedValue)
137      //.def("expand",&escript::Data::expand)      .def("setRefValue",&escript::Data::setRefValue)
138      //.def("tag",&escript::Data::tag)      .def("getRefValue",&escript::Data::getRefValue)
139      .def("wherePositive",&escript::Data::wherePositive)      .def("expand",&escript::Data::expand)
140      .def("whereNegative",&escript::Data::whereNegative)      .def("tag",&escript::Data::tag)
141      .def("whereNonNegative",&escript::Data::whereNonNegative)      .def("copy",&escript::Data::copy)
142      .def("whereNonPositive",&escript::Data::whereNonPositive)      .def("convertToNumArray",&escript::Data::convertToNumArray)
143      .def("whereZero",&escript::Data::whereZero)      .def("convertToNumArrayFromSampleNo",&escript::Data::convertToNumArrayFromSampleNo)
144      .def("whereNonZero",&escript::Data::whereNonZero)      .def("convertToNumArrayFromDPNo",&escript::Data::convertToNumArrayFromDPNo)
145      // Unary functions for Data      .def("fillFromNumArray",&escript::Data::fillFromNumArray)
146      .def("interpolate",&escript::Data::interpolate)      .def("interpolate",&escript::Data::interpolate)
147      .def("grad",&escript::Data::gradOn)      .def("mindp",&escript::Data::mindp)
148      .def("grad",&escript::Data::grad)  
149      .def("integrate",&escript::Data::integrate)      .def("saveDX",&escript::Data::saveDX)
150      .def("transpose",&escript::Data::transpose)      .def("saveVTK",&escript::Data::saveVTK)
151      .def("trace",&escript::Data::trace)      .def("getTagNumber",&escript::Data::getTagNumber)
152      .def("sin",&escript::Data::sin)      .def("archiveData",&escript::Data::archiveData)
153      .def("cos",&escript::Data::cos)      .def("extractData",&escript::Data::extractData)
154      .def("tan",&escript::Data::tan)      // Unary functions for Data
155      .def("log",&escript::Data::log)      .def("_interpolate",&escript::Data::interpolate)
156      .def("ln",&escript::Data::ln)      .def("_grad",&escript::Data::gradOn)
157      .def("Lsup",&escript::Data::Lsup)      .def("_grad",&escript::Data::grad)
158      .def("sup",&escript::Data::sup)      .def("_transpose",&escript::Data::transpose)
159      .def("inf",&escript::Data::inf)      .def("_trace",&escript::Data::trace)
160      .def("abs",&escript::Data::abs)      .def("_maxval",&escript::Data::maxval)
161      .def("exp",&escript::Data::exp)      .def("_minval",&escript::Data::minval)
162      .def("sqrt",&escript::Data::sqrt)      .def("_wherePositive",&escript::Data::wherePositive)
163      .def("maxval",&escript::Data::maxval)      .def("_whereNegative",&escript::Data::whereNegative)
164      .def("minval",&escript::Data::minval)      .def("_whereNonNegative",&escript::Data::whereNonNegative)
165      .def("length",&escript::Data::length)      .def("_whereNonPositive",&escript::Data::whereNonPositive)
166      .def("sign",&escript::Data::sign)      .def("_whereZero",&escript::Data::whereZero)
167        .def("_whereNonZero",&escript::Data::whereNonZero)
168        .def("_sin",&escript::Data::sin)
169        .def("_cos",&escript::Data::cos)
170        .def("_tan",&escript::Data::tan)
171        .def("_asin",&escript::Data::asin)
172        .def("_acos",&escript::Data::acos)
173        .def("_atan",&escript::Data::atan)
174        .def("_sinh",&escript::Data::sinh)
175        .def("_cosh",&escript::Data::cosh)
176        .def("_tanh",&escript::Data::tanh)
177        .def("_asinh",&escript::Data::asinh)
178        .def("_acosh",&escript::Data::acosh)
179        .def("_atanh",&escript::Data::atanh)
180        .def("_exp",&escript::Data::exp)
181        .def("_sqrt",&escript::Data::sqrt)
182        .def("_log10",&escript::Data::log10)
183        .def("_log",&escript::Data::log)
184        .def("_sign",&escript::Data::sign)
185        // functions returning a single real number:
186        .def("_Lsup",&escript::Data::Lsup)
187        .def("_sup",&escript::Data::sup)
188        .def("_inf",&escript::Data::inf)
189        .def("_integrate",&escript::Data::integrate)
190    
191        // following implements the python abs operator
192        .def("__abs__",&escript::Data::abs)
193      // following implements the python "-" negation operator      // following implements the python "-" negation operator
194      .def("__neg__",&escript::Data::neg)      .def("__neg__",&escript::Data::neg)
195      // following implements the python "+" identity operator      // following implements the python "+" identity operator
# Line 149  BOOST_PYTHON_MODULE(escriptcpp) Line 204  BOOST_PYTHON_MODULE(escriptcpp)
204      // NOTE:: The order of these declarations is important. Anything      // NOTE:: The order of these declarations is important. Anything
205      // declared before the generic declaration isn't found so the generic      // declared before the generic declaration isn't found so the generic
206      // version will be called.      // version will be called.
     .def(self += other<object>())  
     .def(self += self)  
207      .def(self + other<object>())      .def(self + other<object>())
208      .def(other<object>() + self)      .def(other<object>() + self)
209      .def(self + self)      .def(self + self)
210      .def(self -= other<object>())      .def(self += other<object>())
211      .def(self -= self)      .def(self += self)
212    
213      .def(self - other<object>())      .def(self - other<object>())
214      .def(other<object>() - self)      .def(other<object>() - self)
215      .def(self - self)      .def(self - self)
216      .def(self *= other<object>())      .def(self -= other<object>())
217      .def(self *= self)      .def(self -= self)
218    
219      .def(self * other<object>())      .def(self * other<object>())
220      .def(other<object>() * self)      .def(other<object>() * self)
221      .def(self * self)      .def(self * self)
222      .def(self /= other<object>())      .def(self *= other<object>())
223      .def(self /= self)      .def(self *= self)
224    
225      .def(self / other<object>())      .def(self / other<object>())
226      .def(other<object>() / self)      .def(other<object>() / self)
227      .def(self / self)      .def(self / self)
228        .def(self /= other<object>())
229        .def(self /= self)
230      // Need scope resolution due to a bug either in the compiler or      // Need scope resolution due to a bug either in the compiler or
231      // the boost code. This calls operator << for Data.      // the boost code. This calls operator << for Data.
232      .def(self_ns::str(self));      .def(self_ns::str(self));
# Line 217  BOOST_PYTHON_MODULE(escriptcpp) Line 275  BOOST_PYTHON_MODULE(escriptcpp)
275       .def("solve",&escript::AbstractSystemMatrix::solve)       .def("solve",&escript::AbstractSystemMatrix::solve)
276       .def("of",&escript::AbstractSystemMatrix::vectorMultiply)       .def("of",&escript::AbstractSystemMatrix::vectorMultiply)
277       .def("saveMM",&escript::AbstractSystemMatrix::saveMM)       .def("saveMM",&escript::AbstractSystemMatrix::saveMM)
278       .def("setValue",&escript::AbstractSystemMatrix::setValue)       .def("saveHB",&escript::AbstractSystemMatrix::saveHB)
279         .def("resetValues",&escript::AbstractSystemMatrix::resetValues)
280       .def(self*other<escript::Data>());       .def(self*other<escript::Data>());
281    
282    //    //

Legend:
Removed from v.102  
changed lines
  Added in v.391

  ViewVC Help
Powered by ViewVC 1.1.26