1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
7 -------------------------------------------------------------------------------
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
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 "lduAddressing.H"
28 #include "demandDrivenData.H"
30 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
32 void Foam::lduAddressing::calcLosort() const
36 FatalErrorIn("lduAddressing::calcLosort() const")
37 << "losort already calculated"
41 // Scan the neighbour list to find out how many times the cell
42 // appears as a neighbour of the face. Done this way to avoid guessing
44 labelList nNbrOfFace(size(), 0);
46 const unallocLabelList& nbr = upperAddr();
50 nNbrOfFace[nbr[nbrI]]++;
53 // Create temporary neighbour addressing
54 labelListList cellNbrFaces(size());
56 forAll (cellNbrFaces, cellI)
58 cellNbrFaces[cellI].setSize(nNbrOfFace[cellI]);
61 // Reset the list of number of neighbours to zero
64 // Scatter the neighbour faces
67 cellNbrFaces[nbr[nbrI]][nNbrOfFace[nbr[nbrI]]] = nbrI;
69 nNbrOfFace[nbr[nbrI]]++;
72 // Gather the neighbours into the losort array
73 losortPtr_ = new labelList(nbr.size(), -1);
75 labelList& lst = *losortPtr_;
77 // Set counter for losort
80 forAll (cellNbrFaces, cellI)
82 const labelList& curNbr = cellNbrFaces[cellI];
84 forAll (curNbr, curNbrI)
86 lst[lstI] = curNbr[curNbrI];
93 void Foam::lduAddressing::calcOwnerStart() const
97 FatalErrorIn("lduAddressing::calcOwnerStart() const")
98 << "owner start already calculated"
102 const labelList& own = lowerAddr();
104 ownerStartPtr_ = new labelList(size() + 1, own.size());
106 labelList& ownStart = *ownerStartPtr_;
108 // Set up first lookup by hand
115 label curOwn = own[faceI];
117 if (curOwn > nOwnStart)
121 ownStart[i++] = faceI;
130 void Foam::lduAddressing::calcLosortStart() const
134 FatalErrorIn("lduAddressing::calcLosortStart() const")
135 << "losort start already calculated"
136 << abort(FatalError);
139 losortStartPtr_ = new labelList(size() + 1, 0);
141 labelList& lsrtStart = *losortStartPtr_;
143 const labelList& nbr = upperAddr();
145 const labelList& lsrt = losortAddr();
147 // Set up first lookup by hand
149 label nLsrtStart = 0;
155 const label curNbr = nbr[lsrt[faceI]];
157 if (curNbr > nLsrtStart)
161 lsrtStart[i++] = faceI;
168 // Set up last lookup by hand
169 lsrtStart[size()] = nbr.size();
173 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
175 Foam::lduAddressing::~lduAddressing()
177 deleteDemandDrivenData(losortPtr_);
178 deleteDemandDrivenData(ownerStartPtr_);
179 deleteDemandDrivenData(losortStartPtr_);
183 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
185 const Foam::unallocLabelList& Foam::lduAddressing::losortAddr() const
196 const Foam::unallocLabelList& Foam::lduAddressing::ownerStartAddr() const
203 return *ownerStartPtr_;
207 const Foam::unallocLabelList& Foam::lduAddressing::losortStartAddr() const
209 if (!losortStartPtr_)
214 return *losortStartPtr_;
218 // Return edge index given owner and neighbour label
219 Foam::label Foam::lduAddressing::triIndex(const label a, const label b) const
221 label own = min(a, b);
223 label nbr = max(a, b);
225 label startLabel = ownerStartAddr()[own];
227 label endLabel = ownerStartAddr()[own + 1];
229 const unallocLabelList& neighbour = upperAddr();
231 for (label i = startLabel; i < endLabel; i++)
233 if (neighbour[i] == nbr)
239 // If neighbour has not been found, something has gone seriously
240 // wrong with the addressing mechanism
243 "lduAddressing::triIndex(const label owner, const label nbr) const"
244 ) << "neighbour " << nbr << " not found for owner " << own << ". "
245 << "Problem with addressing"
246 << abort(FatalError);
252 // ************************************************************************* //