/[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 122 by jgs, Thu Jun 9 05:38:05 2005 UTC trunk/escript/src/escriptcpp.cpp revision 1718 by gross, Thu Aug 21 05:50:11 2008 UTC
# Line 1  Line 1 
1  //$Id$  
2  /*=============================================================================  /* $Id$ */
3    
4   ******************************************************************************  /*******************************************************
5   *                                                                            *   *
6   *       COPYRIGHT ACcESS 2004 -  All Rights Reserved                         *   *           Copyright 2003-2007 by ACceSS MNRF
7   *                                                                            *   *       Copyright 2007 by University of Queensland
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    *   *                http://esscc.uq.edu.au
10   * consent of ACcESS.  Copying, use or modification of this software          *   *        Primary Business: Queensland, Australia
11   * by any unauthorised person is illegal unless that                          *   *  Licensed under the Open Software License version 3.0
12   * person has a software license agreement with ACcESS.                       *   *     http://www.opensource.org/licenses/osl-3.0.php
13   *                                                                            *   *
14   ******************************************************************************   *******************************************************/
15    
16  ******************************************************************************/  #include "Data.h"
17    #include "FunctionSpace.h"
18  #include "escript/Data/Data.h"  #include "FunctionSpaceFactory.h"
19  #include "escript/Data/DataVariable.h"  #include "DataFactory.h"
20  #include "escript/Data/FunctionSpace.h"  #include "AbstractContinuousDomain.h"
21  #include "escript/Data/FunctionSpaceFactory.h"  #include "AbstractDomain.h"
22  #include "escript/Data/DataFactory.h"  #include "Utils.h"
23  #include "escript/Data/AbstractContinuousDomain.h"  #include "AbstractSystemMatrix.h"
24  #include "escript/Data/AbstractDomain.h"  #include "AbstractTransportProblem.h"
25    #include "DataVector.h"
26    
27    extern "C" {
28    #include "escript/blocktimer.h"
29    }
30    
31  #include "esysUtils/esysExceptionTranslator.h"  #include "esysUtils/esysExceptionTranslator.h"
32    
33  #include <boost/python.hpp>  #include <boost/python.hpp>
# Line 29  Line 35 
35  #include <boost/python/def.hpp>  #include <boost/python/def.hpp>
36  #include <boost/python/object.hpp>  #include <boost/python/object.hpp>
37  #include <boost/python/tuple.hpp>  #include <boost/python/tuple.hpp>
38                                                                                                                                              #include <boost/python/numeric.hpp>
39    
40  using namespace boost::python;  using namespace boost::python;
41    
42  /*! \mainpage Esys Documentation  /*! \mainpage Esys Documentation
# Line 42  using namespace boost::python; Line 49  using namespace boost::python;
49   *   *
50   * - \ref finley   * - \ref finley
51   *   *
52   * - <a href=http://www.esscc.uq.edu.au/~cochrane/esys_python_doc/html/index.html>Python module documentation (doxygen generated)</a>   * - <a href=http://iservo.edu.au/esys/epydoc/index.html>Python module documentation (epydoc generated)</a>
  *  
  * - <a href=http://www.esscc.uq.edu.au/~cochrane/esys_python_doc/index.html>Python module documentation (epydoc generated)</a>  
53   *   *
54   */   */
55    
# Line 70  using namespace boost::python; Line 75  using namespace boost::python;
75    
76  BOOST_PYTHON_MODULE(escriptcpp)  BOOST_PYTHON_MODULE(escriptcpp)
77  {  {
78      def("setNumberOfThreads",escript::setNumberOfThreads);
79      def("getNumberOfThreads",escript::getNumberOfThreads);
80      def("releaseUnusedMemory",escript::releaseUnusedMemory);
81      def("blocktimer_initialize",blocktimer_initialize);
82      def("blocktimer_reportSortByName",blocktimer_reportSortByName);
83      def("blocktimer_reportSortByTime",blocktimer_reportSortByTime);
84      def("blocktimer_increment",blocktimer_increment);
85      def("blocktimer_time",blocktimer_time);
86      def("getVersion",escript::getSvnVersion);
87      def("printParallelThreadCounts",escript::printParallelThreadCnt);
88    
89    
90    //    //
91    // Interface for AbstractDomain    // Interface for AbstractDomain
92    //    //
93    class_<escript::AbstractDomain>("Domain",no_init)    class_<escript::AbstractDomain>("Domain",no_init)
94         .def("setTagMap",&escript::AbstractDomain::setTagMap)
95         .def("getTag",&escript::AbstractDomain::getTag)
96         .def("isValidTagName",&escript::AbstractDomain::isValidTagName)
97         .def("showTagNames",&escript::AbstractDomain::showTagNames)
98       .def("getX",&escript::AbstractDomain::getX)       .def("getX",&escript::AbstractDomain::getX)
99       .def("getNormal",&escript::AbstractDomain::getNormal)       .def("getNormal",&escript::AbstractDomain::getNormal)
100       .def("getSize",&escript::AbstractDomain::getSize)       .def("getSize",&escript::AbstractDomain::getSize)
101         .def("saveVTK",&escript::AbstractDomain::saveVTK)
102         .def("saveDX",&escript::AbstractDomain::saveDX)
103         .def("getMPISize",&escript::AbstractDomain::getMPISize)
104         .def("getMPIRank",&escript::AbstractDomain::getMPIRank)
105    
106       .def(self == self)       .def(self == self)
107       .def(self != self);       .def(self != self);
108    
# Line 90  BOOST_PYTHON_MODULE(escriptcpp) Line 115  BOOST_PYTHON_MODULE(escriptcpp)
115    //    //
116    // Interface for FunctionSpace    // Interface for FunctionSpace
117    //    //
118    class_<escript::FunctionSpace>("FunctionSpace",init<>())    class_<escript::FunctionSpace> fs_definer("FunctionSpace",init<>());
119       .def("getDim",&escript::FunctionSpace::getDim)    fs_definer.def("getDim",&escript::FunctionSpace::getDim);
120       .def("getX",&escript::FunctionSpace::getX)    fs_definer.def("getDomain",&escript::FunctionSpace::getDomain,
121       .def("getNormal",&escript::FunctionSpace::getNormal)                   return_internal_reference<>());
122       .def("getSize",&escript::FunctionSpace::getSize)    fs_definer.def("getX",&escript::FunctionSpace::getX);
123       .def("toString",&escript::FunctionSpace::toString)    fs_definer.def("getNormal",&escript::FunctionSpace::getNormal);
124       .def(self == self)    fs_definer.def("getSize",&escript::FunctionSpace::getSize);
125       .def(self != self);    fs_definer.def("setTags",&escript::FunctionSpace::setTags);
126      fs_definer.def("getTagFromDataPointNo",
127    //                   &escript::FunctionSpace::getTagFromDataPointNo);
128    // Interface for DataVariable    fs_definer.def("getReferenceIDFromDataPointNo", &escript::FunctionSpace::getReferenceIDFromDataPointNo);
129    //    fs_definer.def("getListOfTags",&escript::FunctionSpace::getListOfTags);
130    class_<escript::DataVariable>("DataVariable",init<>())    fs_definer.def("__str__", &escript::FunctionSpace::toString);
131      .def(init<escript::Data*>())    fs_definer.def(self == self);
132      .def("evaluate",&escript::DataVariable::evaluate)    fs_definer.def(self != self);
     .def("sum",&escript::DataVariable::sum)  
     .def("diff",&escript::DataVariable::diff);  
   
133    //    //
134    // Interface for Data    // Interface for Data
135    //    //
136    class_<escript::Data>("Data",init<>())    class_<escript::Data>("Data","TEST DOCUMENTATION",init<>())
137      // various constructors for Data objects      // various constructors for Data objects
138      .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")))
139      .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 120  BOOST_PYTHON_MODULE(escriptcpp) Line 142  BOOST_PYTHON_MODULE(escriptcpp)
142      .def(init<const escript::Data&>())      .def(init<const escript::Data&>())
143      // 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
144      // reference. In this case return_internal_reference.      // reference. In this case return_internal_reference.
145      .def("toString",&escript::Data::toString)      .def("__str__",&escript::Data::toString)
146      .def("getDomain",&escript::Data::getDomain,return_internal_reference<>())      .def("getDomain",&escript::Data::getDomain,return_internal_reference<>())
147      .def("getFunctionSpace",&escript::Data::getFunctionSpace,return_internal_reference<>())      .def("getFunctionSpace",&escript::Data::getFunctionSpace,return_internal_reference<>())
148      .def("isEmpty",&escript::Data::isEmpty)      .def("isEmpty",&escript::Data::isEmpty)
149        .def("isProtected",&escript::Data::isProtected)
150        .def("setProtection",&escript::Data::setProtection)
151      .def("getShape",&escript::Data::getShapeTuple)      .def("getShape",&escript::Data::getShapeTuple)
152      .def("getRank",&escript::Data::getDataPointRank)      .def("getRank",&escript::Data::getDataPointRank)
153        .def("dump",&escript::Data::dump)
154      .def("copyWithMask",&escript::Data::copyWithMask)      .def("copyWithMask",&escript::Data::copyWithMask)
155      .def("setTaggedValue",&escript::Data::setTaggedValue)      .def("setTaggedValue",&escript::Data::setTaggedValue)
156      .def("setRefValue",&escript::Data::setRefValue)      .def("setTaggedValue",&escript::Data::setTaggedValueByName)
157      .def("getRefValue",&escript::Data::getRefValue)      .def("getNumberOfDataPoints",&escript::Data::getNumDataPoints)
158        .def("isExpanded",&escript::Data::isExpanded)
159        .def("isTagged",&escript::Data::isTagged)
160      .def("expand",&escript::Data::expand)      .def("expand",&escript::Data::expand)
161      .def("tag",&escript::Data::tag)      .def("tag",&escript::Data::tag)
162        .def("copy",&escript::Data::copy)
163        .def("setValueOfDataPoint",&escript::Data::setValueOfDataPointToPyObject)
164        .def("setValueOfDataPoint",&escript::Data::setValueOfDataPointToArray)
165        .def("setValueOfDataPoint",&escript::Data::setValueOfDataPoint)
166        .def("getValueOfDataPoint",&escript::Data::getValueOfDataPoint)
167        .def("getValueOfGlobalDataPoint",&escript::Data::getValueOfGlobalDataPoint)
168        .def("setToZero",&escript::Data::setToZero)
169        .def("interpolate",&escript::Data::interpolate)
170        .def("minGlobalDataPoint",&escript::Data::minGlobalDataPoint)
171      .def("saveDX",&escript::Data::saveDX)      .def("saveDX",&escript::Data::saveDX)
172      .def("saveVTK",&escript::Data::saveVTK)      .def("saveVTK",&escript::Data::saveVTK)
173      .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)  
     .def("convertToNumArrayFromSampleNo",&escript::Data::convertToNumArrayFromSampleNo)  
     .def("convertToNumArrayFromDPNo",&escript::Data::convertToNumArrayFromDPNo)  
174      .def("archiveData",&escript::Data::archiveData)      .def("archiveData",&escript::Data::archiveData)
175      .def("extractData",&escript::Data::extractData)      .def("extractData",&escript::Data::extractData)
176      .def("integrate",&escript::Data::integrate)      // Unary functions for Data
177      .def("transpose",&escript::Data::transpose)      .def("_interpolate",&escript::Data::interpolate)
178      .def("trace",&escript::Data::trace)      .def("_grad",&escript::Data::gradOn)
179      .def("sin",&escript::Data::sin)      .def("_grad",&escript::Data::grad)
180      .def("cos",&escript::Data::cos)      .def("_transpose",&escript::Data::transpose)
181      .def("tan",&escript::Data::tan)      .def("_trace",&escript::Data::trace)
182      .def("log",&escript::Data::log)      .def("_maxval",&escript::Data::maxval)
183      .def("ln",&escript::Data::ln)      .def("_minval",&escript::Data::minval)
184      .def("Lsup",&escript::Data::Lsup)      .def("_wherePositive",&escript::Data::wherePositive)
185      .def("Linf",&escript::Data::Lsup)      .def("_whereNegative",&escript::Data::whereNegative)
186      .def("sup",&escript::Data::sup)      .def("_whereNonNegative",&escript::Data::whereNonNegative)
187      .def("inf",&escript::Data::inf)      .def("_whereNonPositive",&escript::Data::whereNonPositive)
188        .def("_whereZero",&escript::Data::whereZero,(arg("tol")=0.0))
189        .def("_whereNonZero",&escript::Data::whereNonZero,(arg("tol")=0.0))
190        .def("_erf",&escript::Data::erf)
191        .def("_sin",&escript::Data::sin)
192        .def("_cos",&escript::Data::cos)
193        .def("_tan",&escript::Data::tan)
194        .def("_asin",&escript::Data::asin)
195        .def("_acos",&escript::Data::acos)
196        .def("_atan",&escript::Data::atan)
197        .def("_sinh",&escript::Data::sinh)
198        .def("_cosh",&escript::Data::cosh)
199        .def("_tanh",&escript::Data::tanh)
200        .def("_asinh",&escript::Data::asinh)
201        .def("_acosh",&escript::Data::acosh)
202        .def("_atanh",&escript::Data::atanh)
203        .def("_exp",&escript::Data::exp)
204        .def("_sqrt",&escript::Data::sqrt)
205        .def("_log10",&escript::Data::log10)
206        .def("_log",&escript::Data::log)
207        .def("_sign",&escript::Data::sign)
208        .def("_symmetric",&escript::Data::symmetric)
209        .def("_nonsymmetric",&escript::Data::nonsymmetric)
210        .def("_trace",&escript::Data::trace)
211        .def("_swap_axes",&escript::Data::swapaxes)
212        .def("_eigenvalues",&escript::Data::eigenvalues)
213        .def("_eigenvalues_and_eigenvectors",&escript::Data::eigenvalues_and_eigenvectors,(arg("tol")=1.e-13))
214        // functions returning a single real number:
215        .def("_Lsup",&escript::Data::Lsup)
216        .def("_sup",&escript::Data::sup)
217        .def("_inf",&escript::Data::inf)
218        .def("_integrate",&escript::Data::integrate)
219    
220        // following implements the python abs operator
221      .def("__abs__",&escript::Data::abs)      .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("mindp",&escript::Data::mindp)  
     .def("length",&escript::Data::length)  
     .def("sign",&escript::Data::sign)  
222      // following implements the python "-" negation operator      // following implements the python "-" negation operator
223      .def("__neg__",&escript::Data::neg)      .def("__neg__",&escript::Data::neg)
     .def("neg",&escript::Data::neg)  
224      // following implements the python "+" identity operator      // following implements the python "+" identity operator
225      .def("__pos__",&escript::Data::pos)      .def("__pos__",&escript::Data::pos)
     .def("pos",&escript::Data::pos)  
226      // following two functions implement the python [] operator      // following two functions implement the python [] operator
227      .def("__getitem__",&escript::Data::getItem)      .def("__getitem__",&escript::Data::getItem)
228      .def("__setitem__",&escript::Data::setItemO)      .def("__setitem__",&escript::Data::setItemO)
# Line 183  BOOST_PYTHON_MODULE(escriptcpp) Line 230  BOOST_PYTHON_MODULE(escriptcpp)
230      // following two functions implement the python ** operator      // following two functions implement the python ** operator
231      .def("__pow__",&escript::Data::powO)      .def("__pow__",&escript::Data::powO)
232      .def("__pow__",&escript::Data::powD)      .def("__pow__",&escript::Data::powD)
233        .def("__rpow__",&escript::Data::rpowO)
234      // NOTE:: The order of these declarations is important. Anything      // NOTE:: The order of these declarations is important. Anything
235      // declared before the generic declaration isn't found so the generic      // declared before the generic declaration isn't found so the generic
236      // version will be called.      // version will be called.
     .def(self += other<object>())  
     .def(self += self)  
237      .def(self + other<object>())      .def(self + other<object>())
238      .def(other<object>() + self)      .def(other<object>() + self)
239      .def(self + self)      .def(self + self)
240      .def(self -= other<object>())      .def(self += other<object>())
241      .def(self -= self)      .def(self += self)
242    
243      .def(self - other<object>())      .def(self - other<object>())
244      .def(other<object>() - self)      .def(other<object>() - self)
245      .def(self - self)      .def(self - self)
246      .def(self *= other<object>())      .def(self -= other<object>())
247      .def(self *= self)      .def(self -= self)
248    
249      .def(self * other<object>())      .def(self * other<object>())
250      .def(other<object>() * self)      .def(other<object>() * self)
251      .def(self * self)      .def(self * self)
252      .def(self /= other<object>())      .def(self *= other<object>())
253      .def(self /= self)      .def(self *= self)
254    
255      .def(self / other<object>())      .def(self / other<object>())
256      .def(other<object>() / self)      .def(other<object>() / self)
257      .def(self / self)      .def(self / self)
258        .def(self /= other<object>())
259        .def(self /= self)
260      // Need scope resolution due to a bug either in the compiler or      // Need scope resolution due to a bug either in the compiler or
261      // the boost code. This calls operator << for Data.      // the boost code. This calls operator << for Data.
262      .def(self_ns::str(self));      .def(self_ns::str(self));
# Line 214  BOOST_PYTHON_MODULE(escriptcpp) Line 265  BOOST_PYTHON_MODULE(escriptcpp)
265    // Factory methods for function space    // Factory methods for function space
266    //    //
267    def("ContinuousFunction",escript::continuousFunction);    def("ContinuousFunction",escript::continuousFunction);
268      def("ReducedContinuousFunction",escript::reducedContinuousFunction);
269    def("Function",escript::function);    def("Function",escript::function);
270      def("ReducedFunction",escript::reducedFunction);
271    def("FunctionOnBoundary",escript::functionOnBoundary);    def("FunctionOnBoundary",escript::functionOnBoundary);
272      def("ReducedFunctionOnBoundary",escript::reducedFunctionOnBoundary);
273    def("FunctionOnContactZero",escript::functionOnContactZero);    def("FunctionOnContactZero",escript::functionOnContactZero);
274      def("ReducedFunctionOnContactZero",escript::reducedFunctionOnContactZero);
275    def("FunctionOnContactOne",escript::functionOnContactOne);    def("FunctionOnContactOne",escript::functionOnContactOne);
276      def("ReducedFunctionOnContactOne",escript::reducedFunctionOnContactOne);
277    def("Solution",escript::solution);    def("Solution",escript::solution);
278    def("ReducedSolution",escript::reducedSolution);    def("ReducedSolution",escript::reducedSolution);
279    def("DiracDeltaFunction",escript::diracDeltaFunction);    def("DiracDeltaFunction",escript::diracDeltaFunction);
# Line 225  BOOST_PYTHON_MODULE(escriptcpp) Line 281  BOOST_PYTHON_MODULE(escriptcpp)
281    //    //
282    // Factory methods for Data    // Factory methods for Data
283    //    //
284      def("load",escript::load);
285      def("loadIsConfigured",escript::loadConfigured);
286    def("Scalar",escript::Scalar,    def("Scalar",escript::Scalar,
287        (arg("value")=0.0,        (arg("value")=0.0,
288         arg("what")=escript::FunctionSpace(),         arg("what")=escript::FunctionSpace(),
# Line 247  BOOST_PYTHON_MODULE(escriptcpp) Line 305  BOOST_PYTHON_MODULE(escriptcpp)
305         arg("expanded")=false));         arg("expanded")=false));
306    
307    //    //
308      // Binary operators
309      //
310      def("C_GeneralTensorProduct",escript::C_GeneralTensorProduct,
311          (arg("arg0")=escript::Data(),
312           arg("arg1")=escript::Data(),
313           arg("axis_offset")=0,
314           arg("transpose")=0));
315    
316      //
317    // Interface for AbstractSystemMatrix    // Interface for AbstractSystemMatrix
318    //    //
319    class_<escript::AbstractSystemMatrix>("Operator",init<>())    class_<escript::AbstractSystemMatrix>("Operator",init<>())
# Line 254  BOOST_PYTHON_MODULE(escriptcpp) Line 321  BOOST_PYTHON_MODULE(escriptcpp)
321       .def("solve",&escript::AbstractSystemMatrix::solve)       .def("solve",&escript::AbstractSystemMatrix::solve)
322       .def("of",&escript::AbstractSystemMatrix::vectorMultiply)       .def("of",&escript::AbstractSystemMatrix::vectorMultiply)
323       .def("saveMM",&escript::AbstractSystemMatrix::saveMM)       .def("saveMM",&escript::AbstractSystemMatrix::saveMM)
324       .def("setValue",&escript::AbstractSystemMatrix::setValue)       .def("saveHB",&escript::AbstractSystemMatrix::saveHB)
325       .def("resetSolver",&escript::AbstractSystemMatrix::resetSolver)       .def("resetValues",&escript::AbstractSystemMatrix::resetValues)
326       .def(self*other<escript::Data>());       .def(self*other<escript::Data>());
327      //
328      // Interface for AbstractTransportProblem
329      //
330      class_<escript::AbstractTransportProblem>("TransportProblem",init<>())
331         .def("isEmpty",&escript::AbstractTransportProblem::isEmpty)
332         .def("solve",&escript::AbstractTransportProblem::solve)
333         .def("setInitialValue",&escript::AbstractTransportProblem::setInitialValue)
334         .def("insertConstraint",&escript::AbstractTransportProblem::insertConstraint)
335         .def("reset",&escript::AbstractTransportProblem::resetTransport)
336         .def("getSafeTimeStepSize",&escript::AbstractTransportProblem::getSafeTimeStepSize);
337    
338    //    //
339    // Register esysExceptionTranslator    // Register esysExceptionTranslator

Legend:
Removed from v.122  
changed lines
  Added in v.1718

  ViewVC Help
Powered by ViewVC 1.1.26