1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend 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 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "lduAddressing.H"
27 #include "demandDrivenData.H"
29 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
31 void Foam::lduAddressing::calcLosort() const
35 FatalErrorIn("lduAddressing::calcLosort() const")
36 << "losort already calculated"
40 // Scan the neighbour list to find out how many times the cell
41 // appears as a neighbour of the face. Done this way to avoid guessing
43 labelList nNbrOfFace(size(), 0);
45 const unallocLabelList& nbr = upperAddr();
49 nNbrOfFace[nbr[nbrI]]++;
52 // Create temporary neighbour addressing
53 labelListList cellNbrFaces(size());
55 forAll (cellNbrFaces, cellI)
57 cellNbrFaces[cellI].setSize(nNbrOfFace[cellI]);
60 // Reset the list of number of neighbours to zero
63 // Scatter the neighbour faces
66 cellNbrFaces[nbr[nbrI]][nNbrOfFace[nbr[nbrI]]] = nbrI;
68 nNbrOfFace[nbr[nbrI]]++;
71 // Gather the neighbours into the losort array
72 losortPtr_ = new labelList(nbr.size(), -1);
74 labelList& lst = *losortPtr_;
76 // Set counter for losort
79 forAll (cellNbrFaces, cellI)
81 const labelList& curNbr = cellNbrFaces[cellI];
83 forAll (curNbr, curNbrI)
85 lst[lstI] = curNbr[curNbrI];
92 void Foam::lduAddressing::calcOwnerStart() const
96 FatalErrorIn("lduAddressing::calcOwnerStart() const")
97 << "owner start already calculated"
101 const labelList& own = lowerAddr();
103 ownerStartPtr_ = new labelList(size() + 1, own.size());
105 labelList& ownStart = *ownerStartPtr_;
107 // Set up first lookup by hand
114 label curOwn = own[faceI];
116 if (curOwn > nOwnStart)
120 ownStart[i++] = faceI;
129 void Foam::lduAddressing::calcLosortStart() const
133 FatalErrorIn("lduAddressing::calcLosortStart() const")
134 << "losort start already calculated"
135 << abort(FatalError);
138 losortStartPtr_ = new labelList(size() + 1, 0);
140 labelList& lsrtStart = *losortStartPtr_;
142 const labelList& nbr = upperAddr();
144 const labelList& lsrt = losortAddr();
146 // Set up first lookup by hand
148 label nLsrtStart = 0;
154 const label curNbr = nbr[lsrt[faceI]];
156 if (curNbr > nLsrtStart)
160 lsrtStart[i++] = faceI;
167 // Set up last lookup by hand
168 lsrtStart[size()] = nbr.size();
172 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
174 Foam::lduAddressing::~lduAddressing()
176 deleteDemandDrivenData(losortPtr_);
177 deleteDemandDrivenData(ownerStartPtr_);
178 deleteDemandDrivenData(losortStartPtr_);
182 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
184 const Foam::unallocLabelList& Foam::lduAddressing::losortAddr() const
195 const Foam::unallocLabelList& Foam::lduAddressing::ownerStartAddr() const
202 return *ownerStartPtr_;
206 const Foam::unallocLabelList& Foam::lduAddressing::losortStartAddr() const
208 if (!losortStartPtr_)
213 return *losortStartPtr_;
217 // Return edge index given owner and neighbour label
218 Foam::label Foam::lduAddressing::triIndex(const label a, const label b) const
220 label own = min(a, b);
222 label nbr = max(a, b);
224 label startLabel = ownerStartAddr()[own];
226 label endLabel = ownerStartAddr()[own + 1];
228 const unallocLabelList& neighbour = upperAddr();
230 for (label i = startLabel; i < endLabel; i++)
232 if (neighbour[i] == nbr)
238 // If neighbour has not been found, something has gone seriously
239 // wrong with the addressing mechanism
242 "lduAddressing::triIndex(const label owner, const label nbr) const"
243 ) << "neighbour " << nbr << " not found for owner " << own << ". "
244 << "Problem with addressing"
245 << abort(FatalError);
251 // ************************************************************************* //