BUG: createBaffles.C: converting coupled faces into baffles
[OpenFOAM-2.0.x.git] / applications / utilities / mesh / advanced / refineHexMesh / refineHexMesh.C
blob876d46d9846c894f35448c822ca0ac8e4ef7d3bc
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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/>.
24 Description
25     Refines a hex mesh by 2x2x2 cell splitting.
27 \*---------------------------------------------------------------------------*/
29 #include "fvMesh.H"
30 #include "pointMesh.H"
31 #include "argList.H"
32 #include "Time.H"
33 #include "hexRef8.H"
34 #include "cellSet.H"
35 #include "OFstream.H"
36 #include "meshTools.H"
37 #include "IFstream.H"
38 #include "polyTopoChange.H"
39 #include "mapPolyMesh.H"
40 #include "volMesh.H"
41 #include "surfaceMesh.H"
42 #include "volFields.H"
43 #include "surfaceFields.H"
44 #include "pointFields.H"
45 #include "ReadFields.H"
47 using namespace Foam;
49 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
51 // Main program:
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
69         << nl << endl;
71     cellSet cellsToRefine(mesh, cellSetName);
73     Info<< "Read " << returnReduce(cellsToRefine.size(), sumOp<label>())
74         << " cells to refine from cellSet " << cellSetName << nl
75         << endl;
78     // Read objects in time directory
79     IOobjectList objects(mesh, runTime.timeName());
81     // Read vol fields.
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);
115     // Read point fields
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);
127     // Some stats
128     Info<< "Read mesh:" << nl
129         << "    cells:" << mesh.globalData().nTotalCells() << nl
130         << "    faces:" << mesh.globalData().nTotalFaces() << nl
131         << "    points:" << mesh.globalData().nTotalPoints() << nl
132         << "    cellLevel :"
133         << " min:" << gMin(meshCutter.cellLevel())
134         << " max:" << gMax(meshCutter.cellLevel()) << nl
135         << "    pointLevel :"
136         << " min:" << gMin(meshCutter.pointLevel())
137         << " max:" << gMax(meshCutter.pointLevel()) << nl
138         << endl;
141     // Maintain 2:1 ratio
142     labelList newCellsToRefine
143     (
144         meshCutter.consistentRefinement
145         (
146             cellsToRefine.toc(),
147             true                  // extend set
148         )
149     );
151     // Mesh changing engine.
152     polyTopoChange meshMod(mesh);
154     // Play refinement commands into mesh changer.
155     meshCutter.setRefinement(newCellsToRefine, meshMod);
157     if (!overwrite)
158     {
159         runTime++;
160     }
162     // Create mesh, return map from old to new mesh.
163     autoPtr<mapPolyMesh> map = meshMod.changeMesh(mesh, false);
165     // Update fields
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())
174     {
175         mesh.movePoints(map().preMotionPoints());
176         pMesh.movePoints(map().preMotionPoints());
177     }
179     Pout<< "Refined from " << returnReduce(map().nOldCells(), sumOp<label>())
180         << " to " << mesh.globalData().nTotalCells() << " cells." << nl << endl;
182     if (overwrite)
183     {
184         mesh.setInstance(oldInstance);
185         meshCutter.setInstance(oldInstance);
186     }
187     Info<< "Writing mesh to " << runTime.timeName() << endl;
189     mesh.write();
190     meshCutter.write();
192     Info<< "End\n" << endl;
194     return 0;
198 // ************************************************************************* //