{"id":69,"date":"2008-08-15T11:07:48","date_gmt":"2008-08-15T09:07:48","guid":{"rendered":"http:\/\/142.93.241.207\/?p=69"},"modified":"2009-11-26T07:21:34","modified_gmt":"2009-11-26T05:21:34","slug":"defining-unsteady-boundary-conditions-in-openfoam","status":"publish","type":"post","link":"https:\/\/www.albertopassalacqua.com\/?p=69","title":{"rendered":"Unsteady boundary conditions in openFOAM"},"content":{"rendered":"<p style=\"text-align: justify;\">I recently had to help a friend setting up a case in <a href=\"http:\/\/www.opencfd.co.uk\/openfoam\/\" target=\"_blank\">OpenFOAM<\/a>, where a ramp boundary condition for the velocity was required. Apparently OpenFOAM doesn&#8217;t offer this boudary condition, or at least it might seem so at a first impression.<\/p>\n<p style=\"text-align: justify;\">Actually, OpenFOAM offers a very general way to specify unsteady boundary conditions called timeVaryingFixedValue, which can read a data set from a text file, interpolate them with respect to time and use them to generate the unsteady boundary condition.<\/p>\n<p style=\"text-align: justify;\">I will show how to use this boundary condition with a simple example of a ramp for a velocity boundary condition. We want the velocity to ramp from the value <em>U<sub>1<\/sub> = (0, 1, 0)<\/em> to the value <em>U<sub>2<\/sub> = (0, 3, 0)<\/em> in the time interval between <em>t<sub>1<\/sub> = 0<\/em> and <em>t<sub>2<\/sub> = 5s<\/em>. The velocity stays constant and equal to <em>U<sub>2<\/sub><\/em> for <em>t &gt; t<sub>2<\/sub><\/em>.<\/p>\n<p style=\"text-align: justify;\">The ramp is simply defined by the extrema: the interpolation routine will automatically provide the correct values for the times contained inside the interval specified above. So, we need to create a text file with the following format:<\/p>\n<pre style=\"text-align: justify; padding-left: 30px;\">(\r\n\u00a0(t_0 value_0)\r\n\u00a0...\r\n\u00a0(t_n value_n)\r\n)<\/pre>\n<p style=\"text-align: justify;\">In our specific case, we create a file called ramp containing the following lines:<\/p>\n<pre style=\"text-align: justify; padding-left: 30px;\">(\r\n\u00a0(0.0 (0 1 0))\r\n\u00a0(5.0 (0 3 0))\r\n)<\/pre>\n<p style=\"text-align: justify;\">This file must be saved in the main directory of the simulation case, containing the 0, constant and system directories.<\/p>\n<p style=\"text-align: justify;\">The boundary condition can be then specified in the velocity dictionary in the 0 directory as follows:<\/p>\n<pre style=\"text-align: justify; padding-left: 30px;\">rampInlet\u00a0\u00a0\u00a0\u00a0\u00a0\r\n{\r\n\u00a0 type\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 timeVaryingUniformFixedValue;\r\n\u00a0 fileName\u00a0\u00a0\u00a0\u00a0 \"ramp\";\r\n\u00a0 outOfBounds\u00a0 clamp;\r\n}<\/pre>\n<p style=\"text-align: justify;\">It is worth to pay attention to the option<\/p>\n<pre style=\"text-align: justify; padding-left: 30px;\"> outOfBounds\u00a0 clamp;<\/pre>\n<p style=\"text-align: justify;\">which specifies that for all the values of <em>t<\/em> outside the interval provided by the data, the values of the dependent variable are clamped to the last available value. In our case this means that the condition <em>U = U<sub>2<\/sub><\/em> for <em>t &gt; t<sub>2<\/sub><\/em> will be imposed.<\/p>\n<p style=\"text-align: justify;\">The clamp option is also useful if we want to specify a ramp that begins for <em>t &gt; 0<\/em> or to change the final value of the dependent variable when the ramp is completed. Let&#8217;s consider the previous example again. Now we want the ramp to start at <em>t = 2s<\/em> and the velocity to go to zero at the end of the ramp. This can be simply accomplished by adding two lines to the dictionary, as follows:<\/p>\n<pre style=\"text-align: justify; padding-left: 30px;\">(\r\n (1.99999 (0 0 0))\r\n\u00a0(2.0 (0 1 0))\r\n\u00a0(5.0 (0 3 0))\r\n (5.00001 (0 0 0))\r\n)<\/pre>\n<p style=\"text-align: justify;\">The timeVaryingFixedValue boundary condition is of course suitable for all kinds of fields. For a scalar, the dictionary will contain couples of data <em>(t, value)<\/em>, while for tensors each line will have a 9 components tuple.<\/p>\n<p style=\"text-align: justify;\"><strong>Note:<\/strong> This procedure was tested on OpenFOAM 1.5.<\/p>\n<p style=\"text-align: justify;\">Enjoy \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I recently had to help a friend setting up a case in OpenFOAM, where a ramp boundary condition for the velocity was required. Apparently OpenFOAM doesn&#8217;t offer this boudary condition, or at least it might seem so at a first impression. Actually, OpenFOAM offers a very general way to specify unsteady boundary conditions called timeVaryingFixedValue, which can read a data set from a text file, interpolate them with respect to time and use them to generate the unsteady boundary condition. I will show how to use this boundary condition with a simple example of a ramp for a velocity boundary condition. We want the velocity to ramp from the value U1 = (0, 1, 0) to the value U2 = (0, 3, 0) in the time interval between t1 = 0 and t2 = 5s. The velocity stays constant and equal to U2 for t &gt; t2. The ramp is simply defined by the extrema: the interpolation routine will automatically provide the correct values for the times contained inside the interval specified above. So, we need to create a text file with the following format: ( \u00a0(t_0 value_0) \u00a0&#8230; \u00a0(t_n value_n) ) In our specific case, we create a file called ramp containing the following lines: ( \u00a0(0.0 (0 1 0)) \u00a0(5.0 (0 3 0)) ) This file must be saved in the main directory of the simulation case, containing the 0, constant and system directories. The boundary condition can be then specified in the velocity dictionary in the 0 directory as follows: rampInlet\u00a0\u00a0\u00a0\u00a0\u00a0 { \u00a0 type\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 timeVaryingUniformFixedValue; \u00a0 fileName\u00a0\u00a0\u00a0\u00a0 &#8220;ramp&#8221;; \u00a0 outOfBounds\u00a0 clamp; } It is worth to pay attention to the option outOfBounds\u00a0 clamp; which specifies that for all the values of t outside the interval provided by the data, the values of the dependent variable are clamped to the last available value. In our case this means that the condition U = U2 for t &gt; t2 will be imposed. The clamp option is also useful if we want to specify a ramp that begins for t &gt; 0 or to change the final value of the dependent variable when the ramp is completed. Let&#8217;s consider the previous example again. Now we want the ramp to start at t = 2s and the velocity to go to zero at the end of the ramp. This can be simply accomplished by adding two lines to the dictionary, as follows: ( (1.99999 (0 0 0)) \u00a0(2.0 (0 1 0)) \u00a0(5.0 (0 3 0)) (5.00001 (0 0 0)) ) The timeVaryingFixedValue boundary condition is of course suitable for all kinds of fields. For a scalar, the dictionary will contain couples of data (t, value), while for tensors each line will have a 9 components tuple. Note: This procedure was tested on OpenFOAM 1.5. Enjoy \ud83d\ude42<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[117,47,46],"class_list":["post-69","post","type-post","status-publish","format-standard","hentry","category-openfoam","tag-openfoam","tag-ramp","tag-unsteady-boundary-condition"],"_links":{"self":[{"href":"https:\/\/www.albertopassalacqua.com\/index.php?rest_route=\/wp\/v2\/posts\/69","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=69"}],"version-history":[{"count":16,"href":"https:\/\/www.albertopassalacqua.com\/index.php?rest_route=\/wp\/v2\/posts\/69\/revisions"}],"predecessor-version":[{"id":525,"href":"https:\/\/www.albertopassalacqua.com\/index.php?rest_route=\/wp\/v2\/posts\/69\/revisions\/525"}],"wp:attachment":[{"href":"https:\/\/www.albertopassalacqua.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=69"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.albertopassalacqua.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=69"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.albertopassalacqua.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=69"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}