1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 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, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 Selects a cell set through a dictionary.
28 \*---------------------------------------------------------------------------*/
31 #include "timeSelector.H"
34 #include "topoSetSource.H"
36 #include "volFields.H"
40 template<class GeoField>
44 const labelList& selectedCells,
45 Istream& fieldValueStream
48 word fieldName(fieldValueStream);
53 mesh.time().timeName(),
59 if (fieldHeader.headerOk())
61 Info<< " Setting " << fieldHeader.headerClassName()
62 << " " << fieldName << endl;
64 GeoField field(fieldHeader, mesh);
66 typename GeoField::value_type value
68 static_cast<const typename GeoField::value_type&>
70 pTraits<typename GeoField::value_type>(fieldValueStream)
74 if (selectedCells.size() == field.size())
76 field.internalField() = value;
80 forAll(selectedCells, celli)
82 field[selectedCells[celli]] = value;
86 forAll(field.boundaryField(), patchi)
88 field.boundaryField()[patchi] =
89 field.boundaryField()[patchi].patchInternalField();
99 "(const fvMesh& mesh, const labelList& selectedCells,"
100 "Istream& fieldValueStream)"
101 ) << "Field " << fieldName << " not found" << endl;
114 autoPtr<setField> clone() const
116 return autoPtr<setField>(new setField());
122 const labelList& selectedCells_;
126 iNew(const fvMesh& mesh, const labelList& selectedCells)
129 selectedCells_(selectedCells)
132 autoPtr<setField> operator()(Istream& fieldValues) const
134 word fieldType(fieldValues);
136 if (fieldType == "volScalarFieldValue")
138 setFieldType<volScalarField>
139 (mesh_, selectedCells_, fieldValues);
141 else if (fieldType == "volVectorFieldValue")
143 setFieldType<volVectorField>
144 (mesh_, selectedCells_, fieldValues);
146 else if (fieldType == "volSphericalTensorFieldValue")
148 setFieldType<volSphericalTensorField>
149 (mesh_, selectedCells_, fieldValues);
151 else if (fieldType == "volSymmTensorFieldValue")
153 setFieldType<volSymmTensorField>
154 (mesh_, selectedCells_, fieldValues);
156 else if (fieldType == "volTensorFieldValue")
158 setFieldType<volTensorField>
159 (mesh_, selectedCells_, fieldValues);
163 WarningIn("setField::iNew::operator()(Istream& is)")
164 << "field type " << fieldType << " not currently supported"
168 return autoPtr<setField>(new setField());
174 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
176 int main(int argc, char *argv[])
178 timeSelector::addOptions();
180 # include "setRootCase.H"
181 # include "createTime.H"
184 instantList timeDirs = timeSelector::select0(runTime, args);
186 # include "createMesh.H"
188 Info<< "Reading setFieldsDict\n" << endl;
190 IOdictionary setFieldsDict
202 if (setFieldsDict.found("defaultFieldValues"))
204 Info<< "Setting field default values" << endl;
205 PtrList<setField> defaultFieldValues
207 setFieldsDict.lookup("defaultFieldValues"),
208 setField::iNew(mesh, labelList(mesh.nCells()))
214 Info<< "Setting field region values" << endl;
216 PtrList<entry> regions(setFieldsDict.lookup("regions"));
218 forAll(regions, regionI)
220 const entry& region = regions[regionI];
222 autoPtr<topoSetSource> cellSelector =
223 topoSetSource::New(region.keyword(), mesh, region.dict());
225 cellSet selectedCellSet
229 mesh.nCells()/10+1 // Reasonable size estimate.
232 cellSelector->applyToSet
238 PtrList<setField> fieldValues
240 region.dict().lookup("fieldValues"),
241 setField::iNew(mesh, selectedCellSet.toc())
245 Info<< "\nEnd" << endl;
251 // ************************************************************************* //