{"id":1987,"date":"2021-01-05T21:14:38","date_gmt":"2021-01-05T19:14:38","guid":{"rendered":"https:\/\/www.albertopassalacqua.com\/?p=1987"},"modified":"2021-01-05T21:17:56","modified_gmt":"2021-01-05T19:17:56","slug":"p-2-the-structure-of-dictionaries-ep-1","status":"publish","type":"post","link":"https:\/\/www.albertopassalacqua.com\/?p=1987","title":{"rendered":"P. 2. The structure of dictionaries (Ep. 1)"},"content":{"rendered":"<p><\/p>\r\n<p style=\"text-align: justify;\">Dictionaries are what OpenFOAM<sup>\u00ae<\/sup> uses as input files, but the same name is used to indicate some of the structures inside such files.<\/p>\r\n<p style=\"text-align: justify;\">I will distinguish between a dictionary file and a dictionary to avoid ambiguity, but this distinction is not systematic in the documentation found on the Internet. In this part we focus on the structure of dictionary files.<\/p>\r\n<p>A dictionary files starts with the <code>FoamFile<\/code> subdictionary, which looks like<\/p>\r\n<pre>FoamFile\r\n{\r\n    version     2.0;\r\n    format      ascii;\r\n    class       dictionary;\r\n    location    \"system\";\r\n    object      controlDict;\r\n}<\/pre>\r\n<p style=\"text-align: justify;\">The first entry, <code>version<\/code>, indicates the format version of the input file. The second, more interesting, indicates that the dictionary is in ASCII format. The alternative is binary, which may be found in dictionaries storing fields, if the output is set to be written in binary format.<\/p>\r\n<p style=\"text-align: justify;\">The class entry indicates the type of object stored in the dictionary file. In this case the dictionary file stores a <code>dictionary<\/code>, but it could be a <code>volScalarField<\/code>, a <code>volVectorField<\/code> and so on.<\/p>\r\n<p style=\"text-align: justify;\">The <code>location<\/code> indicates in what directory in the case structure the dictionary is stored. Typical values are 0 (the folder of initial conditions), constant or systems. Note this entry is a string, so it appears between double quotes.<\/p>\r\n<p style=\"text-align: justify;\">Finally, the <code>object<\/code> indicates what object corresponds to the dictionary. In this case, a <code>controlDict<\/code> object. This is the name with which the dictionary object is identified in the internal database of OpenFOAM, so it may be important it is unique in case lookup operations on such database are performed to retrieve it (or you will spend hours figuring out why your code looks right and the object is not found: often the code is correct, but the input file is not! :-D).<\/p>\r\n<p>The simple structure of <code>FoamFile<\/code> is that of a standard subdictionary, which is as follows:<\/p>\r\n<pre>name<br \/>{<br \/>    entry 1;<br \/>    entry 2;<br \/>}<\/pre>\r\n<p style=\"text-align: justify;\">where <code>name<\/code> is the name of the subdictionary, and entries are contained between a scope, represented by <code>{}<\/code>, and separated by semicolons.<\/p>\r\n<p>A dictionary file may contain an arbitrary number of subdictionaries, but may also contain entries itself, not in a subdictionary. A very common example is controlDict, which has entries outside of a subdictionary, directly in the main body of the dictionary file:<\/p>\r\n<pre>FoamFile\r\n{\r\n    version     2.0;\r\n    format      ascii;\r\n    class       dictionary;\r\n    location    \"system\";\r\n    object      controlDict;\r\n}\r\n\r\napplication     simpleFoam;\r\nstartFrom       startTime;\r\nstartTime       0;\r\nstopAt          endTime;\r\nendTime         500;\r\ndeltaT          1;\r\nwriteControl    timeStep;\r\nwriteInterval   500;\r\npurgeWrite      0;\r\nwriteFormat     binary;\r\nwritePrecision  6;\r\nwriteCompression off;\r\ntimeFormat      general;\r\ntimePrecision   6;\r\nrunTimeModifiable true;<\/pre>\r\n<p style=\"text-align: justify;\">From this example, it appears that an entry has the following structure:<\/p>\r\n<p><code>key\u00a0 \u00a0 value;<\/code><\/p>\r\n<p style=\"text-align: justify;\">where <code>key<\/code> is a string without spaces and <code>value<\/code> can be a string (in a very general sense, as we will see later) or a number.<\/p>\r\n<p style=\"text-align: justify;\">The next post will focus on the type of entries and how they look like. Stay tuned!<\/p>\r\n\r\n\r\n\r\n\r\n\n<p style=\"text-align: justify;\"><em>This offering is not approved or endorsed by OpenCFD Limited, the producer of the OpenFOAM software and owner of the OPENFOAM\u00ae and OpenCFD\u00ae trade marks. Alberto Passalacqua is not associated to OpenCFD Ltd.<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Dictionaries are what OpenFOAM\u00ae uses as input files, but the same name is used to indicate some of the structures inside such files. In this part a general overview of their structure is provided.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,125,13,6],"tags":[],"class_list":["post-1987","post","type-post","status-publish","format-standard","hentry","category-cfd","category-education","category-general","category-openfoam"],"_links":{"self":[{"href":"https:\/\/www.albertopassalacqua.com\/index.php?rest_route=\/wp\/v2\/posts\/1987","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.albertopassalacqua.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.albertopassalacqua.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.albertopassalacqua.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.albertopassalacqua.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1987"}],"version-history":[{"count":4,"href":"https:\/\/www.albertopassalacqua.com\/index.php?rest_route=\/wp\/v2\/posts\/1987\/revisions"}],"predecessor-version":[{"id":1991,"href":"https:\/\/www.albertopassalacqua.com\/index.php?rest_route=\/wp\/v2\/posts\/1987\/revisions\/1991"}],"wp:attachment":[{"href":"https:\/\/www.albertopassalacqua.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1987"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.albertopassalacqua.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1987"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.albertopassalacqua.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1987"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}