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/>.
25 Selects a cell set through a dictionary.
27 \*---------------------------------------------------------------------------*/
30 #include "timeSelector.H"
31 #include "objectRegistry.H"
34 #include "topoSetSource.H"
36 #include "volFields.H"
40 template<class GeoField>
44 const labelList& selectedCells,
45 Istream& fieldValueStream
48 // Read field and value together; otherwise there will be an input error
49 // when a field is not found. HJ, 3/Aug/2011
50 word fieldName(fieldValueStream);
52 typename GeoField::value_type value
54 static_cast<const typename GeoField::value_type&>
56 pTraits<typename GeoField::value_type>(fieldValueStream)
63 mesh.time().timeName(),
69 if (fieldHeader.headerOk())
71 Info<< " Setting " << fieldHeader.headerClassName()
72 << " " << fieldName << endl;
74 GeoField field(fieldHeader, mesh);
76 if (selectedCells.size() == field.size())
78 field.internalField() = value;
82 forAll (selectedCells, celli)
84 field[selectedCells[celli]] = value;
88 forAll (field.boundaryField(), patchi)
90 // Forced patch assignment. HJ, 1/Aug/2010
91 field.boundaryField()[patchi] ==
92 field.boundaryField()[patchi].patchInternalField();
102 "(const fvMesh& mesh, const labelList& selectedCells,"
103 "Istream& fieldValueStream)"
104 ) << "Field " << fieldName << " not found" << endl;
117 autoPtr<setField> clone() const
119 return autoPtr<setField>(new setField());
125 const labelList& selectedCells_;
129 iNew(const fvMesh& mesh, const labelList& selectedCells)
132 selectedCells_(selectedCells)
135 autoPtr<setField> operator()(Istream& fieldValues) const
137 word fieldType(fieldValues);
139 if (fieldType == "volScalarFieldValue")
141 setFieldType<volScalarField>
142 (mesh_, selectedCells_, fieldValues);
144 else if (fieldType == "volVectorFieldValue")
146 setFieldType<volVectorField>
147 (mesh_, selectedCells_, fieldValues);
149 else if (fieldType == "volSphericalTensorFieldValue")
151 setFieldType<volSphericalTensorField>
152 (mesh_, selectedCells_, fieldValues);
154 else if (fieldType == "volSymmTensorFieldValue")
156 setFieldType<volSymmTensorField>
157 (mesh_, selectedCells_, fieldValues);
159 else if (fieldType == "volTensorFieldValue")
161 setFieldType<volTensorField>
162 (mesh_, selectedCells_, fieldValues);
166 WarningIn("setField::iNew::operator()(Istream& is)")
167 << "field type " << fieldType << " not currently supported"
171 return autoPtr<setField>(new setField());
177 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
179 int main(int argc, char *argv[])
181 # include "setRootCase.H"
182 # include "createTime.H"
184 Info<< "Time = " << runTime.timeName() << endl;
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 // ************************************************************************* //