su_junwei 发表于 2009-6-8 00:00:08

[转载]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-roscillatingFixedValuetdbcFixedValue

//go into your new boundary condition dir
cdtdbcFixedValue                        

//rename the original files
mvoscillatingFixedValueFvPatchField.C   tdbcFixedValueFvPatchField.C
mvoscillatingFixedValueFvPatchField.H   tdbcFixedValueFvPatchField.H
mvoscillatingFixedValueFvPatchFields.CtdbcFixedValueFvPatchFields.C
mvoscillatingFixedValueFvPatchFields.HtdbcFixedValueFvPatchFields.H
mvoscillatingFixedValueFvPatchFieldsFwd.HtdbcFixedValueFvPatchFieldsFwd.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;    //get the face center of face i; x=xyz, y=xyz, z=xyz.
patchField=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.

转自OpenFOAM研究:http://blog.sina.com.cn/openfoamresearch

[ 本帖最后由 su_junwei 于 2009-6-8 00:05 编辑 ]

OpenFOAM 发表于 2009-6-11 21:32:38

难道你让他到cfluid看中文?哈哈
页: [1]
查看完整版本: [转载]OpenFOAM如何定义与时间有关的边界条件