Difference between revisions of "OpenFOAM guide/Input and Output operations using dictionaries and the IOobject class"

From OpenFOAMWiki
 
m (Input/Output operations using dictionaries and the IOobject class)
Line 1: Line 1:
== Input/Output operations using dictionaries and the IOobject class ==
 
 
Many input/output operations are performed in OpenFOAM using the IOobject class, which is described in its header file as follows:
 
Many input/output operations are performed in OpenFOAM using the IOobject class, which is described in its header file as follows:
  
 
''IOobject defines the attributes of an object for which implicit objectRegistry management is supported, and provides the infrastructure for performing stream I/O. An IOobject is constructed with an object name, a class name, an instance path, a reference to a objectRegistry, and parameters determining its storage status.''
 
''IOobject defines the attributes of an object for which implicit objectRegistry management is supported, and provides the infrastructure for performing stream I/O. An IOobject is constructed with an object name, a class name, an instance path, a reference to a objectRegistry, and parameters determining its storage status.''
  
==== IOobject constructors ====
+
== IOobject constructors ==
  
 
The constructor of an IOobject may have two forms:
 
The constructor of an IOobject may have two forms:
Line 38: Line 37:
 
While reading the two previous code snippets, remember that string inherits word, from which fileName is derived. Moreover, both Time and polyMesh inherit objectRegistry. As a consequence fvMesh, inheriting polyMesh, indirectly inherits objectRegistry too. For further information, see the [http://foam.sourceforge.net/doc/Doxygen/html/da/df5/classFoam_1_1IOobject.html IOobject class reference].
 
While reading the two previous code snippets, remember that string inherits word, from which fileName is derived. Moreover, both Time and polyMesh inherit objectRegistry. As a consequence fvMesh, inheriting polyMesh, indirectly inherits objectRegistry too. For further information, see the [http://foam.sourceforge.net/doc/Doxygen/html/da/df5/classFoam_1_1IOobject.html IOobject class reference].
  
==== Read options ====
+
== Read options ==
 
Read options, which define what is done on object construction and explicit reads, are:
 
Read options, which define what is done on object construction and explicit reads, are:
 
* MUST_READ
 
* MUST_READ
Line 47: Line 46:
 
   Don't read the object.
 
   Don't read the object.
  
==== Write options ====
+
== Write options ==
 
Write options, which define what is done on object destruction and explicit writes, are:
 
Write options, which define what is done on object destruction and explicit writes, are:
  
Line 55: Line 54:
 
   The object is not written automatically on destruction, but it can be written explicitly.
 
   The object is not written automatically on destruction, but it can be written explicitly.
  
==== IOobject and dictionaries ====
+
== IOobject and dictionaries ==
 
Dictionaries can be read using the IOobject class when they are declared. Usually the readOption for a dictionary is MUST_READ, while the writeOption is NO_WRITE not to overwrite the settings contained in the dictionary.
 
Dictionaries can be read using the IOobject class when they are declared. Usually the readOption for a dictionary is MUST_READ, while the writeOption is NO_WRITE not to overwrite the settings contained in the dictionary.
 
For example, for the usual transportProperties dictionary, the syntax is:
 
For example, for the usual transportProperties dictionary, the syntax is:
Line 74: Line 73:
 
where runTime.constant() gives the position of the dictionary, which is, in this case, contained in the constant directory of the considered case.
 
where runTime.constant() gives the position of the dictionary, which is, in this case, contained in the constant directory of the considered case.
  
==== IOobect and fields ====
+
== IOobect and fields ==
 
Input/output options for a field can be set similarly to
 
Input/output options for a field can be set similarly to

Revision as of 01:27, 13 August 2005

Many input/output operations are performed in OpenFOAM using the IOobject class, which is described in its header file as follows:

IOobject defines the attributes of an object for which implicit objectRegistry management is supported, and provides the infrastructure for performing stream I/O. An IOobject is constructed with an object name, a class name, an instance path, a reference to a objectRegistry, and parameters determining its storage status.

1 IOobject constructors

The constructor of an IOobject may have two forms:

  • Construct from name, instance, registry and IO options
 
IOobject  	
(  
    const word &   	 	name,
    const word &  		instance,
    const objectRegistry &  	registry,
    readOption  		r = NO_READ,
    writeOption  		w = NO_WRITE,
    bool  			registerObject = true
)
  • Construct from name, instance, local, registry and IO options
 
IOobject  	
(
    const word &   	 	name,
    const word &  		instance,
    const fileName &  		local,
    const objectRegistry &  	registry,
    readOption  		r = NO_READ,
    writeOption  		w = NO_WRITE,
    bool  			registerObject = true
)

While reading the two previous code snippets, remember that string inherits word, from which fileName is derived. Moreover, both Time and polyMesh inherit objectRegistry. As a consequence fvMesh, inheriting polyMesh, indirectly inherits objectRegistry too. For further information, see the IOobject class reference.

2 Read options

Read options, which define what is done on object construction and explicit reads, are:

  • MUST_READ
 The object must be read from Istream on construction. An error message is produced if Istream does not exist or can't be read.
  • READ_IF_PRESENT
 It reads the object from Istream if Istream exists, otherwise doesn't. An error message is produced only if Istream exists but can't be read.
  • NO_READ
 Don't read the object.

3 Write options

Write options, which define what is done on object destruction and explicit writes, are:

  • AUTO_WRITE
 The object is written automatically when requested to by the objectRegistry.
  • NO_WRITE
 The object is not written automatically on destruction, but it can be written explicitly.

4 IOobject and dictionaries

Dictionaries can be read using the IOobject class when they are declared. Usually the readOption for a dictionary is MUST_READ, while the writeOption is NO_WRITE not to overwrite the settings contained in the dictionary. For example, for the usual transportProperties dictionary, the syntax is:

 
IOdictionary transportProperties
(
     IOobject
     (
          "transportProperties",
          runTime.constant(),
          mesh,
          IOobject::MUST_READ,
          IOobject::NO_WRITE
     )
);

where runTime.constant() gives the position of the dictionary, which is, in this case, contained in the constant directory of the considered case.

5 IOobect and fields

Input/output options for a field can be set similarly to