PatchToolsCheck.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 "PatchTools.H"
00028
00029
00030
00031 template
00032 <
00033 class Face,
00034 template<class> class FaceList,
00035 class PointField,
00036 class PointType
00037 >
00038
00039 bool
00040 Foam::PatchTools::checkOrientation
00041 (
00042 const PrimitivePatch<Face, FaceList, PointField, PointType>& p,
00043 const bool report,
00044 labelHashSet* setPtr
00045 )
00046 {
00047 bool foundError = false;
00048
00049
00050 forAll(p.faceEdges(), faceI)
00051 {
00052 const labelList& edgeLabels = p.faceEdges()[faceI];
00053 bool valid = true;
00054
00055 if (edgeLabels.size() < 3)
00056 {
00057 if (report)
00058 {
00059 Info<< "Face[" << faceI << "] " << p[faceI]
00060 << " has fewer than 3 edges. Edges: " << edgeLabels
00061 << endl;
00062 }
00063 valid = false;
00064 }
00065 else
00066 {
00067 forAll(edgeLabels, i)
00068 {
00069 if (edgeLabels[i] < 0 || edgeLabels[i] >= p.nEdges())
00070 {
00071 if (report)
00072 {
00073 Info<< "edge number " << edgeLabels[i]
00074 << " on face " << faceI
00075 << " out-of-range\n"
00076 << "This usually means the input surface has "
00077 << "edges with more than 2 faces connected."
00078 << endl;
00079 }
00080 valid = false;
00081 }
00082 }
00083 }
00084
00085 if (!valid)
00086 {
00087 foundError = true;
00088 continue;
00089 }
00090
00091
00092
00093
00094
00095 const Face& f = p[faceI];
00096 const point& p0 = p.points()[f[0]];
00097 const point& p1 = p.points()[f[1]];
00098 const point& p2 = p.points()[f[f.size()-1]];
00099
00100 const vector pointNormal((p1 - p0) ^ (p2 - p0));
00101 if ((pointNormal & p.faceNormals()[faceI]) < 0)
00102 {
00103 foundError = false;
00104
00105 if (report)
00106 {
00107 Info
00108 << "Normal calculated from points inconsistent"
00109 << " with faceNormal" << nl
00110 << "face: " << f << nl
00111 << "points: " << p0 << ' ' << p1 << ' ' << p2 << nl
00112 << "pointNormal:" << pointNormal << nl
00113 << "faceNormal:" << p.faceNormals()[faceI] << endl;
00114 }
00115 }
00116 }
00117
00118
00119 forAll(p.edges(), edgeI)
00120 {
00121 const edge& e = p.edges()[edgeI];
00122 const labelList& neighbouringFaces = p.edgeFaces()[edgeI];
00123
00124 if (neighbouringFaces.size() == 2)
00125 {
00126
00127
00128 const Face& faceA = p.localFaces()[neighbouringFaces[0]];
00129 const Face& faceB = p.localFaces()[neighbouringFaces[1]];
00130
00131
00132
00133 if (faceA.edgeDirection(e) == faceB.edgeDirection(e))
00134 {
00135 if (report)
00136 {
00137 Info<< "face orientation incorrect." << nl
00138 << "localEdge[" << edgeI << "] " << e
00139 << " between faces:" << nl
00140 << " face[" << neighbouringFaces[0] << "] "
00141 << p[neighbouringFaces[0]]
00142 << " localFace: " << faceA
00143 << nl
00144 << " face[" << neighbouringFaces[1] << "] "
00145 << p[neighbouringFaces[1]]
00146 << " localFace: " << faceB
00147 << endl;
00148 }
00149 if (setPtr)
00150 {
00151 setPtr->insert(edgeI);
00152 }
00153
00154 foundError = true;
00155 }
00156 }
00157 else if (neighbouringFaces.size() != 1)
00158 {
00159 if (report)
00160 {
00161 Info
00162 << "Wrong number of edge neighbours." << nl
00163 << "edge[" << edgeI << "] " << e
00164 << " with points:" << p.localPoints()[e.start()]
00165 << ' ' << p.localPoints()[e.end()]
00166 << " has neighbouringFaces:" << neighbouringFaces << endl;
00167 }
00168
00169 if (setPtr)
00170 {
00171 setPtr->insert(edgeI);
00172 }
00173
00174 foundError = true;
00175 }
00176 }
00177
00178 return foundError;
00179 }
00180
00181
00182
Copyright © 2000-2009 OpenCFD Ltd