FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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-2010 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
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your 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, see <http://www.gnu.org/licenses/>.
00023 
00024 \*---------------------------------------------------------------------------*/
00025 
00026 #include "polyMesh.H"
00027 
00028 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00029 
00030 void Foam::polyMesh::initMesh()
00031 {
00032     if (debug)
00033     {
00034         Info<< "void polyMesh::initMesh() : "
00035             << "initialising primitiveMesh" << endl;
00036     }
00037 
00038     // For backward compatibility check if the neighbour array is the same
00039     // length as the owner and shrink to remove the -1s padding
00040     if (neighbour_.size() == owner_.size())
00041     {
00042         label nInternalFaces = 0;
00043 
00044         forAll(neighbour_, faceI)
00045         {
00046             if (neighbour_[faceI] == -1)
00047             {
00048                 break;
00049             }
00050             else
00051             {
00052                 nInternalFaces++;
00053             }
00054         }
00055 
00056         neighbour_.setSize(nInternalFaces);
00057     }
00058 
00059     label nCells = -1;
00060 
00061     forAll(owner_, facei)
00062     {
00063         nCells = max(nCells, owner_[facei]);
00064     }
00065 
00066     // The neighbour array may or may not be the same length as the owner
00067     forAll(neighbour_, facei)
00068     {
00069         nCells = max(nCells, neighbour_[facei]);
00070     }
00071 
00072     nCells++;
00073 
00074     // Reset the primitiveMesh with the sizes of the primitive arrays
00075     primitiveMesh::reset
00076     (
00077         points_.size(),
00078         neighbour_.size(),
00079         owner_.size(),
00080         nCells
00081     );
00082 
00083     string meshInfo =
00084         "nPoints:" + Foam::name(nPoints())
00085       + "  nCells:" + Foam::name(this->nCells())
00086       + "  nFaces:" + Foam::name(nFaces())
00087       + "  nInternalFaces:" + Foam::name(nInternalFaces());
00088 
00089     owner_.note() = meshInfo;
00090     neighbour_.note() = meshInfo;
00091 }
00092 
00093 
00094 void Foam::polyMesh::initMesh(cellList& c)
00095 {
00096     if (debug)
00097     {
00098         Info<< "void polyMesh::initMesh(cellList& c) : "
00099             << "calculating owner-neighbour arrays" << endl;
00100     }
00101 
00102     owner_.setSize(faces_.size(), -1);
00103     neighbour_.setSize(faces_.size(), -1);
00104 
00105     boolList markedFaces(faces_.size(), false);
00106 
00107     label nInternalFaces = 0;
00108 
00109     forAll(c, cellI)
00110     {
00111         // get reference to face labels for current cell
00112         const labelList& cellfaces = c[cellI];
00113 
00114         forAll (cellfaces, faceI)
00115         {
00116             if (!markedFaces[cellfaces[faceI]])
00117             {
00118                 // First visit: owner
00119                 owner_[cellfaces[faceI]] = cellI;
00120                 markedFaces[cellfaces[faceI]] = true;
00121             }
00122             else
00123             {
00124                 // Second visit: neighbour
00125                 neighbour_[cellfaces[faceI]] = cellI;
00126                 nInternalFaces++;
00127             }
00128         }
00129     }
00130 
00131     // The neighbour array is initialised with the same length as the owner
00132     // padded with -1s and here it is truncated to the correct size of the
00133     // number of internal faces.
00134     neighbour_.setSize(nInternalFaces);
00135 
00136     // Reset the primitiveMesh
00137     primitiveMesh::reset
00138     (
00139         points_.size(),
00140         neighbour_.size(),
00141         owner_.size(),
00142         c.size(),
00143         c
00144     );
00145 
00146     string meshInfo =
00147         "nPoints: " + Foam::name(nPoints())
00148       + " nCells: " + Foam::name(nCells())
00149       + " nFaces: " + Foam::name(nFaces())
00150       + " nInternalFaces: " + Foam::name(this->nInternalFaces());
00151 
00152     owner_.note() = meshInfo;
00153     neighbour_.note() = meshInfo;
00154 }
00155 
00156 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines