OpenFOAM은 일반적인 해석프로그램과는 매우 다른 형태를 가지고 있다. 일단, OpenFOAM을 실행하려고 하면 PATH가 생성되어 있어야 한다.
Ubuntu System의 현재 PATH를 확인하기 위한 방법은 아래와 같으며, OpenFOAM설치시 PATH가 잡혀야 Project Directory(OpenFOAM 커뮤니티에서는 Case directory라고 이야기 한다)에서 실행이 가능해 진다.
~/OpenFOAM/OpenFOAM-5.x/tutorials/incompressible/icoFoam/cavity/cavity$ echo $PATH
/home/hp-z8/CFDEM/hp-z8-PUBLIC-5.x/platforms/linux64GccDPInt32Opt/bin:
/home/hp-z8/CFDEM/CFDEMcoupling-PUBLIC-5.x/platforms/linux64GccDPInt32Opt/bin:
/home/hp-z8/OpenFOAM/ThirdParty-5.x/platforms/linux64Gcc/gperftools-svn/bin:
/home/hp-z8/OpenFOAM/hp-z8-5.x/platforms/linux64GccDPInt32Opt/bin:
/home/hp-z8/OpenFOAM/site/5.x/platforms/linux64GccDPInt32Opt/bin:
/home/hp-z8/OpenFOAM/OpenFOAM-5.x/platforms/linux64GccDPInt32Opt/bin:
/home/hp-z8/OpenFOAM/OpenFOAM-5.x/bin:
/home/hp-z8/OpenFOAM/OpenFOAM-5.x/wmake:
OpenFOAM Project directory는 기본적으로 아래와 같은 구조를 가진다.
~/OpenFOAM/OpenFOAM-5.x/tutorials/incompressible/icoFoam/cavity/cavity$ ls -al
drwxrwxr-x 5 hp-z8 hp-z8 4096 8월 28 23:57 .
drwxrwxr-x 5 hp-z8 hp-z8 4096 8월 28 23:57 ..
drwxrwxr-x 2 hp-z8 hp-z8 4096 8월 28 23:57 0
drwxrwxr-x 3 hp-z8 hp-z8 4096 12월 24 23:24 constant
drwxrwxr-x 2 hp-z8 hp-z8 4096 8월 28 23:57 system
cavity라는 project아래 다음과 같은 디렉토리를 가지게 되는데, 각각의 디렉토리는 다음의 정보를 포함한다.
1) "0"
- Initial value problem을 풀기위한 initial condition
2) "constant"
- 유체의 properties, Mesh information
3) "system"
- 사용될 수치해석기법(solver 정보) 및 계산조건
먼저, system directory로 이동해 보면 다음과 같은 파일리스트가 나타나는데, blockMeshDict이 mesh구성을 위한 설정값을 저장하고 있는 파일이다.
~/OpenFOAM/OpenFOAM-5.x/tutorials/incompressible/icoFoam/cavity/cavity/system$ ls -al
drwxrwxr-x 2 hp-z8 hp-z8 4096 8월 28 23:57 .
drwxrwxr-x 5 hp-z8 hp-z8 4096 8월 28 23:57 ..
-rw-rw-r-- 1 hp-z8 hp-z8 1476 8월 28 23:57 blockMeshDict
-rw-rw-r-- 1 hp-z8 hp-z8 1214 8월 28 23:57 controlDict
-rw-rw-r-- 1 hp-z8 hp-z8 1236 8월 28 23:57 fvSchemes
-rw-rw-r-- 1 hp-z8 hp-z8 1340 8월 28 23:57 fvSolution
1. Mesh의 구성
- project 디렉토리에서 blockMesh를 실행하면 된다.
~/OpenFOAM/OpenFOAM-5.x/tutorials/incompressible/icoFoam/cavity/cavity$ ls
0 constant system
~/OpenFOAM/OpenFOAM-5.x/tutorials/incompressible/icoFoam/cavity/cavity$ blockMesh
/*---------------------------------------------------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: 5.x |
| \\ / A nd | Web: www.OpenFOAM.org |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
Build : 5.x-538044ac05c4
Exec : blockMesh
Date : Dec 24 2023
Time : 23:47:18
Host : "HP-Z8"
PID : 232029
I/O : uncollated
Case : /home/hp-z8/OpenFOAM/OpenFOAM-5.x/tutorials/incompressible/icoFoam/cavity/cavity
nProcs : 1
sigFpe : Enabling floating point exception trapping (FOAM_SIGFPE).
fileModificationChecking : Monitoring run-time modified files using timeStampMaster (fileModificationSkew 10)
allowSystemOperations : Allowing user-supplied system call operations
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Create time
Deleting polyMesh directory
"/home/hp-z8/OpenFOAM/OpenFOAM-5.x/tutorials/incompressible/icoFoam/cavity/cavity/constant/polyMesh"
Creating block mesh from
"/home/hp-z8/OpenFOAM/OpenFOAM-5.x/tutorials/incompressible/icoFoam/cavity/cavity/system/blockMeshDict"
Creating block edges
No non-planar block faces defined
Creating topology blocks
Creating topology patches
Creating block mesh topology
Check topology
Basic statistics
Number of internal faces : 0
Number of boundary faces : 6
Number of defined boundary faces : 6
Number of undefined boundary faces : 0
Checking patch -> block consistency
Creating block offsets
Creating merge list .
Creating polyMesh from blockMesh
Creating patches
Creating cells
Creating points with scale 0.1
Block 0 cell size :
i : 0.005 .. 0.005
j : 0.005 .. 0.005
k : 0.01 .. 0.01
Writing polyMesh
----------------
Mesh Information
----------------
boundingBox: (0 0 0) (0.1 0.1 0.01)
nPoints: 882
nCells: 400
nFaces: 1640
nInternalFaces: 760
----------------
Patches
----------------
patch 0 (start: 760 size: 20) name: movingWall
patch 1 (start: 780 size: 60) name: fixedWalls
patch 2 (start: 840 size: 800) name: frontAndBack
End
- constant directory아래 polyMesh디렉토리가 생성되었다. 만들어진 파일은 boundary, faces, neighbour, owner, points이다
~/OpenFOAM/OpenFOAM-5.x/tutorials/incompressible/icoFoam/cavity/cavity/constant$ ls -al
drwxrwxr-x 3 hp-z8 hp-z8 4096 12월 24 23:47 .
drwxrwxr-x 5 hp-z8 hp-z8 4096 8월 28 23:57 ..
drwxrwxr-x 2 hp-z8 hp-z8 4096 12월 24 23:47 polyMesh
-rw-rw-r-- 1 hp-z8 hp-z8 912 8월 28 23:57 transportProperties
~/OpenFOAM/OpenFOAM-5.x/tutorials/incompressible/icoFoam/cavity/cavity/constant/polyMesh$ ls -al
drwxrwxr-x 2 hp-z8 hp-z8 4096 12월 24 23:47 .
drwxrwxr-x 3 hp-z8 hp-z8 4096 12월 24 23:47 ..
-rw-rw-r-- 1 hp-z8 hp-z8 1328 12월 24 23:47 boundary
-rw-rw-r-- 1 hp-z8 hp-z8 31276 12월 24 23:47 faces
-rw-rw-r-- 1 hp-z8 hp-z8 3813 12월 24 23:47 neighbour
-rw-rw-r-- 1 hp-z8 hp-z8 7038 12월 24 23:47 owner
-rw-rw-r-- 1 hp-z8 hp-z8 15054 12월 24 23:47 points
2. Intial value의 설정
- "0" directory에 다음과 같은 파일이 설정되어야 한다. "p"는 pressure정보를 담고 있으며, "U"는 velocity 정보를 포함한다
~/OpenFOAM/OpenFOAM-5.x/tutorials/incompressible/icoFoam/cavity/cavity/0$ ls -al
drwxrwxr-x 2 hp-z8 hp-z8 4096 8월 28 23:57 .
drwxrwxr-x 5 hp-z8 hp-z8 4096 8월 28 23:57 ..
-rw-rw-r-- 1 hp-z8 hp-z8 1103 8월 28 23:57 p
-rw-rw-r-- 1 hp-z8 hp-z8 1142 8월 28 23:57 U
3. Fluid property 설정 파일
- Fluid property 설정파일은 아래 위치에 있는 transportProperties 파일에 정보가 담겨 있다
~/OpenFOAM/OpenFOAM-5.x/tutorials/incompressible/icoFoam/cavity/cavity/constant$ ls -al
drwxrwxr-x 3 hp-z8 hp-z8 4096 12월 24 23:47 .
drwxrwxr-x 5 hp-z8 hp-z8 4096 8월 28 23:57 ..
drwxrwxr-x 2 hp-z8 hp-z8 4096 12월 24 23:47 polyMesh
-rw-rw-r-- 1 hp-z8 hp-z8 912 8월 28 23:57 transportProperties
4. Control
- 해석에 관련된 파일은 case directory안(controlDict)에 들어가 있다.
~/OpenFOAM/OpenFOAM-5.x/tutorials/incompressible/icoFoam/cavity/cavity/system$ ls -al
drwxrwxr-x 2 hp-z8 hp-z8 4096 8월 28 23:57 .
drwxrwxr-x 10 hp-z8 hp-z8 4096 12월 25 01:45 ..
-rw-rw-r-- 1 hp-z8 hp-z8 1476 8월 28 23:57 blockMeshDict
-rw-rw-r-- 1 hp-z8 hp-z8 1214 8월 28 23:57 controlDict
-rw-rw-r-- 1 hp-z8 hp-z8 1236 8월 28 23:57 fvSchemes
-rw-rw-r-- 1 hp-z8 hp-z8 1340 8월 28 23:57 fvSolution
5. Solver setting
- OpenFOAM을 이용한 CFD해석을 위해서는 수치해석을 위한 Solver를 지정하여야 하는데, 문제 및 해석조건에 따라 여러 Solver를 지원하고 있다. 본 포스팅에서 예를 들고 있는 cavity문제는 icoFoam solver를 사용하며, Solver의 지정은 case directory안(controlDict)에 아래와 같이 들어가 있다.
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: 5 |
| \\ / A nd | Web: www.OpenFOAM.org |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
location "system";
object controlDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
application icoFoam;
startFrom startTime;
startTime 0;
stopAt endTime;
endTime 0.5;
deltaT 0.005;
writeControl timeStep;
writeInterval 20;
purgeWrite 0;
writeFormat ascii;
writePrecision 6;
writeCompression off;
timeFormat general;
timePrecision 6;
runTimeModifiable true;
// ************************************************************************* //
6. Run
- OpenFOAM의 실행은 case directory에서 command line에 Solver를 지정, 타이핑을 하면 실행이 된다.
~/OpenFOAM/OpenFOAM-5.x/tutorials/incompressible/icoFoam/cavity/cavity$ icoFoam
/*---------------------------------------------------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: 5.x |
| \\ / A nd | Web: www.OpenFOAM.org |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
Build : 5.x-538044ac05c4
Exec : icoFoam
Date : Dec 26 2023
Time : 12:44:53
Host : "HP-Z8"
PID : 241966
I/O : uncollated
Case : /home/hp-z8/OpenFOAM/OpenFOAM-5.x/tutorials/incompressible/icoFoam/cavity/cavity
nProcs : 1
sigFpe : Enabling floating point exception trapping (FOAM_SIGFPE).
fileModificationChecking : Monitoring run-time modified files using timeStampMaster (fileModificationSkew 10)
allowSystemOperations : Allowing user-supplied system call operations
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Create time
Create mesh for time = 0
PISO: Operating solver in PISO mode
Reading transportProperties
Reading field p
Reading field U
Reading/calculating face flux field phi
Starting time loop
Time = 0.005
Courant Number mean: 0 max: 0
smoothSolver: Solving for Ux, Initial residual = 1, Final residual = 8.90511e-06, No Iterations 19
smoothSolver: Solving for Uy, Initial residual = 0, Final residual = 0, No Iterations 0
DICPCG: Solving for p, Initial residual = 1, Final residual = 0.0492854, No Iterations 12
time step continuity errors : sum local = 0.000466513, global = -1.79995e-19, cumulative = -1.79995e-19
DICPCG: Solving for p, Initial residual = 0.590864, Final residual = 2.65225e-07, No Iterations 35
time step continuity errors : sum local = 2.74685e-09, global = -2.6445e-19, cumulative = -4.44444e-19
ExecutionTime = 0 s ClockTime = 0 s
Time = 0.01
Courant Number mean: 0.0976825 max: 0.585607
smoothSolver: Solving for Ux, Initial residual = 0.160686, Final residual = 6.83031e-06, No Iterations 19
smoothSolver: Solving for Uy, Initial residual = 0.260828, Final residual = 9.65939e-06, No Iterations 18
DICPCG: Solving for p, Initial residual = 0.428925, Final residual = 0.0103739, No Iterations 22
time step continuity errors : sum local = 0.000110788, global = 3.77194e-19, cumulative = -6.72498e-20
DICPCG: Solving for p, Initial residual = 0.30209, Final residual = 5.26569e-07, No Iterations 33
time step continuity errors : sum local = 6.61987e-09, global = -2.74872e-19, cumulative = -3.42122e-19
ExecutionTime = 0 s ClockTime = 0 s
- controlDict파일에서 deltaT를 0.005초 단위로 지정하였기 때문에 해석은 0.005초 간격으로 해석을 실행하며, writeInterval이 20으로 지정되어 있으므로, 0.1초 간격으로 결과는 저장된다. 종료시간(endTime)은 0.5초이다.
- 해석결과는 case directory아래 저장되는 시간별로 디렉토리가 형성된다.

7. Post Processing
- OpenFOAM의 결과는 PARAVIEW를 통해 확인할 수 있다. 최초 OpenFOAM의 개발시 PARAVIEW 5.4 기반의 ParaFoam이라는 wrapper script를 사용하여 결과를 읽어 왔으나, PARAVIEW의 버전업을 따라갈 수 없는지 요즘은 이 방법이 추천되지 않는 듯 하다.
- 대신, PARAVIEW에서는 case directory에서 *.foam의 파일을 발견시(불러오면) case directory내의 파일구조를 자동으로 인식하여 불러올 수 있는 자체 기능을 제공한다.
- 하지만, OpenFOAM의 실행결과로 *.foam파일은 생성되지 않는다. 그래서 사용되는 방법이 *.foam파일을 임의로 case directory내에 생성하여 PARAVIEW에 인식시키는 방법을 사용한다. 이때 사용할 수 있는 Linux명령어는 touch이다.
~/OpenFOAM/OpenFOAM-5.x/tutorials/incompressible/icoFoam/cavity/cavity$ touch example.foam
~/OpenFOAM/OpenFOAM-5.x/tutorials/incompressible/icoFoam/cavity/cavity$ ls -al
drwxrwxr-x 10 hp-z8 hp-z8 4096 12월 26 12:58 .
drwxrwxr-x 5 hp-z8 hp-z8 4096 8월 28 23:57 ..
drwxrwxr-x 2 hp-z8 hp-z8 4096 8월 28 23:57 0
drwxrwxr-x 3 hp-z8 hp-z8 4096 12월 26 12:44 0.1
drwxrwxr-x 3 hp-z8 hp-z8 4096 12월 26 12:44 0.2
drwxrwxr-x 3 hp-z8 hp-z8 4096 12월 26 12:44 0.3
drwxrwxr-x 3 hp-z8 hp-z8 4096 12월 26 12:44 0.4
drwxrwxr-x 3 hp-z8 hp-z8 4096 12월 26 12:44 0.5
drwxrwxr-x 3 hp-z8 hp-z8 4096 12월 24 23:47 constant
-rw-rw-r-- 1 hp-z8 hp-z8 0 12월 26 12:58 example.foam
drwxrwxr-x 2 hp-z8 hp-z8 4096 8월 28 23:57 system
- 크기 0 byte인 "example.foam"파일이 생성되었다. 생성시 .foam파일의 이름은 중요치 않다. .foam의 파일만 존재하면 된다.
- PARAVIEW에서 불러 보면,

- Case directory내에 생성된 .foam파일을 선택하면 PARAVIEW가 자동으로 case directory내의 파일구조를 인식하여 해석결과를 불러들인다.

- 만약 mesh를 보고 싶으면, Properties - Representation - (Drop Menu : Wireframe)을 선택하면 된다.

'OpenFOAM' 카테고리의 다른 글
BlockMesh 생성하기 (1) | 2024.01.03 |
---|---|
Update-alternatives (Ubuntu Package Version 관리, GCC) (1) | 2023.08.14 |
GCC Version (0) | 2023.08.13 |
CFD-DEM (0) | 2023.08.12 |