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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1799 - (hide annotations)
Wed Sep 17 06:33:18 2008 UTC (11 years, 2 months ago) by jfenwick
File size: 13419 byte(s)
Added Data::copySelf() [Note: this is exposed as copy() in python].
This method returns a pointer to a deep copy of the target.
There are c++ tests but no python tests for this yet.

All DataAbstracts now have a deepCopy() which simplifies the 
implementation of the compy methods.


1 jgs 102
2 ksteube 1312 /* $Id$ */
3    
4     /*******************************************************
5     *
6     * Copyright 2003-2007 by ACceSS MNRF
7     * Copyright 2007 by University of Queensland
8     *
9     * http://esscc.uq.edu.au
10     * Primary Business: Queensland, Australia
11     * Licensed under the Open Software License version 3.0
12     * http://www.opensource.org/licenses/osl-3.0.php
13     *
14     *******************************************************/
15    
16 jgs 474 #include "Data.h"
17     #include "FunctionSpace.h"
18     #include "FunctionSpaceFactory.h"
19     #include "DataFactory.h"
20     #include "AbstractContinuousDomain.h"
21     #include "AbstractDomain.h"
22     #include "Utils.h"
23 jgs 480 #include "AbstractSystemMatrix.h"
24 gross 1364 #include "AbstractTransportProblem.h"
25 gross 797 #include "DataVector.h"
26 jgs 474
27 ksteube 1312 extern "C" {
28     #include "escript/blocktimer.h"
29     }
30    
31 robwdcock 682 #include "esysUtils/esysExceptionTranslator.h"
32 jgs 102
33     #include <boost/python.hpp>
34     #include <boost/python/module.hpp>
35     #include <boost/python/def.hpp>
36     #include <boost/python/object.hpp>
37     #include <boost/python/tuple.hpp>
38 gross 285 #include <boost/python/numeric.hpp>
39    
40 jgs 102 using namespace boost::python;
41    
42 jgs 121 /*! \mainpage Esys Documentation
43     *
44     * \version 1.0.0
45     *
46     * - \ref escript
47     *
48     * - \ref esys_exception "Esys Exception"
49     *
50     * - \ref finley
51     *
52 cochrane 358 * - <a href=http://iservo.edu.au/esys/epydoc/index.html>Python module documentation (epydoc generated)</a>
53 jgs 122 *
54 jgs 121 */
55 jgs 102
56 jgs 121 /*! \page escript Escript
57     * Escript is the python module that contains the interfaces
58     * to the C++ side of escript.
59     *
60     * \version 1.0.0
61     *
62     * \section class_desc Class Description:
63     * Data
64     *
65     * \section class_limits Class Limitations:
66     * None
67     *
68     * \section class_conds Class Conditions of Use:
69     * None
70     *
71     * \section class_throws Throws:
72     * None
73     *
74     */
75 jgs 102
76     BOOST_PYTHON_MODULE(escriptcpp)
77     {
78 gross 391 def("setNumberOfThreads",escript::setNumberOfThreads);
79     def("getNumberOfThreads",escript::getNumberOfThreads);
80 gross 797 def("releaseUnusedMemory",escript::releaseUnusedMemory);
81 ksteube 1312 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 ksteube 1247 def("getVersion",escript::getSvnVersion);
87 ksteube 1561 def("printParallelThreadCounts",escript::printParallelThreadCnt);
88 jgs 102
89 gross 797
90 jgs 102 //
91     // Interface for AbstractDomain
92     //
93     class_<escript::AbstractDomain>("Domain",no_init)
94 gross 1044 .def("setTagMap",&escript::AbstractDomain::setTagMap)
95     .def("getTag",&escript::AbstractDomain::getTag)
96     .def("isValidTagName",&escript::AbstractDomain::isValidTagName)
97     .def("showTagNames",&escript::AbstractDomain::showTagNames)
98 jgs 102 .def("getX",&escript::AbstractDomain::getX)
99     .def("getNormal",&escript::AbstractDomain::getNormal)
100     .def("getSize",&escript::AbstractDomain::getSize)
101 jgs 153 .def("saveVTK",&escript::AbstractDomain::saveVTK)
102     .def("saveDX",&escript::AbstractDomain::saveDX)
103 ksteube 1312 .def("getMPISize",&escript::AbstractDomain::getMPISize)
104     .def("getMPIRank",&escript::AbstractDomain::getMPIRank)
105    
106 jgs 102 .def(self == self)
107     .def(self != self);
108    
109     //
110     // Interface for AbstractContinuousDomain
111     //
112     class_<escript::AbstractContinuousDomain, bases<escript::AbstractDomain> >("ContinuousDomain",no_init)
113     .def("getSystemMatrixTypeId",&escript::AbstractContinuousDomain::getSystemMatrixTypeId);
114    
115     //
116     // Interface for FunctionSpace
117     //
118 trankine 1426 class_<escript::FunctionSpace> fs_definer("FunctionSpace",init<>());
119     fs_definer.def("getDim",&escript::FunctionSpace::getDim);
120     fs_definer.def("getDomain",&escript::FunctionSpace::getDomain,
121     return_internal_reference<>());
122     fs_definer.def("getX",&escript::FunctionSpace::getX);
123     fs_definer.def("getNormal",&escript::FunctionSpace::getNormal);
124     fs_definer.def("getSize",&escript::FunctionSpace::getSize);
125     fs_definer.def("setTags",&escript::FunctionSpace::setTags);
126     fs_definer.def("getTagFromDataPointNo",
127     &escript::FunctionSpace::getTagFromDataPointNo);
128 gross 1718 fs_definer.def("getReferenceIDFromDataPointNo", &escript::FunctionSpace::getReferenceIDFromDataPointNo);
129 gross 1716 fs_definer.def("getListOfTags",&escript::FunctionSpace::getListOfTags);
130 phornby 1628 fs_definer.def("__str__", &escript::FunctionSpace::toString);
131 trankine 1426 fs_definer.def(self == self);
132     fs_definer.def(self != self);
133 jgs 102 //
134     // Interface for Data
135     //
136 jgs 149 class_<escript::Data>("Data","TEST DOCUMENTATION",init<>())
137 jgs 102 // various constructors for Data objects
138     .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")))
140     .def(init<const double, const tuple&, optional<const escript::FunctionSpace&, bool> >(args("value","shape","what","expand")))
141     .def(init<const escript::Data&, const escript::FunctionSpace&>(args("value","what")))
142     .def(init<const escript::Data&>())
143     // Note for Lutz, Need to specify the call policy in order to return a
144     // reference. In this case return_internal_reference.
145 ksteube 1312 .def("__str__",&escript::Data::toString)
146 jgs 102 .def("getDomain",&escript::Data::getDomain,return_internal_reference<>())
147     .def("getFunctionSpace",&escript::Data::getFunctionSpace,return_internal_reference<>())
148     .def("isEmpty",&escript::Data::isEmpty)
149 gross 783 .def("isProtected",&escript::Data::isProtected)
150     .def("setProtection",&escript::Data::setProtection)
151 jgs 102 .def("getShape",&escript::Data::getShapeTuple)
152     .def("getRank",&escript::Data::getDataPointRank)
153 gross 950 .def("dump",&escript::Data::dump)
154 jgs 102 .def("copyWithMask",&escript::Data::copyWithMask)
155     .def("setTaggedValue",&escript::Data::setTaggedValue)
156 gross 1044 .def("setTaggedValue",&escript::Data::setTaggedValueByName)
157 gross 921 .def("getNumberOfDataPoints",&escript::Data::getNumDataPoints)
158 gross 1141 .def("isExpanded",&escript::Data::isExpanded)
159     .def("isTagged",&escript::Data::isTagged)
160 jgs 119 .def("expand",&escript::Data::expand)
161     .def("tag",&escript::Data::tag)
162 jgs 126 .def("copy",&escript::Data::copy)
163 jfenwick 1799 .def("copy",&escript::Data::copySelf,return_value_policy<manage_new_object>())
164 gross 1034 .def("setValueOfDataPoint",&escript::Data::setValueOfDataPointToPyObject)
165     .def("setValueOfDataPoint",&escript::Data::setValueOfDataPointToArray)
166 gross 921 .def("setValueOfDataPoint",&escript::Data::setValueOfDataPoint)
167     .def("getValueOfDataPoint",&escript::Data::getValueOfDataPoint)
168     .def("getValueOfGlobalDataPoint",&escript::Data::getValueOfGlobalDataPoint)
169 gross 1118 .def("setToZero",&escript::Data::setToZero)
170 gross 285 .def("interpolate",&escript::Data::interpolate)
171 gross 921 .def("minGlobalDataPoint",&escript::Data::minGlobalDataPoint)
172 gross 285 .def("saveDX",&escript::Data::saveDX)
173     .def("saveVTK",&escript::Data::saveVTK)
174 jgs 149 .def("getTagNumber",&escript::Data::getTagNumber)
175 gross 285 // Unary functions for Data
176     .def("_interpolate",&escript::Data::interpolate)
177     .def("_grad",&escript::Data::gradOn)
178     .def("_grad",&escript::Data::grad)
179     .def("_transpose",&escript::Data::transpose)
180     .def("_trace",&escript::Data::trace)
181     .def("_maxval",&escript::Data::maxval)
182     .def("_minval",&escript::Data::minval)
183 gross 698 .def("_wherePositive",&escript::Data::wherePositive)
184     .def("_whereNegative",&escript::Data::whereNegative)
185     .def("_whereNonNegative",&escript::Data::whereNonNegative)
186     .def("_whereNonPositive",&escript::Data::whereNonPositive)
187 jgs 571 .def("_whereZero",&escript::Data::whereZero,(arg("tol")=0.0))
188     .def("_whereNonZero",&escript::Data::whereNonZero,(arg("tol")=0.0))
189 ksteube 876 .def("_erf",&escript::Data::erf)
190 gross 285 .def("_sin",&escript::Data::sin)
191     .def("_cos",&escript::Data::cos)
192     .def("_tan",&escript::Data::tan)
193     .def("_asin",&escript::Data::asin)
194     .def("_acos",&escript::Data::acos)
195     .def("_atan",&escript::Data::atan)
196     .def("_sinh",&escript::Data::sinh)
197     .def("_cosh",&escript::Data::cosh)
198     .def("_tanh",&escript::Data::tanh)
199     .def("_asinh",&escript::Data::asinh)
200     .def("_acosh",&escript::Data::acosh)
201     .def("_atanh",&escript::Data::atanh)
202     .def("_exp",&escript::Data::exp)
203     .def("_sqrt",&escript::Data::sqrt)
204     .def("_log10",&escript::Data::log10)
205     .def("_log",&escript::Data::log)
206     .def("_sign",&escript::Data::sign)
207 ksteube 775 .def("_symmetric",&escript::Data::symmetric)
208     .def("_nonsymmetric",&escript::Data::nonsymmetric)
209 gross 800 .def("_trace",&escript::Data::trace)
210 gross 804 .def("_swap_axes",&escript::Data::swapaxes)
211 gross 576 .def("_eigenvalues",&escript::Data::eigenvalues)
212     .def("_eigenvalues_and_eigenvectors",&escript::Data::eigenvalues_and_eigenvectors,(arg("tol")=1.e-13))
213 gross 285 // functions returning a single real number:
214     .def("_Lsup",&escript::Data::Lsup)
215     .def("_sup",&escript::Data::sup)
216     .def("_inf",&escript::Data::inf)
217     .def("_integrate",&escript::Data::integrate)
218    
219     // following implements the python abs operator
220 jgs 108 .def("__abs__",&escript::Data::abs)
221 jgs 102 // following implements the python "-" negation operator
222     .def("__neg__",&escript::Data::neg)
223     // following implements the python "+" identity operator
224     .def("__pos__",&escript::Data::pos)
225     // following two functions implement the python [] operator
226     .def("__getitem__",&escript::Data::getItem)
227     .def("__setitem__",&escript::Data::setItemO)
228     .def("__setitem__",&escript::Data::setItemD)
229     // following two functions implement the python ** operator
230     .def("__pow__",&escript::Data::powO)
231     .def("__pow__",&escript::Data::powD)
232 gross 699 .def("__rpow__",&escript::Data::rpowO)
233 jgs 102 // NOTE:: The order of these declarations is important. Anything
234     // declared before the generic declaration isn't found so the generic
235     // version will be called.
236     .def(self + other<object>())
237     .def(other<object>() + self)
238     .def(self + self)
239 gross 285 .def(self += other<object>())
240     .def(self += self)
241    
242 jgs 102 .def(self - other<object>())
243     .def(other<object>() - self)
244     .def(self - self)
245 gross 285 .def(self -= other<object>())
246     .def(self -= self)
247    
248 jgs 102 .def(self * other<object>())
249     .def(other<object>() * self)
250     .def(self * self)
251 gross 285 .def(self *= other<object>())
252     .def(self *= self)
253    
254 jgs 102 .def(self / other<object>())
255     .def(other<object>() / self)
256     .def(self / self)
257 gross 285 .def(self /= other<object>())
258     .def(self /= self)
259 jgs 102 // Need scope resolution due to a bug either in the compiler or
260     // the boost code. This calls operator << for Data.
261     .def(self_ns::str(self));
262    
263     //
264     // Factory methods for function space
265     //
266     def("ContinuousFunction",escript::continuousFunction);
267 gross 1062 def("ReducedContinuousFunction",escript::reducedContinuousFunction);
268 jgs 102 def("Function",escript::function);
269 gross 1062 def("ReducedFunction",escript::reducedFunction);
270 jgs 102 def("FunctionOnBoundary",escript::functionOnBoundary);
271 gross 1062 def("ReducedFunctionOnBoundary",escript::reducedFunctionOnBoundary);
272 jgs 102 def("FunctionOnContactZero",escript::functionOnContactZero);
273 gross 1062 def("ReducedFunctionOnContactZero",escript::reducedFunctionOnContactZero);
274 jgs 102 def("FunctionOnContactOne",escript::functionOnContactOne);
275 gross 1062 def("ReducedFunctionOnContactOne",escript::reducedFunctionOnContactOne);
276 jgs 102 def("Solution",escript::solution);
277     def("ReducedSolution",escript::reducedSolution);
278     def("DiracDeltaFunction",escript::diracDeltaFunction);
279    
280     //
281     // Factory methods for Data
282     //
283 gross 950 def("load",escript::load);
284 gross 1023 def("loadIsConfigured",escript::loadConfigured);
285 jgs 102 def("Scalar",escript::Scalar,
286     (arg("value")=0.0,
287     arg("what")=escript::FunctionSpace(),
288     arg("expanded")=false));
289     def("Vector",escript::Vector,
290     (arg("value")=0.0,
291     arg("what")=escript::FunctionSpace(),
292     arg("expanded")=false));
293     def("Tensor",escript::Tensor,
294     (arg("value")=0.0,
295     arg("what")=escript::FunctionSpace(),
296     arg("expanded")=false));
297     def("Tensor3",escript::Tensor3,
298     (arg("value")=0.0,
299     arg("what")=escript::FunctionSpace(),
300     arg("expanded")=false));
301     def("Tensor4",escript::Tensor4,
302     (arg("value")=0.0,
303     arg("what")=escript::FunctionSpace(),
304     arg("expanded")=false));
305    
306     //
307 ksteube 813 // Binary operators
308     //
309     def("C_GeneralTensorProduct",escript::C_GeneralTensorProduct,
310     (arg("arg0")=escript::Data(),
311     arg("arg1")=escript::Data(),
312     arg("axis_offset")=0,
313     arg("transpose")=0));
314    
315     //
316 jgs 102 // Interface for AbstractSystemMatrix
317     //
318     class_<escript::AbstractSystemMatrix>("Operator",init<>())
319     .def("isEmpty",&escript::AbstractSystemMatrix::isEmpty)
320     .def("solve",&escript::AbstractSystemMatrix::solve)
321     .def("of",&escript::AbstractSystemMatrix::vectorMultiply)
322     .def("saveMM",&escript::AbstractSystemMatrix::saveMM)
323 jgs 123 .def("saveHB",&escript::AbstractSystemMatrix::saveHB)
324 jgs 149 .def("resetValues",&escript::AbstractSystemMatrix::resetValues)
325 jgs 102 .def(self*other<escript::Data>());
326 gross 1364 //
327     // Interface for AbstractTransportProblem
328     //
329     class_<escript::AbstractTransportProblem>("TransportProblem",init<>())
330     .def("isEmpty",&escript::AbstractTransportProblem::isEmpty)
331     .def("solve",&escript::AbstractTransportProblem::solve)
332 gross 1370 .def("setInitialValue",&escript::AbstractTransportProblem::setInitialValue)
333 gross 1417 .def("insertConstraint",&escript::AbstractTransportProblem::insertConstraint)
334     .def("reset",&escript::AbstractTransportProblem::resetTransport)
335 gross 1407 .def("getSafeTimeStepSize",&escript::AbstractTransportProblem::getSafeTimeStepSize);
336 jgs 102
337     //
338     // Register esysExceptionTranslator
339     //
340     register_exception_translator<esysUtils::EsysException>(&esysUtils::esysExceptionTranslator);
341    
342     }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26