1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation, either version 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "fieldToCell.H"
32 #include "addToRunTimeSelectionTable.H"
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
39 defineTypeNameAndDebug(fieldToCell, 0);
41 addToRunTimeSelectionTable(topoSetSource, fieldToCell, word);
43 addToRunTimeSelectionTable(topoSetSource, fieldToCell, istream);
48 Foam::topoSetSource::addToUsageTable Foam::fieldToCell::usage_
50 fieldToCell::typeName,
51 "\n Usage: fieldToCell field min max\n\n"
52 " Select all cells with field value >= min and <= max\n\n"
56 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
58 void Foam::fieldToCell::applyToSet
60 const topoSetSource::setAction action,
61 const scalarField& field,
65 Info<< " Field min:" << min(field)
66 << " max:" << max(field) << endl;
68 if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
70 Info<< " Adding all cells with value of field " << fieldName_
71 << " within range " << min_ << ".." << max_ << endl;
75 if (field[cellI] >= min_ && field[cellI] <= max_)
81 else if (action == topoSetSource::DELETE)
83 Info<< " Removing all cells with value of field " << fieldName_
84 << " within range " << min_ << ".." << max_ << endl;
88 if (field[cellI] >= min_ && field[cellI] <= max_)
97 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
99 // Construct from components
100 Foam::fieldToCell::fieldToCell
102 const polyMesh& mesh,
103 const word& fieldName,
109 fieldName_(fieldName),
115 // Construct from dictionary
116 Foam::fieldToCell::fieldToCell
118 const polyMesh& mesh,
119 const dictionary& dict
123 fieldName_(dict.lookup("fieldName")),
124 min_(readScalar(dict.lookup("min"))),
125 max_(readScalar(dict.lookup("max")))
129 // Construct from Istream
130 Foam::fieldToCell::fieldToCell
132 const polyMesh& mesh,
137 fieldName_(checkIs(is)),
138 min_(readScalar(checkIs(is))),
139 max_(readScalar(checkIs(is)))
143 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
145 Foam::fieldToCell::~fieldToCell()
149 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
151 void Foam::fieldToCell::applyToSet
153 const topoSetSource::setAction action,
158 // // Construct temporary fvMesh from polyMesh
161 // mesh(), // IOobject
167 // const polyBoundaryMesh& patches = mesh().boundaryMesh();
169 // List<polyPatch*> newPatches(patches.size());
170 // forAll(patches, patchI)
172 // const polyPatch& pp = patches[patchI];
174 // newPatches[patchI] =
175 // patches[patchI].clone
177 // fMesh.boundaryMesh(),
183 // fMesh.addFvPatches(newPatches);
189 mesh().time().timeName(),
195 if (!fieldObject.headerOk())
199 "fieldToCell::applyToSet(const topoSetSource::setAction"
201 ) << "Cannot read field " << fieldName_
202 << " from time " << mesh().time().timeName() << endl;
204 else if (fieldObject.headerClassName() == "volScalarField")
206 IFstream str(fieldObject.filePath());
209 dictionary fieldDict(str);
211 scalarField internalVals("internalField", fieldDict, mesh().nCells());
213 applyToSet(action, internalVals, set);
215 else if (fieldObject.headerClassName() == "volVectorField")
217 IFstream str(fieldObject.filePath());
220 dictionary fieldDict(str);
222 vectorField internalVals("internalField", fieldDict, mesh().nCells());
224 applyToSet(action, mag(internalVals), set);
230 "fieldToCell::applyToSet(const topoSetSource::setAction"
232 ) << "Cannot handle fields of type " << fieldObject.headerClassName()
238 // ************************************************************************* //