{"id":947,"date":"2011-05-28T09:13:24","date_gmt":"2011-05-28T07:13:24","guid":{"rendered":"http:\/\/142.93.241.207\/?p=947"},"modified":"2011-05-28T09:13:24","modified_gmt":"2011-05-28T07:13:24","slug":"how-to-access-dictionary-values-from-boundary-conditions-in-openfoam","status":"publish","type":"post","link":"https:\/\/www.albertopassalacqua.com\/?p=947","title":{"rendered":"How to access dictionary values from boundary conditions in OpenFOAM"},"content":{"rendered":"<p style=\"text-align: justify;\">OpenFOAM\u00ae offers a standard way to access user-specified constant data by means of dictionaries. However, dictionaries are by default read during the start-up phase of the main code. If a boundary condition requires to access the same information, the value can be looked up from the internal database used by OpenFOAM to store objects. The procedure is quite simple, and I show an example below, in a general case. Let&#8217;s assume our solver uses the &#8220;transportProperties&#8221; dictionary, which contains a  subdictionary, called &#8220;mySubDict&#8221;. This sub-dictionary contains a dimensioned scalar, named &#8220;myScalar&#8221;. In the BC, you can recover &#8220;myScalar&#8221; as follows:<\/p>\n<pre lang=\"c++\">\/\/ Extract the dictionary from the database\r\nconst dictionary&amp; transportProperties = db().lookupObject&lt;IOdictionary&gt;\r\n(\r\n \"transportProperties\"\r\n);\r\n\r\n\/\/ Exctract subdictionary from the main dictionary\r\ndictionary mySubDict\r\n(\r\n transportProperties.subDict(\"mySubDict\")\r\n);\r\n\r\n\/\/ Extracting scalar value\r\ndimensionedScalar myScalar(mySubDict.lookup(\"myScalar\"));<\/pre>\n<p style=\"text-align: justify;\">At this point &#8220;myScalar&#8221; is accessible from inside the code of the boundary condition.<\/p>\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>OpenFOAM\u00ae offers a standard way to access user-specified constant data by means of dictionaries. However, dictionaries are by default read during the start-up phase of the main code. If a boundary condition requires to access the same information, the value can be looked up from the internal database used by OpenFOAM to store objects. The procedure is quite simple, and I show an example below, in a general case. Let&#8217;s assume our solver uses the &#8220;transportProperties&#8221; dictionary, which contains a subdictionary, called &#8220;mySubDict&#8221;. This sub-dictionary contains a dimensioned scalar, named &#8220;myScalar&#8221;. In the BC, you can recover &#8220;myScalar&#8221; as follows: \/\/ Extract the dictionary from the database const dictionary&amp; transportProperties = db().lookupObject&lt;IOdictionary&gt; ( &#8220;transportProperties&#8221; ); \/\/ Exctract subdictionary from the main dictionary dictionary mySubDict ( transportProperties.subDict(&#8220;mySubDict&#8221;) ); \/\/ Extracting scalar value dimensionedScalar myScalar(mySubDict.lookup(&#8220;myScalar&#8221;)); At this point &#8220;myScalar&#8221; is accessible from inside the code of the boundary condition. 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.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13],"tags":[],"class_list":["post-947","post","type-post","status-publish","format-standard","hentry","category-general"],"_links":{"self":[{"href":"https:\/\/www.albertopassalacqua.com\/index.php?rest_route=\/wp\/v2\/posts\/947","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=947"}],"version-history":[{"count":6,"href":"https:\/\/www.albertopassalacqua.com\/index.php?rest_route=\/wp\/v2\/posts\/947\/revisions"}],"predecessor-version":[{"id":953,"href":"https:\/\/www.albertopassalacqua.com\/index.php?rest_route=\/wp\/v2\/posts\/947\/revisions\/953"}],"wp:attachment":[{"href":"https:\/\/www.albertopassalacqua.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=947"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.albertopassalacqua.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=947"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.albertopassalacqua.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=947"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}