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 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
//go into your new boundary condition dir
//rename the original files
//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
(3) Alter the functions
All the function definition is located in the file
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();
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
(5) use the new boundary
Para1 and para2 are like parameters in your new boundary condition.
If there are something not clearly written or encounter some problems in the process of implementation, please don’t hesitate to contact me.