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