OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

polyMeshInitMesh.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 \*---------------------------------------------------------------------------*/
00026 
00027 #include "polyMesh.H"
00028 
00029 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00030 
00031 void Foam::polyMesh::initMesh()
00032 {
00033     if (debug)
00034     {
00035         Info<< "void polyMesh::initMesh() : "
00036             << "initialising primitiveMesh" << endl;
00037     }
00038 
00039     // For backward compatibility check if the neighbour array is the same
00040     // length as the owner and shrink to remove the -1s padding
00041     if (neighbour_.size() == owner_.size())
00042     {
00043         label nInternalFaces = 0;
00044 
00045         forAll(neighbour_, faceI)
00046         {
00047             if (neighbour_[faceI] == -1)
00048             {
00049                 break;
00050             }
00051             else
00052             {
00053                 nInternalFaces++;
00054             }
00055         }
00056 
00057         neighbour_.setSize(nInternalFaces);
00058     }
00059 
00060     label nCells = -1;
00061 
00062     forAll(owner_, facei)
00063     {
00064         nCells = max(nCells, owner_[facei]);
00065     }
00066 
00067     // The neighbour array may or may not be the same length as the owner
00068     forAll(neighbour_, facei)
00069     {
00070         nCells = max(nCells, neighbour_[facei]);
00071     }
00072 
00073     nCells++;
00074 
00075     // Reset the primitiveMesh with the sizes of the primitive arrays
00076     primitiveMesh::reset
00077     (
00078         points_.size(),
00079         neighbour_.size(),
00080         owner_.size(),
00081         nCells
00082     );
00083 
00084     string meshInfo =
00085         "nPoints:" + Foam::name(nPoints())
00086       + "  nCells:" + Foam::name(this->nCells())
00087       + "  nFaces:" + Foam::name(nFaces())
00088       + "  nInternalFaces:" + Foam::name(nInternalFaces());
00089 
00090     owner_.note() = meshInfo;
00091     neighbour_.note() = meshInfo;
00092 }
00093 
00094 
00095 void Foam::polyMesh::initMesh(cellList& c)
00096 {
00097     if (debug)
00098     {
00099         Info<< "void polyMesh::initMesh(cellList& c) : "
00100             << "calculating owner-neighbour arrays" << endl;
00101     }
00102 
00103     owner_.setSize(faces_.size(), -1);
00104     neighbour_.setSize(faces_.size(), -1);
00105 
00106     boolList markedFaces(faces_.size(), false);
00107 
00108     label nInternalFaces = 0;
00109 
00110     forAll(c, cellI)
00111     {
00112         // get reference to face labels for current cell
00113         const labelList& cellfaces = c[cellI];
00114 
00115         forAll (cellfaces, faceI)
00116         {
00117             if (!markedFaces[cellfaces[faceI]])
00118             {
00119                 // First visit: owner
00120                 owner_[cellfaces[faceI]] = cellI;
00121                 markedFaces[cellfaces[faceI]] = true;
00122             }
00123             else
00124             {
00125                 // Second visit: neighbour
00126                 neighbour_[cellfaces[faceI]] = cellI;
00127                 nInternalFaces++;
00128             }
00129         }
00130     }
00131 
00132     // The neighbour array is initialised with the same length as the owner
00133     // padded with -1s and here it is truncated to the correct size of the
00134     // number of internal faces.
00135     neighbour_.setSize(nInternalFaces);
00136 
00137     // Reset the primitiveMesh
00138     primitiveMesh::reset
00139     (
00140         points_.size(),
00141         neighbour_.size(),
00142         owner_.size(),
00143         c.size(),
00144         c
00145     );
00146 
00147     string meshInfo =
00148         "nPoints: " + Foam::name(nPoints())
00149       + " nCells: " + Foam::name(nCells())
00150       + " nFaces: " + Foam::name(nFaces())
00151       + " nInternalFaces: " + Foam::name(this->nInternalFaces());
00152 
00153     owner_.note() = meshInfo;
00154     neighbour_.note() = meshInfo;
00155 }
00156 
00157 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd