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

calcPointCells.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 Description
00025     Create intermediate mesh files from PROSTAR files
00026 
00027 \*---------------------------------------------------------------------------*/
00028 
00029 #include "starMesh.H"
00030 
00031 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00032 
00033 void starMesh::calcPointCells() const
00034 {
00035     const static label UNIT_POINT_CELLS = 12;
00036 
00037     if (pointCellsPtr_)
00038     {
00039         FatalErrorIn("starMesh::calcPointCells() const")
00040             << "pointCells already calculated"
00041             << abort(FatalError);
00042     }
00043 
00044 
00045     pointCellsPtr_ = new labelListList(points_.size());
00046 
00047     labelListList& pc = *pointCellsPtr_;
00048 
00049     forAll(pc, i)
00050     {
00051         pc[i].setSize(UNIT_POINT_CELLS);
00052     }
00053 
00054     // Initialise the list of labels which will hold the count the
00055     // actual number of cells per point during the analysis
00056     labelList cellCount(points_.size());
00057 
00058     forAll(cellCount, i)
00059     {
00060         cellCount[i] = 0;
00061     }
00062 
00063     // Note. Unlike the standard point-cell algorithm, which asks the cell for
00064     // the supporting point labels, we need to work based on the cell faces.
00065     // This is because some of the faces for meshes with arbitrary interfaces
00066     // do not come from the cell shape, but from the slaves of the coupled
00067     // match. It is also adventageous to remove the duplicates from the
00068     // point-cell addressing, because this removes a lot of waste later.
00069     // 
00070 
00071     // For each cell
00072     forAll(cellShapes_, cellI)
00073     {
00074         const faceList& faces = cellFaces_[cellI];
00075 
00076         forAll (faces, i)
00077         {
00078             // For each vertex
00079             const labelList& labels = faces[i];
00080 
00081             forAll(labels, j)
00082             {
00083                 // Set working point label
00084                 label curPoint = labels[j];
00085                 labelList& curPointCells = pc[curPoint];
00086                 label curCount = cellCount[curPoint];
00087 
00088                 // check if the cell has been added before
00089                 bool found = false;
00090 
00091                 for (label f = 0; f < curCount; f++)
00092                 {
00093                     if (curPointCells[f] == cellI)
00094                     {
00095                         found = true;
00096 
00097                         break;
00098                     }
00099                 }
00100 
00101                 if (!found)
00102                 {
00103 
00104                     // If the list of pointCells is not big enough, double it
00105                     if (curPointCells.size() <= curCount)
00106                     {
00107                         curPointCells.setSize(curPointCells.size()*2);
00108                     }
00109 
00110                     // Enter the cell label in the point's cell list
00111                     curPointCells[curCount] = cellI;
00112 
00113                     // Increment the cell count for the point addressed
00114                     cellCount[curPoint]++;
00115                 }
00116             }
00117         }
00118     }
00119 
00120     // Finally, truncate the lists made to their active size
00121     forAll(pc, i)
00122     {
00123         pc[i].setSize(cellCount[i]);
00124     }
00125 }
00126 
00127 
00128 const labelListList& starMesh::pointCells() const
00129 {
00130     if (!pointCellsPtr_)
00131     {
00132         calcPointCells();
00133     }
00134 
00135     return *pointCellsPtr_;
00136 }
00137 
00138 
00139 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines