OpenFOAM中funkySetFields的安裝與使用

OpenFOAM中有個setFields函數(shù)能夠設置簡單的初始場,其實,OpenFOAM的插件swak4foam中funkySetFields能夠設置更復雜的初始條件。

funkySetFields的安裝

根據(jù)不同的OpenFOAM版本,在這個網(wǎng)站選擇安裝.

  • 以OpenFOAM 3.0.1為例:
  1. 新建一個安裝文件夾
mkdir -p $FOAM_RUN
cd "$HOME/OpenFOAM/$USER-$WM_PROJECT_VERSION"
  1. 用svn安裝:
svn checkout svn://svn.code.sf.net/p/openfoam-extend/svn/trunk/Breeder_2.0/libraries/swak4Foam/ swak4Foam

當然也可以試試網(wǎng)站中的另兩種方法。

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
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 //用來指定那些定值邊界由臨近內部節(jié)點值給定
dimension //用來指定新建立場的單位 
time //用來指定funkySetField所指定的時間點 

應當指出,上述關鍵字可以直接在控制臺上輸,也可以寫在名字為funkySetFieldsDict(類似于setFieldsDict)中。

  • 2、使用方法網(wǎng)址1網(wǎng)址2
    方法一 直接在控制臺輸入
    基本命令行用法
    直接進入你要初始話的case中,輸入類似于下面的命令。如上面的setField也可以通過下面的funkySetFields命令來實現(xiàn)
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字典

  1. C++基本操作符

+,-,*,/,%, <,>,<=,>=,!=,==, &&,||,? :

  1. OpenFOAM定義的向量操作符

&,^

  1. 圓周率常量

pi

  1. 標量函數(shù)

pow,log,exp,sqr,sqrt,sin,cos,tan

  1. OpenFOAM中的一些函數(shù)(部分)
mag:求模 
grad :求標量梯度 
curl :求向量旋度 
snGrad:表面法向剃度 
div :向量場散度 
laplaction :求一個場的laplacian項目 
min,max :標量場的最值 
average,integrate,sum,
reconstruct重建一個面場(產生體積場)
pos :網(wǎng)格中心位置矢量 
fpos :面中心位置矢量 
face :表面法向量場 
area:表面面積場 
vol :網(wǎng)格單元體積場 
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
    }
 );
  • 海面上豎直方向上風速的對數(shù)廓線分布:
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

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

友情鏈接更多精彩內容