OpenFOAM中有个setFields函数能够设置简单的初始场,其实,OpenFOAM的插件swak4foam中funkySetFields能够设置更复杂的初始条件。
funkySetFields的安装
根据不同的OpenFOAM版本,在这个网站选择安装.
- 以OpenFOAM 3.0.1为例:
- 新建一个安装文件夹
mkdir -p $FOAM_RUN
cd "$HOME/OpenFOAM/$USER-$WM_PROJECT_VERSION"
- 用svn安装:
svn checkout svn://svn.code.sf.net/p/openfoam-extend/svn/trunk/Breeder_2.0/libraries/swak4Foam/ swak4Foam
当然也可以试试网站中的另两种方法。
swak4foam包含下列文件或文件夹:
├── COPYING
├── debian
├── distroPatches
├── Documentation
├── Doxyfile
├── Examples
├── gtags.conf
├── Libraries
├── maintainanceScripts
├── Makefile
├── misc
├── README
├── README.md
├── releases
├── releaseTesting
├── swakConfiguration.automatic
├── swakConfiguration.centos6
├── swakConfiguration.debian
├── swakConfiguration.example
├── theFiles.sh
└── Utilities
编译
在swak4foam中输入以下命令:
./Allwmake
显示如下
This is a clean install
No file 'swakConfiguration'. Python etc won't work. See README for details
Try 'ln -s swakConfiguration.automatic swakConfiguration' for automatic configuration. BEWARE: this does not work on some systems
Checking swak4Foam-version and generating file
Swak version is 0.4.1
No 'bison' found. This is absolutely essential for swak4Foam. Can't go on
Every Linux has a binary package that installs bison (http://www.gnu.org/software/bison/). Install it. Then go on
As an alternative you can install a local copy of bison by running ./maintainanceScripts/compileRequirements.sh from the installation directory
BTW: it was listed as a requirement in the README. You read that, didn't you?
Requirements for Library not satisfied. I see no sense in going on
Check the README before you go on to ask. And search: Most likely your problem occured to 5 other people before and has been solved on the MessageBoard
- 根据cfd-online上的回答:
How to install swak4Foam in OF 2.3?
swak4foam >>>> INSTALLATION PROBLEM
下载文件
在swak4foam路径下输入:
maintainanceScripts/compileRequirements.sh
然后编译:
./Allwmake
终端中输入funkySetFields
显示如下,说明安装成功。
llp@ubuntu:~/OpenFOAM/llp-3.0.1/swak4Foam$ funkySetFields
/*---------------------------------------------------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: 3.0.1 |
| \\ / A nd | Web: www.OpenFOAM.org |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
Build : 3.0.1-119cac7e8750
Exec : funkySetFields
Date : Dec 15 2017
Time : 00:52:30
Host : "ubuntu"
PID : 40573
Case : /home/llp/OpenFOAM/llp-3.0.1/swak4Foam
nProcs : 1
sigFpe : Enabling floating point exception trapping (FOAM_SIGFPE).
fileModificationChecking : Monitoring run-time modified files using timeStampMaster
allowSystemOperations : Allowing user-supplied system call operations
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
swakVersion: 0.4.1 (Release date: 2017-05-31)
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
--> FOAM FATAL ERROR:
funkySetFields: time/latestTime option is required
From function main()
in file funkySetFields.C at line 759.
FOAM exiting
使用
- 1、常用关键字
field //用来指定要修改的场
expression_r //用来指定表达式
condition //用来指定上述表达式应当满足的条件
keepPatches //用来说明是否保持原来边界条件,最好加上,不加的话,funkySetField会给所有边界为0梯度
create //用来说明是否是新建场
valuePatches //用来指定那些定值边界由临近内部节点值给定
dimension //用来指定新建立场的单位
time //用来指定funkySetField所指定的时间点
应当指出,上述关键字可以直接在控制台上输,也可以写在名字为funkySetFieldsDict(类似于setFieldsDict)中。
- 2、使用方法网址1网址2
方法一 直接在控制台输入
基本命令行用法
直接进入你要初始话的case中,输入类似于下面的命令。如上面的setField也可以通过下面的funkySetFields命令来实现
funkySetFields -case damBreak -time 0 -field alpha.water -expression 1 -condition "pos().x <= 0.1461 && pos().y <= 0.292"
or:
funkySetFields -case damBreak -time 0 -field alpha.water -expression " pos().x <= 0.1461 && pos().y <= 0.292 ? 1 : 0"
注意比较长的式子用单引号或者双引号隔开。 上述关键字没有次序要求。
类似于setFields:
1 defaultFieldValues
2 (
3 volScalarFieldValue alpha.water 0
4 );
5
6 regions
7 (
8 boxToCell
9 {
10 box (0 0 -1) (0.1461 0.292 1);
11 fieldValues
12 (
13 volScalarFieldValue alpha.water 1
14 );
15 }
16 );
高级命令行用法
方法二 使用funkySetFieldsDict
字典
- C++基本操作符
+,-,*,/,%, <,>,<=,>=,!=,==, &&,||,? :
- OpenFOAM定义的向量操作符
&,^
- 圆周率常量
pi
- 标量函数
pow,log,exp,sqr,sqrt,sin,cos,tan
- OpenFOAM中的一些函数(部分)
mag:求模
grad :求标量梯度
curl :求向量旋度
snGrad:表面法向剃度
div :向量场散度
laplaction :求一个场的laplacian项目
min,max :标量场的最值
average,integrate,sum,
reconstruct重建一个面场(产生体积场)
pos :网格中心位置矢量
fpos :面中心位置矢量
face :表面法向量场
area:表面面积场
vol :网格单元体积场
deltaT :时间步长
time :当前时间
- 示例1
expressions
(
initLower
{
field lowerPatch;
create true;
expression "1";
condition "pos().y<0";
valuePatches ( zminus );
dimension [0 1 -1 0 0];
}
clearLower
{
field lowerPatch;
expression "0";
keepPatches true; //是否保持以前边界
}
setTube
{
field tubeField;
create true;
expression "pos().z";
condition "sqrt(pow(pos().x,2)+pow(pos().y,2))<0.0001";
}
);
- 示例2:
expressions
(
circleVel
{
field U;
expression "(grad(dist())^vector(0,0,-1))*mag(pos()-vector(0.05,0.05,0))/0.05";
}
pressure1
{
field p;
expression "10.*(0.1-pos().y)";
}
pressure2
{
field p;
expression "p+U&U";
condition "pos().x > (max(pos().x)-min(pos().x))/2";
}
);
- 初始化水箱中z方向上的压力梯度。水箱水表面高度2.1米,底部z坐标-3.4米,总共深5.5米。
expressions
(
pressureWater
{
field p; //field to initialise
expression "9810.*(2.1-pos().z)+100000";
condition "(pos().z<2.1) && (pos().z>=-3.4)"; //ranging from 2.1 meter to -3.4 meter
keepPatches 1; //keep the boundary conditions that were set before
}
);
- 海面上竖直方向上风速的对数廓线分布:
expressions
(
WindSpeed
{
field U; //field to initialise
expression "(vector(0,Ustar,0)/0.41)log(pos().z/z0_)";
condition "(pos().z<500) && (pos().z>=0)"; //ranging from 0 meter to 500 meter
keepPatches 1; //keep the boundary conditions that were set before
}
);
命令:funkySetFields -time 0