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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2078 - (show annotations)
Thu Nov 20 16:10:10 2008 UTC (10 years, 5 months ago) by phornby
File size: 15277 byte(s)
Two changes.

1. Move blocktimer from escript to esysUtils.
2. Make it possible to link to paso as a DLL or .so.

Should have no effect on 'nix's

In respect of 1., blocktimer had begun to spring up everywhere, so
for the moment I thought it best to move it to the only other library that
pops up all over the place.

In respect of 2., paso needed to be a DLL in order to use the windows intelc /fast
option, which does aggressive multi-file optimisations. Even in its current form, it either
vectorises or parallelises  hundreds more loops in the esys system than appear in the pragmas.

In achieving 2. I have not been too delicate in adding

PASO_DLL_API

declarations to the .h files in paso/src. Only toward the end of the process of
the conversion, when the number of linker errors dropped below 20, say, did I choosy about what
functions in a header I declared PASO_DLL_API. As a result, there are likely to be many routines
declared as external functions symbols that are in fact internal to the paso DLL. 
Why is this an issue?  It prevents the intelc compiler from getting aggressive on the paso module.
With pain there is sometimes gain. At least all the DLL rules in windows give good
(non-microsoft) compiler writers a chance to really shine.

So, if you should see a PASO_DLL_API on a function in a paso header file,
and think to yourself, "that function is only called in paso, why export it?", then feel free to
delete the PASO_DLL_API export declaration.

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26