Debian Codegraph @

packages/seacas/libraries/ioss/doc/IOSystem.tex

raw
1 % This file was converted to LaTeX by Writer2LaTeX ver. 0.4
2 % see http://www.hj-gym.dk/~hj/writer2latex for more info
3 \documentclass[11pt,twoside]{article}
4 \usepackage{graphicx}
5 \usepackage[ascii]{inputenc}
6 \usepackage[T1]{fontenc}
7 \usepackage{amsmath,amssymb,amsfonts,textcomp}
8 \usepackage{color}
9 \usepackage{alltt}
10 \usepackage{calc}
11 \usepackage{hyperref}
12 \hypersetup{colorlinks=true, linkcolor=blue, filecolor=blue, pagecolor=blue, urlcolor=blue}
13
14 %% Define a new 'url' style for the url package that will use a smaller font.
15 \makeatletter
16 \def\url@urlstyle{%
17 \@ifundefined{selectfont}{\def\UrlFont{\sf}}{\def\UrlFont{\small\ttfamily}}}
18 \makeatother
19 %% Now actually use the newly defined style.
20 \urlstyle{urlstyle}
21
22 % Pages styles (master pages)
23 \setlength\parindent{0in}
24 \setlength{\parskip}{1ex plus 0.5ex minus 0.2ex}
25 \setlength\textwidth{6.5in}
26 \makeatletter
27 \newcommand\ps@Standard{%
28 \renewcommand\@oddhead{}%
29 \renewcommand\@evenhead{\@oddhead}%
30 \renewcommand\@oddfoot{}%
31 \renewcommand\@evenfoot{\@oddfoot}%
32 \setlength\paperwidth{8.5in}\setlength\paperheight{11in}\setlength\voffset{-1in}\setlength\hoffset{-1in}\setlength\topmargin{0.5in}\setlength\headheight{12pt}\setlength\headsep{0.461in}\setlength\footskip{12pt+0.461in}\setlength\textheight{11in-0.5in-0.5in-0.461in-12pt-0.461in-12pt}\setlength\oddsidemargin{1in}\setlength\textwidth{8.5in-1in-1in}
33 \renewcommand\thepage{\arabic{page}}
34 \setlength{\skip\footins}{0.0398in}\renewcommand\footnoterule{\vspace*{-0.0071in}\noindent{\rule{0.25\columnwidth}{0.0071in}}\vspace*{0.0398in}}
35 }
36 \makeatother
37 \pagestyle{Standard}
38 % footnotes configuration
39 \makeatletter
40 \renewcommand\thefootnote{\arabic{footnote}}
41 \makeatother
42
43 \newcommand{\cmd}[1]
44 {\mbox{\sf #1}\null}
45 \newcommand{\code}[1]
46 {\mbox{\bf\tt #1}\null}
47 \newcommand{\file}[1]
48 {\mbox{\bf\em #1}\null}
49 \newcommand{\param}[1]
50 {\mbox{\{\em #1\}}\null}
51 \newenvironment{source}
52 {\small\begin{quote}\begin{alltt}}
53 {\end{alltt}\end{quote}\normalsize}
54
55 \title{Sierra IO System}
56 \begin{document}
57 \clearpage\pagestyle{Standard}
58 \title{Sierra IO System}
59 \author{Gregory D. Sjaardema\\
60 Advanced Computational Mechanics Architectures\\
61 Sandia National Laboratories}
62
63 \maketitle
64
65 \setcounter{tocdepth}{3}
66 \setlength{\parskip}{0ex plus 0.5ex minus 0.2ex}
67 \tableofcontents
68
69 \section{Introduction}
70 The documentation below is a medium{}- to low{}-level view of the Sierra
71 IO system targeted at developers who will be adding or modifying the
72 database IO portion of the system. It should give enough detail that a
73 new database type could be added by reading this document and looking
74 at an existing database class. It is also helpful to have the
75 doxygen{}-generated documentation for the Ioss class hierarchy
76 available.
77
78 The IO Subsystem has been designed to support multiple database formats
79 simultaneously. It is possible to have the finite element model read
80 from an ExodusII database; two results files being written to an
81 ExodusII file with a third results file being written to a CGNS file;
82 and the restart file being written to yet another ExodusII file. Each of
83 these output databases can have a different schedule for when to write
84 and what data is to be written.
85
86 If there are any questions or corrections, please contact Greg Sjaardema
87 at \href{mailto:[email protected]}{\nolinkurl{[email protected]}}.
88
89 \setlength{\parskip}{1ex plus 0.5ex minus 0.2ex}
90 \section{Class Structure Overview}
91 The three main modules or namespaces involved in the IO are:
92 \begin{description}
93 \item [\code{Fmwk}] Main sierra framework namespace. This
94 defines and manages the Sierra applications data structures,
95 algorithms, mechanics, etc. Each \code{Fmwk::Region} owns a
96 \code{Frio::IOBroker} which is its link to all bulk data io.
97 \item [\code{Frio}] The bridge between the Sierra frameworks
98 data structures and the IO databases data structures in the Ioss
99 namespace. Ideally all data transfers between Sierra and the IO
100 databases is under the control of the \code{Frio} classes.
101 However, there are some special cases where an application will
102 directly interact with the Ioss classes. The
103 \code{Frio::IOBroker} manages the Restart, Mesh, Results, and
104 other databases used by a \code{Fmwk::Region.}
105 \item [\code{Ioss}] The \code{Ioss} namespace
106 contains several classes which attempt to provide an abstract interface
107 to multiple concrete database types. It also defines a lightweight
108 generic representation of the finite element model.
109 \end{description}
110
111 \subsection{The Ioss Module}
112 There are two major pieces of the \code{Ioss} module: The
113 \code{Ioss::DatabaseIO} which is a pure virtual base class
114 from which all concrete IO databases are derived and the
115 \code{Ioss::GroupingEntity} classes which define a
116 lightweight generic model representation.
117
118 The current inheritance structure of
119 \code{Ioss::DatabaseIO} is shown in Figure~\ref{fig:dbio_inherit}.
120 \begin{figure}[htp]
121 \centering
122 \includegraphics[scale=0.75]{DatabaseIO__inherit__graph.png}
123 \caption{\code{Ioss::DatabaseIO} Inheritance Diagram}\label{fig:dbio_inherit}
124 \end{figure}
125 Currently the concrete database types are ExodusII (\code{Ioex}), CGNS
126 (\code{Iocgns}), and Heartbeat (\code{Iohb}). The
127 \code{Ioss::DatabaseIO} class has a pointer to an \code{Ioss::Region
128 }which is the root of the generic model representation.
129
130 \subsubsection{Ioss::Region and Ioss::GroupingEntity Classes}
131 An \code{Ioss::Region} is an
132 \code{Ioss:GroupingEntity} and it contains a vector of
133 \code{NodeBlocks}, \code{ElementBlocks},
134 \code{SideSets}, and \code{CommSets} defining the current model. These are all
135 also \code{Ioss::GroupingEntities}. The
136 \code{Ioss::GroupingEntity} inheritance structure is shown in Figure~\ref{fig:ge_inherit}.
137 \begin{figure}[htp]
138 \centering
139 \includegraphics[scale=0.75]{GroupingEntity__inherit__graph.png}
140 \caption{\code{Ioss::GroupingEntity} Inheritance Diagram}\label{fig:ge_inherit}
141 \end{figure}
142 An \code{Ioss::GroupingEntity}
143 contains an \code{Ioss::PropertyManager} which maintains 1 or
144 more \code{Ioss::Property;} and an
145 \code{Ioss::FieldManager} which maintains 1 or
146 more\code{ Ioss::Field}. It also contains a name and a
147 pointer to the \code{Ioss::DatabaseIO}. There is also an
148 \code{Ioss::EntityBlock} which contains 1 extra member which
149 is the \code{Ioel::ElementTopology} which is the topology of
150 the entities contained in this block. The collaboration diagram for
151 the \code{Ioss::GroupingEntity} is shown in Figure~\ref{fig:ge_collab}
152 \begin{figure}[htp]
153 \centering
154 \includegraphics[scale=0.75]{GroupingEntity__coll__graph.png}
155 \caption{\code{Ioss::GroupingEntity} Collaboration Diagram}\label{fig:ge_collab}
156 \end{figure}
157
158 A \code{GroupingEntity} is a very lightweight class; it does
159 not contain any bulk data. It represents a portion of the finite
160 element model and can transfer bulk data to/from the database from/to
161 the Sierra datastructures. It also contains metadata about that portion
162 of the finite element model. Each specific
163 \code{GroupingEntity} type has a few required properties and
164 fields and some optional properties and fields.
165
166 The \code{Ioss::GroupingEntity}'s define the basic finite
167 element model. For example, a model with two element blocks, a nodeset,
168 and two sidesets is shown in Figure~\ref{fig:block}.
169 \begin{figure}[htp]
170 \centering
171 \includegraphics[scale=0.5]{Block_Diagram_Model.png}
172 \caption{Block Diagram of Finite Element Model Structure}\label{fig:block}
173 \end{figure}
174
175 Note that the \code{SideSets} are further divided into one or more
176 \code{SideBlocks} which contain entities of homogeneous topology.
177
178 Each of these \code{GroupingEntity's} contain both
179 \code{Properties} and \code{Field} definitions
180 which can be queried by the \code{Frio} classes to define the
181 model.
182
183 \subsubsection{Ioss::Property and Ioss::PropertyManager}
184 Each \code{Ioss::GroupingEntity} class contains an
185 \code{Ioss::PropertyManager} which manages the
186 \code{Ioss::Property} on this particular entity. An
187 \code{Ioss::Property} is basically a named integer, real,
188 string, or pointer value. The \code{PropertyManager}
189 maintains a list of all \code{Properties} for a specific
190 entity and provides an interface where the \code{Properties}
191 can be located by name.
192
193 \subsubsection{Ioss::Field and Ioss::FieldManager}
194 Each \code{Ioss::GroupingEntity} class contains an
195 \code{Ioss::FieldManager} which manages the
196 \code{Ioss::Field}s on this particular entity. An
197 \code{Ioss::Field} contains the metadata for the field it
198 describes; it does not hold the bulk data, so an
199 \code{Ioss::Field} is fairly lightweight. Each
200 \code{Ioss::Field} contains:
201
202 \begin{itemize}
203 \item {
204 std::string \code{name} -- The name of the field.}
205 \item {
206 Int \code{rawCount\_} -- The size of the untransformed
207 field }
208 \item {
209 Int \code{transCount\_} -- The size of the transformed
210 field.}
211 \item {
212 BasicType \code{type\_} -- The basic type of the field
213 (Integer, Real, String)}
214 \item {
215 const VariableType * \code{rawStorage\_} -- The storage
216 type of the untransformed field (Vector, Scalar, Tensor, ....)}
217 \item {
218 const VariableType * \code{transStorage\_} -- The storage
219 type of the transformed field (Vector, Scalar, Tensor, ...)}
220 \item {
221 RoleType \code{role\_} -- The ``role'' of the field. Valid
222 roles are: \code{INTERNAL}, \code{MESH}, \code{ATTRIBUTE},
223 \code{COMMUNICATION}, \code{INFORMATION},
224 \code{REDUCTION}, and \code{TRANSIENT}. The most
225 common are \code{MESH} for describing the model
226 geometry/topology, \code{ATTRIBUTE} for block entity attributes
227 (typically \code{ElementBlock} at this time), \code{TRANSIENT} for time{}-dependent
228 results data, and \code{REDUCTION} for ``summary fields''
229 (see below).}
230 \item {
231 Int \code{size\_} -- The number of bytes required to store
232 the entire \code{Field}. Equal to \code{rawCount\_
233 * sizeof(type\_) * (rawStorage\_ components)}. }
234 \item {
235 std::vector{\textless} Iotr::Transform * {\textgreater}
236 \code{ransforms\_} -- A list of transforms which are
237 applied to this field. \textit{Note that the transforms are implemented
238 at the Field level, but are not yet functional in Sierra
239 applications.}}
240 \end{itemize}
241 The \code{Ioss::Fields} are used for all bulk data input and
242 output. Each \code{Ioss::GroupingEntity }contains a
243 \code{get\_field\_data} and a
244 \code{put\_field\_data} function. The function signatures
245 are:
246 \begin{source}
247 int get\_field\_data(const std::string \&field\_name, void *data, size\_t data\_size=0)
248 int put\_field\_data(const std::string \&field\_name, void *data, size\_t data\_size=0)
249 \end{source}
250
251 The functions will get or put the data corresponding to the field
252 named \code{field\_name}; the data will be read from/written to the
253 memory pointed to by \code{data} which is of size \code{data\_size}.
254 If \code{data\_size} is nonzero, then the field checks that there is
255 sufficient space to store the field data; if it is zero, then it is
256 assumed to be large enough. The function returns the number of
257 entities for which the field was read/written.
258
259 The \code{get\_field\_data} and
260 \code{put\_field\_data} functions are actually at
261 the\code{ Ioss::GroupingEntity} level and they forward the
262 call down to \code{internal\_get\_field\_data} and
263 \code{internal\_put\_field\_data} which are defined on each
264 class derived from \code{Ioss::GroupingEntity.} These in turn
265 call\footnote{The \code{offset} and \code{count}
266 were originally intended to provide partial field input and output, but
267 this became too unwieldy and is not used at this time. Only full field
268 input or output is supported.}:
269 \begin{source}
270 int get\_database(){}-{\textgreater}get\_field(this, field, offset, count, data, data\_size);
271 \end{source}
272
273 get the concrete database class which is responsible for transferring
274 the bulk data to/from the database to/from the memory pointed to by
275 \code{data} of size \code{data\_size} bytes.
276
277 \paragraph{Ioss::Field -- Roles}
278 As defined above, there are six values for a fields
279 \code{role}. The three most commonly used are:
280
281 \begin{description}
282 \item [\code{MESH}] A field which is used to define the basic
283 geometry or topology of the model and is not normally transient in
284 nature. Examples would be element connectivity or nodal coordinates.
285 \item [\code{ATTRIBUTE}] A field which is used to define an attribute
286 on an \code{EntityBlock} derived class. Examples would be thickness
287 of the elements in a shell element block or the radius of particles in
288 a particle element block.
289 \item [\code{TRANSIENT}] A field which is typically calculated
290 at multiple steps or times in an analysis. These are typically
291 ``results'' data. Examples would be nodal displacement or element
292 stress.
293 \item [\code{REDUCTION}] A field which is typically summarizes
294 some transient data about an entity. The size of this field is
295 typically not proportionate to the number of entities in a
296 \code{GroupingEntity}. An example would be average
297 displacement over a group of nodes or the kinetic energy of a model.
298 This data is also transient.
299 \end{description}
300 \paragraph{Ioss::Field -- Storage}
301 The field storage members define the higher{}-order type of the variable
302 such as vector, tensor, etc. The storage class is represented by the
303 \code{Ioss::VariableType} base class which has several
304 derived classes. The four types of derived class are:
305
306 \begin{itemize}
307 \item {
308 \code{ConstructredVariableType} -- Specify a name and the
309 number of components. This is typically used for user{}-defined storage
310 types such as state variables. A specific variable may have 86
311 components, so the user would create composite variable type specifying
312 a name and 86 components. By default, the IO system will create the
313 type as \code{Real[component\_count]}, so the above type
314 would be known as ``\code{Real[86]}''.}
315 \item {
316 \code{CompositeVariableType }{--} A combination (or
317 ``composite'') of the other field storage classes. For example, a
318 field defined on the four integration points of a quadrilateral element
319 would be a composite of 4 tensors. Currently the composite can only
320 contain two subfields.}
321 \item {
322 \code{Ioel::ElementVariableType} -- Each element known to
323 the IO system will register a type which is sufficient for storing its
324 nodal connectivity. For example, a 20{}-node hex registers the type
325 \code{Ioel::St\_Hex20} which has the name ``hex20'' and
326 consists of 20 components.}
327 \item {
328 Predefined ``common'' types. This category encompasses many predefined
329 types such as:}
330 \begin{tabular}{rl}
331 Scalar: & \\
332 Vector: & 2D, 3D \\
333 Quaternion: & 2D, 3D \\
334 Full\_Tensor:& 36, 32, 22, 16, 12 \\
335 Sym\_Tensor: & 33, 31, 21, 13, 11, 10 \\
336 Asym\_Tensor:& 03, 02, 01 \\
337 \end{tabular}
338 \end{itemize}
339 Each variable type will return its component count. It also will return
340 an optional suffix for each component. For example, the
341 \code{Sym\_Tensor\_33} will return the suffices XX, YY, ZZ,
342 XY, YZ, ZX.
343
344 \subsubsection{Defined Properties and Fields}
345
346 All classes derived from \code{GroupingEntity} provide the property:
347 \begin{quote}
348 \begin{tabular}{ll}
349 \code{name} &(String) \\
350 \end{tabular}
351 \end{quote}
352
353 In addition, the \code{NodeSet} class provides the properties:
354 \begin{quote}
355 \begin{tabular}{ll}
356 \code{entity\_count} &(Integer) \\
357 \code{distribution\_factor\_count} &(Integer) \\
358 \end{tabular}
359 \end{quote}
360 And the fields:
361 \begin{quote}
362 \begin{tabular}{lll}
363 \code{ids} & (Integer) & scalar \\
364 \code{distribution\_factors} & (Real) & scalar \\
365 \end{tabular}
366 \end{quote}
367
368 The \code{SideSet} class provides the properties:
369 \begin{quote}
370 \begin{tabular}{ll}
371 \code{block\_count} &(Integer) \\
372 \code{side\_block\_count} &(Integer) \\
373 \end{tabular}
374 \end{quote}
375 And no additional fields.
376
377 All classes derived from \code{EntityBlock} provide the properties:
378 \begin{quote}
379 \begin{tabular}{ll}
380 \code{name} &(String) \\
381 \code{entity\_count} &(Integer) \\
382 \code{topology\_node\_count} &(Integer) \\
383 \code{topology\_type} &(String) \\
384 \code{parent\_topology\_type}&(String) \\
385 \end{tabular}
386 \end{quote}
387 And the fields:
388 \begin{quote}
389 \begin{tabular}{lll}
390 \code{ids} & (Integer) & scalar \\
391 \code{connectivity} & (Integer) & topology\_node\_count \\
392 \end{tabular}
393 \end{quote}
394
395 The \code{NodeBlock} class provides the additional properties:
396 \begin{quote}
397 \begin{tabular}{ll}
398 \code{component\_degree} &(Integer) \\
399 \end{tabular}
400 \end{quote}
401 And the additional fields:
402 \begin{quote}
403 \begin{tabular}{lll}
404 \code{mesh\_model\_coordinates} & (Real) & component\_degree \\
405 \end{tabular}
406 \end{quote}
407
408 The \code{ElementBlock} class provides the additional properties:
409 \begin{quote}
410 \begin{tabular}{ll}
411 \code{attribute\_count} &(Integer) \\
412 \end{tabular}
413 \end{quote}
414 If \code{attribute\_count} is greater than zero, then there will be
415 additional fields defined for the attributes. These fields will all
416 have the role \code{Ioss::Field::ATTRIBUTE}. In addition to the
417 individual attribute fields, there will be a single Real field named
418 ``attribute'' which contains a field for each element in the element
419 block; the field will have \code{attribute\_count} components.
420
421 The \code{SideBlock} class provides the additional properties:
422 \begin{quote}
423 \begin{tabular}{ll}
424 \code{distribution\_factor\_count} &(Integer) \\
425 \end{tabular}
426 \end{quote}
427 And the field:
428 \begin{quote}
429 \begin{tabular}{lll}
430 \code{element\_side} &(Integer) & 2 (first component is element
431 global id, second is local element ordinal; 1-based \\
432 \end{tabular}
433 \end{quote}
434
435 An \code{Ioss::Region} is an \code{Ioss::GroupingEntity}. In addition
436 to the \code{name} property, it also provides properties that describe
437 the overall structure of the model:
438 \begin{quote}
439 \begin{tabular}{ll}
440 \code{entity\_count} &(Integer) \\
441 \code{node\_block\_count} &(Integer) \\
442 \code{node\_block\_count} &(Integer) \\
443 \code{element\_block\_count} &(Integer) \\
444 \code{side\_set\_count} &(Integer) \\
445 \code{node\_set\_count} &(Integer) \\
446 \code{comm\_set\_count} &(Integer) \\
447 \code{node\_count} &(Integer) \\
448 \code{element\_count} &(Integer) \\
449 \code{state\_count} &(Integer) \\
450 \code{current\_state} &(Integer) \\
451 \code{database\_name} &(String) \\
452 \end{tabular}
453 \end{quote}
454
455
456 \subsection{Ioss::DatabaseIO Class Hierarchy}
457 The\code{ Ioss::DatabaseIO} class is a virtual base class
458 which defines the interface required of each concrete database format.
459 In addition, it also provides some functionality which is common to all
460 (or many) database types.
461
462 \subsubsection{Attributes}
463 The \code{Ioss::DatabaseIO }class has the following
464 attributes:
465
466 \begin{description}
467 \item [\code{std::string DBFilename}] --The name of the file
468 this database is reading or writing.
469 \item [\code{Ioss::State dbState}] --An input database will
470 always be in \code{STATE\_READONLY} which signifies that it
471 cannot be written to or modified. An output database follows a set
472 order of access. The states corresponding to this access are:
473 \begin{center}
474 \begin{tabular}{rp{4in}}
475 \code{STATE\_INVALID}&Error state if something goes wrong.\\
476 \code{STATE\_UNKNOWN}&Typically used at the very
477 beginning of the databases existence when the class has been created,
478 but no reading or writing has occurred.\\
479 \code{STATE\_READONLY}&An input database is only in
480 either \code{STATE\_UNKNOWN} or in
481 \code{STATE\_READONLY} which means that it cannot be written
482 to or changed.\\
483 \code{STATE\_CLOSED}&The states are not nested, so each
484 state must end with a transition to the \code{STATE\_CLOSED}
485 prior to entering the next state.\\
486 \code{STATE\_DEFINE\_MODEL}&Defining the metadata which
487 defines the model (non{}-transient, geometry and topology).\\
488 \code{STATE\_MODEL}&Outputting the bulk data
489 (mesh\_model\_coordinates, ids, connectivity) relating to the model portion.\\
490 \code{STATE\_DEFINE\_TRANSIENT}&Defining the metadata
491 relating to the transient data. For example, the element or nodal
492 fields.\\
493 \code{STATE\_TRANSIENT}&Outputting the transient bulk data.\\
494 \end{tabular}
495 \end{center}
496 \item [\code{bool isParallel}]-- true if running in parallel
497 \item [\code{int myProcessor}]-- the processor this instance is
498 running on.
499 \item [\code{TopoContainer faceTopology}]-- There are times when
500 a Sierra application needs to know the topology of the faces in the
501 model. This container contains a list of the face topology types in the
502 model. It is populated by the concrete database types.
503 \item [\code{Ioel::ElementTopology *commonFaceTopology}]-- If
504 there is a single face topology in the model, this is set to that
505 value; otherwise it is \code{NULL}. This is used to speed up
506 some face topology queries.
507 \end{description}
508 \subsubsection{Interface}
509 Each concrete database class must derive from the
510 \code{Ioss::DatabaseIO} class and provide an implementation
511 of several functions. The most obvious of these is the constructor:
512 \begin{source}
513 DatabaseIO (Region *region, const std::string \&filename, Ioss::EventInterest db\_usage)
514 \end{source}
515
516 The constructor is passed a pointer to an \code{Ioss::Region},
517 a \code{filename}, and a `\code{db\_usage}' field.
518 The region can be \code{NULL} at this time if the database is
519 an input database. The \code{db\_usage} specifies what this
520 database will be used for and have valid values of
521 \code{WRITE\_RESTART}, \code{READ\_RESTART},
522 \code{WRITE\_RESULTS}, \code{READ\_MODEL},
523 \code{WRITE\_HISTORY}, or \code{WRITE\_HEARTBEAT}.
524 If this is an output database, then it should not be opened at this
525 time since the user may have specified the same file for the reading of
526 an initial state or a restart and we don't want to overwrite any data
527 that may be needed. If an input database, then it can be opened to
528 check that it exists, but no major processing of data should occur.
529
530 For an input database, data processing will occur in the
531 `\code{read\_meta\_data()}' function. When this is called,
532 the database will be in state \code{STATE\_DEFINE\_MODEL}. It
533 should then create all \code{GroupingEntities} and add them
534 to the \code{Region} to create the lightweight
535 \code{Ioss} model. Any properties should be added to the
536 \code{GroupingEntities} at this time also as should transient
537 fields. Basically, the \code{Ioss} system should have a
538 complete metadata representation of the model at this time and should
539 be able to respond to any queries about the model that do not involve
540 bulk data without accessing the database.
541
542 For an output database, the Sierra application through the
543 \code{Frio} classes will build the \code{Ioss}
544 metadata representation of the model while in
545 \code{STATE\_DEFINE\_MODEL}. When Ioss::DatabaseIO::end() is
546 called to exit from \code{STATE\_DEFINE\_MODEL}, then the
547 metadata model is complete and the database can write whatever
548 non{}-bulk data is needed at that point.
549
550 The Ioss system will next go into the \code{STATE\_MODEL} at
551 this point and the fields with a role of \code{MODEL} will be
552 written or read via the field interface.
553
554 As documented earlier, all bulk data reading and writing is done via
555 \code{Ioss::Field}s. The \code{Ioss::DatabaseIO}
556 class has several field input and output functions; one for each
557 \code{GroupingEntity} type:
558 \begin{source}
559 int get\_field (const Region *reg, const Field \&field, void *data, size\_t data\_size)
560 int get\_field (const NodeBlock *nb, const Field \&field, void *data, size\_t data\_size)
561 int get\_field (const ElementBlock *eb, const Field \&field, void *data, size\_t data\_size)
562 int get\_field (const SideBlock *sb, const Field \&field, void *data, size\_t data\_size)
563 int get\_field (const NodeSet *ns, const Field \&field, void *data, size\_t data\_size)
564 int get\_field (const SideSet *ss, const Field \&field, void *data, size\_t data\_size)
565 int get\_field (const CommSet *cs, const Field \&field, void *data, size\_t data\_size)
566
567 int put\_field (const Region *reg, const Field \&field, void *data, size\_t data\_size)
568 int put\_field (const NodeBlock *nb, const Field \&field, void *data, size\_t data\_size)
569 int put\_field (const ElementBlock *eb, const Field \&field, void *data, size\_t data\_size)
570 int put\_field (const SideBlock *sb, const Field \&field, void *data, size\_t data\_size)
571 int put\_field (const NodeSet *ns, const Field \&field, void *data, size\_t data\_size)
572 int put\_field (const SideSet *ss, const Field \&field, void *data, size\_t data\_size)
573 int put\_field (const CommSet *cs, const Field \&field, void *data, size\_t data\_size)
574 \end{source}
575 The implementation of these functions simply do some optional logging
576 and then call the private pure virtual function
577 \code{put\_field\_internal(...)} with the exact same
578 arguments that they were called with.\footnote{See
579 \url{http://www.gotw.ca/publications/mill18.htm} for a discussion of why
580 (pure) virtual functions should not appear in the public interface.
581 Note that this guideline is both respected and violated in
582 Ioss::DatabaseIO....} The underlying concrete database must either read
583 or write the specified field when the function is called. It is
584 recommended to treat the `\code{data}' field as readonly at
585 this time, so if any reordering or processing of the data is required,
586 a scratch array should be allocated to hold the modified
587 data\footnote{I am considering adding an argument to the field
588 functions which would indicate whether the `data' can be modified or
589 should be treated as readonly. This could help a little with memory
590 use, but most cases don't need to do any modifications of the
591 field....}. One of the first fields read/written from/to most
592 \code{GroupingEntities} is the ``ids'' field. This defines a
593 global id for each entity in the \code{GroupingEntity} and
594 also defines the ordering of all subsequent fields on that entity. For
595 example, if the id field for a nodeblock is \{1,5,2,4,3\}, then a nodal
596 coordinate of \{1.0, 2.0, 3.0, 4.0, 5.0\} would assign 1.0 to node 1,
597 2.0 to node 5, 3.0 to node 2, 4.0 to node 4 and 5.0 to node 3. There is
598 a caveat to this which is discussed in a later section.
599
600 Once the \code{STATE\_MODEL} state is finished, the
601 application may enter the \code{STATE\_DEFINE\_TRANSIENT}
602 state for an output database. It will then define what fields are to be
603 written to each of the GroupingEntities. Once these fields are defined,
604 the database will enter \code{STATE\_TRANSIENT}.
605
606 In \code{STATE\_TRANSIENT}, the transient fields are written.
607 The application will call:
608 \begin{source}
609 Ioss::DatabaseIO::begin\_state(Ioss::Region *region, int state, Real time)
610 \end{source}
611 which tells the database that the application will start writing
612 transient fields applying to time `\code{time}'. The
613 `\code{state}' will be an sequentially increasing counter
614 which indicates how many transient steps have been written. It is
615 1{}-based. This function can also be called for an input database if
616 the application is going to be reading transient data from the input
617 database. In this case, access to the state can be essentially random;
618 the application does not have to read from step 1...end\_step
619 sequentially. The function:
620 \begin{source}
621 Ioss::DatabaseIO::end\_state(Ioss::Region *region, int state, Real time)
622 \end{source}
623 will be called when all transient fields for this state have been
624 written. At this time, the \code{DatabaseIO} class can do
625 whatever is needed to finalize this particular timestep.
626
627 \subsubsection{Database Traits Interface}
628 In addition to the model and field{}-related functions defined above,
629 there are a few functions which specify characteristics of the
630 database. They are:
631
632 \begin{description}
633 \item [\code{virtual bool supports\_nodal\_fields()}]--
634 true/false depending on whether this database type supports fields
635 written on nodes in nodeblocks.
636 \item [\code{virtual bool supports\_side\_fields()}]-- true/false
637 depending on whether this database type supports fields written on
638 sides in sidesets.
639 \item [\code{virtual bool supports\_element\_fields()}]--
640 true/false depending on whether this database type supports fields
641 written on elements in element blocks.
642 \item [\code{virtual bool supports\_nodelist\_fields()}]--
643 true/false depending on whether this database type supports fields
644 written on nodes in nodelists.
645 \item [\code{virtual Int node\_global\_to\_local(Int global, bool
646 must\_exist)}]-- Provides a mapping from a global node id down to
647 the local 1..entity\_count position in the field data. In the `id' and
648 coordinate example above, the local position of global node `5' is `2'.
649 If the boolean `\code{must\_exist}' is true, then it is an
650 error if the specified node does not exist; otherwise if
651 \code{must\_exist} is false, then the function returns `0' if
652 a node with that global id does not exist.
653 \item [\code{virtual int maximum\_symbol\_length()}]-- Return
654 the maximum length of the `field names' that the database can handle;
655 return 0 if it is unlimited. This is used by the restart system which
656 must `mangle' the field names down to the maximum size that can be
657 supported on the database.
658 \end{description}
659 \section{Special Cases --Dynamic Topology}
660 Although the above description is valid for most cases, there are some
661 situations which must be handled to allow the database to be used in
662 all situations. Dynamic topology which include element death, load
663 balancing, and adaptivity cause the topology of the original mesh to
664 change from the originally defined topology.
665
666 \subsection{Element Death}
667 In the element death case, elements are selectively ``killed'' or
668 inactivated based on some criteria in the application. Most databases
669 continue to output these elements but they are flagged via an element
670 variable as whether they are active or inactive. This shouldn't cause
671 much difficulty, but the Sierra framework reorders the elements when
672 element death occurs, so the output database must map the element
673 fields which are not ordered based on the new element ordering back to
674 the original element ordering so that they can be output correctly.
675 When the element id ordering is changed, the \code{Frio}
676 system will inform the database by calling a
677 \code{put\_field} on the element block entities ``ids'' field
678 with the new ordering. This can be distinguished from the original
679 output of the element ids by the fact that in the original ordering,
680 the database will be in \code{STATE\_DEFINE\_MODEL}; in any
681 subsequent reordering of the element ids, the database will be in
682 \code{STATE\_TRANSIENT}. All subsequent output of element
683 transient fields will then be in the current ordering and will need to
684 be mapped to the original ordering before being written to the
685 database.
686
687 \subsection{Load Balance}
688 The load balance case involves shuffling the current nodes and elements
689 among processors. One or more nodes and elements will move to a new
690 processor in this case. The current handling of this case is suboptimal
691 and is based on the characteristics of the ExodusII database format
692 which is the primary format currently used in Sierra applications. The
693 ExodusII database creates a file per processor and all communications
694 to these databases are independent of all other databases. At the end
695 of the calculation, a separate program is used to join the
696 per{}-processor databases into a single database. Because the
697 per{}-processor databases are independent, the current handling of a
698 load balance reshuffling is that the current databases are all closed
699 and a new set is opened; a new model is defined; the transient fields
700 are redefined; and then everything continues from that point.
701
702 This is definitely not the optimal situation and will be changing in the
703 future. It is expected that a new function will be added to the
704 \code{Ioss::DatabaseIO} traits interface which will indicate
705 whether a concrete database instance supports dynamic topology. If it
706 is supported, then the \code{Frio} system will notify the
707 database that shuffling of elements and nodes among processors has
708 occurred and output a new set of node, element, face, and edge
709 orderings. If the database does not support dynamic topology, execution
710 will continue as above.
711
712 \subsection{Adaptivity}
713 The adaptivity case is handled the same way as the above load balance
714 case. The only difference is if the database is being used to store
715 restart data. In that case, instead of just outputting fields existing
716 on all of the current generation nodes and elements; fields are output
717 on the complete element and node hierarchy including the parent
718 elements which have been adapted. As stated above, the current behavior
719 will be changing in the future.
720
721 \section{Database Registration}
722 Before a database type can be used in a Sierra application, it must be
723 registered and it must provide a method for creating an instance of
724 itself. This is currently handled via an
725 \code{Ioss::IOFactory} class as shown below:
726
727 \begin{source}
728 namespace IoXX \{
729
730 \ \ const IOFactory* IOFactory::factory()\{
731 \ \ \ \ static IOFactory registerThis;
732 \ \ \ \ return \&registerThis;
733 \ \ \}
734
735 \ \ IOFactory::IOFactory()
736 \ \ \ \ : Ioss::IOFactory({\textquotedbl}database\_type{\textquotedbl}) \{
737 \ \ \ \ Ioss::IOFactory::alias({\textquotedbl}database\_type{\textquotedbl}, {\textquotedbl}alias\_for\_database\_type{\textquotedbl});
738 \ \ \}
739
740 \ \ Ioss::DatabaseIO* IOFactory::make\_IO(const std::string\& filename,
741 \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ Ioss::EventInterest db\_usage) const
742 \ \ \{ return new DatabaseIO(NULL, filename, db\_usage); \}
743 \}
744 \end{source}
745 The database type must also be made known to the parsing system. This is
746 done by editing the file
747 \code{framework/parser/io/Ioss\_MeshInput.xml }and adding an
748 enum\_entry with ``\code{database\_type}'' to the enum
749 \code{DatabaseTypes} near the top of the file.
750
751 Since Sierra applications are currently statically linked, some function
752 in your database library must be called by an existing piece of Sierra
753 code in order for the linker to pull in your library. If the database
754 is to be available for all codes, the best way to do this is to add a
755 call to your database's \code{IOFactory} to the code in
756 \code{Ioinit::Initializer()} as shown below:
757
758 \begin{source}
759 namespace Ioinit \{
760 \ \ Initializer::Initializer() \{
761 \ \ \ \ Ioex::IOFactory::factory(); \ \ \ // ExodusII
762 \ \ \ \ Iohb::IOFactory::factory(); \ \ // HeartBeat
763 \ \ \ \ IoXX::IOFactory::factory(); \ // My new database type
764 \ \ \}
765 \ \}
766 \end{source}
767 If the database is only available to a few applications, then the call
768 to the \code{factory()} method is usually placed in the
769 applications main routine. If a database has some finalization
770 functions which must be called at the end of execution (this is for a
771 library, not a specific database instance), then a call to that code
772 can be added to the \code{Ioinit::Initializer} destructor.
773
774 The user can then request this database type in the input file using the
775 line command \cmd{Database Type = database\_type} or \cmd{Database Type =
776 alias\_for\_database\_type}
777
778 \section{Build System}
779
780 The \code{io\_system} uses the standard Sierra build system which is
781 currently \code{BJam}. The main documentation page for BJam is
782 \url{http://boost.org/boost-build2/index.html}, and
783 documentation for using BJam with Sierra applications can be reached
784 from the Sierra developers documentation page at
785 \url{http://swi.sandia.gov/developers/develop.php}.
786 The build system must also be notified that the new library is to be
787 built and linked to the other code. The building of the library is
788 controlled in the
789 \file{NbtTools/io\_system/votd/Jamfile} file. If the
790 new database requires any external libraries (which are referred to as ``TPL's''
791 which means ``third-party libraries'') which provide an API or
792 other functionality, they are specified in the rules for the
793 library. For example, the \code{ioex} library (exodusII)
794 requires the exodusII, nemesis, and netcdf libraries and that is specified as:
795 \begin{source}
796 lib ioex
797 :
798 [ glob $(io_system-root)/src/exodusII/*.C ]
799 ioss
800 /sierra/utility//utility
801 /tpl/exodus//exodus
802 /tpl/nemesis//nemesis
803 /tpl/netcdf-c//netcdf
804 ;
805 \end{source}
806 The specification of what library versions will be used is specified in the \file{Nbtools/Jamroot} file:
807 \begin{source}
808 \ldots
809 register-product tpl : exodus : exodusii : 4.72 ;
810 register-product tpl : nemesis : nemesis : 3.09 ;
811 register-product tpl : netcdf : netcdf : 3.6.2-snl1 ;
812 \ldots
813 \end{source}
814 This specifies that version 4.72 of the ExodusII library, version 3.09
815 of the Nemesis library, and version 3.6.2-snl1 of the netcdf library
816 will be used. Later on in the file, the Ioex library build
817 instructions are defined as:
818 \begin{source}
819 lib ioex
820 :
821 [ glob $(io_system-root)/src/exodusII/*.C ]
822 ioss
823 /sierra/utility//utility
824 /tpl/exodus//exodus
825 /tpl/nemesis//nemesis
826 /tpl/netcdf-c//netcdf
827 ;
828
829 \end{source}
830 This specifies that the Ioex library is to be built. The source code
831 for the library is in \file{src/exodusII}. And it consists of all \file{.C}
832 files in that directory. The \code{Ioex} library ``requires'' the
833 \code{ioss} library from the io\_system; the external \code{utility}
834 library from \code{/sierra/utility}; and the \code{exodus},
835 \code{nemesis}, and \code{netcdf} third-party-libraries (tpl). There
836 are similar sections for the other libraries that are part of the
837 io\_system package.
838
839 One last piece of information is to tell the build system how to build
840 an application that uses the IO libraries. The build system is told
841 this in the following code block for the \code{io\_shell} executable:
842 \begin{source}
843 exe io_shell
844 :
845 $(io_system-root)/src/main/Main_io_shell.C
846 ioinit
847 ioss
848 iotr
849 iocgns
850 /sierra/utility//utility
851 : <tag>@runtest-tag
852 ;
853
854 \end{source}
855 Using this information, the build system should be able to generate
856 compile flags and correctly order the libraries on the link line for
857 the linker. A new database type can be added by following the
858 patterns for the Ioex, Iocgns, and Iohb database types.
859
860 \section{Testing}
861 The Sierra unit test system contains an executable called
862 \code{Utst\_io} which can be used to test the various
863 \code{DatabaseIO} classes. This executable is part of the
864 Sierra system, but it is also available in a standalone version which
865 can be built outside of the Sierra tools. The executable reads a
866 database of a specified format and then writes the data to a database
867 of a specified format. This can be used to test your
868 \code{DatabaseIO} class to make sure it reads the data
869 correctly and writes the data correctly. It can also be used as a
870 translator from one database format to another.
871
872 \section{Summary}
873 The above documentation gives a brief overview of the Sierra IO system.
874 It is not enough detail for the reader to add a completely functioning
875 new database type, but hopefully gives enough detail that the reader
876 can understand existing database IO classes and using those as an
877 example add a new database type.
878
879 There are some idiosyncrasies in the current Ioss system, but hopefully
880 as they are discovered, they will be removed via refactoring. The
881 current interface is definitely biased towards the ExodusII
882 functionality, but as more database types are added, I will attempt to
883 remove these biases.
884
885 \end{document}