/[escript]/branches/split/escriptcore/src/escriptcpp.cpp
ViewVC logotype

Contents of /branches/split/escriptcore/src/escriptcpp.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4734 - (show annotations)
Mon Mar 10 06:38:54 2014 UTC (3 years, 9 months ago) by jfenwick
File size: 42168 byte(s)
Run skeleton jobs with no params.
1
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2014 by University of Queensland
5 * http://www.uq.edu.au
6 *
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 * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 * Development 2012-2013 by School of Earth Sciences
13 * Development from 2014 by Centre for Geoscience Computing (GeoComp)
14 *
15 *****************************************************************************/
16
17
18 #include "Data.h"
19 #include "FunctionSpace.h"
20 #include "FunctionSpaceFactory.h"
21 #include "DataFactory.h"
22 #include "AbstractContinuousDomain.h"
23 #include "AbstractDomain.h"
24 #include "Utils.h"
25 #include "AbstractSystemMatrix.h"
26 #include "AbstractTransportProblem.h"
27 #include "DataVector.h"
28 #include "esysUtils/Esys_MPI.h"
29 #include "EscriptParams.h"
30 #include "TestDomain.h"
31 #include "SubWorld.h"
32 #include "SplitWorld.h"
33
34 #include "esysUtils/blocktimer.h"
35
36 #include "esysUtils/esysExceptionTranslator.h"
37
38 #include <boost/version.hpp>
39 #include <boost/python.hpp>
40 #include <boost/python/module.hpp>
41 #include <boost/python/def.hpp>
42 #include <boost/python/object.hpp>
43 #include <boost/python/tuple.hpp>
44 #include <boost/smart_ptr.hpp>
45 #include <boost/version.hpp>
46
47 using namespace boost::python;
48
49 /*! \mainpage Esys Documentation
50 *
51 * \version 3.3.1
52 *
53 * Main modules/namespaces:
54 *
55 * - \ref escript
56 *
57 * - \ref paso
58 *
59 * - \ref finley
60 *
61 * - \ref dudley
62 *
63 * - \ref ripley
64 *
65 * - \ref weipa
66 *
67 * Depending on your system, only one of the following will work:
68 *
69 * - <a href="../../sphinx_api/index.html">Python module documentation (sphinx generated)</a>
70 *
71 * - <a href="../../epydoc/index.html">Python module documentation (epydoc generated)</a>
72 *
73 */
74
75 /*
76 namespace escript
77 {
78
79 // Note: not virtual because it calls the virtual probeInterpolationOnDomain
80 ESCRIPT_DLL_API
81 bool canInterpolate(FunctionSpace src, FunctionSpace dest)
82 {
83 return src.getDomain()->probeInterpolationOnDomain(src.getTypeCode(), dest.getTypeCode());
84 }
85
86
87 }
88 */
89
90 #include <boost/python/raw_function.hpp>
91
92
93 bool test1(double d)
94 {
95 std::cout << "Line " << __LINE__ << std::endl;
96 return true;
97 }
98
99
100 bool test2(boost::python::object o, double x, double y, double z)
101 {
102 std::cout << "Line " << __LINE__ << std::endl;
103 return true;
104 }
105
106 bool test3(double x, double y, double z)
107 {
108 std::cout << "Line " << __LINE__ << std::endl;
109 return true;
110 }
111
112 bool test4(double x, double y, double z, bool bozo1=true, bool bozo2=false)
113 {
114 std::cout << "Line " << __LINE__ << std::endl;
115 return true;
116 }
117
118
119 namespace
120 {
121
122 object raw1(boost::python::tuple t, boost::python::dict kwargs)
123 {
124 std::cout << "In raw1\n";
125 if (len(t)<2)
126 {
127 return object(false);
128 }
129 t[0](*t, **kwargs);
130 return object();
131 }
132
133 object raw2(boost::python::tuple t, boost::python::dict kwargs)
134 {
135 std::cout << "In raw2\n";
136 // raw1(t, kwargs);
137 if (len(t)<1)
138 {
139 return object(false);
140 }
141 object target=t[0];
142 object zz=t.slice(1,len(t));
143 tuple t2=tuple(zz);
144 target(*t2, **kwargs);
145 //target(t2[0], t2[1], t2[2], t2[3], **kwargs); // This doesn't work
146 return object();
147 }
148
149
150 }
151
152
153
154 tuple raw(tuple args, dict kw)
155 {
156 return make_tuple(args, kw);
157 }
158
159 BOOST_PYTHON_MODULE(escriptcpp)
160 {
161
162 #if BOOST_VERSION >= 103500
163 // params are: bool show_user_defined, bool show_py_signatures, bool show_cpp_signatures
164 docstring_options docopt(true,true,false);
165 #endif
166
167 scope().attr("__doc__") = "To use this module, please import esys.escript";
168
169
170 def("jf1", &test1, "Here is a docstring");
171 def("jf2", &test2);
172 def("jf3", &test3);
173 def("jf4", &test4, args("x","y","z","bozo1","bozo2"));
174
175 def("passthrough", raw_function(raw1));
176 def("pass2", raw_function(raw2,2));
177
178
179
180
181
182 /* begin SubWorld things */
183 // Why doesn't this have a doc-string? Because it doesn't compile if you try to add one
184 def("buildDomains", raw_function(escript::raw_buildDomains,2));
185
186 class_<escript::SplitWorld, boost::noncopyable>("SplitWorld", "Manages a group of sub worlds", init<unsigned int>(args("num_worlds")))
187 .def("runJobs", &escript::SplitWorld::runJobs, arg("tuplelist"), "Create a set of jobs and execute them on the subworlds.");
188
189 // This class has no methods. This is deliberate - at this stage, I would like this to be an opaque type
190 class_ <escript::SubWorld, escript::SubWorld_ptr, boost::noncopyable>("SubWorld", "Information about a group of workers.", no_init);
191 /* end SubWorld things */
192
193 def("setNumberOfThreads",escript::setNumberOfThreads,"Use of this method is strongly discouraged.");
194 def("getNumberOfThreads",escript::getNumberOfThreads,"Return the maximum number of threads"
195 " available to OpenMP.");
196 def("releaseUnusedMemory",escript::releaseUnusedMemory);
197 def("blocktimer_initialize",blocktimer_initialize);
198 def("blocktimer_reportSortByName",blocktimer_reportSortByName);
199 def("blocktimer_reportSortByTime",blocktimer_reportSortByTime);
200 def("blocktimer_increment",blocktimer_increment);
201 def("blocktimer_time",blocktimer_time);
202 def("getVersion",escript::getSvnVersion,"This method will only report accurate version numbers for clean checkouts.");
203 def("printParallelThreadCounts",escript::printParallelThreadCnt);
204 def("getMPISizeWorld",escript::getMPISizeWorld,"Return number of MPI processes in the job.");
205 def("getMPIRankWorld",escript::getMPIRankWorld,"Return the rank of this process in the MPI World.");
206 def("MPIBarrierWorld",escript::MPIBarrierWorld,"Wait until all MPI processes have reached this point.");
207 def("getMPIWorldMax",escript::getMPIWorldMax,"\nEach MPI process calls this function with a"
208 " value for arg1. The maximum value is computed and returned.\n\n:rtype: int");
209 def("getMPIWorldSum",escript::getMPIWorldSum,"\nEach MPI process calls this function with a"
210 " value for arg1. The values are added up and the total value is returned.\n\n:rtype: int");
211 def("runMPIProgram",escript::runMPIProgram,"Spawns an external MPI program using a separate communicator.");
212 def("getMachinePrecision",escript::getMachinePrecision);
213 def("getMaxFloat",escript::getMaxFloat);
214 def("_saveDataCSV",escript::saveDataCSV, (args("filename","arg","sep","csep"), arg("append")=false),
215 "Saves data objects passed in a python dictionary to a file.\n"
216 "The data objects must be over the same domain and be able to be interpolated to the same FunctionSpace.\n"
217 "If one of the dictionary keys is named ``mask``, then only samples where ``mask`` has a positive\n"
218 "value will be written to the file.\n\n"
219 "A header line giving the names of each column will be output first.\n"
220 "The keys given in the dictionary will be used to name columns.\n"
221 "Then the data will be output, one line per sample (for all data).\n"
222 "That is, items in each column will be printed in the same order.\n"
223 "So you can be sure that values in the same row correspond to the same input value.\n\n"
224 "\n:param filename:\n:type filename: ``string``\n"
225 ":param arg: dictionary of named `Data` objects. If one is called ``mask`` it must be scalar data.\n"
226 ":type arg: ``dict``\n"
227 ":param sep: separator for columns (defaults to ',')\n"
228 ":type sep: ``string``\n"
229 ":param csep: separator for fields within data object (defaults to \"_\")\n:type csep: ``string``\n"
230 ":param append: If True, write to the end of ``filename``\n:type append: ``string``\n");
231 def("canInterpolate", &escript::canInterpolate, args("src", "dest"),":param src: Source FunctionSpace\n:param dest: Destination FunctionSpace\n:return: True if src can be interpolated to dest\n:rtype: `bool`");
232
233 //
234 // Interface for AbstractDomain
235 //
236 class_<escript::AbstractDomain, escript::Domain_ptr, boost::noncopyable >("Domain","Base class for all domains.",no_init)
237 .def("getStatus",&escript::AbstractDomain::getStatus,"The status of a domain changes whenever the domain is modified\n\n:rtype: int")
238 .def("setTagMap",&escript::AbstractDomain::setTagMap,args("name","tag"),
239 "Give a tag number a name.\n\n:param name: Name for the tag\n:type name: ``string``\n"
240 ":param tag: numeric id\n:type tag: ``int``\n:note: Tag names must be unique within a domain")
241 .def("getTag",&escript::AbstractDomain::getTag,args("name"),":return: tag id for "
242 "``name``\n:rtype: ``string``")
243 .def("isValidTagName",&escript::AbstractDomain::isValidTagName,args("name"),
244 ":return: True is ``name`` corresponds to a tag\n:rtype: ``bool``")
245 .def("showTagNames",&escript::AbstractDomain::showTagNames,":return: A space separated list of tag names\n:rtype: ``string``")
246 .def("getX",&escript::AbstractDomain::getX,":rtype: `Data`\n:return: Locations in the"
247 "`Domain`. FunctionSpace is chosen appropriately")
248 .def("getDim",&escript::AbstractDomain::getDim,":rtype: `int`\n:return: Spatial dimension of the `Domain`")
249 .def("getNormal",&escript::AbstractDomain::getNormal,":rtype: `escript`\n:return: Boundary normals")
250 .def("getSize",&escript::AbstractDomain::getSize,":return: the local size of samples. The function space is chosen appropriately\n:rtype: `Data`")
251 .def("dump",&escript::AbstractDomain::dump,args("filename"),"Dumps the domain to a file"
252 ":param filename:\n:type filename: string")
253 .def("getMPISize",&escript::AbstractDomain::getMPISize,":return: the number of processes used for this `Domain`\n:rtype: ``int``")
254 .def("getMPIRank",&escript::AbstractDomain::getMPIRank,":return: the rank of this process\n:rtype: ``int``")
255 .def("MPIBarrier",&escript::AbstractDomain::MPIBarrier,"Wait until all processes have reached this point")
256 .def("onMasterProcessor",&escript::AbstractDomain::onMasterProcessor,":return: True if this code is executing on the master process\n:rtype: `bool`")
257 .def("supportsContactElements", &escript::AbstractDomain::supportsContactElements,"Does this domain support contact elements.")
258 .def(self == self)
259 .def(self != self);
260
261 //
262 // Interface for AbstractContinuousDomain
263 //
264 class_<escript::AbstractContinuousDomain, bases<escript::AbstractDomain>, boost::noncopyable >("ContinuousDomain","Class representing continuous domains",no_init)
265 .def("getSystemMatrixTypeId",&escript::AbstractContinuousDomain::getSystemMatrixTypeId,
266 args("solver", "preconditioner", "package", "symmetry"),
267 ":return: the identifier of the matrix type to be used for the global stiffness matrix "
268 "when a particular solver package and symmetric matrix is used.\n"
269 ":rtype: int")
270 .def("getTransportTypeId",&escript::AbstractContinuousDomain::getTransportTypeId,
271 args("solver", "preconditioner", "package", "symmetry"))
272
273 .def("addPDEToSystem",&escript::AbstractContinuousDomain::addPDEToSystem,
274 args("mat", "rhs","A", "B", "C", "D", "X", "Y", "d", "y", "d_contact", "y_contact", "d_dirac", "y_dirac"),
275 "adds a PDE onto the stiffness matrix mat and a rhs\n\n"
276 ":param mat:\n:type mat: `OperatorAdapter`\n:param rhs:\n:type rhs: `Data`\n"
277 ":param A:\n:type A: `Data`\n"
278 ":param B:\n:type B: `Data`\n"
279 ":param C:\n:type C: `Data`\n"
280 ":param D:\n:type D: `Data`\n"
281 ":param X:\n:type X: `Data`\n"
282 ":param Y:\n:type Y: `Data`\n"
283 ":param d:\n:type d: `Data`\n"
284 ":param d_contact:\n:type d_contact: `Data`\n"
285 ":param y_contact:\n:type y_contact: `Data`\n"
286 ":param d_dirac:\n:type d_dirac: `Data`\n"
287 ":param y_dirac:\n:type y_dirac: `Data`\n"
288 )
289 .def("addPDEToRHS",&escript::AbstractContinuousDomain::addPDEToRHS,
290 args("rhs", "X", "Y", "y", "y_contact", "y_dirac"),
291 "adds a PDE onto the stiffness matrix mat and a rhs\n\n"
292 ":param rhs:\n:type rhs: `Data`\n"
293 ":param X:\n:type X: `Data`\n"
294 ":param Y:\n:type Y: `Data`\n"
295 ":param y:\n:type y: `Data`\n"
296 ":param y_contact:\n:type y_contact: `Data`\n"
297 ":param y_dirac:\n:type y_dirac: `Data`"
298 )
299 .def("addPDEToTransportProblem",&escript::AbstractContinuousDomain::addPDEToTransportProblem,
300 args( "tp", "source", "M", "A", "B", "C", "D", "X", "Y", "d", "y", "d_contact", "y_contact", "d_dirac", "y_dirac"),
301 ":param tp:\n:type tp: `TransportProblemAdapter`\n"
302 ":param source:\n:type source: `Data`\n"
303 ":param M:\n:type M: `Data`\n"
304 ":param A:\n:type A: `Data`\n"
305 ":param B:\n:type B: `Data`\n"
306 ":param C:\n:type C: `Data`\n"
307 ":param D:\n:type D: `Data`\n"
308 ":param X:\n:type X: `Data`\n"
309 ":param Y:\n:type Y: `Data`\n"
310 ":param d:\n:type d: `Data`\n"
311 ":param y:\n:type y: `Data`\n"
312 ":param d_contact:\n:type d_contact: `Data`\n"
313 ":param y_contact:\n:type y_contact: `Data`\n"
314 ":param d_dirac:\n:type d_dirac: `Data`\n"
315 ":param y_dirac:\n:type y_dirac: `Data`\n"
316 )
317 .def("newOperator",&escript::AbstractContinuousDomain::newSystemMatrix,
318 args("row_blocksize", "row_functionspace", "column_blocksize", "column_functionspace", "type"),
319 "creates a SystemMatrixAdapter stiffness matrix and initializes it with zeros\n\n"
320 ":param row_blocksize:\n:type row_blocksize: ``int``\n"
321 ":param row_functionspace:\n:type row_functionspace: `FunctionSpace`\n"
322 ":param column_blocksize:\n:type column_blocksize: ``int``\n"
323 ":param column_functionspace:\n:type column_functionspace: `FunctionSpace`\n"
324 ":param type:\n:type type: ``int``\n"
325 )
326 .def("newTransportProblem",&escript::AbstractContinuousDomain::newTransportProblem,
327 args("theta", "blocksize", "functionspace", "type"),
328 "creates a TransportProblemAdapter\n\n"
329 ":param theta:\n:type theta: ``float``\n"
330 ":param blocksize:\n:type blocksize: ``int``\n"
331 ":param functionspace:\n:type functionspace: `FunctionSpace`\n"
332 ":param type:\n:type type: ``int``\n"
333 )
334 .def("getDataShape",&escript::AbstractContinuousDomain::getDataShape, args("functionSpaceCode"),
335 ":return: a pair (dps, ns) where dps=the number of data points per sample, and ns=the number of samples\n:rtype: ``tuple``")
336 .def("print_mesh_info",&escript::AbstractContinuousDomain::Print_Mesh_Info,(arg("full")=false),
337 ":param full:\n:type full: ``bool``")
338 .def("getDescription",&escript::AbstractContinuousDomain::getDescription,
339 ":return: a description for this domain\n:rtype: ``string``")
340 .def("setX",&escript::AbstractContinuousDomain::setNewX,
341 args("arg"), "assigns new location to the domain\n\n:param arg:\n:type arg: `Data`")
342 .def("getNumDataPointsGlobal",&escript::AbstractContinuousDomain::getNumDataPointsGlobal,
343 ":return: the number of data points summed across all MPI processes\n"
344 ":rtype: ``int``");
345
346
347
348
349 //
350 // Interface for TestDomain
351 //
352 class_ <escript::TestDomain, bases<escript::AbstractDomain> >("TestDomain",
353 "Test Class for domains with no structure. May be removed from future releases without notice.", no_init);
354
355 // This is the only python visible way to get a TestDomain
356 def("getTestDomainFunctionSpace",&escript::getTestDomainFunctionSpace, (arg("dpps"),
357 arg("samples"), arg("size")=1),
358 "For testing only. May be removed without notice.");
359
360 //
361 // Interface for FunctionSpace
362 //
363 class_<escript::FunctionSpace> fs_definer("FunctionSpace","A FunctionSpace describes which points from the `Domain` to use to represent functions.",init<>()); // Doco goes in the empty string param
364 fs_definer.def("getDim",&escript::FunctionSpace::getDim,":return: the spatial dimension of the underlying domain.\n:rtype: int");
365 // fs_definer.def("getDomain",&escript::FunctionSpace::getDomain,
366 // return_internal_reference<>());
367 fs_definer.def("getDomain",&escript::FunctionSpace::getDomainPython,":return: the underlying `Domain` for this FunctionSpace.\n:rtype: `Domain`");
368 fs_definer.def("getX",&escript::FunctionSpace::getX,"\n:return: a function whose values are its input coordinates. ie an identity function.\n:rtype: `Data`");
369 fs_definer.def("getNormal",&escript::FunctionSpace::getNormal,":return: the surface normal field.\n\n:rtype: `Data`");
370 fs_definer.def("getSize",&escript::FunctionSpace::getSize,":return: sample size\n:rtype: `Data`");
371 fs_definer.def("setTags",&escript::FunctionSpace::setTags,args("newtag","mask"),
372 "Set tags according to a mask\n\n:param newtag: tag number to set\n:type newtag: string, non-zero ``int``\n:param mask: Samples which correspond to positive values in the mask will be set to ``newtag``.\n:type mask: scalar `Data`");
373 fs_definer.def("setTags",&escript::FunctionSpace::setTagsByString,args("newtag","mask"));
374 fs_definer.def("getTagFromDataPointNo",
375 &escript::FunctionSpace::getTagFromDataPointNo,":return: the tag associated with the given sample number.\n:rtype: int");
376 fs_definer.def("getReferenceIDFromDataPointNo", &escript::FunctionSpace::getReferenceIDFromDataPointNo,args("dataPointNo"),":return: the reference number associated with ``dataPointNo``\n:rtype: int ");
377 fs_definer.def("getListOfTags",&escript::FunctionSpace::getListOfTags,":return: a list of the tags used in this function space\n:rtype: ``list``");
378 fs_definer.def("getApproximationOrder", &escript::FunctionSpace::getApproximationOrder,":return: the approximation order referring to the maximum degree of a polynomial which can be represented exactly in interpolation and/or integration.\n:rtype: ``int``");
379 fs_definer.def("__str__", &escript::FunctionSpace::toString);
380 fs_definer.def(self == self);
381 fs_definer.def(self != self);
382 //
383 // Interface for Data
384 //
385 class_<escript::Data>("Data"/*,shared_ptr<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<>() )
386 // various constructors for Data objects
387 .def(init<const object&, optional<const escript::FunctionSpace&, bool> >(args("value","what","expand")))
388 .def(init<const double, const tuple&, optional<const escript::FunctionSpace&, bool> >(args("value","shape","what","expand")))
389 .def(init<const escript::Data&, const escript::FunctionSpace&>(args("value","what")))
390 .def(init<const escript::Data&>())
391 // Note for Lutz, Need to specify the call policy in order to return a
392 // reference. In this case return_internal_reference.
393 .def("__str__",&escript::Data::toString)
394 .def("getDomain",&escript::Data::getDomainPython,":rtype: `Domain`")
395 .def("getFunctionSpace",&escript::Data::getFunctionSpace,return_value_policy<copy_const_reference>(),":rtype: `FunctionSpace`")
396 .def("isEmpty",&escript::Data::isEmpty,"Is this object an instance of ``DataEmpty``\n\n:rtype: ``bool``\n:note: This is not the same thing as asking if the object contains datapoints.")
397 .def("isProtected",&escript::Data::isProtected,"Can this instance be modified.\n:rtype: ``bool``")
398 .def("setProtection",&escript::Data::setProtection,"Disallow modifications to this data object\n\n:note: This method does not allow you to undo protection.")
399 .def("getShape",&escript::Data::getShapeTuple,"\nReturns the shape of the datapoints in this object as a python tuple. Scalar data has the shape ``()``\n\n:rtype: ``tuple``")
400 .def("getRank",&escript::Data::getDataPointRank,":return: the number of indices required to address a component of a datapoint\n:rtype: positive ``int``")
401 .def("dump",&escript::Data::dump,args("fileName"),"Save the data as a netCDF file\n\n:param fileName: \n:type fileName: ``string``")
402 .def("toListOfTuples",&escript::Data::toListOfTuples, (arg("scalarastuple")=false),
403 "Return the datapoints of this object in a list. Each datapoint is stored as a tuple.\n\n"
404 ":param scalarastuple: if True, scalar data will be wrapped as a tuple."
405 " True => [(0), (1), (2)]; False => [0, 1, 2]")
406 .def("copyWithMask",&escript::Data::copyWithMask,args("other","mask"),
407 "Selectively copy values from ``other`` `Data`."
408 "Datapoints which correspond to positive values in ``mask`` will be copied from ``other``\n"
409 "\n:param other: source of values\n"
410 ":type other: `Data`\n:param mask:\n:type mask: Scalar `Data`")
411 .def("setTaggedValue",&escript::Data::setTaggedValue,args("tagKey","value"),
412 "Set the value of tagged Data.\n\n:param tagKey: tag to update\n:type tagKey: ``int``\n")
413 .def("setTaggedValue",&escript::Data::setTaggedValueByName,args("name","value"),":param name: tag to update\n:type name: ``string``\n"
414 ":param value: value to set tagged data to\n:type value: ``object`` which acts like an array, ``tuple`` or ``list``\n")
415 .def("getNumberOfDataPoints",&escript::Data::getNumDataPoints,":rtype: ``int``\n:return: Number of datapoints in the object")
416 .def("isExpanded",&escript::Data::isExpanded,":rtype: ``bool``\n:return: True if this ``Data`` is expanded.")
417 .def("isTagged",&escript::Data::isTagged,":rtype: ``bool``\n:return: True if this ``Data`` is expanded.")
418 .def("isConstant",&escript::Data::isConstant,":rtype: ``bool``\n:return: True if this ``Data`` is an instance of ``DataConstant``\n:note: This does not mean the data is immutable.")
419 .def("isLazy",&escript::Data::isLazy,":rtype: ``bool``\n:return: True if this ``Data`` is lazy.")
420 .def("isReady",&escript::Data::isReady,":rtype: ``bool``\n:return: True if this ``Data`` is not lazy.")
421 .def("expand",&escript::Data::expand,"Convert the data to expanded representation if it is not expanded already.")
422 .def("tag",&escript::Data::tag,"Convert data to tagged representation if it is not already tagged or expanded")
423 .def("resolve",&escript::Data::resolve,"Convert the data to non-lazy representation.")
424 .def("copy",&escript::Data::copy,args("other"),"Make this object a copy of ``other``\n"
425 "\n:note: The two objects will act independently from now on. That is, changing ``other`` "
426 "after this call will not change this object and vice versa.")
427 .def("copy",&escript::Data::copySelf,":note: In the no argument form, a new object will be returned which is an independent copy of this object.")
428 .def("delay",&escript::Data::delay,"Convert this object into lazy representation")
429 .def("setValueOfDataPoint",&escript::Data::setValueOfDataPointToPyObject,args("dataPointNo","value"))
430 .def("setValueOfDataPoint",&escript::Data::setValueOfDataPointToArray)
431 .def("_setTupleForGlobalDataPoint", &escript::Data::setTupleForGlobalDataPoint)
432 .def("setValueOfDataPoint",&escript::Data::setValueOfDataPoint,"\nModify the value of a single datapoint.\n\n:param dataPointNo:\n"
433 ":type dataPointNo: int\n:param value: \n:type value: ``float`` or an object which acts like an array, ``tuple`` or ``list``\n:warning: Use of this operation is discouraged. It prevents some optimisations from operating.")
434 .def("getTupleForDataPoint",&escript::Data::getValueOfDataPointAsTuple,args("dataPointNo"),
435 ":return: Value of the specified datapoint\n:rtype: ``tuple``\n:param dataPointNo: datapoint to access\n:type dataPointNo: ``int``")
436 .def("getTupleForGlobalDataPoint",&escript::Data::getValueOfGlobalDataPointAsTuple,args("procNo","dataPointNo"),"Get a specific datapoint from a specific process\n\n"
437 ":rtype: ``tuple``\n:param procNo: MPI rank of the process\n:type procNo: positive ``int``"
438 "\n:param dataPointNo: datapoint to access\n:type dataPointNo: int")
439 .def("setToZero",&escript::Data::setToZero,"After this call the object will store values of the same shape as before but all components will be zero.")
440 .def("interpolate",&escript::Data::interpolate,args("functionspace"),"Interpolate this object's values into a new functionspace.")
441 .def("_interpolateTable3d", &escript::Data::interpolateFromTable3DP,
442 (arg("table"),arg("Amin"),arg("Astep"), arg("B"), arg("Bmin"), arg("Bstep"), arg("C"), arg("Cmin"), arg("Cstep"), arg("undef")=1.e50, arg("check_boundaries")=false, "For internal use only. Please use the interpolateTable function.")
443 )
444
445 .def("interpolateTable", &escript::Data::interpolateFromTable2DP,
446 (arg("table"),arg("Amin"),arg("Astep"), arg("B"), arg("Bmin"), arg("Bstep"), arg("undef")=1.e50, arg("check_boundaries")=false),
447 "Creates a new Data object by interpolating using the source data (which are\n"
448 "looked up in ``table``)\n``A`` must be the outer dimension on the table\n\n"
449 ":param table: two dimensional collection of values\n"
450 ":param Amin: The base of locations in table\n:type Amin: float\n"
451 ":param Astep: size of gap between each item in the table\n:type Astep: float\n"
452 ":param undef: upper bound on interpolated values\n:type undef: float\n"
453 ":param B: Scalar representing the second coordinate to be mapped into the table\n"
454 ":type B: `Data`\n"
455 ":param Bmin: The base of locations in table for 2nd dimension\n:type Bmin: float\n"
456 ":param Bstep: size of gap between each item in the table for 2nd dimension\n:type Bstep: float\n"
457 ":param check_boundaries: if true, then values outside the boundaries will be rejected. If false, then boundary values will be used.\n"
458 ":raise RuntimeError(DataException): if the coordinates do not map into the table or if the interpolated value is above ``undef``"
459 "\n:rtype: `Data`"
460 )
461 .def("interpolateTable", &escript::Data::interpolateFromTable1DP,
462 (arg("table"),arg("Amin"),arg("Astep"), arg("undef")=1.e50, arg("check_boundaries")=false)/*,
463 "Creates a new Data object by interpolating using the source data (which are\n"
464 "looked up in ``table``)\n\n"
465 ":param table: one dimensional collection of values\n"
466 ":param Amin: The base of locations in table\n:type Amin: float\n"
467 ":param Astep: size of gap between each item in the table\n:type Astep: float\n"
468 ":param undef: upper bound on interpolated values\n:type undef: float\n"
469 ":param check_boundaries: if true, then values outside the boundaries will be rejected. If false, then boundary values will be used.\n"
470 ":raise RuntimeError(DataException): if the coordinates do not map into the table or if the interpolated value is above ``undef``"
471 "\n:rtype: `Data`"
472 */
473 )
474 .def("nonuniformInterpolate", &escript::Data::nonuniforminterp, "1D interpolation with non equally spaced points",
475 (arg("in"), arg("out"), arg("check_boundaries")),
476 "Creates a Data object by linear interpolation of the function F(in)->out\n\n"
477 ":param in: input values of interpolation function\n"
478 ":param out: corresponding output values of interpolation function\n"
479 ":param check_boundaries: If True, an exception will the thrown if the data object contains values"
480 "outside the range given by ``in``.\n"
481 )
482 .def("nonuniformSlope", &escript::Data::nonuniformslope, "1D interpolation of slope with non equally spaced points",
483 (arg("in"), arg("out"), arg("check_boundaries")),
484 "Creates a Data object by computing the slope of the function F(in)->out\n\n"
485 ":param in: input values of interpolation function\n"
486 ":param out: corresponding output values of interpolation function\n"
487 ":param check_boundaries: If True, an exception will the thrown if the data object contains values"
488 "outside the range given by ``in``.\n"
489 )
490 .def("minGlobalDataPoint",&escript::Data::minGlobalDataPoint,"Please consider using getInfLocator() from pdetools instead.")
491 .def("maxGlobalDataPoint",&escript::Data::maxGlobalDataPoint, "Please consider using getSupLocator() from pdetools instead.")
492 .def("getTagNumber",&escript::Data::getTagNumber,args("dpno"),"Return tag number for the specified datapoint\n\n:rtype: int\n:param dpno: datapoint number\n:type dpno: int")
493 // Unary functions for Data
494 .def("_interpolate",&escript::Data::interpolate)
495 .def("_grad",&escript::Data::gradOn)
496 .def("_grad",&escript::Data::grad)
497 .def("_transpose",&escript::Data::transpose)
498 .def("_trace",&escript::Data::trace)
499 .def("_maxval",&escript::Data::maxval)
500 .def("_minval",&escript::Data::minval)
501 .def("_wherePositive",&escript::Data::wherePositive)
502 .def("_whereNegative",&escript::Data::whereNegative)
503 .def("_whereNonNegative",&escript::Data::whereNonNegative)
504 .def("_whereNonPositive",&escript::Data::whereNonPositive)
505 .def("_whereZero",&escript::Data::whereZero,(arg("tol")=0.0))
506 .def("_whereNonZero",&escript::Data::whereNonZero,(arg("tol")=0.0))
507 .def("_erf",&escript::Data::erf)
508 .def("_sin",&escript::Data::sin)
509 .def("_cos",&escript::Data::cos)
510 .def("_tan",&escript::Data::tan)
511 .def("_asin",&escript::Data::asin)
512 .def("_acos",&escript::Data::acos)
513 .def("_atan",&escript::Data::atan)
514 .def("_sinh",&escript::Data::sinh)
515 .def("_cosh",&escript::Data::cosh)
516 .def("_tanh",&escript::Data::tanh)
517 .def("_asinh",&escript::Data::asinh)
518 .def("_acosh",&escript::Data::acosh)
519 .def("_atanh",&escript::Data::atanh)
520 .def("_exp",&escript::Data::exp)
521 .def("_sqrt",&escript::Data::sqrt)
522 .def("_log10",&escript::Data::log10)
523 .def("_log",&escript::Data::log)
524 .def("_sign",&escript::Data::sign)
525 .def("_symmetric",&escript::Data::symmetric)
526 .def("_nonsymmetric",&escript::Data::nonsymmetric)
527 .def("_trace",&escript::Data::trace)
528 .def("_swap_axes",&escript::Data::swapaxes)
529 .def("_eigenvalues",&escript::Data::eigenvalues)
530 .def("_eigenvalues_and_eigenvectors",&escript::Data::eigenvalues_and_eigenvectors,(arg("tol")=1.e-13))
531 // functions returning a single real number:
532 .def("_Lsup",&escript::Data::Lsup,":return: the Lsup-norm of the object\n:rtype: float\n:note: If the ``Data`` contains no values, zero will be returned instead.")
533 .def("_sup",&escript::Data::sup,":return: the maximum value over all data points.\n:rtype: float\n:note: If the ``Data`` contains no values a large negative value will be returned instead.")
534 .def("_inf",&escript::Data::inf,":return: minimum value over all components and all data points\n:rtype: float\n:note: If the ``Data`` contains no values a large positive value will be returned instead.")
535 .def("_integrateToTuple",&escript::Data::integrateToTuple,":return: Calculate the integral over the function space domain as a python tuple\n:rtype: tuple")
536 // following implements the python abs operator
537 .def("__abs__",&escript::Data::abs,":return: absolute value\n\n:rtype: `Data`")
538 // following implements the python "-" negation operator
539 .def("__neg__",&escript::Data::neg, ":return: negation of the values in this object\n:rtype: `Data`")
540 // following implements the python "+" identity operator
541 .def("__pos__",&escript::Data::pos, "\nThe unary + operator\n\n:rtype: `Data`")
542 // following three functions implement the python [] operator
543 .def("__getitem__",&escript::Data::getItem,"Used by the python [] operator\n\n:rtype: `Data`")
544 .def("__setitem__",&escript::Data::setItemO,"Used by the python [] operator")
545 .def("__setitem__",&escript::Data::setItemD,"Used by the python [] operator")
546 // following three functions implement the python ** operator
547 .def("__pow__",&escript::Data::powO,"Used by the python ** operator\n\n:rtype: `Data`")
548 .def("__pow__",&escript::Data::powD)
549 .def("__rpow__",&escript::Data::rpowO,"\nUsed by the python ** operator\n\n:rtype: `Data`")
550 // following two functions implement the newer python / operator
551 .def("__truediv__",&escript::Data::truedivO)
552 .def("__truediv__",&escript::Data::truedivD)
553 .def("__rtruediv__",&escript::Data::rtruedivO)
554 // NOTE:: The order of these declarations is important. Anything
555 // declared before the generic declaration isn't found so the generic
556 // version will be called.
557 // .def(self + other<object>())
558 // .def(other<object>() + self)
559 // .def(self + self)
560 .def(self += other<object>())
561 .def(self += self)
562
563 // .def(self - other<object>())
564 // .def(other<object>() - self)
565 // .def(self - self)
566 .def(self -= other<object>())
567 .def(self -= self)
568
569 // .def(self * other<object>())
570 // .def(other<object>() * self)
571 // .def(self * self)
572 .def(self *= other<object>())
573 .def(self *= self)
574
575 // .def(self / other<object>())
576 // .def(other<object>() / self)
577 // .def(self / self)
578 .def(self /= other<object>())
579 .def(self /= self)
580 // Need scope resolution due to a bug either in the compiler or
581 // the boost code. This calls operator << for Data.
582 .def(self_ns::str(self))
583 .def("_inverse", &escript::Data::matrixInverse, ":return: inverse of square matrices\n")
584 // .def("__add__", &escript::Data::addOperatorD)
585 .def("__add__", &escript::Data::__add__)
586 .def("__radd__", &escript::Data::__add__) // its the same coz + is commutative
587 .def("__sub__", &escript::Data::__sub__)
588 .def("__rsub__", &escript::Data::__rsub__)
589 .def("__mul__", &escript::Data::__mul__)
590 .def("__rmul__", &escript::Data::__mul__) // commutative
591 .def("__div__", &escript::Data::__div__)
592 .def("__rdiv__", &escript::Data::__rdiv__) // commutative
593
594 ;
595
596 //
597 // Factory methods for function space
598 //
599 def("ContinuousFunction",escript::continuousFunction,args("domain"),
600 ":return: a continuous FunctionSpace (overlapped node values)\n"
601 ":rtype: `FunctionSpace`");
602 def("ReducedContinuousFunction",escript::reducedContinuousFunction,args("domain"),
603 ":return: a continuous with reduced order FunctionSpace (overlapped node values on reduced element order)\n"
604 ":rtype: `FunctionSpace`");
605 def("Function",escript::function,args("domain"),":return: a function `FunctionSpace`\n"
606 ":rtype: `FunctionSpace`");
607 def("ReducedFunction",escript::reducedFunction, args("domain"),":return: a function FunctionSpace with reduced integration order\n:rtype: `FunctionSpace`");
608 def("FunctionOnBoundary",escript::functionOnBoundary, args("domain"), ":return: a function on boundary FunctionSpace\n:rtype: `FunctionSpace`");
609 def("ReducedFunctionOnBoundary",escript::reducedFunctionOnBoundary, args("domain"),
610 ":return: a function on boundary FunctionSpace with reduced integration order\n"
611 ":rtype: `FunctionSpace`");
612 def("FunctionOnContactZero",escript::functionOnContactZero, args("domain"), ":return: Return a FunctionSpace on left side of contact\n:rtype: `FunctionSpace`");
613 def("ReducedFunctionOnContactZero",escript::reducedFunctionOnContactZero, args("domain"),
614 ":return: a FunctionSpace on left side of contact with reduced integration order\n:rtype: `FunctionSpace`");
615 def("FunctionOnContactOne",escript::functionOnContactOne, args("domain"), ":return: Return a FunctionSpace on right side of contact\n:rtype: `FunctionSpace`");
616 def("ReducedFunctionOnContactOne",escript::reducedFunctionOnContactOne, args("domain"),
617 ":return: Return a FunctionSpace on right side of contact with reduced integration order\n"
618 ":rtype: `FunctionSpace`");
619 def("Solution",escript::solution, args("domain"), ":rtype: `FunctionSpace`");
620 def("ReducedSolution",escript::reducedSolution, args("domain"), ":rtype: `FunctionSpace`");
621 def("DiracDeltaFunctions",escript::diracDeltaFunctions, args("domain"), ":rtype: `FunctionSpace`");
622
623
624
625
626
627 //
628 // Factory methods for Data
629 //
630 def("load",escript::load, args("fileName","domain"), "reads Data on domain from file in netCDF format\n\n:param fileName:\n:type fileName: ``string``\n:param domain:\n:type domain: `Domain`");
631 def("loadIsConfigured",escript::loadConfigured,":return: True if the load function is configured.");
632 def("Scalar",escript::Scalar,
633 (arg("value")=0.0,
634 arg("what")=escript::FunctionSpace(),
635 arg("expanded")=false),
636 "Construct a Data object containing scalar data-points.\n\n:param value: scalar value for all points\n"
637 "\n:rtype: `Data`\n:type value: float\n:param what: FunctionSpace for Data\n:type what: `FunctionSpace`\n"
638 ":param expanded: If True, a value is stored for each point. If False, more efficient representations may be used\n"
639 ":type expanded: ``bool``");
640 def("Vector",escript::Vector,
641 (arg("value")=0.0,
642 arg("what")=escript::FunctionSpace(),
643 arg("expanded")=false),
644 "Construct a Data object containing rank1 data-points.\n\n:param value: scalar value for all points\n"
645 "\n:rtype: `Data`\n:type value: float\n:param what: FunctionSpace for Data\n:type what: `FunctionSpace`\n"
646 ":param expanded: If True, a value is stored for each point. If False, more efficient representations may be used\n"
647 ":type expanded: ``bool``");
648 def("Vector", escript::VectorFromObj,
649 (arg("value"),
650 arg("what")=escript::FunctionSpace(),
651 arg("expanded")=false));
652 def("Tensor",escript::Tensor,
653 (arg("value")=0.0,
654 arg("what")=escript::FunctionSpace(),
655 arg("expanded")=false),
656 "Construct a Data object containing rank2 data-points.\n\n:param value: scalar value for all points\n"
657 "\n:rtype: `Data`\n:type value: float\n:param what: FunctionSpace for Data\n:type what: `FunctionSpace`\n"
658 ":param expanded: If True, a value is stored for each point. If False, more efficient representations may be used\n"
659 ":type expanded: ``bool``");
660 def("Tensor", escript::TensorFromObj,
661 (arg("value"),
662 arg("what")=escript::FunctionSpace(),
663 arg("expanded")=false));
664 def("Tensor3",escript::Tensor3,
665 (arg("value")=0.0,
666 arg("what")=escript::FunctionSpace(),
667 arg("expanded")=false),
668 "Construct a Data object containing rank3 data-points.\n\n:param value: scalar value for all points\n"
669 "\n:rtype: `Data`\n:type value: float\n:param what: FunctionSpace for Data\n:type what: `FunctionSpace`\n"
670 ":param expanded: If True, a value is stored for each point. If False, more efficient representations may be used\n"
671 ":type expanded: ``bool``"
672 );
673 def("Tensor3", escript::Tensor3FromObj,
674 (arg("value"),
675 arg("what")=escript::FunctionSpace(),
676 arg("expanded")=false));
677 def("Tensor4",escript::Tensor4,
678 (arg("value")=0.0,
679 arg("what")=escript::FunctionSpace(),
680 arg("expanded")=false),
681 "Construct a Data object containing rank4 data-points.\n\n:param value: scalar value for all points\n"
682 "\n:rtype: `Data`\n:type value: float\n:param what: FunctionSpace for Data\n:type what: `FunctionSpace`\n"
683 ":param expanded: If True, a value is stored for each point. If False, more efficient representations may be used\n"
684 ":type expanded: ``bool``"
685 );
686 def("Tensor4", escript::Tensor4FromObj,
687 (arg("value"),
688 arg("what")=escript::FunctionSpace(),
689 arg("expanded")=false));
690
691
692 def("RandomData", escript::randomData, (arg("shape"), arg("fs"), arg("seed")=0, arg("filter")=boost::python::tuple()),
693 "Creates a new expanded Data object containing pseudo-random values.\n\n"
694 ":param shape: datapoint shape\n:type shape: tuple\n"
695 ":param fs: function space for data object.\n:type fs: `FunctionSpace`\n"
696 ":param seed: seed for random number generator.\n:type seed: long\n");
697
698 //
699 // Binary operators
700 //
701 def("C_GeneralTensorProduct",escript::C_GeneralTensorProduct,
702 (arg("arg0"),
703 arg("arg1"),
704 arg("axis_offset")=0,
705 arg("transpose")=0),
706 "Compute a tensor product of two Data objects.\n\n:rtype: `Data`\n:param arg0:\n"
707 ":param arg1:\n:param axis_offset:\n:type axis_offset: ``int``\n"
708 ":param transpose: 0: transpose neither, 1: transpose arg0, 2: transpose arg1\n"
709 ":type transpose: int");
710
711 //
712 // Interface for AbstractSystemMatrix
713 //
714 class_<escript::AbstractSystemMatrix,escript::ASM_ptr, boost::noncopyable>("Operator","",init<>()) // Doco goes in the empty string param
715 .def("isEmpty",&escript::AbstractSystemMatrix::isEmpty,":rtype: ``bool``\n"
716 ":return: True if matrix is empty")
717 .def("solve",&escript::AbstractSystemMatrix::solve, args("in","options"),
718 ":return: the solution *u* of the linear system *this*u=in*\n\n:param in:\n:type in: `Data`")
719 .def("of",&escript::AbstractSystemMatrix::vectorMultiply,args("right"),
720 "matrix*vector multiplication")
721 .def("nullifyRowsAndCols",&escript::AbstractSystemMatrix::nullifyRowsAndCols)
722 .def("saveMM",&escript::AbstractSystemMatrix::saveMM, args("fileName"),
723 "writes the matrix to a file using the Matrix Market file format")
724 .def("saveHB",&escript::AbstractSystemMatrix::saveHB, args("filename"),
725 "writes the matrix to a file using the Harwell-Boeing file format")
726 .def("resetValues",&escript::AbstractSystemMatrix::resetValues, "resets the matrix entries")
727 .def(self*other<escript::Data>());
728 //
729 // Interface for AbstractTransportProblem
730 //
731 class_<escript::AbstractTransportProblem, escript::ATP_ptr, boost::noncopyable >("TransportProblem","",init<>()) // Doco goes in the empty string param
732 .def("isEmpty",&escript::AbstractTransportProblem::isEmpty,":rtype: ``int``")
733 .def("solve",&escript::AbstractTransportProblem::solve, args("u0","source","dt", "options"),
734 "returns the solution *u* for a time step *dt>0* with initial value u0\n\n:rtype: `Data`\n"
735 ":param source:\n:type source: `Data`")
736 .def("insertConstraint",&escript::AbstractTransportProblem::insertConstraint,
737 args("source", "q", "r","factor"),
738 "inserts constraint *u_{,t}=r* where *q>0* into the problem using a weighting factor")
739 .def("reset",&escript::AbstractTransportProblem::resetTransport,
740 "resets the transport operator typically as they have been updated.")
741 .def("resetValues",&escript::AbstractTransportProblem::resetTransport)
742 .def("getSafeTimeStepSize",&escript::AbstractTransportProblem::getSafeTimeStepSize)
743 .def("getUnlimitedTimeStepSize",&escript::AbstractTransportProblem::getUnlimitedTimeStepSize);
744
745 // Functions to modify global parameters
746 def("setEscriptParamInt",escript::setEscriptParamInt,
747 (arg("name"), arg("value")=0), "Modify the value of an escript tuning parameter\n\n"
748 ":param name:\n:type name: ``string``\n:param value:\n:type value: ``int``");
749 def("getEscriptParamInt",escript::getEscriptParamInt,
750 (arg("name"),arg("sentinel")=0), "Read the value of an escript tuning parameter\n\n"
751 ":param name: parameter to lookup\n:type name: ``string``\n:param sentinel: Value to be returned if ``name`` is not a known parameter\n"
752 ":type sentinel: ``int``");
753 def("listEscriptParams",escript::listEscriptParams,":return: A list of pairs (p,d) where p is the name of a parameter for escript and d is a description.");
754
755
756 def("resolveGroup", escript::resolveGroup);
757
758 #ifdef IKNOWWHATIMDOING
759
760 def("applyBinaryCFunction", escript::applyBinaryCFunction, (arg("function"), arg("outshape"),
761 arg("in1"),
762 arg("in2"))
763 );
764 #endif
765
766 def("_condEval", escript::condEval, (arg("mask"), arg("trueval"), arg("falseval")));
767
768 //
769 // Register esysExceptionTranslator
770 //
771 register_exception_translator<esysUtils::EsysException>(&esysUtils::esysExceptionTranslator);
772 }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26