1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by
13 the Free Software Foundation, either version 3 of the License, or
14 (at your option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "fieldToCell.H"
31 #include "fieldDictionary.H"
33 #include "addToRunTimeSelectionTable.H"
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
40 defineTypeNameAndDebug(fieldToCell, 0);
42 addToRunTimeSelectionTable(topoSetSource, fieldToCell, word);
44 addToRunTimeSelectionTable(topoSetSource, fieldToCell, istream);
49 Foam::topoSetSource::addToUsageTable Foam::fieldToCell::usage_
51 fieldToCell::typeName,
52 "\n Usage: fieldToCell field min max\n\n"
53 " Select all cells with field value >= min and <= max\n\n"
57 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
59 void Foam::fieldToCell::applyToSet
61 const topoSetSource::setAction action,
62 const scalarField& field,
66 Info<< " Field min:" << min(field)
67 << " max:" << max(field) << endl;
69 if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
71 Info<< " Adding all cells with value of field " << fieldName_
72 << " within range " << min_ << ".." << max_ << endl;
76 if (field[cellI] >= min_ && field[cellI] <= max_)
82 else if (action == topoSetSource::DELETE)
84 Info<< " Removing all cells with value of field " << fieldName_
85 << " within range " << min_ << ".." << max_ << endl;
89 if (field[cellI] >= min_ && field[cellI] <= max_)
98 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
100 // Construct from components
101 Foam::fieldToCell::fieldToCell
103 const polyMesh& mesh,
104 const word& fieldName,
110 fieldName_(fieldName),
116 // Construct from dictionary
117 Foam::fieldToCell::fieldToCell
119 const polyMesh& mesh,
120 const dictionary& dict
124 fieldName_(dict.lookup("fieldName")),
125 min_(readScalar(dict.lookup("min"))),
126 max_(readScalar(dict.lookup("max")))
130 // Construct from Istream
131 Foam::fieldToCell::fieldToCell
133 const polyMesh& mesh,
138 fieldName_(checkIs(is)),
139 min_(readScalar(checkIs(is))),
140 max_(readScalar(checkIs(is)))
144 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
146 Foam::fieldToCell::~fieldToCell()
150 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
152 void Foam::fieldToCell::applyToSet
154 const topoSetSource::setAction action,
159 // // Construct temporary fvMesh from polyMesh
162 // mesh(), // IOobject
168 // const polyBoundaryMesh& patches = mesh().boundaryMesh();
170 // List<polyPatch*> newPatches(patches.size());
171 // forAll(patches, patchI)
173 // const polyPatch& pp = patches[patchI];
175 // newPatches[patchI] =
176 // patches[patchI].clone
178 // fMesh.boundaryMesh(),
184 // fMesh.addFvPatches(newPatches);
190 mesh().time().timeName(),
193 IOobject::AUTO_WRITE,
197 if (!fieldObject.headerOk())
201 "fieldToCell::applyToSet(const topoSetSource::setAction"
203 ) << "Cannot read field " << fieldName_
204 << " from time " << mesh().time().timeName() << endl;
206 else if (fieldObject.headerClassName() == "volScalarField")
208 IFstream str(fieldObject.filePath());
211 fieldDictionary fieldDict(fieldObject, fieldObject.headerClassName());
213 scalarField internalVals("internalField", fieldDict, mesh().nCells());
215 applyToSet(action, internalVals, set);
217 else if (fieldObject.headerClassName() == "volVectorField")
219 IFstream str(fieldObject.filePath());
222 fieldDictionary fieldDict(fieldObject, fieldObject.headerClassName());
224 vectorField internalVals("internalField", fieldDict, mesh().nCells());
226 applyToSet(action, mag(internalVals), set);
232 "fieldToCell::applyToSet(const topoSetSource::setAction"
234 ) << "Cannot handle fields of type " << fieldObject.headerClassName()
240 // ************************************************************************* //