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

Legend:
Removed from v.126  
changed lines
  Added in v.1811

  ViewVC Help
Powered by ViewVC 1.1.26