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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1803 - (hide annotations)
Wed Sep 24 06:20:29 2008 UTC (11 years ago) by jfenwick
File size: 13499 byte(s)
All about making DataEmpty instances throw.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Exposed getDim from AbstractDomain to python to fix bug.

Added isEmpty member to DataAbstract to allow it to throw is queries are 
made about a DataEmpty instance.


Added exceptions to DataAbstract, DataEmpty and Data to prevent calls 
being made against DataEmpty objects.
The following still work as expected on DataEmpty instances

copy, getDomain, getFunctionSpace, isEmpty, isExpanded, isProtected, 
isTagged, setprotection.

You can also call interpolate, however it should throw if you try to 
change FunctionSpaces.


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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26