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 "normalToFace.H"
00027 #include <OpenFOAM/polyMesh.H>
00028 #include <meshTools/faceSet.H>
00029
00030 #include <OpenFOAM/addToRunTimeSelectionTable.H>
00031
00032
00033
00034 namespace Foam
00035 {
00036
00037 defineTypeNameAndDebug(normalToFace, 0);
00038
00039 addToRunTimeSelectionTable(topoSetSource, normalToFace, word);
00040
00041 addToRunTimeSelectionTable(topoSetSource, normalToFace, istream);
00042
00043 }
00044
00045
00046 Foam::topoSetSource::addToUsageTable Foam::normalToFace::usage_
00047 (
00048 normalToFace::typeName,
00049 "\n Usage: normalToFace (nx ny nz) <tol>\n\n"
00050 " Select faces with normal aligned to unit vector (nx ny nz)\n"
00051 " to within tol\n"
00052 );
00053
00054
00055
00056
00057 void Foam::normalToFace::setNormal()
00058 {
00059 normal_ /= mag(normal_) + VSMALL;
00060
00061 Info<< " normalToFace : Normalized vector to " << normal_ << endl;
00062
00063 if (tol_ < -1 || tol_ > 1)
00064 {
00065 FatalErrorIn
00066 (
00067 "normalToFace::normalToFace(const polyMesh&, const vector&"
00068 ", const scalar)"
00069 ) << "tolerance not within range -1..1 : " << tol_
00070 << exit(FatalError);
00071 }
00072 }
00073
00074
00075
00076
00077
00078 Foam::normalToFace::normalToFace
00079 (
00080 const polyMesh& mesh,
00081 const vector& normal,
00082 const scalar tol
00083 )
00084 :
00085 topoSetSource(mesh),
00086 normal_(normal),
00087 tol_(tol)
00088 {
00089 setNormal();
00090 }
00091
00092
00093
00094 Foam::normalToFace::normalToFace(const polyMesh& mesh, const dictionary& dict)
00095 :
00096 topoSetSource(mesh),
00097 normal_(dict.lookup("normal")),
00098 tol_(readScalar(dict.lookup("cos")))
00099 {
00100 setNormal();
00101 }
00102
00103
00104
00105 Foam::normalToFace::normalToFace(const polyMesh& mesh, Istream& is)
00106 :
00107 topoSetSource(mesh),
00108 normal_(checkIs(is)),
00109 tol_(readScalar(checkIs(is)))
00110 {
00111 setNormal();
00112 }
00113
00114
00115
00116
00117 Foam::normalToFace::~normalToFace()
00118 {}
00119
00120
00121
00122
00123 void Foam::normalToFace::applyToSet
00124 (
00125 const topoSetSource::setAction action,
00126 topoSet& set
00127 ) const
00128 {
00129 if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
00130 {
00131 Info<< " Adding faces according to normal being aligned with "
00132 << normal_ << " (to within " << tol_ << ") ..." << endl;
00133
00134 forAll(mesh_.faceAreas(), faceI)
00135 {
00136 vector n = mesh_.faceAreas()[faceI];
00137 n /= mag(n) + VSMALL;
00138
00139 if (mag(1 - (n & normal_)) < tol_)
00140 {
00141 set.insert(faceI);
00142 }
00143 }
00144 }
00145 else if (action == topoSetSource::DELETE)
00146 {
00147 Info<< " Removing faces according to normal being aligned with "
00148 << normal_ << " (to within " << tol_ << ") ..." << endl;
00149
00150
00151 DynamicList<label> toBeRemoved(set.size()/10);
00152
00153 forAllIter(topoSet, set, iter)
00154 {
00155 label faceI = iter.key();
00156
00157 vector n = mesh_.faceAreas()[faceI];
00158 n /= mag(n) + VSMALL;
00159
00160 if (mag(1 - (n & normal_)) < tol_)
00161 {
00162 toBeRemoved.append(faceI);
00163 }
00164 }
00165
00166 forAll(toBeRemoved, i)
00167 {
00168 set.erase(toBeRemoved[i]);
00169 }
00170 }
00171 }
00172
00173
00174