cell.C
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
00027 #include "cell.H"
00028 #include "pyramidPointFaceRef.H"
00029
00030
00031
00032 const char* const Foam::cell::typeName = "cell";
00033
00034
00035
00036 Foam::labelList Foam::cell::labels(const unallocFaceList& f) const
00037 {
00038
00039
00040
00041 label maxVert = 0;
00042
00043 const labelList& faces = *this;
00044
00045 forAll (faces, faceI)
00046 {
00047 maxVert += f[faces[faceI]].size();
00048 }
00049
00050
00051 labelList p(maxVert);
00052
00053
00054 const labelList& first = f[faces[0]];
00055
00056 forAll (first, pointI)
00057 {
00058 p[pointI] = first[pointI];
00059 }
00060
00061
00062 maxVert = first.size();
00063
00064
00065
00066
00067 for (label faceI = 1; faceI < faces.size(); faceI++)
00068 {
00069 const labelList& curFace = f[faces[faceI]];
00070
00071 forAll (curFace, pointI)
00072 {
00073 const label curPoint = curFace[pointI];
00074
00075 bool found = false;
00076
00077 for (register label checkI = 0; checkI < maxVert; checkI++)
00078 {
00079 if (curPoint == p[checkI])
00080 {
00081 found = true;
00082 break;
00083 }
00084 }
00085
00086 if (!found)
00087 {
00088 p[maxVert] = curPoint;
00089
00090 maxVert++;
00091 }
00092 }
00093 }
00094
00095
00096 p.setSize(maxVert);
00097
00098 return p;
00099 }
00100
00101
00102 Foam::pointField Foam::cell::points
00103 (
00104 const unallocFaceList& f,
00105 const pointField& meshPoints
00106 ) const
00107 {
00108 labelList pointLabels = labels(f);
00109
00110 pointField p(pointLabels.size());
00111
00112 forAll(p, i)
00113 {
00114 p[i] = meshPoints[pointLabels[i]];
00115 }
00116
00117 return p;
00118 }
00119
00120
00121 Foam::edgeList Foam::cell::edges(const unallocFaceList& f) const
00122 {
00123
00124
00125 const labelList& curFaces = *this;
00126
00127
00128 label maxNoEdges = 0;
00129
00130 forAll (curFaces, faceI)
00131 {
00132 maxNoEdges += f[curFaces[faceI]].nEdges();
00133 }
00134
00135 edgeList allEdges(maxNoEdges);
00136 label nEdges = 0;
00137
00138 forAll (curFaces, faceI)
00139 {
00140 const edgeList curFaceEdges = f[curFaces[faceI]].edges();
00141
00142 forAll (curFaceEdges, faceEdgeI)
00143 {
00144 const edge& curEdge = curFaceEdges[faceEdgeI];
00145
00146 bool edgeFound = false;
00147
00148 for (label addedEdgeI = 0; addedEdgeI < nEdges; addedEdgeI++)
00149 {
00150 if (allEdges[addedEdgeI] == curEdge)
00151 {
00152 edgeFound = true;
00153
00154 break;
00155 }
00156 }
00157
00158 if (!edgeFound)
00159 {
00160
00161 allEdges[nEdges] = curEdge;
00162 nEdges++;
00163 }
00164 }
00165 }
00166
00167 allEdges.setSize(nEdges);
00168
00169 return allEdges;
00170 }
00171
00172
00173 Foam::point Foam::cell::centre
00174 (
00175 const pointField& p,
00176 const unallocFaceList& f
00177 ) const
00178 {
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196 vector cEst = vector::zero;
00197 scalar sumArea = 0;
00198
00199 const labelList& faces = *this;
00200
00201 forAll (faces, faceI)
00202 {
00203 scalar a = f[faces[faceI]].mag(p);
00204 cEst += f[faces[faceI]].centre(p)*a;
00205 sumArea += a;
00206 }
00207
00208 cEst /= sumArea + VSMALL;
00209
00210
00211
00212 vector sumVc = vector::zero;
00213
00214 scalar sumV = 0;
00215
00216 forAll (faces, faceI)
00217 {
00218
00219
00220
00221 scalar pyrVol = pyramidPointFaceRef(f[faces[faceI]], cEst).mag(p);
00222 vector pyrCentre = pyramidPointFaceRef(f[faces[faceI]], cEst).centre(p);
00223
00224
00225
00226 if (pyrVol < 0)
00227 {
00228 pyrVol = -pyrVol;
00229 }
00230
00231 sumVc += pyrVol*pyrCentre;
00232 sumV += pyrVol;
00233 }
00234
00235 return sumVc/(sumV + VSMALL);
00236 }
00237
00238
00239 Foam::scalar Foam::cell::mag
00240 (
00241 const pointField& p,
00242 const unallocFaceList& f
00243 ) const
00244 {
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255 vector cEst = vector::zero;
00256 scalar nCellFaces = 0;
00257
00258 const labelList& faces = *this;
00259
00260 forAll (faces, faceI)
00261 {
00262 cEst += f[faces[faceI]].centre(p);
00263 nCellFaces += 1;
00264 }
00265
00266 cEst /= nCellFaces;
00267
00268
00269 scalar v = 0;
00270
00271 forAll (faces, faceI)
00272 {
00273 v += ::Foam::mag(pyramidPointFaceRef(f[faces[faceI]], cEst).mag(p));
00274 }
00275
00276 return v;
00277 }
00278
00279
00280
00281
00282 bool Foam::operator==(const cell& a, const cell& b)
00283 {
00284
00285 if (a.size() != b.size())
00286 {
00287 return false;
00288 }
00289
00290 List<bool> fnd(a.size(), false);
00291
00292 forAll (b, bI)
00293 {
00294 label curLabel = b[bI];
00295
00296 bool found = false;
00297
00298 forAll (a, aI)
00299 {
00300 if (a[aI] == curLabel)
00301 {
00302 found = true;
00303 fnd[aI] = true;
00304 break;
00305 }
00306 }
00307
00308 if (!found)
00309 {
00310 return false;
00311 }
00312 }
00313
00314
00315 bool result = true;
00316
00317 forAll (fnd, aI)
00318 {
00319 result = (result && fnd[aI]);
00320 }
00321
00322 return result;
00323 }
00324
00325
00326
Copyright © 2000-2009 OpenCFD Ltd