edgeStats.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 "edgeStats.H"
00028 #include "Time.H"
00029 #include "polyMesh.H"
00030 #include "Ostream.H"
00031 #include "twoDPointCorrector.H"
00032
00033
00034
00035 const Foam::scalar Foam::edgeStats::edgeTol_ = 1E-3;
00036
00037
00038
00039
00040
00041 Foam::direction Foam::edgeStats::getNormalDir
00042 (
00043 const twoDPointCorrector* correct2DPtr
00044 ) const
00045 {
00046 direction dir = 3;
00047
00048 if (correct2DPtr)
00049 {
00050 const vector& normal = correct2DPtr->planeNormal();
00051
00052 if (mag(normal & vector(1, 0, 0)) > 1-edgeTol_)
00053 {
00054 dir = 0;
00055 }
00056 else if (mag(normal & vector(0, 1, 0)) > 1-edgeTol_)
00057 {
00058 dir = 1;
00059 }
00060 else if (mag(normal & vector(0, 0, 1)) > 1-edgeTol_)
00061 {
00062 dir = 2;
00063 }
00064 }
00065 return dir;
00066 }
00067
00068
00069
00070
00071
00072 Foam::edgeStats::edgeStats(const polyMesh& mesh)
00073 :
00074 mesh_(mesh),
00075 normalDir_(3)
00076 {
00077 IOobject motionObj
00078 (
00079 "motionProperties",
00080 mesh.time().constant(),
00081 mesh,
00082 IOobject::MUST_READ,
00083 IOobject::NO_WRITE
00084 );
00085
00086 if (motionObj.headerOk())
00087 {
00088 Info<< "Reading " << mesh.time().constant() / "motionProperties"
00089 << endl << endl;
00090
00091 IOdictionary motionProperties(motionObj);
00092
00093 Switch twoDMotion(motionProperties.lookup("twoDMotion"));
00094
00095 if (twoDMotion)
00096 {
00097 Info<< "Correcting for 2D motion" << endl << endl;
00098
00099 autoPtr<twoDPointCorrector> correct2DPtr
00100 (
00101 new twoDPointCorrector(mesh)
00102 );
00103
00104 normalDir_ = getNormalDir(&correct2DPtr());
00105 }
00106 }
00107 }
00108
00109
00110
00111 Foam::edgeStats::edgeStats
00112 (
00113 const polyMesh& mesh,
00114 const twoDPointCorrector* correct2DPtr
00115 )
00116 :
00117 mesh_(mesh),
00118 normalDir_(getNormalDir(correct2DPtr))
00119 {}
00120
00121
00122
00123
00124 Foam::scalar Foam::edgeStats::minLen(Ostream& os) const
00125 {
00126 label nX = 0;
00127 label nY = 0;
00128 label nZ = 0;
00129
00130 scalar minX = GREAT;
00131 scalar maxX = -GREAT;
00132 vector x(1, 0, 0);
00133
00134 scalar minY = GREAT;
00135 scalar maxY = -GREAT;
00136 vector y(0, 1, 0);
00137
00138 scalar minZ = GREAT;
00139 scalar maxZ = -GREAT;
00140 vector z(0, 0, 1);
00141
00142 scalar minOther = GREAT;
00143 scalar maxOther = -GREAT;
00144
00145 const edgeList& edges = mesh_.edges();
00146
00147 forAll(edges, edgeI)
00148 {
00149 const edge& e = edges[edgeI];
00150
00151 vector eVec(e.vec(mesh_.points()));
00152
00153 scalar eMag = mag(eVec);
00154
00155 eVec /= eMag;
00156
00157 if (mag(eVec & x) > 1-edgeTol_)
00158 {
00159 minX = min(minX, eMag);
00160 maxX = max(maxX, eMag);
00161 nX++;
00162 }
00163 else if (mag(eVec & y) > 1-edgeTol_)
00164 {
00165 minY = min(minY, eMag);
00166 maxY = max(maxY, eMag);
00167 nY++;
00168 }
00169 else if (mag(eVec & z) > 1-edgeTol_)
00170 {
00171 minZ = min(minZ, eMag);
00172 maxZ = max(maxZ, eMag);
00173 nZ++;
00174 }
00175 else
00176 {
00177 minOther = min(minOther, eMag);
00178 maxOther = max(maxOther, eMag);
00179 }
00180 }
00181
00182 os << "Mesh bounding box:" << boundBox(mesh_.points()) << nl << nl
00183 << "Mesh edge statistics:" << nl
00184 << " x aligned : number:" << nX << "\tminLen:" << minX
00185 << "\tmaxLen:" << maxX << nl
00186 << " y aligned : number:" << nY << "\tminLen:" << minY
00187 << "\tmaxLen:" << maxY << nl
00188 << " z aligned : number:" << nZ << "\tminLen:" << minZ
00189 << "\tmaxLen:" << maxZ << nl
00190 << " other : number:" << mesh_.nEdges() - nX - nY - nZ
00191 << "\tminLen:" << minOther
00192 << "\tmaxLen:" << maxOther << nl << endl;
00193
00194 if (normalDir_ == 0)
00195 {
00196 return min(minY, min(minZ, minOther));
00197 }
00198 else if (normalDir_ == 1)
00199 {
00200 return min(minX, min(minZ, minOther));
00201 }
00202 else if (normalDir_ == 2)
00203 {
00204 return min(minX, min(minY, minOther));
00205 }
00206 else
00207 {
00208 return min(minX, min(minY, min(minZ, minOther)));
00209 }
00210 }
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
Copyright © 2000-2009 OpenCFD Ltd