SlideShare a Scribd company logo
3
Most read
5
Most read
12
Most read
OpenFOAM Programming Tips
Keywords:
• OpenFOAM
• findPatchID
• gSum
• faceCells
• DynamicList
English
Fumiya Nozaki
Last Updated: 6 May 2015
2
1. How to get patch’s label from patch’s name
label patchID = mesh.boundaryMesh().findPatchID("NAME_OF_PATCH");
Info << "patchID = " << patchID << endl;
Example
5
(
inlet
{
type patch;
nFaces 30;
startFace 24170;
}
outlet
{
type patch;
nFaces 57;
startFace 24200;
}
upperWall
{
type wall;
inGroups 1(wall);
nFaces 223;
startFace 24257;
}
lowerWall
{
type wall;
inGroups 1(wall);
nFaces 250;
startFace 24480;
}
…
)
label patchID = mesh.boundaryMesh().findPatchID(“upperWall");
Info << "patchID = " << patchID << endl;
⇒ patchID = 2
0
1
2
3
3
2. How to calculate the sum over the specified patch
label outletPatchID = mesh.boundaryMesh().findPatchID(“outlet");
scalar outFlux = gSum(phi.boundaryField()[outletPatchID]);
Info << “Volumetric flux = " << outFlux << “ [m^3/s]” << endl;
We can calculate the total outlet flux
by summing the field phi over the patch named outlet:
 gSum() sums over all the processors in a parallel run
 If you calculate the total “inlet” flux using the above code, it takes the
negative value because the face normal vectors point in the opposite
direction from the inlet velocities.
inlet outlet
U
mesh.Sf()
4
3. How to get a boundary value of a variable
label patchID = mesh.boundaryMesh().findPatchID(“outlet");
forAll(mesh.boundary()[patchID], faceI)
{
Info<< U.boundaryField()[patchID][faceI] << endl;
}
We can get the velocity on the outlet patch using the following code:
faceI=0
faceI=1
faceI=2
U.boundaryField()[patchID][1]
outlet
U.boundaryField()[patchID][2]
U.boundaryField()[patchID][0]
5
4. How to get variable values in the cells adjacent to a patch
We can get the label list of cells adjacent to patch using faceCells():
label patchID = mesh.boundaryMesh().findPatchID(“outlet");
forAll(mesh.boundary()[patchID], faceI)
{
Info<< U[mesh.boundary()[patchID].faceCells()[faceI]] << endl;
}
faceI=0
faceI=1
faceI=2
U[mesh.boundary()[patchID].faceCells()[1]]
outlet
6
5. How to read cellZones
FoamFile
{
version 2.0;
format ascii;
class regIOobject;
location "constant/polyMesh";
object cellZones;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
2
(
rotor
{
type cellZone;
cellLabels List<label>
5
(
3
4
5
10
11
)
;
}
 Format of the cellZones file
stator
{
type cellZone;
cellLabels List<label>
4
(
15
17
20
21
)
;
}
)
For want of space
The number of cellzones Name of cellzones
The number of cells
that belong to the cellZone
List of cell labels
7
5. How to read cellZones
label cellZoneID = mesh.cellZones().findZoneID("stator");
const labelList& cellLabels = mesh.cellZones()[cellZoneID];
Info<< "cellZoneID: " << cellZoneID << endl;
Info<< "cellLabels: " << cellLabels << endl;
Continued from the previous page.
cellZoneID: 1
cellLabels: 4(15 17 20 21)
MRFZone.C
Example of use
8
6. Logical operators
boolList A(4);
A[0] = true;
A[1] = false;
A[2] = true;
A[3] = false;
Info<< "A: " << A << endl;
boolList B(4);
B[0] = true;
B[1] = true;
B[2] = false;
B[3] = false;
Info<< "B: " << B << endl;
boolList C = A * B;
Info<< "C: " << C << endl;
boolList D = A + B;
Info<< "D: " << D << endl;
A: 4(1 0 1 0)
B: 4(1 1 0 0)
C: 4(1 0 0 0)
D: 4(1 1 1 0)
Logical conjunction
Logical disjunction
9
7. How to use DynamicList
DynamicList<label> partA(0);
partA.append(3);
partA.append(1);
partA.append(4);
partA.append(1);
partA.append(5);
partA.append(9);
partA.append(2);
Info<< partA << endl;
DynamicList<label> partB(0);
partB.append(6);
partB.append(5);
partB.append(3);
partB.append(5);
partA.append(partB);
Info<< partA << endl;
Append an element at the end of the list
Initialization
7(3 1 4 1 5 9 2)
11(3 1 4 1 5 9 2 6 5 3 5)
Append a List(partB) at the end of partA
10
7. How to use DynamicList
labelList uniqueIndex;
uniqueOrder(partA, uniqueIndex);
Info<< uniqueIndex << endl;
DynamicList<label> uniqueList(0);
forAll(uniqueIndex, i)
{
uniqueList.append(partA[uniqueIndex[i]]);
}
partA.transfer(uniqueList);
Info<< partA << endl;
7(3 6 9 2 10 7 5)
Continued from the previous page.
Generate (sorted) indices
corresponding to unique list values
7(1 2 3 4 5 6 9)
11(3 1 4 1 5 9 2 6 5 3 5)
0 1 2 3 4 5 6 7 8 9 10
Index
Create a list of unique values
(remove duplicate values)
PartA
11
I will continuously update this slide in the future.
Kindly let me know
if you have any ideas about what topics to cover.
12
Thank
You!

More Related Content

What's hot (20)

PDF
OpenFOAM の cyclic、cyclicAMI、cyclicACMI 条件について
Fumiya Nozaki
 
PDF
OpenFOAM の境界条件をまとめよう!
Fumiya Nozaki
 
PPTX
OpenFOAMによる気液2相流解析の基礎と設定例
takuyayamamoto1800
 
PDF
OpenFOAMのinterfoamによる誤差
takuyayamamoto1800
 
PDF
Turbulence Models in OpenFOAM
Fumiya Nozaki
 
PDF
Dynamic Mesh in OpenFOAM
Fumiya Nozaki
 
PDF
OpenFOAM -回転領域を含む流体計算 (Rotating Geometry)-
Fumiya Nozaki
 
PDF
OpenFOAMの壁関数
Fumiya Nozaki
 
PDF
About dexcs2021 for OpenFOAM
Etsuji Nomura
 
PDF
OpenFOAMの混相流用改造solver(S-CLSVOF法)の設定・使い方
takuyayamamoto1800
 
PDF
About multiphaseEulerFoam
守淑 田村
 
PDF
無償のモデリングソフトウェアCAESESを使ってみた
Fumiya Nozaki
 
PDF
OpenFOAMソルバの実行時ベイズ最適化
Masashi Imano
 
PDF
Adjoint Shape Optimization using OpenFOAM
Fumiya Nozaki
 
PDF
OpenFOAM の Function Object 機能について
Fumiya Nozaki
 
PDF
buoyantBousinessqSimpleFoam
Milad Sm
 
PDF
OpenFOAM v2.3.0のチュートリアル 『oscillatingInletACMI2D』
Fumiya Nozaki
 
PDF
interFoamの検証
takuyayamamoto1800
 
PDF
Mixer vessel by cfmesh
Etsuji Nomura
 
PDF
Motor bike by cfmesh
Etsuji Nomura
 
OpenFOAM の cyclic、cyclicAMI、cyclicACMI 条件について
Fumiya Nozaki
 
OpenFOAM の境界条件をまとめよう!
Fumiya Nozaki
 
OpenFOAMによる気液2相流解析の基礎と設定例
takuyayamamoto1800
 
OpenFOAMのinterfoamによる誤差
takuyayamamoto1800
 
Turbulence Models in OpenFOAM
Fumiya Nozaki
 
Dynamic Mesh in OpenFOAM
Fumiya Nozaki
 
OpenFOAM -回転領域を含む流体計算 (Rotating Geometry)-
Fumiya Nozaki
 
OpenFOAMの壁関数
Fumiya Nozaki
 
About dexcs2021 for OpenFOAM
Etsuji Nomura
 
OpenFOAMの混相流用改造solver(S-CLSVOF法)の設定・使い方
takuyayamamoto1800
 
About multiphaseEulerFoam
守淑 田村
 
無償のモデリングソフトウェアCAESESを使ってみた
Fumiya Nozaki
 
OpenFOAMソルバの実行時ベイズ最適化
Masashi Imano
 
Adjoint Shape Optimization using OpenFOAM
Fumiya Nozaki
 
OpenFOAM の Function Object 機能について
Fumiya Nozaki
 
buoyantBousinessqSimpleFoam
Milad Sm
 
OpenFOAM v2.3.0のチュートリアル 『oscillatingInletACMI2D』
Fumiya Nozaki
 
interFoamの検証
takuyayamamoto1800
 
Mixer vessel by cfmesh
Etsuji Nomura
 
Motor bike by cfmesh
Etsuji Nomura
 

Similar to OpenFOAM Programming Tips (20)

PPTX
Image representation
Rahul Dadwal
 
PDF
mooney slides for dynamic topoFvMesh in open foam for mesh motion
SukhamMichael
 
PDF
How_to_blockMesh using OpenFOAM good mateiral
ssusercf6d0e
 
PDF
Collision Detection an Overview
slantsixgames
 
PDF
Physics for Game Programmers: Spatial Data Structures
ナム-Nam Nguyễn
 
PDF
Mincut_Placement_Final_Report
Anandhavel Nagendra
 
PPTX
Image Representation & Descriptors
PundrikPatel
 
PPTX
3 d active meshes for cell tracking
Prashant Pal
 
PDF
Computing the Area of a Polygon
Kasun Ranga Wijeweera
 
PPTX
Computer graphics
Nanhen Verma
 
PPTX
representation.pptx
vijayalakshmi257551
 
PPT
Polygon filling
Ankit Garg
 
PPTX
On the Convex Layers of a Planer Dynamic Set of Points
Kasun Ranga Wijeweera
 
KEY
openFrameworks 007 - 3D
roxlu
 
PDF
High-Performance Physics Solver Design for Next Generation Consoles
Slide_N
 
PPTX
Hidden surface removal
Ankit Garg
 
PPT
PAM.ppt
janaki raman
 
PPT
Fill area algorithms
Kumar
 
PDF
Delaunay triangulation from 2-d delaunay to 3-d delaunay
greentask
 
PDF
Verification of Efficacy of Inside-Outside Judgement in Respect of a 3D-Primi...
International Journal of Modern Research in Engineering and Technology
 
Image representation
Rahul Dadwal
 
mooney slides for dynamic topoFvMesh in open foam for mesh motion
SukhamMichael
 
How_to_blockMesh using OpenFOAM good mateiral
ssusercf6d0e
 
Collision Detection an Overview
slantsixgames
 
Physics for Game Programmers: Spatial Data Structures
ナム-Nam Nguyễn
 
Mincut_Placement_Final_Report
Anandhavel Nagendra
 
Image Representation & Descriptors
PundrikPatel
 
3 d active meshes for cell tracking
Prashant Pal
 
Computing the Area of a Polygon
Kasun Ranga Wijeweera
 
Computer graphics
Nanhen Verma
 
representation.pptx
vijayalakshmi257551
 
Polygon filling
Ankit Garg
 
On the Convex Layers of a Planer Dynamic Set of Points
Kasun Ranga Wijeweera
 
openFrameworks 007 - 3D
roxlu
 
High-Performance Physics Solver Design for Next Generation Consoles
Slide_N
 
Hidden surface removal
Ankit Garg
 
PAM.ppt
janaki raman
 
Fill area algorithms
Kumar
 
Delaunay triangulation from 2-d delaunay to 3-d delaunay
greentask
 
Verification of Efficacy of Inside-Outside Judgement in Respect of a 3D-Primi...
International Journal of Modern Research in Engineering and Technology
 
Ad

More from Fumiya Nozaki (8)

PDF
Basic Boundary Conditions in OpenFOAM v2.4
Fumiya Nozaki
 
PDF
blockCoupledSwirlTestチュートリアル
Fumiya Nozaki
 
PDF
CAESES Free チュートリアル
Fumiya Nozaki
 
PDF
CAESES-FFW,GridPro,OpenFOAMを使用した形状最適化事例#1
Fumiya Nozaki
 
PDF
ParaView による可視化 Tips
Fumiya Nozaki
 
PDF
OpenFOAMのチュートリアルを作ってみた#1 『くさび油膜効果の計算』
Fumiya Nozaki
 
PDF
オープンソースの CFD ソフトウェア SU2 のチュートリアルをやってみた
Fumiya Nozaki
 
PDF
OpenFOAM を用いた Adjoint 形状最適化事例1
Fumiya Nozaki
 
Basic Boundary Conditions in OpenFOAM v2.4
Fumiya Nozaki
 
blockCoupledSwirlTestチュートリアル
Fumiya Nozaki
 
CAESES Free チュートリアル
Fumiya Nozaki
 
CAESES-FFW,GridPro,OpenFOAMを使用した形状最適化事例#1
Fumiya Nozaki
 
ParaView による可視化 Tips
Fumiya Nozaki
 
OpenFOAMのチュートリアルを作ってみた#1 『くさび油膜効果の計算』
Fumiya Nozaki
 
オープンソースの CFD ソフトウェア SU2 のチュートリアルをやってみた
Fumiya Nozaki
 
OpenFOAM を用いた Adjoint 形状最適化事例1
Fumiya Nozaki
 
Ad

Recently uploaded (20)

PDF
“Scaling i.MX Applications Processors’ Native Edge AI with Discrete AI Accele...
Edge AI and Vision Alliance
 
PPTX
Smarter Governance with AI: What Every Board Needs to Know
OnBoard
 
PDF
Darley - FIRST Copenhagen Lightning Talk (2025-06-26) Epochalypse 2038 - Time...
treyka
 
PDF
Python Conference Singapore - 19 Jun 2025
ninefyi
 
PDF
My Journey from CAD to BIM: A True Underdog Story
Safe Software
 
PPTX
reInforce 2025 Lightning Talk - Scott Francis.pptx
ScottFrancis51
 
PDF
EIS-Webinar-Engineering-Retail-Infrastructure-06-16-2025.pdf
Earley Information Science
 
PPTX
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Pitch ...
Michele Kryston
 
PDF
Enhancing Environmental Monitoring with Real-Time Data Integration: Leveragin...
Safe Software
 
PPTX
Practical Applications of AI in Local Government
OnBoard
 
PDF
UiPath Agentic AI ile Akıllı Otomasyonun Yeni Çağı
UiPathCommunity
 
PDF
The Growing Value and Application of FME & GenAI
Safe Software
 
PDF
Salesforce Summer '25 Release Frenchgathering.pptx.pdf
yosra Saidani
 
PPTX
Enabling the Digital Artisan – keynote at ICOCI 2025
Alan Dix
 
DOCX
Daily Lesson Log MATATAG ICT TEchnology 8
LOIDAALMAZAN3
 
PDF
5 Things to Consider When Deploying AI in Your Enterprise
Safe Software
 
PDF
From Chatbot to Destroyer of Endpoints - Can ChatGPT Automate EDR Bypasses (1...
Priyanka Aash
 
PDF
How to Visualize the ​Spatio-Temporal Data Using CesiumJS​
SANGHEE SHIN
 
PDF
Optimizing the trajectory of a wheel loader working in short loading cycles
Reno Filla
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
“Scaling i.MX Applications Processors’ Native Edge AI with Discrete AI Accele...
Edge AI and Vision Alliance
 
Smarter Governance with AI: What Every Board Needs to Know
OnBoard
 
Darley - FIRST Copenhagen Lightning Talk (2025-06-26) Epochalypse 2038 - Time...
treyka
 
Python Conference Singapore - 19 Jun 2025
ninefyi
 
My Journey from CAD to BIM: A True Underdog Story
Safe Software
 
reInforce 2025 Lightning Talk - Scott Francis.pptx
ScottFrancis51
 
EIS-Webinar-Engineering-Retail-Infrastructure-06-16-2025.pdf
Earley Information Science
 
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Pitch ...
Michele Kryston
 
Enhancing Environmental Monitoring with Real-Time Data Integration: Leveragin...
Safe Software
 
Practical Applications of AI in Local Government
OnBoard
 
UiPath Agentic AI ile Akıllı Otomasyonun Yeni Çağı
UiPathCommunity
 
The Growing Value and Application of FME & GenAI
Safe Software
 
Salesforce Summer '25 Release Frenchgathering.pptx.pdf
yosra Saidani
 
Enabling the Digital Artisan – keynote at ICOCI 2025
Alan Dix
 
Daily Lesson Log MATATAG ICT TEchnology 8
LOIDAALMAZAN3
 
5 Things to Consider When Deploying AI in Your Enterprise
Safe Software
 
From Chatbot to Destroyer of Endpoints - Can ChatGPT Automate EDR Bypasses (1...
Priyanka Aash
 
How to Visualize the ​Spatio-Temporal Data Using CesiumJS​
SANGHEE SHIN
 
Optimizing the trajectory of a wheel loader working in short loading cycles
Reno Filla
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 

OpenFOAM Programming Tips

  • 1. OpenFOAM Programming Tips Keywords: • OpenFOAM • findPatchID • gSum • faceCells • DynamicList English Fumiya Nozaki Last Updated: 6 May 2015
  • 2. 2 1. How to get patch’s label from patch’s name label patchID = mesh.boundaryMesh().findPatchID("NAME_OF_PATCH"); Info << "patchID = " << patchID << endl; Example 5 ( inlet { type patch; nFaces 30; startFace 24170; } outlet { type patch; nFaces 57; startFace 24200; } upperWall { type wall; inGroups 1(wall); nFaces 223; startFace 24257; } lowerWall { type wall; inGroups 1(wall); nFaces 250; startFace 24480; } … ) label patchID = mesh.boundaryMesh().findPatchID(“upperWall"); Info << "patchID = " << patchID << endl; ⇒ patchID = 2 0 1 2 3
  • 3. 3 2. How to calculate the sum over the specified patch label outletPatchID = mesh.boundaryMesh().findPatchID(“outlet"); scalar outFlux = gSum(phi.boundaryField()[outletPatchID]); Info << “Volumetric flux = " << outFlux << “ [m^3/s]” << endl; We can calculate the total outlet flux by summing the field phi over the patch named outlet:  gSum() sums over all the processors in a parallel run  If you calculate the total “inlet” flux using the above code, it takes the negative value because the face normal vectors point in the opposite direction from the inlet velocities. inlet outlet U mesh.Sf()
  • 4. 4 3. How to get a boundary value of a variable label patchID = mesh.boundaryMesh().findPatchID(“outlet"); forAll(mesh.boundary()[patchID], faceI) { Info<< U.boundaryField()[patchID][faceI] << endl; } We can get the velocity on the outlet patch using the following code: faceI=0 faceI=1 faceI=2 U.boundaryField()[patchID][1] outlet U.boundaryField()[patchID][2] U.boundaryField()[patchID][0]
  • 5. 5 4. How to get variable values in the cells adjacent to a patch We can get the label list of cells adjacent to patch using faceCells(): label patchID = mesh.boundaryMesh().findPatchID(“outlet"); forAll(mesh.boundary()[patchID], faceI) { Info<< U[mesh.boundary()[patchID].faceCells()[faceI]] << endl; } faceI=0 faceI=1 faceI=2 U[mesh.boundary()[patchID].faceCells()[1]] outlet
  • 6. 6 5. How to read cellZones FoamFile { version 2.0; format ascii; class regIOobject; location "constant/polyMesh"; object cellZones; } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 2 ( rotor { type cellZone; cellLabels List<label> 5 ( 3 4 5 10 11 ) ; }  Format of the cellZones file stator { type cellZone; cellLabels List<label> 4 ( 15 17 20 21 ) ; } ) For want of space The number of cellzones Name of cellzones The number of cells that belong to the cellZone List of cell labels
  • 7. 7 5. How to read cellZones label cellZoneID = mesh.cellZones().findZoneID("stator"); const labelList& cellLabels = mesh.cellZones()[cellZoneID]; Info<< "cellZoneID: " << cellZoneID << endl; Info<< "cellLabels: " << cellLabels << endl; Continued from the previous page. cellZoneID: 1 cellLabels: 4(15 17 20 21) MRFZone.C Example of use
  • 8. 8 6. Logical operators boolList A(4); A[0] = true; A[1] = false; A[2] = true; A[3] = false; Info<< "A: " << A << endl; boolList B(4); B[0] = true; B[1] = true; B[2] = false; B[3] = false; Info<< "B: " << B << endl; boolList C = A * B; Info<< "C: " << C << endl; boolList D = A + B; Info<< "D: " << D << endl; A: 4(1 0 1 0) B: 4(1 1 0 0) C: 4(1 0 0 0) D: 4(1 1 1 0) Logical conjunction Logical disjunction
  • 9. 9 7. How to use DynamicList DynamicList<label> partA(0); partA.append(3); partA.append(1); partA.append(4); partA.append(1); partA.append(5); partA.append(9); partA.append(2); Info<< partA << endl; DynamicList<label> partB(0); partB.append(6); partB.append(5); partB.append(3); partB.append(5); partA.append(partB); Info<< partA << endl; Append an element at the end of the list Initialization 7(3 1 4 1 5 9 2) 11(3 1 4 1 5 9 2 6 5 3 5) Append a List(partB) at the end of partA
  • 10. 10 7. How to use DynamicList labelList uniqueIndex; uniqueOrder(partA, uniqueIndex); Info<< uniqueIndex << endl; DynamicList<label> uniqueList(0); forAll(uniqueIndex, i) { uniqueList.append(partA[uniqueIndex[i]]); } partA.transfer(uniqueList); Info<< partA << endl; 7(3 6 9 2 10 7 5) Continued from the previous page. Generate (sorted) indices corresponding to unique list values 7(1 2 3 4 5 6 9) 11(3 1 4 1 5 9 2 6 5 3 5) 0 1 2 3 4 5 6 7 8 9 10 Index Create a list of unique values (remove duplicate values) PartA
  • 11. 11 I will continuously update this slide in the future. Kindly let me know if you have any ideas about what topics to cover.