Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "lduAddressing.H"
00027 #include <OpenFOAM/demandDrivenData.H>
00028
00029
00030
00031 void Foam::lduAddressing::calcLosort() const
00032 {
00033 if (losortPtr_)
00034 {
00035 FatalErrorIn("lduAddressing::calcLosort() const")
00036 << "losort already calculated"
00037 << abort(FatalError);
00038 }
00039
00040
00041
00042
00043 labelList nNbrOfFace(size(), 0);
00044
00045 const unallocLabelList& nbr = upperAddr();
00046
00047 forAll (nbr, nbrI)
00048 {
00049 nNbrOfFace[nbr[nbrI]]++;
00050 }
00051
00052
00053 labelListList cellNbrFaces(size());
00054
00055 forAll (cellNbrFaces, cellI)
00056 {
00057 cellNbrFaces[cellI].setSize(nNbrOfFace[cellI]);
00058 }
00059
00060
00061 nNbrOfFace = 0;
00062
00063
00064 forAll (nbr, nbrI)
00065 {
00066 cellNbrFaces[nbr[nbrI]][nNbrOfFace[nbr[nbrI]]] = nbrI;
00067
00068 nNbrOfFace[nbr[nbrI]]++;
00069 }
00070
00071
00072 losortPtr_ = new labelList(nbr.size(), -1);
00073
00074 labelList& lst = *losortPtr_;
00075
00076
00077 label lstI = 0;
00078
00079 forAll (cellNbrFaces, cellI)
00080 {
00081 const labelList& curNbr = cellNbrFaces[cellI];
00082
00083 forAll (curNbr, curNbrI)
00084 {
00085 lst[lstI] = curNbr[curNbrI];
00086 lstI++;
00087 }
00088 }
00089 }
00090
00091
00092 void Foam::lduAddressing::calcOwnerStart() const
00093 {
00094 if (ownerStartPtr_)
00095 {
00096 FatalErrorIn("lduAddressing::calcOwnerStart() const")
00097 << "owner start already calculated"
00098 << abort(FatalError);
00099 }
00100
00101 const labelList& own = lowerAddr();
00102
00103 ownerStartPtr_ = new labelList(size() + 1, own.size());
00104
00105 labelList& ownStart = *ownerStartPtr_;
00106
00107
00108 ownStart[0] = 0;
00109 label nOwnStart = 0;
00110 label i = 1;
00111
00112 forAll (own, faceI)
00113 {
00114 label curOwn = own[faceI];
00115
00116 if (curOwn > nOwnStart)
00117 {
00118 while (i <= curOwn)
00119 {
00120 ownStart[i++] = faceI;
00121 }
00122
00123 nOwnStart = curOwn;
00124 }
00125 }
00126 }
00127
00128
00129 void Foam::lduAddressing::calcLosortStart() const
00130 {
00131 if (losortStartPtr_)
00132 {
00133 FatalErrorIn("lduAddressing::calcLosortStart() const")
00134 << "losort start already calculated"
00135 << abort(FatalError);
00136 }
00137
00138 losortStartPtr_ = new labelList(size() + 1, 0);
00139
00140 labelList& lsrtStart = *losortStartPtr_;
00141
00142 const labelList& nbr = upperAddr();
00143
00144 const labelList& lsrt = losortAddr();
00145
00146
00147 lsrtStart[0] = 0;
00148 label nLsrtStart = 0;
00149 label i = 0;
00150
00151 forAll (lsrt, faceI)
00152 {
00153
00154 const label curNbr = nbr[lsrt[faceI]];
00155
00156 if (curNbr > nLsrtStart)
00157 {
00158 while (i <= curNbr)
00159 {
00160 lsrtStart[i++] = faceI;
00161 }
00162
00163 nLsrtStart = curNbr;
00164 }
00165 }
00166
00167
00168 lsrtStart[size()] = nbr.size();
00169 }
00170
00171
00172
00173
00174 Foam::lduAddressing::~lduAddressing()
00175 {
00176 deleteDemandDrivenData(losortPtr_);
00177 deleteDemandDrivenData(ownerStartPtr_);
00178 deleteDemandDrivenData(losortStartPtr_);
00179 }
00180
00181
00182
00183
00184 const Foam::unallocLabelList& Foam::lduAddressing::losortAddr() const
00185 {
00186 if (!losortPtr_)
00187 {
00188 calcLosort();
00189 }
00190
00191 return *losortPtr_;
00192 }
00193
00194
00195 const Foam::unallocLabelList& Foam::lduAddressing::ownerStartAddr() const
00196 {
00197 if (!ownerStartPtr_)
00198 {
00199 calcOwnerStart();
00200 }
00201
00202 return *ownerStartPtr_;
00203 }
00204
00205
00206 const Foam::unallocLabelList& Foam::lduAddressing::losortStartAddr() const
00207 {
00208 if (!losortStartPtr_)
00209 {
00210 calcLosortStart();
00211 }
00212
00213 return *losortStartPtr_;
00214 }
00215
00216
00217
00218 Foam::label Foam::lduAddressing::triIndex(const label a, const label b) const
00219 {
00220 label own = min(a, b);
00221
00222 label nbr = max(a, b);
00223
00224 label startLabel = ownerStartAddr()[own];
00225
00226 label endLabel = ownerStartAddr()[own + 1];
00227
00228 const unallocLabelList& neighbour = upperAddr();
00229
00230 for (label i = startLabel; i < endLabel; i++)
00231 {
00232 if (neighbour[i] == nbr)
00233 {
00234 return i;
00235 }
00236 }
00237
00238
00239
00240 FatalErrorIn
00241 (
00242 "lduAddressing::triIndex(const label owner, const label nbr) const"
00243 ) << "neighbour " << nbr << " not found for owner " << own << ". "
00244 << "Problem with addressing"
00245 << abort(FatalError);
00246
00247 return -1;
00248 }
00249
00250
00251