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 "primitiveMesh.H"
00027 #include <OpenFOAM/cell.H>
00028
00029
00030
00031
00032
00033 bool Foam::primitiveMesh::pointInCellBB(const point& p, label celli) const
00034 {
00035 const pointField& points = this->points();
00036 const faceList& f = faces();
00037 const vectorField& centres = cellCentres();
00038 const cellList& cf = cells();
00039
00040 labelList cellVertices = cf[celli].labels(f);
00041
00042 vector bbmax = -GREAT*vector::one;
00043 vector bbmin = GREAT*vector::one;
00044
00045 forAll (cellVertices, vertexI)
00046 {
00047 bbmax = max(bbmax, points[cellVertices[vertexI]]);
00048 bbmin = min(bbmin, points[cellVertices[vertexI]]);
00049 }
00050
00051 scalar distance = mag(centres[celli] - p);
00052
00053 if ((distance - mag(bbmax - bbmin)) < SMALL)
00054 {
00055 return true;
00056 }
00057 else
00058 {
00059 return false;
00060 }
00061 }
00062
00063
00064
00065 bool Foam::primitiveMesh::pointInCell(const point& p, label celli) const
00066 {
00067 const labelList& f = cells()[celli];
00068 const labelList& owner = this->faceOwner();
00069 const vectorField& cf = faceCentres();
00070 const vectorField& Sf = faceAreas();
00071
00072 bool inCell = true;
00073
00074 forAll(f, facei)
00075 {
00076 label nFace = f[facei];
00077 vector proj = p - cf[nFace];
00078 vector normal = Sf[nFace];
00079 if (owner[nFace] != celli)
00080 {
00081 normal = -normal;
00082 }
00083 inCell = inCell && ((normal & proj) <= 0);
00084 }
00085
00086 return inCell;
00087 }
00088
00089
00090
00091 Foam::label Foam::primitiveMesh::findNearestCell(const point& location) const
00092 {
00093 const vectorField& centres = cellCentres();
00094
00095 label nearestCelli = 0;
00096 scalar minProximity = magSqr(centres[0] - location);
00097
00098 for (label celli = 1; celli < centres.size(); celli++)
00099 {
00100 scalar proximity = magSqr(centres[celli] - location);
00101
00102 if (proximity < minProximity)
00103 {
00104 nearestCelli = celli;
00105 minProximity = proximity;
00106 }
00107 }
00108
00109 return nearestCelli;
00110 }
00111
00112
00113
00114 Foam::label Foam::primitiveMesh::findCell(const point& location) const
00115 {
00116 if (nCells() == 0)
00117 {
00118 return -1;
00119 }
00120
00121
00122 label celli = findNearestCell(location);
00123
00124
00125 if (pointInCell(location, celli))
00126 {
00127 return celli;
00128 }
00129 else
00130 {
00131 bool cellFound = false;
00132 label n = 0;
00133
00134 while ((!cellFound) && (n < nCells()))
00135 {
00136 if (pointInCell(location, n))
00137 {
00138 cellFound = true;
00139 celli = n;
00140 }
00141 else
00142 {
00143 n++;
00144 }
00145 }
00146 if (cellFound)
00147 {
00148 return celli;
00149 }
00150 else
00151 {
00152 return -1;
00153 }
00154 }
00155 }
00156
00157
00158