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/>.
25 Selects a section of mesh based on a cellSet.
27 The utility sub-sets the mesh to choose only a part of interest. Check
28 the setSet/cellSet utilities to see how to select cells based on various.
30 The mesh will subset all points, faces and cells needed to make a sub-mesh
31 but will not preserve attached boundary types.
33 \*---------------------------------------------------------------------------*/
35 #include "fvMeshSubset.H"
38 #include "IOobjectList.H"
39 #include "volFields.H"
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49 const fvMeshSubset& subsetter,
50 const wordList& fieldNames,
51 PtrList<GeometricField<Type, fvPatchField, volMesh> >& subFields
54 const fvMesh& baseMesh = subsetter.baseMesh();
58 const word& fieldName = fieldNames[i];
60 Info<< "Subsetting field " << fieldName << endl;
62 GeometricField<Type, fvPatchField, volMesh> fld
67 baseMesh.time().timeName(),
75 subFields.set(i, subsetter.interpolate(fld));
81 void subsetSurfaceFields
83 const fvMeshSubset& subsetter,
84 const wordList& fieldNames,
85 PtrList<GeometricField<Type, fvsPatchField, surfaceMesh> >& subFields
88 const fvMesh& baseMesh = subsetter.baseMesh();
92 const word& fieldName = fieldNames[i];
94 Info<< "Subsetting field " << fieldName << endl;
96 GeometricField<Type, fvsPatchField, surfaceMesh> fld
101 baseMesh.time().timeName(),
109 subFields.set(i, subsetter.interpolate(fld));
115 void subsetPointFields
117 const fvMeshSubset& subsetter,
118 const pointMesh& pMesh,
119 const wordList& fieldNames,
120 PtrList<GeometricField<Type, pointPatchField, pointMesh> >& subFields
123 const fvMesh& baseMesh = subsetter.baseMesh();
125 forAll(fieldNames, i)
127 const word& fieldName = fieldNames[i];
129 Info<< "Subsetting field " << fieldName << endl;
131 GeometricField<Type, pointPatchField, pointMesh> fld
136 baseMesh.time().timeName(),
144 subFields.set(i, subsetter.interpolate(fld));
151 int main(int argc, char *argv[])
155 "select a mesh subset based on a cellSet"
158 #include "addOverwriteOption.H"
159 argList::validArgs.append("cellSet");
164 "add exposed internal faces to specified patch instead of to "
167 #include "setRootCase.H"
168 #include "createTime.H"
169 runTime.functionObjects().off();
170 #include "createMesh.H"
172 const word oldInstance = mesh.pointsInstance();
174 const word setName = args[1];
175 const bool overwrite = args.optionFound("overwrite");
178 Info<< "Reading cell set from " << setName << endl << endl;
180 // Create mesh subsetting engine
181 fvMeshSubset subsetter(mesh);
185 if (args.optionFound("patch"))
187 const word patchName = args["patch"];
189 patchI = mesh.boundaryMesh().findPatchID(patchName);
193 FatalErrorIn(args.executable()) << "Illegal patch " << patchName
194 << nl << "Valid patches are " << mesh.boundaryMesh().names()
198 Info<< "Adding exposed internal faces to patch " << patchName << endl
203 Info<< "Adding exposed internal faces to a patch called"
204 << " \"oldInternalFaces\" (created if necessary)" << endl
209 cellSet currentSet(mesh, setName);
211 subsetter.setLargeCellSubset(currentSet, patchI, true);
213 IOobjectList objects(mesh, runTime.timeName());
216 // Read vol fields and subset
217 // ~~~~~~~~~~~~~~~~~~~~~~~~~~
219 wordList scalarNames(objects.names(volScalarField::typeName));
220 PtrList<volScalarField> scalarFlds(scalarNames.size());
221 subsetVolFields(subsetter, scalarNames, scalarFlds);
223 wordList vectorNames(objects.names(volVectorField::typeName));
224 PtrList<volVectorField> vectorFlds(vectorNames.size());
225 subsetVolFields(subsetter, vectorNames, vectorFlds);
227 wordList sphericalTensorNames
229 objects.names(volSphericalTensorField::typeName)
231 PtrList<volSphericalTensorField> sphericalTensorFlds
233 sphericalTensorNames.size()
235 subsetVolFields(subsetter, sphericalTensorNames, sphericalTensorFlds);
237 wordList symmTensorNames(objects.names(volSymmTensorField::typeName));
238 PtrList<volSymmTensorField> symmTensorFlds(symmTensorNames.size());
239 subsetVolFields(subsetter, symmTensorNames, symmTensorFlds);
241 wordList tensorNames(objects.names(volTensorField::typeName));
242 PtrList<volTensorField> tensorFlds(tensorNames.size());
243 subsetVolFields(subsetter, tensorNames, tensorFlds);
246 // Read surface fields and subset
247 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
249 wordList surfScalarNames(objects.names(surfaceScalarField::typeName));
250 PtrList<surfaceScalarField> surfScalarFlds(surfScalarNames.size());
251 subsetSurfaceFields(subsetter, surfScalarNames, surfScalarFlds);
253 wordList surfVectorNames(objects.names(surfaceVectorField::typeName));
254 PtrList<surfaceVectorField> surfVectorFlds(surfVectorNames.size());
255 subsetSurfaceFields(subsetter, surfVectorNames, surfVectorFlds);
257 wordList surfSphericalTensorNames
259 objects.names(surfaceSphericalTensorField::typeName)
261 PtrList<surfaceSphericalTensorField> surfSphericalTensorFlds
263 surfSphericalTensorNames.size()
268 surfSphericalTensorNames,
269 surfSphericalTensorFlds
272 wordList surfSymmTensorNames
274 objects.names(surfaceSymmTensorField::typeName)
276 PtrList<surfaceSymmTensorField> surfSymmTensorFlds
278 surfSymmTensorNames.size()
280 subsetSurfaceFields(subsetter, surfSymmTensorNames, surfSymmTensorFlds);
282 wordList surfTensorNames(objects.names(surfaceTensorField::typeName));
283 PtrList<surfaceTensorField> surfTensorFlds(surfTensorNames.size());
284 subsetSurfaceFields(subsetter, surfTensorNames, surfTensorFlds);
287 // Read point fields and subset
288 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
290 const pointMesh& pMesh = pointMesh::New(mesh);
292 wordList pointScalarNames(objects.names(pointScalarField::typeName));
293 PtrList<pointScalarField> pointScalarFlds(pointScalarNames.size());
294 subsetPointFields(subsetter, pMesh, pointScalarNames, pointScalarFlds);
296 wordList pointVectorNames(objects.names(pointVectorField::typeName));
297 PtrList<pointVectorField> pointVectorFlds(pointVectorNames.size());
298 subsetPointFields(subsetter, pMesh, pointVectorNames, pointVectorFlds);
300 wordList pointSphericalTensorNames
302 objects.names(pointSphericalTensorField::typeName)
304 PtrList<pointSphericalTensorField> pointSphericalTensorFlds
306 pointSphericalTensorNames.size()
312 pointSphericalTensorNames,
313 pointSphericalTensorFlds
316 wordList pointSymmTensorNames
318 objects.names(pointSymmTensorField::typeName)
320 PtrList<pointSymmTensorField> pointSymmTensorFlds
322 pointSymmTensorNames.size()
328 pointSymmTensorNames,
332 wordList pointTensorNames(objects.names(pointTensorField::typeName));
333 PtrList<pointTensorField> pointTensorFlds(pointTensorNames.size());
334 subsetPointFields(subsetter, pMesh, pointTensorNames, pointTensorFlds);
338 // Write mesh and fields to new time
339 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
347 subsetter.subMesh().setInstance(oldInstance);
350 Info<< "Writing subsetted mesh and fields to time " << runTime.timeName()
352 subsetter.subMesh().write();
355 // Subsetting adds 'subset' prefix. Rename field to be like original.
356 forAll(scalarFlds, i)
358 scalarFlds[i].rename(scalarNames[i]);
360 scalarFlds[i].write();
362 forAll(vectorFlds, i)
364 vectorFlds[i].rename(vectorNames[i]);
366 vectorFlds[i].write();
368 forAll(sphericalTensorFlds, i)
370 sphericalTensorFlds[i].rename(sphericalTensorNames[i]);
372 sphericalTensorFlds[i].write();
374 forAll(symmTensorFlds, i)
376 symmTensorFlds[i].rename(symmTensorNames[i]);
378 symmTensorFlds[i].write();
380 forAll(tensorFlds, i)
382 tensorFlds[i].rename(tensorNames[i]);
384 tensorFlds[i].write();
388 forAll(surfScalarFlds, i)
390 surfScalarFlds[i].rename(surfScalarNames[i]);
392 surfScalarFlds[i].write();
394 forAll(surfVectorFlds, i)
396 surfVectorFlds[i].rename(surfVectorNames[i]);
398 surfVectorFlds[i].write();
400 forAll(surfSphericalTensorFlds, i)
402 surfSphericalTensorFlds[i].rename(surfSphericalTensorNames[i]);
404 surfSphericalTensorFlds[i].write();
406 forAll(surfSymmTensorFlds, i)
408 surfSymmTensorFlds[i].rename(surfSymmTensorNames[i]);
410 surfSymmTensorFlds[i].write();
412 forAll(surfTensorNames, i)
414 surfTensorFlds[i].rename(surfTensorNames[i]);
416 surfTensorFlds[i].write();
420 forAll(pointScalarFlds, i)
422 pointScalarFlds[i].rename(pointScalarNames[i]);
424 pointScalarFlds[i].write();
426 forAll(pointVectorFlds, i)
428 pointVectorFlds[i].rename(pointVectorNames[i]);
430 pointVectorFlds[i].write();
432 forAll(pointSphericalTensorFlds, i)
434 pointSphericalTensorFlds[i].rename(pointSphericalTensorNames[i]);
436 pointSphericalTensorFlds[i].write();
438 forAll(pointSymmTensorFlds, i)
440 pointSymmTensorFlds[i].rename(pointSymmTensorNames[i]);
442 pointSymmTensorFlds[i].write();
444 forAll(pointTensorNames, i)
446 pointTensorFlds[i].rename(pointTensorNames[i]);
448 pointTensorFlds[i].write();
452 Info<< "\nEnd\n" << endl;
458 // ************************************************************************* //