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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 117 - (hide annotations)
Fri Apr 1 05:48:57 2005 UTC (14 years, 6 months ago) by jgs
File size: 9076 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 jgs 110 .def("setRefValue",&escript::Data::setRefValue)
109     .def("getRefValue",&escript::Data::getRefValue)
110 jgs 102 //.def("expand",&escript::Data::expand)
111     //.def("tag",&escript::Data::tag)
112 jgs 104 .def("saveDX",&escript::Data::saveDX)
113 jgs 110 .def("saveVTK",&escript::Data::saveVTK)
114 jgs 102 .def("wherePositive",&escript::Data::wherePositive)
115     .def("whereNegative",&escript::Data::whereNegative)
116     .def("whereNonNegative",&escript::Data::whereNonNegative)
117     .def("whereNonPositive",&escript::Data::whereNonPositive)
118     .def("whereZero",&escript::Data::whereZero)
119     .def("whereNonZero",&escript::Data::whereNonZero)
120     // Unary functions for Data
121     .def("interpolate",&escript::Data::interpolate)
122     .def("grad",&escript::Data::gradOn)
123     .def("grad",&escript::Data::grad)
124 jgs 117 .def("convertToNumArray",&escript::Data::convertToNumArray)
125 jgs 102 .def("integrate",&escript::Data::integrate)
126     .def("transpose",&escript::Data::transpose)
127     .def("trace",&escript::Data::trace)
128     .def("sin",&escript::Data::sin)
129     .def("cos",&escript::Data::cos)
130     .def("tan",&escript::Data::tan)
131     .def("log",&escript::Data::log)
132     .def("ln",&escript::Data::ln)
133     .def("Lsup",&escript::Data::Lsup)
134 jgs 117 .def("Linf",&escript::Data::Lsup)
135 jgs 102 .def("sup",&escript::Data::sup)
136     .def("inf",&escript::Data::inf)
137 jgs 108 .def("__abs__",&escript::Data::abs)
138 jgs 102 .def("exp",&escript::Data::exp)
139     .def("sqrt",&escript::Data::sqrt)
140     .def("maxval",&escript::Data::maxval)
141     .def("minval",&escript::Data::minval)
142     .def("length",&escript::Data::length)
143     .def("sign",&escript::Data::sign)
144     // following implements the python "-" negation operator
145     .def("__neg__",&escript::Data::neg)
146     // following implements the python "+" identity operator
147     .def("__pos__",&escript::Data::pos)
148     // following two functions implement the python [] operator
149     .def("__getitem__",&escript::Data::getItem)
150     .def("__setitem__",&escript::Data::setItemO)
151     .def("__setitem__",&escript::Data::setItemD)
152     // following two functions implement the python ** operator
153     .def("__pow__",&escript::Data::powO)
154     .def("__pow__",&escript::Data::powD)
155     // NOTE:: The order of these declarations is important. Anything
156     // declared before the generic declaration isn't found so the generic
157     // version will be called.
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     .def(self /= other<object>())
174     .def(self /= self)
175     .def(self / other<object>())
176     .def(other<object>() / self)
177     .def(self / self)
178     // Need scope resolution due to a bug either in the compiler or
179     // the boost code. This calls operator << for Data.
180     .def(self_ns::str(self));
181    
182     //
183     // Factory methods for function space
184     //
185     def("ContinuousFunction",escript::continuousFunction);
186     def("Function",escript::function);
187     def("FunctionOnBoundary",escript::functionOnBoundary);
188     def("FunctionOnContactZero",escript::functionOnContactZero);
189     def("FunctionOnContactOne",escript::functionOnContactOne);
190     def("Solution",escript::solution);
191     def("ReducedSolution",escript::reducedSolution);
192     def("DiracDeltaFunction",escript::diracDeltaFunction);
193    
194     //
195     // Factory methods for Data
196     //
197     def("Scalar",escript::Scalar,
198     (arg("value")=0.0,
199     arg("what")=escript::FunctionSpace(),
200     arg("expanded")=false));
201     def("Vector",escript::Vector,
202     (arg("value")=0.0,
203     arg("what")=escript::FunctionSpace(),
204     arg("expanded")=false));
205     def("Tensor",escript::Tensor,
206     (arg("value")=0.0,
207     arg("what")=escript::FunctionSpace(),
208     arg("expanded")=false));
209     def("Tensor3",escript::Tensor3,
210     (arg("value")=0.0,
211     arg("what")=escript::FunctionSpace(),
212     arg("expanded")=false));
213     def("Tensor4",escript::Tensor4,
214     (arg("value")=0.0,
215     arg("what")=escript::FunctionSpace(),
216     arg("expanded")=false));
217    
218     //
219     // Interface for AbstractSystemMatrix
220     //
221     class_<escript::AbstractSystemMatrix>("Operator",init<>())
222     .def("isEmpty",&escript::AbstractSystemMatrix::isEmpty)
223     .def("solve",&escript::AbstractSystemMatrix::solve)
224     .def("of",&escript::AbstractSystemMatrix::vectorMultiply)
225     .def("saveMM",&escript::AbstractSystemMatrix::saveMM)
226     .def("setValue",&escript::AbstractSystemMatrix::setValue)
227 jgs 108 .def("resetSolver",&escript::AbstractSystemMatrix::resetSolver)
228 jgs 102 .def(self*other<escript::Data>());
229    
230     //
231     // Register esysExceptionTranslator
232     //
233     register_exception_translator<esysUtils::EsysException>(&esysUtils::esysExceptionTranslator);
234    
235     }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26