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 "faceToCell.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(faceToCell, 0);
00038
00039 addToRunTimeSelectionTable(topoSetSource, faceToCell, word);
00040
00041 addToRunTimeSelectionTable(topoSetSource, faceToCell, istream);
00042
00043 }
00044
00045
00046 Foam::topoSetSource::addToUsageTable Foam::faceToCell::usage_
00047 (
00048 faceToCell::typeName,
00049 "\n Usage: faceToCell <faceSet> neighbour|owner|any|all\n\n"
00050 " Select cells that are the owner|neighbour|any"
00051 " of the faces in the faceSet or where all faces are in the faceSet\n\n"
00052 );
00053
00054 template<>
00055 const char* Foam::NamedEnum<Foam::faceToCell::faceAction, 4>::names[] =
00056 {
00057 "neighbour",
00058 "owner",
00059 "any",
00060 "all"
00061 };
00062
00063 const Foam::NamedEnum<Foam::faceToCell::faceAction, 4>
00064 Foam::faceToCell::faceActionNames_;
00065
00066
00067
00068
00069 void Foam::faceToCell::combine(topoSet& set, const bool add) const
00070 {
00071
00072 faceSet loadedSet(mesh_, setName_);
00073
00074
00075
00076 for
00077 (
00078 faceSet::const_iterator iter = loadedSet.begin();
00079 iter != loadedSet.end();
00080 ++iter
00081 )
00082 {
00083 label faceI = iter.key();
00084
00085 if ((option_ == OWNER) || (option_ == ANY))
00086 {
00087 label cellI = mesh_.faceOwner()[faceI];
00088
00089 addOrDelete(set, cellI, add);
00090 }
00091
00092 if (mesh_.isInternalFace(faceI))
00093 {
00094 if ((option_ == NEIGHBOUR) || (option_ == ANY))
00095 {
00096 label cellI = mesh_.faceNeighbour()[faceI];
00097
00098 addOrDelete(set, cellI, add);
00099 }
00100 }
00101 }
00102
00103
00104 if (option_ == ALL)
00105 {
00106
00107
00108 Map<label> facesPerCell(loadedSet.size());
00109
00110 for
00111 (
00112 faceSet::const_iterator iter = loadedSet.begin();
00113 iter != loadedSet.end();
00114 ++iter
00115 )
00116 {
00117 label faceI = iter.key();
00118
00119 label own = mesh_.faceOwner()[faceI];
00120
00121 Map<label>::iterator fndOwn = facesPerCell.find(own);
00122
00123 if (fndOwn == facesPerCell.end())
00124 {
00125 facesPerCell.insert(own, 1);
00126 }
00127 else
00128 {
00129 fndOwn()++;
00130 }
00131
00132 if (mesh_.isInternalFace(faceI))
00133 {
00134 label nei = mesh_.faceNeighbour()[faceI];
00135
00136 Map<label>::iterator fndNei = facesPerCell.find(nei);
00137
00138 if (fndNei == facesPerCell.end())
00139 {
00140 facesPerCell.insert(nei, 1);
00141 }
00142 else
00143 {
00144 fndNei()++;
00145 }
00146 }
00147 }
00148
00149
00150
00151 for
00152 (
00153 Map<label>::const_iterator iter = facesPerCell.begin();
00154 iter != facesPerCell.end();
00155 ++iter
00156 )
00157 {
00158 label cellI = iter.key();
00159
00160 if (iter() == mesh_.cells()[cellI].size())
00161 {
00162 addOrDelete(set, cellI, add);
00163 }
00164 }
00165 }
00166 }
00167
00168
00169
00170
00171
00172 Foam::faceToCell::faceToCell
00173 (
00174 const polyMesh& mesh,
00175 const word& setName,
00176 const faceAction option
00177 )
00178 :
00179 topoSetSource(mesh),
00180 setName_(setName),
00181 option_(option)
00182 {}
00183
00184
00185
00186 Foam::faceToCell::faceToCell
00187 (
00188 const polyMesh& mesh,
00189 const dictionary& dict
00190 )
00191 :
00192 topoSetSource(mesh),
00193 setName_(dict.lookup("set")),
00194 option_(faceActionNames_.read(dict.lookup("option")))
00195 {}
00196
00197
00198
00199 Foam::faceToCell::faceToCell
00200 (
00201 const polyMesh& mesh,
00202 Istream& is
00203 )
00204 :
00205 topoSetSource(mesh),
00206 setName_(checkIs(is)),
00207 option_(faceActionNames_.read(checkIs(is)))
00208 {}
00209
00210
00211
00212
00213 Foam::faceToCell::~faceToCell()
00214 {}
00215
00216
00217
00218
00219 void Foam::faceToCell::applyToSet
00220 (
00221 const topoSetSource::setAction action,
00222 topoSet& set
00223 ) const
00224 {
00225 if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
00226 {
00227 Info<< " Adding cells according to faceSet " << setName_
00228 << " ..." << endl;
00229
00230 combine(set, true);
00231 }
00232 else if (action == topoSetSource::DELETE)
00233 {
00234 Info<< " Removing cells according to faceSet " << setName_
00235 << " ..." << endl;
00236
00237 combine(set, false);
00238 }
00239 }
00240
00241
00242