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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 950 - (hide annotations)
Tue Feb 6 07:01:11 2007 UTC (12 years, 8 months ago) by gross
File size: 11443 byte(s)
escript data objects can now be saved to netCDF files, see http://www.unidata.ucar.edu/software/netcdf/.
Currently only constant data are implemented with expanded and tagged data to follow.
There are two new functions to dump a data object

   s=Data(...)
   s.dump(<filename>)

and to recover it

   s=load(<filename>, domain)

Notice that the function space of s is recovered but domain is still need. 

dump and load will replace archive and extract.

The installation needs now the netCDF installed. 


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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26