/[escript]/trunk/doc/user/escript.tex
ViewVC logotype

Contents of /trunk/doc/user/escript.tex

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3293 - (show annotations)
Thu Oct 21 23:18:32 2010 UTC (9 years, 8 months ago) by caltinay
File MIME type: application/x-tex
File size: 66430 byte(s)
user's guide builds again with new class file. The cleanup can commence...

1
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 % Copyright (c) 2003-2010 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 \chapter{The \escript Module}\label{ESCRIPT CHAP}
15
16 \section{Concepts}
17 \escript is a \PYTHON module that allows you to represent the values of
18 a function at points in a \Domain in such a way that the function will
19 be useful for the Finite Element Method (FEM) simulation. It also
20 provides what we call a function space that describes how the data is
21 used in the simulation. Stored along with the data is information
22 about the elements and nodes which will be used by \finley.
23
24 \subsection{Function spaces}
25 In order to understand what we mean by the term 'function space',
26 consider that the solution of a partial differential
27 equation\index{partial differential equation} (PDE) is a function on a domain
28 $\Omega$. When solving a PDE using FEM, the solution is
29 piecewise-differentiable but, in general, its gradient is discontinuous.
30 To reflect these different degrees of smoothness, different function spaces
31 are used.
32 For instance, in FEM, the displacement field is represented by its values at
33 the nodes of the mesh, and so is continuous.
34 The strain, which is the symmetric part of the gradient of the displacement
35 field, is stored on the element centers, and so is considered to be
36 discontinuous.
37
38 A function space is described by a \FunctionSpace object.
39 The following statement generates the object \var{solution_space} which is
40 a \FunctionSpace object and provides access to the function space of
41 PDE solutions on the \Domain \var{mydomain}:
42
43 \begin{python}
44 solution_space=Solution(mydomain)
45 \end{python}
46 The following generators for function spaces on a \Domain \var{mydomain} are commonly used:
47 \begin{itemize}
48 \item \var{Solution(mydomain)}: solutions of a PDE
49 \item \var{ReducedSolution(mydomain)}: solutions of a PDE with a reduced
50 smoothness requirement, e.g. using a lower order approximation on the same
51 element or using macro elements\index{macro elements}
52 \item \var{ContinuousFunction(mydomain)}: continuous functions, e.g. a temperature distribution
53 \item \var{Function(mydomain)}: general functions which are not necessarily continuous, e.g. a stress field
54 \item \var{FunctionOnBoundary(mydomain)}: functions on the boundary of the domain, e.g. a surface pressure
55 \item \var{FunctionOnContact0(mydomain)}: functions on side $0$ of the discontinuity
56 \item \var{FunctionOnContact1(mydomain)}: functions on side $1$ of the discontinuity
57 \end{itemize}
58 In some cases under-integration is used. For these cases the user may use a
59 \FunctionSpace from the following list:
60 \begin{itemize}
61 \item \var{ReducedFunction(mydomain)}
62 \item \var{ReducedFunctionOnBoundary(mydomain)}
63 \item \var{ReducedFunctionOnContact0(mydomain)}
64 \item \var{ReducedFunctionOnContact1(mydomain)}
65 \end{itemize}
66 In comparison to the corresponding full version they use a reduced number of
67 integration nodes (typically one only) to represent values.
68
69 \begin{figure}
70 \centering
71 \includegraphics{EscriptDiagram1}
72 \caption{\label{ESCRIPT DEP}Dependency of function spaces in \finley.
73 An arrow indicates that a function in the \FunctionSpace at the starting point
74 can be interpolated to the \FunctionSpace of the arrow target.
75 All function spaces above the dotted line can be interpolated to any of
76 the function spaces below the line. See also \Sec{SEC Projection}.}
77 \end{figure}
78
79 The reduced smoothness for a PDE solution is often used to fulfill the
80 Ladyzhenskaya-Babuska-Brezzi condition\cite{LBB} when solving saddle point
81 problems\index{saddle point problems}, e.g. the Stokes equation.
82 A discontinuity\index{discontinuity} is a region within the domain across
83 which functions may be discontinuous.
84 The location of a discontinuity is defined in the \Domain object.
85 \fig{ESCRIPT DEP} shows the dependency between the types of function spaces
86 in \finley (other libraries may have different relationships).
87
88 The solution of a PDE is a continuous function. Any continuous function can
89 be seen as a general function on the domain and can be restricted to the
90 boundary as well as to one side of a discontinuity (the result will be
91 different depending on which side is chosen). Functions on any side of the
92 discontinuity can be seen as a function on the corresponding other side.
93
94 A function on the boundary or on one side of the discontinuity cannot be seen
95 as a general function on the domain as there are no values defined for the
96 interior. For most PDE solver libraries the space of the solution and
97 continuous functions is identical, however in some cases, for example when
98 periodic boundary conditions are used in \finley, a solution fulfills periodic
99 boundary conditions while a continuous function does not have to be periodic.
100
101 The concept of function spaces describes the properties of functions and
102 allows abstraction from the actual representation of the function in the
103 context of a particular application. For instance, in the FEM context a
104 function of the \Function type (written as \emph{Function()} in \fig{ESCRIPT DEP})
105 is usually represented by its values at the element center,
106 but in a finite difference scheme the edge midpoint of cells is preferred.
107 By changing its function space you can use the same function in a Finite
108 Difference scheme instead of Finite Element scheme.
109 Changing the function space of a particular function will typically lead to
110 a change of its representation.
111 So, when seen as a general function, a continuous function which is typically
112 represented by its values on the nodes of the FEM mesh or finite difference
113 grid must be interpolated to the element centers or the cell edges,
114 respectively. Interpolation happens automatically in \escript whenever it is
115 required\index{interpolation}. The user needs to be aware that an
116 interpolation is not always possible, see \fig{ESCRIPT DEP} for \finley.
117 An alternative approach to change the representation (=\FunctionSpace) is
118 projection\index{projection}, see \Sec{SEC Projection}.
119
120 \subsection{\Data objects}
121 In \escript the class that stores these functions is called \Data.
122 The function is represented through its values on \DataSamplePoints where
123 the \DataSamplePoints are chosen according to the function space of the
124 function.
125 \Data class objects are used to define the coefficients of the PDEs to be
126 solved by a PDE solver library and also to store the solutions of the PDE.
127
128 The values of the function have a rank which gives the number of indices,
129 and a \Shape defining the range of each index.
130 The rank in \escript is limited to the range 0 through 4 and it is assumed
131 that the rank and \Shape is the same for all \DataSamplePoints.
132 The \Shape of a \Data object is a tuple (list) \var{s} of integers.
133 The length of \var{s} is the rank of the \Data object and the \var{i}-th
134 index ranges between 0 and $\var{s[i]}-1$.
135 For instance, a stress field has rank 2 and \Shape $(d,d)$ where $d$ is the
136 spatial dimension.
137 The following statement creates the \Data object \var{mydat} representing a
138 continuous function with values of \Shape $(2,3)$ and rank $2$:
139 \begin{python}
140 mydat=Data(value=1, what=ContinuousFunction(myDomain), shape=(2,3))
141 \end{python}
142 The initial value is the constant 1 for all \DataSamplePoints and all
143 components.
144
145 \Data objects can also be created from any \numpy array or any object, such
146 as a list of floating point numbers, that can be converted into
147 a \numpyNDA\cite{NUMPY}.
148 The following two statements create objects which are equivalent
149 to \var{mydat}:
150 \begin{python}
151 mydat1=Data(value=numpy.ones((2,3)), what=ContinuousFunction(myDomain))
152 mydat2=Data(value=[[1,1], [1,1], [1,1]], what=ContinuousFunction(myDomain))
153 \end{python}
154 In the first case the initial value is \var{numpy.ones((2,3))} which generates
155 a $2 \times 3$ matrix as a \numpyNDA filled with ones.
156 The \Shape of the created \Data object is taken from the \Shape of the array.
157 In the second case, the creator converts the initial value, which is a list of
158 lists, into a \numpyNDA before creating the actual \Data object.
159
160 For convenience \escript provides creators for the most common types
161 of \Data objects in the following forms (\var{d} defines the spatial dimension):
162 \begin{itemize}
163 \item \code{Scalar(0, Function(mydomain))} is the same as \code{Data(0, Function(myDomain),(,))}
164 (each value is a scalar), e.g. a temperature field
165 \item \code{Vector(0, Function(mydomain))} is the same as \code{Data(0, Function(myDomain),(d))}
166 (each value is a vector), e.g. a velocity field
167 \item \code{Tensor(0, Function(mydomain))} is the same as \code{Data(0, Function(myDomain), (d,d))},
168 e.g. a stress field
169 \item \code{Tensor4(0,Function(mydomain))} is the same as \code{Data(0,Function(myDomain), (d,d,d,d))}
170 e.g. a Hook tensor field
171 \end{itemize}
172 Here the initial value is 0 but any object that can be converted into
173 a \numpyNDA and whose \Shape is consistent with \Shape of the \Data object to
174 be created can be used as the initial value.
175
176 \Data objects can be manipulated by applying unary operations (e.g. cos, sin,
177 log), and they can be combined point-wise by applying arithmetic operations
178 (e.g. +, - ,* , /).
179 We emphasize that \escript itself does not handle any spatial dependencies as
180 it does not know how values are interpreted by the processing PDE solver library.
181 However \escript invokes interpolation if this is needed during data manipulations.
182 Typically, this occurs in binary operations when both arguments belong to
183 different function spaces or when data are handed over to a PDE solver library
184 which requires functions to be represented in a particular way.
185
186 The following example shows the usage of \Data objects. Assume we have a
187 displacement field $u$ and we want to calculate the corresponding stress field
188 $\sigma$ using the linear-elastic isotropic material model
189 \begin{eqnarray}\label{eq: linear elastic stress}
190 \sigma\hackscore {ij}=\lambda u\hackscore {k,k} \delta\hackscore {ij} + \mu ( u\hackscore {i,j} + u\hackscore {j,i})
191 \end{eqnarray}
192 where $\delta\hackscore {ij}$ is the Kronecker symbol and
193 $\lambda$ and $\mu$ are the Lame coefficients. The following function
194 takes the displacement \var{u} and the Lame coefficients \var{lam} and \var{mu}
195 as arguments and returns the corresponding stress:
196 \begin{python}
197 from esys.escript import *
198 def getStress(u, lam, mu):
199 d=u.getDomain().getDim()
200 g=grad(u)
201 stress=lam*trace(g)*kronecker(d)+mu*(g+transpose(g))
202 return stress
203 \end{python}
204 The variable \var{d} gives the spatial dimension of the domain on which the
205 displacements are defined.
206 \var{kronecker} returns the Kronecker symbol with indexes $i$ and $j$ running
207 from 0 to \var{d}-1.
208 The call \var{grad(u)} requires the displacement field \var{u} to be in
209 the \var{Solution} or \ContinuousFunction.
210 The result \var{g} as well as the returned stress will be in the \Function.
211 If, for example, \var{u} is the solution of a PDE then \code{getStress} might
212 be called in the following way:
213 \begin{python}
214 s=getStress(u, 1., 2.)
215 \end{python}
216 However \code{getStress} can also be called with \Data objects as values for
217 \var{lam} and \var{mu} which, for instance in the case of a temperature
218 dependency, are calculated by an expression.
219 The following call is equivalent to the previous example:
220 \begin{python}
221 lam=Scalar(1., ContinuousFunction(mydomain))
222 mu=Scalar(2., Function(mydomain))
223 s=getStress(u, lam, mu)
224 \end{python}
225
226 The function \var{lam} belongs to the \ContinuousFunction but with \var{g} the
227 function \var{trace(g)} is in the \Function.
228 In the evaluation of the product \var{lam*trace(g)} we have different function
229 spaces (on the nodes versus in the centers) and at first glance we have incompatible data.
230 \escript converts the arguments into an appropriate function space according
231 to \fig{ESCRIPT DEP}.
232 In this example that means \escript sees \var{lam} as a function of the \Function.
233 In the context of FEM this means the nodal values of \var{lam} are
234 interpolated to the element centers.
235 The interpolation is automatic and requires no special handling.
236
237 \begin{figure}
238 \centering
239 \includegraphics{EscriptDiagram2}
240 \caption{\label{Figure: tag}Element Tagging. A rectangular mesh over a region
241 with two rock types {\it white} and {\it gray} is shown.
242 The number in each cell refers to the major rock type present in the cell
243 ($1$ for {\it white} and $2$ for {\it gray}).}
244 \end{figure}
245
246 \subsection{Tagged, Expanded and Constant Data}
247 Material parameters such as the Lame coefficients are typically dependent on
248 rock types present in the area of interest.
249 A common technique to handle these kinds of material parameters is
250 \emph{tagging}\index{tagging}, which uses storage efficiently.
251 \fig{Figure: tag} shows an example. In this case two rock types {\it white}
252 and {\it gray} can be found in the domain.
253 The domain is subdivided into triangular shaped cells.
254 Each cell has a tag indicating the rock type predominantly found in this cell.
255 Here $1$ is used to indicate rock type {\it white} and $2$ for rock type {\it gray}.
256 The tags are assigned at the time when the cells are generated and stored in
257 the \Domain class object. To allow easier usage of tags, names can be used
258 instead of numbers. These names are typically defined at the time when the
259 geometry is generated.
260
261 The following statements show how to use tagged values for \var{lam} as shown
262 in \fig{Figure: tag} for the stress calculation discussed above:
263 \begin{python}
264 lam=Scalar(value=2., what=Function(mydomain))
265 insertTaggedValue(lam, white=30., gray=5000.)
266 s=getStress(u, lam, 2.)
267 \end{python}
268 In this example \var{lam} is set to $30$ for those cells with tag {\it white}
269 (=$1$) and to $5000$ for cells with tag {\it gray} (=$2$).
270 The initial value $2$ of \var{lam} is used as a default value for the case
271 when a tag is encountered which has not been linked with a value.
272 The \code{getStress} method does not need to be changed now that we are using tags.
273 \escript resolves the tags when \var{lam*trace(g)} is calculated.
274
275 This brings us to a very important point about \escript.
276 You can develop a simulation with constant Lame coefficients, and then later
277 switch to tagged Lame coefficients without otherwise changing your python script.
278 In short, you can use the same script for models with different domains and
279 different types of input data.
280
281 There are three main ways in which \Data objects are represented internally --
282 constant, tagged, and expanded.
283 In the constant case, the same value is used at each sample point while only a
284 single value is stored to save memory.
285 In the expanded case, each sample point has an individual value (such as for the solution of a PDE).
286 This is where your largest data sets will be created because the values are
287 stored as a complete array.
288 The tagged case has already been discussed above.
289
290 Expanded data is created when you create a \Data object with \code{expanded=True}.
291 Tagged data sets are created when you use the \member{insertTaggedValue}
292 method as shown above.
293
294 Values are accessed through a sample reference number.
295 Operations on expanded \Data objects have to be performed for each sample
296 point individually.
297 When tagged values are used, the values are held in a dictionary.
298 Operations on tagged data require processing the set of tagged values only,
299 rather than processing the value for each individual sample point.
300 \escript allows any mixture of constant, tagged and expanded data in a single expression.
301
302 \subsection{Saving and Restoring Simulation Data}
303 \Data objects can be written to disk files with the \member{dump} method and
304 read back using the \member{load} method, both of which use the
305 \netCDF\cite{NETCDF} file format.
306 Use these to save data for checkpoint/restart or simply to save and reuse data
307 that was expensive to compute.
308
309 For instance, to save the coordinates of the data points of a
310 \ContinuousFunction to the file \file{x.nc} use
311 \begin{python}
312 x=ContinuousFunction(mydomain).getX()
313 x.dump("x.nc")
314 mydomain.dump("dom.nc")
315 \end{python}
316 To recover the object \var{x}, and \var{mydomain} was a \finley mesh use
317 \begin{python}
318 from esys.finley import LoadMesh
319 mydomain=LoadMesh("dom.nc")
320 x=load("x.nc", mydomain)
321 \end{python}
322 Obviously, it is possible to execute the same steps that were originally used
323 to generate \var{mydomain} to recreate it. However, in most cases using
324 \member{dump} and \member{load} is faster, particularly if optimization has
325 been applied.
326 If \escript is running on more than one \MPI process \member{dump} will create
327 an individual file for each process containing the local data.
328 In order to avoid conflicts the file names are extended by the \MPI processor
329 rank, that is instead of one file \file{dom.nc} you would get
330 \file{dom.nc.0000}, \file{dom.nc.0001}, etc. You still call
331 \code{LoadMesh('dom.nc')} to load the domain but you have to make sure that
332 the appropriate file is accessible from the corresponding rank, and loading
333 will only succeed if you run with as many processes as were used when calling
334 \member{dump}.
335
336 The function space of the \Data is stored in \file{x.nc}.
337 If the \Data object is expanded, the number of data points in the file and of
338 the \Domain for the particular \FunctionSpace must match.
339 Moreover, the ordering of the values is checked using the reference
340 identifiers provided by \FunctionSpace on the \Domain.
341 In some cases, data points will be reordered so be aware and confirm that you
342 get what you wanted.
343
344 A newer, more flexible way of saving and restoring \escript simulation data
345 is through a \class{DataManager} class object.
346 It has the advantage of allowing to save and load not only a \Domain and
347 \Data objects but also other values\footnote{The \PYTHON \emph{pickle} module
348 is used for other types.} you compute in your simulation script.
349 Further, \class{DataManager} objects can simultaneously create files for
350 visualization so no extra calls to, e.g. \code{saveVTK} are needed.
351
352 The following example shows how the \class{DataManager} class can be used.
353 For an explanation of all member functions and options see the relevant
354 reference section.
355 \begin{python}
356 from esys.escript import DataManager, Scalar, Function
357 from esys.finley import Rectangle
358
359 dm = DataManager(formats=[DataManager.RESTART, DataManager.VTK])
360 if dm.hasData():
361 mydomain=dm.getDomain()
362 val=dm.getValue("val")
363 t=dm.getValue("t")
364 t_max=dm.getValue("t_max")
365 else:
366 mydomain=Rectangle()
367 val=Function(mydomain).getX()
368 t=0.
369 t_max=2.5
370
371 while t<t_max:
372 t+=.01
373 val=val+t/2
374 dm.addData(val=val, t=t, t_max=t_max)
375 dm.export()
376 \end{python}
377 In the constructor we specify that we want \code{RESTART} (i.e. dump) files
378 and \code{VTK} files to be saved.
379 By default, the constructor will look for previously saved \code{RESTART}
380 files under the current directory and load them.
381 We can then enquire if such files were found by calling the \member{hasData}
382 method. If it returns \True we retrieve the domain and values into local
383 variables. Otherwise the same variables are initialized with appropriate
384 values to start a new simulation.
385 Note, that \var{t} and \var{t_max} are regular floating point values and not
386 \Data objects but are treated the same way by the \class{DataManager}.
387
388 After this initialization step the script enters the main simulation loop
389 where calculations are performed.
390 When these are finalized for a time step we call the \member{addData} method
391 to let the manager know which variables to store on disk.
392 Note, that this does not actually save the data yet and it is allowed to call
393 \member{addData} more than once to add information incrementally, e.g. from
394 separate functions that have access to the \class{DataManager} instance.
395 Once all variables have been added the \member{export} method has to be called
396 to flush all data to disk and clear the manager.
397 In this example, this call dumps \var{mydomain} and \var{val} to files
398 in a restart directory and also stores \var{t} and \var{t_max} on disk.
399 Additionally, it generates a \VTK file for visualization of the data.
400
401 \section{\escript Classes}
402 \declaremodule{extension}{esys.escript}
403 \modulesynopsis{Data manipulation}
404
405 \subsection{\Domain class}
406 \begin{classdesc}{Domain}{}
407 A \Domain object is used to describe a geometric region together with
408 a way of representing functions over this region.
409 The \Domain class provides an abstract interface to the domain of \FunctionSpace and \Data objects.
410 \Domain needs to be subclassed in order to provide a complete implementation.
411 \end{classdesc}
412 The following methods are available:
413 \begin{methoddesc}[Domain]{getDim}{}
414 returns the spatial dimension of the \Domain.
415 \end{methoddesc}
416 \begin{methoddesc}[Domain]{dump}{filename}
417 dumps the \Domain into the file \var{filename}.
418 \end{methoddesc}
419 \begin{methoddesc}[Domain]{getX}{}
420 returns the locations in the \Domain. The \FunctionSpace of the returned
421 \Data object is chosen by the \Domain implementation. Typically it will be
422 in the \Function.
423 \end{methoddesc}
424
425 \begin{methoddesc}[Domain]{setX}{newX}
426 assigns a new location to the \Domain. \var{newX} has to have \Shape $(d,)$
427 where $d$ is the spatial dimension of the domain. Typically \var{newX} must be
428 in the \ContinuousFunction but the space actually to be used depends on the \Domain implementation.
429 \end{methoddesc}
430
431 \begin{methoddesc}[Domain]{getNormal}{}
432 returns the surface normals on the boundary of the \Domain as \Data object.
433 \end{methoddesc}
434
435 \begin{methoddesc}[Domain]{getSize}{}
436 returns the local sample size, e.g. the element diameter, as \Data object.
437 \end{methoddesc}
438
439 \begin{methoddesc}[Domain]{setTagMap}{tag_name, tag}
440 defines a mapping of the tag name \var{tag_name} to the \var{tag}.
441 \end{methoddesc}
442 \begin{methoddesc}[Domain]{getTag}{tag_name}
443 returns the tag associated with the tag name \var{tag_name}.
444 \end{methoddesc}
445 \begin{methoddesc}[Domain]{isValidTagName}{tag_name}
446 return \True if \var{tag_name} is a valid tag name.
447 \end{methoddesc}
448
449 \begin{methoddesc}[Domain]{__eq__}{arg}
450 (python == operator) returns \True if the \Domain \var{arg} describes the same domain. Otherwise
451 \False is returned.
452 \end{methoddesc}
453
454 \begin{methoddesc}[Domain]{__ne__}{arg}
455 (python != operator) returns \True if the \Domain \var{arg} does not describe the same domain.
456 Otherwise \False is returned.
457 \end{methoddesc}
458
459 \begin{methoddesc}[Domain]{__str__}{arg}
460 (python str() function) returns string representation of the \Domain.
461 \end{methoddesc}
462
463 \begin{methoddesc}[Domain]{onMasterProcessor)}{}
464 returns \True if the processor is the master processor within
465 the \MPI processor group used by the \Domain. This is the processor with rank 0.
466 If \MPI support is not enabled the return value is always \True.
467 \end{methoddesc}
468
469 \begin{methoddesc}[Domain]{getMPISize}{}
470 returns the number of \MPI processors used for this \Domain. If \MPI support is not enabled
471 1 is returned.
472 \end{methoddesc}
473
474 \begin{methoddesc}[Domain]{getMPIRank}{}
475 returns the rank of the processor executing the statement
476 within the \MPI processor group used by the \Domain.
477 If \MPI support is not enabled 0 is returned.
478 \end{methoddesc}
479
480 \begin{methoddesc}[Domain]{MPIBarrier}{}
481 executes barrier synchronization within
482 the \MPI processor group used by the \Domain.
483 If \MPI support is not enabled, this command does nothing.
484 \end{methoddesc}
485
486 \subsection{\FunctionSpace class}
487 \begin{classdesc}{FunctionSpace}{}
488 \FunctionSpace objects are used to define properties of \Data objects, such as continuity. \FunctionSpace objects
489 are instantiated by generator functions. A \Data object in a particular \FunctionSpace is
490 represented by its values at \DataSamplePoints which are defined by the type and the \Domain of the
491 \FunctionSpace.
492 \end{classdesc}
493 The following methods are available:
494 \begin{methoddesc}[FunctionSpace]{getDim}{}
495 returns the spatial dimension of the \Domain of the \FunctionSpace.
496 \end{methoddesc}
497
498
499
500 \begin{methoddesc}[FunctionSpace]{getX}{}
501 returns the location of the \DataSamplePoints.
502 \end{methoddesc}
503
504 \begin{methoddesc}[FunctionSpace]{getNormal}{}
505 If the domain of functions in the \FunctionSpace
506 is a hyper-manifold (e.g. the boundary of a domain)
507 the method returns the outer normal at each of the
508 \DataSamplePoints. Otherwise an exception is raised.
509 \end{methoddesc}
510
511 \begin{methoddesc}[FunctionSpace]{getSize}{}
512 returns a \Data objects measuring the spacing of the \DataSamplePoints.
513 The size may be zero.
514 \end{methoddesc}
515
516 \begin{methoddesc}[FunctionSpace]{getDomain}{}
517 returns the \Domain of the \FunctionSpace.
518 \end{methoddesc}
519
520 \begin{methoddesc}[FunctionSpace]{setTags}{new_tag, mask}
521 assigns a new tag \var{new_tag} to all data sample
522 where \var{mask} is positive for a least one data point.
523 \var{mask} must be defined on the this \FunctionSpace.
524 Use the \var{setTagMap} to assign a tag name to \var{new_tag}.
525 \end{methoddesc}
526
527 \begin{methoddesc}[FunctionSpace]{__eq__}{arg}
528 (python == operator) returns \True if the \Domain \var{arg} describes the same domain. Otherwise
529 \False is returned.
530 \end{methoddesc}
531
532 \begin{methoddesc}[FunctionSpace]{__ne__}{arg}
533 (python != operator) returns \True if the \Domain \var{arg} do not describe the same domain.
534 Otherwise \False is returned.
535 \end{methoddesc}
536
537 \begin{methoddesc}[Domain]{__str__}{g}
538 (python str() function) returns string representation of the \Domain.
539 \end{methoddesc}
540
541 The following function provide generators for \FunctionSpace objects:
542 \begin{funcdesc}{Function}{domain}
543 returns the \Function on the \Domain \var{domain}. \Data objects in this type of \Function
544 are defined over the whole geometric region defined by \var{domain}.
545 \end{funcdesc}
546
547 \begin{funcdesc}{ContinuousFunction}{domain}
548 returns the \ContinuousFunction on the \Domain domain. \Data objects in this type of \Function
549 are defined over the whole geometric region defined by \var{domain} and assumed to represent
550 a continuous function.
551 \end{funcdesc}
552
553 \begin{funcdesc}{FunctionOnBoundary}{domain}
554 returns the \ContinuousFunction on the \Domain domain. \Data objects in this type of \Function
555 are defined on the boundary of the geometric region defined by \var{domain}.
556 \end{funcdesc}
557
558 \begin{funcdesc}{FunctionOnContactZero}{domain}
559 returns the \FunctionOnContactZero the \Domain domain. \Data objects in this type of \Function
560 are defined on side 0 of a discontinuity within the geometric region defined by \var{domain}.
561 The discontinuity is defined when \var{domain} is instantiated.
562 \end{funcdesc}
563
564 \begin{funcdesc}{FunctionOnContactOne}{domain}
565 returns the \FunctionOnContactOne on the \Domain domain.
566 \Data objects in this type of \Function
567 are defined on side 1 of a discontinuity within the geometric region defined by \var{domain}.
568 The discontinuity is defined when \var{domain} is instantiated.
569 \end{funcdesc}
570
571 \begin{funcdesc}{Solution}{domain}
572 returns the \SolutionFS on the \Domain domain. \Data objects in this type of \Function
573 are defined on geometric region defined by \var{domain} and are solutions of
574 partial differential equations \index{partial differential equation}.
575 \end{funcdesc}
576
577 \begin{funcdesc}{ReducedSolution}{domain}
578 returns the \ReducedSolutionFS on the \Domain domain. \Data objects in this type of \Function
579 are defined on geometric region defined by \var{domain} and are solutions of
580 partial differential equations \index{partial differential equation} with a reduced smoothness
581 for the solution approximation.
582 \end{funcdesc}
583
584 \subsection{\Data Class}
585 \label{SEC ESCRIPT DATA}
586
587 The following table shows arithmetic operations that can be performed point-wise on
588 \Data objects.
589 \begin{table}
590 \centering
591 \begin{tabular}{l|l}
592 \bfseries expression & Description\\
593 \hline
594 +\var{arg0} & identical to \var{arg} \index{+}\\
595 -\var{arg0} & negation\index{-}\\
596 \var{arg0}+\var{arg1} & adds \var{arg0} and \var{arg1} \index{+}\\
597 \var{arg0}*\var{arg1} & multiplies \var{arg0} and \var{arg1} \index{*}\\
598 \var{arg0}-\var{arg1} & difference \var{arg1} from\var{arg1} \index{-}\\
599 \var{arg0}/\var{arg1} & divide \var{arg0} by \var{arg1} \index{/}\\
600 \var{arg0}**\var{arg1} & raises \var{arg0} to the power of \var{arg1} \index{**}\\
601 \end{tabular}
602 \end{table}
603 At least one of the arguments \var{arg0} or \var{arg1} must be a
604 \Data object.
605 Either of the arguments may be a \Data object, a python number or a \numpy object.
606
607 If \var{arg0} or \var{arg1} are
608 not defined on the same \FunctionSpace, then an attempt is made to convert \var{arg0}
609 to the \FunctionSpace of \var{arg1} or to convert \var{arg1} to
610 the \FunctionSpace of \var{arg0}. Both arguments must have the same
611 \Shape or one of the arguments may be of rank 0 (a constant).
612
613 The returned \Data object has the same \Shape and is defined on
614 the \DataSamplePoints as \var{arg0} or \var{arg1}.
615
616 The following table shows the update operations that can be applied to
617 \Data objects:
618 \begin{table}
619 \centering
620 \begin{tabular}{l|l}
621 \bfseries Expression & Description\\
622 \hline
623 \var{arg0}+=\var{arg2} & adds \var{arg0} to \var{arg2}\index{+}\\
624 \var{arg0}*=\var{arg2} & multiplies \var{arg0} with \var{arg2}\index{*}\\
625 \var{arg0}-=\var{arg2} & subtracts \var{arg2} from\var{arg2}\index{-}\\
626 \var{arg0}/=\var{arg2} & divides \var{arg0} by \var{arg2}\index{/}\\
627 \var{arg0}**=\var{arg2} & raises \var{arg0} by \var{arg2}\index{**}\\
628 \end{tabular}
629 \end{table}
630 \var{arg0} must be a \Data object. \var{arg1} must be a
631 \Data object or an object that can be converted into a
632 \Data object. \var{arg1} must have the same \Shape as
633 \var{arg0} or have rank 0. In the latter case it is
634 assumed that the values of \var{arg1} are constant for all
635 components. \var{arg1} must be defined in the same \FunctionSpace as
636 \var{arg0} or it must be possible to interpolate \var{arg1} onto the
637 \FunctionSpace of \var{arg0}.
638
639 The \Data class supports taking slices from a \Data object as well as assigning new values to a slice of an existing
640 \Data object. \index{slicing}
641 The following expressions for taking and setting slices are valid:
642 \begin{table}
643 \centering
644 \begin{tabular}{l|ll}
645 \bfseries rank of \var{arg} & slicing expression & \Shape of returned and assigned object\\
646 \hline
647 0 & no slicing & -\\
648 1 & \var{arg[l0:u0]} & (\var{u0}-\var{l0},)\\
649 2 & \var{arg[l0:u0,l1:u1]} & (\var{u0}-\var{l0},\var{u1}-\var{l1})\\
650 3 & \var{arg[l0:u0,l1:u1,l2:u2]} & (\var{u0}-\var{l0},\var{u1}-\var{l1},\var{u2}-\var{l2})\\
651 4 & \var{arg[l0:u0,l1:u1,l2:u2,l3:u3]} & (\var{u0}-\var{l0},\var{u1}-\var{l1},\var{u2}-\var{l2},\var{u3}-\var{l3})\\
652 \end{tabular}
653 \end{table}
654 where \var{s} is the \Shape of \var{arg} and
655 \[0 \le \var{l0} \le \var{u0} \le \var{s[0]},\]
656 \[0 \le \var{l1} \le \var{u1} \le \var{s[1]},\]
657 \[0 \le \var{l2} \le \var{u2} \le \var{s[2]},\]
658 \[0 \le \var{l3} \le \var{u3} \le \var{s[3]}.\]
659 Any of the lower indexes \var{l0}, \var{l1}, \var{l2} and \var{l3} may not be present in which case
660 $0$ is assumed.
661 Any of the upper indexes \var{u0}, \var{u1}, \var{u2} and \var{u3} may be omitted, in which case, the upper limit for that dimension is assumed.
662 The lower and upper index may be identical, in which case the column and the lower or upper
663 index may be dropped. In the returned or in the object assigned to a slice, the corresponding component is dropped,
664 i.e. the rank is reduced by one in comparison to \var{arg}.
665 The following examples show slicing in action:
666 \begin{python}
667 t=Data(1.,(4,4,6,6),Function(mydomain))
668 t[1,1,1,0]=9.
669 s=t[:2,:,2:6,5] # s has rank 3
670 s[:,:,1]=1.
671 t[:2,:2,5,5]=s[2:4,1,:2]
672 \end{python}
673
674 \subsection{Generation of \Data objects}
675 \begin{classdesc}{Data}{value=0,shape=(,),what=FunctionSpace(),expand=\False}
676 creates a \Data object with \Shape \var{shape} in the \FunctionSpace \var{what}.
677 The values at all \DataSamplePoints are set to the double value \var{value}. If \var{expanded} is \True
678 the \Data object is represented in expanded from.
679 \end{classdesc}
680
681 \begin{classdesc}{Data}{value,what=FunctionSpace(),expand=\False}
682 creates a \Data object in the \FunctionSpace \var{what}.
683 The value for each \DataSamplePoints is set to \var{value}, which could be a \numpy, \Data object \var{value} or a dictionary of
684 \numpy or floating point numbers. In the latter case the keys must be integers and are used
685 as tags.
686 The \Shape of the returned object is equal to the \Shape of \var{value}. If \var{expanded} is \True
687 the \Data object is represented in expanded form.
688 \end{classdesc}
689
690 \begin{classdesc}{Data}{}
691 creates an \EmptyData object. The \EmptyData object is used to indicate that an argument is not present
692 where a \Data object is required.
693 \end{classdesc}
694
695 \begin{funcdesc}{Scalar}{value=0.,what=FunctionSpace(),expand=\False}
696 returns a \Data object of rank 0 (a constant) in the \FunctionSpace \var{what}.
697 Values are initialized with \var{value}, a double precision quantity. If \var{expanded} is \True
698 the \Data object is represented in expanded from.
699 \end{funcdesc}
700
701 \begin{funcdesc}{Vector}{value=0.,what=FunctionSpace(),expand=\False}
702 returns a \Data object of \Shape \var{(d,)} in the \FunctionSpace \var{what},
703 where \var{d} is the spatial dimension of the \Domain of \var{what}.
704 Values are initialed with \var{value}, a double precision quantity. If \var{expanded} is \True
705 the \Data object is represented in expanded from.
706 \end{funcdesc}
707
708 \begin{funcdesc}{Tensor}{value=0.,what=FunctionSpace(),expand=\False}
709 returns a \Data object of \Shape \var{(d,d)} in the \FunctionSpace \var{what},
710 where \var{d} is the spatial dimension of the \Domain of \var{what}.
711 Values are initialed with \var{value}, a double precision quantity. If \var{expanded} is \True
712 the \Data object is represented in expanded from.
713 \end{funcdesc}
714
715 \begin{funcdesc}{Tensor3}{value=0.,what=FunctionSpace(),expand=\False}
716 returns a \Data object of \Shape \var{(d,d,d)} in the \FunctionSpace \var{what},
717 where \var{d} is the spatial dimension of the \Domain of \var{what}.
718 Values are initialed with \var{value}, a double precision quantity. If \var{expanded} is \True
719 the \Data object is re\var{arg}presented in expanded from.
720 \end{funcdesc}
721
722 \begin{funcdesc}{Tensor4}{value=0.,what=FunctionSpace(),expand=\False}
723 returns a \Data object of \Shape \var{(d,d,d,d)} in the \FunctionSpace \var{what},
724 where \var{d} is the spatial dimension of the \Domain of \var{what}.
725 Values are initialized with \var{value}, a double precision quantity. If \var{expanded} is \True
726 the \Data object is represented in expanded from.
727 \end{funcdesc}
728
729 \begin{funcdesc}{load}{filename,domain}
730 recovers a \Data object on \Domain \var{domain} from the file \var{filename}, which was created by \function{dump}.
731 \end{funcdesc}
732
733 \subsection{\Data methods}
734 These are the most frequently-used methods of the
735 \Data class. A complete list of methods can be found on \ReferenceGuide.
736 \begin{methoddesc}[Data]{getFunctionSpace}{}
737 returns the \FunctionSpace of the object.
738 \end{methoddesc}
739
740 \begin{methoddesc}[Data]{getDomain}{}
741 returns the \Domain of the object.
742 \end{methoddesc}
743
744 \begin{methoddesc}[Data]{getShape}{}
745 returns the \Shape of the object as a \class{tuple} of
746 integers.
747 \end{methoddesc}
748
749 \begin{methoddesc}[Data]{getRank}{}
750 returns the rank of the data on each data point. \index{rank}
751 \end{methoddesc}
752
753 \begin{methoddesc}[Data]{isEmpty}{}
754 returns \True id the \Data object is the \EmptyData object.
755 Otherwise \False is returned.
756 Note that this is not the same as asking if the object contains no \DataSamplePoints.
757 \end{methoddesc}
758
759 \begin{methoddesc}[Data]{setTaggedValue}{tag_name,value}
760 assigns the \var{value} to all \DataSamplePoints which have the tag
761 assigned to \var{tag_name}. \var{value} must be an object of class
762 \class{numpy.ndarray} or must be convertible into a
763 \class{numpy.ndarray} object. \var{value} (or the corresponding
764 \class{numpy.ndarray} object) must be of rank $0$ or must have the
765 same rank like the object.
766 If a value has already be defined for tag \var{tag_name} within the object
767 it is overwritten by the new \var{value}. If the object is expanded,
768 the value assigned to \DataSamplePoints with tag \var{tag_name} is replaced by
769 \var{value}. If no tag is assigned tag name \var{tag_name}, no value is set.
770 \end{methoddesc}
771
772 \begin{methoddesc}[Data]{dump}{filename}
773 dumps the \Data object to the file \var{filename}. The file stores the
774 function space but not the \Domain. It is in the responsibility of the user to
775 save the \Domain.
776 \end{methoddesc}
777
778 \begin{methoddesc}[Data]{__str__}{}
779 returns a string representation of the object.
780 \end{methoddesc}
781
782 \subsection{Functions of \Data objects}
783 This section lists the most important functions for \Data class objects \var{a}.
784 A complete list and a more detailed description of the functionality can be found on \ReferenceGuide.
785 \begin{funcdesc}{saveVTK}{filename,**kwdata}
786 writes \Data defined by keywords in the file with \var{filename} using the
787 vtk file format \VTK file format. The key word is used as an identifier. The statement
788 \begin{python}
789 saveVTK("out.xml",temperature=T,velocity=v)
790 \end{python}
791 will write the scalar \var{T} as \var{temperature} and the vector \var{v} as \var{velocity} into the
792 file \file{out.xml}. Restrictions on the allowed combinations of \FunctionSpace apply.
793 \end{funcdesc}
794 \begin{funcdesc}{saveDX}{filename,**kwdata}
795 writes \Data defined by keywords in the file with \var{filename} using the
796 vtk file format \OpenDX file format. The key word is used as an identifier. The statement
797 \begin{python}
798 saveDX("out.dx",temperature=T,velocity=v)
799 \end{python}
800 will write the scalar \var{T} as \var{temperature} and the vector \var{v} as \var{velocity} into the
801 file \file{out.dx}. Restrictions on the allowed combinations of \FunctionSpace apply.
802 \end{funcdesc}
803 \begin{funcdesc}{kronecker}{d}
804 returns a \RankTwo \Data object in \FunctionSpace \var{d} such that
805 \begin{equation}
806 \code{kronecker(d)}\left[ i,j\right] = \left\{
807 \begin{array}{cc}
808 1 & \mbox{ if } i=j \\
809 0 & \mbox{ otherwise }
810 \end{array}
811 \right.
812 \end{equation}
813 If \var{d} is an integer a $(d,d)$ \numpy array is returned.
814 \end{funcdesc}
815 \begin{funcdesc}{identityTensor}{d}
816 is a synonym for \code{kronecker} (see above).
817 % returns a \RankTwo \Data object in \FunctionSpace \var{d} such that
818 % \begin{equation}
819 % \code{identityTensor(d)}\left[ i,j\right] = \left\{
820 % \begin{array}{cc}
821 % 1 & \mbox{ if } i=j \\
822 % 0 & \mbox{ otherwise }
823 % \end{array}
824 % \right.
825 % \end{equation}
826 % If \var{d} is an integer a $(d,d)$ \numpy array is returned.
827 \end{funcdesc}
828 \begin{funcdesc}{identityTensor4}{d}
829 returns a \RankFour \Data object in \FunctionSpace \var{d} such that
830 \begin{equation}
831 \code{identityTensor(d)}\left[ i,j,k,l\right] = \left\{
832 \begin{array}{cc}
833 1 & \mbox{ if } i=k \mbox{ and } j=l\\
834 0 & \mbox{ otherwise }
835 \end{array}
836 \right.
837 \end{equation}
838 If \var{d} is an integer a $(d,d,d,d)$ \numpy array is returned.
839 \end{funcdesc}
840 \begin{funcdesc}{unitVector}{i,d}
841 returns a \RankOne \Data object in \FunctionSpace \var{d} such that
842 \begin{equation}
843 \code{identityTensor(d)}\left[ j \right] = \left\{
844 \begin{array}{cc}
845 1 & \mbox{ if } j=i\\
846 0 & \mbox{ otherwise }
847 \end{array}
848 \right.
849 \end{equation}
850 If \var{d} is an integer a $(d,)$ \numpy array is returned.
851
852 \end{funcdesc}
853
854 \begin{funcdesc}{Lsup}{a}
855 returns the $L^{sup}$ norm of \var{arg}. This is the maximum of the absolute values
856 over all components and all \DataSamplePoints of \var{a}.
857 \end{funcdesc}
858
859 \begin{funcdesc}{sup}{a}
860 returns the maximum value over all components and all \DataSamplePoints of \var{a}.
861 \end{funcdesc}
862
863 \begin{funcdesc}{inf}{a}
864 returns the minimum value over all components and all \DataSamplePoints of \var{a}
865 \end{funcdesc}
866
867
868
869 \begin{funcdesc}{minval}{a}
870 returns at each \DataSamplePoints the minimum value over all components.
871 \end{funcdesc}
872
873 \begin{funcdesc}{maxval}{a}
874 returns at each \DataSamplePoints the maximum value over all components.
875 \end{funcdesc}
876
877 \begin{funcdesc}{length}{a}
878 returns at Euclidean norm at each \DataSamplePoints. For a \RankFour \var{a} this is
879 \begin{equation}
880 \code{length(a)}=\sqrt{\sum\hackscore{ijkl} \var{a} \left[i,j,k,l\right]^2}
881 \end{equation}
882 \end{funcdesc}
883 \begin{funcdesc}{trace}{a\optional{,axis_offset=0}}
884 returns the trace of \var{a}. This is the sum over components \var{axis_offset} and \var{axis_offset+1} with the same index. For instance in the
885 case of a \RankTwo function and this is
886 \begin{equation}
887 \code{trace(a)}=\sum\hackscore{i} \var{a} \left[i,i\right]
888 \end{equation}
889 and for a \RankFour function and \code{axis_offset=1} this is
890 \begin{equation}
891 \code{trace(a,1)}\left[i,j\right]=\sum\hackscore{k} \var{a} \left[i,k,k,j\right]
892 \end{equation}
893 \end{funcdesc}
894
895 \begin{funcdesc}{transpose}{a\optional{, axis_offset=None}}
896 returns the transpose of \var{a}. This swaps the first \var{axis_offset} components of \var{a} with the rest. If \var{axis_offset} is not
897 present \code{int(r/2)} is used where \var{r} is the rank of \var{a}.
898 the sum over components \var{axis_offset} and \var{axis_offset+1} with the same index. For instance in the
899 case of a \RankTwo function and this is
900 \begin{equation}
901 \code{transpose(a)}\left[i,j\right]=\var{a} \left[j,i\right]
902 \end{equation}
903 and for a \RankFour function and \code{axis_offset=1} this is
904 \begin{equation}
905 \code{transpose(a,1)}\left[i,j,k,l\right]=\var{a} \left[j,k,l,i\right]
906 \end{equation}
907 \end{funcdesc}
908
909 \begin{funcdesc}{swap_axes}{a\optional{, axis0=0 \optional{, axis1=1 }}}
910 returns \var{a} but with swapped components \var{axis0} and \var{axis1}. The argument \var{a} must be
911 at least of \RankTwo. For instance in the
912 for a \RankFour argument, \code{axis0=1} and \code{axis1=2} this is
913 \begin{equation}
914 \code{swap_axes(a,1,2)}\left[i,j,k,l\right]=\var{a} \left[i,k,j,l\right]
915 \end{equation}
916 \end{funcdesc}
917
918 \begin{funcdesc}{symmetric}{a}
919 returns the symmetric part of \var{a}. This is \code{(a+transpose(a))/2}.
920 \end{funcdesc}
921 \begin{funcdesc}{nonsymmetric}{a}
922 returns the non--symmetric part of \var{a}. This is \code{(a-transpose(a))/2}.
923 \end{funcdesc}
924 \begin{funcdesc}{inverse}{a}
925 return the inverse of \var{a}. This is
926 \begin{equation}
927 \code{matrix_mult(inverse(a),a)=kronecker(d)}
928 \end{equation}
929 if \var{a} has shape \code{(d,d)}. The current implementation is restricted to arguments of shape
930 \code{(2,2)} and \code{(3,3)}.
931 \end{funcdesc}
932 \begin{funcdesc}{eigenvalues}{a}
933 return the eigenvalues of \var{a}. This is
934 \begin{equation}
935 \code{matrix_mult(a,V)=e[i]*V}
936 \end{equation}
937 where \code{e=eigenvalues(a)} and \var{V} is suitable non--zero vector \var{V}.
938 The eigenvalues are ordered in increasing size.
939 The argument \var{a} has to be the symmetric, ie. \code{a=symmetric(a)}.
940 The current implementation is restricted to arguments of shape
941 \code{(2,2)} and \code{(3,3)}.
942 \end{funcdesc}
943 \begin{funcdesc}{eigenvalues_and_eigenvectors}{a}
944 return the eigenvalues and eigenvectors of \var{a}. This is
945 \begin{equation}
946 \code{matrix_mult(a,V[:,i])=e[i]*V[:,i]}
947 \end{equation}
948 where \code{e,V=eigenvalues_and_eigenvectors(a)}. The eigenvectors \var{V} are orthogonal and normalized, ie.
949 \begin{equation}
950 \code{matrix_mult(transpose(V),V)=kronecker(d)}
951 \end{equation}
952 if \var{a} has shape \code{(d,d)}. The eigenvalues are ordered in increasing size.
953 The argument \var{a} has to be the symmetric, ie. \code{a=symmetric(a)}.
954 The current implementation is restricted to arguments of shape
955 \code{(2,2)} and \code{(3,3)}.
956 \end{funcdesc}
957 \begin{funcdesc}{maximum}{*a}
958 returns the maximum value over all arguments at all \DataSamplePoints and for each component.
959 For instance
960 \begin{equation}
961 \code{maximum(a0,a1)}\left[i,j\right]=max(\var{a0} \left[i,j\right],\var{a1} \left[i,j\right])
962 \end{equation}
963 at all \DataSamplePoints.
964 \end{funcdesc}
965 \begin{funcdesc}{minimum}{*a}
966 returns the minimum value over all arguments at all \DataSamplePoints and for each component.
967 For instance
968 \begin{equation}
969 \code{minimum(a0,a1)}\left[i,j\right]=min(\var{a0} \left[i,j\right],\var{a1} \left[i,j\right])
970 \end{equation}
971 at all \DataSamplePoints.
972 \end{funcdesc}
973
974 \begin{funcdesc}{clip}{a\optional{, minval=0.}\optional{, maxval=1.}}
975 cuts back \var{a} into the range between \var{minval} and \var{maxval}. A value in the returned object equals
976 \var{minval} if the corresponding value of \var{a} is less than \var{minval}, equals \var{maxval} if the
977 corresponding value of \var{a} is greater than \var{maxval}
978 or corresponding value of \var{a} otherwise.
979 \end{funcdesc}
980 \begin{funcdesc}{inner}{a0,a1}
981 returns the inner product of \var{a0} and \var{a1}. For instance in the
982 case of \RankTwo arguments and this is
983 \begin{equation}
984 \code{inner(a)}=\sum\hackscore{ij}\var{a0} \left[j,i\right] \cdot \var{a1} \left[j,i\right]
985 \end{equation}
986 and for a \RankFour arguments this is
987 \begin{equation}
988 \code{inner(a)}=\sum\hackscore{ijkl}\var{a0} \left[i,j,k,l\right] \cdot \var{a1} \left[j,i,k,l\right]
989 \end{equation}
990 \end{funcdesc}
991
992 \begin{funcdesc}{matrix_mult}{a0,a1}
993 returns the matrix product of \var{a0} and \var{a1}. If \var{a1} is \RankOne this is
994 \begin{equation}
995 \code{matrix_mult(a)}\left[i\right]=\sum\hackscore{k}\var{a0} \cdot \left[i,k\right]\var{a1} \left[k\right]
996 \end{equation}
997 and if \var{a1} is \RankTwo this is
998 \begin{equation}
999 \code{matrix_mult(a)}\left[i,j\right]=\sum\hackscore{k}\var{a0} \cdot \left[i,k\right]\var{a1} \left[k,j\right]
1000 \end{equation}
1001 \end{funcdesc}
1002
1003 \begin{funcdesc}{transposed_matrix_mult}{a0,a1}
1004 returns the matrix product of the transposed of \var{a0} and \var{a1}. The function is equivalent to
1005 \code{matrix_mult(transpose(a0),a1)}.
1006 If \var{a1} is \RankOne this is
1007 \begin{equation}
1008 \code{transposed_matrix_mult(a)}\left[i\right]=\sum\hackscore{k}\var{a0} \cdot \left[k,i\right]\var{a1} \left[k\right]
1009 \end{equation}
1010 and if \var{a1} is \RankTwo this is
1011 \begin{equation}
1012 \code{transposed_matrix_mult(a)}\left[i,j\right]=\sum\hackscore{k}\var{a0} \cdot \left[k,i\right]\var{a1} \left[k,j\right]
1013 \end{equation}
1014 \end{funcdesc}
1015
1016 \begin{funcdesc}{matrix_transposed_mult}{a0,a1}
1017 returns the matrix product of \var{a0} and the transposed of \var{a1}.
1018 The function is equivalent to
1019 \code{matrix_mult(a0,transpose(a1))}.
1020 If \var{a1} is \RankTwo this is
1021 \begin{equation}
1022 \code{matrix_transposed_mult(a)}\left[i,j\right]=\sum\hackscore{k}\var{a0} \cdot \left[i,k\right]\var{a1} \left[j,k\right]
1023 \end{equation}
1024 \end{funcdesc}
1025
1026 \begin{funcdesc}{outer}{a0,a1}
1027 returns the outer product of \var{a0} and \var{a1}. For instance if \var{a0} and \var{a1} both are \RankOne then
1028 \begin{equation}
1029 \code{outer(a)}\left[i,j\right]=\var{a0} \left[i\right] \cdot \var{a1}\left[j\right]
1030 \end{equation}
1031 and if \var{a0} is \RankOne and \var{a1} is \RankThree
1032 \begin{equation}
1033 \code{outer(a)}\left[i,j,k\right]=\var{a0} \left[i\right] \cdot \var{a1}\left[j,k\right]
1034 \end{equation}
1035 \end{funcdesc}
1036
1037 \begin{funcdesc}{tensor_mult}{a0,a1}
1038 returns the tensor product of \var{a0} and \var{a1}. If \var{a1} is \RankTwo this is
1039 \begin{equation}
1040 \code{tensor_mult(a)}\left[i,j\right]=\sum\hackscore{kl}\var{a0}\left[i,j,k,l\right] \cdot \var{a1} \left[k,l\right]
1041 \end{equation}
1042 and if \var{a1} is \RankFour this is
1043 \begin{equation}
1044 \code{tensor_mult(a)}\left[i,j,k,l\right]=\sum\hackscore{mn}\var{a0} \left[i,j,m,n\right] \cdot \var{a1} \left[m,n,k,l\right]
1045 \end{equation}
1046 \end{funcdesc}
1047
1048 \begin{funcdesc}{transposed_tensor_mult}{a0,a1}
1049 returns the tensor product of the transposed of \var{a0} and \var{a1}. The function is equivalent to
1050 \code{tensor_mult(transpose(a0),a1)}.
1051 If \var{a1} is \RankTwo this is
1052 \begin{equation}
1053 \code{transposed_tensor_mult(a)}\left[i,j\right]=\sum\hackscore{kl}\var{a0}\left[k,l,i,j\right] \cdot \var{a1} \left[k,l\right]
1054 \end{equation}
1055 and if \var{a1} is \RankFour this is
1056 \begin{equation}
1057 \code{transposed_tensor_mult(a)}\left[i,j,k,l\right]=\sum\hackscore{mn}\var{a0} \left[m,n,i,j\right] \cdot \var{a1} \left[m,n,k,l\right]
1058 \end{equation}
1059 \end{funcdesc}
1060
1061 \begin{funcdesc}{tensor_transposed_mult}{a0,a1}
1062 returns the tensor product of \var{a0} and the transposed of \var{a1}.
1063 The function is equivalent to
1064 \code{tensor_mult(a0,transpose(a1))}.
1065 If \var{a1} is \RankTwo this is
1066 \begin{equation}
1067 \code{tensor_transposed_mult(a)}\left[i,j\right]=\sum\hackscore{kl}\var{a0}\left[i,j,k,l\right] \cdot \var{a1} \left[l,k\right]
1068 \end{equation}
1069 and if \var{a1} is \RankFour this is
1070 \begin{equation}
1071 \code{tensor_transposed_mult(a)}\left[i,j,k,l\right]=\sum\hackscore{mn}\var{a0} \left[i,j,m,n\right] \cdot \var{a1} \left[k,l,m,n\right]
1072 \end{equation}
1073 \end{funcdesc}
1074
1075 \begin{funcdesc}{grad}{a\optional{, where=None}}
1076 returns the gradient of \var{a}. If \var{where} is present the gradient will be calculated in \FunctionSpace \var{where} otherwise a
1077 default \FunctionSpace is used. In case that \var{a} has \RankTwo one has
1078 \begin{equation}
1079 \code{grad(a)}\left[i,j,k\right]=\frac{\partial \var{a} \left[i,j\right]}{\partial x\hackscore{k}}
1080 \end{equation}
1081 \end{funcdesc}
1082 \begin{funcdesc}{integrate}{a\optional{ ,where=None}}
1083 returns the integral of \var{a} where the domain of integration is defined by the \FunctionSpace of \var{a}. If \var{where} is
1084 present the argument is interpolated into \FunctionSpace \var{where} before integration. For instance in the case of
1085 a \RankTwo argument in \ContinuousFunction it is
1086 \begin{equation}
1087 \code{integrate(a)}\left[i,j\right]=\int\hackscore{\Omega}\var{a} \left[i,j\right] \; d\Omega
1088 \end{equation}
1089 where $\Omega$ is the spatial domain and $d\Omega$ volume integration. To integrate over the boundary of the domain one uses
1090 \begin{equation}
1091 \code{integrate(a,where=FunctionOnBoundary(a.getDomain))}\left[i,j\right]=\int\hackscore{\partial \Omega} a\left[i,j\right] \; ds
1092 \end{equation}
1093 where $\partial \Omega$ is the surface of the spatial domain and $ds$ area or line integration.
1094 \end{funcdesc}
1095 \begin{funcdesc}{interpolate}{a,where}
1096 interpolates argument \var{a} into the \FunctionSpace \var{where}.
1097 \end{funcdesc}
1098 \begin{funcdesc}{div}{a\optional{ ,where=None}}
1099 returns the divergence of \var{a}. This
1100 \begin{equation}
1101 \code{div(a)}=trace(grad(a),where)
1102 \end{equation}
1103 \end{funcdesc}
1104 \begin{funcdesc}{jump}{a\optional{ ,domain=None}}
1105 returns the jump of \var{a} over the discontinuity in its domain or if \Domain \var{domain} is present
1106 in \var{domain}.
1107 \begin{equation}
1108 \begin{array}{rcl}
1109 \code{jump(a)}& = &\code{interpolate(a,FunctionOnContactOne(domain))} \\
1110 & & \hfill - \code{interpolate(a,FunctionOnContactZero(domain))}
1111 \end{array}
1112 \end{equation}
1113 \end{funcdesc}
1114 \begin{funcdesc}{L2}{a}
1115 returns the $L^2$-norm of \var{a} in its function space. This is
1116 \begin{equation}
1117 \code{L2(a)=integrate(length(a)}^2\code{)} \; .
1118 \end{equation}
1119 \end{funcdesc}
1120
1121 The following functions operate ``point-wise''. That is, the operation is applied to each component of each point
1122 individually.
1123
1124 \begin{funcdesc}{sin}{a}
1125 applies sine function to \var{a}.
1126 \end{funcdesc}
1127
1128 \begin{funcdesc}{cos}{a}
1129 applies cosine function to \var{a}.
1130 \end{funcdesc}
1131
1132 \begin{funcdesc}{tan}{a}
1133 applies tangent function to \var{a}.
1134 \end{funcdesc}
1135
1136 \begin{funcdesc}{asin}{a}
1137 applies arc (inverse) sine function to \var{a}.
1138 \end{funcdesc}
1139
1140 \begin{funcdesc}{acos}{a}
1141 applies arc (inverse) cosine function to \var{a}.
1142 \end{funcdesc}
1143
1144 \begin{funcdesc}{atan}{a}
1145 applies arc (inverse) tangent function to \var{a}.
1146 \end{funcdesc}
1147
1148 \begin{funcdesc}{sinh}{a}
1149 applies hyperbolic sine function to \var{a}.
1150 \end{funcdesc}
1151
1152 \begin{funcdesc}{cosh}{a}
1153 applies hyperbolic cosine function to \var{a}.
1154 \end{funcdesc}
1155
1156 \begin{funcdesc}{tanh}{a}
1157 applies hyperbolic tangent function to \var{a}.
1158 \end{funcdesc}
1159
1160 \begin{funcdesc}{asinh}{a}
1161 applies arc (inverse) hyperbolic sine function to \var{a}.
1162 \end{funcdesc}
1163
1164 \begin{funcdesc}{acosh}{a}
1165 applies arc (inverse) hyperbolic cosine function to \var{a}.
1166 \end{funcdesc}
1167
1168 \begin{funcdesc}{atanh}{a}
1169 applies arc (inverse) hyperbolic tangent function to \var{a}.
1170 \end{funcdesc}
1171
1172 \begin{funcdesc}{exp}{a}
1173 applies exponential function to \var{a}.
1174 \end{funcdesc}
1175
1176 \begin{funcdesc}{sqrt}{a}
1177 applies square root function to \var{a}.
1178 \end{funcdesc}
1179
1180 \begin{funcdesc}{log}{a}
1181 applies the natural logarithm to \var{a}.
1182 \end{funcdesc}
1183
1184 \begin{funcdesc}{log10}{a}
1185 applies the base-$10$ logarithm to \var{a}.
1186 \end{funcdesc}
1187
1188 \begin{funcdesc}{sign}{a}
1189 applies the sign function to \var{a}, that is $1$ where \var{a} is positive,
1190 $-1$ where \var{a} is negative and $0$ otherwise.
1191 \end{funcdesc}
1192
1193 \begin{funcdesc}{wherePositive}{a}
1194 returns a function which is $1$ where \var{a} is positive and $0$ otherwise.
1195 \end{funcdesc}
1196
1197 \begin{funcdesc}{whereNegative}{a}
1198 returns a function which is $1$ where \var{a} is negative and $0$ otherwise.
1199 \end{funcdesc}
1200
1201 \begin{funcdesc}{whereNonNegative}{a}
1202 returns a function which is $1$ where \var{a} is non--negative and $0$ otherwise.
1203 \end{funcdesc}
1204
1205 \begin{funcdesc}{whereNonPositive}{a}
1206 returns a function which is $1$ where \var{a} is non--positive and $0$ otherwise.
1207 \end{funcdesc}
1208
1209 \begin{funcdesc}{whereZero}{a\optional{, tol=None, \optional{, rtol=1.e-8}}}
1210 returns a function which is $1$ where \var{a} equals zero with tolerance \var{tol} and $0$ otherwise. If \var{tol} is not present, the absolute maximum value of C{a} times C{rtol} is used.
1211 \end{funcdesc}
1212
1213 \begin{funcdesc}{whereNonZero}{a, \optional{, tol=None, \optional{, rtol=1.e-8}}}
1214 returns a function which is $1$ where \var{a} different from zero with tolerance \var{tol} and $0$ otherwise. If \var{tol} is not present, the absolute maximum value of C{a} times C{rtol} is used.
1215 \end{funcdesc}
1216
1217 \subsection{Interpolating Data}
1218 \index{interpolateTable}
1219 In some cases, it may be useful to produce Data objects which fit some user defined function.
1220 Manually modifying each value in the Data object is not a good idea since it depends on
1221 knowing the location and order of each datapoint in the domain.
1222 Instead \escript can use an interpolation table to produce a Data object.
1223
1224 The following example is available as \file{int_save.py} in the examples directory.
1225 We will produce a \Data object which aproximates a sine curve.
1226
1227 \begin{python}
1228 from esys.escript import saveDataCSV, sup
1229 import numpy
1230 from esys.finley import Rectangle
1231
1232 n=4
1233 r=Rectangle(n,n)
1234 x=r.getX()
1235 x0=x[0]
1236 x1=x[1] #we'll use this later
1237 toobig=100
1238 \end{python}
1239
1240 First we produce an interpolation table.
1241 \begin{python}
1242 sine_table=[0, 0.70710678118654746, 1, 0.70710678118654746, 0,
1243 -0.70710678118654746, -1, -0.70710678118654746, 0]
1244 \end{python}
1245
1246 We wish to identify $0$ and $1$ with the ends of the curve.
1247 That is, with the first and eighth values in the table.
1248
1249 \begin{python}
1250 numslices=len(sine_table)-1
1251
1252 minval=0
1253 maxval=1
1254
1255 step=sup(maxval-minval)/numslices
1256 \end{python}
1257
1258 So the values $v$ from the input lie in the interval minval$\leq v < $maxval.
1259 \var{step} represents the gap (in the input range) between entries in the table.
1260 By default values of $v$ outside the table argument range (minval, maxval) will
1261 be pushed back into the range, ie. if $v <$ minval the value minval will be used to
1262 evaluate the table. Similarly, for values $v>$ maxval the value maxval is used.
1263
1264 Now we produce our new \Data object.
1265
1266 \begin{python}
1267 result=x0.interpolateTable(sine_table, minval, step, toobig)
1268 \end{python}
1269 Any values which interpolate to larger than \var{toobig} will raise an exception. You can
1270 switch on boundary checking by adding ''check_boundaries=True`` the argument list.
1271
1272
1273 Now for a 2D example.
1274 We will interpolate a surface such that the bottom edge is the sine curve described above.
1275 The amplitude of the curve decreases as we move towards the top edge.
1276
1277 Our interpolation table will have three rows.
1278 \begin{python}
1279 st=numpy.array(sine_table)
1280
1281 table=[st, 0.5*st, 0*st ]
1282 \end{python}
1283
1284 The use of numpy and multiplication here is just to save typing.
1285
1286 \begin{python}
1287 result2=x1.interpolateTable(table, 0, 0.55, x0, minval, step, toobig)
1288 \end{python}
1289
1290 In the 2D case, the parameters for the x1 direction (min=0, step=0.55) come first followed by the x0 data object and
1291 its parameters.
1292 By default, if a point is specified which is outside the boundary, then \var{interpolateTable} will operate
1293 as if the point was on the boundary.
1294 Passing \var{check_boundaries}=\var{True} will \var{interpolateTable} to reject any points outside the boundaries.
1295
1296 \subsection{Saving Data as CSV}
1297 \index{saveDataCSV}
1298 \index{CSV}
1299 For simple post-processing, \Data objects can be saved in comma separated value format.
1300
1301 If \var{mydata1} and \var{mydata2} are scalar data, the following command:
1302 \begin{python}
1303 saveDataCSV('output.csv',U=mydata1, V=mydata2)
1304 \end{python}
1305 will record the values of mydata in \texttt{output.csv} in the following format:
1306 \begin{verbatim}
1307 U, V
1308 1.0000000e+0, 2.0000000e-1
1309 5.0000000e-0, 1.0000000e+1
1310 ...
1311 \end{verbatim}
1312
1313 The names of the keyword parameters form the names of columns in the output.
1314 If the data objects are over different function spaces, then saveDataCSV will attempt to
1315 interpolate to a common function space.
1316 If this is not possible, then an exception will be raised.
1317
1318 Output can be restricted using a scalar mask.
1319 \begin{python}
1320 saveDataCSV('outfile.csv', U=mydata1, V=mydata2, mask=myscalar)
1321 \end{python}
1322 Will only output those rows which correspond to to positive values of \var{myscalar}.
1323 Some aspects of the output can be tuned using additional parameters.
1324 \begin{python}
1325 saveDataCSV('data.csv', append=True, sep=' ', csep='/', mask=mymask, e=mat1)
1326 \end{python}
1327
1328 \begin{itemize}
1329 \item \var{append} - specifies that the output should be written to the end of an existing file.
1330 \item \var{sep} - defines the separator between fields.
1331 \item \var{csep} - defines the separator between components in the header line. For example between the components of a matrix.
1332 \end{itemize}
1333
1334 The above command would produce output like this:
1335 \begin{verbatim}
1336 e/0/0 e/1/0 e/0/1 e/1/1
1337 1.0000000000e+00 2.0000000000e+00 3.0000000000e+00 4.0000000000e+00
1338 ...
1339 \end{verbatim}
1340
1341 Note that while the order in which rows are output can vary, all the elements in a given row
1342 always correspond to the same input.
1343
1344
1345 \subsection{\Operator Class}
1346 The \Operator class provides an abstract access to operators build
1347 within the \LinearPDE class. \Operator objects are created
1348 when a PDE is handed over to a PDE solver library and handled
1349 by the \LinearPDE object defining the PDE. The user can gain access
1350 to the \Operator of a \LinearPDE object through the \var{getOperator}
1351 method.
1352
1353 \begin{classdesc}{Operator}{}
1354 creates an empty \Operator object.
1355 \end{classdesc}
1356
1357 \begin{methoddesc}[Operator]{isEmpty}{fileName}
1358 returns \True is the object is empty. Otherwise \True is returned.
1359 \end{methoddesc}
1360
1361 \begin{methoddesc}[Operator]{setValue}{value}
1362 resets all entries in the object representation to \var{value}
1363 \end{methoddesc}
1364
1365 \begin{methoddesc}[Operator]{solves}{rhs}
1366 solves the operator equation with right hand side \var{rhs}
1367 \end{methoddesc}
1368
1369 \begin{methoddesc}[Operator]{of}{u}
1370 applies the operator to the \Data object \var{u}
1371 \end{methoddesc}
1372
1373 \begin{methoddesc}[Operator]{saveMM}{fileName}
1374 saves the object to a matrix market format file of name
1375 \var{fileName}, see
1376 \url{http://maths.nist.gov/MatrixMarket}
1377 % \ulink{maths.nist.gov/MatrixMarket}{\url{http://maths.nist.gov/MatrixMarket}}.
1378 \index{Matrix Market}
1379 \end{methoddesc}
1380
1381 \section{Physical Units}
1382 \escript provides support for physical units in the SI system \index{SI units} including unit conversion. So the
1383 user can define variables in the form
1384 \begin{python}
1385 from esys.escript.unitsSI import *
1386 l=20*m
1387 w=30*kg
1388 w2=40*lb
1389 T=100*Celsius
1390 \end{python}
1391 In the two latter cases an conversion from pounds\index{pounds} and degree Celsius\index{Celsius} is performed into the appropriate SI units kg and Kelvin is performed. In addition
1392 composed units can be used, for instance
1393 \begin{python}
1394 from esys.escript.unitsSI import *
1395 rho=40*lb/cm**3
1396 \end{python}
1397 to define the density in the units of pounds per cubic centimeter. The value $40$ will be converted
1398 into SI units, in this case kg per cubic meter.
1399 Moreover unit prefixes are supported:
1400 \begin{python}
1401 from esys.escript.unitsSI import *
1402 p=40*Mega*Pa
1403 \end{python}
1404 to the the pressure to 40 Mega Pascal. Units can also be converted back from the SI system into
1405 a desired unit, e.g
1406 \begin{python}
1407 from esys.escript.unitsSI import *
1408 print p/atm
1409 \end{python}
1410 can be used print the pressure in units of atmosphere\index{atmosphere}.
1411
1412 This is an incomplete list of supported physical units:
1413
1414 \begin{datadesc}{km}
1415 unit of kilo meter
1416 \end{datadesc}
1417
1418 \begin{datadesc}{m}
1419 unit of meter
1420 \end{datadesc}
1421
1422 \begin{datadesc}{cm}
1423 unit of centi meter
1424 \end{datadesc}
1425
1426 \begin{datadesc}{mm}
1427 unit of milli meter
1428 \end{datadesc}
1429
1430 \begin{datadesc}{sec}
1431 unit of second
1432 \end{datadesc}
1433
1434 \begin{datadesc}{minute}
1435 unit of minute
1436 \end{datadesc}
1437
1438 \begin{datadesc}{h}
1439 unit of hour
1440 \end{datadesc}
1441 \begin{datadesc}{day}
1442 unit of day
1443 \end{datadesc}
1444 \begin{datadesc}{yr}
1445 unit of year
1446 \end{datadesc}
1447
1448 \begin{datadesc}{gram}
1449 unit of gram
1450 \end{datadesc}
1451 \begin{datadesc}{kg}
1452 unit of kilo gram
1453 \end{datadesc}
1454 \begin{datadesc}{lb}
1455 unit of pound
1456 \end{datadesc}
1457 \begin{datadesc}{ton}
1458 metric ton
1459 \end{datadesc}
1460
1461 \begin{datadesc}{A}
1462 unit of Ampere
1463 \end{datadesc}
1464
1465 \begin{datadesc}{Hz}
1466 unit of Hertz
1467 \end{datadesc}
1468
1469 \begin{datadesc}{N}
1470 unit of Newton
1471 \end{datadesc}
1472 \begin{datadesc}{Pa}
1473 unit of Pascal
1474 \end{datadesc}
1475 \begin{datadesc}{atm}
1476 unit of atmosphere
1477 \end{datadesc}
1478 \begin{datadesc}{J}
1479 unit of Joule
1480 \end{datadesc}
1481
1482 \begin{datadesc}{W}
1483 unit of Watt
1484 \end{datadesc}
1485
1486 \begin{datadesc}{C}
1487 unit of Coulomb
1488 \end{datadesc}
1489 \begin{datadesc}{V}
1490 unit of Volt
1491 \end{datadesc}
1492 \begin{datadesc}{F}
1493 unit of Farad
1494 \end{datadesc}
1495
1496 \begin{datadesc}{Ohm}
1497 unit of Ohm
1498 \end{datadesc}
1499 \begin{datadesc}{K}
1500 unit of Kelvin
1501 \end{datadesc}
1502 \begin{datadesc}{Celsius}
1503 unit of Celsius
1504 \end{datadesc}
1505
1506 \begin{datadesc}{Fahrenheit}
1507 unit of Fahrenheit
1508 \end{datadesc}
1509
1510 Moreover unit prefixes are supported:
1511
1512 \begin{datadesc}{Yotta}
1513 prefix yotta = $10^{24}$.
1514
1515 \end{datadesc}
1516
1517 \begin{datadesc}{Zetta}
1518 prefix zetta= $10^{21}$.
1519 \end{datadesc}
1520
1521 \begin{datadesc}{Exa}
1522 prefix exa= $10^{18}$.
1523 \end{datadesc}
1524
1525 \begin{datadesc}{Peta}
1526 prefix peta= $10^{15}$.
1527 \end{datadesc}
1528
1529 \begin{datadesc}{Tera}
1530 prefix tera= $10^{12}$.
1531 \end{datadesc}
1532
1533 \begin{datadesc}{Giga}
1534 prefix giga= $10^9$.
1535 \end{datadesc}
1536
1537 \begin{datadesc}{Mega}
1538 prefix mega= $10^6$.
1539 \end{datadesc}
1540
1541 \begin{datadesc}{Kilo}
1542 prefix kilo= $10^3$.
1543 \end{datadesc}
1544
1545 \begin{datadesc}{Hecto}
1546 prefix hecto= $10^2$.
1547 \end{datadesc}
1548
1549 \begin{datadesc}{Deca}
1550 prefix deca= $10^1$.
1551 \end{datadesc}
1552
1553 \begin{datadesc}{Deci}
1554 prefix deci= $10^{-1}$.
1555 \end{datadesc}
1556
1557 \begin{datadesc}{Centi}
1558 prefix centi= $10^{-2}$.
1559 \end{datadesc}
1560
1561 \begin{datadesc}{Milli}
1562 prefix milli= $10^{-3}$.
1563 \end{datadesc}
1564
1565 \begin{datadesc}{Micro}
1566 prefix micro= $10^{-6}$.
1567 \end{datadesc}
1568
1569 \begin{datadesc}{Nano}
1570 prefix nano= $10^{-9}$.
1571 \end{datadesc}
1572
1573 \begin{datadesc}{Pico}
1574 prefix pico= $10^{-12}$.
1575 \end{datadesc}
1576
1577 \begin{datadesc}{Femto}
1578 prefix femto= $10^{-15}$.
1579 \end{datadesc}
1580
1581 \begin{datadesc}{Atto}
1582 prefix atto= $10^{-18}$.
1583 \end{datadesc}
1584
1585 \begin{datadesc}{Zepto}
1586 prefix zepto= $10^{-21}$.
1587 \end{datadesc}
1588
1589 \begin{datadesc}{Yocto}
1590 prefix yocto= $10^{-24}$.
1591 \end{datadesc}
1592
1593
1594 \section{Utilities}
1595
1596 The \class{FileWriter} provides a mechanism to write data to a file.
1597 In essence, this class wraps the standard \class{file} class to write data
1598 that are global in MPI to a file. In fact, data are written on the processor
1599 with \MPI rank 0 only. It is recommended to use \class{FileWriter}
1600 rather than \class{open} in order to write code that is running
1601 with and without \MPI. It is save to use \class{open} under MPI to read data which are global under \MPI.
1602
1603 \begin{classdesc}{FileWriter}{fn\optional{,append=\False, \optional{createLocalFiles=\False}})}
1604 Opens a file of name \var{fn} for writing. If \var{append} is set to \True
1605 written data are append at the end of the file.
1606 If running under \MPI only the first processor with rank==0
1607 will open the file and write to it.
1608 If \var{createLocalFiles} is set each individual processor will create a file
1609 where for any processor with rank>0 the file name is extended by its rank. This option is normally used for debug purposes only.
1610 \end{classdesc}
1611
1612 The following methods are available:
1613 \begin{methoddesc}[FileWriter]{close}{}
1614 closes the file.
1615 \end{methoddesc}
1616 \begin{methoddesc}[FileWriter]{flush}{}
1617 flushes the internal buffer to disk.
1618 \end{methoddesc}
1619 \begin{methoddesc}[FileWriter]{write}{txt}
1620 Write string \var{txt} to file.
1621 Note that newline is not added.
1622 \end{methoddesc}
1623 \begin{methoddesc}[FileWriter]{writelines}{txts}
1624 Write the list \var{txts} of strings to the file..
1625 Note that newlines are not added.
1626 This method is equivalent to call write() for each string.
1627 \end{methoddesc}
1628 \begin{memberdesc}[FileWriter]{closed}
1629 \True if file is closed.
1630 \end{memberdesc}
1631 \begin{memberdesc}[FileWriter]{mode}
1632 access mode.
1633 \end{memberdesc}
1634 \begin{memberdesc}[FileWriter]{name}
1635 file name.
1636 \end{memberdesc}
1637 \begin{memberdesc}[FileWriter]{newlines}
1638 line separator
1639 \end{memberdesc}
1640
1641
1642 \begin{funcdesc}{setEscriptParamInt}{name,value}
1643 assigns the integer value \var{value} to the parameter \var{name}.
1644 If \var{name}="TOO_MANY_LINES" conversion of any \Data object to a string switches to a
1645 condensed format if more than \var{value} lines would be created.
1646 \end{funcdesc}
1647
1648 \begin{funcdesc}{getEscriptParamInt}{name}
1649 returns the current value of integer parameter \var{name}.
1650 \end{funcdesc}
1651
1652 \begin{funcdesc}{listEscriptParams}{a}
1653 returns a list of valid parameters and their description.
1654 \end{funcdesc}
1655
1656 \begin{funcdesc}{getMPISizeWorld}{}
1657 returns the number of \MPI processors in use in the \env{MPI_COMM_WORLD} processor group.
1658 If \MPI is not used 1 is returned.
1659 \end{funcdesc}
1660 \begin{funcdesc}{getMPIRankWorld}{}
1661 returns the rank of the process within the \env{MPI_COMM_WORLD} processor group.
1662 If \MPI is not used 0 is returned.
1663 \end{funcdesc}
1664 \begin{funcdesc}{MPIBarrierWorld}{}
1665 performs a barrier synchronization across all processors within \env{MPI_COMM_WORLD}
1666 processor group.
1667 \end{funcdesc}
1668 \begin{funcdesc}{getMPIWorldMax}{a}
1669 returns the maximum value of the integer \var{a} across all
1670 processors within \env{MPI_COMM_WORLD}.
1671 \end{funcdesc}
1672

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26