1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
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 Refines a hex mesh by 2x2x2 cell splitting.
27 \*---------------------------------------------------------------------------*/
30 #include "pointMesh.H"
36 #include "meshTools.H"
38 #include "polyTopoChange.H"
39 #include "mapPolyMesh.H"
41 #include "surfaceMesh.H"
42 #include "volFields.H"
43 #include "surfaceFields.H"
44 #include "pointFields.H"
45 #include "ReadFields.H"
49 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
52 int main(int argc, char *argv[])
54 # include "addOverwriteOption.H"
55 argList::validArgs.append("cellSet");
57 # include "setRootCase.H"
58 # include "createTime.H"
59 runTime.functionObjects().off();
60 # include "createMesh.H"
61 const word oldInstance = mesh.pointsInstance();
63 pointMesh pMesh(mesh);
65 word cellSetName(args.args()[1]);
66 const bool overwrite = args.optionFound("overwrite");
68 Info<< "Reading cells to refine from cellSet " << cellSetName
71 cellSet cellsToRefine(mesh, cellSetName);
73 Info<< "Read " << returnReduce(cellsToRefine.size(), sumOp<label>())
74 << " cells to refine from cellSet " << cellSetName << nl
78 // Read objects in time directory
79 IOobjectList objects(mesh, runTime.timeName());
83 PtrList<volScalarField> vsFlds;
84 ReadFields(mesh, objects, vsFlds);
86 PtrList<volVectorField> vvFlds;
87 ReadFields(mesh, objects, vvFlds);
89 PtrList<volSphericalTensorField> vstFlds;
90 ReadFields(mesh, objects, vstFlds);
92 PtrList<volSymmTensorField> vsymtFlds;
93 ReadFields(mesh, objects, vsymtFlds);
95 PtrList<volTensorField> vtFlds;
96 ReadFields(mesh, objects, vtFlds);
98 // Read surface fields.
100 PtrList<surfaceScalarField> ssFlds;
101 ReadFields(mesh, objects, ssFlds);
103 PtrList<surfaceVectorField> svFlds;
104 ReadFields(mesh, objects, svFlds);
106 PtrList<surfaceSphericalTensorField> sstFlds;
107 ReadFields(mesh, objects, sstFlds);
109 PtrList<surfaceSymmTensorField> ssymtFlds;
110 ReadFields(mesh, objects, ssymtFlds);
112 PtrList<surfaceTensorField> stFlds;
113 ReadFields(mesh, objects, stFlds);
116 PtrList<pointScalarField> psFlds;
117 ReadFields(pMesh, objects, psFlds);
119 PtrList<pointVectorField> pvFlds;
120 ReadFields(pMesh, objects, pvFlds);
124 // Construct refiner without unrefinement. Read existing point/cell level.
125 hexRef8 meshCutter(mesh);
128 Info<< "Read mesh:" << nl
129 << " cells:" << mesh.globalData().nTotalCells() << nl
130 << " faces:" << mesh.globalData().nTotalFaces() << nl
131 << " points:" << mesh.globalData().nTotalPoints() << nl
133 << " min:" << gMin(meshCutter.cellLevel())
134 << " max:" << gMax(meshCutter.cellLevel()) << nl
136 << " min:" << gMin(meshCutter.pointLevel())
137 << " max:" << gMax(meshCutter.pointLevel()) << nl
141 // Maintain 2:1 ratio
142 labelList newCellsToRefine
144 meshCutter.consistentRefinement
151 // Mesh changing engine.
152 polyTopoChange meshMod(mesh);
154 // Play refinement commands into mesh changer.
155 meshCutter.setRefinement(newCellsToRefine, meshMod);
162 // Create mesh, return map from old to new mesh.
163 autoPtr<mapPolyMesh> map = meshMod.changeMesh(mesh, false);
166 mesh.updateMesh(map);
167 pMesh.updateMesh(map);
169 // Update numbering of cells/vertices.
170 meshCutter.updateMesh(map);
172 // Optionally inflate mesh
173 if (map().hasMotionPoints())
175 mesh.movePoints(map().preMotionPoints());
176 pMesh.movePoints(map().preMotionPoints());
179 Pout<< "Refined from " << returnReduce(map().nOldCells(), sumOp<label>())
180 << " to " << mesh.globalData().nTotalCells() << " cells." << nl << endl;
184 mesh.setInstance(oldInstance);
185 meshCutter.setInstance(oldInstance);
187 Info<< "Writing mesh to " << runTime.timeName() << endl;
192 Info<< "End\n" << endl;
198 // ************************************************************************* //