ENH: Added UserGuide in AsciiDoc
[freefoam.git] / doc / UserGuide / cases / basic-file-format.txt
blob4b4756793f3e31c569faaf7fba64f00cfba97d44
1 === Basic input/output file format
2 ((({project},file format))) (((file format)))
4 {project} needs to read a range of data structures such as strings, scalars,
5 vectors, tensors, lists and fields. The input/output (I/O) format of files is
6 designed to be extremely flexible to enable the user to modify the I/O in
7 {project} applications as easily as possible. The I/O follows a simple set of
8 rules that make the files extremely easy to understand, in contrast to many
9 software packages whose file format may not only be difficult to understand
10 intuitively but also not be published anywhere. The description of the
11 {project} file format is described in the following sections.
13 ==== General syntax rules
15 The format follows the following some general principles of {cpp} source code.
17 - Files have free form, with no particular meaning assigned to any column and
18   no need to indicate continuation across lines.
19 - Lines have no particular meaning except to a `//`
20   (((`//`,{project} file syntax)))((({project} file syntax,`//`))) comment
21   delimiter which makes {project} ignore any text that follows it until the end
22   of line.
23 - A comment over multiple lines is done by enclosing the text between `/*` and
24   `*/`(((`/* ... */`,{project} file syntax)))
25   ((({project} file syntax,`/* ... */`))) delimiters.
27 ==== Dictionaries
29 {project} uses 'dictionaries' as the most common means of specifying data. A
30 dictionary is an entity that contains a set data entries that can be retrieved
31 by the I/O by means of 'keywords'. The keyword entries follow the general
32 format
34 -------------------------------------------------------------------------------
35 <keyword> <dataEntry1> ... <dataEntryN>;
36 -------------------------------------------------------------------------------
38 Most entries are single data entries of the form:
40 -------------------------------------------------------------------------------
41 <keyword> <dataEntry>;
42 -------------------------------------------------------------------------------
44 Most {project} data files are themselves dictionaries containing a set of
45 keyword entries. Dictionaries provide the means for organising entries into
46 logical categories and can be specified hierarchically so that any dictionary
47 can itself contain one or more dictionary entries. The format for a dictionary
48 is to specify the dictionary name followed the the entries enclosed in curly
49 braces \{\} as follows
51 -------------------------------------------------------------------------------
52 <dictionaryName>
54     ... keyword entries ...
56 -------------------------------------------------------------------------------
58 ==== The data file header
60 All data files that are read and written by {project} begin with a dictionary
61 named `FoamFile`(((`FoamFile` keyword)))(((keyword,`FoamFile`))) containing a
62 standard set of keyword entries, listed in <<tab_dataFileHeaderKeywords>>.
64 [[tab_dataFileHeaderKeywords]]
65 .Header keywords entries for data files
66 [grid="none",frame="topbot",options="header"]
67 |==============================================================================
68 | Keyword | Description | Entry
69 | `version`(((`version` keyword)))(((keyword,`version`))) | I/O format version
70 | `2.0`
71 | `format`(((`format` keyword)))(((keyword,`format`))) | Data format |
72 ++ascii++/++binary++
73 | `location`(((`location` keyword)))(((keyword,`location`))) | Path to the
74 file, in `"..."` | (optional)
75 | `class`(((`class` keyword)))(((keyword,`class`))) | {project} class
76 constructed from the data file concerned | typically `dictionary` or a field,
77 'e.g.' `volVectorField`
78 | `object`(((`object` keyword)))(((keyword,`object`))) | Filename | 'e.g.'
79 `controlDict`
80 |==============================================================================
82 The table provides brief descriptions of each entry, which is probably
83 sufficient for most entries with the notable exception of `class`. The `class`
84 entry is the name of the {cpp} class in the {project} library that will be
85 constructed from the data in the file. Without knowledge of the underlying code
86 which calls the file to be read, and knowledge of the {project} classes, the
87 user will probably be unable to surmise the `class` entry correctly. However,
88 most data files with simple keyword entries are read into an internal
89 `dictionary` class and therefore the `class` entry is `dictionary` in those
90 cases.
92 The following example shows the use of keywords to provide data for a case
93 using the types of entry described so far. The extract, from an
94 filename:fvSolution[] dictionary file, contains 2 dictionaries, `solvers` and
95 `PISO`. The `solvers` dictionary contains multiple data entries for solver and
96 tolerances for each of the pressure and velocity equations, represented by the
97 `p` and `U` keywords respectively; the `PISO` dictionary contains algorithm
98 controls.
100 -------------------------------------------------------------------------------
101 solvers
103     p
104     {
105         solver          PCG;
106         preconditioner  DIC;
107         tolerance       1e-06;
108         relTol          0;
109     }
111     U
112     {
113         solver          PBiCG;
114         preconditioner  DILU;
115         tolerance       1e-05;
116         relTol          0;
117     }
120 PISO
122     nCorrectors              2;
123     nNonOrthogonalCorrectors 0;
124     pRefCell                 0;
125     pRefValue                0;
127 -------------------------------------------------------------------------------
129 ==== Lists
131 {project} applications contain lists, 'e.g.' a list of vertex coordinates for a
132 mesh description. Lists are commonly found in I/O and have a format of their
133 own in which the entries are contained within round braces `()`. There is
134 also a choice of format preceeding the round braces:
136 simple::
137     the keyword is followed immediately by round braces
139 -------------------------------------------------------------------------------
140 <listName>
142     ... entries ...
144 -------------------------------------------------------------------------------
146 numbered::
147     the keyword is followed by the number of elements `<n>` in the list
149 -------------------------------------------------------------------------------
150 <listName>
153     ... entries ...
155 -------------------------------------------------------------------------------
157 token identifier::
158     the keyword is followed by a class name identifier `Label<Type>` where
159     `<Type>` states what the list contains, 'e.g.' for a list of `scalar`
160     elements is
162 -------------------------------------------------------------------------------
163 <listName>
164 List<scalar>
165 <n>        // optional
167     ... entries ...
169 -------------------------------------------------------------------------------
171 Note that `<scalar>` in `List<scalar>` is not a generic name but the actual
172 text that should be entered.
174 The simple format is a convenient way of writing a list. The other formats
175 allow the code to read the data faster since the size of the list can be
176 allocated to memory in advance of reading the data. The simple format is
177 therefore preferred for short lists, where read time is minimal, and the other
178 formats are preferred for long lists.
180 [[sec_formatScalarsVectorsTensors]]
181 ==== Scalars, vectors and tensors
183 A scalar is a single number represented as such in a data file. A
184 `vector`(((`vector` class)))(((class,`vector`))) is a `VectorSpace` of rank 1
185 and dimension 3, and since the number of elements is always fixed to 3, the
186 simple List format is used. Therefore a vector math:[(1.0,1.1,1.2)] is
187 written:
189 -------------------------------------------------------------------------------
190 (1.0 1.1 1.2)
191 -------------------------------------------------------------------------------
193 In {project}, a tensor is a `VectorSpace` of rank 2 and dimension 3 and
194 therefore the data entries are always fixed to 9 real numbers. Therefore the
195 identity tensor can be written:
197 -------------------------------------------------------------------------------
199     1 0 0
200     0 1 0
201     0 0 1
203 -------------------------------------------------------------------------------
205 This example demonstrates the way in which {project} ignores the line return is
206 so that the entry can be written over multiple lines. It is treated no
207 differently to listing the numbers on a single line:
209 -------------------------------------------------------------------------------
210 (1 0 0 0 1 0 0 0 1)
211 -------------------------------------------------------------------------------
213 [[sec_dimensionalUnits]]
214 ==== Dimensional units
215 (((units,of measurement))) (((dimensional units)))
217 In continuum mechanics, properties are represented in some chosen units, 'e.g.'
218 mass in kilograms (math:[\unit{kg}]), volume in cubic metres
219 (math:[\unit{m^3}]), pressure in Pascals (math:[\unitfrac{kg}{m s^2}]).
220 Algebraic operations must be performed on these properties using consistent
221 units of measurement; in particular, addition, subtraction and equality are
222 only physically meaningful for properties of the same dimensional units. As a
223 safeguard against implementing a meaningless operation, {project} attaches
224 dimensions to field data and physical properties and performs dimension
225 checking(((dimension,checking in {project}))) on any tensor operation.
227 The I/O format for a `dimensionSet` is 7 scalars delimited by square brackets,
228 'e.g.'
230 -------------------------------------------------------------------------------
231 [0 2 -1 0 0 0 0]
232 -------------------------------------------------------------------------------
234 [[tab_unitsOfMeasurment]]
235 .Base units for SI and USCS
236 [grid="none",frame="topbot",options="header"]
237 |==============================================================================
238 | No. | Property | SI unit | USCS unit
239 | 1 | Mass | kilogram (math:[\unit{kg}]) | pound-mass (math:[\unit{lbm}])
240 | 2 | Length | metre (math:[\unit{m}]) | foot (math:[\unit{ft}])
241 | 3 | Time 2+^|  second (math:[\unit{s}])
242 | 4 | Temperature | Kelvin (math:[\unit{K}]) | degree Rankine
243 (math:[\unit{^\circ R}])
244 | 5 | Quantity | kilogram-mole (math:[\unit{kgmol}]) | pound-mole
245 (math:[\unit{lbmol}])
246 | 6 | Current 2+^| ampere (math:[\unit{A}])
247 | 7 | Luminous intensity 2+^| candela (math:[\unit{cd}])
248 |==============================================================================
250 where each of the values corresponds to the power of each of the base
251 units(((units,base))) of measurement listed in <<tab_unitsOfMeasurment>>.
252 The table gives the base units for the Syst&egrave;me International
253 (SI)(((units,SI)))(((SI units)))(((units,Syst&egrave;me International))) and
254 the United States Customary System (USCS) (((units,USCS)))(((USCS
255 units)))(((units,United States Customary System))) but {project} can be used
256 with any system of units. All that is required is that the 'input data is
257 correct for the chosen set of units'. It is particularly important to
258 recognise that {project} requires some dimensioned physical constants, 'e.g.'
259 the Universal Gas Constant math:[R], for certain calculations, 'e.g.'
260 thermophysical modelling. These dimensioned constants are specified in a
261 filename:DimensionedConstant[] sub-dictionary of main
262 filename:<prefix>etc/{project}/controlDict[] file of the {project}
263 installation. By default these constants are set in SI units. Those wishing to
264 use the USCS or any other system of units should modify these constants to
265 their chosen set of units accordingly.
267 ==== Dimensioned types
269 Physical properties are typically specified with their associated dimensions.
270 These entries have the format that the following example of a
271 `dimensionedScalar` demonstrates:
273 -------------------------------------------------------------------------------
274 nu nu [0 2 -1 0 0 0 0] 1;
275 -------------------------------------------------------------------------------
277 The first `nu` is the keyword; the second `nu` is the word name stored in class
278 `word`, usually chosen to be the same as the keyword; the next entry is the
279 `dimensionSet` and the final entry is the `scalar` value.
281 [[sec_fieldData]]
282 ==== Fields
284 Much of the I/O data in {project} are tensor fields, 'e.g.' velocity, pressure
285 data, that are read from and written into the time directories. {project}
286 writes field data using keyword entries as described in
287 <<tab_fieldDictKeywords>>.
289 [[tab_fieldDictKeywords]]
290 .Main keywords used in field dictionaries
291 [grid="none",frame="topbot",options="header"]
292 |==============================================================================
293 | Keyword | Description | Example
294 | `dimensions`(((`dimensions` keyword)))(((keyword,`dimensions`))) | Dimensions
295 of field | `[1 1 -2 0 0 0 0]`
296 | `internalField`(((`internalField` keyword)))(((keyword,`internalField`))) |
297 Value of internal field | `uniform (1 0 0)`
298 | `boundaryField`(((`boundaryField` keyword)))(((keyword,`boundaryField`))) |
299 Boundary field | see file listing in <<sec_fieldData>>
300 |==============================================================================
302 The data begins with an entry for its `dimensions`. Following that, is the
303 `internalField`, described in one of the following ways.
305 *Uniform field*::
306   a single value is assigned to all elements within the field, taking the
307   form:
309 -------------------------------------------------------------------------------
310 internalField uniform <entry>;
311 -------------------------------------------------------------------------------
313 *Nonuniform field*::
314   each field element is assigned a unique value from a list, taking the
315   following form where the token identifier form of list is recommended:
317 -------------------------------------------------------------------------------
318 internalField nonuniform <List>;
319 -------------------------------------------------------------------------------
321 The `boundaryField` is a dictionary containing a set of entries whose names
322 correspond to each of the names of the boundary patches listed in the
323 filename:boundary[] file in the dirname:polyMesh[] directory. Each patch entry
324 is itself a dictionary containing a list of keyword entries. The compulsory
325 entry, `type`, describes the patch field condition specified for the field. The
326 remaining entries correspond to the type of patch field condition selected and
327 can typically include field data specifying initial conditions on patch faces.
328 A selection of patch field conditions available in {project} are listed in
329 <<tab_primitivePatchTypes>> and <<tab_derivedPatchTypes>> with a description
330 and the data that must be specified with it. Example field dictionary entries
331 for velocity `U` are shown below:
333 -------------------------------------------------------------------------------
334 dimensions      [0 1 -1 0 0 0 0];
336 internalField   uniform (0 0 0);
338 boundaryField
340     movingWall
341     {
342         type          fixedValue;
343         value         uniform (1 0 0);
344     }
346     fixedWalls
347     {
348         type          fixedValue;
349         value         uniform (0 0 0);
350     }
352     frontAndBack
353     {
354         type          empty;
355     }
357 -------------------------------------------------------------------------------
359 ==== Directives and macro substitutions
361 There is additional file syntax that offers great flexibility for the setting
362 up of {project} case files, namely directives and macro substitutions.
363 Directives are commands that can be contained within case files that begin with
364 the hash (`#`) symbol. Macro substitutions begin with the dollar (`$`) symbol.
366 At present there are 2 directive commands available in {project}:
368 `#include "<fileName>"`::
369   reads the file of name filename:<fileName>[];
370 `#inputMode`::
371   has two options: `merge`, which merges keyword entries in successive
372   dictionaries, so that a keyword entry specified in one place will be
373   overridden by a later specification of the same keyword entry; `overwrite`,
374   which overwrites the contents of an entire dictionary; generally, use
375   `merge`.
377 For example, let us say a user wishes to set an initial value of pressure once
378 to be used as the internal field and initial value at a boundary. We could
379 create a file, 'e.g.' named filename:initialConditions[], which contains the
380 following entries:
382 -------------------------------------------------------------------------------
383 pressure 1e+05;
384 #inputMode merge
385 -------------------------------------------------------------------------------
387 In order to use this pressure for both the internal and initial boundary
388 fields, the user would simply include the following macro substitutions in the
389 pressure field file filename:0/p[]:
391 -------------------------------------------------------------------------------
392 #include "initialConditions"
393 internalField uniform $pressure;
394 boundaryField
396     patch1
397     {
398         type fixedValue;
399         value $internalField;
400     }
402 -------------------------------------------------------------------------------
404 This is a fairly trivial example that simply demonstrates how this
405 functionality works. However, the functionality can be used in many, more
406 powerful ways particularly as a means of generalising case data to suit the
407 user's needs. For example, if a user has a set of cases that require the same
408 RAS turbulence model settings, a single file can be created with those settings
409 which is simply included in the filename:constantRASProperties[] file of each
410 case. Macro substitutions can extend well beyond a singe value so that, for
411 example, sets of boundary conditions can be predefined and called by a single
412 macro. The extent to which such functionality can be used is almost endless.