initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / finiteVolume / fvMesh / extendedStencil / cellToCell / fullStencils / CFCCellToCellStencil.C
blob7c718cacfd44256700210b1740abe0190da989b2
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM is free software; you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "CFCCellToCellStencil.H"
28 #include "syncTools.H"
29 #include "SortableList.H"
30 #include "emptyPolyPatch.H"
32 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
34 // Calculates per face the neighbour data (= cell or boundary face)
35 void Foam::CFCCellToCellStencil::calcFaceBoundaryData
37     labelList& neiGlobal
38 ) const
40     const polyBoundaryMesh& patches = mesh().boundaryMesh();
41     const label nBnd = mesh().nFaces()-mesh().nInternalFaces();
42     const labelList& own = mesh().faceOwner();
44     neiGlobal.setSize(nBnd);
46     forAll(patches, patchI)
47     {
48         const polyPatch& pp = patches[patchI];
49         label faceI = pp.start();
51         if (pp.coupled())
52         {
53             // For coupled faces get the cell on the other side
54             forAll(pp, i)
55             {
56                 label bFaceI = faceI-mesh().nInternalFaces(); 
57                 neiGlobal[bFaceI] = globalNumbering().toGlobal(own[faceI]);
58                 faceI++;
59             }
60         }
61         else if (isA<emptyPolyPatch>(pp))
62         {
63             forAll(pp, i)
64             {
65                 label bFaceI = faceI-mesh().nInternalFaces(); 
66                 neiGlobal[bFaceI] = -1;
67                 faceI++;
68             }
69         }
70         else
71         {
72             // For noncoupled faces get the boundary face.
73             forAll(pp, i)
74             {
75                 label bFaceI = faceI-mesh().nInternalFaces(); 
76                 neiGlobal[bFaceI] =
77                     globalNumbering().toGlobal(mesh().nCells()+bFaceI);
78                 faceI++;
79             }
80         }
81     }
82     syncTools::swapBoundaryFaceList(mesh(), neiGlobal, false);
86 // Calculates per cell the neighbour data (= cell or boundary in global
87 // numbering). First element is always cell itself!
88 void Foam::CFCCellToCellStencil::calcCellStencil(labelListList& globalCellCells)
89  const
91     const label nBnd = mesh().nFaces()-mesh().nInternalFaces();
92     const labelList& own = mesh().faceOwner();
93     const labelList& nei = mesh().faceNeighbour();
96     // Calculate coupled neighbour (in global numbering)
97     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
99     labelList neiGlobal(nBnd);
100     calcFaceBoundaryData(neiGlobal);
103     // Determine cellCells in global numbering
104     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
106     globalCellCells.setSize(mesh().nCells());
107     forAll(globalCellCells, cellI)
108     {
109         const cell& cFaces = mesh().cells()[cellI];
111         labelList& cCells = globalCellCells[cellI];
113         cCells.setSize(cFaces.size()+1);
115         label nNbr = 0;
117         // Myself
118         cCells[nNbr++] = globalNumbering().toGlobal(cellI);
120         // Collect neighbouring cells/faces
121         forAll(cFaces, i)
122         {
123             label faceI = cFaces[i];
125             if (mesh().isInternalFace(faceI))
126             {
127                 label nbrCellI = own[faceI];
128                 if (nbrCellI == cellI)
129                 {
130                     nbrCellI = nei[faceI];
131                 }
132                 cCells[nNbr++] = globalNumbering().toGlobal(nbrCellI);
133             }
134             else
135             {
136                 label nbrCellI = neiGlobal[faceI-mesh().nInternalFaces()];
137                 if (nbrCellI != -1)
138                 {
139                     cCells[nNbr++] = nbrCellI;
140                 }
141             }
142         }
143         cCells.setSize(nNbr);
144     }
148 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
150 Foam::CFCCellToCellStencil::CFCCellToCellStencil(const polyMesh& mesh)
152     cellToCellStencil(mesh)
154     // Calculate per cell the (face) connected cells (in global numbering)
155     calcCellStencil(*this);
159 // ************************************************************************* //