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

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


 1 2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 3 % 4 % Copyright (c) 2003-2010 by University of Queensland 5 % Earth Systems Science Computational Center (ESSCC) 6 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\hackscore {ij}=\lambda u\hackscore {k,k} \delta\hackscore {ij} + \mu ( u\hackscore {i,j} + u\hackscore {j,i}) 191 \end{eqnarray} 192 where $\delta\hackscore {ij}$ is the Kronecker symbol and 193 $\lambda$ and $\mu$ are the Lame coefficients. The following function 194 takes the displacement \var{u} and the Lame coefficients \var{lam} and \var{mu} 195 as arguments and returns the corresponding stress: 196 \begin{python} 197 from esys.escript import * 198 def getStress(u, lam, mu): 199 d=u.getDomain().getDim() 200 g=grad(u) 201 stress=lam*trace(g)*kronecker(d)+mu*(g+transpose(g)) 202 return stress 203 \end{python} 204 The variable \var{d} gives the spatial dimension of the domain on which the 205 displacements are defined. 206 \var{kronecker} returns the Kronecker symbol with indexes $i$ and $j$ running 207 from 0 to \var{d}-1. 208 The call \var{grad(u)} requires the displacement field \var{u} to be in 209 the \var{Solution} or \ContinuousFunction. 210 The result \var{g} as well as the returned stress will be in the \Function. 211 If, for example, \var{u} is the solution of a PDE then \code{getStress} might 212 be called in the following way: 213 \begin{python} 214 s=getStress(u, 1., 2.) 215 \end{python} 216 However \code{getStress} can also be called with \Data objects as values for 217 \var{lam} and \var{mu} which, for instance in the case of a temperature 218 dependency, are calculated by an expression. 219 The following call is equivalent to the previous example: 220 \begin{python} 221 lam=Scalar(1., ContinuousFunction(mydomain)) 222 mu=Scalar(2., Function(mydomain)) 223 s=getStress(u, lam, mu) 224 \end{python} 225 226 The function \var{lam} belongs to the \ContinuousFunction but with \var{g} the 227 function \var{trace(g)} is in the \Function. 228 In the evaluation of the product \var{lam*trace(g)} we have different function 229 spaces (on the nodes versus in the centers) and at first glance we have incompatible data. 230 \escript converts the arguments into an appropriate function space according 231 to \fig{ESCRIPT DEP}. 232 In this example that means \escript sees \var{lam} as a function of the \Function. 233 In the context of FEM this means the nodal values of \var{lam} are 234 interpolated to the element centers. 235 The interpolation is automatic and requires no special handling. 236 237 \begin{figure} 238 \centering 239 \includegraphics{EscriptDiagram2} 240 \caption{\label{Figure: tag}Element Tagging. A rectangular mesh over a region 241 with two rock types {\it white} and {\it gray} is shown. 242 The number in each cell refers to the major rock type present in the cell 243 ($1$ for {\it white} and $2$ for {\it gray}).} 244 \end{figure} 245 246 \subsection{Tagged, Expanded and Constant Data} 247 Material parameters such as the Lame coefficients are typically dependent on 248 rock types present in the area of interest. 249 A common technique to handle these kinds of material parameters is 250 \emph{tagging}\index{tagging}, which uses storage efficiently. 251 \fig{Figure: tag} shows an example. In this case two rock types {\it white} 252 and {\it gray} can be found in the domain. 253 The domain is subdivided into triangular shaped cells. 254 Each cell has a tag indicating the rock type predominantly found in this cell. 255 Here $1$ is used to indicate rock type {\it white} and $2$ for rock type {\it gray}. 256 The tags are assigned at the time when the cells are generated and stored in 257 the \Domain class object. To allow easier usage of tags, names can be used 258 instead of numbers. These names are typically defined at the time when the 259 geometry is generated. 260 261 The following statements show how to use tagged values for \var{lam} as shown 262 in \fig{Figure: tag} for the stress calculation discussed above: 263 \begin{python} 264 lam=Scalar(value=2., what=Function(mydomain)) 265 insertTaggedValue(lam, white=30., gray=5000.) 266 s=getStress(u, lam, 2.) 267 \end{python} 268 In this example \var{lam} is set to $30$ for those cells with tag {\it white} 269 (=$1$) and to $5000$ for cells with tag {\it gray} (=$2$). 270 The initial value $2$ of \var{lam} is used as a default value for the case 271 when a tag is encountered which has not been linked with a value. 272 The \code{getStress} method does not need to be changed now that we are using tags. 273 \escript resolves the tags when \var{lam*trace(g)} is calculated. 274 275 This brings us to a very important point about \escript. 276 You can develop a simulation with constant Lame coefficients, and then later 277 switch to tagged Lame coefficients without otherwise changing your python script. 278 In short, you can use the same script for models with different domains and 279 different types of input data. 280 281 There are three main ways in which \Data objects are represented internally -- 282 constant, tagged, and expanded. 283 In the constant case, the same value is used at each sample point while only a 284 single value is stored to save memory. 285 In the expanded case, each sample point has an individual value (such as for the solution of a PDE). 286 This is where your largest data sets will be created because the values are 287 stored as a complete array. 288 The tagged case has already been discussed above. 289 290 Expanded data is created when you create a \Data object with \code{expanded=True}. 291 Tagged data sets are created when you use the \member{insertTaggedValue} 292 method as shown above. 293 294 Values are accessed through a sample reference number. 295 Operations on expanded \Data objects have to be performed for each sample 296 point individually. 297 When tagged values are used, the values are held in a dictionary. 298 Operations on tagged data require processing the set of tagged values only, 299 rather than processing the value for each individual sample point. 300 \escript allows any mixture of constant, tagged and expanded data in a single expression. 301 302 \subsection{Saving and Restoring Simulation Data} 303 \Data objects can be written to disk files with the \member{dump} method and 304 read back using the \member{load} method, both of which use the 305 \netCDF\cite{NETCDF} file format. 306 Use these to save data for checkpoint/restart or simply to save and reuse data 307 that was expensive to compute. 308 309 For instance, to save the coordinates of the data points of a 310 \ContinuousFunction to the file \file{x.nc} use 311 \begin{python} 312 x=ContinuousFunction(mydomain).getX() 313 x.dump("x.nc") 314 mydomain.dump("dom.nc") 315 \end{python} 316 To recover the object \var{x}, and \var{mydomain} was a \finley mesh use 317 \begin{python} 318 from esys.finley import LoadMesh 319 mydomain=LoadMesh("dom.nc") 320 x=load("x.nc", mydomain) 321 \end{python} 322 Obviously, it is possible to execute the same steps that were originally used 323 to generate \var{mydomain} to recreate it. However, in most cases using 324 \member{dump} and \member{load} is faster, particularly if optimization has 325 been applied. 326 If \escript is running on more than one \MPI process \member{dump} will create 327 an individual file for each process containing the local data. 328 In order to avoid conflicts the file names are extended by the \MPI processor 329 rank, that is instead of one file \file{dom.nc} you would get 330 \file{dom.nc.0000}, \file{dom.nc.0001}, etc. You still call 331 \code{LoadMesh('dom.nc')} to load the domain but you have to make sure that 332 the appropriate file is accessible from the corresponding rank, and loading 333 will only succeed if you run with as many processes as were used when calling 334 \member{dump}. 335 336 The function space of the \Data is stored in \file{x.nc}. 337 If the \Data object is expanded, the number of data points in the file and of 338 the \Domain for the particular \FunctionSpace must match. 339 Moreover, the ordering of the values is checked using the reference 340 identifiers provided by \FunctionSpace on the \Domain. 341 In some cases, data points will be reordered so be aware and confirm that you 342 get what you wanted. 343 344 A newer, more flexible way of saving and restoring \escript simulation data 345 is through a \class{DataManager} class object. 346 It has the advantage of allowing to save and load not only a \Domain and 347 \Data objects but also other values\footnote{The \PYTHON \emph{pickle} module 348 is used for other types.} you compute in your simulation script. 349 Further, \class{DataManager} objects can simultaneously create files for 350 visualization so no extra calls to, e.g. \code{saveVTK} are needed. 351 352 The following example shows how the \class{DataManager} class can be used. 353 For an explanation of all member functions and options see the relevant 354 reference section. 355 \begin{python} 356 from esys.escript import DataManager, Scalar, Function 357 from esys.finley import Rectangle 358 359 dm = DataManager(formats=[DataManager.RESTART, DataManager.VTK]) 360 if dm.hasData(): 361 mydomain=dm.getDomain() 362 val=dm.getValue("val") 363 t=dm.getValue("t") 364 t_max=dm.getValue("t_max") 365 else: 366 mydomain=Rectangle() 367 val=Function(mydomain).getX() 368 t=0. 369 t_max=2.5 370 371 while t$maxval the value maxval is used. 1263 1264 Now we produce our new \Data object. 1265 1266 \begin{python} 1267 result=x0.interpolateTable(sine_table, minval, step, toobig) 1268 \end{python} 1269 Any values which interpolate to larger than \var{toobig} will raise an exception. You can 1270 switch on boundary checking by adding ''check_boundaries=True the argument list. 1271 1272 1273 Now for a 2D example. 1274 We will interpolate a surface such that the bottom edge is the sine curve described above. 1275 The amplitude of the curve decreases as we move towards the top edge. 1276 1277 Our interpolation table will have three rows. 1278 \begin{python} 1279 st=numpy.array(sine_table) 1280 1281 table=[st, 0.5*st, 0*st ] 1282 \end{python} 1283 1284 The use of numpy and multiplication here is just to save typing. 1285 1286 \begin{python} 1287 result2=x1.interpolateTable(table, 0, 0.55, x0, minval, step, toobig) 1288 \end{python} 1289 1290 In the 2D case, the parameters for the x1 direction (min=0, step=0.55) come first followed by the x0 data object and 1291 its parameters. 1292 By default, if a point is specified which is outside the boundary, then \var{interpolateTable} will operate 1293 as if the point was on the boundary. 1294 Passing \var{check_boundaries}=\var{True} will \var{interpolateTable} to reject any points outside the boundaries. 1295 1296 \subsection{Saving Data as CSV} 1297 \index{saveDataCSV} 1298 \index{CSV} 1299 For simple post-processing, \Data objects can be saved in comma separated value format. 1300 1301 If \var{mydata1} and \var{mydata2} are scalar data, the following command: 1302 \begin{python} 1303 saveDataCSV('output.csv',U=mydata1, V=mydata2) 1304 \end{python} 1305 will record the values of mydata in \texttt{output.csv} in the following format: 1306 \begin{verbatim} 1307 U, V 1308 1.0000000e+0, 2.0000000e-1 1309 5.0000000e-0, 1.0000000e+1 1310 ... 1311 \end{verbatim} 1312 1313 The names of the keyword parameters form the names of columns in the output. 1314 If the data objects are over different function spaces, then saveDataCSV will attempt to 1315 interpolate to a common function space. 1316 If this is not possible, then an exception will be raised. 1317 1318 Output can be restricted using a scalar mask. 1319 \begin{python} 1320 saveDataCSV('outfile.csv', U=mydata1, V=mydata2, mask=myscalar) 1321 \end{python} 1322 Will only output those rows which correspond to to positive values of \var{myscalar}. 1323 Some aspects of the output can be tuned using additional parameters. 1324 \begin{python} 1325 saveDataCSV('data.csv', append=True, sep=' ', csep='/', mask=mymask, e=mat1) 1326 \end{python} 1327 1328 \begin{itemize} 1329 \item \var{append} - specifies that the output should be written to the end of an existing file. 1330 \item \var{sep} - defines the separator between fields. 1331 \item \var{csep} - defines the separator between components in the header line. For example between the components of a matrix. 1332 \end{itemize} 1333 1334 The above command would produce output like this: 1335 \begin{verbatim} 1336 e/0/0 e/1/0 e/0/1 e/1/1 1337 1.0000000000e+00 2.0000000000e+00 3.0000000000e+00 4.0000000000e+00 1338 ... 1339 \end{verbatim} 1340 1341 Note that while the order in which rows are output can vary, all the elements in a given row 1342 always correspond to the same input. 1343 1344 1345 \subsection{\Operator Class} 1346 The \Operator class provides an abstract access to operators build 1347 within the \LinearPDE class. \Operator objects are created 1348 when a PDE is handed over to a PDE solver library and handled 1349 by the \LinearPDE object defining the PDE. The user can gain access 1350 to the \Operator of a \LinearPDE object through the \var{getOperator} 1351 method. 1352 1353 \begin{classdesc}{Operator}{} 1354 creates an empty \Operator object. 1355 \end{classdesc} 1356 1357 \begin{methoddesc}[Operator]{isEmpty}{fileName} 1358 returns \True is the object is empty. Otherwise \True is returned. 1359 \end{methoddesc} 1360 1361 \begin{methoddesc}[Operator]{setValue}{value} 1362 resets all entries in the object representation to \var{value} 1363 \end{methoddesc} 1364 1365 \begin{methoddesc}[Operator]{solves}{rhs} 1366 solves the operator equation with right hand side \var{rhs} 1367 \end{methoddesc} 1368 1369 \begin{methoddesc}[Operator]{of}{u} 1370 applies the operator to the \Data object \var{u} 1371 \end{methoddesc} 1372 1373 \begin{methoddesc}[Operator]{saveMM}{fileName} 1374 saves the object to a matrix market format file of name 1375 \var{fileName}, see 1376 \url{http://maths.nist.gov/MatrixMarket} 1377 % \ulink{maths.nist.gov/MatrixMarket}{\url{http://maths.nist.gov/MatrixMarket}}. 1378 \index{Matrix Market} 1379 \end{methoddesc} 1380 1381 \section{Physical Units} 1382 \escript provides support for physical units in the SI system \index{SI units} including unit conversion. So the 1383 user can define variables in the form 1384 \begin{python} 1385 from esys.escript.unitsSI import * 1386 l=20*m 1387 w=30*kg 1388 w2=40*lb 1389 T=100*Celsius 1390 \end{python} 1391 In the two latter cases an conversion from pounds\index{pounds} and degree Celsius\index{Celsius} is performed into the appropriate SI units kg and Kelvin is performed. In addition 1392 composed units can be used, for instance 1393 \begin{python} 1394 from esys.escript.unitsSI import * 1395 rho=40*lb/cm**3 1396 \end{python} 1397 to define the density in the units of pounds per cubic centimeter. The value$40$will be converted 1398 into SI units, in this case kg per cubic meter. 1399 Moreover unit prefixes are supported: 1400 \begin{python} 1401 from esys.escript.unitsSI import * 1402 p=40*Mega*Pa 1403 \end{python} 1404 to the the pressure to 40 Mega Pascal. Units can also be converted back from the SI system into 1405 a desired unit, e.g 1406 \begin{python} 1407 from esys.escript.unitsSI import * 1408 print p/atm 1409 \end{python} 1410 can be used print the pressure in units of atmosphere\index{atmosphere}. 1411 1412 This is an incomplete list of supported physical units: 1413 1414 \begin{datadesc}{km} 1415 unit of kilo meter 1416 \end{datadesc} 1417 1418 \begin{datadesc}{m} 1419 unit of meter 1420 \end{datadesc} 1421 1422 \begin{datadesc}{cm} 1423 unit of centi meter 1424 \end{datadesc} 1425 1426 \begin{datadesc}{mm} 1427 unit of milli meter 1428 \end{datadesc} 1429 1430 \begin{datadesc}{sec} 1431 unit of second 1432 \end{datadesc} 1433 1434 \begin{datadesc}{minute} 1435 unit of minute 1436 \end{datadesc} 1437 1438 \begin{datadesc}{h} 1439 unit of hour 1440 \end{datadesc} 1441 \begin{datadesc}{day} 1442 unit of day 1443 \end{datadesc} 1444 \begin{datadesc}{yr} 1445 unit of year 1446 \end{datadesc} 1447 1448 \begin{datadesc}{gram} 1449 unit of gram 1450 \end{datadesc} 1451 \begin{datadesc}{kg} 1452 unit of kilo gram 1453 \end{datadesc} 1454 \begin{datadesc}{lb} 1455 unit of pound 1456 \end{datadesc} 1457 \begin{datadesc}{ton} 1458 metric ton 1459 \end{datadesc} 1460 1461 \begin{datadesc}{A} 1462 unit of Ampere 1463 \end{datadesc} 1464 1465 \begin{datadesc}{Hz} 1466 unit of Hertz 1467 \end{datadesc} 1468 1469 \begin{datadesc}{N} 1470 unit of Newton 1471 \end{datadesc} 1472 \begin{datadesc}{Pa} 1473 unit of Pascal 1474 \end{datadesc} 1475 \begin{datadesc}{atm} 1476 unit of atmosphere 1477 \end{datadesc} 1478 \begin{datadesc}{J} 1479 unit of Joule 1480 \end{datadesc} 1481 1482 \begin{datadesc}{W} 1483 unit of Watt 1484 \end{datadesc} 1485 1486 \begin{datadesc}{C} 1487 unit of Coulomb 1488 \end{datadesc} 1489 \begin{datadesc}{V} 1490 unit of Volt 1491 \end{datadesc} 1492 \begin{datadesc}{F} 1493 unit of Farad 1494 \end{datadesc} 1495 1496 \begin{datadesc}{Ohm} 1497 unit of Ohm 1498 \end{datadesc} 1499 \begin{datadesc}{K} 1500 unit of Kelvin 1501 \end{datadesc} 1502 \begin{datadesc}{Celsius} 1503 unit of Celsius 1504 \end{datadesc} 1505 1506 \begin{datadesc}{Fahrenheit} 1507 unit of Fahrenheit 1508 \end{datadesc} 1509 1510 Moreover unit prefixes are supported: 1511 1512 \begin{datadesc}{Yotta} 1513 prefix yotta =$10^{24}$. 1514 1515 \end{datadesc} 1516 1517 \begin{datadesc}{Zetta} 1518 prefix zetta=$10^{21}$. 1519 \end{datadesc} 1520 1521 \begin{datadesc}{Exa} 1522 prefix exa=$10^{18}$. 1523 \end{datadesc} 1524 1525 \begin{datadesc}{Peta} 1526 prefix peta=$10^{15}$. 1527 \end{datadesc} 1528 1529 \begin{datadesc}{Tera} 1530 prefix tera=$10^{12}$. 1531 \end{datadesc} 1532 1533 \begin{datadesc}{Giga} 1534 prefix giga=$10^9$. 1535 \end{datadesc} 1536 1537 \begin{datadesc}{Mega} 1538 prefix mega=$10^6$. 1539 \end{datadesc} 1540 1541 \begin{datadesc}{Kilo} 1542 prefix kilo=$10^3$. 1543 \end{datadesc} 1544 1545 \begin{datadesc}{Hecto} 1546 prefix hecto=$10^2$. 1547 \end{datadesc} 1548 1549 \begin{datadesc}{Deca} 1550 prefix deca=$10^1$. 1551 \end{datadesc} 1552 1553 \begin{datadesc}{Deci} 1554 prefix deci=$10^{-1}$. 1555 \end{datadesc} 1556 1557 \begin{datadesc}{Centi} 1558 prefix centi=$10^{-2}$. 1559 \end{datadesc} 1560 1561 \begin{datadesc}{Milli} 1562 prefix milli=$10^{-3}$. 1563 \end{datadesc} 1564 1565 \begin{datadesc}{Micro} 1566 prefix micro=$10^{-6}$. 1567 \end{datadesc} 1568 1569 \begin{datadesc}{Nano} 1570 prefix nano=$10^{-9}$. 1571 \end{datadesc} 1572 1573 \begin{datadesc}{Pico} 1574 prefix pico=$10^{-12}$. 1575 \end{datadesc} 1576 1577 \begin{datadesc}{Femto} 1578 prefix femto=$10^{-15}$. 1579 \end{datadesc} 1580 1581 \begin{datadesc}{Atto} 1582 prefix atto=$10^{-18}$. 1583 \end{datadesc} 1584 1585 \begin{datadesc}{Zepto} 1586 prefix zepto=$10^{-21}$. 1587 \end{datadesc} 1588 1589 \begin{datadesc}{Yocto} 1590 prefix yocto=$10^{-24}\$. 1591 \end{datadesc} 1592 1593 1594 \section{Utilities} 1595 1596 The \class{FileWriter} provides a mechanism to write data to a file. 1597 In essence, this class wraps the standard \class{file} class to write data 1598 that are global in MPI to a file. In fact, data are written on the processor 1599 with \MPI rank 0 only. It is recommended to use \class{FileWriter} 1600 rather than \class{open} in order to write code that is running 1601 with and without \MPI. It is save to use \class{open} under MPI to read data which are global under \MPI. 1602 1603 \begin{classdesc}{FileWriter}{fn\optional{,append=\False, \optional{createLocalFiles=\False}})} 1604 Opens a file of name \var{fn} for writing. If \var{append} is set to \True 1605 written data are append at the end of the file. 1606 If running under \MPI only the first processor with rank==0 1607 will open the file and write to it. 1608 If \var{createLocalFiles} is set each individual processor will create a file 1609 where for any processor with rank>0 the file name is extended by its rank. This option is normally used for debug purposes only. 1610 \end{classdesc} 1611 1612 The following methods are available: 1613 \begin{methoddesc}[FileWriter]{close}{} 1614 closes the file. 1615 \end{methoddesc} 1616 \begin{methoddesc}[FileWriter]{flush}{} 1617 flushes the internal buffer to disk. 1618 \end{methoddesc} 1619 \begin{methoddesc}[FileWriter]{write}{txt} 1620 Write string \var{txt} to file. 1621 Note that newline is not added. 1622 \end{methoddesc} 1623 \begin{methoddesc}[FileWriter]{writelines}{txts} 1624 Write the list \var{txts} of strings to the file.. 1625 Note that newlines are not added. 1626 This method is equivalent to call write() for each string. 1627 \end{methoddesc} 1628 \begin{memberdesc}[FileWriter]{closed} 1629 \True if file is closed. 1630 \end{memberdesc} 1631 \begin{memberdesc}[FileWriter]{mode} 1632 access mode. 1633 \end{memberdesc} 1634 \begin{memberdesc}[FileWriter]{name} 1635 file name. 1636 \end{memberdesc} 1637 \begin{memberdesc}[FileWriter]{newlines} 1638 line separator 1639 \end{memberdesc} 1640 1641 1642 \begin{funcdesc}{setEscriptParamInt}{name,value} 1643 assigns the integer value \var{value} to the parameter \var{name}. 1644 If \var{name}="TOO_MANY_LINES" conversion of any \Data object to a string switches to a 1645 condensed format if more than \var{value} lines would be created. 1646 \end{funcdesc} 1647 1648 \begin{funcdesc}{getEscriptParamInt}{name} 1649 returns the current value of integer parameter \var{name}. 1650 \end{funcdesc} 1651 1652 \begin{funcdesc}{listEscriptParams}{a} 1653 returns a list of valid parameters and their description. 1654 \end{funcdesc} 1655 1656 \begin{funcdesc}{getMPISizeWorld}{} 1657 returns the number of \MPI processors in use in the \env{MPI_COMM_WORLD} processor group. 1658 If \MPI is not used 1 is returned. 1659 \end{funcdesc} 1660 \begin{funcdesc}{getMPIRankWorld}{} 1661 returns the rank of the process within the \env{MPI_COMM_WORLD} processor group. 1662 If \MPI is not used 0 is returned. 1663 \end{funcdesc} 1664 \begin{funcdesc}{MPIBarrierWorld}{} 1665 performs a barrier synchronization across all processors within \env{MPI_COMM_WORLD} 1666 processor group. 1667 \end{funcdesc} 1668 \begin{funcdesc}{getMPIWorldMax}{a} 1669 returns the maximum value of the integer \var{a} across all 1670 processors within \env{MPI_COMM_WORLD}. 1671 \end{funcdesc} 1672

## Properties

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