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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6721 - (show annotations)
Wed Sep 26 05:58:38 2018 UTC (6 months, 3 weeks ago) by aellery
File MIME type: application/x-tex
File size: 85047 byte(s)
getNumpy now supports complex Data. I have also added a new section to the documentation (3.2.11) that describes how the getNumpy function works.


1
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 % Copyright (c) 2003-2018 by The University of Queensland
4 % http://www.uq.edu.au
5 %
6 % Primary Business: Queensland, Australia
7 % Licensed under the Apache License, version 2.0
8 % http://www.apache.org/licenses/LICENSE-2.0
9 %
10 % Development until 2012 by Earth Systems Science Computational Center (ESSCC)
11 % Development 2012-2013 by School of Earth Sciences
12 % Development from 2014 by Centre for Geoscience Computing (GeoComp)
13 %
14 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
15
16 \chapter{The \escript Module}\label{ESCRIPT CHAP}
17
18 \section{Concepts}
19 \escript is a \PYTHON module that allows you to represent the values of
20 a function at points in a \Domain in such a way that the function will
21 be useful for the Finite Element Method (FEM) simulation. It also
22 provides what we call a function space that describes how the data is
23 used in the simulation. Stored along with the data is information
24 about the elements and nodes which will be used by the domain (e.g. \finley).
25
26 \subsection{Function spaces}
27 In order to understand what we mean by the term 'function space',
28 consider that the solution of a partial differential
29 equation\index{partial differential equation} (PDE) is a function on a domain
30 $\Omega$. When solving a PDE using FEM, the solution is
31 piecewise-differentiable but, in general, its gradient is discontinuous.
32 To reflect these different degrees of smoothness, different function spaces
33 are used.
34 For instance, in FEM, the displacement field is represented by its values at
35 the nodes of the mesh, and so is continuous.
36 The strain, which is the symmetric part of the gradient of the displacement
37 field, is stored on the element centers, and so is considered to be
38 discontinuous.
39
40 A function space is described by a \FunctionSpace object.
41 The following statement generates the object \var{solution_space} which is
42 a \FunctionSpace object and provides access to the function space of
43 PDE solutions on the \Domain \var{mydomain}:
44
45 \begin{python}
46 solution_space=Solution(mydomain)
47 \end{python}
48 The following generators for function spaces on a \Domain \var{mydomain} are commonly used:
49 \begin{itemize}
50 \item \var{Solution(mydomain)}: solutions of a PDE
51 \item \var{ReducedSolution(mydomain)}: solutions of a PDE with a reduced
52 smoothness requirement, e.g. using a lower order approximation on the same
53 element or using macro elements\index{macro elements}
54 \item \var{ContinuousFunction(mydomain)}: continuous functions, e.g. a temperature distribution
55 \item \var{Function(mydomain)}: general functions which are not necessarily continuous, e.g. a stress field
56 \item \var{FunctionOnBoundary(mydomain)}: functions on the boundary of the domain, e.g. a surface pressure
57 \item \var{DiracDeltaFunctions(mydomain)}: functions defined on a set of points
58 \item \var{FunctionOnContact0(mydomain)}: functions on side $0$ of a discontinuity
59 \item \var{FunctionOnContact1(mydomain)}: functions on side $1$ of a discontinuity
60 \end{itemize}
61 In some cases under-integration is used. For these cases the user may use a
62 \FunctionSpace from the following list:
63 \begin{itemize}
64 \item \var{ReducedFunction(mydomain)}
65 \item \var{ReducedFunctionOnBoundary(mydomain)}
66 \item \var{ReducedFunctionOnContact0(mydomain)}
67 \item \var{ReducedFunctionOnContact1(mydomain)}
68 \end{itemize}
69 In comparison to the corresponding full version they use a reduced number of
70 integration nodes (typically one only) to represent values.
71
72 \begin{figure}
73 \centering
74 \scalebox{0.97}{\includegraphics{EscriptDiagram1}}
75 \caption{\label{ESCRIPT DEP}Dependency of function spaces in \finley.
76 An arrow indicates that a function in the \FunctionSpace at the starting point
77 can be interpolated to the \FunctionSpace of the arrow target.
78 All function spaces above the dotted line can be interpolated to any of
79 the function spaces below the line. See also \Sec{SEC Projection}.}
80 \end{figure}
81
82 The reduced smoothness for a PDE solution is often used to fulfill the
83 Ladyzhenskaya-Babuska-Brezzi condition~\cite{LBB} when solving saddle point
84 problems\index{saddle point problems}, e.g. the Stokes equation.
85 A discontinuity\index{discontinuity} is a region within the domain across
86 which functions may be discontinuous.
87 The location of a discontinuity is defined in the \Domain object.
88 \fig{ESCRIPT DEP} shows the dependency between the types of function spaces
89 in \finley (other libraries may have different relationships).
90
91 The solution of a PDE is a continuous function. Any continuous function can
92 be seen as a general function on the domain and can be restricted to the
93 boundary as well as to one side of a discontinuity (the result will be
94 different depending on which side is chosen). Functions on any side of the
95 discontinuity can be seen as a function on the corresponding other side.
96
97 A function on the boundary or on one side of the discontinuity cannot be seen
98 as a general function on the domain as there are no values defined for the
99 interior. For most PDE solver libraries the space of the solution and
100 continuous functions is identical, however in some cases, for example when
101 periodic boundary conditions are used in \finley, a solution fulfills periodic
102 boundary conditions while a continuous function does not have to be periodic.
103
104 The concept of function spaces describes the properties of functions and
105 allows abstraction from the actual representation of the function in the
106 context of a particular application. For instance, in the FEM context a
107 function of the \Function type (written as \emph{Function()} in \fig{ESCRIPT DEP})
108 is usually represented by its values at the element center,
109 but in a finite difference scheme the edge midpoint of cells is preferred.
110 By changing its function space you can use the same function in a Finite
111 Difference scheme instead of Finite Element scheme.
112 Changing the function space of a particular function will typically lead to
113 a change of its representation.
114 So, when seen as a general function, a continuous function which is typically
115 represented by its values on the nodes of the FEM mesh or finite difference
116 grid must be interpolated to the element centers or the cell edges,
117 respectively. Interpolation happens automatically in \escript whenever it is
118 required\index{interpolation}. The user needs to be aware that an
119 interpolation is not always possible, see \fig{ESCRIPT DEP} for \finley.
120 An alternative approach to change the representation (=\FunctionSpace) is
121 projection\index{projection}, see \Sec{SEC Projection}.
122
123 \subsection{\Data Objects}
124 In \escript the class that stores these functions is called \Data.
125 The function is represented through its values on \DataSamplePoints where
126 the \DataSamplePoints are chosen according to the function space of the
127 function.
128 \Data class objects are used to define the coefficients of the PDEs to be
129 solved by a PDE solver library and also to store the solutions of the PDE.
130
131 The values of the function have a rank which gives the number of indices,
132 and a \Shape defining the range of each index.
133 The rank in \escript is limited to the range 0 through 4 and it is assumed
134 that the rank and \Shape is the same for all \DataSamplePoints.
135 The \Shape of a \Data object is a tuple (list) \var{s} of integers.
136 The length of \var{s} is the rank of the \Data object and the \var{i}-th
137 index ranges between 0 and $\var{s[i]}-1$.
138 For instance, a stress field has rank 2 and \Shape $(d,d)$ where $d$ is the
139 number of spatial dimensions.
140 The following statement creates the \Data object \var{mydat} representing a
141 continuous function with values of \Shape $(2,3)$ and rank $2$:
142 \begin{python}
143 mydat=Data(value=1, what=ContinuousFunction(myDomain), shape=(2,3))
144 \end{python}
145 The initial value is the constant 1 for all \DataSamplePoints and all
146 components.
147
148 \Data objects can also be created from any \numpy array or any object, such
149 as a list of floating point numbers, that can be converted into
150 a \numpyNDA\cite{NUMPY}.
151 The following two statements create objects which are equivalent
152 to \var{mydat}:
153 \begin{python}
154 mydat1=Data(value=numpy.ones((2,3)), what=ContinuousFunction(myDomain))
155 mydat2=Data(value=[[1,1], [1,1], [1,1]], what=ContinuousFunction(myDomain))
156 \end{python}
157 In the first case the initial value is \var{numpy.ones((2,3))} which generates
158 a $2 \times 3$ matrix as an instance of \numpyNDA filled with ones.
159 The \Shape of the created \Data object is taken from the \Shape of the array.
160 In the second case, the creator converts the initial value, which is a list of
161 lists, into a \numpyNDA before creating the actual \Data object.
162
163 For convenience \escript provides creators for the most common types
164 of \Data objects in the following forms (\var{d} defines the spatial
165 dimensionality):
166 \begin{itemize}
167 \item \code{Scalar(0, Function(mydomain))} is the same as \code{Data(0, Function(myDomain),(,))}\\
168 (each value is a scalar), e.g. a temperature field
169 \item \code{Vector(0, Function(mydomain))} is the same as \code{Data(0, Function(myDomain),(d,))}\\
170 (each value is a vector), e.g. a velocity field
171 \item \code{Tensor(0, Function(mydomain))} equals \code{Data(0, Function(myDomain), (d,d))},
172 e.g. a stress field
173 \item \code{Tensor4(0,Function(mydomain))} equals \code{Data(0,Function(myDomain), (d,d,d,d))},
174 e.g. a Hook tensor field
175 \end{itemize}
176 Here the initial value is 0 but any object that can be converted into
177 a \numpyNDA and whose \Shape is consistent with \Shape of the \Data object to
178 be created can be used as the initial value.
179
180 \Data objects can be manipulated by applying unary operations (e.g. cos, sin,
181 log), and they can be combined point-wise by applying arithmetic operations
182 (e.g. +, - ,* , /).
183 We emphasize that \escript itself does not handle any spatial dependencies as
184 it does not know how values are interpreted by the processing PDE solver library.
185 However \escript invokes interpolation if this is needed during data manipulations.
186 Typically, this occurs in binary operations when the arguments belong to
187 different function spaces or when data are handed over to a PDE solver library
188 which requires functions to be represented in a particular way.
189
190 The following example shows the usage of \Data objects. Assume we have a
191 displacement field $u$ and we want to calculate the corresponding stress field
192 $\sigma$ using the linear-elastic isotropic material model
193 \begin{eqnarray}\label{eq: linear elastic stress}
194 \sigma_{ij}=\lambda u_{k,k} \delta_{ij} + \mu ( u_{i,j} + u_{j,i})
195 \end{eqnarray}
196 where $\delta_{ij}$ is the Kronecker symbol and
197 $\lambda$ and $\mu$ are the Lam\'e coefficients. The following function
198 takes the displacement \var{u} and the Lam\'e coefficients \var{lam} and \var{mu}
199 as arguments and returns the corresponding stress:
200 \begin{python}
201 from esys.escript import *
202 def getStress(u, lam, mu):
203 d=u.getDomain().getDim()
204 g=grad(u)
205 stress=lam*trace(g)*kronecker(d)+mu*(g+transpose(g))
206 return stress
207 \end{python}
208 The variable \var{d} gives the spatial dimensionality of the domain on which
209 the displacements are defined.
210 The \code{kronecker(d)} call, returns the Kronecker symbol with indices $i$ and $j$ running
211 from 0 to \var{d}-1.
212 The \var{grad(u)} call, requires the displacement field \var{u} to be in
213 the \var{Solution} or \ContinuousFunction.
214 The result \var{g} as well as the returned stress will be in the \Function.
215 If, for example, \var{u} is the solution of a PDE then \code{getStress} might
216 be called in the following way:
217 \begin{python}
218 s=getStress(u, 1., 2.)
219 \end{python}
220 However \code{getStress} can also be called with \Data objects as values for
221 \var{lam} and \var{mu} which, for instance in the case of a temperature
222 dependency, are calculated by an expression.
223 The following call is equivalent to the previous example:
224 \begin{python}
225 lam=Scalar(1., ContinuousFunction(mydomain))
226 mu=Scalar(2., Function(mydomain))
227 s=getStress(u, lam, mu)
228 \end{python}
229 %
230 The function \var{lam} belongs to the \ContinuousFunction but with \var{g} the
231 function \var{trace(g)} is in the \Function.
232 In the evaluation of the product \var{lam*trace(g)} we have different function
233 spaces (on the nodes versus in the centers) and at first glance we have incompatible data.
234 \escript converts the arguments into an appropriate function space according
235 to \fig{ESCRIPT DEP}.
236 In this example that means \escript sees \var{lam} as a function of the \Function.
237 In the context of FEM this means the nodal values of \var{lam} are
238 interpolated to the element centers.
239 The interpolation is automatic and requires no special handling.
240
241 \begin{figure}
242 \centering
243 \includegraphics{EscriptDiagram2}
244 \caption{\label{Figure: tag}Element Tagging. A rectangular mesh over a region
245 with two rock types {\it white} and {\it gray} is shown.
246 The number in each cell refers to the major rock type present in the cell
247 ($1$ for {\it white} and $2$ for {\it gray}).}
248 \end{figure}
249
250 \subsection{Tagged, Expanded and Constant Data}
251 Material parameters such as the Lam\'e coefficients are typically dependent on
252 rock types present in the area of interest.
253 A common technique to handle these kinds of material parameters is
254 \emph{tagging}\index{tagging}, which uses storage efficiently.
255 \fig{Figure: tag} shows an example. In this case two rock types {\it white}
256 and {\it gray} can be found in the domain.
257 The domain is subdivided into triangular shaped cells.
258 Each cell has a tag indicating the rock type predominantly found in this cell.
259 Here $1$ is used to indicate rock type {\it white} and $2$ for rock type {\it gray}.
260 The tags are assigned at the time when the cells are generated and stored in
261 the \Domain class object. To allow easier usage of tags, names can be used
262 instead of numbers. These names are typically defined at the time when the
263 geometry is generated.
264
265 The following statements show how to use tagged values for \var{lam} as shown
266 in \fig{Figure: tag} for the stress calculation discussed above:
267 \begin{python}
268 lam=Scalar(value=2., what=Function(mydomain))
269 insertTaggedValue(lam, white=30., gray=5000.)
270 s=getStress(u, lam, 2.)
271 \end{python}
272 In this example \var{lam} is set to $30$ for those cells with tag {\it white}
273 (=$1$) and to $5000$ for cells with tag {\it gray} (=$2$).
274 The initial value $2$ of \var{lam} is used as a default value for the case
275 when a tag is encountered which has not been linked with a value.
276 The \code{getStress} method does not need to be changed now that we are using tags.
277 \escript resolves the tags when \var{lam*trace(g)} is calculated.
278
279 This brings us to a very important point about \escript.
280 You can develop a simulation with constant Lam\'e coefficients, and then later
281 switch to tagged Lam\'e coefficients without otherwise changing your \PYTHON script.
282 In short, you can use the same script for models with different domains and
283 different types of input data.
284
285 There are three main ways in which \Data objects are represented internally --
286 constant, tagged, and expanded.
287 In the constant case, the same value is used at each sample point while only a
288 single value is stored to save memory.
289 In the expanded case, each sample point has an individual value (such as for the solution of a PDE).
290 This is where your largest data sets will be created because the values are
291 stored as a complete array.
292 The tagged case has already been discussed above.
293 Expanded data is created when specifying \code{expanded=True} in the \Data
294 object constructor, while tagged data requires calling the \member{insertTaggedValue}
295 method as shown above.
296
297 Values are accessed through a sample reference number.
298 Operations on expanded \Data objects have to be performed for each sample
299 point individually.
300 When tagged values are used, the values are held in a dictionary.
301 Operations on tagged data require processing the set of tagged values only,
302 rather than processing the value for each individual sample point.
303 \escript allows any mixture of constant, tagged and expanded data in a single expression.
304
305 \subsection{Saving and Restoring Simulation Data}
306 \Data objects can be written to disk files with the \member{dump} method and
307 read back using the \member{load} method, both of which use the
308 \netCDF\cite{NETCDF} file format.
309 Use these to save data for checkpoint/restart or simply to save and reuse data
310 that was expensive to compute.
311 For instance, to save the coordinates of the data points of a
312 \ContinuousFunction to the file \file{x.nc} use
313 \begin{python}
314 x=ContinuousFunction(mydomain).getX()
315 x.dump("x.nc")
316 mydomain.dump("dom.nc")
317 \end{python}
318 To recover the object \var{x}, and you know that \var{mydomain} was an \finley
319 mesh, use
320 \begin{python}
321 from esys.finley import LoadMesh
322 mydomain=LoadMesh("dom.nc")
323 x=load("x.nc", mydomain)
324 \end{python}
325 Obviously, it is possible to execute the same steps that were originally used
326 to generate \var{mydomain} to recreate it. However, in most cases using
327 \member{dump} and \member{load} is faster, particularly if optimization has
328 been applied.
329 If \escript is running on more than one \MPI process \member{dump} will create
330 an individual file for each process containing the local data.
331 In order to avoid conflicts the \MPI processor
332 rank is appended to the file names.
333 That is instead of one file \file{dom.nc} you would get
334 \file{dom.nc.0000}, \file{dom.nc.0001}, etc.
335 You still call \code{LoadMesh("dom.nc")} to load the domain but you have to
336 make sure that the appropriate file is accessible from the corresponding rank,
337 and loading will only succeed if you run with as many processes as were used
338 when calling \member{dump}.
339
340 The function space of the \Data is stored in \file{x.nc}.
341 If the \Data object is expanded, the number of data points in the file and of
342 the \Domain for the particular \FunctionSpace must match.
343 Moreover, the ordering of the values is checked using the reference
344 identifiers provided by the \FunctionSpace on the \Domain.
345 In some cases, data points will be reordered so be aware and confirm that you
346 get what you wanted.
347
348 A more flexible way of saving and restoring \escript simulation data
349 is through an instance of the \class{DataManager} class.
350 It has the advantage of allowing to save and load not only a \Domain and
351 \Data objects but also other values\footnote{The \PYTHON \emph{pickle} module
352 is used for other types.} you compute in your simulation script.
353 Further, \class{DataManager} objects can simultaneously create files for
354 visualization so no extra calls to \code{saveVTK} etc. are needed.
355
356 The following example shows how the \class{DataManager} class can be used.
357 For an explanation of all member functions and options see the class reference
358 Section \ref{sec:datamanager}.
359 \begin{python}
360 from esys.escript import DataManager, Scalar, Function
361 from esys.finley import Rectangle
362
363 dm = DataManager(formats=[DataManager.RESTART, DataManager.VTK])
364 if dm.hasData():
365 mydomain=dm.getDomain()
366 val=dm.getValue("val")
367 t=dm.getValue("t")
368 t_max=dm.getValue("t_max")
369 else:
370 mydomain=Rectangle()
371 val=Function(mydomain).getX()
372 t=0.
373 t_max=2.5
374
375 while t<t_max:
376 t+=.01
377 val=val+t/2
378 dm.addData(val=val, t=t, t_max=t_max)
379 dm.export()
380 \end{python}
381 In the constructor we specify that we want \code{RESTART} (i.e. dump) files
382 and \code{VTK} files to be saved.
383 By default, the constructor will look for previously saved \code{RESTART}
384 files under the current directory and load them.
385 We can then enquire if such files were found by calling the \member{hasData}
386 method. If it returns \True we retrieve the domain and values into local
387 variables. Otherwise the same variables are initialized with appropriate
388 values to start a new simulation.
389 Note, that \var{t} and \var{t_max} are regular floating point values and not
390 \Data objects. Yet they are treated the same way by the \class{DataManager}.
391
392 After this initialization step the script enters the main simulation loop
393 where calculations are performed.
394 When these are finalized for a time step we call the \member{addData} method
395 to let the manager know which variables to store on disk.
396 This does not actually save the data yet and it is allowed to call
397 \member{addData} more than once to add information incrementally, e.g. from
398 separate functions that have access to the \class{DataManager} instance.
399 Once all variables have been added the \member{export} method has to be called
400 to flush all data to disk and clear the manager.
401 In this example, this call dumps \var{mydomain} and \var{val} to files
402 in a restart directory and also stores \var{t} and \var{t_max} on disk.
403 Additionally, it generates a \VTK file for visualization of the data.
404 If the script would stop running before its completion for some reason (e.g.
405 because its runtime limit was exceeded in a batch job environment), you could
406 simply run it again and it would resume at the point it stopped before.
407
408 \section{\escript Classes}
409
410 \subsection{The \Domain class}
411 \begin{classdesc}{Domain}{}
412 A \Domain object is used to describe a geometric region together with
413 a way of representing functions over this region.
414 The \Domain class provides an abstract interface to the domain of \FunctionSpace and \Data objects.
415 \Domain needs to be subclassed in order to provide a complete implementation.
416 \end{classdesc}
417
418 \vspace{1em}\noindent The following methods are available:
419 \begin{methoddesc}[Domain]{getDim}{}
420 returns the number of spatial dimensions of the \Domain.
421 \end{methoddesc}
422 %
423 \begin{methoddesc}[Domain]{dump}{filename}
424 writes the \Domain to the file \var{filename} using the \netCDF file format.
425 \end{methoddesc}
426 %
427 \begin{methoddesc}[Domain]{getX}{}
428 returns the locations in the \Domain. The \FunctionSpace of the returned
429 \Data object is chosen by the \Domain implementation. Typically it will be
430 in the \ContinuousFunction.
431 \end{methoddesc}
432 %
433 \begin{methoddesc}[Domain]{setX}{newX}
434 assigns new locations to the \Domain. \var{newX} has to have \Shape $(d,)$
435 where $d$ is the spatial dimensionality of the domain. Typically \var{newX}
436 must be in the \ContinuousFunction but the space actually to be used
437 depends on the \Domain implementation. Not all domain families support
438 setting locations.
439 \end{methoddesc}
440 %
441 \begin{methoddesc}[Domain]{getNormal}{}
442 returns the surface normals on the boundary of the \Domain as a \Data object.
443 \end{methoddesc}
444 %
445 \begin{methoddesc}[Domain]{getSize}{}
446 returns the local sample size, i.e. the element diameter, as a \Data object.
447 \end{methoddesc}
448 %
449 \begin{methoddesc}[Domain]{setTagMap}{tag_name, tag}
450 defines a mapping of the tag name \var{tag_name} to the \var{tag}.
451 \end{methoddesc}
452 %
453 \begin{methoddesc}[Domain]{getTag}{tag_name}
454 returns the tag associated with the tag name \var{tag_name}.
455 \end{methoddesc}
456 %
457 \begin{methoddesc}[Domain]{isValidTagName}{tag_name}
458 returns \True if \var{tag_name} is a valid tag name.
459 \end{methoddesc}
460 %
461 \begin{methoddesc}[Domain]{__eq__}{arg}
462 (\PYTHON \var{==} operator) returns \True if the \Domain \var{arg}
463 describes the same domain, \False otherwise.
464 \end{methoddesc}
465 %
466 \begin{methoddesc}[Domain]{__ne__}{arg}
467 (\PYTHON \var{!=} operator) returns \True if the \Domain \var{arg} does
468 not describe the same domain, \False otherwise.
469 \end{methoddesc}
470 %
471 \begin{methoddesc}[Domain]{__str__}{}
472 (\PYTHON \var{str()} function) returns a string representation of the
473 \Domain.
474 \end{methoddesc}
475 %
476 \begin{methoddesc}[Domain]{onMasterProcessor}{}
477 returns \True if the process is the master process within the \MPI
478 process group used by the \Domain. This is the process with rank 0.
479 If \MPI support is not enabled the return value is always \True.
480 \end{methoddesc}
481 %
482 \begin{methoddesc}[Domain]{getMPISize}{}
483 returns the number of \MPI processes used for this \Domain. If \MPI
484 support is not enabled 1 is returned.
485 \end{methoddesc}
486 %
487 \begin{methoddesc}[Domain]{getMPIRank}{}
488 returns the rank of the process executing the statement within the
489 \MPI process group used by the \Domain. If \MPI support is not enabled
490 0 is returned.
491 \end{methoddesc}
492 %
493 \begin{methoddesc}[Domain]{MPIBarrier}{}
494 executes barrier synchronization within the \MPI process group used by
495 the \Domain. If \MPI support is not enabled, this command does nothing.
496 \end{methoddesc}
497
498 \subsection{The \FunctionSpace class}
499 \begin{classdesc}{FunctionSpace}{}
500 \FunctionSpace objects, which are instantiated by generator functions, are
501 used to define properties of \Data objects such as continuity.
502 A \Data object in a particular \FunctionSpace is represented by its values at
503 \DataSamplePoints which are defined by the type and the \Domain of the \FunctionSpace.
504 \end{classdesc}
505
506 \vspace{1em}\noindent The following methods are available:
507 %
508 \begin{methoddesc}[FunctionSpace]{getDim}{}
509 returns the spatial dimensionality of the \Domain of the \FunctionSpace.
510 \end{methoddesc}
511 %
512 \begin{methoddesc}[FunctionSpace]{getX}{}
513 returns the location of the \DataSamplePoints.
514 \end{methoddesc}
515 %
516 \begin{methoddesc}[FunctionSpace]{getNormal}{}
517 If the domain of functions in the \FunctionSpace is a hyper-manifold (e.g.
518 the boundary of a domain) the method returns the outer normal at each of
519 the \DataSamplePoints. Otherwise an exception is raised.
520 \end{methoddesc}
521 %
522 \begin{methoddesc}[FunctionSpace]{getSize}{}
523 returns a \Data object measuring the spacing of the \DataSamplePoints.
524 The size may be zero.
525 \end{methoddesc}
526 %
527 \begin{methoddesc}[FunctionSpace]{getDomain}{}
528 returns the \Domain of the \FunctionSpace.
529 \end{methoddesc}
530 %
531 \begin{methoddesc}[FunctionSpace]{setTags}{new_tag, mask}
532 assigns a new tag \var{new_tag} to all data samples where \var{mask} is
533 positive for a least one data point.
534 \var{mask} must be defined on this \FunctionSpace.
535 Use the \var{setTagMap} to assign a tag name to \var{new_tag}.
536 \end{methoddesc}
537 %
538 \begin{methoddesc}[FunctionSpace]{__eq__}{arg}
539 (\PYTHON \var{==} operator) returns \True if the \FunctionSpace \var{arg}
540 describes the same function space, \False otherwise.
541 \end{methoddesc}
542 %
543 \begin{methoddesc}[FunctionSpace]{__ne__}{arg}
544 (\PYTHON \var{!=} operator) returns \True if the \FunctionSpace \var{arg}
545 does not describe the same function space, \False otherwise.
546 \end{methoddesc}
547
548 \begin{methoddesc}[Domain]{__str__}{}
549 (\PYTHON \var{str()} function) returns a string representation of the
550 \FunctionSpace.
551 \end{methoddesc}
552
553 \noindent The following functions provide generators for \FunctionSpace objects:
554
555 \begin{funcdesc}{Function}{domain}
556 returns the \Function on the \Domain \var{domain}. \Data objects in this
557 type of \Function are defined over the whole geometric region defined by
558 \var{domain}.
559 \end{funcdesc}
560 %
561 \begin{funcdesc}{ContinuousFunction}{domain}
562 returns the \ContinuousFunction on the \Domain domain. \Data objects in
563 this type of \Function are defined over the whole geometric region defined
564 by \var{domain} and assumed to represent a continuous function.
565 \end{funcdesc}
566 %
567 \begin{funcdesc}{FunctionOnBoundary}{domain}
568 returns the \FunctionOnBoundary on the \Domain domain. \Data objects in
569 this type of \Function are defined on the boundary of the geometric region
570 defined by \var{domain}.
571 \end{funcdesc}
572 %
573 \begin{funcdesc}{FunctionOnContactZero}{domain}
574 returns the \FunctionOnContactZero the \Domain domain. \Data objects in
575 this type of \Function are defined on side 0 of a discontinuity within
576 the geometric region defined by \var{domain}.
577 The discontinuity is defined when \var{domain} is instantiated.
578 \end{funcdesc}
579 %
580 \begin{funcdesc}{FunctionOnContactOne}{domain}
581 returns the \FunctionOnContactOne on the \Domain domain. \Data objects in
582 this type of \Function are defined on side 1 of a discontinuity within
583 the geometric region defined by \var{domain}.
584 The discontinuity is defined when \var{domain} is instantiated.
585 \end{funcdesc}
586 %
587 \begin{funcdesc}{Solution}{domain}
588 returns the \SolutionFS on the \Domain domain. \Data objects in this type
589 of \Function are defined on the geometric region defined by \var{domain}
590 and are solutions of partial differential equations\index{partial differential equation}.
591 \end{funcdesc}
592 %
593 \begin{funcdesc}{ReducedSolution}{domain}
594 returns the \ReducedSolutionFS on the \Domain domain. \Data objects in
595 this type of \Function are defined on the geometric region defined by
596 \var{domain} and are solutions of partial differential
597 equations\index{partial differential equation} with a reduced smoothness
598 for the solution approximation.
599 \end{funcdesc}
600
601 \subsection{The \Data Class}
602 \label{SEC ESCRIPT DATA}
603
604 The following table shows arithmetic operations that can be performed
605 point-wise on \Data objects:
606 \begin{center}
607 \begin{tabular}{l|l}
608 \textbf{Expression} & \textbf{Description}\\
609 \hline
610 \code{+arg} & identical to \var{arg}\index{+}\\
611 \code{-arg} & negation of \var{arg}\index{-}\\
612 \code{arg0+arg1} & adds \var{arg0} and \var{arg1}\index{+}\\
613 \code{arg0*arg1} & multiplies \var{arg0} and \var{arg1}\index{*}\\
614 \code{arg0-arg1} & subtracts \var{arg1} from \var{arg0}\index{-}\\
615 \code{arg0/arg1} & divides \var{arg0} by \var{arg1}\index{/}\\
616 \code{arg0**arg1} & raises \var{arg0} to the power of \var{arg1}\index{**}\\
617 \end{tabular}
618 \end{center}
619 At least one of the arguments \var{arg0} or \var{arg1} must be a \Data object.
620 Either of the arguments may be a \Data object, a \PYTHON number or a \numpy
621 object.
622 If \var{arg0} or \var{arg1} are not defined on the same \FunctionSpace, then
623 an attempt is made to convert \var{arg0} to the \FunctionSpace of \var{arg1}
624 or to convert \var{arg1} to \var{arg0}'s \FunctionSpace.
625 Both arguments must have the same \Shape or one of the arguments may be of
626 rank 0 (a constant).
627 The returned \Data object has the same \Shape and is defined on
628 the \DataSamplePoints as \var{arg0} or \var{arg1}.
629
630 The following table shows the update operations that can be applied to
631 \Data objects:
632 \begin{center}
633 \begin{tabular}{l|l}
634 \textbf{Expression} & \textbf{Description}\\
635 \hline
636 \code{arg0+=arg1} & adds \var{arg1} to \var{arg0}\index{+}\\
637 \code{arg0*=arg1} & multiplies \var{arg0} by \var{arg1}\index{*}\\
638 \code{arg0-=arg1} & subtracts \var{arg1} from\var{arg0}\index{-}\\
639 \code{arg0/=arg1} & divides \var{arg0} by \var{arg1}\index{/}\\
640 \code{arg0**=arg1} & raises \var{arg0} to the power of \var{arg1}\index{**}\\
641 \end{tabular}
642 \end{center}
643 \var{arg0} must be a \Data object. \var{arg1} must be a \Data object or an
644 object that can be converted into a \Data object.
645 \var{arg1} must have the same \Shape as \var{arg0} or have rank 0.
646 In the latter case it is assumed that the values of \var{arg1} are constant
647 for all components. \var{arg1} must be defined in the same \FunctionSpace as
648 \var{arg0} or it must be possible to interpolate \var{arg1} onto the
649 \FunctionSpace of \var{arg0}.
650
651 The \Data class supports taking slices as well as assigning new values to a
652 slice of an existing \Data object\index{slicing}.
653 The following expressions for taking and setting slices are valid:
654 \begin{center}
655 \begin{tabular}{l|ll}
656 \textbf{Rank of \var{arg}} & \textbf{Slicing expression} & \textbf{\Shape of returned and assigned object}\\
657 \hline
658 0 & no slicing & N/A\\
659 1 & \var{arg[l0:u0]} & (\var{u0}-\var{l0},)\\
660 2 & \var{arg[l0:u0,l1:u1]} & (\var{u0}-\var{l0},\var{u1}-\var{l1})\\
661 3 & \var{arg[l0:u0,l1:u1,l2:u2]} & (\var{u0}-\var{l0},\var{u1}-\var{l1},\var{u2}-\var{l2})\\
662 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})\\
663 \end{tabular}
664 \end{center}
665 Let \var{s} be the \Shape of \var{arg}, then
666 \begin{align*}
667 0 \le \var{l0} \le \var{u0} \le \var{s[0]},\\
668 0 \le \var{l1} \le \var{u1} \le \var{s[1]},\\
669 0 \le \var{l2} \le \var{u2} \le \var{s[2]},\\
670 0 \le \var{l3} \le \var{u3} \le \var{s[3]}.
671 \end{align*}
672 Any of the lower indexes \var{l0}, \var{l1}, \var{l2} and \var{l3} may not be
673 present in which case $0$ is assumed.
674 Any of the upper indexes \var{u0}, \var{u1}, \var{u2} and \var{u3} may be
675 omitted, in which case the upper limit for that dimension is assumed.
676 The lower and upper index may be identical in which case the column and the
677 lower or upper index may be dropped.
678 In the returned or in the object assigned to a slice, the corresponding
679 component is dropped, i.e. the rank is reduced by one in comparison to \var{arg}.
680 The following examples show slicing in action:
681 \begin{python}
682 t=Data(1., (4,4,6,6), Function(mydomain))
683 t[1,1,1,0]=9.
684 s=t[:2,:,2:6,5] # s has rank 3
685 s[:,:,1]=1.
686 t[:2,:2,5,5]=s[2:4,1,:2]
687 \end{python}
688
689
690 \subsection{Generation of \Data objects}
691 \begin{classdesc}{Data}{value=0, shape=(,), what=FunctionSpace(), expanded=\False}
692 creates a \Data object with \Shape \var{shape} in the \FunctionSpace \var{what}.
693 The values at all \DataSamplePoints are set to the double value \var{value}.
694 If \var{expanded} is \True the \Data object is represented in expanded form.
695 \end{classdesc}
696
697 \begin{classdesc}{Data}{value, what=FunctionSpace(), expanded=\False}
698 creates a \Data object in the \FunctionSpace \var{what}.
699 The value for each data sample point is set to \var{value}, which could be a
700 \numpy object, \Data object or a dictionary of \numpy or floating point
701 numbers. In the latter case the keys must be integers and are used as tags.
702 The \Shape of the returned object is equal to the \Shape of \var{value}.
703 If \var{expanded} is \True the \Data object is represented in expanded form.
704 \end{classdesc}
705
706 \begin{classdesc}{Data}{}
707 creates an \EmptyData object. The \EmptyData object is used to indicate that
708 an argument is not present where a \Data object is required.
709 \end{classdesc}
710
711 \begin{funcdesc}{Scalar}{value=0., what=FunctionSpace(), expanded=\False}
712 returns a \Data object of rank 0 (a constant) in the \FunctionSpace \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}
716
717 \begin{funcdesc}{Vector}{value=0., what=FunctionSpace(), expanded=\False}
718 returns a \Data object of \Shape \var{(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}
723
724 \begin{funcdesc}{Tensor}{value=0., what=FunctionSpace(), expanded=\False}
725 returns a \Data object of \Shape \var{(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}
730
731 \begin{funcdesc}{Tensor3}{value=0., what=FunctionSpace(), expanded=\False}
732 returns a \Data object of \Shape \var{(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}
737
738 \begin{funcdesc}{Tensor4}{value=0., what=FunctionSpace(), expanded=\False}
739 returns a \Data object of \Shape \var{(d,d,d,d)} in the \FunctionSpace \var{what},
740 where \var{d} is the spatial dimension of the \Domain of \var{what}.
741 Values are initialized with \var{value}, a double precision quantity.
742 If \var{expanded} is \True the \Data object is represented in expanded form.
743 \end{funcdesc}
744
745 \begin{funcdesc}{load}{filename, domain}
746 recovers a \Data object on \Domain \var{domain} from the file \var{filename},
747 which was created by \function{dump}.
748 \end{funcdesc}
749
750 \subsection{Generating random \Data objects}
751 A \Data object filled with random values can be produced using the
752 \function{RandomData} function.
753 By default values are drawn uniformly at random from the interval $[0,1]$ (i.e.
754 including end points).
755 The function takes a shape for the data points and a \FunctionSpace for the new
756 \Data as arguments.
757 For example:
758 \begin{python}
759 from esys.finley import *
760 from esys.escript import *
761
762 domain=Rectangle(11,11)
763 fs=ContinuousFunction(domain)
764 d=RandomData((), fs)
765 \end{python}
766 would result in \var{d} being filled with scalar random data since \texttt{()}
767 is an empty tuple.
768
769 \begin{python}
770 from esys.finley import *
771 from esys.escript import *
772
773 domain=Rectangle(11,11)
774 fs=ContinuousFunction(domain)
775 d=RandomData((2,2), fs)
776 \end{python}
777 would give \var{d} the same number of data points, but each point would be a
778 $2\times 2$ matrix instead of a scalar.
779
780 By default, the seed used to generate the random values will be different each
781 time.
782 If required, you can specify a seed to ensure the same sequence is produced.
783 \begin{python}
784 from esys.dudley import *
785 from esys.escript import *
786
787 seed=-17171717
788 domain=Brick(10,10,10)
789 fs=Function(domain)
790 d=RandomData((2,2), fs, seed)
791 \end{python}
792
793 The \var{seed} can be any integer value\footnote{which can be converted to a
794 C++ long} but 0 is special.
795 A seed of zero will cause \escript to use a different seed each time.
796 Also, note that the mechanism used to produce the random values could be
797 different in different releases.
798
799 \noindent\textbf{Note for MPI users:}
800 \textsl{
801 Even if you specify a seed, you will only get the same results if you are running with the same
802 number of ranks.
803 If you change the number of ranks, you will get different values for the same seed.
804 }
805
806 \subsubsection{Smoothed randoms}
807 The \ripley domains (see Chapter \ref{chap:ripley}) support generating random
808 scalars which are smoothed using Gaussian blur.
809 To use this, you need to supply the radius of the filter kernel (in elements)
810 and the \var{sigma} value used in the filter.
811 For example:
812 \begin{python}
813 from esys.ripley import *
814 from esys.escript import *
815
816 fs=ContinuousFunction(Rectangle(11,11, d1=2,d0=2))
817 d=RandomData((), fs, 0, ('gaussian', 1, 0.5))
818 \end{python}
819 will use a filter that uses the immediate neighbours of each point with a sigma
820 value of $0.5$.
821 The random values will be different each time this code is executed due to the
822 seed of $0$.
823
824 Ripley's Gaussian smoothing has the following requirements:
825 \begin{enumerate}
826 \item If \MPI is in use, then each rank must have at least $5$ elements in
827 it \emph{in each dimension}. This value increases as the radius of
828 the blur increases.
829 \item The data being generated must be scalar. (You can generate random
830 data objects for \ripley domains with whatever shape you require, you
831 just can't smooth them unless that shape is scalar).
832 \end{enumerate}
833 An exception will be raised if either of these requirements is not met.
834
835 The components of the matrix used in the kernal for the 2D case are
836 defined\cite{gaussfilter} by:
837
838 \[ G(x,y) = \frac{1}{2\pi\sigma^2} e^{-\frac{x^2+y^2}{2\sigma^2}} \]
839
840 \noindent For the 3D case, we use:
841
842 \[ G(x,y) = \frac{1}{(\sqrt{2\pi\sigma^2})^3} e^{-\frac{x^2+y^2+z^2}{2\sigma^2}} \]
843
844 All distances ($x$,$y$,$z$) refer to the number of points from the centre point.
845 That is, the closest neighbours have at least one distance of $1$, the next
846 ``ring'' of neighbours have at least one $2$ and so on.
847 The matrix is normalised before use.
848
849 \subsection{\Data methods}
850 These are the most frequently used methods of the \Data class.
851 A complete list of methods can be found in the reference guide,
852 see \ReferenceGuide.
853
854 \begin{methoddesc}[Data]{getFunctionSpace}{}
855 returns the \FunctionSpace of the object.
856 \end{methoddesc}
857
858 \begin{methoddesc}[Data]{getDomain}{}
859 returns the \Domain of the object.
860 \end{methoddesc}
861
862 \begin{methoddesc}[Data]{getShape}{}
863 returns the \Shape of the object as a \class{tuple} of integers.
864 \end{methoddesc}
865
866 \begin{methoddesc}[Data]{getRank}{}
867 returns the rank of the data on each data point\index{rank}.
868 \end{methoddesc}
869
870 \begin{methoddesc}[Data]{isEmpty}{}
871 returns \True if the \Data object is the \EmptyData object, \False otherwise.
872 Note that this is not the same as asking if the object contains no \DataSamplePoints.
873 \end{methoddesc}
874
875 \begin{methoddesc}[Data]{setTaggedValue}{tag_name, value}
876 assigns the \var{value} to all \DataSamplePoints which have the tag
877 assigned to \var{tag_name}. \var{value} must be an object of class
878 \class{numpy.ndarray} or must be convertible into a \class{numpy.ndarray} object.
879 \var{value} (or the corresponding \class{numpy.ndarray} object) must be of
880 rank $0$ or must have the same rank as the object.
881 If a value has already been defined for tag \var{tag_name} within the object
882 it is overwritten by the new \var{value}. If the object is expanded,
883 the value assigned to \DataSamplePoints with tag \var{tag_name} is replaced by
884 \var{value}. If no value is assigned the tag name \var{tag_name}, no value is set.
885 \end{methoddesc}
886
887 \begin{methoddesc}[Data]{dump}{filename}
888 dumps the \Data object to the file \var{filename}. The file stores the
889 function space but not the \Domain. It is the responsibility of the user to
890 save the \Domain in order to be able to recover the \Data object.
891 \end{methoddesc}
892
893 \begin{methoddesc}[Data]{__str__}{}
894 returns a string representation of the object.
895 \end{methoddesc}
896
897 \subsection{Functions of \Data objects}
898 This section lists the most important functions for \Data class objects.
899 A complete list and a more detailed description of the functionality can be
900 found on \ReferenceGuide.
901
902 \begin{funcdesc}{kronecker}{d}
903 returns a \RankTwo in \FunctionSpace \var{d} such that
904 \begin{equation}
905 \code{kronecker(d)}\left[ i,j\right] = \left\{
906 \begin{array}{l l}
907 1 & \quad \text{if $i=j$}\\
908 0 & \quad \text{otherwise}
909 \end{array}
910 \right.
911 \end{equation}
912 If \var{d} is an integer a $(d,d)$ \numpy array is returned.
913 \end{funcdesc}
914
915 \begin{funcdesc}{identityTensor}{d}
916 is a synonym for \code{kronecker} (see above).
917 \end{funcdesc}
918
919 \begin{funcdesc}{identityTensor4}{d}
920 returns a \RankFour in \FunctionSpace \var{d} such that
921 \begin{equation}
922 \code{identityTensor(d)}\left[ i,j,k,l\right] = \left\{
923 \begin{array}{l l}
924 1 & \quad \text{if $i=k$ and $j=l$}\\
925 0 & \quad \text{otherwise}
926 \end{array}
927 \right.
928 \end{equation}
929 If \var{d} is an integer a $(d,d,d,d)$ \numpy array is returned.
930 \end{funcdesc}
931
932 \begin{funcdesc}{unitVector}{i,d}
933 returns a \RankOne in \FunctionSpace \var{d} such that
934 \begin{equation}
935 \code{identityTensor(d)}\left[ j \right] = \left\{
936 \begin{array}{l l}
937 1 & \quad \text{if $j=i$}\\
938 0 & \quad \text{otherwise}
939 \end{array}
940 \right.
941 \end{equation}
942 If \var{d} is an integer a $(d,)$ \numpy array is returned.
943 \end{funcdesc}
944
945 \begin{funcdesc}{Lsup}{a}
946 returns the $L^{sup}$ norm of \var{arg}. This is the maximum of the absolute
947 values over all components and all \DataSamplePoints of \var{a}.
948 \end{funcdesc}
949
950 \begin{funcdesc}{sup}{a}
951 returns the maximum value over all components and all \DataSamplePoints of \var{a}.
952 \end{funcdesc}
953
954 \begin{funcdesc}{inf}{a}
955 returns the minimum value over all components and all \DataSamplePoints of \var{a}
956 \end{funcdesc}
957
958 \begin{funcdesc}{minval}{a}
959 returns at each data sample point the minimum value over all components.
960 \end{funcdesc}
961
962 \begin{funcdesc}{maxval}{a}
963 returns at each data sample point the maximum value over all components.
964 \end{funcdesc}
965
966 \begin{funcdesc}{length}{a}
967 returns the Euclidean norm at each data sample point.
968 For a \RankFour \var{a} this is
969 \begin{equation}
970 \code{length(a)}=\sqrt{\sum_{ijkl} \var{a} \left[i,j,k,l\right]^2}
971 \end{equation}
972 \end{funcdesc}
973
974 \begin{funcdesc}{trace}{a\optional{, axis_offset=0}}
975 returns the trace of \var{a}. This is the sum over components \var{axis_offset}
976 and \var{axis_offset+1} with the same index.
977 For instance, in the case of a \RankTwo this is
978 \begin{equation}
979 \code{trace(a)}=\sum_{i} \var{a} \left[i,i\right]
980 \end{equation}
981 and for a \RankFour and \code{axis_offset=1} this is
982 \begin{equation}
983 \code{trace(a,1)}\left[i,j\right]=\sum_{k} \var{a} \left[i,k,k,j\right]
984 \end{equation}
985 \end{funcdesc}
986
987 \begin{funcdesc}{transpose}{a\optional{, axis_offset=None}}
988 returns the transpose of \var{a}. This swaps the first \var{axis_offset}
989 components of \var{a} with the rest. If \var{axis_offset} is not
990 present \code{int(r/2)} is used where \var{r} is the rank of \var{a}.
991 For instance, in the case of a \RankTwo this is
992 \begin{equation}
993 \code{transpose(a)}\left[i,j\right]=\var{a} \left[j,i\right]
994 \end{equation}
995 and for a \RankFour and \code{axis_offset=1} this is
996 \begin{equation}
997 \code{transpose(a,1)}\left[i,j,k,l\right]=\var{a} \left[j,k,l,i\right]
998 \end{equation}
999 \end{funcdesc}
1000
1001 \begin{funcdesc}{swap_axes}{a\optional{, axis0=0 \optional{, axis1=1 }}}
1002 returns \var{a} but with swapped components \var{axis0} and \var{axis1}.
1003 The argument \var{a} must be at least of rank 2. For instance, if \var{a}
1004 is a \RankFour, \code{axis0=1} and \code{axis1=2}, the result is
1005 \begin{equation}
1006 \code{swap_axes(a,1,2)}\left[i,j,k,l\right]=\var{a} \left[i,k,j,l\right]
1007 \end{equation}
1008 \end{funcdesc}
1009
1010 \begin{funcdesc}{symmetric}{a}
1011 returns the symmetric part of \var{a}. This is \code{(a+transpose(a))/2}.
1012 \end{funcdesc}
1013
1014 \begin{funcdesc}{nonsymmetric}{a}
1015 returns the non-symmetric part of \var{a}. This is \code{(a-transpose(a))/2}.
1016 \end{funcdesc}
1017
1018 \begin{funcdesc}{inverse}{a}
1019 return the inverse of \var{a} so that
1020 \begin{equation}
1021 \code{matrix_mult(inverse(a),a)=kronecker(d)}
1022 \end{equation}
1023 if \var{a} has shape \code{(d,d)}. The current implementation is restricted to
1024 arguments of shape \code{(2,2)} and \code{(3,3)}.
1025 \end{funcdesc}
1026
1027 \begin{funcdesc}{eigenvalues}{a}
1028 returns the eigenvalues of \var{a} so that
1029 \begin{equation}
1030 \code{matrix_mult(a,V)=e[i]*V}
1031 \end{equation}
1032 where \code{e=eigenvalues(a)} and \var{V} is a suitable non-zero vector.
1033 The eigenvalues are ordered in increasing size.
1034 The argument \var{a} has to be symmetric, i.e. \code{a=symmetric(a)}.
1035 The current implementation is restricted to arguments of shape \code{(2,2)}
1036 and \code{(3,3)}.
1037 \end{funcdesc}
1038
1039 \begin{funcdesc}{eigenvalues_and_eigenvectors}{a}
1040 returns the eigenvalues and eigenvectors of \var{a}.
1041 \begin{equation}
1042 \code{matrix_mult(a,V[:,i])=e[i]*V[:,i]}
1043 \end{equation}
1044 where \code{e,V=eigenvalues_and_eigenvectors(a)}. The eigenvectors \var{V} are
1045 orthogonal and normalized, i.e.
1046 \begin{equation}
1047 \code{matrix_mult(transpose(V),V)=kronecker(d)}
1048 \end{equation}
1049 if \var{a} has shape \code{(d,d)}. The eigenvalues are ordered in increasing
1050 size. The argument \var{a} has to be the symmetric, i.e. \code{a=symmetric(a)}.
1051 The current implementation is restricted to arguments of shape \code{(2,2)}
1052 and \code{(3,3)}.
1053 \end{funcdesc}
1054
1055 \begin{funcdesc}{maximum}{*a}
1056 returns the maximum value over all arguments at all \DataSamplePoints and for each component.
1057 \begin{equation}
1058 \code{maximum(a0,a1)}\left[i,j\right]=max(\var{a0} \left[i,j\right],\var{a1} \left[i,j\right])
1059 \end{equation}
1060 at all \DataSamplePoints.
1061 \end{funcdesc}
1062
1063 \begin{funcdesc}{minimum}{*a}
1064 returns the minimum value over all arguments at all \DataSamplePoints and for each component.
1065 \begin{equation}
1066 \code{minimum(a0,a1)}\left[i,j\right]=min(\var{a0} \left[i,j\right],\var{a1} \left[i,j\right])
1067 \end{equation}
1068 at all \DataSamplePoints.
1069 \end{funcdesc}
1070
1071 \begin{funcdesc}{clip}{a\optional{, minval=0.}\optional{, maxval=1.}}
1072 cuts back \var{a} into the range between \var{minval} and \var{maxval}.
1073 A value in the returned object equals \var{minval} if the corresponding value
1074 of \var{a} is less than \var{minval}, equals \var{maxval} if the corresponding
1075 value of \var{a} is greater than \var{maxval}, or corresponding value of
1076 \var{a} otherwise.
1077 \end{funcdesc}
1078
1079 \begin{funcdesc}{inner}{a0, a1}
1080 returns the inner product of \var{a0} and \var{a1}. For instance in the
1081 case of a \RankTwo:
1082 \begin{equation}
1083 \code{inner(a)}=\sum_{ij}\var{a0} \left[j,i\right] \cdot \var{a1} \left[j,i\right]
1084 \end{equation}
1085 and for a \RankFour:
1086 \begin{equation}
1087 \code{inner(a)}=\sum_{ijkl}\var{a0} \left[i,j,k,l\right] \cdot \var{a1} \left[j,i,k,l\right]
1088 \end{equation}
1089 \end{funcdesc}
1090
1091 \begin{funcdesc}{matrix_mult}{a0, a1}
1092 returns the matrix product of \var{a0} and \var{a1}.
1093 If \var{a1} is a \RankOne this is
1094 \begin{equation}
1095 \code{matrix_mult(a)}\left[i\right]=\sum_{k}\var{a0} \cdot \left[i,k\right]\var{a1} \left[k\right]
1096 \end{equation}
1097 and if \var{a1} is a \RankTwo this is
1098 \begin{equation}
1099 \code{matrix_mult(a)}\left[i,j\right]=\sum_{k}\var{a0} \cdot \left[i,k\right]\var{a1} \left[k,j\right]
1100 \end{equation}
1101 \end{funcdesc}
1102
1103 \begin{funcdesc}{transposed_matrix_mult}{a0, a1}
1104 returns the matrix product of the transposed of \var{a0} and \var{a1}.
1105 The function is equivalent to \code{matrix_mult(transpose(a0),a1)}.
1106 If \var{a1} is a \RankOne this is
1107 \begin{equation}
1108 \code{transposed_matrix_mult(a)}\left[i\right]=\sum_{k}\var{a0} \cdot \left[k,i\right]\var{a1} \left[k\right]
1109 \end{equation}
1110 and if \var{a1} is a \RankTwo this is
1111 \begin{equation}
1112 \code{transposed_matrix_mult(a)}\left[i,j\right]=\sum_{k}\var{a0} \cdot \left[k,i\right]\var{a1} \left[k,j\right]
1113 \end{equation}
1114 \end{funcdesc}
1115
1116 \begin{funcdesc}{matrix_transposed_mult}{a0, a1}
1117 returns the matrix product of \var{a0} and the transposed of \var{a1}.
1118 The function is equivalent to \code{matrix_mult(a0,transpose(a1))}.
1119 If \var{a1} is a \RankTwo this is
1120 \begin{equation}
1121 \code{matrix_transposed_mult(a)}\left[i,j\right]=\sum_{k}\var{a0} \cdot \left[i,k\right]\var{a1} \left[j,k\right]
1122 \end{equation}
1123 \end{funcdesc}
1124
1125 \begin{funcdesc}{outer}{a0, a1}
1126 returns the outer product of \var{a0} and \var{a1}.
1127 For instance, if both, \var{a0} and \var{a1} is a \RankOne then
1128 \begin{equation}
1129 \code{outer(a)}\left[i,j\right]=\var{a0} \left[i\right] \cdot \var{a1}\left[j\right]
1130 \end{equation}
1131 and if \var{a0} is a \RankOne and \var{a1} is a \RankThree:
1132 \begin{equation}
1133 \code{outer(a)}\left[i,j,k\right]=\var{a0} \left[i\right] \cdot \var{a1}\left[j,k\right]
1134 \end{equation}
1135 \end{funcdesc}
1136
1137 \begin{funcdesc}{tensor_mult}{a0, a1}
1138 returns the tensor product of \var{a0} and \var{a1}.
1139 If \var{a1} is a \RankTwo this is
1140 \begin{equation}
1141 \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]
1142 \end{equation}
1143 and if \var{a1} is a \RankFour this is
1144 \begin{equation}
1145 \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]
1146 \end{equation}
1147 \end{funcdesc}
1148
1149 \begin{funcdesc}{transposed_tensor_mult}{a0, a1}
1150 returns the tensor product of the transposed of \var{a0} and \var{a1}.
1151 The function is equivalent to \code{tensor_mult(transpose(a0),a1)}.
1152 If \var{a1} is a \RankTwo this is
1153 \begin{equation}
1154 \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]
1155 \end{equation}
1156 and if \var{a1} is a \RankFour this is
1157 \begin{equation}
1158 \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]
1159 \end{equation}
1160 \end{funcdesc}
1161
1162 \begin{funcdesc}{tensor_transposed_mult}{a0, a1}
1163 returns the tensor product of \var{a0} and the transposed of \var{a1}.
1164 The function is equivalent to \code{tensor_mult(a0,transpose(a1))}.
1165 If \var{a1} is a \RankTwo this is
1166 \begin{equation}
1167 \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]
1168 \end{equation}
1169 and if \var{a1} is a \RankFour this is
1170 \begin{equation}
1171 \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]
1172 \end{equation}
1173 \end{funcdesc}
1174
1175 \begin{funcdesc}{grad}{a\optional{, where=None}}
1176 returns the gradient of \var{a}. If \var{where} is present the gradient will
1177 be calculated in the \FunctionSpace \var{where}, otherwise a default
1178 \FunctionSpace is used. In case that \var{a} is a \RankTwo one has
1179 \begin{equation}
1180 \code{grad(a)}\left[i,j,k\right]=\frac{\partial \var{a} \left[i,j\right]}{\partial x_{k}}
1181 \end{equation}
1182 \end{funcdesc}
1183
1184 \begin{funcdesc}{integrate}{a\optional{, where=None}}
1185 returns the integral of \var{a} where the domain of integration is defined by
1186 the \FunctionSpace of \var{a}. If \var{where} is present the argument is
1187 interpolated into \FunctionSpace \var{where} before integration.
1188 For instance in the case of a \RankTwo in \ContinuousFunction it is
1189 \begin{equation}
1190 \code{integrate(a)}\left[i,j\right]=\int_{\Omega}\var{a} \left[i,j\right] \; d\Omega
1191 \end{equation}
1192 where $\Omega$ is the spatial domain and $d\Omega$ volume integration.
1193 To integrate over the boundary of the domain one uses
1194 \begin{equation}
1195 \code{integrate(a,where=FunctionOnBoundary(a.getDomain))}\left[i,j\right]=\int_{\partial \Omega} a\left[i,j\right] \; ds
1196 \end{equation}
1197 where $\partial \Omega$ is the surface of the spatial domain and $ds$ area or
1198 line integration.
1199 \end{funcdesc}
1200
1201 \begin{funcdesc}{interpolate}{a, where}
1202 interpolates argument \var{a} into the \FunctionSpace \var{where}.
1203 \end{funcdesc}
1204
1205 \begin{funcdesc}{div}{a\optional{, where=None}}
1206 returns the divergence of \var{a}:
1207 \begin{equation}
1208 \code{div(a)=trace(grad(a),where)}
1209 \end{equation}
1210 \end{funcdesc}
1211
1212 \begin{funcdesc}{jump}{a\optional{, domain=None}}
1213 returns the jump of \var{a} over the discontinuity in its domain or if
1214 \Domain \var{domain} is present in \var{domain}.
1215 \begin{equation}
1216 \begin{array}{rcl}
1217 \code{jump(a)}& = &\code{interpolate(a,FunctionOnContactOne(domain))} \\
1218 & & \hfill - \code{interpolate(a,FunctionOnContactZero(domain))}
1219 \end{array}
1220 \end{equation}
1221 \end{funcdesc}
1222
1223 \begin{funcdesc}{L2}{a}
1224 returns the $L^2$-norm of \var{a} in its \FunctionSpace. This is
1225 \begin{equation}
1226 \code{L2(a)=integrate(length(a)}^2\code{)} \; .
1227 \end{equation}
1228 \end{funcdesc}
1229
1230 \noindent The following functions operate ``point-wise''.
1231 That is, the operation is applied to each component of each point individually.
1232
1233 \begin{funcdesc}{sin}{a}
1234 applies the sine function to \var{a}.
1235 \end{funcdesc}
1236
1237 \begin{funcdesc}{cos}{a}
1238 applies the cosine function to \var{a}.
1239 \end{funcdesc}
1240
1241 \begin{funcdesc}{tan}{a}
1242 applies the tangent function to \var{a}.
1243 \end{funcdesc}
1244
1245 \begin{funcdesc}{asin}{a}
1246 applies the arc (inverse) sine function to \var{a}.
1247 \end{funcdesc}
1248
1249 \begin{funcdesc}{acos}{a}
1250 applies the arc (inverse) cosine function to \var{a}.
1251 \end{funcdesc}
1252
1253 \begin{funcdesc}{atan}{a}
1254 applies the arc (inverse) tangent function to \var{a}.
1255 \end{funcdesc}
1256
1257 \begin{funcdesc}{sinh}{a}
1258 applies the hyperbolic sine function to \var{a}.
1259 \end{funcdesc}
1260
1261 \begin{funcdesc}{cosh}{a}
1262 applies the hyperbolic cosine function to \var{a}.
1263 \end{funcdesc}
1264
1265 \begin{funcdesc}{tanh}{a}
1266 applies the hyperbolic tangent function to \var{a}.
1267 \end{funcdesc}
1268
1269 \begin{funcdesc}{asinh}{a}
1270 applies the arc (inverse) hyperbolic sine function to \var{a}.
1271 \end{funcdesc}
1272
1273 \begin{funcdesc}{acosh}{a}
1274 applies the arc (inverse) hyperbolic cosine function to \var{a}.
1275 \end{funcdesc}
1276
1277 \begin{funcdesc}{atanh}{a}
1278 applies the arc (inverse) hyperbolic tangent function to \var{a}.
1279 \end{funcdesc}
1280
1281 \begin{funcdesc}{exp}{a}
1282 applies the exponential function to \var{a}.
1283 \end{funcdesc}
1284
1285 \begin{funcdesc}{sqrt}{a}
1286 applies the square root function to \var{a}.
1287 \end{funcdesc}
1288
1289 \begin{funcdesc}{log}{a}
1290 takes the natural logarithm of \var{a}.
1291 \end{funcdesc}
1292
1293 \begin{funcdesc}{log10}{a}
1294 takes the base-$10$ logarithm of \var{a}.
1295 \end{funcdesc}
1296
1297 \begin{funcdesc}{sign}{a}
1298 applies the sign function to \var{a}. The result is $1$ where \var{a} is
1299 positive, $-1$ where \var{a} is negative, and $0$ otherwise.
1300 \end{funcdesc}
1301
1302 \begin{funcdesc}{wherePositive}{a}
1303 returns a function which is $1$ where \var{a} is positive and $0$ otherwise.
1304 \end{funcdesc}
1305
1306 \begin{funcdesc}{whereNegative}{a}
1307 returns a function which is $1$ where \var{a} is negative and $0$ otherwise.
1308 \end{funcdesc}
1309
1310 \begin{funcdesc}{whereNonNegative}{a}
1311 returns a function which is $1$ where \var{a} is non-negative and $0$ otherwise.
1312 \end{funcdesc}
1313
1314 \begin{funcdesc}{whereNonPositive}{a}
1315 returns a function which is $1$ where \var{a} is non-positive and $0$ otherwise.
1316 \end{funcdesc}
1317
1318 \begin{funcdesc}{whereZero}{a\optional{, tol=None\optional{, rtol=1.e-8}}}
1319 returns a function which is $1$ where \var{a} equals zero with tolerance
1320 \var{tol} and $0$ otherwise. If \var{tol} is not present, the absolute maximum
1321 value of \var{a} times \var{rtol} is used.
1322 \end{funcdesc}
1323
1324 \begin{funcdesc}{whereNonZero}{a\optional{, tol=None\optional{, rtol=1.e-8}}}
1325 returns a function which is $1$ where \var{a} is non-zero with tolerance
1326 \var{tol} and $0$ otherwise. If \var{tol} is not present, the absolute maximum
1327 value of \var{a} times \var{rtol} is used.
1328 \end{funcdesc}
1329
1330 \subsection{Interpolating Data}
1331 \index{interpolateTable}
1332 \label{sec:interpolation}
1333 In some cases, it may be useful to produce Data objects which fit some user
1334 defined function.
1335 Manually modifying each value in the Data object is not a good idea since it
1336 depends on knowing the location and order of each data point in the domain.
1337 Instead, \escript can use an interpolation table to produce a \Data object.
1338
1339 The following example is available as \file{int_save.py} in the \ExampleDirectory.
1340 We will produce a \Data object which approximates a sine curve.
1341
1342 \begin{python}
1343 from esys.escript import saveDataCSV, sup, interpolateTable
1344 import numpy
1345 from esys.finley import Rectangle
1346
1347 n=4
1348 r=Rectangle(n,n)
1349 x=r.getX()
1350 toobig=100
1351 \end{python}
1352
1353 \noindent First we produce an interpolation table:
1354 \begin{python}
1355 sine_table=[0, 0.70710678118654746, 1, 0.70710678118654746, 0,
1356 -0.70710678118654746, -1, -0.70710678118654746, 0]
1357 \end{python}
1358 %
1359 We wish to identify $0$ and $1$ with the ends of the curve, that is
1360 with the first and eighth value in the table.
1361
1362 \begin{python}
1363 numslices=len(sine_table)-1
1364 minval=0.
1365 maxval=1.
1366 step=sup(maxval-minval)/numslices
1367 \end{python}
1368 %
1369 So the values $v$ from the input lie in the interval
1370 \var{minval} $\leq v <$ \var{maxval}.
1371 \var{step} represents the gap (in the input range) between entries in the table.
1372 By default, values of $v$ outside the table argument range (minval, maxval)
1373 will be pushed back into the range, i.e. if $v <$ \var{minval} the value
1374 \var{minval} will be used to evaluate the table.
1375 Similarly, for values $v>$ \var{maxval} the value \var{maxval} is used.
1376
1377 Now we produce our new \Data object:
1378
1379 \begin{python}
1380 result=interpolateTable(sine_table, x[0], minval, step, toobig)
1381 \end{python}
1382 Any values which interpolate to larger than \var{toobig} will raise an
1383 exception. You can switch on boundary checking by adding
1384 \code{check_boundaries=True} to the argument list.
1385
1386 Now consider a 2D example. We will interpolate from a plane where $\forall x,y\in[0,9]:(x,y)=x+y\cdot10$.
1387
1388 \begin{python}
1389 from esys.escript import whereZero
1390 table2=[]
1391 for y in range(0,10):
1392 r=[]
1393 for x in range(0,10):
1394 r.append(x+y*10)
1395 table2.append(r)
1396 xstep=(maxval-minval)/(10-1)
1397 ystep=(maxval-minval)/(10-1)
1398
1399 xmin=minval
1400 ymin=minval
1401
1402 result2=interpolateTable(table2, x2, (xmin, ymin), (xstep, ystep), toobig)
1403 \end{python}
1404
1405 We can check the values using \function{whereZero}.
1406 For example, for $x=0$:
1407 \begin{python}
1408 print(result2*whereZero(x[0]))
1409 \end{python}
1410
1411 Finally let us look at a 3D example. Note that the parameter tuples should be
1412 $(x,y,z)$ but that in the interpolation table, $x$ is the innermost dimension.
1413 \begin{python}
1414 b=Brick(n,n,n)
1415 x3=b.getX()
1416 toobig=1000000
1417
1418 table3=[]
1419 for z in range(0,10):
1420 face=[]
1421 for y in range(0,10):
1422 r=[]
1423 for x in range(0,10):
1424 r.append(x+y*10+z*100)
1425 face.append(r)
1426 table3.append(face);
1427
1428 zstep=(maxval-minval)/(10-1)
1429
1430 zmin=minval
1431
1432 result3=interpolateTable(table3, x3, (xmin, ymin, zmin),
1433 (xstep, ystep, zstep), toobig)
1434 \end{python}
1435
1436
1437 \subsubsection{Non-uniform Interpolation}
1438 Non-uniform interpolation is also supported for the one dimensional case.
1439 \begin{python}
1440 Data.nonuniformInterpolate(in, out, check_boundaries)
1441 Data.nonuniformSlope(in, out, check_boundaries)
1442 \end{python}
1443
1444 Will produce a new \Data object by mapping the given \Data object through the user-defined function
1445 specified by \texttt{in} and \texttt{out}.
1446 The \ldots Interpolate version gives the value of the function at the specified point and the
1447 \ldots Slope version gives the slope at those points.
1448 The check_boundaries boolean argument specifies what the function should do if the \Data object contains
1449 values outside the range specified by the \texttt{in} parameter.
1450 If the argument is \texttt{False}, then those datapoints will be interpolated to the value of the edge
1451 they are closest to (or assigned a slope of zero).
1452 If the argument is \texttt{True}, then an exception will be thrown if out of bounds values are detected.
1453 Note that the values given by the \texttt{in} parameter must be monotonically increasing.
1454
1455 \noindent For example:\\
1456 If \texttt{d} contains the values \texttt{\{1,2,3,4,5\}}, then
1457 \begin{python}
1458 d.nonuniformInterpolate([1.5, 2, 2.8, 4.6], [4, 5, -1, 1], False)
1459 \end{python}
1460 would produce a \Data object containing \texttt{\{4, 5, -0.7777, 0.3333, 1\}}.\\
1461 A similar call to \texttt{nonuniformSlope} would produce a \Data object containing \texttt{\{0, 2, 1.1111, 1.1111, 0\}}.
1462 %
1463 %
1464 % We will interpolate a surface such that the bottom
1465 % edge is the sine curve described above.
1466 % The amplitude of the curve decreases as we move towards the top edge.
1467 % Our interpolation table will have three rows:
1468 %
1469 % \begin{python}
1470 % st=numpy.array(sine_table)
1471 % table=[st, 0.5*st, 0*st]
1472 % \end{python}
1473 % %
1474 % The use of \numpy and multiplication here is just to save typing.
1475 %
1476 % % result2=x1.interpolateTable(table, 0, 0.55, x0, minval, step, toobig)
1477 % \begin{python}
1478 % result=interpolateTable(table, x (minval,0), (0.55, step), toobig)
1479 % \end{python}
1480 %
1481 % In the 2D case the start and step parameters are tuples $(x,y)$.
1482 % By default, if a point is specified which is outside the boundary, then
1483 % \var{interpolateTable} will operate as if the point was on the boundary.
1484 % Passing \code{check_boundaries=True} will lead to the rejection of any points
1485 % outside the boundaries by \var{interpolateTable}.
1486 %
1487 % This method can also be called with three dimensional tables and \Data objects.
1488 % Tuples should be ordered $(x,y,z)$.
1489
1490 \subsection{The \var{DataManager} Class}
1491 \label{sec:datamanager}
1492
1493 The \var{DataManager} class can be used to conveniently add checkpoint/restart
1494 functionality to \escript simulations.
1495 Once an instance is created \Data objects and other values can be added and
1496 dumped to disk by a single method call.
1497 If required the object can be set up to also save the data in a format suitable
1498 for visualization.
1499 Internally the \var{DataManager} interfaces with \weipa for this.
1500
1501 \begin{classdesc}{DataManager}{formats=[RESTART], work_dir=".", restart_prefix="restart", do_restart=\True}
1502 initializes a new \var{DataManager} object which can be used to save,
1503 restore and export simulation data in a number of formats.
1504 All files and directories saved or restored by this object are located
1505 under the directory specified by \var{work_dir}.
1506 If \var{RESTART} is specified in \var{formats}, the \var{DataManager} will
1507 look for directories whose name starts with \var{restart_prefix}.
1508 In case \var{do_restart} is \True, the last of these directories is used
1509 to restore simulation data while all others are deleted.
1510 If \var{do_restart} is \False, then all of those directories are deleted.
1511 The \var{restart_prefix} and \var{do_restart} parameters are ignored if
1512 \var{RESTART} is not specified in \var{formats}.
1513 \end{classdesc}
1514
1515 \noindent Valid values for the \var{formats} parameter are:
1516 \begin{memberdesc}[DataManager]{RESTART}
1517 enables writing of checkpoint files to be able to continue simulations
1518 as explained in the class description.
1519 \end{memberdesc}
1520 \begin{memberdesc}[DataManager]{SILO}
1521 exports simulation data in the \SILO file format. \escript must have
1522 been compiled with \SILO support for this to work.
1523 \end{memberdesc}
1524 \begin{memberdesc}[DataManager]{VISIT}
1525 enables the \VisIt simulation interface which allows connecting to and
1526 interacting with the running simulation from a compatible \VisIt client.
1527 \escript must have been compiled with \VisIt (version 2) support and the
1528 version of the client has to match the version used at compile time.
1529 In order to connect to the simulation the client needs to have access and
1530 load the file \file{escriptsim.sim2} located under the work directory.
1531 \end{memberdesc}
1532 \begin{memberdesc}[DataManager]{VTK}
1533 exports simulation data in the \VTK file format.
1534 \end{memberdesc}
1535
1536 \noindent The \var{DataManager} class has the following methods:
1537 \begin{methoddesc}[DataManager]{addData}{**data}
1538 adds \Data objects and other data to the manager. Calling this method does
1539 not save or export the data yet so it is allowed to incrementally add data
1540 at various points in the simulation script if required.
1541 Note, that only a single domain is supported so all \Data objects have to
1542 be defined on the same one or an exception is raised.
1543 \end{methoddesc}
1544
1545 \begin{methoddesc}[DataManager]{setDomain}{domain}
1546 explicitly sets the domain for this manager.
1547 It is generally not required to call this method directly.
1548 Instead, the \var{addData} method will set the domain used by the \Data
1549 objects.
1550 An exception is raised if the domain was set to a different domain before
1551 (explicitly or implicitly).
1552 \end{methoddesc}
1553
1554 \begin{methoddesc}[DataManager]{hasData}{}
1555 returns \True if the manager has loaded simulation data for a restart.
1556 \end{methoddesc}
1557
1558 \begin{methoddesc}[DataManager]{getDomain}{}
1559 returns the domain as recovered from a restart.
1560 \end{methoddesc}
1561
1562 \begin{methoddesc}[DataManager]{getValue}{value_name}
1563 returns a \Data object or other value with the name \var{value_name} that
1564 has been recovered after a restart.
1565 \end{methoddesc}
1566
1567 \begin{methoddesc}[DataManager]{getCycle}{}
1568 returns the export cycle, i.e. the number of times \var{export()} has been
1569 called.
1570 \end{methoddesc}
1571
1572 \begin{methoddesc}[DataManager]{setCheckpointFrequency}{freq}
1573 sets the frequency with which checkpoint files are created. This is only
1574 useful if the \var{DataManager} object was created with at least one other
1575 format next to \var{RESTART}. The frequency is 1 by default which means
1576 that checkpoint files are created every time \var{export()} is called.
1577 Unlike visualization output, a simulation checkpoint is usually not
1578 required at every time step. Thus, the frequency can be decreased by
1579 calling this method with $\var{freq}>1$ which would then create restart
1580 files every \var{freq} times \var{export()} is called.
1581 \end{methoddesc}
1582
1583 \begin{methoddesc}[DataManager]{setTime}{time}
1584 sets the simulation time stamp. This floating point number is stored in
1585 the metadata of exported data but not used by \var{RESTART}.
1586 \end{methoddesc}
1587
1588 \begin{methoddesc}[DataManager]{setMeshLabels}{x, y, z=""}
1589 sets labels for the mesh axes. These are currently only used by the \SILO
1590 exporter.
1591 \end{methoddesc}
1592
1593 \begin{methoddesc}[DataManager]{setMeshUnits}{x, y, z=""}
1594 sets units for the mesh axes. These are currently only used by the \SILO
1595 exporter.
1596 \end{methoddesc}
1597
1598 \begin{methoddesc}[DataManager]{setMetadataSchemaString}{schema, metadata=""}
1599 sets metadata namespaces and the corresponding metadata. These are
1600 currently only used by the \VTK exporter.
1601 \var{schema} is a dictionary that maps prefixes to namespace names, e.g.\\
1602 \code{\{"gml": "http://www.opengis.net/gml"\}} and \var{metadata} is a
1603 string with the actual content which will be enclosed in \var{<MetaData>}
1604 tags.
1605 \end{methoddesc}
1606
1607 \begin{methoddesc}[DataManager]{export}{}
1608 executes the actual data export. Depending on the \var{formats} parameter
1609 used in the constructor all data added by \var{addData()} is written to
1610 disk (\var{RESTART,SILO,VTK}) or made available through the \VisIt
1611 simulation interface (\var{VISIT}).
1612 At least the domain must be set for something to be exported.
1613 \end{methoddesc}
1614
1615 \subsection{Saving Data as CSV}
1616 \label{sec:savedatacsv}
1617 \index{saveDataCSV}\index{CSV}
1618 For simple post-processing, \Data objects can be saved in comma separated
1619 value (\emph{CSV}) format.
1620 If \var{mydata1} and \var{mydata2} are scalar data, the command
1621 \begin{python}
1622 saveDataCSV('output.csv', U=mydata1, V=mydata2)
1623 \end{python}
1624 will record the values in \file{output.csv} in the following format:
1625 \begin{verbatim}
1626 U, V
1627 1.0000000e+0, 2.0000000e-1
1628 5.0000000e-0, 1.0000000e+1
1629 ...
1630 \end{verbatim}
1631
1632 The names of the keyword parameters form the names of columns in the output.
1633 If the data objects are over different function spaces, then \var{saveDataCSV}
1634 will attempt to interpolate to a common function space.
1635 If this is not possible, then an exception is raised.
1636
1637 Output can be restricted using a scalar mask as follows:
1638 \begin{python}
1639 saveDataCSV('outfile.csv', U=mydata1, V=mydata2, mask=myscalar)
1640 \end{python}
1641 This command will only output those rows which correspond to to positive
1642 values of \var{myscalar}.
1643 Some aspects of the output can be tuned using additional parameters:
1644 \begin{python}
1645 saveDataCSV('data.csv', refid=True, append=True, sep=' ', csep='/', mask=mymask, e=mat1)
1646 \end{python}
1647
1648 \begin{itemize}
1649 \item \var{refid} -- specifies that the output should include the reference IDs of the elements or nodes
1650 \item \var{append} -- specifies that the output should be written to the end of an existing file
1651 \item \var{sep} -- defines the separator between fields
1652 \item \var{csep} -- defines the separator between components in the header
1653 line. For example between the components of a matrix.
1654 \end{itemize}
1655 %
1656 The above command would produce output like this:
1657 \begin{verbatim}
1658 refid e/0/0 e/1/0 e/0/1 e/1/1
1659 0 1.0000000000e+00 2.0000000000e+00 3.0000000000e+00 4.0000000000e+00
1660 ...
1661 \end{verbatim}
1662
1663 Note that while the order in which rows are output can vary, all the elements
1664 in a given row always correspond to the same input.
1665
1666 \subsection{Converting \Data to a Numpy Array}
1667 \label{sec:getnumpy}
1668 \index{getNumpy}\index{GN}
1669 \Data objects can be converted into a numpy structured array.
1670 If \var{mydata1} and \var{mydata2} are scalar \Data, then the command
1671 \begin{python}
1672 a,b = getNumpy(U=mydata1, V=mydata2)
1673 \end{python}
1674 will return two structured ndarrays with the names '\emph{U}' and '\emph{V}'.
1675 \begin{verbatim}
1676 a['U'] = [1.0000000e+0, 2.0000000e-1, ...
1677 b['V'] = [2.0000000e+0, 3.0000000e-1, ...
1678 \end{verbatim}
1679
1680 Up to five \Data objects can be passed to \var{getNumpy} at the time. These objects can be scalar, vector or tensor \Data objects. The names of the keyword parameters form the names of the returned arrays.
1681 If the data objects are over different function spaces, then \var{getNumpy}
1682 will attempt to interpolate to a common function space.
1683 If this is not possible, then an exception is raised.
1684
1685 Output can be restricted using a scalar mask as follows:
1686 \begin{python}
1687 a,b,c = getNumpy(U=mydata1, V=mydata2, W=mydata3, mask=myscalar)
1688 \end{python}
1689 This command will only output those rows which correspond to to positive
1690 values of \var{myscalar}.
1691
1692 Note that while the order in which output rows are output can vary, all the elements
1693 in a given row always correspond to the same input.
1694
1695
1696 \subsection{The \Operator Class}
1697 The \Operator class provides an abstract access to operators built
1698 within the \LinearPDE class. \Operator objects are created
1699 when a PDE is handed over to a PDE solver library and handled
1700 by the \LinearPDE object defining the PDE. The user can gain access
1701 to the \Operator of a \LinearPDE object through the \var{getOperator}
1702 method.
1703
1704 \begin{classdesc}{Operator}{}
1705 creates an empty \Operator object.
1706 \end{classdesc}
1707
1708 \begin{methoddesc}[Operator]{isEmpty}{fileName}
1709 returns \True is the object is empty, \False otherwise.
1710 \end{methoddesc}
1711
1712 \begin{methoddesc}[Operator]{resetValues}{}
1713 resets all entries in the operator.
1714 \end{methoddesc}
1715
1716 \begin{methoddesc}[Operator]{solve}{rhs}
1717 returns the solution \var{u} of: operator * \var{u} = \var{rhs}.
1718 \end{methoddesc}
1719
1720 \begin{methoddesc}[Operator]{of}{u}
1721 applies the operator to the \Data object \var{u}, i.e. performs a matrix-vector
1722 multiplication.
1723 \end{methoddesc}
1724
1725 \begin{methoddesc}[Operator]{saveMM}{fileName}\index{Matrix Market}
1726 saves the object to a Matrix Market format file with name \var{fileName}, see
1727 \url{http://math.nist.gov/MatrixMarket}
1728 \end{methoddesc}
1729
1730 \section{Physical Units}
1731 \escript provides support for physical units in the SI system\index{SI units}
1732 including unit conversion. So the user can define variables in the form
1733 \begin{python}
1734 from esys.escript.unitsSI import *
1735 l=20*m
1736 w=30*kg
1737 w2=40*lb
1738 T=100*Celsius
1739 \end{python}
1740 In the two latter cases a conversion from pounds\index{pounds} and degrees
1741 Celsius\index{Celsius} is performed into the appropriate SI units \emph{kg}
1742 and \emph{Kelvin}.
1743 In addition, composed units can be used, for instance
1744 \begin{python}
1745 from esys.escript.unitsSI import *
1746 rho=40*lb/cm**3
1747 \end{python}
1748 defines the density in the units of pounds per cubic centimeter.
1749 The value $40$ will be converted into SI units, in this case kg per cubic
1750 meter. Moreover unit prefixes are supported:
1751 \begin{python}
1752 from esys.escript.unitsSI import *
1753 p=40*Mega*Pa
1754 \end{python}
1755 The pressure \var{p} is set to 40 Mega Pascal. Units can also be converted
1756 back from the SI system into a desired unit, e.g.
1757 \begin{python}
1758 from esys.escript.unitsSI import *
1759 print(p/atm)
1760 \end{python}
1761 can be used print the pressure in units of atmosphere\index{atmosphere}.
1762
1763 The following is an incomplete list of supported physical units:
1764
1765 \begin{datadesc}{km}
1766 unit of kilometer
1767 \end{datadesc}
1768
1769 \begin{datadesc}{m}
1770 unit of meter
1771 \end{datadesc}
1772
1773 \begin{datadesc}{cm}
1774 unit of centimeter
1775 \end{datadesc}
1776
1777 \begin{datadesc}{mm}
1778 unit of millimeter
1779 \end{datadesc}
1780
1781 \begin{datadesc}{sec}
1782 unit of second
1783 \end{datadesc}
1784
1785 \begin{datadesc}{minute}
1786 unit of minute
1787 \end{datadesc}
1788
1789 \begin{datadesc}{h}
1790 unit of hour
1791 \end{datadesc}
1792
1793 \begin{datadesc}{day}
1794 unit of day
1795 \end{datadesc}
1796
1797 \begin{datadesc}{yr}
1798 unit of year
1799 \end{datadesc}
1800
1801 \begin{datadesc}{gram}
1802 unit of gram
1803 \end{datadesc}
1804
1805 \begin{datadesc}{kg}
1806 unit of kilogram
1807 \end{datadesc}
1808
1809 \begin{datadesc}{lb}
1810 unit of pound
1811 \end{datadesc}
1812
1813 \begin{datadesc}{ton}
1814 metric ton
1815 \end{datadesc}
1816
1817 \begin{datadesc}{A}
1818 unit of Ampere
1819 \end{datadesc}
1820
1821 \begin{datadesc}{Hz}
1822 unit of Hertz
1823 \end{datadesc}
1824
1825 \begin{datadesc}{N}
1826 unit of Newton
1827 \end{datadesc}
1828
1829 \begin{datadesc}{Pa}
1830 unit of Pascal
1831 \end{datadesc}
1832
1833 \begin{datadesc}{atm}
1834 unit of atmosphere
1835 \end{datadesc}
1836
1837 \begin{datadesc}{J}
1838 unit of Joule
1839 \end{datadesc}
1840
1841 \begin{datadesc}{W}
1842 unit of Watt
1843 \end{datadesc}
1844
1845 \begin{datadesc}{C}
1846 unit of Coulomb
1847 \end{datadesc}
1848
1849 \begin{datadesc}{V}
1850 unit of Volt
1851 \end{datadesc}
1852
1853 \begin{datadesc}{F}
1854 unit of Farad
1855 \end{datadesc}
1856
1857 \begin{datadesc}{Ohm}
1858 unit of Ohm
1859 \end{datadesc}
1860
1861 \begin{datadesc}{K}
1862 unit of degrees Kelvin
1863 \end{datadesc}
1864
1865 \begin{datadesc}{Celsius}
1866 unit of degrees Celsius
1867 \end{datadesc}
1868
1869 \begin{datadesc}{Fahrenheit}
1870 unit of degrees Fahrenheit
1871 \end{datadesc}
1872
1873 \noindent Supported unit prefixes:
1874
1875 \begin{datadesc}{Yotta}
1876 prefix yotta = $10^{24}$
1877 \end{datadesc}
1878
1879 \begin{datadesc}{Zetta}
1880 prefix zetta = $10^{21}$
1881 \end{datadesc}
1882
1883 \begin{datadesc}{Exa}
1884 prefix exa = $10^{18}$
1885 \end{datadesc}
1886
1887 \begin{datadesc}{Peta}
1888 prefix peta = $10^{15}$
1889 \end{datadesc}
1890
1891 \begin{datadesc}{Tera}
1892 prefix tera = $10^{12}$
1893 \end{datadesc}
1894
1895 \begin{datadesc}{Giga}
1896 prefix giga = $10^9$
1897 \end{datadesc}
1898
1899 \begin{datadesc}{Mega}
1900 prefix mega = $10^6$
1901 \end{datadesc}
1902
1903 \begin{datadesc}{Kilo}
1904 prefix kilo = $10^3$
1905 \end{datadesc}
1906
1907 \begin{datadesc}{Hecto}
1908 prefix hecto = $10^2$
1909 \end{datadesc}
1910
1911 \begin{datadesc}{Deca}
1912 prefix deca = $10^1$
1913 \end{datadesc}
1914
1915 \begin{datadesc}{Deci}
1916 prefix deci = $10^{-1}$
1917 \end{datadesc}
1918
1919 \begin{datadesc}{Centi}
1920 prefix centi = $10^{-2}$
1921 \end{datadesc}
1922
1923 \begin{datadesc}{Milli}
1924 prefix milli = $10^{-3}$
1925 \end{datadesc}
1926
1927 \begin{datadesc}{Micro}
1928 prefix micro = $10^{-6}$
1929 \end{datadesc}
1930
1931 \begin{datadesc}{Nano}
1932 prefix nano = $10^{-9}$
1933 \end{datadesc}
1934
1935 \begin{datadesc}{Pico}
1936 prefix pico = $10^{-12}$
1937 \end{datadesc}
1938
1939 \begin{datadesc}{Femto}
1940 prefix femto = $10^{-15}$
1941 \end{datadesc}
1942
1943 \begin{datadesc}{Atto}
1944 prefix atto = $10^{-18}$
1945 \end{datadesc}
1946
1947 \begin{datadesc}{Zepto}
1948 prefix zepto = $10^{-21}$
1949 \end{datadesc}
1950
1951 \begin{datadesc}{Yocto}
1952 prefix yocto = $10^{-24}$
1953 \end{datadesc}
1954
1955 \section{Utilities}
1956 The \class{FileWriter} class provides a mechanism to write data to a file.
1957 In essence, this class wraps the standard \PYTHON \class{file} class to write
1958 data that are global in \MPI to a file. In fact, data are written on the
1959 processor with \MPI rank 0 only. It is recommended to use \class{FileWriter}
1960 rather than \class{open} in order to write code that will run with and without
1961 \MPI. It is safe to use \class{open} under \MPI to \emph{read} data which are
1962 global under \MPI.
1963
1964 \begin{classdesc}{FileWriter}{fn\optional{,append=\False, \optional{createLocalFiles=\False}})}
1965 Opens a file with name \var{fn} for writing. If \var{append} is set to \True
1966 data are appended at the end of the file.
1967 If running under \MPI, only the first processor (rank==0) will open the file
1968 and write to it.
1969 If \var{createLocalFiles} is set each individual processor will create a file
1970 where for any processor with rank $> 0$ the file name is extended by its rank.
1971 This option is normally used for debugging purposes only.
1972 \end{classdesc}
1973
1974 \vspace{1em}\noindent The following methods are available:
1975 \begin{methoddesc}[FileWriter]{close}{}
1976 closes the file.
1977 \end{methoddesc}
1978 \begin{methoddesc}[FileWriter]{flush}{}
1979 flushes the internal buffer to disk.
1980 \end{methoddesc}
1981 \begin{methoddesc}[FileWriter]{write}{txt}
1982 writes string \var{txt} to the file. Note that a newline is not added.
1983 \end{methoddesc}
1984 \begin{methoddesc}[FileWriter]{writelines}{txts}
1985 writes the list \var{txts} of strings to the file.
1986 Note that newlines are not added.
1987 This method is equivalent to calling \var{write()} for each string.
1988 \end{methoddesc}
1989 \begin{memberdesc}[FileWriter]{closed}
1990 this member is \True if the file is closed.
1991 \end{memberdesc}
1992 \begin{memberdesc}[FileWriter]{mode}
1993 holds the access mode.
1994 \end{memberdesc}
1995 \begin{memberdesc}[FileWriter]{name}
1996 holds the file name.
1997 \end{memberdesc}
1998 \begin{memberdesc}[FileWriter]{newlines}
1999 holds the line separator.
2000 \end{memberdesc}
2001
2002 \noindent The following additional functions are available in the \escript
2003 module:
2004 \begin{funcdesc}{setEscriptParamInt}{name,value}
2005 assigns the integer value \var{value} to the internal Escript parameter
2006 \var{name}. This should be considered an advanced feature and it is generally
2007 not required to call this function. One parameter worth mentioning is
2008 \var{name}="TOO_MANY_LINES" which affects the conversion of \Data objects to a
2009 string. If more than \var{value} lines would be created, a condensed format is
2010 used instead which reports the minimum and maximum values and general
2011 information about the \Data object rather than all values.
2012 \end{funcdesc}
2013
2014 \begin{funcdesc}{getEscriptParamInt}{name}
2015 returns the current value of internal Escript parameter \var{name}.
2016 \end{funcdesc}
2017
2018 \begin{funcdesc}{listEscriptParams}{a}
2019 returns a list of valid Escript parameters and their description.
2020 \end{funcdesc}
2021
2022 \begin{funcdesc}{getMPISizeWorld}{}
2023 returns the number of \MPI processes in use in the \env{MPI_COMM_WORLD}
2024 process group. If \MPI is not used 1 is returned.
2025 \end{funcdesc}
2026
2027 \begin{funcdesc}{getMPIRankWorld}{}
2028 returns the rank of the current process within the \env{MPI_COMM_WORLD}
2029 process group. If \MPI is not used 0 is returned.
2030 \end{funcdesc}
2031
2032 \begin{funcdesc}{MPIBarrierWorld}{}
2033 performs a barrier synchronization across all processes within the
2034 \env{MPI_COMM_WORLD} process group.
2035 \end{funcdesc}
2036
2037 \begin{funcdesc}{getMPIWorldMax}{a}
2038 returns the maximum value of the integer \var{a} across all processes within
2039 \env{MPI_COMM_WORLD}.
2040 \end{funcdesc}
2041
2042 \section{Lazy Evaluation of Data}
2043 \label{sec:lazy}
2044 Constant and Tagged representations of Data are relatively small but Expanded\footnote{Separate values stored for each point of the FunctionSpace.} are larger and
2045 will not entirely fit in CPU cache.
2046
2047 Escript's lazy evaluation features record operations performed on Data objects but do not actually carry them out until the Data is ``resolved''.
2048
2049 Consider the following code:
2050 \begin{python}
2051 from esys.escript import *
2052 from esys.dudley import Rectangle
2053 x=Rectangle(3,3)
2054 x=Rectangle(3,3).getX()
2055 c=Data((1.5, 1), x.getFunctionSpace())
2056 t=Data(((1,1),(0,1)), x.getFunctionSpace())
2057 t.tag()
2058 \end{python}
2059
2060 The variables \var{c}, \var{t}, \var{x} are stored as \texttt{constant}, \texttt{tagged} and \texttt{expanded} Data respectively.
2061 Printing those variables will show the values stored (or if we were to use a larger Rectangle, a summary).
2062
2063 \begin{python}
2064 v = matrix_mult(t,x) + c
2065 print(v.isExpanded())
2066 print(v)
2067 \end{python}
2068
2069 Will output \texttt{True} followed by all of the values for \var{v}.
2070 Now we'll introduce lazy evaluation:
2071
2072 \begin{python}
2073 xx = x.delay()
2074 print(xx.isExpanded(), xx.isLazy())
2075 print(x.isExpanded(), x.isLazy())
2076 print(xx)
2077 \end{python}
2078
2079 The first print will show that \var{xx} is not considered to be ``expanded'', while the second print shows that \var{x} is unaffected.
2080 The last print will produce something like:
2081 \begin{python}
2082 Lazy Data: [depth=0] E@0x55ed512ad760
2083 \end{python}
2084 The \texttt{E} before the \verb|@| shows that this lazy Data is wrapping ``expanded'' Data.
2085 Calling \texttt{.delay()} on constant or tagged Data results in \verb|C@...| and \verb|T@...| respectively.
2086
2087 If an input to an operation is lazy, then the result will be lazy as well\footnote{Matrix inverse is an exception to this.}:
2088 \begin{python}
2089 res = matrix_mult(t,-xx) + c
2090 print(res)
2091 \end{python}
2092 Will produce:
2093 \begin{python}
2094 Lazy Data: [depth=3] (prod(T@0x..., neg(E@...)) + C@0x...)
2095 \end{python}
2096 Depth indicates the largest number of operators from the top of the expression to the bottom.
2097
2098 To actually find the value of this lazy Data object, we need to resolve it:
2099 \begin{python}
2100 res.resolve()
2101 \end{python}
2102 Note that \texttt{resolve()} doesn't return a new object, but transforms the object it is called on.
2103 Printing, \var{res} now will show the values at each point.
2104
2105 \subsection{Lazyness and non-expanded Data}
2106 While it is possible to call delay on constant or tagged Data, escript will not build expressions consisting solely of such Data.
2107 \begin{python}
2108 cx=c.delay()
2109 res=cx+cx
2110 print(res)
2111 \end{python}
2112 would output:
2113 \begin{python}
2114 Lazy Data: [depth=0] C@0x55ed512cc7c0
2115 # Not
2116 Lazy Data: [depth=1] (C@0x... + C@0x...)
2117 \end{python}
2118
2119
2120 \subsection{When to resolve}
2121
2122 You are never \emph{required} to manually resolve lazy Data in \texttt{escript}.
2123 Any operations which need the actual values of an expression will either
2124 \begin{itemize}
2125 \item compute the values without resolving the whole Data object at once (solvers assembling FEM matrices)
2126 \item resolve the data automatically (everthing else)
2127 \end{itemize}
2128
2129 \noindent Escript will automatically resolve lazy Data:
2130 \begin{enumerate}
2131 \item If a matrix inversion operation is applied to the Data.
2132 \item If the expression tree becomes too deep\footnote{At time of writing, this threshold is somewhat arbitrarily set at \texttt{depth>9}, but this is configurable.}.
2133 \end{enumerate}
2134 Note, the second point is important when writing loops like this:
2135 \begin{python}
2136 # x is initial guess
2137 while err > tol:
2138 construct PDE coefficients involving x
2139 solve PDE
2140 calculate err
2141 update x
2142 \end{python}
2143
2144 After a few iterations of the loop, \var{x} may be something like \texttt{x=F(F(F(F(originalX))))}.
2145 So it will probably be better to \texttt{resolve} \var{x} at the end of each loop iteration.
2146 Alternatively, if \var{x} is included in many expressions in the loop, it may be better to resolve it earlier.
2147
2148 \subsection{Options for using lazy evaluation}
2149
2150 There are two ways to enable lazy evaluation:
2151 \begin{enumerate}
2152 \item Any escript script can make use of lazy evaluation by \texttt{delay()}-ing one of its expanded Data variables.
2153 Any expressions including that delayed variable (directly or indirectly) will be lazy until resolved.
2154 \item Setting the \texttt{AUTOLAZY} parameter for \texttt{escript} to \texttt{1}.
2155 In this case, most escript operation which would normally produce extended Data, will produce lazy Data instead.
2156 In general, this option is not recommended for two reasons:
2157 \begin{itemize}
2158 \item AUTOLAZY uses the \texttt{setEscriptParamInt()} which is not guaranteed to have continued support.
2159 \item Making everything lazy instead of just more complex objects is not likely to give significant efficiency improvements.
2160 \end{itemize}
2161 \end{enumerate}
2162
2163 \subsection{When to use lazy evaluation?}
2164 Exactly when using lazy evaluation will be more efficient is still an open question.
2165 When the objects being manipulated are large (eg 4-Tensors in Drucker-Prager), significant memory and runtime improvements can be achieved.
2166 See~\cite{lazyauspdc}.
2167
2168 Our best advice is to experiment with it.
2169
2170

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26