2019-04-06

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 <http://www.gnu.org/licenses/>.

\*---------------------------------------------------------------------------*/

#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<point>& pts = mesh.points();
    const List<point>& cents = mesh.faceCentres();

    forAll(fcs,faceI)
        if (faceI%80==0)
        {
            if (faceI<mesh.Cf().size())
                Info << "Internal face ";
            else
            {
                forAll(mesh.boundary(),patchI)
                    if ((mesh.boundary()[patchI].start()<= faceI) &&
                        (faceI < mesh.boundary()[patchI].start()+mesh.boundary()[patchI].Cf().size()))
                    {
                        Info << "Face on patch " << patchI << ", faceI ";
                        break; // exit the forAll loop prematurely
                    }
            }

            Info << faceI << " with centre at " << cents[faceI]
                 << " has " << fcs[faceI].size() << " vertices:";
            forAll(fcs[faceI],vertexI)
                // Note how fcs[faceI] holds the indices of points whose coordinates
                // are stored in the pts list.
                Info << " " << pts[fcs[faceI][vertexI]];
            Info << endl;
        }
    Info << endl;

    // In the original cavity tutorial, on which the test case is based,
    // the frontAndBack boundary is defined as and "empty" type. This is a special
    // BC case which may cause unexpected behaviour as its .Cf() field has size of 0.
    // Type of a patch may be checked to avoid running into this problem if there
    // is a substantial risk that an empty patch type will appear
    label patchID(0);
    const polyPatch& pp = mesh.boundaryMesh()[patchID];
    if (isA<emptyPolyPatch>(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
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 204,293评论 6 478
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 85,604评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 150,958评论 0 337
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,729评论 1 277
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,719评论 5 366
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,630评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,000评论 3 397
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,665评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,909评论 1 299
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,646评论 2 321
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,726评论 1 330
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,400评论 4 321
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,986评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,959评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,197评论 1 260
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 44,996评论 2 349
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,481评论 2 342

推荐阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 7,283评论 0 10
  • 文|四号巷口的厨子 最近身边有几位朋友正面临爱情的问题,忽然有感而来,就写下这篇文章。 我也害怕,感情经验不丰富的...
    四号巷口的厨子阅读 444评论 0 3