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 "fieldToCell.H"
00027 #include <OpenFOAM/polyMesh.H>
00028 #include <meshTools/cellSet.H>
00029 #include <OpenFOAM/Time.H>
00030 #include <OpenFOAM/IFstream.H>
00031
00032 #include <OpenFOAM/addToRunTimeSelectionTable.H>
00033
00034
00035
00036 namespace Foam
00037 {
00038
00039 defineTypeNameAndDebug(fieldToCell, 0);
00040
00041 addToRunTimeSelectionTable(topoSetSource, fieldToCell, word);
00042
00043 addToRunTimeSelectionTable(topoSetSource, fieldToCell, istream);
00044
00045 }
00046
00047
00048 Foam::topoSetSource::addToUsageTable Foam::fieldToCell::usage_
00049 (
00050 fieldToCell::typeName,
00051 "\n Usage: fieldToCell field min max\n\n"
00052 " Select all cells with field value >= min and <= max\n\n"
00053 );
00054
00055
00056
00057
00058 void Foam::fieldToCell::applyToSet
00059 (
00060 const topoSetSource::setAction action,
00061 const scalarField& field,
00062 topoSet& set
00063 ) const
00064 {
00065 Info<< " Field min:" << min(field)
00066 << " max:" << max(field) << endl;
00067
00068 if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
00069 {
00070 Info<< " Adding all cells with value of field " << fieldName_
00071 << " within range " << min_ << ".." << max_ << endl;
00072
00073 forAll(field, cellI)
00074 {
00075 if (field[cellI] >= min_ && field[cellI] <= max_)
00076 {
00077 set.insert(cellI);
00078 }
00079 }
00080 }
00081 else if (action == topoSetSource::DELETE)
00082 {
00083 Info<< " Removing all cells with value of field " << fieldName_
00084 << " within range " << min_ << ".." << max_ << endl;
00085
00086 forAll(field, cellI)
00087 {
00088 if (field[cellI] >= min_ && field[cellI] <= max_)
00089 {
00090 set.erase(cellI);
00091 }
00092 }
00093 }
00094 }
00095
00096
00097
00098
00099
00100 Foam::fieldToCell::fieldToCell
00101 (
00102 const polyMesh& mesh,
00103 const word& fieldName,
00104 const scalar min,
00105 const scalar max
00106 )
00107 :
00108 topoSetSource(mesh),
00109 fieldName_(fieldName),
00110 min_(min),
00111 max_(max)
00112 {}
00113
00114
00115
00116 Foam::fieldToCell::fieldToCell
00117 (
00118 const polyMesh& mesh,
00119 const dictionary& dict
00120 )
00121 :
00122 topoSetSource(mesh),
00123 fieldName_(dict.lookup("fieldName")),
00124 min_(readScalar(dict.lookup("min"))),
00125 max_(readScalar(dict.lookup("max")))
00126 {}
00127
00128
00129
00130 Foam::fieldToCell::fieldToCell
00131 (
00132 const polyMesh& mesh,
00133 Istream& is
00134 )
00135 :
00136 topoSetSource(mesh),
00137 fieldName_(checkIs(is)),
00138 min_(readScalar(checkIs(is))),
00139 max_(readScalar(checkIs(is)))
00140 {}
00141
00142
00143
00144
00145 Foam::fieldToCell::~fieldToCell()
00146 {}
00147
00148
00149
00150
00151 void Foam::fieldToCell::applyToSet
00152 (
00153 const topoSetSource::setAction action,
00154 topoSet& set
00155 ) const
00156 {
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186 IOobject fieldObject
00187 (
00188 fieldName_,
00189 mesh().time().timeName(),
00190 mesh(),
00191 IOobject::MUST_READ,
00192 IOobject::AUTO_WRITE
00193 );
00194
00195 if (!fieldObject.headerOk())
00196 {
00197 WarningIn
00198 (
00199 "fieldToCell::applyToSet(const topoSetSource::setAction"
00200 ", topoSet& set)"
00201 ) << "Cannot read field " << fieldName_
00202 << " from time " << mesh().time().timeName() << endl;
00203 }
00204 else if (fieldObject.headerClassName() == "volScalarField")
00205 {
00206 IFstream str(fieldObject.filePath());
00207
00208
00209 dictionary fieldDict(str);
00210
00211 scalarField internalVals("internalField", fieldDict, mesh().nCells());
00212
00213 applyToSet(action, internalVals, set);
00214 }
00215 else if (fieldObject.headerClassName() == "volVectorField")
00216 {
00217 IFstream str(fieldObject.filePath());
00218
00219
00220 dictionary fieldDict(str);
00221
00222 vectorField internalVals("internalField", fieldDict, mesh().nCells());
00223
00224 applyToSet(action, mag(internalVals), set);
00225 }
00226 else
00227 {
00228 WarningIn
00229 (
00230 "fieldToCell::applyToSet(const topoSetSource::setAction"
00231 ", topoSet& set)"
00232 ) << "Cannot handle fields of type " << fieldObject.headerClassName()
00233 << endl;
00234 }
00235 }
00236
00237
00238