The source code
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see .
\*---------------------------------------------------------------------------*/
#include "fvCFD.H"
int main(int argc, char *argv[])
{
#include "setRootCase.H"
// These two create the time system (instance called runTime) and fvMesh (instance called mesh).
#include "createTime.H"
#include "createMesh.H"
// runTime and mesh are instances of objects (or classes).
// If you are not familiar with what a class or object is, it is HIGHLY RECOMMENDED you visit this
// website and only come back once you've read everything about classes, inheritance and polymorphism:
// http://www.cplusplus.com/doc/tutorial/classes/
// Note how the next lines call functions .timeName(), .C() and .Cf() implemented in the objects.
// It is also important to realise that mesh.C() and .Cf() return vector fields denoting centres of each
// cell and internal face.
// Calling the mesh.C().size() method therefore yields the total size of the mesh.
Info << "Hello there, the most recent time folder found is " << runTime.timeName() << nl
<< "The mesh has " << mesh.C().size() << " cells and " << mesh.Cf().size()
<< " internal faces in it. Wubalubadubdub!" << nl << endl;
// It's possible to iterate over every cell in a standard C++ for loop
for (label cellI = 0; cellI < mesh.C().size(); cellI++)
if (cellI%20 == 0) // only show every twentieth cell not to spam the screen too much
Info << "Cell " << cellI << " with centre at " << mesh.C()[cellI] << endl;
Info << endl; // spacer
// Each cell is constructed of faces - these may either be internal or constitute a
// boundary, or a patch in OpenFOAM terms; internal faces have an owner cell
// and a neighbour.
for (label faceI = 0; faceI < mesh.owner().size(); faceI++)
if (faceI%40 == 0)
Info << "Internal face " << faceI << " with centre at " << mesh.Cf()[faceI]
<< " with owner cell " << mesh.owner()[faceI]
<< " and neighbour " << mesh.neighbour()[faceI] << endl;
Info << endl;
// Boundary conditions may be accessed through the boundaryMesh object.
// In reality, each boundary face is also included in the constant/polyMesh/faces
// description. But, in that file, the internal faces are defined first.
// In addition, the constant/polyMesh/boundary file defines the starting faceI
// indices from which boundary face definitions start.
// OpenFOAM also provides a macro definition for for loops over all entries
// in a field or a list, which saves up on the amount of typing.
forAll(mesh.boundaryMesh(), patchI)
Info << "Patch " << patchI << ": " << mesh.boundary()[patchI].name() << " with "
<< mesh.boundary()[patchI].Cf().size() << " faces. Starts at total face "
<< mesh.boundary()[patchI].start() << endl;
Info << endl;
// Faces adjacent to boundaries may be accessed as follows.
// Also, a useful thing to know about a face is its normal vector and face area.
label patchFaceI(0);
forAll(mesh.boundaryMesh(), patchI)
Info << "Patch " << patchI << " has its face " << patchFaceI << " adjacent to cell "
<< mesh.boundary()[patchI].patch().faceCells()[patchFaceI]
<< ". It has normal vector " << mesh.boundary()[patchI].Sf()[patchFaceI]
<< " and surface area " << mag(mesh.boundary()[patchI].Sf()[patchFaceI])
<< endl;
Info << endl;
// For internal faces, method .Sf() can be called directly on the mesh instance.
// Moreover, there is a shorthand method .magSf() which returns the surface area
// as a scalar.
// For internal faces, the normal vector points from the owner to the neighbour
// and the owner has a smaller cellI index than the neighbour. For boundary faces,
// the normals always point outside of the domain (they have "imaginary" neighbours
// which do not exist).
// It is possible to look at the points making up each face in more detail.
// First, we define a few shorthands by getting references to the respective
// objects in the mesh. These are defined as constants since we do not aim to
// alter the mesh in any way.
// NOTE: these lists refer to the physical definition of the mesh and thus
// include boundary faces. Use can be made of the mesh.boundary()[patchI].Cf().size()
// and mesh.boundary()[patchI].start() methods to check whether the face is internal
// or lies on a boundary.
const faceList& fcs = mesh.faces();
const List& pts = mesh.points();
const List& cents = mesh.faceCentres();
forAll(fcs,faceI)
if (faceI%80==0)
{
if (faceI(pp))
{
// patch patchID is of type "empty".
Info << "You will not see this." << endl;
}
// Patches may also be retrieved from the mesh using their name. This could be
// useful if the user were to refer to a particular patch from a dictionary
// (like when you do when calculating forces on a particular patch).
word patchName("movingWall");
patchID = mesh.boundaryMesh().findPatchID(patchName);
Info << "Retrieved patch " << patchName << " at index " << patchID << " using its name only." << nl << endl;
Info<< "End\n" << endl;
return 0;
}
// ************************************************************************* //
The running results
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: 6
\\/ M anipulation |
\*---------------------------------------------------------------------------*/
Build : 6
Exec : ofTutorial3
Date : Apr 06 2019
Time : 20:44:02
Host : "zhoudq-MacBookAir"
PID : 3065
I/O : uncollated
Case : /home/zhoudq/OpenFOAM/BasicOpenFOAMProgrammingTutorials/OFtutorial03_understandingTheMesh/testCase
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
Hello there, the most recent time folder found is 0
The mesh has 400 cells and 760 internal faces in it. Wubalubadubdub!
Cell 0 with centre at (0.0025 0.0025 0.005)
Cell 20 with centre at (0.0025 0.0075 0.005)
Cell 40 with centre at (0.0025 0.0125 0.005)
Cell 60 with centre at (0.0025 0.0175 0.005)
Cell 80 with centre at (0.0025 0.0225 0.005)
Cell 100 with centre at (0.0025 0.0275 0.005)
Cell 120 with centre at (0.0025 0.0325 0.005)
Cell 140 with centre at (0.0025 0.0375 0.005)
Cell 160 with centre at (0.0025 0.0425 0.005)
Cell 180 with centre at (0.0025 0.0475 0.005)
Cell 200 with centre at (0.0025 0.0525 0.005)
Cell 220 with centre at (0.0025 0.0575 0.005)
Cell 240 with centre at (0.0025 0.0625 0.005)
Cell 260 with centre at (0.0025 0.0675 0.005)
Cell 280 with centre at (0.0025 0.0725 0.005)
Cell 300 with centre at (0.0025 0.0775 0.005)
Cell 320 with centre at (0.0025 0.0825 0.005)
Cell 340 with centre at (0.0025 0.0875 0.005)
Cell 360 with centre at (0.0025 0.0925 0.005)
Cell 380 with centre at (0.0025 0.0975 0.005)
Internal face 0 with centre at (0.005 0.0025 0.005) with owner cell 0 and neighbour 1
Internal face 40 with centre at (0.0025 0.01 0.005) with owner cell 20 and neighbour 40
Internal face 80 with centre at (0.01 0.0125 0.005) with owner cell 41 and neighbour 42
Internal face 120 with centre at (0.0075 0.02 0.005) with owner cell 61 and neighbour 81
Internal face 160 with centre at (0.015 0.0225 0.005) with owner cell 82 and neighbour 83
Internal face 200 with centre at (0.0125 0.03 0.005) with owner cell 102 and neighbour 122
Internal face 240 with centre at (0.02 0.0325 0.005) with owner cell 123 and neighbour 124
Internal face 280 with centre at (0.0175 0.04 0.005) with owner cell 143 and neighbour 163
Internal face 320 with centre at (0.025 0.0425 0.005) with owner cell 164 and neighbour 165
Internal face 360 with centre at (0.0225 0.05 0.005) with owner cell 184 and neighbour 204
Internal face 400 with centre at (0.03 0.0525 0.005) with owner cell 205 and neighbour 206
Internal face 440 with centre at (0.0275 0.06 0.005) with owner cell 225 and neighbour 245
Internal face 480 with centre at (0.035 0.0625 0.005) with owner cell 246 and neighbour 247
Internal face 520 with centre at (0.0325 0.07 0.005) with owner cell 266 and neighbour 286
Internal face 560 with centre at (0.04 0.0725 0.005) with owner cell 287 and neighbour 288
Internal face 600 with centre at (0.0375 0.08 0.005) with owner cell 307 and neighbour 327
Internal face 640 with centre at (0.045 0.0825 0.005) with owner cell 328 and neighbour 329
Internal face 680 with centre at (0.0425 0.09 0.005) with owner cell 348 and neighbour 368
Internal face 720 with centre at (0.05 0.0925 0.005) with owner cell 369 and neighbour 370
Patch 0: movingWall with 20 faces. Starts at total face 760
Patch 1: fixedWalls with 60 faces. Starts at total face 780
Patch 2: frontAndBack with 800 faces. Starts at total face 840
Patch 0 has its face 0 adjacent to cell 380. It has normal vector (0 5e-05 0) and surface area 5e-05
Patch 1 has its face 0 adjacent to cell 0. It has normal vector (-5e-05 0 0) and surface area 5e-05
Patch 2 has its face 0 adjacent to cell 0. It has normal vector (0 0 -2.5e-05) and surface area 2.5e-05
Internal face 0 with centre at (0.005 0.0025 0.005) has 4 vertices: (0.005 0 0) (0.005 0.005 0) (0.005 0.005 0.01) (0.005 0 0.01)
Internal face 80 with centre at (0.01 0.0125 0.005) has 4 vertices: (0.01 0.01 0) (0.01 0.015 0) (0.01 0.015 0.01) (0.01 0.01 0.01)
Internal face 160 with centre at (0.015 0.0225 0.005) has 4 vertices: (0.015 0.02 0) (0.015 0.025 0) (0.015 0.025 0.01) (0.015 0.02 0.01)
Internal face 240 with centre at (0.02 0.0325 0.005) has 4 vertices: (0.02 0.03 0) (0.02 0.035 0) (0.02 0.035 0.01) (0.02 0.03 0.01)
Internal face 320 with centre at (0.025 0.0425 0.005) has 4 vertices: (0.025 0.04 0) (0.025 0.045 0) (0.025 0.045 0.01) (0.025 0.04 0.01)
Internal face 400 with centre at (0.03 0.0525 0.005) has 4 vertices: (0.03 0.05 0) (0.03 0.055 0) (0.03 0.055 0.01) (0.03 0.05 0.01)
Internal face 480 with centre at (0.035 0.0625 0.005) has 4 vertices: (0.035 0.06 0) (0.035 0.065 0) (0.035 0.065 0.01) (0.035 0.06 0.01)
Internal face 560 with centre at (0.04 0.0725 0.005) has 4 vertices: (0.04 0.07 0) (0.04 0.075 0) (0.04 0.075 0.01) (0.04 0.07 0.01)
Internal face 640 with centre at (0.045 0.0825 0.005) has 4 vertices: (0.045 0.08 0) (0.045 0.085 0) (0.045 0.085 0.01) (0.045 0.08 0.01)
Internal face 720 with centre at (0.05 0.0925 0.005) has 4 vertices: (0.05 0.09 0) (0.05 0.095 0) (0.05 0.095 0.01) (0.05 0.09 0.01)
Face on patch 1, faceI 800 with centre at (0.1 0.0025 0.005) has 4 vertices: (0.1 0 0) (0.1 0.005 0) (0.1 0.005 0.01) (0.1 0 0.01)
Face on patch 2, faceI 880 with centre at (0.0125 0.0025 0) has 4 vertices: (0.01 0 0) (0.01 0.005 0) (0.015 0.005 0) (0.015 0 0)
Face on patch 2, faceI 960 with centre at (0.0325 0.0025 0) has 4 vertices: (0.03 0 0) (0.03 0.005 0) (0.035 0.005 0) (0.035 0 0)
Face on patch 2, faceI 1040 with centre at (0.0525 0.0025 0) has 4 vertices: (0.05 0 0) (0.05 0.005 0) (0.055 0.005 0) (0.055 0 0)
Face on patch 2, faceI 1120 with centre at (0.0725 0.0025 0) has 4 vertices: (0.07 0 0) (0.07 0.005 0) (0.075 0.005 0) (0.075 0 0)
Face on patch 2, faceI 1200 with centre at (0.0925 0.0025 0) has 4 vertices: (0.09 0 0) (0.09 0.005 0) (0.095 0.005 0) (0.095 0 0)
Face on patch 2, faceI 1280 with centre at (0.0125 0.0025 0.01) has 4 vertices: (0.01 0 0.01) (0.015 0 0.01) (0.015 0.005 0.01) (0.01 0.005 0.01)
Face on patch 2, faceI 1360 with centre at (0.0325 0.0025 0.01) has 4 vertices: (0.03 0 0.01) (0.035 0 0.01) (0.035 0.005 0.01) (0.03 0.005 0.01)
Face on patch 2, faceI 1440 with centre at (0.0525 0.0025 0.01) has 4 vertices: (0.05 0 0.01) (0.055 0 0.01) (0.055 0.005 0.01) (0.05 0.005 0.01)
Face on patch 2, faceI 1520 with centre at (0.0725 0.0025 0.01) has 4 vertices: (0.07 0 0.01) (0.075 0 0.01) (0.075 0.005 0.01) (0.07 0.005 0.01)
Face on patch 2, faceI 1600 with centre at (0.0925 0.0025 0.01) has 4 vertices: (0.09 0 0.01) (0.095 0 0.01) (0.095 0.005 0.01) (0.09 0.005 0.01)
Retrieved patch movingWall at index 0 using its name only.
End