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

Revision 3309 - (show annotations)
Tue Oct 26 03:56:26 2010 UTC (8 years, 10 months ago) by caltinay
File MIME type: application/x-tex
File size: 72274 byte(s)
Updated escript section with added DataManager reference.


 1 2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 3 % 4 % Copyright (c) 2003-2010 by University of Queensland 5 % Earth Systems Science Computational Center (ESSCC) 6 7 % 8 % Primary Business: Queensland, Australia 9 % Licensed under the Open Software License version 3.0 10 11 % 12 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 13 14 \chapter{The \escript Module}\label{ESCRIPT CHAP} 15 16 \section{Concepts} 17 \escript is a \PYTHON module that allows you to represent the values of 18 a function at points in a \Domain in such a way that the function will 19 be useful for the Finite Element Method (FEM) simulation. It also 20 provides what we call a function space that describes how the data is 21 used in the simulation. Stored along with the data is information 22 about the elements and nodes which will be used by \finley. 23 24 \subsection{Function spaces} 25 In order to understand what we mean by the term 'function space', 26 consider that the solution of a partial differential 27 equation\index{partial differential equation} (PDE) is a function on a domain 28 $\Omega$. When solving a PDE using FEM, the solution is 29 piecewise-differentiable but, in general, its gradient is discontinuous. 30 To reflect these different degrees of smoothness, different function spaces 31 are used. 32 For instance, in FEM, the displacement field is represented by its values at 33 the nodes of the mesh, and so is continuous. 34 The strain, which is the symmetric part of the gradient of the displacement 35 field, is stored on the element centers, and so is considered to be 36 discontinuous. 37 38 A function space is described by a \FunctionSpace object. 39 The following statement generates the object \var{solution_space} which is 40 a \FunctionSpace object and provides access to the function space of 41 PDE solutions on the \Domain \var{mydomain}: 42 43 \begin{python} 44 solution_space=Solution(mydomain) 45 \end{python} 46 The following generators for function spaces on a \Domain \var{mydomain} are commonly used: 47 \begin{itemize} 48 \item \var{Solution(mydomain)}: solutions of a PDE 49 \item \var{ReducedSolution(mydomain)}: solutions of a PDE with a reduced 50 smoothness requirement, e.g. using a lower order approximation on the same 51 element or using macro elements\index{macro elements} 52 \item \var{ContinuousFunction(mydomain)}: continuous functions, e.g. a temperature distribution 53 \item \var{Function(mydomain)}: general functions which are not necessarily continuous, e.g. a stress field 54 \item \var{FunctionOnBoundary(mydomain)}: functions on the boundary of the domain, e.g. a surface pressure 55 \item \var{FunctionOnContact0(mydomain)}: functions on side $0$ of the discontinuity 56 \item \var{FunctionOnContact1(mydomain)}: functions on side $1$ of the discontinuity 57 \end{itemize} 58 In some cases under-integration is used. For these cases the user may use a 59 \FunctionSpace from the following list: 60 \begin{itemize} 61 \item \var{ReducedFunction(mydomain)} 62 \item \var{ReducedFunctionOnBoundary(mydomain)} 63 \item \var{ReducedFunctionOnContact0(mydomain)} 64 \item \var{ReducedFunctionOnContact1(mydomain)} 65 \end{itemize} 66 In comparison to the corresponding full version they use a reduced number of 67 integration nodes (typically one only) to represent values. 68 69 \begin{figure} 70 \centering 71 \includegraphics{EscriptDiagram1} 72 \caption{\label{ESCRIPT DEP}Dependency of function spaces in \finley. 73 An arrow indicates that a function in the \FunctionSpace at the starting point 74 can be interpolated to the \FunctionSpace of the arrow target. 75 All function spaces above the dotted line can be interpolated to any of 76 the function spaces below the line. See also \Sec{SEC Projection}.} 77 \end{figure} 78 79 The reduced smoothness for a PDE solution is often used to fulfill the 80 Ladyzhenskaya-Babuska-Brezzi condition\cite{LBB} when solving saddle point 81 problems\index{saddle point problems}, e.g. the Stokes equation. 82 A discontinuity\index{discontinuity} is a region within the domain across 83 which functions may be discontinuous. 84 The location of a discontinuity is defined in the \Domain object. 85 \fig{ESCRIPT DEP} shows the dependency between the types of function spaces 86 in \finley (other libraries may have different relationships). 87 88 The solution of a PDE is a continuous function. Any continuous function can 89 be seen as a general function on the domain and can be restricted to the 90 boundary as well as to one side of a discontinuity (the result will be 91 different depending on which side is chosen). Functions on any side of the 92 discontinuity can be seen as a function on the corresponding other side. 93 94 A function on the boundary or on one side of the discontinuity cannot be seen 95 as a general function on the domain as there are no values defined for the 96 interior. For most PDE solver libraries the space of the solution and 97 continuous functions is identical, however in some cases, for example when 98 periodic boundary conditions are used in \finley, a solution fulfills periodic 99 boundary conditions while a continuous function does not have to be periodic. 100 101 The concept of function spaces describes the properties of functions and 102 allows abstraction from the actual representation of the function in the 103 context of a particular application. For instance, in the FEM context a 104 function of the \Function type (written as \emph{Function()} in \fig{ESCRIPT DEP}) 105 is usually represented by its values at the element center, 106 but in a finite difference scheme the edge midpoint of cells is preferred. 107 By changing its function space you can use the same function in a Finite 108 Difference scheme instead of Finite Element scheme. 109 Changing the function space of a particular function will typically lead to 110 a change of its representation. 111 So, when seen as a general function, a continuous function which is typically 112 represented by its values on the nodes of the FEM mesh or finite difference 113 grid must be interpolated to the element centers or the cell edges, 114 respectively. Interpolation happens automatically in \escript whenever it is 115 required\index{interpolation}. The user needs to be aware that an 116 interpolation is not always possible, see \fig{ESCRIPT DEP} for \finley. 117 An alternative approach to change the representation (=\FunctionSpace) is 118 projection\index{projection}, see \Sec{SEC Projection}. 119 120 \subsection{\Data Objects} 121 In \escript the class that stores these functions is called \Data. 122 The function is represented through its values on \DataSamplePoints where 123 the \DataSamplePoints are chosen according to the function space of the 124 function. 125 \Data class objects are used to define the coefficients of the PDEs to be 126 solved by a PDE solver library and also to store the solutions of the PDE. 127 128 The values of the function have a rank which gives the number of indices, 129 and a \Shape defining the range of each index. 130 The rank in \escript is limited to the range 0 through 4 and it is assumed 131 that the rank and \Shape is the same for all \DataSamplePoints. 132 The \Shape of a \Data object is a tuple (list) \var{s} of integers. 133 The length of \var{s} is the rank of the \Data object and the \var{i}-th 134 index ranges between 0 and $\var{s[i]}-1$. 135 For instance, a stress field has rank 2 and \Shape $(d,d)$ where $d$ is the 136 spatial dimension. 137 The following statement creates the \Data object \var{mydat} representing a 138 continuous function with values of \Shape $(2,3)$ and rank $2$: 139 \begin{python} 140 mydat=Data(value=1, what=ContinuousFunction(myDomain), shape=(2,3)) 141 \end{python} 142 The initial value is the constant 1 for all \DataSamplePoints and all 143 components. 144 145 \Data objects can also be created from any \numpy array or any object, such 146 as a list of floating point numbers, that can be converted into 147 a \numpyNDA\cite{NUMPY}. 148 The following two statements create objects which are equivalent 149 to \var{mydat}: 150 \begin{python} 151 mydat1=Data(value=numpy.ones((2,3)), what=ContinuousFunction(myDomain)) 152 mydat2=Data(value=[[1,1], [1,1], [1,1]], what=ContinuousFunction(myDomain)) 153 \end{python} 154 In the first case the initial value is \var{numpy.ones((2,3))} which generates 155 a $2 \times 3$ matrix as a \numpyNDA filled with ones. 156 The \Shape of the created \Data object is taken from the \Shape of the array. 157 In the second case, the creator converts the initial value, which is a list of 158 lists, into a \numpyNDA before creating the actual \Data object. 159 160 For convenience \escript provides creators for the most common types 161 of \Data objects in the following forms (\var{d} defines the spatial dimension): 162 \begin{itemize} 163 \item \code{Scalar(0, Function(mydomain))} is the same as \code{Data(0, Function(myDomain),(,))} 164 (each value is a scalar), e.g. a temperature field 165 \item \code{Vector(0, Function(mydomain))} is the same as \code{Data(0, Function(myDomain),(d))} 166 (each value is a vector), e.g. a velocity field 167 \item \code{Tensor(0, Function(mydomain))} is the same as \code{Data(0, Function(myDomain), (d,d))}, 168 e.g. a stress field 169 \item \code{Tensor4(0,Function(mydomain))} is the same as \code{Data(0,Function(myDomain), (d,d,d,d))} 170 e.g. a Hook tensor field 171 \end{itemize} 172 Here the initial value is 0 but any object that can be converted into 173 a \numpyNDA and whose \Shape is consistent with \Shape of the \Data object to 174 be created can be used as the initial value. 175 176 \Data objects can be manipulated by applying unary operations (e.g. cos, sin, 177 log), and they can be combined point-wise by applying arithmetic operations 178 (e.g. +, - ,* , /). 179 We emphasize that \escript itself does not handle any spatial dependencies as 180 it does not know how values are interpreted by the processing PDE solver library. 181 However \escript invokes interpolation if this is needed during data manipulations. 182 Typically, this occurs in binary operations when both arguments belong to 183 different function spaces or when data are handed over to a PDE solver library 184 which requires functions to be represented in a particular way. 185 186 The following example shows the usage of \Data objects. Assume we have a 187 displacement field $u$ and we want to calculate the corresponding stress field 188 $\sigma$ using the linear-elastic isotropic material model 189 \begin{eqnarray}\label{eq: linear elastic stress} 190 \sigma_{ij}=\lambda u_{k,k} \delta_{ij} + \mu ( u_{i,j} + u_{j,i}) 191 \end{eqnarray} 192 where $\delta_{ij}$ is the Kronecker symbol and 193 $\lambda$ and $\mu$ are the Lame coefficients. The following function 194 takes the displacement \var{u} and the Lame coefficients \var{lam} and \var{mu} 195 as arguments and returns the corresponding stress: 196 \begin{python} 197 from esys.escript import * 198 def getStress(u, lam, mu): 199 d=u.getDomain().getDim() 200 g=grad(u) 201 stress=lam*trace(g)*kronecker(d)+mu*(g+transpose(g)) 202 return stress 203 \end{python} 204 The variable \var{d} gives the spatial dimension of the domain on which the 205 displacements are defined. 206 \var{kronecker} returns the Kronecker symbol with indexes $i$ and $j$ running 207 from 0 to \var{d}-1. 208 The call \var{grad(u)} requires the displacement field \var{u} to be in 209 the \var{Solution} or \ContinuousFunction. 210 The result \var{g} as well as the returned stress will be in the \Function. 211 If, for example, \var{u} is the solution of a PDE then \code{getStress} might 212 be called in the following way: 213 \begin{python} 214 s=getStress(u, 1., 2.) 215 \end{python} 216 However \code{getStress} can also be called with \Data objects as values for 217 \var{lam} and \var{mu} which, for instance in the case of a temperature 218 dependency, are calculated by an expression. 219 The following call is equivalent to the previous example: 220 \begin{python} 221 lam=Scalar(1., ContinuousFunction(mydomain)) 222 mu=Scalar(2., Function(mydomain)) 223 s=getStress(u, lam, mu) 224 \end{python} 225 % 226 The function \var{lam} belongs to the \ContinuousFunction but with \var{g} the 227 function \var{trace(g)} is in the \Function. 228 In the evaluation of the product \var{lam*trace(g)} we have different function 229 spaces (on the nodes versus in the centers) and at first glance we have incompatible data. 230 \escript converts the arguments into an appropriate function space according 231 to \fig{ESCRIPT DEP}. 232 In this example that means \escript sees \var{lam} as a function of the \Function. 233 In the context of FEM this means the nodal values of \var{lam} are 234 interpolated to the element centers. 235 The interpolation is automatic and requires no special handling. 236 237 \begin{figure} 238 \centering 239 \includegraphics{EscriptDiagram2} 240 \caption{\label{Figure: tag}Element Tagging. A rectangular mesh over a region 241 with two rock types {\it white} and {\it gray} is shown. 242 The number in each cell refers to the major rock type present in the cell 243 ($1$ for {\it white} and $2$ for {\it gray}).} 244 \end{figure} 245 246 \subsection{Tagged, Expanded and Constant Data} 247 Material parameters such as the Lame coefficients are typically dependent on 248 rock types present in the area of interest. 249 A common technique to handle these kinds of material parameters is 250 \emph{tagging}\index{tagging}, which uses storage efficiently. 251 \fig{Figure: tag} shows an example. In this case two rock types {\it white} 252 and {\it gray} can be found in the domain. 253 The domain is subdivided into triangular shaped cells. 254 Each cell has a tag indicating the rock type predominantly found in this cell. 255 Here $1$ is used to indicate rock type {\it white} and $2$ for rock type {\it gray}. 256 The tags are assigned at the time when the cells are generated and stored in 257 the \Domain class object. To allow easier usage of tags, names can be used 258 instead of numbers. These names are typically defined at the time when the 259 geometry is generated. 260 261 The following statements show how to use tagged values for \var{lam} as shown 262 in \fig{Figure: tag} for the stress calculation discussed above: 263 \begin{python} 264 lam=Scalar(value=2., what=Function(mydomain)) 265 insertTaggedValue(lam, white=30., gray=5000.) 266 s=getStress(u, lam, 2.) 267 \end{python} 268 In this example \var{lam} is set to $30$ for those cells with tag {\it white} 269 (=$1$) and to $5000$ for cells with tag {\it gray} (=$2$). 270 The initial value $2$ of \var{lam} is used as a default value for the case 271 when a tag is encountered which has not been linked with a value. 272 The \code{getStress} method does not need to be changed now that we are using tags. 273 \escript resolves the tags when \var{lam*trace(g)} is calculated. 274 275 This brings us to a very important point about \escript. 276 You can develop a simulation with constant Lame coefficients, and then later 277 switch to tagged Lame coefficients without otherwise changing your \PYTHON script. 278 In short, you can use the same script for models with different domains and 279 different types of input data. 280 281 There are three main ways in which \Data objects are represented internally -- 282 constant, tagged, and expanded. 283 In the constant case, the same value is used at each sample point while only a 284 single value is stored to save memory. 285 In the expanded case, each sample point has an individual value (such as for the solution of a PDE). 286 This is where your largest data sets will be created because the values are 287 stored as a complete array. 288 The tagged case has already been discussed above. 289 Expanded data is created when specifying \code{expanded=True} in the \Data 290 object constructor, while tagged data requires calling the \member{insertTaggedValue} 291 method as shown above. 292 293 Values are accessed through a sample reference number. 294 Operations on expanded \Data objects have to be performed for each sample 295 point individually. 296 When tagged values are used, the values are held in a dictionary. 297 Operations on tagged data require processing the set of tagged values only, 298 rather than processing the value for each individual sample point. 299 \escript allows any mixture of constant, tagged and expanded data in a single expression. 300 301 \subsection{Saving and Restoring Simulation Data} 302 \Data objects can be written to disk files with the \member{dump} method and 303 read back using the \member{load} method, both of which use the 304 \netCDF\cite{NETCDF} file format. 305 Use these to save data for checkpoint/restart or simply to save and reuse data 306 that was expensive to compute. 307 For instance, to save the coordinates of the data points of a 308 \ContinuousFunction to the file \file{x.nc} use 309 \begin{python} 310 x=ContinuousFunction(mydomain).getX() 311 x.dump("x.nc") 312 mydomain.dump("dom.nc") 313 \end{python} 314 To recover the object \var{x}, and you know that \var{mydomain} was an \finley 315 mesh, use 316 \begin{python} 317 from esys.finley import LoadMesh 318 mydomain=LoadMesh("dom.nc") 319 x=load("x.nc", mydomain) 320 \end{python} 321 Obviously, it is possible to execute the same steps that were originally used 322 to generate \var{mydomain} to recreate it. However, in most cases using 323 \member{dump} and \member{load} is faster, particularly if optimization has 324 been applied. 325 If \escript is running on more than one \MPI process \member{dump} will create 326 an individual file for each process containing the local data. 327 In order to avoid conflicts the file names are extended by the \MPI processor 328 rank, that is instead of one file \file{dom.nc} you would get 329 \file{dom.nc.0000}, \file{dom.nc.0001}, etc. You still call 330 \code{LoadMesh("dom.nc")} to load the domain but you have to make sure that 331 the appropriate file is accessible from the corresponding rank, and loading 332 will only succeed if you run with as many processes as were used when calling 333 \member{dump}. 334 335 The function space of the \Data is stored in \file{x.nc}. 336 If the \Data object is expanded, the number of data points in the file and of 337 the \Domain for the particular \FunctionSpace must match. 338 Moreover, the ordering of the values is checked using the reference 339 identifiers provided by \FunctionSpace on the \Domain. 340 In some cases, data points will be reordered so be aware and confirm that you 341 get what you wanted. 342 343 A newer, more flexible way of saving and restoring \escript simulation data 344 is through a \class{DataManager} class object. 345 It has the advantage of allowing to save and load not only a \Domain and 346 \Data objects but also other values\footnote{The \PYTHON \emph{pickle} module 347 is used for other types.} you compute in your simulation script. 348 Further, \class{DataManager} objects can simultaneously create files for 349 visualization so no extra calls to \code{saveVTK} etc. are needed. 350 351 The following example shows how the \class{DataManager} class can be used. 352 For an explanation of all member functions and options see the class reference 353 section \ref{sec:datamanager}. 354 \begin{python} 355 from esys.escript import DataManager, Scalar, Function 356 from esys.finley import Rectangle 357 358 dm = DataManager(formats=[DataManager.RESTART, DataManager.VTK]) 359 if dm.hasData(): 360 mydomain=dm.getDomain() 361 val=dm.getValue("val") 362 t=dm.getValue("t") 363 t_max=dm.getValue("t_max") 364 else: 365 mydomain=Rectangle() 366 val=Function(mydomain).getX() 367 t=0. 368 t_max=2.5 369 370 while t$\var{maxval} the value \var{maxval} is used. 1302 1303 Now we produce our new \Data object: 1304 1305 \begin{python} 1306 result=x0.interpolateTable(sine_table, minval, step, toobig) 1307 \end{python} 1308 Any values which interpolate to larger than \var{toobig} will raise an 1309 exception. You can switch on boundary checking by adding 1310 \code{check_boundaries=True} to the argument list. 1311 1312 Now consider a 2D example. We will interpolate a surface such that the bottom 1313 edge is the sine curve described above. 1314 The amplitude of the curve decreases as we move towards the top edge. 1315 Our interpolation table will have three rows: 1316 1317 \begin{python} 1318 st=numpy.array(sine_table) 1319 table=[st, 0.5*st, 0*st] 1320 \end{python} 1321 % 1322 The use of \numpy and multiplication here is just to save typing. 1323 1324 \begin{python} 1325 result2=x1.interpolateTable(table, 0, 0.55, x0, minval, step, toobig) 1326 \end{python} 1327 1328 In the 2D case, the parameters for the \var{x1} direction (min=0, step=0.55) 1329 come first followed by the \var{x0} data object and its parameters. 1330 By default, if a point is specified which is outside the boundary, then 1331 \var{interpolateTable} will operate as if the point was on the boundary. 1332 Passing \code{check_boundaries=True} will cause \var{interpolateTable} to 1333 reject any points outside the boundaries. 1334 1335 \subsection{The \var{DataManager} Class} 1336 \label{sec:datamanager} 1337 1338 \begin{classdesc}{DataManager}{formats=[RESTART], work_dir=".", restart_prefix="restart", do_restart=\True} 1339 initializes a new \var{DataManager} object which can be used to save, 1340 restore and export simulation data in a number of formats. 1341 All files and directories saved or restored by this object are located 1342 under the directory specified by \var{work_dir}. 1343 If \var{RESTART} is specified in \var{formats}, the \var{DataManager} will 1344 look for directories whose name starts with \var{restart_prefix}. 1345 In case \var{do_restart} is \True, the last of these directories is used 1346 to restore simulation data while all others are deleted. 1347 If \var{do_restart} is \False, then all of those directories are deleted. 1348 The \var{restart_prefix} and \var{do_restart} parameters are ignored if 1349 \var{RESTART} is not specified in \var{formats}. 1350 \end{classdesc} 1351 1352 \noindent Valid values for the \var{formats} parameter are: 1353 \begin{memberdesc}[DataManager]{RESTART} 1354 enables writing of checkpoint files to be able to continue simulations 1355 as explained in the class description. 1356 \end{memberdesc} 1357 \begin{memberdesc}[DataManager]{SILO} 1358 exports simulation data in the \SILO file format. \escript must have 1359 been compiled with \SILO support for this to work. 1360 \end{memberdesc} 1361 \begin{memberdesc}[DataManager]{VISIT} 1362 enables the \VisIt simulation interface which allows connecting to and 1363 interacting with the running simulation from a compatible \VisIt client. 1364 \escript must have been compiled with \VisIt (version 2) support and the 1365 version of the client has to match the version used at compile time. 1366 In order to connect to the simulation the client needs to have access and 1367 load the file \file{escriptsim.sim2} located under the work directory. 1368 \end{memberdesc} 1369 \begin{memberdesc}[DataManager]{VTK} 1370 exports simulation data in the \VTK file format. 1371 \end{memberdesc} 1372 1373 \noindent The \var{DataManager} class has the following methods: 1374 \begin{methoddesc}[DataManager]{addData}{**data} 1375 adds \Data objects and other data to the manager. Calling this method does 1376 not save or export the data yet so it is allowed to incrementally add data 1377 at various points in the simulation script if required. 1378 Note, that only a single domain is supported so all \Data objects have to 1379 be defined on the same one or an exception is raised. 1380 \end{methoddesc} 1381 1382 \begin{methoddesc}[DataManager]{setDomain}{domain} 1383 explicitly sets the domain for this manager. 1384 It is generally not required to call this method directly. 1385 Instead, the \var{addData} method will set the domain used by the \Data 1386 objects. 1387 An exception is raised if the domain was set to a different domain before 1388 (explicitly or implicitly). 1389 \end{methoddesc} 1390 1391 \begin{methoddesc}[DataManager]{hasData}{} 1392 returns \True if the manager has loaded simulation data for a restart. 1393 \end{methoddesc} 1394 1395 \begin{methoddesc}[DataManager]{getDomain}{} 1396 returns the domain as recovered from a restart. 1397 \end{methoddesc} 1398 1399 \begin{methoddesc}[DataManager]{getValue}{value_name} 1400 returns a \Data object or other value with the name \var{value_name} that 1401 has been recovered after a restart. 1402 \end{methoddesc} 1403 1404 \begin{methoddesc}[DataManager]{getCycle}{} 1405 returns the export cycle, i.e. the number of time \var{export()} has been 1406 called. 1407 \end{methoddesc} 1408 1409 \begin{methoddesc}[DataManager]{setCheckpointFrequency}{freq} 1410 sets the frequency with which checkpoint files are created. This is only 1411 useful if the \var{DataManager} object was created with at least one other 1412 format next to \var{RESTART}. The frequency is 1 by default which means 1413 that checkpoint files are created every time \var{export()} is called. 1414 Unlike visualization output, a simulation checkpoint is usually not 1415 required at every time step. Thus, the frequency can be decreased by 1416 calling this method with$\var{freq}>1$which would then create restart 1417 files every \var{freq} times \var{export()} is called. 1418 \end{methoddesc} 1419 1420 \begin{methoddesc}[DataManager]{setTime}{time} 1421 sets the simulation time stamp. This floating point number is stored in 1422 the metadata of exported data but not used by \var{RESTART}. 1423 \end{methoddesc} 1424 1425 \begin{methoddesc}[DataManager]{setMeshLabels}{x, y, z=""} 1426 sets labels for the mesh axes. These are currently only used by the \SILO 1427 exporter. 1428 \end{methoddesc} 1429 1430 \begin{methoddesc}[DataManager]{setMeshUnits}{x, y, z=""} 1431 sets units for the mesh axes. These are currently only used by the \SILO 1432 exporter. 1433 \end{methoddesc} 1434 1435 \begin{methoddesc}[DataManager]{setMetadataSchemaString}{schema, metadata=""} 1436 sets metadata namespaces and the corresponding metadata. These are 1437 currently only used by the \VTK exporter. 1438 \var{schema} is a dictionary that maps prefixes to namespace names, e.g.\\ 1439 \code{\{"gml": "http://www.opengis.net/gml"\}} and \var{metadata} is a 1440 string with the actual content which will be enclosed in \var{} 1441 tags. 1442 \end{methoddesc} 1443 1444 \begin{methoddesc}[DataManager]{export}{} 1445 executes the actual data export. Depending on the \var{formats} parameter 1446 used in the constructor all data added by \var{addData()} is written to 1447 disk (\var{RESTART,SILO,VTK}) or made available through the \VisIt 1448 simulation interface (\var{VISIT}). 1449 At least the domain must be set for something to be exported. 1450 \end{methoddesc} 1451 1452 \subsection{Saving Data as CSV} 1453 \index{saveDataCSV}\index{CSV} 1454 For simple post-processing, \Data objects can be saved in comma separated 1455 value (\emph{CSV}) format. 1456 If \var{mydata1} and \var{mydata2} are scalar data, the command 1457 \begin{python} 1458 saveDataCSV('output.csv', U=mydata1, V=mydata2) 1459 \end{python} 1460 will record the values in \file{output.csv} in the following format: 1461 \begin{verbatim} 1462 U, V 1463 1.0000000e+0, 2.0000000e-1 1464 5.0000000e-0, 1.0000000e+1 1465 ... 1466 \end{verbatim} 1467 1468 The names of the keyword parameters form the names of columns in the output. 1469 If the data objects are over different function spaces, then \var{saveDataCSV} 1470 will attempt to interpolate to a common function space. 1471 If this is not possible, then an exception is raised. 1472 1473 Output can be restricted using a scalar mask as follows: 1474 \begin{python} 1475 saveDataCSV('outfile.csv', U=mydata1, V=mydata2, mask=myscalar) 1476 \end{python} 1477 This command will only output those rows which correspond to to positive 1478 values of \var{myscalar}. 1479 Some aspects of the output can be tuned using additional parameters: 1480 \begin{python} 1481 saveDataCSV('data.csv', append=True, sep=' ', csep='/', mask=mymask, e=mat1) 1482 \end{python} 1483 1484 \begin{itemize} 1485 \item \var{append} -- specifies that the output should be written to the end of an existing file 1486 \item \var{sep} -- defines the separator between fields 1487 \item \var{csep} -- defines the separator between components in the header 1488 line. For example between the components of a matrix. 1489 \end{itemize} 1490 % 1491 The above command would produce output like this: 1492 \begin{verbatim} 1493 e/0/0 e/1/0 e/0/1 e/1/1 1494 1.0000000000e+00 2.0000000000e+00 3.0000000000e+00 4.0000000000e+00 1495 ... 1496 \end{verbatim} 1497 1498 Note that while the order in which rows are output can vary, all the elements 1499 in a given row always correspond to the same input. 1500 1501 \subsection{The \Operator Class} 1502 The \Operator class provides an abstract access to operators built 1503 within the \LinearPDE class. \Operator objects are created 1504 when a PDE is handed over to a PDE solver library and handled 1505 by the \LinearPDE object defining the PDE. The user can gain access 1506 to the \Operator of a \LinearPDE object through the \var{getOperator} 1507 method. 1508 1509 \begin{classdesc}{Operator}{} 1510 creates an empty \Operator object. 1511 \end{classdesc} 1512 1513 \begin{methoddesc}[Operator]{isEmpty}{fileName} 1514 returns \True is the object is empty, \False otherwise. 1515 \end{methoddesc} 1516 1517 \begin{methoddesc}[Operator]{setValue}{value} 1518 resets all entries in the object representation to \var{value}. 1519 \end{methoddesc} 1520 1521 \begin{methoddesc}[Operator]{solves}{rhs} 1522 solves the operator equation with right hand side \var{rhs}. 1523 \end{methoddesc} 1524 1525 \begin{methoddesc}[Operator]{of}{u} 1526 applies the operator to the \Data object \var{u}. 1527 \end{methoddesc} 1528 1529 \begin{methoddesc}[Operator]{saveMM}{fileName}\index{Matrix Market} 1530 saves the object to a Matrix Market format file with name \var{fileName}, see 1531 \url{http://maths.nist.gov/MatrixMarket} 1532 \end{methoddesc} 1533 1534 \section{Physical Units} 1535 \escript provides support for physical units in the SI system\index{SI units} 1536 including unit conversion. So the user can define variables in the form 1537 \begin{python} 1538 from esys.escript.unitsSI import * 1539 l=20*m 1540 w=30*kg 1541 w2=40*lb 1542 T=100*Celsius 1543 \end{python} 1544 In the two latter cases a conversion from pounds\index{pounds} and degrees 1545 Celsius\index{Celsius} is performed into the appropriate SI units \emph{kg} 1546 and \emph{Kelvin}. 1547 In addition, composed units can be used, for instance 1548 \begin{python} 1549 from esys.escript.unitsSI import * 1550 rho=40*lb/cm**3 1551 \end{python} 1552 defines the density in the units of pounds per cubic centimeter. 1553 The value$40$will be converted into SI units, in this case kg per cubic 1554 meter. Moreover unit prefixes are supported: 1555 \begin{python} 1556 from esys.escript.unitsSI import * 1557 p=40*Mega*Pa 1558 \end{python} 1559 The pressure \var{p} is set to 40 Mega Pascal. Units can also be converted 1560 back from the SI system into a desired unit, e.g. 1561 \begin{python} 1562 from esys.escript.unitsSI import * 1563 print p/atm 1564 \end{python} 1565 can be used print the pressure in units of atmosphere\index{atmosphere}. 1566 1567 The following is an incomplete list of supported physical units: 1568 1569 \begin{datadesc}{km} 1570 unit of kilometer 1571 \end{datadesc} 1572 1573 \begin{datadesc}{m} 1574 unit of meter 1575 \end{datadesc} 1576 1577 \begin{datadesc}{cm} 1578 unit of centimeter 1579 \end{datadesc} 1580 1581 \begin{datadesc}{mm} 1582 unit of millimeter 1583 \end{datadesc} 1584 1585 \begin{datadesc}{sec} 1586 unit of second 1587 \end{datadesc} 1588 1589 \begin{datadesc}{minute} 1590 unit of minute 1591 \end{datadesc} 1592 1593 \begin{datadesc}{h} 1594 unit of hour 1595 \end{datadesc} 1596 1597 \begin{datadesc}{day} 1598 unit of day 1599 \end{datadesc} 1600 1601 \begin{datadesc}{yr} 1602 unit of year 1603 \end{datadesc} 1604 1605 \begin{datadesc}{gram} 1606 unit of gram 1607 \end{datadesc} 1608 1609 \begin{datadesc}{kg} 1610 unit of kilogram 1611 \end{datadesc} 1612 1613 \begin{datadesc}{lb} 1614 unit of pound 1615 \end{datadesc} 1616 1617 \begin{datadesc}{ton} 1618 metric ton 1619 \end{datadesc} 1620 1621 \begin{datadesc}{A} 1622 unit of Ampere 1623 \end{datadesc} 1624 1625 \begin{datadesc}{Hz} 1626 unit of Hertz 1627 \end{datadesc} 1628 1629 \begin{datadesc}{N} 1630 unit of Newton 1631 \end{datadesc} 1632 1633 \begin{datadesc}{Pa} 1634 unit of Pascal 1635 \end{datadesc} 1636 1637 \begin{datadesc}{atm} 1638 unit of atmosphere 1639 \end{datadesc} 1640 1641 \begin{datadesc}{J} 1642 unit of Joule 1643 \end{datadesc} 1644 1645 \begin{datadesc}{W} 1646 unit of Watt 1647 \end{datadesc} 1648 1649 \begin{datadesc}{C} 1650 unit of Coulomb 1651 \end{datadesc} 1652 1653 \begin{datadesc}{V} 1654 unit of Volt 1655 \end{datadesc} 1656 1657 \begin{datadesc}{F} 1658 unit of Farad 1659 \end{datadesc} 1660 1661 \begin{datadesc}{Ohm} 1662 unit of Ohm 1663 \end{datadesc} 1664 1665 \begin{datadesc}{K} 1666 unit of degrees Kelvin 1667 \end{datadesc} 1668 1669 \begin{datadesc}{Celsius} 1670 unit of degrees Celsius 1671 \end{datadesc} 1672 1673 \begin{datadesc}{Fahrenheit} 1674 unit of degrees Fahrenheit 1675 \end{datadesc} 1676 1677 \noindent Supported unit prefixes: 1678 1679 \begin{datadesc}{Yotta} 1680 prefix yotta =$10^{24}$1681 \end{datadesc} 1682 1683 \begin{datadesc}{Zetta} 1684 prefix zetta =$10^{21}$1685 \end{datadesc} 1686 1687 \begin{datadesc}{Exa} 1688 prefix exa =$10^{18}$1689 \end{datadesc} 1690 1691 \begin{datadesc}{Peta} 1692 prefix peta =$10^{15}$1693 \end{datadesc} 1694 1695 \begin{datadesc}{Tera} 1696 prefix tera =$10^{12}$1697 \end{datadesc} 1698 1699 \begin{datadesc}{Giga} 1700 prefix giga =$10^9$1701 \end{datadesc} 1702 1703 \begin{datadesc}{Mega} 1704 prefix mega =$10^6$1705 \end{datadesc} 1706 1707 \begin{datadesc}{Kilo} 1708 prefix kilo =$10^3$1709 \end{datadesc} 1710 1711 \begin{datadesc}{Hecto} 1712 prefix hecto =$10^2$1713 \end{datadesc} 1714 1715 \begin{datadesc}{Deca} 1716 prefix deca =$10^1$1717 \end{datadesc} 1718 1719 \begin{datadesc}{Deci} 1720 prefix deci =$10^{-1}$1721 \end{datadesc} 1722 1723 \begin{datadesc}{Centi} 1724 prefix centi =$10^{-2}$1725 \end{datadesc} 1726 1727 \begin{datadesc}{Milli} 1728 prefix milli =$10^{-3}$1729 \end{datadesc} 1730 1731 \begin{datadesc}{Micro} 1732 prefix micro =$10^{-6}$1733 \end{datadesc} 1734 1735 \begin{datadesc}{Nano} 1736 prefix nano =$10^{-9}$1737 \end{datadesc} 1738 1739 \begin{datadesc}{Pico} 1740 prefix pico =$10^{-12}$1741 \end{datadesc} 1742 1743 \begin{datadesc}{Femto} 1744 prefix femto =$10^{-15}$1745 \end{datadesc} 1746 1747 \begin{datadesc}{Atto} 1748 prefix atto =$10^{-18}$1749 \end{datadesc} 1750 1751 \begin{datadesc}{Zepto} 1752 prefix zepto =$10^{-21}$1753 \end{datadesc} 1754 1755 \begin{datadesc}{Yocto} 1756 prefix yocto =$10^{-24}\$ 1757 \end{datadesc} 1758 1759 \section{Utilities} 1760 The \class{FileWriter} class provides a mechanism to write data to a file. 1761 In essence, this class wraps the standard \PYTHON \class{file} class to write 1762 data that are global in \MPI to a file. In fact, data are written on the 1763 processor with \MPI rank 0 only. It is recommended to use \class{FileWriter} 1764 rather than \class{open} in order to write code that will run with and without 1765 \MPI. It is safe to use \class{open} under \MPI to \emph{read} data which are 1766 global under \MPI. 1767 1768 \begin{classdesc}{FileWriter}{fn\optional{,append=\False, \optional{createLocalFiles=\False}})} 1769 Opens a file with name \var{fn} for writing. If \var{append} is set to \True 1770 data are appended at the end of the file. 1771 If running under \MPI, only the first processor (rank==0) will open the file 1772 and write to it. 1773 If \var{createLocalFiles} is set each individual processor will create a file 1774 where for any processor with rank>0 the file name is extended by its rank. 1775 This option is normally used for debugging purposes only. 1776 \end{classdesc} 1777 1778 \noindent The following methods are available: 1779 \begin{methoddesc}[FileWriter]{close}{} 1780 closes the file. 1781 \end{methoddesc} 1782 \begin{methoddesc}[FileWriter]{flush}{} 1783 flushes the internal buffer to disk. 1784 \end{methoddesc} 1785 \begin{methoddesc}[FileWriter]{write}{txt} 1786 writes string \var{txt} to the file. Note that a newline is not added. 1787 \end{methoddesc} 1788 \begin{methoddesc}[FileWriter]{writelines}{txts} 1789 writes the list \var{txts} of strings to the file. 1790 Note that newlines are not added. 1791 This method is equivalent to calling \var{write()} for each string. 1792 \end{methoddesc} 1793 \begin{memberdesc}[FileWriter]{closed} 1794 this member is \True if the file is closed. 1795 \end{memberdesc} 1796 \begin{memberdesc}[FileWriter]{mode} 1797 holds the access mode. 1798 \end{memberdesc} 1799 \begin{memberdesc}[FileWriter]{name} 1800 holds the file name. 1801 \end{memberdesc} 1802 \begin{memberdesc}[FileWriter]{newlines} 1803 holds the line separator. 1804 \end{memberdesc} 1805 1806 \begin{funcdesc}{setEscriptParamInt}{name,value} 1807 assigns the integer value \var{value} to the parameter \var{name}. 1808 If \var{name}="TOO_MANY_LINES" conversion of any \Data object to a string 1809 switches to a condensed format if more than \var{value} lines would be created. 1810 \end{funcdesc} 1811 1812 \begin{funcdesc}{getEscriptParamInt}{name} 1813 returns the current value of integer parameter \var{name}. 1814 \end{funcdesc} 1815 1816 \begin{funcdesc}{listEscriptParams}{a} 1817 returns a list of valid parameters and their description. 1818 \end{funcdesc} 1819 1820 \begin{funcdesc}{getMPISizeWorld}{} 1821 returns the number of \MPI processors in use in the \env{MPI_COMM_WORLD} processor group. 1822 If \MPI is not used 1 is returned. 1823 \end{funcdesc} 1824 1825 \begin{funcdesc}{getMPIRankWorld}{} 1826 returns the rank of the current process within the \env{MPI_COMM_WORLD} 1827 processor group. If \MPI is not used 0 is returned. 1828 \end{funcdesc} 1829 1830 \begin{funcdesc}{MPIBarrierWorld}{} 1831 performs a barrier synchronization across all processors within the 1832 \env{MPI_COMM_WORLD} processor group. 1833 \end{funcdesc} 1834 1835 \begin{funcdesc}{getMPIWorldMax}{a} 1836 returns the maximum value of the integer \var{a} across all processors within 1837 \env{MPI_COMM_WORLD}. 1838 \end{funcdesc} 1839

## Properties

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