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

From OpenFOAMWiki
(IOobject constructors: Minor formatting changes)
 
(12 intermediate revisions by 5 users not shown)
Line 1: Line 1:
 
Many input/output operations are performed in OpenFOAM using the IOobject class, which is described in its [http://foam.sourceforge.net/doc/Doxygen/html/db/d1a/IOobject_8H-source.html header file] as follows:
 
Many input/output operations are performed in OpenFOAM using the IOobject class, which is described in its [http://foam.sourceforge.net/doc/Doxygen/html/db/d1a/IOobject_8H-source.html 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 [[snip_objectRegistry|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 ==
+
== <code>IOobject</code> constructors ==
  
The constructor of an IOobject may have two forms:
+
The constructor of an <code>IOobject</code> may have two forms:
 +
 
 +
1. Construct from name, instance, registry and IO options:
  
* Construct from name, instance, registry and IO options
 
 
<cpp>
 
<cpp>
 
IOobject 
 
IOobject 
 
(   
 
(   
     const word &amp;   name,
+
     const word &  name,
     const word &amp; instance,
+
     const word &  instance,
     const objectRegistry &amp; registry,
+
     const objectRegistry &  registry,
 
     readOption  r = NO_READ,
 
     readOption  r = NO_READ,
 
     writeOption  w = NO_WRITE,
 
     writeOption  w = NO_WRITE,
Line 20: Line 21:
 
</cpp>
 
</cpp>
  
* Construct from name, instance, local, registry and IO options
+
2. Construct from name, instance, local, registry and IO options:
  
 
<cpp>
 
<cpp>
 
IOobject 
 
IOobject 
 
(
 
(
     const word &amp;   name,
+
     const word &  name,
     const word &amp; instance,
+
     const word &  instance,
     const fileName &amp; local,
+
     const fileName &  local,
     const objectRegistry &amp; registry,
+
     const objectRegistry &  registry,
 
     readOption  r = NO_READ,
 
     readOption  r = NO_READ,
 
     writeOption  w = NO_WRITE,
 
     writeOption  w = NO_WRITE,
Line 35: Line 36:
 
</cpp>
 
</cpp>
  
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 <code>word</code> inherits <code>string</code>, from which <code>fileName</code> is also derived. Moreover, both <code>Time</code> and <code>polyMesh</code> inherit <code>objectRegistry</code>. As a consequence <code>fvMesh</code>, inheriting <code>polyMesh</code>, indirectly inherits <code>objectRegistry</code> too. For further information, see the [http://foam.sourceforge.net/docs/cpp/a00926.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
+
 
  The object must be read from Istream on construction. An error message is produced if Istream does not exist or can't be read.
+
* <code>MUST_READ</code> – The object must be read from <code>Istream</code> on construction. An error message is produced if Istream does not exist or can't be read.
* READ_IF_PRESENT
+
* <code>READ_IF_PRESENT</code> – It reads the object from <code>Istream</code> if <code>Istream</code> exists, otherwise doesn't. An error message is produced only if <code>Istream</code> exists but can't be read.
  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.
+
* <code>NO_READ</code> – Don't read the object.
* NO_READ
+
  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:
  
* AUTO_WRITE
+
* <code>AUTO_WRITE</code> – The object is written automatically when requested to by the <code>objectRegistry</code>.
  The object is written automatically when requested to by the objectRegistry.
+
* <code>NO_WRITE</code> – The object is not written automatically on destruction, but it can be written explicitly.
* NO_WRITE
+
  The object is not written automatically on destruction, but it can be written explicitly.
+
  
== IOobject and dictionaries ==
+
== <code>IOobject</code> 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 <code>IOobject</code> class when they are declared. Usually the <code>readOption</code> for a dictionary is <code>MUST_READ</code>, while the <code>writeOption</code> is <code>NO_WRITE</code> not to overwrite the settings contained in the dictionary.
For example, the code required to read the usual transportProperties dictionary is:
+
For example, the code required to read the usual <code>transportProperties</code> dictionary is:
  
 
<cpp>
 
<cpp>
Line 73: Line 70:
 
The first constructor form is adopted in this case, where:
 
The first constructor form is adopted in this case, where:
  
* "transportProperties" is the name of the file containing the dictionary.
+
* <code>transportProperties</code> is the name of the file containing the dictionary.
* runTime.constant(), the instance, gives the position of the dictionary, which is, in this case, contained in the constant directory of the considered case.
+
* <code>runTime.constant()</code>, the instance, gives the position of the dictionary, which is, in this case, contained in the constant directory of the considered case.
* The objectRegistry is represented by the mesh.
+
* The <code>objectRegistry</code> is represented by the mesh.
 +
 
 +
== <code>IOobject</code> and fields ==
 +
Similarly to dictionaries, read and write options for a field can be set using the <code>IOobject</code> class. The syntax is almost the same for all kind of field and it is clarified by the following example.
 +
If we would like to define a <code>volScalarField</code> called <code>T</code>, saving it at user-defined intervals of time in a file called <code>T</code>, the code is:
  
== IOobject and fields ==
 
Similarly to dictionaries, read and write options for a field can be set using the IOobject class. The syntax is almost the same for all kind of field and it is clarified by the following example.
 
If we would like to define a volScalarField called T, saving it at user-defined intervals of time in a file called T, the code is:
 
 
<cpp>
 
<cpp>
 
volScalarField T
 
volScalarField T
Line 94: Line 92:
 
);
 
);
 
</cpp>
 
</cpp>
 +
 
where:
 
where:
* "T" is the name of the file.
+
* <code>T</code> is the name of the file.
* runTime.timeName() tells OpenFOAM to save the file in a directory called as the current run time.
+
* <code>runTime.timeName()</code> tells OpenFOAM to save the file in a directory called as the current run time.
* mesh is the objectRegistry.
+
* <code>mesh</code> is the <code>objectRegistry</code>.
* Read and write options are set to MUST_READ and AUTO_WRITE in order to make OpenFOAM read the field and to automatically save it. If reading the field is not required, the MUST_READ option has to be changed into NO_READ.
+
* Read and write options are set to <code>MUST_READ</code> and <code>AUTO_WRITE</code> in order to make OpenFOAM read the field and to automatically save it. If reading the field is not required, the <code>MUST_READ</code> option has to be changed into <code>NO_READ</code>.
<div id="aflknwerkamfs" style="overflow:auto;height:4px;">[http://swissfzuwdj.toplog.nl swiss panerai replica watch] [http://swissadvrqg.toplog.nl swiss cartier watch replica] [http://swissoemejy.toplog.nl swiss gear backpack laptop] [http://patekmcpuau.toplog.nl patek philippe swiss replica] [http://swissthutrc.toplog.nl swiss watch quartz] [http://luxurqnjwhk.toplog.nl luxury replica swiss watch] [http://swissicrunf.toplog.nl swiss offshore bank account] [http://swissdgkxpg.toplog.nl swiss army chronograph] [http://fakessqbtrm.toplog.nl fake swiss rolex watch replica] [http://fakerwqmqdm.toplog.nl fake replica rolex swiss watch] [http://armycwvjjec.toplog.nl army chronograph swiss watch] [http://omegawuhvgw.toplog.nl omega swiss replica] [http://fakerdgisdy.toplog.nl fake rolex swiss watch] [http://cartilabann.toplog.nl cartier swiss replica] [http://swissxuextt.toplog.nl swiss breitling replica] [http://swissuqtlzh.toplog.nl swiss made breitling replica watch] [http://fakesnbtmsu.toplog.nl fake swiss watch] [http://accougeatrl.toplog.nl account bank credit offshore suisse swiss] [http://swisswofaro.toplog.nl swiss army wrist watch] [http://swisslamver.toplog.nl swiss army laptop bag] [http://panerhzbttj.toplog.nl panerai swiss replica] [http://accouccrkng.toplog.nl account bank bank offshore swiss switzerland union] [http://swissjblwhx.toplog.nl swiss camping gear] [http://cncswynxson.toplog.nl cnc swiss machining] [http://armybrzvpdt.toplog.nl army briefcase swiss] [http://001reebyjqw.toplog.nl 0.01 replica rolex swiss watch] [http://swissmveoaq.toplog.nl swiss army laptop backpack] [http://swisshvtqjf.toplog.nl swiss made replica watch] [http://swissdmgird.toplog.nl swiss army backpack] [http://repliqxyqnf.toplog.nl replica rolex swiss watch] [http://replixblwen.toplog.nl replica rolex swiss] [http://swissarykjr.toplog.nl swiss rolex replica] [http://swissooitfp.toplog.nl swiss replica watch] [http://lastmjveumi.toplog.nl last minute package travel] [http://alaskmfuimh.toplog.nl alaska deal travel] [http://travelwgfem.toplog.nl travel agency lawton oklahoma] [http://califcsqxoh.toplog.nl california jose san travel] [http://travedczfpd.toplog.nl travel lancaster pennsylvania] [http://dealeraosxt.toplog.nl dealer illinois trailer travel] [http://groupynlqed.toplog.nl group holland travel] [http://agentsmsofo.toplog.nl agent california jose san travel] [http://travedxwhwt.toplog.nl travel agent johnstown pennsylvania] [http://jamailhrvck.toplog.nl jamaica travel requirement] [http://travevyhvcz.toplog.nl travel johnstown pennsylvania] [http://jamaisuccle.toplog.nl jamaica travel tip] [http://traverxgris.toplog.nl travel agency cleveland ohio] [http://travebwddig.toplog.nl travel agency cincinnati ohio] [http://hawaihjplsp.toplog.nl hawaii information travel] [http://travekbcdyz.toplog.nl travel agency lancaster pennsylvania] [http://travejvjjpm.toplog.nl travel agent madison wisconsin] [http://golfithncpn.toplog.nl golf ireland travel] [http://travebdhlnd.toplog.nl travel steubenville ohio] [http://alaskooilkc.toplog.nl alaska nursing travel] [http://travexkbnsl.toplog.nl travel agency allentown pennsylvania] [http://traveejuwub.toplog.nl travel trailer rental in wisconsin] [http://coastdthysc.toplog.nl coastal discount package travel vacation] [http://robotgeovnx.toplog.nl robot site travel web] [http://traveimorkl.toplog.nl travel agency fort smith oklahoma] [http://busesfsdcho.toplog.nl bus escort hanover travel] [http://hawaipawhpw.toplog.nl hawaii onlin online travel] [http://agentrfmtki.toplog.nl agent illinois travel] [http://hawaikqzvra.toplog.nl hawaii tip travel] [http://travemlngej.toplog.nl travel fort smith oklahoma] [http://agenctraebn.toplog.nl agency davenport illinois travel] [http://travefgcffq.toplog.nl travel agent cincinnati] [http://agencxdoqkx.toplog.nl agency nebraska travel] [http://discopnfzoq.toplog.nl discount hawaii package travel] [http://travegwiqmj.toplog.nl travel agent louisville] [http://travehpibeg.toplog.nl travel agent harrisburg pennsylvania] [http://califejjidz.toplog.nl california francisco guide san travel] [http://califybjgcu.toplog.nl california rental trailer travel] [http://aainsafplev.toplog.nl aa insurance travel] [http://travecnxesm.toplog.nl travel agency canton ohio] [http://travedmfkkf.toplog.nl travel agent riverside] [http://onlinklpxvc.toplog.nl online site travel web] [http://gaptrrugpec.toplog.nl gap travel year] [http://gaminttypwn.toplog.nl gaming lodging resort resort spa travel] [http://hawaiklgipk.toplog.nl hawaii links travel] [http://agenclzjemz.toplog.nl agency california jose san travel] [http://ameripvptll.toplog.nl america south travel] [http://bestsbuyzrt.toplog.nl best site travel web] [http://newnyyflbxy.toplog.nl new nyc travel visit york] [http://lastmjveumi.toplog.nl last minute package travel] [http://alaskmfuimh.toplog.nl alaska deal travel] [http://travelwgfem.toplog.nl travel agency lawton oklahoma] [http://califcsqxoh.toplog.nl california jose san travel] [http://travedczfpd.toplog.nl travel lancaster pennsylvania] [http://dealeraosxt.toplog.nl dealer illinois trailer travel] [http://groupynlqed.toplog.nl group holland travel] [http://agentsmsofo.toplog.nl agent california jose san travel] [http://travedxwhwt.toplog.nl travel agent johnstown pennsylvania] [http://jamailhrvck.toplog.nl jamaica travel requirement] [http://travevyhvcz.toplog.nl travel johnstown pennsylvania] [http://jamaisuccle.toplog.nl jamaica travel tip] [http://traverxgris.toplog.nl travel agency cleveland ohio] [http://travebwddig.toplog.nl travel agency cincinnati ohio] [http://hawaihjplsp.toplog.nl hawaii information travel] [http://travekbcdyz.toplog.nl travel agency lancaster pennsylvania] [http://travejvjjpm.toplog.nl travel agent madison wisconsin] [http://golfithncpn.toplog.nl golf ireland travel] [http://travebdhlnd.toplog.nl travel steubenville ohio] [http://alaskooilkc.toplog.nl alaska nursing travel] [http://travexkbnsl.toplog.nl travel agency allentown pennsylvania] [http://traveejuwub.toplog.nl travel trailer rental in wisconsin] [http://coastdthysc.toplog.nl coastal discount package travel vacation] [http://robotgeovnx.toplog.nl robot site travel web] [http://traveimorkl.toplog.nl travel agency fort smith oklahoma] [http://busesfsdcho.toplog.nl bus escort hanover travel] [http://hawaipawhpw.toplog.nl hawaii onlin online travel] [http://agentrfmtki.toplog.nl agent illinois travel] [http://hawaikqzvra.toplog.nl hawaii tip travel] [http://travemlngej.toplog.nl travel fort smith oklahoma] [http://agenctraebn.toplog.nl agency davenport illinois travel] [http://travefgcffq.toplog.nl travel agent cincinnati] [http://agencxdoqkx.toplog.nl agency nebraska travel] [http://discopnfzoq.toplog.nl discount hawaii package travel] [http://travegwiqmj.toplog.nl travel agent louisville] [http://travehpibeg.toplog.nl travel agent harrisburg pennsylvania] [http://califejjidz.toplog.nl california francisco guide san travel] [http://califybjgcu.toplog.nl california rental trailer travel] [http://aainsafplev.toplog.nl aa insurance travel] [http://travecnxesm.toplog.nl travel agency canton ohio] [http://travedmfkkf.toplog.nl travel agent riverside] [http://onlinklpxvc.toplog.nl online site travel web] [http://gaptrrugpec.toplog.nl gap travel year] [http://gaminttypwn.toplog.nl gaming lodging resort resort spa travel] [http://hawaiklgipk.toplog.nl hawaii links travel] [http://agenclzjemz.toplog.nl agency california jose san travel] [http://ameripvptll.toplog.nl america south travel] [http://bestsbuyzrt.toplog.nl best site travel web] [http://newnyyflbxy.toplog.nl new nyc travel visit york] [http://gucciwjrbie.toplog.nl gucci handbag low price] [http://atticpqnoje.toplog.nl attic handbag] [http://strawpixfth.toplog.nl straw handbag] [http://lvhancbyrhz.toplog.nl lv handbag] [http://repliuwjlmo.toplog.nl replica gucci handbag] [http://dknyhelvoxl.toplog.nl dkny handbag] [http://stonephczfg.toplog.nl stone mountain handbag] [http://balendhcafx.toplog.nl balenciaga handbag] [http://disconrbhxc.toplog.nl discount coach handbag] [http://handmwwqifp.toplog.nl handmade handbag] [http://bradldjhckz.toplog.nl bradley handbag vera] [http://michaoqexsf.toplog.nl michael kors handbag] [http://discoqzdupt.toplog.nl discount designer handbag] [http://chrishmdegv.toplog.nl christian dior handbag] [http://authehlafks.toplog.nl authentic gucci handbag] [http://knockrcbckp.toplog.nl knockoff handbag] [http://diorhnbxcnd.toplog.nl dior handbag] [http://repliafpnlw.toplog.nl replica coach handbag] [http://katesjziroe.toplog.nl kate spade handbag] [http://juicymxuzgs.toplog.nl juicy couture handbag] [http://brighvpamhq.toplog.nl brighton handbag] [http://chloevtbrkf.toplog.nl chloe handbag] [http://louisbcknnq.toplog.nl louis vuitton replica handbag] [http://handbhivhfu.toplog.nl handbag jacobs marc] [http://marcjwxgyth.toplog.nl marc jacobs handbag] [http://discoptnnsj.toplog.nl discount handbag] [http://guesscpaojo.toplog.nl guess handbag] [http://burbemdvxmu.toplog.nl burberry handbag] [http://repliqywzpf.toplog.nl replica designer handbag] [http://handbtcnkol.toplog.nl handbag purse] [http://doonemrqjgg.toplog.nl dooney bourke handbag] [http://fendijaupaz.toplog.nl fendi handbag] [http://louiselbecz.toplog.nl louis vuitton handbag] [http://wholeodzlct.toplog.nl wholesale handbag] [http://replisuwumv.toplog.nl replica handbag] [http://coacheygoum.toplog.nl coach handbag] [http://gucciakuupm.toplog.nl gucci handbag] [http://pradaimieyj.toplog.nl prada handbag] [http://fendinptvxq.toplog.nl fendi handbag] [http://louiszekmjg.toplog.nl louis vuitton handbag] [http://cheapbuy.toplog.nl/ cheap buy xanax] [http://orderedxanax.toplog.nl/ order xanax online] [http://toplognl.toplog.nl/ buy xanax] [http://tramadol.toplog.nl/ buy tramadol] [http://xanaxx.zikforum.com/ buy xanax online] [http://www.weblogpage.com/xanaxx/ cheap buy xanax] [http://handbag.toplog.nl/ replica coach handbag] [http://vtopp.zikforum.com louis vuitton replica handbag] [http://www.weblogpage.com/handbag/ replica designer handbag] [http://e-mercato.org/vtop/wholesalehandbag.html wholesale replica handbag] [http://e-mercato.org/vtop/rdesignerhandbag.html replica designer handbag] [http://e-mercato.org/vtop/pradahandbag.html prada replica handbag] [http://e-mercato.org/vtop/louisvuittonhandbag.html louis vuitton replica handbag] [http://e-mercato.org/vtop/guccihandbag.html replica gucci handbag] [http://e-mercato.org/vtop/designerhandbag.html designer handbag replica] [http://e-mercato.org/vtop/coachhandbag.html replica coach handbag] [http://e-mercato.org/vtop/chanelhandbag.html replica chanel handbag] [http://www.dablogs.com/?u=vverh quality replica watch] [http://www.freewebs.com/vverh/ quality replica watch] [http://vverh.forumup.org quality replica watch] [http://topnash.forumup.org/ swiss replica rolex watch] [http://www.freewebs.com/topnash/ swiss replica rolex watch] [http://www.dablogs.com/?u=topnash swiss replica rolex watch] [http://www.dablogs.com/?u=buduvtope omega replica watch] [http://www.freewebs.com/buduvtope/ omega replica watch] [http://buduvtope.forumup.org omega replica watch] [http://www.dablogs.com/?u=replicahandbag12 louis vuitton replica handbag] [http://replicahandbag12.forumup.org/ louis vuitton replica handbag] [http://cartier.forumup.org/ cartier replica watch] [http://www.dablogs.com/?u=cartier cartier replica watch] [http://www.freewebs.com/cartierwatch/ cartier replica watch] [http://www.freewebs.com/brietling/ breitling replica watch] [http://www.dablogs.com/?u=brietling breitling replica watch] </div>
+
[[Category:OpenFOAM coding guide]]

Latest revision as of 16:47, 16 August 2014

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:

1. 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
)

2. 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 word inherits string, from which fileName is also 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, the code required to read the usual transportProperties dictionary is:

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

The first constructor form is adopted in this case, where:

  • transportProperties is the name of the file containing the dictionary.
  • runTime.constant(), the instance, gives the position of the dictionary, which is, in this case, contained in the constant directory of the considered case.
  • The objectRegistry is represented by the mesh.

5 IOobject and fields

Similarly to dictionaries, read and write options for a field can be set using the IOobject class. The syntax is almost the same for all kind of field and it is clarified by the following example. If we would like to define a volScalarField called T, saving it at user-defined intervals of time in a file called T, the code is:

 
volScalarField T
(
    IOobject
    (
        "T",
        runTime.timeName(),
        mesh,
        IOobject::MUST_READ,
        IOobject::AUTO_WRITE
    ),
    mesh
);

where:

  • T is the name of the file.
  • runTime.timeName() tells OpenFOAM to save the file in a directory called as the current run time.
  • mesh is the objectRegistry.
  • Read and write options are set to MUST_READ and AUTO_WRITE in order to make OpenFOAM read the field and to automatically save it. If reading the field is not required, the MUST_READ option has to be changed into NO_READ.