ViewVC logotype

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

Parent Directory Parent Directory | Revision Log Revision Log

Revision 3348 - (show annotations)
Fri Nov 12 05:55:50 2010 UTC (9 years ago) by caltinay
File MIME type: application/x-tex
File size: 72432 byte(s)
Added weipa import statements to the relevant parts in user guide and cookbook.
Documented the deprecation of esys.escript.saveVTK in the changes chapter.

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 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
14 \chapter{The \escript Module}\label{ESCRIPT CHAP}
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.
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.
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}:
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.
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}
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).
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.
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.
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}.
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.
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.
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 an instance of \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.
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))} equals \code{Data(0, Function(myDomain), (d,d))},
168 e.g. a stress field
169 \item \code{Tensor4(0,Function(mydomain))} equals \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.
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.
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_{ij}=\lambda u_{k,k} \delta_{ij} + \mu ( u_{i,j} + u_{j,i})
191 \end{eqnarray}
192 where $\delta_{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.
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}
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.
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.
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.
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 Expanded data is created when specifying \code{expanded=True} in the \Data
290 object constructor, while tagged data requires calling the \member{insertTaggedValue}
291 method as shown above.
293 Values are accessed through a sample reference number.
294 Operations on expanded \Data objects have to be performed for each sample
295 point individually.
296 When tagged values are used, the values are held in a dictionary.
297 Operations on tagged data require processing the set of tagged values only,
298 rather than processing the value for each individual sample point.
299 \escript allows any mixture of constant, tagged and expanded data in a single expression.
301 \subsection{Saving and Restoring Simulation Data}
302 \Data objects can be written to disk files with the \member{dump} method and
303 read back using the \member{load} method, both of which use the
304 \netCDF\cite{NETCDF} file format.
305 Use these to save data for checkpoint/restart or simply to save and reuse data
306 that was expensive to compute.
307 For instance, to save the coordinates of the data points of a
308 \ContinuousFunction to the file \file{x.nc} use
309 \begin{python}
310 x=ContinuousFunction(mydomain).getX()
311 x.dump("x.nc")
312 mydomain.dump("dom.nc")
313 \end{python}
314 To recover the object \var{x}, and you know that \var{mydomain} was an \finley
315 mesh, use
316 \begin{python}
317 from esys.finley import LoadMesh
318 mydomain=LoadMesh("dom.nc")
319 x=load("x.nc", mydomain)
320 \end{python}
321 Obviously, it is possible to execute the same steps that were originally used
322 to generate \var{mydomain} to recreate it. However, in most cases using
323 \member{dump} and \member{load} is faster, particularly if optimization has
324 been applied.
325 If \escript is running on more than one \MPI process \member{dump} will create
326 an individual file for each process containing the local data.
327 In order to avoid conflicts the file names are extended by the \MPI processor
328 rank, that is instead of one file \file{dom.nc} you would get
329 \file{dom.nc.0000}, \file{dom.nc.0001}, etc. You still call
330 \code{LoadMesh("dom.nc")} to load the domain but you have to make sure that
331 the appropriate file is accessible from the corresponding rank, and loading
332 will only succeed if you run with as many processes as were used when calling
333 \member{dump}.
335 The function space of the \Data is stored in \file{x.nc}.
336 If the \Data object is expanded, the number of data points in the file and of
337 the \Domain for the particular \FunctionSpace must match.
338 Moreover, the ordering of the values is checked using the reference
339 identifiers provided by \FunctionSpace on the \Domain.
340 In some cases, data points will be reordered so be aware and confirm that you
341 get what you wanted.
343 A newer, more flexible way of saving and restoring \escript simulation data
344 is through an instance of the \class{DataManager} class.
345 It has the advantage of allowing to save and load not only a \Domain and
346 \Data objects but also other values\footnote{The \PYTHON \emph{pickle} module
347 is used for other types.} you compute in your simulation script.
348 Further, \class{DataManager} objects can simultaneously create files for
349 visualization so no extra calls to \code{saveVTK} etc. are needed.
351 The following example shows how the \class{DataManager} class can be used.
352 For an explanation of all member functions and options see the class reference
353 section \ref{sec:datamanager}.
354 \begin{python}
355 from esys.escript import DataManager, Scalar, Function
356 from esys.finley import Rectangle
358 dm = DataManager(formats=[DataManager.RESTART, DataManager.VTK])
359 if dm.hasData():
360 mydomain=dm.getDomain()
361 val=dm.getValue("val")
362 t=dm.getValue("t")
363 t_max=dm.getValue("t_max")
364 else:
365 mydomain=Rectangle()
366 val=Function(mydomain).getX()
367 t=0.
368 t_max=2.5
370 while t<t_max:
371 t+=.01
372 val=val+t/2
373 dm.addData(val=val, t=t, t_max=t_max)
374 dm.export()
375 \end{python}
376 In the constructor we specify that we want \code{RESTART} (i.e. dump) files
377 and \code{VTK} files to be saved.
378 By default, the constructor will look for previously saved \code{RESTART}
379 files under the current directory and load them.
380 We can then enquire if such files were found by calling the \member{hasData}
381 method. If it returns \True we retrieve the domain and values into local
382 variables. Otherwise the same variables are initialized with appropriate
383 values to start a new simulation.
384 Note, that \var{t} and \var{t_max} are regular floating point values and not
385 \Data objects. Yet they are treated the same way by the \class{DataManager}.
387 After this initialization step the script enters the main simulation loop
388 where calculations are performed.
389 When these are finalized for a time step we call the \member{addData} method
390 to let the manager know which variables to store on disk.
391 This does not actually save the data yet and it is allowed to call
392 \member{addData} more than once to add information incrementally, e.g. from
393 separate functions that have access to the \class{DataManager} instance.
394 Once all variables have been added the \member{export} method has to be called
395 to flush all data to disk and clear the manager.
396 In this example, this call dumps \var{mydomain} and \var{val} to files
397 in a restart directory and also stores \var{t} and \var{t_max} on disk.
398 Additionally, it generates a \VTK file for visualization of the data.
399 If the script would stop running before its completion for some reason (e.g.
400 because its runtime limit was exceeded in a multiuser environment), you could
401 simply run it again and it would resume at the point it stopped before.
403 \section{\escript Classes}
405 \subsection{The \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}
413 \noindent The following methods are available:
414 \begin{methoddesc}[Domain]{getDim}{}
415 returns the spatial dimension of the \Domain.
416 \end{methoddesc}
417 %
418 \begin{methoddesc}[Domain]{dump}{filename}
419 writes the \Domain to the file \var{filename} using the \netCDF file format.
420 \end{methoddesc}
421 %
422 \begin{methoddesc}[Domain]{getX}{}
423 returns the locations in the \Domain. The \FunctionSpace of the returned
424 \Data object is chosen by the \Domain implementation. Typically it will be
425 in the \Function.
426 \end{methoddesc}
427 %
428 \begin{methoddesc}[Domain]{setX}{newX}
429 assigns new locations to the \Domain. \var{newX} has to have \Shape $(d,)$
430 where $d$ is the spatial dimension of the domain. Typically \var{newX}
431 must be in the \ContinuousFunction but the space actually to be used
432 depends on the \Domain implementation.
433 \end{methoddesc}
434 %
435 \begin{methoddesc}[Domain]{getNormal}{}
436 returns the surface normals on the boundary of the \Domain as a \Data object.
437 \end{methoddesc}
438 %
439 \begin{methoddesc}[Domain]{getSize}{}
440 returns the local sample size, i.e. the element diameter, as a \Data object.
441 \end{methoddesc}
442 %
443 \begin{methoddesc}[Domain]{setTagMap}{tag_name, tag}
444 defines a mapping of the tag name \var{tag_name} to the \var{tag}.
445 \end{methoddesc}
446 %
447 \begin{methoddesc}[Domain]{getTag}{tag_name}
448 returns the tag associated with the tag name \var{tag_name}.
449 \end{methoddesc}
450 %
451 \begin{methoddesc}[Domain]{isValidTagName}{tag_name}
452 returns \True if \var{tag_name} is a valid tag name.
453 \end{methoddesc}
454 %
455 \begin{methoddesc}[Domain]{__eq__}{arg}
456 (\PYTHON \var{==} operator) returns \True if the \Domain \var{arg}
457 describes the same domain, \False otherwise.
458 \end{methoddesc}
459 %
460 \begin{methoddesc}[Domain]{__ne__}{arg}
461 (\PYTHON \var{!=} operator) returns \True if the \Domain \var{arg} does
462 not describe the same domain, \False otherwise.
463 \end{methoddesc}
464 %
465 \begin{methoddesc}[Domain]{__str__}{}
466 (\PYTHON \var{str()} function) returns a string representation of the
467 \Domain.
468 \end{methoddesc}
469 %
470 \begin{methoddesc}[Domain]{onMasterProcessor)}{}
471 returns \True if the processor is the master processor within the \MPI
472 processor group used by the \Domain. This is the processor with rank 0.
473 If \MPI support is not enabled the return value is always \True.
474 \end{methoddesc}
475 %
476 \begin{methoddesc}[Domain]{getMPISize}{}
477 returns the number of \MPI processors used for this \Domain. If \MPI
478 support is not enabled 1 is returned.
479 \end{methoddesc}
480 %
481 \begin{methoddesc}[Domain]{getMPIRank}{}
482 returns the rank of the processor executing the statement within the
483 \MPI processor group used by the \Domain. If \MPI support is not enabled
484 0 is returned.
485 \end{methoddesc}
486 %
487 \begin{methoddesc}[Domain]{MPIBarrier}{}
488 executes barrier synchronization within the \MPI processor group used by
489 the \Domain. If \MPI support is not enabled, this command does nothing.
490 \end{methoddesc}
492 \subsection{The \FunctionSpace class}
493 \begin{classdesc}{FunctionSpace}{}
494 \FunctionSpace objects, which are instantiated by generator functions, are
495 used to define properties of \Data objects such as continuity.
496 A \Data object in a particular \FunctionSpace is represented by its values at
497 \DataSamplePoints which are defined by the type and the \Domain of the \FunctionSpace.
498 \end{classdesc}
500 \noindent The following methods are available:
501 %
502 \begin{methoddesc}[FunctionSpace]{getDim}{}
503 returns the spatial dimension of the \Domain of the \FunctionSpace.
504 \end{methoddesc}
505 %
506 \begin{methoddesc}[FunctionSpace]{getX}{}
507 returns the location of the \DataSamplePoints.
508 \end{methoddesc}
509 %
510 \begin{methoddesc}[FunctionSpace]{getNormal}{}
511 If the domain of functions in the \FunctionSpace is a hyper-manifold (e.g.
512 the boundary of a domain) the method returns the outer normal at each of
513 the \DataSamplePoints. Otherwise an exception is raised.
514 \end{methoddesc}
515 %
516 \begin{methoddesc}[FunctionSpace]{getSize}{}
517 returns a \Data object measuring the spacing of the \DataSamplePoints.
518 The size may be zero.
519 \end{methoddesc}
520 %
521 \begin{methoddesc}[FunctionSpace]{getDomain}{}
522 returns the \Domain of the \FunctionSpace.
523 \end{methoddesc}
524 %
525 \begin{methoddesc}[FunctionSpace]{setTags}{new_tag, mask}
526 assigns a new tag \var{new_tag} to all data samples where \var{mask} is
527 positive for a least one data point.
528 \var{mask} must be defined on this \FunctionSpace.
529 Use the \var{setTagMap} to assign a tag name to \var{new_tag}.
530 \end{methoddesc}
531 %
532 \begin{methoddesc}[FunctionSpace]{__eq__}{arg}
533 (\PYTHON \var{==} operator) returns \True if the \FunctionSpace \var{arg}
534 describes the same function space, \False otherwise.
535 \end{methoddesc}
536 %
537 \begin{methoddesc}[FunctionSpace]{__ne__}{arg}
538 (\PYTHON \var{!=} operator) returns \True if the \FunctionSpace \var{arg}
539 does not describe the same function space, \False otherwise.
540 \end{methoddesc}
542 \begin{methoddesc}[Domain]{__str__}{}
543 (\PYTHON \var{str()} function) returns a string representation of the
544 \FunctionSpace.
545 \end{methoddesc}
547 \noindent The following functions provide generators for \FunctionSpace objects:
549 \begin{funcdesc}{Function}{domain}
550 returns the \Function on the \Domain \var{domain}. \Data objects in this
551 type of \Function are defined over the whole geometric region defined by
552 \var{domain}.
553 \end{funcdesc}
554 %
555 \begin{funcdesc}{ContinuousFunction}{domain}
556 returns the \ContinuousFunction on the \Domain domain. \Data objects in
557 this type of \Function are defined over the whole geometric region defined
558 by \var{domain} and assumed to represent a continuous function.
559 \end{funcdesc}
560 %
561 \begin{funcdesc}{FunctionOnBoundary}{domain}
562 returns the \FunctionOnBoundary on the \Domain domain. \Data objects in
563 this type of \Function are defined on the boundary of the geometric region
564 defined by \var{domain}.
565 \end{funcdesc}
566 %
567 \begin{funcdesc}{FunctionOnContactZero}{domain}
568 returns the \FunctionOnContactZero the \Domain domain. \Data objects in
569 this type of \Function are defined on side 0 of a discontinuity within
570 the geometric region defined by \var{domain}.
571 The discontinuity is defined when \var{domain} is instantiated.
572 \end{funcdesc}
573 %
574 \begin{funcdesc}{FunctionOnContactOne}{domain}
575 returns the \FunctionOnContactOne on the \Domain domain. \Data objects in
576 this type of \Function are defined on side 1 of a discontinuity within
577 the geometric region defined by \var{domain}.
578 The discontinuity is defined when \var{domain} is instantiated.
579 \end{funcdesc}
580 %
581 \begin{funcdesc}{Solution}{domain}
582 returns the \SolutionFS on the \Domain domain. \Data objects in this type
583 of \Function are defined on the geometric region defined by \var{domain}
584 and are solutions of partial differential equations\index{partial differential equation}.
585 \end{funcdesc}
586 %
587 \begin{funcdesc}{ReducedSolution}{domain}
588 returns the \ReducedSolutionFS on the \Domain domain. \Data objects in
589 this type of \Function are defined on the geometric region defined by
590 \var{domain} and are solutions of partial differential
591 equations\index{partial differential equation} with a reduced smoothness
592 for the solution approximation.
593 \end{funcdesc}
595 \subsection{The \Data Class}
596 \label{SEC ESCRIPT DATA}
598 The following table shows arithmetic operations that can be performed
599 point-wise on \Data objects:
600 \begin{center}
601 \begin{tabular}{l|l}
602 \textbf{Expression} & \textbf{Description}\\
603 \hline
604 \code{+arg} & identical to \var{arg}\index{+}\\
605 \code{-arg} & negation of \var{arg}\index{-}\\
606 \code{arg0+arg1} & adds \var{arg0} and \var{arg1}\index{+}\\
607 \code{arg0*arg1} & multiplies \var{arg0} and \var{arg1}\index{*}\\
608 \code{arg0-arg1} & subtracts \var{arg1} from \var{arg0}\index{-}\\
609 \code{arg0/arg1} & divides \var{arg0} by \var{arg1}\index{/}\\
610 \code{arg0**arg1} & raises \var{arg0} to the power of \var{arg1}\index{**}\\
611 \end{tabular}
612 \end{center}
613 At least one of the arguments \var{arg0} or \var{arg1} must be a \Data object.
614 Either of the arguments may be a \Data object, a \PYTHON number or a \numpy
615 object.
616 If \var{arg0} or \var{arg1} are not defined on the same \FunctionSpace, then
617 an attempt is made to convert \var{arg0} to the \FunctionSpace of \var{arg1}
618 or to convert \var{arg1} to the \FunctionSpace of \var{arg0}.
619 Both arguments must have the same \Shape or one of the arguments may be of
620 rank 0 (a constant).
621 The returned \Data object has the same \Shape and is defined on
622 the \DataSamplePoints as \var{arg0} or \var{arg1}.
624 The following table shows the update operations that can be applied to
625 \Data objects:
626 \begin{center}
627 \begin{tabular}{l|l}
628 \textbf{Expression} & \textbf{Description}\\
629 \hline
630 \code{arg0+=arg1} & adds \var{arg1} to \var{arg0}\index{+}\\
631 \code{arg0*=arg1} & multiplies \var{arg0} by \var{arg1}\index{*}\\
632 \code{arg0-=arg1} & subtracts \var{arg1} from\var{arg0}\index{-}\\
633 \code{arg0/=arg1} & divides \var{arg0} by \var{arg1}\index{/}\\
634 \code{arg0**=arg1} & raises \var{arg0} to the power of \var{arg1}\index{**}\\
635 \end{tabular}
636 \end{center}
637 \var{arg0} must be a \Data object. \var{arg1} must be a \Data object or an
638 object that can be converted into a \Data object.
639 \var{arg1} must have the same \Shape as \var{arg0} or have rank 0.
640 In the latter case it is assumed that the values of \var{arg1} are constant
641 for all components. \var{arg1} must be defined in the same \FunctionSpace as
642 \var{arg0} or it must be possible to interpolate \var{arg1} onto the
643 \FunctionSpace of \var{arg0}.
645 The \Data class supports taking slices as well as assigning new values to a
646 slice of an existing \Data object\index{slicing}.
647 The following expressions for taking and setting slices are valid:
648 \begin{center}
649 \begin{tabular}{l|ll}
650 \textbf{Rank of \var{arg}} & \textbf{Slicing expression} & \textbf{\Shape of returned and assigned object}\\
651 \hline
652 0 & no slicing & N/A\\
653 1 & \var{arg[l0:u0]} & (\var{u0}-\var{l0},)\\
654 2 & \var{arg[l0:u0,l1:u1]} & (\var{u0}-\var{l0},\var{u1}-\var{l1})\\
655 3 & \var{arg[l0:u0,l1:u1,l2:u2]} & (\var{u0}-\var{l0},\var{u1}-\var{l1},\var{u2}-\var{l2})\\
656 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})\\
657 \end{tabular}
658 \end{center}
659 Let \var{s} be the \Shape of \var{arg}, then
660 \begin{align*}
661 0 \le \var{l0} \le \var{u0} \le \var{s[0]},\\
662 0 \le \var{l1} \le \var{u1} \le \var{s[1]},\\
663 0 \le \var{l2} \le \var{u2} \le \var{s[2]},\\
664 0 \le \var{l3} \le \var{u3} \le \var{s[3]}.
665 \end{align*}
666 Any of the lower indexes \var{l0}, \var{l1}, \var{l2} and \var{l3} may not be
667 present in which case $0$ is assumed.
668 Any of the upper indexes \var{u0}, \var{u1}, \var{u2} and \var{u3} may be
669 omitted, in which case the upper limit for that dimension is assumed.
670 The lower and upper index may be identical in which case the column and the
671 lower or upper index may be dropped.
672 In the returned or in the object assigned to a slice, the corresponding
673 component is dropped, i.e. the rank is reduced by one in comparison to \var{arg}.
674 The following examples show slicing in action:
675 \begin{python}
676 t=Data(1., (4,4,6,6), Function(mydomain))
677 t[1,1,1,0]=9.
678 s=t[:2,:,2:6,5] # s has rank 3
679 s[:,:,1]=1.
680 t[:2,:2,5,5]=s[2:4,1,:2]
681 \end{python}
683 \subsection{Generation of \Data objects}
684 \begin{classdesc}{Data}{value=0, shape=(,), what=FunctionSpace(), expanded=\False}
685 creates a \Data object with \Shape \var{shape} in the \FunctionSpace \var{what}.
686 The values at all \DataSamplePoints are set to the double value \var{value}.
687 If \var{expanded} is \True the \Data object is represented in expanded form.
688 \end{classdesc}
690 \begin{classdesc}{Data}{value, what=FunctionSpace(), expanded=\False}
691 creates a \Data object in the \FunctionSpace \var{what}.
692 The value for each data sample point is set to \var{value}, which could be a
693 \numpy object, \Data object or a dictionary of \numpy or floating point
694 numbers. In the latter case the keys must be integers and are used as tags.
695 The \Shape of the returned object is equal to the \Shape of \var{value}.
696 If \var{expanded} is \True the \Data object is represented in expanded form.
697 \end{classdesc}
699 \begin{classdesc}{Data}{}
700 creates an \EmptyData object. The \EmptyData object is used to indicate that
701 an argument is not present where a \Data object is required.
702 \end{classdesc}
704 \begin{funcdesc}{Scalar}{value=0., what=FunctionSpace(), expanded=\False}
705 returns a \Data object of rank 0 (a constant) in the \FunctionSpace \var{what}.
706 Values are initialized with \var{value}, a double precision quantity.
707 If \var{expanded} is \True the \Data object is represented in expanded form.
708 \end{funcdesc}
710 \begin{funcdesc}{Vector}{value=0., what=FunctionSpace(), expanded=\False}
711 returns a \Data object of \Shape \var{(d,)} in the \FunctionSpace \var{what},
712 where \var{d} is the spatial dimension of the \Domain of \var{what}.
713 Values are initialized with \var{value}, a double precision quantity.
714 If \var{expanded} is \True the \Data object is represented in expanded form.
715 \end{funcdesc}
717 \begin{funcdesc}{Tensor}{value=0., what=FunctionSpace(), expanded=\False}
718 returns a \Data object of \Shape \var{(d,d)} in the \FunctionSpace \var{what},
719 where \var{d} is the spatial dimension of the \Domain of \var{what}.
720 Values are initialized with \var{value}, a double precision quantity.
721 If \var{expanded} is \True the \Data object is represented in expanded form.
722 \end{funcdesc}
724 \begin{funcdesc}{Tensor3}{value=0., what=FunctionSpace(), expanded=\False}
725 returns a \Data object of \Shape \var{(d,d,d)} in the \FunctionSpace \var{what},
726 where \var{d} is the spatial dimension of the \Domain of \var{what}.
727 Values are initialized with \var{value}, a double precision quantity.
728 If \var{expanded} is \True the \Data object is represented in expanded form.
729 \end{funcdesc}
731 \begin{funcdesc}{Tensor4}{value=0., what=FunctionSpace(), expanded=\False}
732 returns a \Data object of \Shape \var{(d,d,d,d)} in the \FunctionSpace \var{what},
733 where \var{d} is the spatial dimension of the \Domain of \var{what}.
734 Values are initialized with \var{value}, a double precision quantity.
735 If \var{expanded} is \True the \Data object is represented in expanded form.
736 \end{funcdesc}
738 \begin{funcdesc}{load}{filename, domain}
739 recovers a \Data object on \Domain \var{domain} from the file \var{filename},
740 which was created by \function{dump}.
741 \end{funcdesc}
743 \subsection{\Data methods}
744 These are the most frequently used methods of the \Data class.
745 A complete list of methods can be found on \ReferenceGuide.
747 \begin{methoddesc}[Data]{getFunctionSpace}{}
748 returns the \FunctionSpace of the object.
749 \end{methoddesc}
751 \begin{methoddesc}[Data]{getDomain}{}
752 returns the \Domain of the object.
753 \end{methoddesc}
755 \begin{methoddesc}[Data]{getShape}{}
756 returns the \Shape of the object as a \class{tuple} of integers.
757 \end{methoddesc}
759 \begin{methoddesc}[Data]{getRank}{}
760 returns the rank of the data on each data point\index{rank}.
761 \end{methoddesc}
763 \begin{methoddesc}[Data]{isEmpty}{}
764 returns \True if the \Data object is the \EmptyData object, \False otherwise.
765 Note that this is not the same as asking if the object contains no \DataSamplePoints.
766 \end{methoddesc}
768 \begin{methoddesc}[Data]{setTaggedValue}{tag_name, value}
769 assigns the \var{value} to all \DataSamplePoints which have the tag
770 assigned to \var{tag_name}. \var{value} must be an object of class
771 \class{numpy.ndarray} or must be convertible into a \class{numpy.ndarray} object.
772 \var{value} (or the corresponding \class{numpy.ndarray} object) must be of
773 rank $0$ or must have the same rank as the object.
774 If a value has already been defined for tag \var{tag_name} within the object
775 it is overwritten by the new \var{value}. If the object is expanded,
776 the value assigned to \DataSamplePoints with tag \var{tag_name} is replaced by
777 \var{value}. If no value is assigned the tag name \var{tag_name}, no value is set.
778 \end{methoddesc}
780 \begin{methoddesc}[Data]{dump}{filename}
781 dumps the \Data object to the file \var{filename}. The file stores the
782 function space but not the \Domain. It is the responsibility of the user to
783 save the \Domain in order to be able to recover the \Data object.
784 \end{methoddesc}
786 \begin{methoddesc}[Data]{__str__}{}
787 returns a string representation of the object.
788 \end{methoddesc}
790 \subsection{Functions of \Data objects}
791 This section lists the most important functions for \Data class objects.
792 A complete list and a more detailed description of the functionality can be
793 found on \ReferenceGuide.
795 \begin{funcdesc}{saveVTK}{filename, **kwdata}
796 writes \Data defined by keywords to the file \var{filename} using the \VTK
797 file format. The keyword is used as an identifier. The statement
798 \begin{python}
799 saveVTK("out.vtu", temperature=T, velocity=v)
800 \end{python}
801 writes the scalar \var{T} as \var{temperature} and the vector \var{v} as
802 \var{velocity} into the file \file{out.vtu}.
803 Restrictions on the allowed combinations of \FunctionSpace apply.
804 This method is deprecated and will be removed in a future version of escript.
805 Use the weipa module instead!
806 \end{funcdesc}
808 \begin{funcdesc}{saveDX}{filename, **kwdata}
809 writes \Data defined by keywords to the file \var{filename} using the \OpenDX
810 file format. The keyword is used as an identifier. The statement
811 \begin{python}
812 saveDX("out.dx", temperature=T, velocity=v)
813 \end{python}
814 writes the scalar \var{T} as \var{temperature} and the vector \var{v} as
815 \var{velocity} into the file \file{out.dx}.
816 Restrictions on the allowed combinations of \FunctionSpace apply.
817 \end{funcdesc}
819 \begin{funcdesc}{kronecker}{d}
820 returns a \RankTwo \Data object in \FunctionSpace \var{d} such that
821 \begin{equation}
822 \code{kronecker(d)}\left[ i,j\right] = \left\{
823 \begin{array}{l l}
824 1 & \quad \text{if $i=j$}\\
825 0 & \quad \text{otherwise}
826 \end{array}
827 \right.
828 \end{equation}
829 If \var{d} is an integer a $(d,d)$ \numpy array is returned.
830 \end{funcdesc}
832 \begin{funcdesc}{identityTensor}{d}
833 is a synonym for \code{kronecker} (see above).
834 % returns a \RankTwo \Data object in \FunctionSpace \var{d} such that
835 % \begin{equation}
836 % \code{identityTensor(d)}\left[ i,j\right] = \left\{
837 % \begin{array}{cc}
838 % 1 & \mbox{ if } i=j \\
839 % 0 & \mbox{ otherwise }
840 % \end{array}
841 % \right.
842 % \end{equation}
843 % If \var{d} is an integer a $(d,d)$ \numpy array is returned.
844 \end{funcdesc}
846 \begin{funcdesc}{identityTensor4}{d}
847 returns a \RankFour \Data object in \FunctionSpace \var{d} such that
848 \begin{equation}
849 \code{identityTensor(d)}\left[ i,j,k,l\right] = \left\{
850 \begin{array}{l l}
851 1 & \quad \text{if $i=k$ and $j=l$}\\
852 0 & \quad \text{otherwise}
853 \end{array}
854 \right.
855 \end{equation}
856 If \var{d} is an integer a $(d,d,d,d)$ \numpy array is returned.
857 \end{funcdesc}
859 \begin{funcdesc}{unitVector}{i,d}
860 returns a \RankOne \Data object in \FunctionSpace \var{d} such that
861 \begin{equation}
862 \code{identityTensor(d)}\left[ j \right] = \left\{
863 \begin{array}{l l}
864 1 & \quad \text{if $j=i$}\\
865 0 & \quad \text{otherwise}
866 \end{array}
867 \right.
868 \end{equation}
869 If \var{d} is an integer a $(d,)$ \numpy array is returned.
870 \end{funcdesc}
872 \begin{funcdesc}{Lsup}{a}
873 returns the $L^{sup}$ norm of \var{arg}. This is the maximum of the absolute
874 values over all components and all \DataSamplePoints of \var{a}.
875 \end{funcdesc}
877 \begin{funcdesc}{sup}{a}
878 returns the maximum value over all components and all \DataSamplePoints of \var{a}.
879 \end{funcdesc}
881 \begin{funcdesc}{inf}{a}
882 returns the minimum value over all components and all \DataSamplePoints of \var{a}
883 \end{funcdesc}
885 \begin{funcdesc}{minval}{a}
886 returns at each data sample point the minimum value over all components.
887 \end{funcdesc}
889 \begin{funcdesc}{maxval}{a}
890 returns at each data sample point the maximum value over all components.
891 \end{funcdesc}
893 \begin{funcdesc}{length}{a}
894 returns the Euclidean norm at each data sample point.
895 For a \RankFour \var{a} this is
896 \begin{equation}
897 \code{length(a)}=\sqrt{\sum_{ijkl} \var{a} \left[i,j,k,l\right]^2}
898 \end{equation}
899 \end{funcdesc}
901 \begin{funcdesc}{trace}{a\optional{,axis_offset=0}}
902 returns the trace of \var{a}. This is the sum over components \var{axis_offset}
903 and \var{axis_offset+1} with the same index.
904 For instance, in the case of a \RankTwo this is
905 \begin{equation}
906 \code{trace(a)}=\sum_{i} \var{a} \left[i,i\right]
907 \end{equation}
908 and for a \RankFour and \code{axis_offset=1} this is
909 \begin{equation}
910 \code{trace(a,1)}\left[i,j\right]=\sum_{k} \var{a} \left[i,k,k,j\right]
911 \end{equation}
912 \end{funcdesc}
914 \begin{funcdesc}{transpose}{a\optional{, axis_offset=None}}
915 returns the transpose of \var{a}. This swaps the first \var{axis_offset}
916 components of \var{a} with the rest. If \var{axis_offset} is not
917 present \code{int(r/2)} is used where \var{r} is the rank of \var{a}.
918 For instance, in the case of a \RankTwo this is
919 \begin{equation}
920 \code{transpose(a)}\left[i,j\right]=\var{a} \left[j,i\right]
921 \end{equation}
922 and for a \RankFour and \code{axis_offset=1} this is
923 \begin{equation}
924 \code{transpose(a,1)}\left[i,j,k,l\right]=\var{a} \left[j,k,l,i\right]
925 \end{equation}
926 \end{funcdesc}
928 \begin{funcdesc}{swap_axes}{a\optional{, axis0=0 \optional{, axis1=1 }}}
929 returns \var{a} but with swapped components \var{axis0} and \var{axis1}.
930 The argument \var{a} must be at least of rank 2. For instance, if \var{a}
931 is a \RankFour, \code{axis0=1} and \code{axis1=2}, the result is
932 \begin{equation}
933 \code{swap_axes(a,1,2)}\left[i,j,k,l\right]=\var{a} \left[i,k,j,l\right]
934 \end{equation}
935 \end{funcdesc}
937 \begin{funcdesc}{symmetric}{a}
938 returns the symmetric part of \var{a}. This is \code{(a+transpose(a))/2}.
939 \end{funcdesc}
941 \begin{funcdesc}{nonsymmetric}{a}
942 returns the non-symmetric part of \var{a}. This is \code{(a-transpose(a))/2}.
943 \end{funcdesc}
945 \begin{funcdesc}{inverse}{a}
946 return the inverse of \var{a} so that
947 \begin{equation}
948 \code{matrix_mult(inverse(a),a)=kronecker(d)}
949 \end{equation}
950 if \var{a} has shape \code{(d,d)}. The current implementation is restricted to
951 arguments of shape \code{(2,2)} and \code{(3,3)}.
952 \end{funcdesc}
954 \begin{funcdesc}{eigenvalues}{a}
955 returns the eigenvalues of \var{a} so that
956 \begin{equation}
957 \code{matrix_mult(a,V)=e[i]*V}
958 \end{equation}
959 where \code{e=eigenvalues(a)} and \var{V} is a suitable non-zero vector.
960 The eigenvalues are ordered in increasing size.
961 The argument \var{a} has to be symmetric, i.e. \code{a=symmetric(a)}.
962 The current implementation is restricted to arguments of shape \code{(2,2)}
963 and \code{(3,3)}.
964 \end{funcdesc}
966 \begin{funcdesc}{eigenvalues_and_eigenvectors}{a}
967 returns the eigenvalues and eigenvectors of \var{a}.
968 \begin{equation}
969 \code{matrix_mult(a,V[:,i])=e[i]*V[:,i]}
970 \end{equation}
971 where \code{e,V=eigenvalues_and_eigenvectors(a)}. The eigenvectors \var{V} are
972 orthogonal and normalized, i.e.
973 \begin{equation}
974 \code{matrix_mult(transpose(V),V)=kronecker(d)}
975 \end{equation}
976 if \var{a} has shape \code{(d,d)}. The eigenvalues are ordered in increasing
977 size. The argument \var{a} has to be the symmetric, i.e. \code{a=symmetric(a)}.
978 The current implementation is restricted to arguments of shape \code{(2,2)}
979 and \code{(3,3)}.
980 \end{funcdesc}
982 \begin{funcdesc}{maximum}{*a}
983 returns the maximum value over all arguments at all \DataSamplePoints and for each component.
984 \begin{equation}
985 \code{maximum(a0,a1)}\left[i,j\right]=max(\var{a0} \left[i,j\right],\var{a1} \left[i,j\right])
986 \end{equation}
987 at all \DataSamplePoints.
988 \end{funcdesc}
990 \begin{funcdesc}{minimum}{*a}
991 returns the minimum value over all arguments at all \DataSamplePoints and for each component.
992 \begin{equation}
993 \code{minimum(a0,a1)}\left[i,j\right]=min(\var{a0} \left[i,j\right],\var{a1} \left[i,j\right])
994 \end{equation}
995 at all \DataSamplePoints.
996 \end{funcdesc}
998 \begin{funcdesc}{clip}{a\optional{, minval=0.}\optional{, maxval=1.}}
999 cuts back \var{a} into the range between \var{minval} and \var{maxval}.
1000 A value in the returned object equals \var{minval} if the corresponding value
1001 of \var{a} is less than \var{minval}, equals \var{maxval} if the corresponding
1002 value of \var{a} is greater than \var{maxval}, or corresponding value of
1003 \var{a} otherwise.
1004 \end{funcdesc}
1006 \begin{funcdesc}{inner}{a0, a1}
1007 returns the inner product of \var{a0} and \var{a1}. For instance in the
1008 case of a \RankTwo:
1009 \begin{equation}
1010 \code{inner(a)}=\sum_{ij}\var{a0} \left[j,i\right] \cdot \var{a1} \left[j,i\right]
1011 \end{equation}
1012 and for a \RankFour:
1013 \begin{equation}
1014 \code{inner(a)}=\sum_{ijkl}\var{a0} \left[i,j,k,l\right] \cdot \var{a1} \left[j,i,k,l\right]
1015 \end{equation}
1016 \end{funcdesc}
1018 \begin{funcdesc}{matrix_mult}{a0, a1}
1019 returns the matrix product of \var{a0} and \var{a1}.
1020 If \var{a1} is a \RankOne this is
1021 \begin{equation}
1022 \code{matrix_mult(a)}\left[i\right]=\sum_{k}\var{a0} \cdot \left[i,k\right]\var{a1} \left[k\right]
1023 \end{equation}
1024 and if \var{a1} is a \RankTwo this is
1025 \begin{equation}
1026 \code{matrix_mult(a)}\left[i,j\right]=\sum_{k}\var{a0} \cdot \left[i,k\right]\var{a1} \left[k,j\right]
1027 \end{equation}
1028 \end{funcdesc}
1030 \begin{funcdesc}{transposed_matrix_mult}{a0,a1}
1031 returns the matrix product of the transposed of \var{a0} and \var{a1}.
1032 The function is equivalent to \code{matrix_mult(transpose(a0),a1)}.
1033 If \var{a1} is a \RankOne this is
1034 \begin{equation}
1035 \code{transposed_matrix_mult(a)}\left[i\right]=\sum_{k}\var{a0} \cdot \left[k,i\right]\var{a1} \left[k\right]
1036 \end{equation}
1037 and if \var{a1} is a \RankTwo this is
1038 \begin{equation}
1039 \code{transposed_matrix_mult(a)}\left[i,j\right]=\sum_{k}\var{a0} \cdot \left[k,i\right]\var{a1} \left[k,j\right]
1040 \end{equation}
1041 \end{funcdesc}
1043 \begin{funcdesc}{matrix_transposed_mult}{a0,a1}
1044 returns the matrix product of \var{a0} and the transposed of \var{a1}.
1045 The function is equivalent to \code{matrix_mult(a0,transpose(a1))}.
1046 If \var{a1} is a \RankTwo this is
1047 \begin{equation}
1048 \code{matrix_transposed_mult(a)}\left[i,j\right]=\sum_{k}\var{a0} \cdot \left[i,k\right]\var{a1} \left[j,k\right]
1049 \end{equation}
1050 \end{funcdesc}
1052 \begin{funcdesc}{outer}{a0,a1}
1053 returns the outer product of \var{a0} and \var{a1}.
1054 For instance, if both, \var{a0} and \var{a1} is a \RankOne then
1055 \begin{equation}
1056 \code{outer(a)}\left[i,j\right]=\var{a0} \left[i\right] \cdot \var{a1}\left[j\right]
1057 \end{equation}
1058 and if \var{a0} is a \RankOne and \var{a1} is a \RankThree:
1059 \begin{equation}
1060 \code{outer(a)}\left[i,j,k\right]=\var{a0} \left[i\right] \cdot \var{a1}\left[j,k\right]
1061 \end{equation}
1062 \end{funcdesc}
1064 \begin{funcdesc}{tensor_mult}{a0,a1}
1065 returns the tensor product of \var{a0} and \var{a1}.
1066 If \var{a1} is a \RankTwo this is
1067 \begin{equation}
1068 \code{tensor_mult(a)}\left[i,j\right]=\sum_{kl}\var{a0}\left[i,j,k,l\right] \cdot \var{a1} \left[k,l\right]
1069 \end{equation}
1070 and if \var{a1} is a \RankFour this is
1071 \begin{equation}
1072 \code{tensor_mult(a)}\left[i,j,k,l\right]=\sum_{mn}\var{a0} \left[i,j,m,n\right] \cdot \var{a1} \left[m,n,k,l\right]
1073 \end{equation}
1074 \end{funcdesc}
1076 \begin{funcdesc}{transposed_tensor_mult}{a0,a1}
1077 returns the tensor product of the transposed of \var{a0} and \var{a1}.
1078 The function is equivalent to \code{tensor_mult(transpose(a0),a1)}.
1079 If \var{a1} is a \RankTwo this is
1080 \begin{equation}
1081 \code{transposed_tensor_mult(a)}\left[i,j\right]=\sum_{kl}\var{a0}\left[k,l,i,j\right] \cdot \var{a1} \left[k,l\right]
1082 \end{equation}
1083 and if \var{a1} is a \RankFour this is
1084 \begin{equation}
1085 \code{transposed_tensor_mult(a)}\left[i,j,k,l\right]=\sum_{mn}\var{a0} \left[m,n,i,j\right] \cdot \var{a1} \left[m,n,k,l\right]
1086 \end{equation}
1087 \end{funcdesc}
1089 \begin{funcdesc}{tensor_transposed_mult}{a0,a1}
1090 returns the tensor product of \var{a0} and the transposed of \var{a1}.
1091 The function is equivalent to \code{tensor_mult(a0,transpose(a1))}.
1092 If \var{a1} is a \RankTwo this is
1093 \begin{equation}
1094 \code{tensor_transposed_mult(a)}\left[i,j\right]=\sum_{kl}\var{a0}\left[i,j,k,l\right] \cdot \var{a1} \left[l,k\right]
1095 \end{equation}
1096 and if \var{a1} is a \RankFour this is
1097 \begin{equation}
1098 \code{tensor_transposed_mult(a)}\left[i,j,k,l\right]=\sum_{mn}\var{a0} \left[i,j,m,n\right] \cdot \var{a1} \left[k,l,m,n\right]
1099 \end{equation}
1100 \end{funcdesc}
1102 \begin{funcdesc}{grad}{a\optional{, where=None}}
1103 returns the gradient of \var{a}. If \var{where} is present the gradient will
1104 be calculated in the \FunctionSpace \var{where}, otherwise a default
1105 \FunctionSpace is used. In case that \var{a} is a \RankTwo one has
1106 \begin{equation}
1107 \code{grad(a)}\left[i,j,k\right]=\frac{\partial \var{a} \left[i,j\right]}{\partial x_{k}}
1108 \end{equation}
1109 \end{funcdesc}
1111 \begin{funcdesc}{integrate}{a\optional{ ,where=None}}
1112 returns the integral of \var{a} where the domain of integration is defined by
1113 the \FunctionSpace of \var{a}. If \var{where} is present the argument is
1114 interpolated into \FunctionSpace \var{where} before integration.
1115 For instance in the case of a \RankTwo in \ContinuousFunction it is
1116 \begin{equation}
1117 \code{integrate(a)}\left[i,j\right]=\int_{\Omega}\var{a} \left[i,j\right] \; d\Omega
1118 \end{equation}
1119 where $\Omega$ is the spatial domain and $d\Omega$ volume integration.
1120 To integrate over the boundary of the domain one uses
1121 \begin{equation}
1122 \code{integrate(a,where=FunctionOnBoundary(a.getDomain))}\left[i,j\right]=\int_{\partial \Omega} a\left[i,j\right] \; ds
1123 \end{equation}
1124 where $\partial \Omega$ is the surface of the spatial domain and $ds$ area or
1125 line integration.
1126 \end{funcdesc}
1128 \begin{funcdesc}{interpolate}{a,where}
1129 interpolates argument \var{a} into the \FunctionSpace \var{where}.
1130 \end{funcdesc}
1132 \begin{funcdesc}{div}{a\optional{ ,where=None}}
1133 returns the divergence of \var{a}:
1134 \begin{equation}
1135 \code{div(a)=trace(grad(a),where)}
1136 \end{equation}
1137 \end{funcdesc}
1139 \begin{funcdesc}{jump}{a\optional{ ,domain=None}}
1140 returns the jump of \var{a} over the discontinuity in its domain or if
1141 \Domain \var{domain} is present in \var{domain}.
1142 \begin{equation}
1143 \begin{array}{rcl}
1144 \code{jump(a)}& = &\code{interpolate(a,FunctionOnContactOne(domain))} \\
1145 & & \hfill - \code{interpolate(a,FunctionOnContactZero(domain))}
1146 \end{array}
1147 \end{equation}
1148 \end{funcdesc}
1150 \begin{funcdesc}{L2}{a}
1151 returns the $L^2$-norm of \var{a} in its \FunctionSpace. This is
1152 \begin{equation}
1153 \code{L2(a)=integrate(length(a)}^2\code{)} \; .
1154 \end{equation}
1155 \end{funcdesc}
1157 \noindent The following functions operate ``point-wise''.
1158 That is, the operation is applied to each component of each point individually.
1160 \begin{funcdesc}{sin}{a}
1161 applies the sine function to \var{a}.
1162 \end{funcdesc}
1164 \begin{funcdesc}{cos}{a}
1165 applies the cosine function to \var{a}.
1166 \end{funcdesc}
1168 \begin{funcdesc}{tan}{a}
1169 applies the tangent function to \var{a}.
1170 \end{funcdesc}
1172 \begin{funcdesc}{asin}{a}
1173 applies the arc (inverse) sine function to \var{a}.
1174 \end{funcdesc}
1176 \begin{funcdesc}{acos}{a}
1177 applies the arc (inverse) cosine function to \var{a}.
1178 \end{funcdesc}
1180 \begin{funcdesc}{atan}{a}
1181 applies the arc (inverse) tangent function to \var{a}.
1182 \end{funcdesc}
1184 \begin{funcdesc}{sinh}{a}
1185 applies the hyperbolic sine function to \var{a}.
1186 \end{funcdesc}
1188 \begin{funcdesc}{cosh}{a}
1189 applies the hyperbolic cosine function to \var{a}.
1190 \end{funcdesc}
1192 \begin{funcdesc}{tanh}{a}
1193 applies the hyperbolic tangent function to \var{a}.
1194 \end{funcdesc}
1196 \begin{funcdesc}{asinh}{a}
1197 applies the arc (inverse) hyperbolic sine function to \var{a}.
1198 \end{funcdesc}
1200 \begin{funcdesc}{acosh}{a}
1201 applies the arc (inverse) hyperbolic cosine function to \var{a}.
1202 \end{funcdesc}
1204 \begin{funcdesc}{atanh}{a}
1205 applies the arc (inverse) hyperbolic tangent function to \var{a}.
1206 \end{funcdesc}
1208 \begin{funcdesc}{exp}{a}
1209 applies the exponential function to \var{a}.
1210 \end{funcdesc}
1212 \begin{funcdesc}{sqrt}{a}
1213 applies the square root function to \var{a}.
1214 \end{funcdesc}
1216 \begin{funcdesc}{log}{a}
1217 takes the natural logarithm of \var{a}.
1218 \end{funcdesc}
1220 \begin{funcdesc}{log10}{a}
1221 takes the base-$10$ logarithm of \var{a}.
1222 \end{funcdesc}
1224 \begin{funcdesc}{sign}{a}
1225 applies the sign function to \var{a}. The result is $1$ where \var{a} is
1226 positive, $-1$ where \var{a} is negative, and $0$ otherwise.
1227 \end{funcdesc}
1229 \begin{funcdesc}{wherePositive}{a}
1230 returns a function which is $1$ where \var{a} is positive and $0$ otherwise.
1231 \end{funcdesc}
1233 \begin{funcdesc}{whereNegative}{a}
1234 returns a function which is $1$ where \var{a} is negative and $0$ otherwise.
1235 \end{funcdesc}
1237 \begin{funcdesc}{whereNonNegative}{a}
1238 returns a function which is $1$ where \var{a} is non-negative and $0$ otherwise.
1239 \end{funcdesc}
1241 \begin{funcdesc}{whereNonPositive}{a}
1242 returns a function which is $1$ where \var{a} is non-positive and $0$ otherwise.
1243 \end{funcdesc}
1245 \begin{funcdesc}{whereZero}{a\optional{, tol=None, \optional{, rtol=1.e-8}}}
1246 returns a function which is $1$ where \var{a} equals zero with tolerance
1247 \var{tol} and $0$ otherwise. If \var{tol} is not present, the absolute maximum
1248 value of \var{a} times \var{rtol} is used.
1249 \end{funcdesc}
1251 \begin{funcdesc}{whereNonZero}{a, \optional{, tol=None, \optional{, rtol=1.e-8}}}
1252 returns a function which is $1$ where \var{a} is non-zero with tolerance
1253 \var{tol} and $0$ otherwise. If \var{tol} is not present, the absolute maximum
1254 value of \var{a} times \var{rtol} is used.
1255 \end{funcdesc}
1257 \subsection{Interpolating Data}
1258 \index{interpolateTable}
1259 In some cases, it may be useful to produce Data objects which fit some user
1260 defined function.
1261 Manually modifying each value in the Data object is not a good idea since it
1262 depends on knowing the location and order of each data point in the domain.
1263 Instead, \escript can use an interpolation table to produce a \Data object.
1265 The following example is available as \file{int_save.py} in the \ExampleDirectory.
1266 We will produce a \Data object which approximates a sine curve.
1268 \begin{python}
1269 from esys.escript import saveDataCSV, sup
1270 import numpy
1271 from esys.finley import Rectangle
1273 n=4
1274 r=Rectangle(n,n)
1275 x=r.getX()
1276 x0=x[0]
1277 x1=x[1] #we will use this later
1278 toobig=100
1279 \end{python}
1281 \noindent First we produce an interpolation table:
1282 \begin{python}
1283 sine_table=[0, 0.70710678118654746, 1, 0.70710678118654746, 0,
1284 -0.70710678118654746, -1, -0.70710678118654746, 0]
1285 \end{python}
1286 %
1287 We wish to identify $0$ and $1$ with the ends of the curve, that is
1288 with the first and eighth value in the table.
1290 \begin{python}
1291 numslices=len(sine_table)-1
1292 minval=0
1293 maxval=1
1294 step=sup(maxval-minval)/numslices
1295 \end{python}
1296 %
1297 So the values $v$ from the input lie in the interval
1298 \var{minval} $\leq v <$ \var{maxval}.
1299 \var{step} represents the gap (in the input range) between entries in the table.
1300 By default, values of $v$ outside the table argument range (minval, maxval)
1301 will be pushed back into the range, i.e. if $v <$ \var{minval} the value
1302 \var{minval} will be used to evaluate the table.
1303 Similarly, for values $v>$ \var{maxval} the value \var{maxval} is used.
1305 Now we produce our new \Data object:
1307 \begin{python}
1308 result=x0.interpolateTable(sine_table, minval, step, toobig)
1309 \end{python}
1310 Any values which interpolate to larger than \var{toobig} will raise an
1311 exception. You can switch on boundary checking by adding
1312 \code{check_boundaries=True} to the argument list.
1314 Now consider a 2D example. We will interpolate a surface such that the bottom
1315 edge is the sine curve described above.
1316 The amplitude of the curve decreases as we move towards the top edge.
1317 Our interpolation table will have three rows:
1319 \begin{python}
1320 st=numpy.array(sine_table)
1321 table=[st, 0.5*st, 0*st]
1322 \end{python}
1323 %
1324 The use of \numpy and multiplication here is just to save typing.
1326 \begin{python}
1327 result2=x1.interpolateTable(table, 0, 0.55, x0, minval, step, toobig)
1328 \end{python}
1330 In the 2D case, the parameters for the \var{x1} direction (min=0, step=0.55)
1331 come first followed by the \var{x0} data object and its parameters.
1332 By default, if a point is specified which is outside the boundary, then
1333 \var{interpolateTable} will operate as if the point was on the boundary.
1334 Passing \code{check_boundaries=True} will lead to the rejection of any points
1335 outside the boundaries by \var{interpolateTable}.
1337 \subsection{The \var{DataManager} Class}
1338 \label{sec:datamanager}
1340 \begin{classdesc}{DataManager}{formats=[RESTART], work_dir=".", restart_prefix="restart", do_restart=\True}
1341 initializes a new \var{DataManager} object which can be used to save,
1342 restore and export simulation data in a number of formats.
1343 All files and directories saved or restored by this object are located
1344 under the directory specified by \var{work_dir}.
1345 If \var{RESTART} is specified in \var{formats}, the \var{DataManager} will
1346 look for directories whose name starts with \var{restart_prefix}.
1347 In case \var{do_restart} is \True, the last of these directories is used
1348 to restore simulation data while all others are deleted.
1349 If \var{do_restart} is \False, then all of those directories are deleted.
1350 The \var{restart_prefix} and \var{do_restart} parameters are ignored if
1351 \var{RESTART} is not specified in \var{formats}.
1352 \end{classdesc}
1354 \noindent Valid values for the \var{formats} parameter are:
1355 \begin{memberdesc}[DataManager]{RESTART}
1356 enables writing of checkpoint files to be able to continue simulations
1357 as explained in the class description.
1358 \end{memberdesc}
1359 \begin{memberdesc}[DataManager]{SILO}
1360 exports simulation data in the \SILO file format. \escript must have
1361 been compiled with \SILO support for this to work.
1362 \end{memberdesc}
1363 \begin{memberdesc}[DataManager]{VISIT}
1364 enables the \VisIt simulation interface which allows connecting to and
1365 interacting with the running simulation from a compatible \VisIt client.
1366 \escript must have been compiled with \VisIt (version 2) support and the
1367 version of the client has to match the version used at compile time.
1368 In order to connect to the simulation the client needs to have access and
1369 load the file \file{escriptsim.sim2} located under the work directory.
1370 \end{memberdesc}
1371 \begin{memberdesc}[DataManager]{VTK}
1372 exports simulation data in the \VTK file format.
1373 \end{memberdesc}
1375 \noindent The \var{DataManager} class has the following methods:
1376 \begin{methoddesc}[DataManager]{addData}{**data}
1377 adds \Data objects and other data to the manager. Calling this method does
1378 not save or export the data yet so it is allowed to incrementally add data
1379 at various points in the simulation script if required.
1380 Note, that only a single domain is supported so all \Data objects have to
1381 be defined on the same one or an exception is raised.
1382 \end{methoddesc}
1384 \begin{methoddesc}[DataManager]{setDomain}{domain}
1385 explicitly sets the domain for this manager.
1386 It is generally not required to call this method directly.
1387 Instead, the \var{addData} method will set the domain used by the \Data
1388 objects.
1389 An exception is raised if the domain was set to a different domain before
1390 (explicitly or implicitly).
1391 \end{methoddesc}
1393 \begin{methoddesc}[DataManager]{hasData}{}
1394 returns \True if the manager has loaded simulation data for a restart.
1395 \end{methoddesc}
1397 \begin{methoddesc}[DataManager]{getDomain}{}
1398 returns the domain as recovered from a restart.
1399 \end{methoddesc}
1401 \begin{methoddesc}[DataManager]{getValue}{value_name}
1402 returns a \Data object or other value with the name \var{value_name} that
1403 has been recovered after a restart.
1404 \end{methoddesc}
1406 \begin{methoddesc}[DataManager]{getCycle}{}
1407 returns the export cycle, i.e. the number of times \var{export()} has been
1408 called.
1409 \end{methoddesc}
1411 \begin{methoddesc}[DataManager]{setCheckpointFrequency}{freq}
1412 sets the frequency with which checkpoint files are created. This is only
1413 useful if the \var{DataManager} object was created with at least one other
1414 format next to \var{RESTART}. The frequency is 1 by default which means
1415 that checkpoint files are created every time \var{export()} is called.
1416 Unlike visualization output, a simulation checkpoint is usually not
1417 required at every time step. Thus, the frequency can be decreased by
1418 calling this method with $\var{freq}>1$ which would then create restart
1419 files every \var{freq} times \var{export()} is called.
1420 \end{methoddesc}
1422 \begin{methoddesc}[DataManager]{setTime}{time}
1423 sets the simulation time stamp. This floating point number is stored in
1424 the metadata of exported data but not used by \var{RESTART}.
1425 \end{methoddesc}
1427 \begin{methoddesc}[DataManager]{setMeshLabels}{x, y, z=""}
1428 sets labels for the mesh axes. These are currently only used by the \SILO
1429 exporter.
1430 \end{methoddesc}
1432 \begin{methoddesc}[DataManager]{setMeshUnits}{x, y, z=""}
1433 sets units for the mesh axes. These are currently only used by the \SILO
1434 exporter.
1435 \end{methoddesc}
1437 \begin{methoddesc}[DataManager]{setMetadataSchemaString}{schema, metadata=""}
1438 sets metadata namespaces and the corresponding metadata. These are
1439 currently only used by the \VTK exporter.
1440 \var{schema} is a dictionary that maps prefixes to namespace names, e.g.\\
1441 \code{\{"gml": "http://www.opengis.net/gml"\}} and \var{metadata} is a
1442 string with the actual content which will be enclosed in \var{<MetaData>}
1443 tags.
1444 \end{methoddesc}
1446 \begin{methoddesc}[DataManager]{export}{}
1447 executes the actual data export. Depending on the \var{formats} parameter
1448 used in the constructor all data added by \var{addData()} is written to
1449 disk (\var{RESTART,SILO,VTK}) or made available through the \VisIt
1450 simulation interface (\var{VISIT}).
1451 At least the domain must be set for something to be exported.
1452 \end{methoddesc}
1454 \subsection{Saving Data as CSV}
1455 \label{sec:savedatacsv}
1456 \index{saveDataCSV}\index{CSV}
1457 For simple post-processing, \Data objects can be saved in comma separated
1458 value (\emph{CSV}) format.
1459 If \var{mydata1} and \var{mydata2} are scalar data, the command
1460 \begin{python}
1461 saveDataCSV('output.csv', U=mydata1, V=mydata2)
1462 \end{python}
1463 will record the values in \file{output.csv} in the following format:
1464 \begin{verbatim}
1465 U, V
1466 1.0000000e+0, 2.0000000e-1
1467 5.0000000e-0, 1.0000000e+1
1468 ...
1469 \end{verbatim}
1471 The names of the keyword parameters form the names of columns in the output.
1472 If the data objects are over different function spaces, then \var{saveDataCSV}
1473 will attempt to interpolate to a common function space.
1474 If this is not possible, then an exception is raised.
1476 Output can be restricted using a scalar mask as follows:
1477 \begin{python}
1478 saveDataCSV('outfile.csv', U=mydata1, V=mydata2, mask=myscalar)
1479 \end{python}
1480 This command will only output those rows which correspond to to positive
1481 values of \var{myscalar}.
1482 Some aspects of the output can be tuned using additional parameters:
1483 \begin{python}
1484 saveDataCSV('data.csv', append=True, sep=' ', csep='/', mask=mymask, e=mat1)
1485 \end{python}
1487 \begin{itemize}
1488 \item \var{append} -- specifies that the output should be written to the end of an existing file
1489 \item \var{sep} -- defines the separator between fields
1490 \item \var{csep} -- defines the separator between components in the header
1491 line. For example between the components of a matrix.
1492 \end{itemize}
1493 %
1494 The above command would produce output like this:
1495 \begin{verbatim}
1496 e/0/0 e/1/0 e/0/1 e/1/1
1497 1.0000000000e+00 2.0000000000e+00 3.0000000000e+00 4.0000000000e+00
1498 ...
1499 \end{verbatim}
1501 Note that while the order in which rows are output can vary, all the elements
1502 in a given row always correspond to the same input.
1504 \subsection{The \Operator Class}
1505 The \Operator class provides an abstract access to operators built
1506 within the \LinearPDE class. \Operator objects are created
1507 when a PDE is handed over to a PDE solver library and handled
1508 by the \LinearPDE object defining the PDE. The user can gain access
1509 to the \Operator of a \LinearPDE object through the \var{getOperator}
1510 method.
1512 \begin{classdesc}{Operator}{}
1513 creates an empty \Operator object.
1514 \end{classdesc}
1516 \begin{methoddesc}[Operator]{isEmpty}{fileName}
1517 returns \True is the object is empty, \False otherwise.
1518 \end{methoddesc}
1520 \begin{methoddesc}[Operator]{setValue}{value}
1521 resets all entries in the object representation to \var{value}.
1522 \end{methoddesc}
1524 \begin{methoddesc}[Operator]{solves}{rhs}
1525 solves the operator equation with right hand side \var{rhs}.
1526 \end{methoddesc}
1528 \begin{methoddesc}[Operator]{of}{u}
1529 applies the operator to the \Data object \var{u}.
1530 \end{methoddesc}
1532 \begin{methoddesc}[Operator]{saveMM}{fileName}\index{Matrix Market}
1533 saves the object to a Matrix Market format file with name \var{fileName}, see
1534 \url{http://maths.nist.gov/MatrixMarket}
1535 \end{methoddesc}
1537 \section{Physical Units}
1538 \escript provides support for physical units in the SI system\index{SI units}
1539 including unit conversion. So the user can define variables in the form
1540 \begin{python}
1541 from esys.escript.unitsSI import *
1542 l=20*m
1543 w=30*kg
1544 w2=40*lb
1545 T=100*Celsius
1546 \end{python}
1547 In the two latter cases a conversion from pounds\index{pounds} and degrees
1548 Celsius\index{Celsius} is performed into the appropriate SI units \emph{kg}
1549 and \emph{Kelvin}.
1550 In addition, composed units can be used, for instance
1551 \begin{python}
1552 from esys.escript.unitsSI import *
1553 rho=40*lb/cm**3
1554 \end{python}
1555 defines the density in the units of pounds per cubic centimeter.
1556 The value $40$ will be converted into SI units, in this case kg per cubic
1557 meter. Moreover unit prefixes are supported:
1558 \begin{python}
1559 from esys.escript.unitsSI import *
1560 p=40*Mega*Pa
1561 \end{python}
1562 The pressure \var{p} is set to 40 Mega Pascal. Units can also be converted
1563 back from the SI system into a desired unit, e.g.
1564 \begin{python}
1565 from esys.escript.unitsSI import *
1566 print p/atm
1567 \end{python}
1568 can be used print the pressure in units of atmosphere\index{atmosphere}.
1570 The following is an incomplete list of supported physical units:
1572 \begin{datadesc}{km}
1573 unit of kilometer
1574 \end{datadesc}
1576 \begin{datadesc}{m}
1577 unit of meter
1578 \end{datadesc}
1580 \begin{datadesc}{cm}
1581 unit of centimeter
1582 \end{datadesc}
1584 \begin{datadesc}{mm}
1585 unit of millimeter
1586 \end{datadesc}
1588 \begin{datadesc}{sec}
1589 unit of second
1590 \end{datadesc}
1592 \begin{datadesc}{minute}
1593 unit of minute
1594 \end{datadesc}
1596 \begin{datadesc}{h}
1597 unit of hour
1598 \end{datadesc}
1600 \begin{datadesc}{day}
1601 unit of day
1602 \end{datadesc}
1604 \begin{datadesc}{yr}
1605 unit of year
1606 \end{datadesc}
1608 \begin{datadesc}{gram}
1609 unit of gram
1610 \end{datadesc}
1612 \begin{datadesc}{kg}
1613 unit of kilogram
1614 \end{datadesc}
1616 \begin{datadesc}{lb}
1617 unit of pound
1618 \end{datadesc}
1620 \begin{datadesc}{ton}
1621 metric ton
1622 \end{datadesc}
1624 \begin{datadesc}{A}
1625 unit of Ampere
1626 \end{datadesc}
1628 \begin{datadesc}{Hz}
1629 unit of Hertz
1630 \end{datadesc}
1632 \begin{datadesc}{N}
1633 unit of Newton
1634 \end{datadesc}
1636 \begin{datadesc}{Pa}
1637 unit of Pascal
1638 \end{datadesc}
1640 \begin{datadesc}{atm}
1641 unit of atmosphere
1642 \end{datadesc}
1644 \begin{datadesc}{J}
1645 unit of Joule
1646 \end{datadesc}
1648 \begin{datadesc}{W}
1649 unit of Watt
1650 \end{datadesc}
1652 \begin{datadesc}{C}
1653 unit of Coulomb
1654 \end{datadesc}
1656 \begin{datadesc}{V}
1657 unit of Volt
1658 \end{datadesc}
1660 \begin{datadesc}{F}
1661 unit of Farad
1662 \end{datadesc}
1664 \begin{datadesc}{Ohm}
1665 unit of Ohm
1666 \end{datadesc}
1668 \begin{datadesc}{K}
1669 unit of degrees Kelvin
1670 \end{datadesc}
1672 \begin{datadesc}{Celsius}
1673 unit of degrees Celsius
1674 \end{datadesc}
1676 \begin{datadesc}{Fahrenheit}
1677 unit of degrees Fahrenheit
1678 \end{datadesc}
1680 \noindent Supported unit prefixes:
1682 \begin{datadesc}{Yotta}
1683 prefix yotta = $10^{24}$
1684 \end{datadesc}
1686 \begin{datadesc}{Zetta}
1687 prefix zetta = $10^{21}$
1688 \end{datadesc}
1690 \begin{datadesc}{Exa}
1691 prefix exa = $10^{18}$
1692 \end{datadesc}
1694 \begin{datadesc}{Peta}
1695 prefix peta = $10^{15}$
1696 \end{datadesc}
1698 \begin{datadesc}{Tera}
1699 prefix tera = $10^{12}$
1700 \end{datadesc}
1702 \begin{datadesc}{Giga}
1703 prefix giga = $10^9$
1704 \end{datadesc}
1706 \begin{datadesc}{Mega}
1707 prefix mega = $10^6$
1708 \end{datadesc}
1710 \begin{datadesc}{Kilo}
1711 prefix kilo = $10^3$
1712 \end{datadesc}
1714 \begin{datadesc}{Hecto}
1715 prefix hecto = $10^2$
1716 \end{datadesc}
1718 \begin{datadesc}{Deca}
1719 prefix deca = $10^1$
1720 \end{datadesc}
1722 \begin{datadesc}{Deci}
1723 prefix deci = $10^{-1}$
1724 \end{datadesc}
1726 \begin{datadesc}{Centi}
1727 prefix centi = $10^{-2}$
1728 \end{datadesc}
1730 \begin{datadesc}{Milli}
1731 prefix milli = $10^{-3}$
1732 \end{datadesc}
1734 \begin{datadesc}{Micro}
1735 prefix micro = $10^{-6}$
1736 \end{datadesc}
1738 \begin{datadesc}{Nano}
1739 prefix nano = $10^{-9}$
1740 \end{datadesc}
1742 \begin{datadesc}{Pico}
1743 prefix pico = $10^{-12}$
1744 \end{datadesc}
1746 \begin{datadesc}{Femto}
1747 prefix femto = $10^{-15}$
1748 \end{datadesc}
1750 \begin{datadesc}{Atto}
1751 prefix atto = $10^{-18}$
1752 \end{datadesc}
1754 \begin{datadesc}{Zepto}
1755 prefix zepto = $10^{-21}$
1756 \end{datadesc}
1758 \begin{datadesc}{Yocto}
1759 prefix yocto = $10^{-24}$
1760 \end{datadesc}
1762 \section{Utilities}
1763 The \class{FileWriter} class provides a mechanism to write data to a file.
1764 In essence, this class wraps the standard \PYTHON \class{file} class to write
1765 data that are global in \MPI to a file. In fact, data are written on the
1766 processor with \MPI rank 0 only. It is recommended to use \class{FileWriter}
1767 rather than \class{open} in order to write code that will run with and without
1768 \MPI. It is safe to use \class{open} under \MPI to \emph{read} data which are
1769 global under \MPI.
1771 \begin{classdesc}{FileWriter}{fn\optional{,append=\False, \optional{createLocalFiles=\False}})}
1772 Opens a file with name \var{fn} for writing. If \var{append} is set to \True
1773 data are appended at the end of the file.
1774 If running under \MPI, only the first processor (rank==0) will open the file
1775 and write to it.
1776 If \var{createLocalFiles} is set each individual processor will create a file
1777 where for any processor with rank>0 the file name is extended by its rank.
1778 This option is normally used for debugging purposes only.
1779 \end{classdesc}
1781 \noindent The following methods are available:
1782 \begin{methoddesc}[FileWriter]{close}{}
1783 closes the file.
1784 \end{methoddesc}
1785 \begin{methoddesc}[FileWriter]{flush}{}
1786 flushes the internal buffer to disk.
1787 \end{methoddesc}
1788 \begin{methoddesc}[FileWriter]{write}{txt}
1789 writes string \var{txt} to the file. Note that a newline is not added.
1790 \end{methoddesc}
1791 \begin{methoddesc}[FileWriter]{writelines}{txts}
1792 writes the list \var{txts} of strings to the file.
1793 Note that newlines are not added.
1794 This method is equivalent to calling \var{write()} for each string.
1795 \end{methoddesc}
1796 \begin{memberdesc}[FileWriter]{closed}
1797 this member is \True if the file is closed.
1798 \end{memberdesc}
1799 \begin{memberdesc}[FileWriter]{mode}
1800 holds the access mode.
1801 \end{memberdesc}
1802 \begin{memberdesc}[FileWriter]{name}
1803 holds the file name.
1804 \end{memberdesc}
1805 \begin{memberdesc}[FileWriter]{newlines}
1806 holds the line separator.
1807 \end{memberdesc}
1809 \begin{funcdesc}{setEscriptParamInt}{name,value}
1810 assigns the integer value \var{value} to the parameter \var{name}.
1811 If \var{name}="TOO_MANY_LINES" conversion of any \Data object to a string
1812 switches to a condensed format if more than \var{value} lines would be created.
1813 \end{funcdesc}
1815 \begin{funcdesc}{getEscriptParamInt}{name}
1816 returns the current value of integer parameter \var{name}.
1817 \end{funcdesc}
1819 \begin{funcdesc}{listEscriptParams}{a}
1820 returns a list of valid parameters and their description.
1821 \end{funcdesc}
1823 \begin{funcdesc}{getMPISizeWorld}{}
1824 returns the number of \MPI processors in use in the \env{MPI_COMM_WORLD} processor group.
1825 If \MPI is not used 1 is returned.
1826 \end{funcdesc}
1828 \begin{funcdesc}{getMPIRankWorld}{}
1829 returns the rank of the current process within the \env{MPI_COMM_WORLD}
1830 processor group. If \MPI is not used 0 is returned.
1831 \end{funcdesc}
1833 \begin{funcdesc}{MPIBarrierWorld}{}
1834 performs a barrier synchronization across all processors within the
1835 \env{MPI_COMM_WORLD} processor group.
1836 \end{funcdesc}
1838 \begin{funcdesc}{getMPIWorldMax}{a}
1839 returns the maximum value of the integer \var{a} across all processors within
1840 \env{MPI_COMM_WORLD}.
1841 \end{funcdesc}


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

  ViewVC Help
Powered by ViewVC 1.1.26