twoDPointCorrector.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
00028
00029
00030
00031
00032 #include "twoDPointCorrector.H"
00033 #include "polyMesh.H"
00034 #include "wedgePolyPatch.H"
00035 #include "emptyPolyPatch.H"
00036
00037
00038
00039 namespace Foam
00040 {
00041
00042
00043
00044 const scalar twoDPointCorrector::edgeOrthogonalityTol = 1.0 - 1e-4;
00045
00046
00047
00048 void twoDPointCorrector::calcAddressing() const
00049 {
00050
00051 planeNormalPtr_ = new vector(0, 0, 0);
00052 vector& pn = *planeNormalPtr_;
00053
00054 bool isWedge = false;
00055
00056
00057
00058
00059
00060
00061
00062
00063 const polyBoundaryMesh& patches = mesh_.boundaryMesh();
00064
00065 forAll (patches, patchI)
00066 {
00067 if (isA<wedgePolyPatch>(patches[patchI]))
00068 {
00069 isWedge = true;
00070
00071 pn = refCast<const wedgePolyPatch>(patches[patchI]).centreNormal();
00072
00073 if (polyMesh::debug)
00074 {
00075 Pout << "Found normal from wedge patch " << patchI;
00076 }
00077
00078 break;
00079 }
00080 }
00081
00082
00083 if (!isWedge)
00084 {
00085 forAll (patches, patchI)
00086 {
00087 if (isA<emptyPolyPatch>(patches[patchI]) && patches[patchI].size())
00088 {
00089 pn = patches[patchI].faceAreas()[0];
00090
00091 if (polyMesh::debug)
00092 {
00093 Pout << "Found normal from empty patch " << patchI;
00094 }
00095
00096 break;
00097 }
00098 }
00099 }
00100
00101
00102 if (mag(pn) < VSMALL)
00103 {
00104 FatalErrorIn
00105 (
00106 "twoDPointCorrector::twoDPointCorrector(const polyMesh& mesh, "
00107 "const vector& n)"
00108 ) << "Cannot determine normal vector from patches."
00109 << abort(FatalError);
00110 }
00111 else
00112 {
00113 pn /= mag(pn);
00114 }
00115
00116 if (polyMesh::debug)
00117 {
00118 Pout << " twoDPointCorrector normal: " << pn << endl;
00119 }
00120
00121
00122 normalEdgeIndicesPtr_ = new labelList(mesh_.nEdges());
00123 labelList& neIndices = *normalEdgeIndicesPtr_;
00124
00125 const edgeList& meshEdges = mesh_.edges();
00126
00127 const pointField& meshPoints = mesh_.points();
00128
00129 label nNormalEdges = 0;
00130
00131 forAll (meshEdges, edgeI)
00132 {
00133 vector edgeVector =
00134 meshEdges[edgeI].vec(meshPoints)/
00135 (meshEdges[edgeI].mag(meshPoints) + VSMALL);
00136
00137 if (mag(edgeVector & pn) > edgeOrthogonalityTol)
00138 {
00139
00140 neIndices[nNormalEdges++] = edgeI;
00141 }
00142 }
00143
00144 neIndices.setSize(nNormalEdges);
00145
00146
00147
00148
00149 if (!isWedge)
00150 {
00151 if (meshPoints.size() % 2 != 0)
00152 {
00153 WarningIn
00154 (
00155 "twoDPointCorrector::twoDPointCorrector("
00156 "const polyMesh& mesh, const vector& n)"
00157 ) << "the number of vertices in the geometry "
00158 << "is odd - this should not be the case for a 2-D case. "
00159 << "Please check the geometry."
00160 << endl;
00161 }
00162
00163 if (2*nNormalEdges != meshPoints.size())
00164 {
00165 WarningIn
00166 (
00167 "twoDPointCorrector::twoDPointCorrector("
00168 "const polyMesh& mesh, const vector& n)"
00169 ) << "The number of points in the mesh is "
00170 << "not equal to twice the number of edges normal to the plane "
00171 << "- this may be OK only for wedge geometries.\n"
00172 << " Please check the geometry or adjust "
00173 << "the orthogonality tolerance.\n" << endl
00174 << "Number of normal edges: " << nNormalEdges
00175 << " number of points: " << meshPoints.size()
00176 << endl;
00177 }
00178 }
00179 }
00180
00181
00182 void twoDPointCorrector::clearAddressing() const
00183 {
00184 deleteDemandDrivenData(planeNormalPtr_);
00185 deleteDemandDrivenData(normalEdgeIndicesPtr_);
00186 }
00187
00188
00189
00190
00191 twoDPointCorrector::twoDPointCorrector(const polyMesh& mesh)
00192 :
00193 mesh_(mesh),
00194 required_(mesh_.nGeometricD() == 2),
00195 planeNormalPtr_(NULL),
00196 normalEdgeIndicesPtr_(NULL)
00197 {}
00198
00199
00200
00201
00202
00203 Foam::twoDPointCorrector::~twoDPointCorrector()
00204 {
00205 clearAddressing();
00206 }
00207
00208
00209
00210
00211 direction twoDPointCorrector::normalDir() const
00212 {
00213 const vector& pn = planeNormal();
00214
00215 if (mag(pn.x()) >= edgeOrthogonalityTol)
00216 {
00217 return vector::X;
00218 }
00219 else if (mag(pn.y()) >= edgeOrthogonalityTol)
00220 {
00221 return vector::Y;
00222 }
00223 else if (mag(pn.z()) >= edgeOrthogonalityTol)
00224 {
00225 return vector::Z;
00226 }
00227 else
00228 {
00229 FatalErrorIn("direction twoDPointCorrector::normalDir() const")
00230 << "Plane normal not aligned with the coordinate system" << nl
00231 << " pn = " << pn
00232 << abort(FatalError);
00233
00234 return vector::Z;
00235 }
00236 }
00237
00238
00239
00240 const vector& twoDPointCorrector::planeNormal() const
00241 {
00242 if (!planeNormalPtr_)
00243 {
00244 calcAddressing();
00245 }
00246
00247 return *planeNormalPtr_;
00248 }
00249
00250
00251
00252 const labelList& twoDPointCorrector::normalEdgeIndices() const
00253 {
00254 if (!normalEdgeIndicesPtr_)
00255 {
00256 calcAddressing();
00257 }
00258
00259 return *normalEdgeIndicesPtr_;
00260 }
00261
00262
00263 void twoDPointCorrector::correctPoints(pointField& p) const
00264 {
00265 if (!required_) return;
00266
00267
00268
00269
00270
00271
00272
00273 const edgeList& meshEdges = mesh_.edges();
00274
00275 const labelList& neIndices = normalEdgeIndices();
00276 const vector& pn = planeNormal();
00277
00278 forAll (neIndices, edgeI)
00279 {
00280 point& pStart = p[meshEdges[neIndices[edgeI]].start()];
00281
00282 point& pEnd = p[meshEdges[neIndices[edgeI]].end()];
00283
00284
00285 const point A = 0.5*(pStart + pEnd);
00286
00287
00288 pStart = A + pn*(pn & (pStart - A));
00289 pEnd = A + pn*(pn & (pEnd - A));
00290 }
00291 }
00292
00293
00294 void twoDPointCorrector::updateMesh()
00295 {
00296 clearAddressing();
00297 }
00298
00299
00300
00301
00302 }
00303
00304
Copyright © 2000-2009 OpenCFD Ltd