加载中…
个人资料
苏军伟
苏军伟
  • 博客等级:
  • 博客积分:1021
  • 博客访问:187,607
  • 关注人气:249
天天美食
相关博文
精彩图文
谁看过这篇博文
加载中…
正文 字体大小:

OpenFOAM如何定义与时间有关的边界条件

(2009-06-07 23:45:33)
标签:

openfoam研究

教育

分类: OpenFOAM入门

组里一个师兄问我如何定义与时间有关的边界条件,我给他写了一下,顺便贴到blog上了。那个师兄是个日本人,只认英文。

In OpenFOAM, there are three basic patch boundary conditions

Dirichlet (first type) boundary condition

Neumann (second type) boundary condition

Mixed Dirichlet and Neumann

 

For time-dependent boundary condition, if the value on the boundary is time-dependent, this is Dirichlet boundary condition. If the gradient of the value on the boundary is time-dependent, it is a Neumann boundary condition.

 

In OpenFOAM, there is a boundary condition named oscillatingFixedvalue boundary condition (located in src\finiteVolume\fields\fvPatchFields\derived\oscillatingFixedValue), the boundary values change with time according to

S=S0(1+A0sin(2πωt))                                      (1)

S is the variable you apply the boundary to. If you want to implement another boundary similar but with different expression, just doing the following steps

(1) Give your new boundary condition a nice name, tdbc(time-dependent boundary condition) for instance. Do the following operations

 

//make a copy for oscillatingFixedvalue

cp  -r  oscillatingFixedValue  tdbcFixedValue

 

//go into your new boundary condition dir

cd  tdbcFixedValue                         

 

//rename the original files

mv  oscillatingFixedValueFvPatchField.C   tdbcFixedValueFvPatchField.C

mv  oscillatingFixedValueFvPatchField.H   tdbcFixedValueFvPatchField.H

mv  oscillatingFixedValueFvPatchFields.C  tdbcFixedValueFvPatchFields.C

mv  oscillatingFixedValueFvPatchFields.H  tdbcFixedValueFvPatchFields.H

mv  oscillatingFixedValueFvPatchFieldsFwd.H  tdbcFixedValueFvPatchFieldsFwd.H

 

//replace all the “oscillating” with “tdbc” in all the files in this dir. I usually use “kate” editpad in OpenSUSE to replace all the words

 

(2) Add the new boundary condition to the compile environment

Go to the dir OpenFOAM-1.5\src\finiteVolume\Make using cd

Add the following code to the “files”: line 108 for instance

$(derivedFvPatchFields)/tdbc FixedValue/tdbcFixedValueFvPatchFields.C

 

(3) Alter the functions

All the function definition is located in the file tdbcFixedValueFvPatchField.C:179 (in function updateCoeffs)

patchField =refValue_*currentScale()

refValue_ is S0 in equation (1), its type (scalar or vector) is determined by the field type this boundary condition applied to. For instance, this boundary is used for pressure, refValue_ should be scalar. If it is used for velocity, refValue_ should be vector. Its definition is defined through class template parameter “type”.

currentScale() is just a function of this class, it is defined at line 38 in this file.

Just write a function similar to currentScalar(), and give its return value to patchField, all the things are OK.

Note:that patchField is a field. If your expression is also dependent on the location, you have to do a loop like this

 

const fvPatch & fvp=this->patch(); //get the geometry of the boundary

const vectorField &fc=fvp.Cf();   //get face center on the boundary.

scalar t=this->db().time().value();  //get the current simulation time.

forAll(patchField,i)

{

   point xyz=fc[i];    //get the face center of face i; x=xyz[0], y=xyz[1], z=xyz[2].

patchField[i]=f(xyz,t); //f is the function of your equation

}

The parameter can be added in a similar way to refValue_ or frequence_

 

(4) Recompile the code

Go to \OpenFOAM-1.5\src\finiteVolume\ using the following line to compile

wmake libso

 

(5) use the new boundary

 If all the things were done correctly, the new boundary condition can be used like the boundary condition in OpenFOAM. Your new boundary condition is “tdbcFixedValue” . you can use like this

inlet   //boundary name        

    {

        type            tdbcFixedValue;

        para1           value;

        para2           value;

}

Para1 and para2 are like parameters in your new boundary condition.

 

Good Luck.

 

If there are something not clearly written or encounter some problems in the process of implementation, please don’t hesitate to contact me.

阅读 评论 收藏 转载 喜欢 打印举报
已投稿到:
  • 评论加载中,请稍候...
发评论

       

    验证码: 请点击后输入验证码 收听验证码

    发评论

    以上网友发言只代表其个人观点,不代表新浪网的观点或立场。

      

    新浪BLOG意见反馈留言板 不良信息反馈 电话:4006900000 提示音后按1键(按当地市话标准计费) 欢迎批评指正

    新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 会员注册 | 产品答疑

    新浪公司 版权所有