1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-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/>.
25 Selects a cell set through a dictionary.
27 \*---------------------------------------------------------------------------*/
30 #include "timeSelector.H"
33 #include "topoSetSource.H"
35 #include "volFields.H"
39 template<class GeoField>
43 const labelList& selectedCells,
44 Istream& fieldValueStream
47 word fieldName(fieldValueStream);
52 mesh.time().timeName(),
58 if (fieldHeader.headerOk())
60 Info<< " Setting " << fieldHeader.headerClassName()
61 << " " << fieldName << endl;
63 GeoField field(fieldHeader, mesh);
65 typename GeoField::value_type value
67 static_cast<const typename GeoField::value_type&>
69 pTraits<typename GeoField::value_type>(fieldValueStream)
73 if (selectedCells.size() == field.size())
75 field.internalField() = value;
79 forAll(selectedCells, celli)
81 field[selectedCells[celli]] = value;
85 forAll(field.boundaryField(), patchi)
87 field.boundaryField()[patchi] =
88 field.boundaryField()[patchi].patchInternalField();
98 "(const fvMesh& mesh, const labelList& selectedCells,"
99 "Istream& fieldValueStream)"
100 ) << "Field " << fieldName << " not found" << endl;
113 autoPtr<setField> clone() const
115 return autoPtr<setField>(new setField());
121 const labelList& selectedCells_;
125 iNew(const fvMesh& mesh, const labelList& selectedCells)
128 selectedCells_(selectedCells)
131 autoPtr<setField> operator()(Istream& fieldValues) const
133 word fieldType(fieldValues);
135 if (fieldType == "volScalarFieldValue")
137 setFieldType<volScalarField>
138 (mesh_, selectedCells_, fieldValues);
140 else if (fieldType == "volVectorFieldValue")
142 setFieldType<volVectorField>
143 (mesh_, selectedCells_, fieldValues);
145 else if (fieldType == "volSphericalTensorFieldValue")
147 setFieldType<volSphericalTensorField>
148 (mesh_, selectedCells_, fieldValues);
150 else if (fieldType == "volSymmTensorFieldValue")
152 setFieldType<volSymmTensorField>
153 (mesh_, selectedCells_, fieldValues);
155 else if (fieldType == "volTensorFieldValue")
157 setFieldType<volTensorField>
158 (mesh_, selectedCells_, fieldValues);
162 WarningIn("setField::iNew::operator()(Istream& is)")
163 << "field type " << fieldType << " not currently supported"
167 return autoPtr<setField>(new setField());
173 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
175 int main(int argc, char *argv[])
177 timeSelector::addOptions();
179 # include "setRootCase.H"
180 # include "createTime.H"
183 instantList timeDirs = timeSelector::select0(runTime, args);
185 # include "createMesh.H"
187 Info<< "Reading setFieldsDict\n" << endl;
189 IOdictionary setFieldsDict
201 if (setFieldsDict.found("defaultFieldValues"))
203 Info<< "Setting field default values" << endl;
204 PtrList<setField> defaultFieldValues
206 setFieldsDict.lookup("defaultFieldValues"),
207 setField::iNew(mesh, labelList(mesh.nCells()))
213 Info<< "Setting field region values" << endl;
215 PtrList<entry> regions(setFieldsDict.lookup("regions"));
217 forAll(regions, regionI)
219 const entry& region = regions[regionI];
221 autoPtr<topoSetSource> cellSelector =
222 topoSetSource::New(region.keyword(), mesh, region.dict());
224 cellSet selectedCellSet
228 mesh.nCells()/10+1 // Reasonable size estimate.
231 cellSelector->applyToSet
237 PtrList<setField> fieldValues
239 region.dict().lookup("fieldValues"),
240 setField::iNew(mesh, selectedCellSet.toc())
244 Info<< "\nEnd" << endl;
250 // ************************************************************************* //