{"id":2018,"date":"2021-01-12T01:21:30","date_gmt":"2021-01-11T23:21:30","guid":{"rendered":"https:\/\/www.albertopassalacqua.com\/?p=2018"},"modified":"2021-01-12T01:21:30","modified_gmt":"2021-01-11T23:21:30","slug":"p-3-the-structure-of-dictionaries-ep-2","status":"publish","type":"post","link":"https:\/\/www.albertopassalacqua.com\/?p=2018","title":{"rendered":"P. 3. The structure of dictionaries (Ep. 2)"},"content":{"rendered":"<p style=\"text-align: justify;\">In the <a href=\"https:\/\/www.albertopassalacqua.com\/?p=1987\">last post of this series<\/a> the general structure of a dictionary was introduced. We will now see the basic structure of entries. The first point to make is that entries in OpenFOAM<sup>\u00ae<\/sup> dictionaries can be of several types but they all follow the key\/value format, at least in a broad sense.<\/p>\r\n<p style=\"text-align: justify;\">The generic format of an entry is:<\/p>\r\n<p style=\"text-align: justify;\"><code>key\u00a0 \u00a0value;<\/code><\/p>\r\n<p style=\"text-align: justify;\">where <code>key<\/code> is an identifier and <code>value<\/code> can have different forms. Technically speaking a subdictionary is also an entry, but it was implemented differently in terms of formatting, so I will leave that out in this description.<\/p>\r\n<p style=\"text-align: justify;\">One of the most common forms of entries are what I will call coefficients. Coefficients can be dimensioned or not, depending on how the implementation was carried out in the code. The simplest form is the following:<\/p>\r\n<p style=\"text-align: justify;\"><code>coeffName\u00a0 \u00a0 numericalValue;<\/code><\/p>\r\n<p style=\"text-align: justify;\">For example:<\/p>\r\n<p style=\"text-align: justify;\"><code>Cmu\u00a0 \u00a0 0.9;<\/code><\/p>\r\n<p style=\"text-align: justify;\">In case a coefficient has a dimension, then its format becomes:<\/p>\r\n<p style=\"text-align: justify;\"><code>nu\u00a0 \u00a0 [<span class=\"pl-c1\">0<\/span> <span class=\"pl-c1\">2<\/span> -<span class=\"pl-c1\">1<\/span> <span class=\"pl-c1\">0<\/span> <span class=\"pl-c1\">0<\/span> <span class=\"pl-c1\">0<\/span> <span class=\"pl-c1\">0<\/span>] <span class=\"pl-c1\">0.01<\/span>;<\/code><\/p>\r\n<p style=\"text-align: justify;\">In older versions of OpenFOAM<sup>\u00ae<\/sup> the format used to be:<\/p>\r\n<p style=\"text-align: justify;\"><code>nu\u00a0 \u00a0 nu [<span class=\"pl-c1\">0<\/span> <span class=\"pl-c1\">2<\/span> -<span class=\"pl-c1\">1<\/span> <span class=\"pl-c1\">0<\/span> <span class=\"pl-c1\">0<\/span> <span class=\"pl-c1\">0<\/span> <span class=\"pl-c1\">0<\/span>] <span class=\"pl-c1\">0.01<\/span>;<\/code><\/p>\r\n<p style=\"text-align: justify;\">In short, the dimensionSet and the numerical value constitute the actual value on the key\/value pair of the dictionary. Note that the value is not necessarily a scalar. It can be a vector:<\/p>\r\n<p style=\"text-align: justify;\"><code>locationInMesh\u00a0 \u00a0 (0 0 1);<\/code><\/p>\r\n<p style=\"text-align: justify;\">or, in the dimensioned case:<\/p>\r\n<p style=\"text-align: justify;\"><code>U\u00a0 \u00a0 [<span class=\"pl-c1\">0<\/span> 1 -<span class=\"pl-c1\">1<\/span> <span class=\"pl-c1\">0<\/span> <span class=\"pl-c1\">0<\/span> <span class=\"pl-c1\">0<\/span> <span class=\"pl-c1\">0<\/span>] (0 1 0);<\/code><\/p>\r\n<p style=\"text-align: justify;\">Lists can be used as values in the key\/value pair of dictionaries (common in fields initialized with non-uniform values):<\/p>\r\n<p style=\"text-align: justify;\"><code>internalField\u00a0 \u00a0 nonuniform List&lt;vector&gt; <\/code><br \/><code>300\u00a0 \/\/ Number of elements<\/code><br \/><code>(<\/code><br \/><code>\u00a0 \u00a0 (0 1 1)\u00a0 \u00a0\/\/ Elements<\/code><br \/><code>\u00a0 \u00a0 (0 1 2)<\/code><\/p>\r\n<p style=\"text-align: justify;\"><code>\u00a0 \u00a0 ...<\/code><\/p>\r\n<p style=\"text-align: justify;\"><code>);<\/code><\/p>\r\n<p style=\"text-align: justify;\">Note that lists may or may not require the number of elements before the list content start, depending on the corresponding type used in C++ code<\/p>\r\n<p style=\"text-align: justify;\">Another type of entry is what in OpenFOAM<sup>\u00ae<\/sup> is identified as <code>word<\/code> (do not confuse this term with the word numerical type of programming languages: word in OpenFOAM<sup>\u00ae<\/sup> is essentially a single-word string!). Several examples of this type of entry were shown in the previous post<\/p>\r\n<p style=\"text-align: justify;\"><code>startFrom\u00a0 \u00a0 startTime;<\/code><\/p>\r\n<p style=\"text-align: justify;\">In an entry of this type, a single word is the value of the key\/value pair.<\/p>\r\n<p style=\"text-align: justify;\">More complex versions of this type of entry, where the value is a string rather than a single word are also possible. For example, when specifying numerical schemes, entries like the following are encountered:<\/p>\r\n<p style=\"text-align: justify;\"><code> <span class=\"pl-c1\">div<\/span>(phi,U)\u00a0 \u00a0 Gauss limitedLinearV <span class=\"pl-c1\">1<\/span>;<\/code><\/p>\r\n<p style=\"text-align: justify;\">The format of these entries depends on the context where they are used, consequently it is pointless to try to extract general rules, since they would be ad-hoc to the specific context.<\/p>\r\n<p style=\"text-align: justify;\">OpenFOAM implements the bool type calling it <code>Switch<\/code>, to allow for different input options from <code>true\/false<\/code>. For example, <code>yes\/no<\/code>, <code>on\/off<\/code> are allowed. The syntax of the corresponding entry is however unaffected:<\/p>\r\n<p style=\"text-align: justify;\"><code>turbulence\u00a0 \u00a0 on;<\/code><\/p>\r\n<p style=\"text-align: justify;\">This is a brief summary of the most commonly encountered types of entries found in dictionaries.<\/p>\r\n<p style=\"text-align: justify;\">Enjoy and stay tuned! \ud83d\ude42<\/p>\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>In the last post of this series the general structure of a dictionary was introduced. We will now see the basic structure of entries. The first point to make is that entries in OpenFOAM\u00ae dictionaries can be of several types but they all follow the key\/value format, at least in a broad sense.<\/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,6],"tags":[],"class_list":["post-2018","post","type-post","status-publish","format-standard","hentry","category-cfd","category-education","category-openfoam"],"_links":{"self":[{"href":"https:\/\/www.albertopassalacqua.com\/index.php?rest_route=\/wp\/v2\/posts\/2018","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=2018"}],"version-history":[{"count":4,"href":"https:\/\/www.albertopassalacqua.com\/index.php?rest_route=\/wp\/v2\/posts\/2018\/revisions"}],"predecessor-version":[{"id":2024,"href":"https:\/\/www.albertopassalacqua.com\/index.php?rest_route=\/wp\/v2\/posts\/2018\/revisions\/2024"}],"wp:attachment":[{"href":"https:\/\/www.albertopassalacqua.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2018"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.albertopassalacqua.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2018"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.albertopassalacqua.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2018"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}