/[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 119 by jgs, Tue Apr 12 04:45:05 2005 UTC trunk/escript/src/escriptcpp.cpp revision 964 by gross, Tue Feb 13 05:10:26 2007 UTC
# Line 1  Line 1 
1  //$Id$  //$Id$
2  /*=============================================================================  /*
3     ************************************************************
4   ******************************************************************************   *          Copyright 2006 by ACcESS MNRF                   *
5   *                                                                            *   *                                                          *
6   *       COPYRIGHT ACcESS 2004 -  All Rights Reserved                         *   *              http://www.access.edu.au                    *
7   *                                                                            *   *       Primary Business: Queensland, Australia            *
8   * This software is the property of ACcESS.  No part of this code             *   *  Licensed under the Open Software License version 3.0    *
9   * may be copied in any form or by any means without the expressed written    *   *     http://www.opensource.org/licenses/osl-3.0.php       *
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   ******************************************************************************  #include "Data.h"
15    #include "FunctionSpace.h"
16  ******************************************************************************/  #include "FunctionSpaceFactory.h"
17    #include "DataFactory.h"
18  #include "escript/Data/Data.h"  #include "AbstractContinuousDomain.h"
19  #include "escript/Data/FunctionSpace.h"  #include "AbstractDomain.h"
20  #include "escript/Data/FunctionSpaceFactory.h"  #include "Utils.h"
21  #include "escript/Data/DataFactory.h"  #include "AbstractSystemMatrix.h"
22  #include "escript/Data/AbstractContinuousDomain.h"  #include "DataVector.h"
23  #include "escript/Data/AbstractDomain.h"  
24  #include "esysUtils/esysExceptionTranslator.h"  #include "esysUtils/esysExceptionTranslator.h"
25    
26  #include <boost/python.hpp>  #include <boost/python.hpp>
# Line 28  Line 28 
28  #include <boost/python/def.hpp>  #include <boost/python/def.hpp>
29  #include <boost/python/object.hpp>  #include <boost/python/object.hpp>
30  #include <boost/python/tuple.hpp>  #include <boost/python/tuple.hpp>
31                                                                                                                                              #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  
32    
33     @doc  using namespace boost::python;
   
    Class Description:  
    Data  
   
    Class Limitations:  
    None  
   
    Class Conditions of Use:  
    None  
   
    Throws:  
    None  
34    
35  */  /*! \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     * - <a href=http://iservo.edu.au/esys/epydoc/index.html>Python module documentation (epydoc generated)</a>
46     *
47     */
48    
49    /*! \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    
69  BOOST_PYTHON_MODULE(escriptcpp)  BOOST_PYTHON_MODULE(escriptcpp)
70  {  {
71      def("setNumberOfThreads",escript::setNumberOfThreads);
72      def("getNumberOfThreads",escript::getNumberOfThreads);
73      def("releaseUnusedMemory",escript::releaseUnusedMemory);
74    
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("setTags",&escript::FunctionSpace::setTags)
104         .def("getTagFromDataPointNo",&escript::FunctionSpace::getTagFromDataPointNo)
105         .def("__str__",&escript::FunctionSpace::toString)
106       .def(self == self)       .def(self == self)
107       .def(self != self);       .def(self != self);
   
108    //    //
109    // Interface for Data    // Interface for Data
110    //    //
111    class_<escript::Data>("Data",init<>())    class_<escript::Data>("Data","TEST DOCUMENTATION",init<>())
112      // various constructors for Data objects      // various constructors for Data objects
113      .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")))
114      .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 117  BOOST_PYTHON_MODULE(escriptcpp)
117      .def(init<const escript::Data&>())      .def(init<const escript::Data&>())
118      // 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
119      // reference. In this case return_internal_reference.      // reference. In this case return_internal_reference.
120      .def("toString",&escript::Data::toString)      .def("__str__",&escript::Data::toString)
121      .def("getDomain",&escript::Data::getDomain,return_internal_reference<>())      .def("getDomain",&escript::Data::getDomain,return_internal_reference<>())
122      .def("getFunctionSpace",&escript::Data::getFunctionSpace,return_internal_reference<>())      .def("getFunctionSpace",&escript::Data::getFunctionSpace,return_internal_reference<>())
123      .def("isEmpty",&escript::Data::isEmpty)      .def("isEmpty",&escript::Data::isEmpty)
124        .def("isProtected",&escript::Data::isProtected)
125        .def("setProtection",&escript::Data::setProtection)
126      .def("getShape",&escript::Data::getShapeTuple)      .def("getShape",&escript::Data::getShapeTuple)
127      .def("getRank",&escript::Data::getDataPointRank)      .def("getRank",&escript::Data::getDataPointRank)
128        .def("dump",&escript::Data::dump)
129      .def("copyWithMask",&escript::Data::copyWithMask)      .def("copyWithMask",&escript::Data::copyWithMask)
130      .def("setTaggedValue",&escript::Data::setTaggedValue)      .def("setTaggedValue",&escript::Data::setTaggedValue)
131      .def("setRefValue",&escript::Data::setRefValue)      .def("getNumberOfDataPoints",&escript::Data::getNumDataPoints)
     .def("getRefValue",&escript::Data::getRefValue)  
132      .def("expand",&escript::Data::expand)      .def("expand",&escript::Data::expand)
133      .def("tag",&escript::Data::tag)      .def("tag",&escript::Data::tag)
134        .def("copy",&escript::Data::copy)
135        .def("convertToNumArray",&escript::Data::convertToNumArray)
136        .def("fillFromNumArray",&escript::Data::fillFromNumArray)
137        .def("setValueOfDataPoint",&escript::Data::setValueOfDataPoint)
138        .def("setValueOfDataPoint",&escript::Data::setValueOfDataPointToArray)
139        .def("getValueOfDataPoint",&escript::Data::getValueOfDataPoint)
140        .def("getValueOfGlobalDataPoint",&escript::Data::getValueOfGlobalDataPoint)
141        .def("interpolate",&escript::Data::interpolate)
142        .def("minGlobalDataPoint",&escript::Data::minGlobalDataPoint)
143      .def("saveDX",&escript::Data::saveDX)      .def("saveDX",&escript::Data::saveDX)
144      .def("saveVTK",&escript::Data::saveVTK)      .def("saveVTK",&escript::Data::saveVTK)
145      .def("wherePositive",&escript::Data::wherePositive)      .def("getTagNumber",&escript::Data::getTagNumber)
     .def("whereNegative",&escript::Data::whereNegative)  
     .def("whereNonNegative",&escript::Data::whereNonNegative)  
     .def("whereNonPositive",&escript::Data::whereNonPositive)  
     .def("whereZero",&escript::Data::whereZero)  
     .def("whereNonZero",&escript::Data::whereNonZero)  
     // Unary functions for Data  
     .def("interpolate",&escript::Data::interpolate)  
     .def("grad",&escript::Data::gradOn)  
     .def("grad",&escript::Data::grad)  
     .def("convertToNumArray",&escript::Data::convertToNumArray)  
146      .def("archiveData",&escript::Data::archiveData)      .def("archiveData",&escript::Data::archiveData)
147      .def("extractData",&escript::Data::extractData)      .def("extractData",&escript::Data::extractData)
148      .def("integrate",&escript::Data::integrate)      // Unary functions for Data
149      .def("transpose",&escript::Data::transpose)      .def("_interpolate",&escript::Data::interpolate)
150      .def("trace",&escript::Data::trace)      .def("_grad",&escript::Data::gradOn)
151      .def("sin",&escript::Data::sin)      .def("_grad",&escript::Data::grad)
152      .def("cos",&escript::Data::cos)      .def("_transpose",&escript::Data::transpose)
153      .def("tan",&escript::Data::tan)      .def("_trace",&escript::Data::trace)
154      .def("log",&escript::Data::log)      .def("_maxval",&escript::Data::maxval)
155      .def("ln",&escript::Data::ln)      .def("_minval",&escript::Data::minval)
156      .def("Lsup",&escript::Data::Lsup)      .def("_wherePositive",&escript::Data::wherePositive)
157      .def("Linf",&escript::Data::Lsup)      .def("_whereNegative",&escript::Data::whereNegative)
158      .def("sup",&escript::Data::sup)      .def("_whereNonNegative",&escript::Data::whereNonNegative)
159      .def("inf",&escript::Data::inf)      .def("_whereNonPositive",&escript::Data::whereNonPositive)
160        .def("_whereZero",&escript::Data::whereZero,(arg("tol")=0.0))
161        .def("_whereNonZero",&escript::Data::whereNonZero,(arg("tol")=0.0))
162        .def("_erf",&escript::Data::erf)
163        .def("_sin",&escript::Data::sin)
164        .def("_cos",&escript::Data::cos)
165        .def("_tan",&escript::Data::tan)
166        .def("_asin",&escript::Data::asin)
167        .def("_acos",&escript::Data::acos)
168        .def("_atan",&escript::Data::atan)
169        .def("_sinh",&escript::Data::sinh)
170        .def("_cosh",&escript::Data::cosh)
171        .def("_tanh",&escript::Data::tanh)
172        .def("_asinh",&escript::Data::asinh)
173        .def("_acosh",&escript::Data::acosh)
174        .def("_atanh",&escript::Data::atanh)
175        .def("_exp",&escript::Data::exp)
176        .def("_sqrt",&escript::Data::sqrt)
177        .def("_log10",&escript::Data::log10)
178        .def("_log",&escript::Data::log)
179        .def("_sign",&escript::Data::sign)
180        .def("_symmetric",&escript::Data::symmetric)
181        .def("_nonsymmetric",&escript::Data::nonsymmetric)
182        .def("_trace",&escript::Data::trace)
183        .def("_swap_axes",&escript::Data::swapaxes)
184        .def("_eigenvalues",&escript::Data::eigenvalues)
185        .def("_eigenvalues_and_eigenvectors",&escript::Data::eigenvalues_and_eigenvectors,(arg("tol")=1.e-13))
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      .def("__abs__",&escript::Data::abs)      .def("__abs__",&escript::Data::abs)
     .def("exp",&escript::Data::exp)  
     .def("sqrt",&escript::Data::sqrt)  
     .def("maxval",&escript::Data::maxval)  
     .def("minval",&escript::Data::minval)  
     .def("length",&escript::Data::length)  
     .def("sign",&escript::Data::sign)  
194      // following implements the python "-" negation operator      // following implements the python "-" negation operator
195      .def("__neg__",&escript::Data::neg)      .def("__neg__",&escript::Data::neg)
196      // following implements the python "+" identity operator      // following implements the python "+" identity operator
# Line 154  BOOST_PYTHON_MODULE(escriptcpp) Line 202  BOOST_PYTHON_MODULE(escriptcpp)
202      // following two functions implement the python ** operator      // following two functions implement the python ** operator
203      .def("__pow__",&escript::Data::powO)      .def("__pow__",&escript::Data::powO)
204      .def("__pow__",&escript::Data::powD)      .def("__pow__",&escript::Data::powD)
205        .def("__rpow__",&escript::Data::rpowO)
206      // NOTE:: The order of these declarations is important. Anything      // NOTE:: The order of these declarations is important. Anything
207      // declared before the generic declaration isn't found so the generic      // declared before the generic declaration isn't found so the generic
208      // version will be called.      // version will be called.
     .def(self += other<object>())  
     .def(self += self)  
209      .def(self + other<object>())      .def(self + other<object>())
210      .def(other<object>() + self)      .def(other<object>() + self)
211      .def(self + self)      .def(self + self)
212      .def(self -= other<object>())      .def(self += other<object>())
213      .def(self -= self)      .def(self += self)
214    
215      .def(self - other<object>())      .def(self - other<object>())
216      .def(other<object>() - self)      .def(other<object>() - self)
217      .def(self - self)      .def(self - self)
218      .def(self *= other<object>())      .def(self -= other<object>())
219      .def(self *= self)      .def(self -= self)
220    
221      .def(self * other<object>())      .def(self * other<object>())
222      .def(other<object>() * self)      .def(other<object>() * self)
223      .def(self * self)      .def(self * self)
224      .def(self /= other<object>())      .def(self *= other<object>())
225      .def(self /= self)      .def(self *= self)
226    
227      .def(self / other<object>())      .def(self / other<object>())
228      .def(other<object>() / self)      .def(other<object>() / self)
229      .def(self / self)      .def(self / self)
230        .def(self /= other<object>())
231        .def(self /= self)
232      // Need scope resolution due to a bug either in the compiler or      // Need scope resolution due to a bug either in the compiler or
233      // the boost code. This calls operator << for Data.      // the boost code. This calls operator << for Data.
234      .def(self_ns::str(self));      .def(self_ns::str(self));
# Line 196  BOOST_PYTHON_MODULE(escriptcpp) Line 248  BOOST_PYTHON_MODULE(escriptcpp)
248    //    //
249    // Factory methods for Data    // Factory methods for Data
250    //    //
251      def("load",escript::load);
252    def("Scalar",escript::Scalar,    def("Scalar",escript::Scalar,
253        (arg("value")=0.0,        (arg("value")=0.0,
254         arg("what")=escript::FunctionSpace(),         arg("what")=escript::FunctionSpace(),
# Line 218  BOOST_PYTHON_MODULE(escriptcpp) Line 271  BOOST_PYTHON_MODULE(escriptcpp)
271         arg("expanded")=false));         arg("expanded")=false));
272    
273    //    //
274      // Binary operators
275      //
276      def("C_GeneralTensorProduct",escript::C_GeneralTensorProduct,
277          (arg("arg0")=escript::Data(),
278           arg("arg1")=escript::Data(),
279           arg("axis_offset")=0,
280           arg("transpose")=0));
281    
282      //
283    // Interface for AbstractSystemMatrix    // Interface for AbstractSystemMatrix
284    //    //
285    class_<escript::AbstractSystemMatrix>("Operator",init<>())    class_<escript::AbstractSystemMatrix>("Operator",init<>())
# Line 225  BOOST_PYTHON_MODULE(escriptcpp) Line 287  BOOST_PYTHON_MODULE(escriptcpp)
287       .def("solve",&escript::AbstractSystemMatrix::solve)       .def("solve",&escript::AbstractSystemMatrix::solve)
288       .def("of",&escript::AbstractSystemMatrix::vectorMultiply)       .def("of",&escript::AbstractSystemMatrix::vectorMultiply)
289       .def("saveMM",&escript::AbstractSystemMatrix::saveMM)       .def("saveMM",&escript::AbstractSystemMatrix::saveMM)
290       .def("setValue",&escript::AbstractSystemMatrix::setValue)       .def("saveHB",&escript::AbstractSystemMatrix::saveHB)
291       .def("resetSolver",&escript::AbstractSystemMatrix::resetSolver)       .def("resetValues",&escript::AbstractSystemMatrix::resetValues)
292       .def(self*other<escript::Data>());       .def(self*other<escript::Data>());
293    
294    //    //

Legend:
Removed from v.119  
changed lines
  Added in v.964

  ViewVC Help
Powered by ViewVC 1.1.26