openfoam-cfd について
OpenFOAM CFDユーザー向けのシミュレーションガイドです。有限体積法のケース設定、ソルバー、メッシュ生成、後処理を扱い、並列実行や境界条件、一般的な問題の対処法も説明します。
主な機能
- 01ケース構成と辞書の設定
- 02流動・熱伝達・混相流ソルバー
- 03境界条件と乱流パラメーター
- 04blockMeshとsnappyHexMeshによるメッシュ生成
- 05ParaViewでの後処理と並列実行
活用シーン
- 01定常または過渡流れのケース設定
- 02入口・出口・乱流の境界条件設定
- 03複雑形状のメッシュ生成
- 04並列シミュレーションの実行と結果確認
インストール
コマンドをコピーしてターミナルで実行します。
npx skills add https:/ / github.com/ soljourner/ claude-engineering-skills --skill openfoam-cfdインストール後、Claude Code で/openfoam-cfdを入力して読み込まれたか確認します。
同梱ファイル
SKILL.md と一緒にインストールされる参考資料やスクリプト。
examples/boundary-conditions-examples.mdREADME.mdexamples/pipe-flow/README.mdexamples/pipe-flow/0/epsilonknutpUexamples/pipe-flow/constant/transportPropertiesturbulencePropertiesexamples/pipe-flow/system/blockMeshDictcontrolDictfvSchemesfvSolutionexamples/pump-impeller/README.mdexamples/pump-impeller/0/epsilonknutomegapUexamples/pump-impeller/constant/dynamicMeshDicttransportPropertiesturbulencePropertiesexamples/pump-impeller/system/blockMeshDictcontrolDictfvSchemesfvSolutionexamples/scripts/calculate_turbulence.pygenerate_case.py詳細
OpenFOAM CFD 統合
概要
OpenFOAM(Open Field Operation and Manipulation)は、複雑な流体力学の問題を解くための包括的なツール群を提供する、無料のオープンソース CFD ソフトウェアパッケージです。有限体積法を使用して、流体の流れ、熱伝達、乱流、化学反応を表す偏微分方程式を離散化して解きます。
主な機能
- オープンソース:GPLv3 のライセンスで提供され、完全に無料で使用および変更できます
- 幅広い物理現象に対応:非圧縮性/圧縮性流れ、多相流、燃焼、熱伝達を扱います
- 並列計算:MPI ベースの並列処理を標準でサポートします
- カスタマイズ可能:C++ で記述されており、独自の物理モデルやソルバーに合わせて高い拡張性を備えています
- 業界標準:研究および商用アプリケーションで、学術機関や産業界に広く使用されています
アーキテクチャ
OpenFOAM はケースベースの構成を採用しており、各シミュレーションは次の要素を含む独立したディレクトリです:
- 初期条件と境界条件
- 物性値
- 数値スキーム
- ソルバー設定
- メッシュデータ
インストール
Ubuntu/Debian へのインストール
オプション 1:Ubuntu 公式リポジトリ(最新版)
# Add OpenFOAM repository
sudo sh -c "wget -O - https://dl.openfoam.org/gpg.key | apt-key add -"
sudo add-apt-repository http://dl.openfoam.org/ubuntu
sudo apt-get update
# Install OpenFOAM v11 (or latest version)
sudo apt-get install openfoam11
# Source the OpenFOAM environment
echo "source /opt/openfoam11/etc/bashrc" >> ~/.bashrc
source ~/.bashrc
オプション 2:ESI-OpenCFD バージョン
# Add repository
sudo sh -c "wget -O - https://dl.openfoam.com/add-debian-repo.sh | bash"
# Install OpenFOAM v2312 (or latest version)
sudo apt-get install openfoam2312-default
# Source environment
echo "source /usr/lib/openfoam/openfoam2312/etc/bashrc" >> ~/.bashrc
source ~/.bashrc
オプション 3:ソースからビルド
# Install dependencies
sudo apt-get install build-essential cmake git ca-certificates \
flex libfl-dev bison zlib1g-dev libboost-system-dev \
libboost-thread-dev libopenmpi-dev openmpi-bin \
gnuplot libreadline-dev libncurses-dev libxt-dev \
qt5-default libqt5x11extras5-dev libqt5help5 qttools5-dev \
qtxmlpatterns5-dev-tools libqt5opengl5-dev freeglut3-dev \
libscotch-dev libcgal-dev
# Clone OpenFOAM
git clone https://github.com/OpenFOAM/OpenFOAM-11.git
cd OpenFOAM-11
# Source and compile
source etc/bashrc
./Allwmake -j
インストールの確認
# Check OpenFOAM environment
which simpleFoam
foamInstallationTest
# Run tutorial
mkdir -p $FOAM_RUN
cp -r $FOAM_TUTORIALS/incompressible/simpleFoam/pitzDaily $FOAM_RUN/
cd $FOAM_RUN/pitzDaily
blockMesh
simpleFoam
ポスト処理用の ParaView のインストール
# Install ParaView
sudo apt-get install paraview
# Or use OpenFOAM's reader
paraFoam
ケースディレクトリの構成
OpenFOAM のすべてのケースは、標準化されたディレクトリ構成に従います:
caseDirectory/
├── 0/ # Initial and boundary conditions
│ ├── U # Velocity field
│ ├── p # Pressure field
│ ├── T # Temperature field (if applicable)
│ ├── k # Turbulent kinetic energy
│ ├── epsilon # Turbulent dissipation rate
│ ├── omega # Specific dissipation rate
│ └── nut # Turbulent viscosity
├── constant/ # Physical properties and mesh
│ ├── polyMesh/ # Mesh data
│ │ ├── points # Vertex coordinates
│ │ ├── faces # Face definitions
│ │ ├── owner # Cell ownership
│ │ ├── neighbour # Cell neighbors
│ │ └── boundary # Boundary patches
│ ├── transportProperties # Fluid properties
│ ├── turbulenceProperties # Turbulence model selection
│ ├── g # Gravity vector
│ └── regionProperties # Multi-region properties
├── system/ # Numerical settings
│ ├── controlDict # Simulation control
│ ├── fvSchemes # Discretization schemes
│ ├── fvSolution # Solver settings
│ ├── blockMeshDict # Mesh generation
│ ├── snappyHexMeshDict # Advanced meshing
│ ├── decomposeParDict # Parallel decomposition
│ └── sampleDict # Sampling/probing
└── [time directories]/ # Results at each time step
├── U
├── p
└── ...
主なディクショナリ
controlDict(system/controlDict)
シミュレーションの実行と出力を制御します:
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object controlDict;
}
application simpleFoam; // Solver to use
startFrom startTime; // latestTime, firstTime
startTime 0;
stopAt endTime;
endTime 1000;
deltaT 1; // Time step
writeControl timeStep; // runTime, adjustableRunTime, cpuTime
writeInterval 100; // Write every N steps
purgeWrite 2; // Keep only last N time directories
writeFormat ascii; // binary
writePrecision 6;
writeCompression off; // on for binary
timeFormat general;
timePrecision 6;
runTimeModifiable true; // Re-read dictionaries during run
// Function objects for monitoring and post-processing
functions
{
forceCoeffs
{
type forceCoeffs;
libs ("libforces.so");
writeControl timeStep;
writeInterval 1;
patches (wall);
rho rhoInf;
rhoInf 1.225;
CofR (0 0 0);
liftDir (0 1 0);
dragDir (1 0 0);
pitchAxis (0 0 1);
magUInf 10;
lRef 1;
Aref 1;
}
probes
{
type probes;
libs ("libsampling.so");
writeControl timeStep;
writeInterval 1;
fields (p U);
probeLocations
(
(0.5 0.5 0.5)
(1.0 0.5 0.5)
);
}
}
fvSchemes(system/fvSchemes)
離散化スキームを定義します:
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object fvSchemes;
}
// Time derivatives
ddtSchemes
{
default steadyState; // Euler, backward, CrankNicolson
}
// Gradient schemes
gradSchemes
{
default Gauss linear; // cellLimited Gauss linear 1
grad(p) Gauss linear;
grad(U) cellLimited Gauss linear 1;
}
// Divergence schemes (convection)
divSchemes
{
default none;
div(phi,U) bounded Gauss linearUpwind grad(U);
div(phi,k) bounded Gauss upwind;
div(phi,epsilon) bounded Gauss upwind;
div(phi,omega) bounded Gauss upwind;
div((nuEff*dev2(T(grad(U))))) Gauss linear;
}
// Laplacian schemes (diffusion)
laplacianSchemes
{
default Gauss linear corrected;
}
// Interpolation schemes
interpolationSchemes
{
default linear;
}
// Surface normal gradient schemes
snGradSchemes
{
default corrected;
}
// Wall distance calculation
wallDist
{
method meshWave;
}
fvSolution(system/fvSolution)
ソルバーのアルゴリズムと許容誤差を定義します:
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object fvSolution;
}
solvers
{
p
{
solver GAMG; // Geometric-Algebraic Multi-Grid
tolerance 1e-6;
relTol 0.01;
smoother GaussSeidel;
nPreSweeps 0;
nPostSweeps 2;
cacheAgglomeration on;
agglomerator faceAreaPair;
nCellsInCoarsestLevel 10;
mergeLevels 1;
}
U
{
solver smoothSolver;
smoother GaussSeidel;
tolerance 1e-7;
relTol 0.1;
nSweeps 1;
}
"(k|epsilon|omega)"
{
solver smoothSolver;
smoother GaussSeidel;
tolerance 1e-8;
relTol 0.1;
nSweeps 1;
}
}
// SIMPLE algorithm for steady-state
SIMPLE
{
nNonOrthogonalCorrectors 0;
consistent yes; // SIMPLEC algorithm
residualControl
{
p 1e-5;
U 1e-5;
"(k|epsilon|omega)" 1e-5;
}
}
// PIMPLE algorithm for transient
PIMPLE
{
nOuterCorrectors 50;
nCorrectors 2;
nNonOrthogonalCorrectors 1;
residualControl
{
U 1e-5;
p 1e-5;
}
}
relaxationFactors
{
fields
{
p 0.3;
}
equations
{
U 0.7;
k 0.7;
epsilon 0.7;
omega 0.7;
}
}
transportProperties(constant/transportProperties)
流体の物性値を定義します:
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object transportProperties;
}
// Single phase
transportModel Newtonian;
nu [0 2 -1 0 0 0 0] 1e-05; // Kinematic viscosity (m²/s)
// For multiphase (interFoam)
phases (water air);
water
{
transportModel Newtonian;
nu [0 2 -1 0 0 0 0] 1e-06;
rho [1 -3 0 0 0 0 0] 1000;
}
air
{
transportModel Newtonian;
nu [0 2 -1 0 0 0 0] 1.48e-05;
rho [1 -3 0 0 0 0 0] 1;
}
sigma [1 0 -2 0 0 0 0] 0.07; // Surface tension
turbulenceProperties(constant/turbulenceProperties)
乱流モデルを選択します:
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object turbulenceProperties;
}
simulationType RAS; // laminar, LES, RAS (RANS)
// RANS models
RAS
{
RASModel kEpsilon; // kOmegaSST, realizableKE, SpalartAllmaras
turbulence on;
printCoeffs on;
}
// LES models
LES
{
LESModel Smagorinsky; // kEqn, WALE, dynamicKEqn
turbulence on;
printCoeffs on;
delta cubeRootVol;
cubeRootVolCoeffs
{
deltaCoeff 1;
}
}
境界条件
一般的な境界タイプ
速度(U)
固定値(入口)
inlet
{
type fixedValue;
value uniform (1 0 0); // 1 m/s in x-direction
}
ゼロ勾配(出口)
outlet
{
type zeroGradient;
}
すべりなし壁面
wall
{
type noSlip; // equivalent to fixedValue uniform (0 0 0)
}
すべり壁面
symmetry
{
type slip;
}
プロファイル付き入口
inlet
{
type codedFixedValue;
value uniform (0 0 0);
name parabolicVelocity;
code
#{
const fvPatch& boundaryPatch = patch();
const vectorField& Cf = boundaryPatch.Cf();
vectorField& field = *this;
forAll(Cf, faceI)
{
scalar y = Cf[faceI].y();
scalar H = 0.1; // Channel height
scalar Umax = 1.5;
field[faceI] = vector(Umax * 4 * y * (H - y) / (H * H), 0, 0);
}
#};
}
圧力(p)
固定値(出口)
outlet
{
type fixedValue;
value uniform 0;
}
ゼロ勾配(入口)
inlet
{
type zeroGradient;
}
壁面
wall
{
type zeroGradient;
}
全圧(入口)
inlet
{
type totalPressure;
p0 uniform 101325;
U U;
phi phi;
rho none;
psi none;
gamma 1;
value uniform 101325;
}
乱流(k、epsilon、omega)
入口 - 固定値
// Turbulent kinetic energy
k_inlet
{
type turbulentIntensityKineticEnergyInlet;
intensity 0.05; // 5% turbulence intensity
value uniform 0.375;
}
// Dissipation rate
epsilon_inlet
{
type turbulentMixingLengthDissipationRateInlet;
mixingLength 0.005; // 0.5 cm
value uniform 14.855;
}
// Specific dissipation rate
omega_inlet
{
type turbulentMixingLengthFrequencyInlet;
mixingLength 0.005;
value uniform 440;
}
壁関数
// k at wall
k_wall
{
type kqRWallFunction;
value uniform 0.375;
}
// epsilon at wall
epsilon_wall
{
type epsilonWallFunction;
value uniform 14.855;
}
// omega at wall
omega_wall
{
type omegaWallFunction;
value uniform 440;
}
// nut at wall
nut_wall
{
type nutkWallFunction;
value uniform 0;
}
出口
k_outlet
{
type zeroGradient;
}
epsilon_outlet
{
type zeroGradient;
}
omega_outlet
{
type zeroGradient;
}
乱流パラメーターの計算
入口条件の場合:
Turbulent intensity: I = u'/U = 0.16 * Re^(-1/8)
Turbulent kinetic energy: k = 3/2 * (U * I)²
Turbulent dissipation: ε = C_μ^(3/4) * k^(3/2) / L
Specific dissipation: ω = k^(1/2) / (C_μ^(1/4) * L)
Where:
- U = mean velocity
- Re = Reynolds number
- L = turbulent length scale ≈ 0.07 * characteristic_length
- C_μ = 0.09
ソルバーの選択
非圧縮性ソルバー
simpleFoam - 定常、非圧縮性、乱流
- 用途:外部空力、HVAC、産業流れ
- アルゴリズム:SIMPLE
- 速度:定常問題で高速に収束します
pimpleFoam - 非定常、非圧縮性、乱流
- 用途:渦放出、非定常流れ、LES
- アルゴリズム:PIMPLE(PISO と SIMPLE の統合)
- 速度:安定性に優れ、大きな時間刻みに対応します
icoFoam - 非定常、非圧縮性、層流
- 用途:低レイノルズ数、教育
- アルゴリズム:PISO
- 速度:層流で高速です
pisoFoam - 非定常、非圧縮性、乱流
- 用途:LES、DNS
- アルゴリズム:PISO
- 速度:小さな時間刻みが必要です
多相流ソルバー
interFoam - VOF 法、混ざり合わない 2 種類の流体
- 用途:自由表面流れ、スロッシング、砕波
- 流体間の界面を追跡します
multiphaseInterFoam - 複数流体用の VOF
- 用途:2 相を超える流れ
twoPhaseEulerFoam - オイラー・オイラー多相流
- 用途:流動層、気泡流
圧縮性ソルバー
rhoSimpleFoam - 定常、圧縮性、乱流
- 用途:高速流れ、圧縮性の影響
rhoPimpleFoam - 非定常、圧縮性、乱流
- 用途:非定常圧縮性流れ
sonicFoam - 非定常、圧縮性、超音速
- 用途:超音速流れ、衝撃波
熱伝達ソルバー
buoyantSimpleFoam - 定常、浮力駆動
- 用途:自然対流
buoyantPimpleFoam - 非定常、浮力駆動
- 用途:非定常自然対流
chtMultiRegionFoam - 共役熱伝達
- 用途:固体と流体間の熱伝達
メッシュ生成
blockMesh - 構造化六面体メッシュ
直方体領域用の基本的なブロックメッシュ:
// system/blockMeshDict
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object blockMeshDict;
}
convertToMeters 1;
vertices
(
(0 0 0) // 0
(1 0 0) // 1
(1 1 0) // 2
(0 1 0) // 3
(0 0 0.1) // 4
(1 0 0.1) // 5
(1 1 0.1) // 6
(0 1 0.1) // 7
);
blocks
(
hex (0 1 2 3 4 5 6 7) (20 20 1) simpleGrading (1 1 1)
);
edges
(
);
boundary
(
inlet
{
type patch;
faces
(
(0 4 7 3)
);
}
outlet
{
type patch;
faces
(
(1 2 6 5)
);
}
walls
{
type wall;
faces
(
(0 1 5 4)
(3 7 6 2)
);
}
frontAndBack
{
type empty;
faces
(
(0 3 2 1)
(4 5 6 7)
);
}
);
mergePatchPairs
(
);
実行:blockMesh
snappyHexMesh - 非構造六面体優勢メッシュ
STL ファイルから複雑な形状を生成する場合:
// system/snappyHexMeshDict (simplified)
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object snappyHexMeshDict;
}
castellatedMesh true;
snap true;
addLayers true;
geometry
{
geometry.stl
{
type triSurfaceMesh;
name geometry;
}
}
castellatedMeshControls
{
maxLocalCells 100000;
maxGlobalCells 2000000;
minRefinementCells 0;
nCellsBetweenLevels 3;
features
(
{
file "geometry.eMesh";
level 2;
}
);
refinementSurfaces
{
geometry
{
level (2 2);
}
}
resolveFeatureAngle 30;
refinementRegions
{
}
locationInMesh (0.01 0.01 0.01);
allowFreeStandingZoneFaces true;
}
snapControls
{
nSmoothPatch 3;
tolerance 2.0;
nSolveIter 30;
nRelaxIter 5;
}
addLayersControls
{
relativeSizes true;
layers
{
geometry
{
nSurfaceLayers 3;
}
}
expansionRatio 1.2;
finalLayerThickness 0.3;
minThickness 0.1;
nGrow 0;
featureAngle 30;
nRelaxIter 3;
nSmoothSurfaceNormals 1;
nSmoothNormals 3;
nSmoothThickness 10;
maxFaceThicknessRatio 0.5;
maxThicknessToMedialRatio 0.3;
minMedianAxisAngle 90;
nBufferCellsNoExtrude 0;
nLayerIter 50;
}
meshQualityControls
{
maxNonOrtho 65;
maxBoundarySkewness 20;
maxInternalSkewness 4;
maxConcave 80;
minVol 1e-13;
minTetQuality 1e-30;
minArea -1;
minTwist 0.02;
minDeterminant 0.001;
minFaceWeight 0.02;
minVolRatio 0.01;
minTriangleTwist -1;
nSmoothScale 4;
errorReduction 0.75;
}
debug 0;
mergeTolerance 1e-6;
実行:snappyHexMesh -overwrite
ParaView による後処理
paraFoam の使用
# In case directory
paraFoam
# With reconstructed parallel case
paraFoam -builtin
# Touch file for newer versions
touch case.foam
paraview case.foam
よく使われる可視化タスク
-
速度の大きさ
- Filters → Calculator
- 結果配列名:UMag
- 数式:
mag(U)
-
流線
- Filters → Stream Tracer
- シードタイプ:Point Source または Line Source
- ベクトル:U
-
スライス/平面
- Filters → Slice
- 平面パラメーター:原点と法線
-
等値面
- Filters → Contour
- 変数と値を選択します
-
壁面せん断応力
- Filters → Calculator
- 数式:
nu * mag(wallShearStress)
サンプリングとデータ抽出
system/sampleDict を作成します:
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object sampleDict;
}
interpolationScheme cellPoint;
setFormat raw;
sets
(
centerline
{
type uniform;
axis distance;
start (0 0.5 0.05);
end (10 0.5 0.05);
nPoints 100;
}
);
surfaces
(
plane
{
type cuttingPlane;
planeType pointAndNormal;
pointAndNormalDict
{
point (0 0 0);
normal (0 0 1);
}
interpolate true;
}
);
fields (p U k epsilon);
実行:postProcess -func sampleDict
並列処理
ケースの分解
system/decomposeParDict を作成します:
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object decomposeParDict;
}
numberOfSubdomains 4;
method scotch; // simple, hierarchical, manual
// For simple decomposition
simpleCoeffs
{
n (2 2 1);
delta 0.001;
}
// For hierarchical decomposition
hierarchicalCoeffs
{
n (2 2 1);
delta 0.001;
order xyz;
}
並列実行
# Decompose the mesh
decomposePar
# Run solver in parallel
mpirun -np 4 simpleFoam -parallel
# Reconstruct results
reconstructPar
# Reconstruct only latest time
reconstructPar -latestTime
ワークフローの概要
# 1. Create case structure
mkdir -p myCase/{0,constant,system}
# 2. Copy base configuration
cp -r $FOAM_TUTORIALS/incompressible/simpleFoam/pitzDaily/* myCase/
# 3. Edit dictionaries
# - system/controlDict
# - system/fvSchemes
# - system/fvSolution
# - constant/transportProperties
# - constant/turbulenceProperties
# - 0/U, 0/p, 0/k, 0/epsilon
# 4. Generate mesh
cd myCase
blockMesh
# 5. Check mesh quality
checkMesh
# 6. Run solver
simpleFoam > log.simpleFoam 2>&1
# 7. Monitor residuals
foamMonitor -l postProcessing/residuals/0/residuals.dat
# 8. Post-process
paraFoam
# For parallel:
decomposePar
mpirun -np 4 simpleFoam -parallel
reconstructPar
ベストプラクティス
- メッシュ品質:シミュレーションの前に必ず
checkMeshを実行します - 残差:収束を監視します(工学的な精度には < 1e-4)
- クーラン数:安定性を保つため、Co < 1 にします(非定常ケース)
- Y+ 値:壁関数では 30-300、境界層を直接解像する場合は < 1
- 格子独立性:メッシュ細分化の調査を実施します
- 初期化:より良い初期速度場を得るために
potentialFoamを使用します - バックアップ:ケースファイルを git でバージョン管理します
トラブルシューティング
よくある問題
メッシュチェックの失敗
checkMesh
# Look for non-orthogonality, skewness
# Increase nNonOrthogonalCorrectors in fvSolution
発散
- 緩和係数を下げます
- 初期条件を改善します
- メッシュを細分化します
- 時間刻みを小さくします(非定常の場合)
収束が遅い
- 境界条件を確認します
- ソルバーの許容誤差を調整します
- より良い前処理法(圧力には GAMG)を使用します
並列処理の問題
# Check decomposition
decomposePar -cellDist
# Verify MPI installation
mpirun -np 2 hostname
リソース
関連項目
examples/pipe-flow/- 乱流管内流れの完全なケースexamples/pump-impeller/- 回転機械のシミュレーションexamples/scripts/- Python によるケース生成ユーティリティreference.md- 辞書とソルバーの詳細なリファレンス