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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 104 - (hide annotations)
Fri Dec 17 07:43:12 2004 UTC (14 years, 10 months ago) by jgs
Original Path: trunk/esys2/escript/src/Data/escriptcpp.cpp
File size: 8753 byte(s)
*** empty log message ***

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     #include "escript/Data/Data.h"
19     #include "escript/Data/FunctionSpace.h"
20     #include "escript/Data/FunctionSpaceFactory.h"
21     #include "escript/Data/DataFactory.h"
22     #include "escript/Data/AbstractContinuousDomain.h"
23     #include "escript/Data/AbstractDomain.h"
24     #include "esysUtils/esysExceptionTranslator.h"
25    
26     #include <boost/python.hpp>
27     #include <boost/python/module.hpp>
28     #include <boost/python/def.hpp>
29     #include <boost/python/object.hpp>
30     #include <boost/python/tuple.hpp>
31    
32     using namespace boost::python;
33    
34     /**
35     @memo
36     escript is the python module that contains the interfaces
37     to the C++ side of escript.
38    
39     @version 1.0.0
40    
41     @doc
42    
43     Class Description:
44     Data
45    
46     Class Limitations:
47     None
48    
49     Class Conditions of Use:
50     None
51    
52     Throws:
53     None
54    
55     */
56    
57     BOOST_PYTHON_MODULE(escriptcpp)
58     {
59    
60     //
61     // Interface for AbstractDomain
62     //
63     class_<escript::AbstractDomain>("Domain",no_init)
64     .def("getX",&escript::AbstractDomain::getX)
65     .def("getNormal",&escript::AbstractDomain::getNormal)
66     .def("getSize",&escript::AbstractDomain::getSize)
67     .def(self == self)
68     .def(self != self);
69    
70     //
71     // Interface for AbstractContinuousDomain
72     //
73     class_<escript::AbstractContinuousDomain, bases<escript::AbstractDomain> >("ContinuousDomain",no_init)
74     .def("getSystemMatrixTypeId",&escript::AbstractContinuousDomain::getSystemMatrixTypeId);
75    
76     //
77     // Interface for FunctionSpace
78     //
79     class_<escript::FunctionSpace>("FunctionSpace",init<>())
80     .def("getDim",&escript::FunctionSpace::getDim)
81     .def("getX",&escript::FunctionSpace::getX)
82     .def("getNormal",&escript::FunctionSpace::getNormal)
83     .def("getSize",&escript::FunctionSpace::getSize)
84     .def("toString",&escript::FunctionSpace::toString)
85     .def(self == self)
86     .def(self != self);
87    
88     //
89     // Interface for Data
90     //
91     class_<escript::Data>("Data",init<>())
92     // various constructors for Data objects
93     .def(init<const numeric::array&, optional<const escript::FunctionSpace&, bool> >(args("value","what","expand")))
94     .def(init<const object&, optional<const escript::FunctionSpace&, bool> >(args("value","what","expand")))
95     .def(init<const double, const tuple&, optional<const escript::FunctionSpace&, bool> >(args("value","shape","what","expand")))
96     .def(init<const escript::Data&, const escript::FunctionSpace&>(args("value","what")))
97     .def(init<const escript::Data&>())
98     // Note for Lutz, Need to specify the call policy in order to return a
99     // reference. In this case return_internal_reference.
100     .def("toString",&escript::Data::toString)
101     .def("getDomain",&escript::Data::getDomain,return_internal_reference<>())
102     .def("getFunctionSpace",&escript::Data::getFunctionSpace,return_internal_reference<>())
103     .def("isEmpty",&escript::Data::isEmpty)
104     .def("getShape",&escript::Data::getShapeTuple)
105     .def("getRank",&escript::Data::getDataPointRank)
106     .def("copyWithMask",&escript::Data::copyWithMask)
107     .def("setTaggedValue",&escript::Data::setTaggedValue)
108     //.def("expand",&escript::Data::expand)
109     //.def("tag",&escript::Data::tag)
110 jgs 104 .def("saveDX",&escript::Data::saveDX)
111 jgs 102 .def("wherePositive",&escript::Data::wherePositive)
112     .def("whereNegative",&escript::Data::whereNegative)
113     .def("whereNonNegative",&escript::Data::whereNonNegative)
114     .def("whereNonPositive",&escript::Data::whereNonPositive)
115     .def("whereZero",&escript::Data::whereZero)
116     .def("whereNonZero",&escript::Data::whereNonZero)
117     // Unary functions for Data
118     .def("interpolate",&escript::Data::interpolate)
119     .def("grad",&escript::Data::gradOn)
120     .def("grad",&escript::Data::grad)
121     .def("integrate",&escript::Data::integrate)
122     .def("transpose",&escript::Data::transpose)
123     .def("trace",&escript::Data::trace)
124     .def("sin",&escript::Data::sin)
125     .def("cos",&escript::Data::cos)
126     .def("tan",&escript::Data::tan)
127     .def("log",&escript::Data::log)
128     .def("ln",&escript::Data::ln)
129     .def("Lsup",&escript::Data::Lsup)
130     .def("sup",&escript::Data::sup)
131     .def("inf",&escript::Data::inf)
132     .def("abs",&escript::Data::abs)
133     .def("exp",&escript::Data::exp)
134     .def("sqrt",&escript::Data::sqrt)
135     .def("maxval",&escript::Data::maxval)
136     .def("minval",&escript::Data::minval)
137     .def("length",&escript::Data::length)
138     .def("sign",&escript::Data::sign)
139     // following implements the python "-" negation operator
140     .def("__neg__",&escript::Data::neg)
141     // following implements the python "+" identity operator
142     .def("__pos__",&escript::Data::pos)
143     // following two functions implement the python [] operator
144     .def("__getitem__",&escript::Data::getItem)
145     .def("__setitem__",&escript::Data::setItemO)
146     .def("__setitem__",&escript::Data::setItemD)
147     // following two functions implement the python ** operator
148     .def("__pow__",&escript::Data::powO)
149     .def("__pow__",&escript::Data::powD)
150     // NOTE:: The order of these declarations is important. Anything
151     // declared before the generic declaration isn't found so the generic
152     // version will be called.
153     .def(self += other<object>())
154     .def(self += self)
155     .def(self + other<object>())
156     .def(other<object>() + self)
157     .def(self + self)
158     .def(self -= other<object>())
159     .def(self -= self)
160     .def(self - other<object>())
161     .def(other<object>() - self)
162     .def(self - self)
163     .def(self *= other<object>())
164     .def(self *= self)
165     .def(self * other<object>())
166     .def(other<object>() * self)
167     .def(self * self)
168     .def(self /= other<object>())
169     .def(self /= self)
170     .def(self / other<object>())
171     .def(other<object>() / self)
172     .def(self / self)
173     // Need scope resolution due to a bug either in the compiler or
174     // the boost code. This calls operator << for Data.
175     .def(self_ns::str(self));
176    
177     //
178     // Factory methods for function space
179     //
180     def("ContinuousFunction",escript::continuousFunction);
181     def("Function",escript::function);
182     def("FunctionOnBoundary",escript::functionOnBoundary);
183     def("FunctionOnContactZero",escript::functionOnContactZero);
184     def("FunctionOnContactOne",escript::functionOnContactOne);
185     def("Solution",escript::solution);
186     def("ReducedSolution",escript::reducedSolution);
187     def("DiracDeltaFunction",escript::diracDeltaFunction);
188    
189     //
190     // Factory methods for Data
191     //
192     def("Scalar",escript::Scalar,
193     (arg("value")=0.0,
194     arg("what")=escript::FunctionSpace(),
195     arg("expanded")=false));
196     def("Vector",escript::Vector,
197     (arg("value")=0.0,
198     arg("what")=escript::FunctionSpace(),
199     arg("expanded")=false));
200     def("Tensor",escript::Tensor,
201     (arg("value")=0.0,
202     arg("what")=escript::FunctionSpace(),
203     arg("expanded")=false));
204     def("Tensor3",escript::Tensor3,
205     (arg("value")=0.0,
206     arg("what")=escript::FunctionSpace(),
207     arg("expanded")=false));
208     def("Tensor4",escript::Tensor4,
209     (arg("value")=0.0,
210     arg("what")=escript::FunctionSpace(),
211     arg("expanded")=false));
212    
213     //
214     // Interface for AbstractSystemMatrix
215     //
216     class_<escript::AbstractSystemMatrix>("Operator",init<>())
217     .def("isEmpty",&escript::AbstractSystemMatrix::isEmpty)
218     .def("solve",&escript::AbstractSystemMatrix::solve)
219     .def("of",&escript::AbstractSystemMatrix::vectorMultiply)
220     .def("saveMM",&escript::AbstractSystemMatrix::saveMM)
221     .def("setValue",&escript::AbstractSystemMatrix::setValue)
222     .def(self*other<escript::Data>());
223    
224     //
225     // Register esysExceptionTranslator
226     //
227     register_exception_translator<esysUtils::EsysException>(&esysUtils::esysExceptionTranslator);
228    
229     }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26