Loading...
Searching...
No Matches
refineHexMesh.C
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2011-2014 OpenFOAM Foundation
9 Copyright (C) 2016 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27Application
28 refineHexMesh
29
30Group
31 grpMeshAdvancedUtilities
32
33Description
34 Refine a hex mesh by 2x2x2 cell splitting for the specified cellSet.
35
36\*---------------------------------------------------------------------------*/
37
38#include "fvMesh.H"
39#include "pointMesh.H"
40#include "argList.H"
41#include "Time.H"
42#include "hexRef8.H"
43#include "cellSet.H"
44#include "Fstream.H"
45#include "meshTools.H"
46#include "polyTopoChange.H"
47#include "mapPolyMesh.H"
48#include "volMesh.H"
49#include "surfaceMesh.H"
50#include "volFields.H"
51#include "surfaceFields.H"
52#include "pointFields.H"
53#include "ReadFields.H"
54#include "processorMeshes.H"
55
56using namespace Foam;
57
58// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
59
60int main(int argc, char *argv[])
61{
63 (
64 "Refine a hex mesh by 2x2x2 cell splitting for the specified cellSet"
65 );
66 #include "addOverwriteOption.H"
67 #include "addRegionOption.H"
68 argList::addArgument("cellSet");
70 (
71 "minSet",
72 "Remove cells from input cellSet to keep to 2:1 ratio"
73 " (default is to extend set)"
74 );
75
76 argList::noFunctionObjects(); // Never use function objects
77
78 #include "setRootCase.H"
79 #include "createTime.H"
80 #include "createNamedMesh.H"
81
82 const word oldInstance = mesh.pointsInstance();
83
84 word cellSetName(args[1]);
85 const bool overwrite = args.found("overwrite");
86
87 const bool minSet = args.found("minSet");
88
89 Info<< "Reading cells to refine from cellSet " << cellSetName
90 << nl << endl;
91
92 cellSet cellsToRefine(mesh, cellSetName);
93
94 Info<< "Read " << returnReduce(cellsToRefine.size(), sumOp<label>())
95 << " cells to refine from cellSet " << cellSetName << nl
96 << endl;
97
98
99 // Read objects in time directory
100 IOobjectList objects(mesh, runTime.timeName());
101
102 // Read vol fields.
103
105 ReadFields(mesh, objects, vsFlds);
106
108 ReadFields(mesh, objects, vvFlds);
109
111 ReadFields(mesh, objects, vstFlds);
112
114 ReadFields(mesh, objects, vsymtFlds);
115
117 ReadFields(mesh, objects, vtFlds);
118
119 // Read surface fields.
120
122 ReadFields(mesh, objects, ssFlds);
123
125 ReadFields(mesh, objects, svFlds);
126
128 ReadFields(mesh, objects, sstFlds);
129
131 ReadFields(mesh, objects, ssymtFlds);
132
134 ReadFields(mesh, objects, stFlds);
135
136 // Read point fields
138 ReadFields(pointMesh::New(mesh), objects, psFlds);
139
141 ReadFields(pointMesh::New(mesh), objects, pvFlds);
142
143
144 // Construct refiner without unrefinement. Read existing point/cell level.
146
147 // Some stats
148 {
149 auto cellLimits = gMinMax(meshCutter.cellLevel());
150 auto pointLimits = gMinMax(meshCutter.pointLevel());
151
152 Info<< "Read mesh:" << nl
153 << " cells:" << mesh.globalData().nTotalCells() << nl
154 << " faces:" << mesh.globalData().nTotalFaces() << nl
155 << " points:" << mesh.globalData().nTotalPoints() << nl
156 << " cellLevel :"
157 << " min:" << cellLimits.min()
158 << " max:" << cellLimits.max() << nl
159 << " pointLevel :"
160 << " min:" << pointLimits.min()
161 << " max:" << pointLimits.max() << nl
162 << endl;
163 }
164
165
166 // Maintain 2:1 ratio
167 labelList newCellsToRefine
168 (
169 meshCutter.consistentRefinement
170 (
171 cellsToRefine.toc(),
172 !minSet // extend set
173 )
174 );
175
176 // Mesh changing engine.
177 polyTopoChange meshMod(mesh);
178
179 // Play refinement commands into mesh changer.
180 meshCutter.setRefinement(newCellsToRefine, meshMod);
181
182 if (!overwrite)
183 {
184 ++runTime;
185 }
186
187 // Create mesh, return map from old to new mesh.
188 autoPtr<mapPolyMesh> map = meshMod.changeMesh(mesh, false);
189
190 // Update fields
191 mesh.updateMesh(map());
192
193 // Update numbering of cells/vertices.
194 meshCutter.updateMesh(map());
195
196 // Optionally inflate mesh
197 if (map().hasMotionPoints())
198 {
199 mesh.movePoints(map().preMotionPoints());
200 }
201
202 Info<< "Refined from " << returnReduce(map().nOldCells(), sumOp<label>())
203 << " to " << mesh.globalData().nTotalCells() << " cells." << nl << endl;
204
205 if (overwrite)
206 {
207 mesh.setInstance(oldInstance);
208 meshCutter.setInstance(oldInstance);
209 }
210 Info<< "Writing mesh to " << runTime.timeName() << endl;
211
212 mesh.write();
213 meshCutter.write();
216
217 Info<< "End\n" << endl;
218
219 return 0;
220}
221
222
223// ************************************************************************* //
Field reading functions for post-processing utilities.
Required Classes.
List of IOobjects with searching and retrieving facilities. Implemented as a HashTable,...
static FOAM_NO_DANGLING_REFERENCE const pointMesh & New(const polyMesh &mesh, Args &&... args)
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition PtrList.H:67
static void noFunctionObjects(bool addWithOption=false)
Remove '-noFunctionObjects' option and ignore any occurrences.
Definition argList.C:562
static void addArgument(const string &argName, const string &usage="")
Append a (mandatory) argument to validArgs.
Definition argList.C:366
static void addBoolOption(const word &optName, const string &usage="", bool advanced=false)
Add a bool option to validOptions with usage information.
Definition argList.C:389
static void addNote(const string &note)
Add extra notes for the usage information.
Definition argList.C:477
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition autoPtr.H:65
A collection of cell labels.
Definition cellSet.H:50
Refinement of (split) hexes using polyTopoChange.
Definition hexRef8.H:63
Cuts (splits) cells.
Definition meshCutter.H:137
void updateMesh(const mapPolyMesh &)
Force recalculation of locally stored data on topological change.
Definition meshCutter.C:988
void setRefinement(const cellCuts &cuts, polyTopoChange &meshMod)
Do actual cutting with cut description. Inserts mesh changes.
Definition meshCutter.C:515
Direct mesh changes based on v1.3 polyTopoChange syntax.
static void removeFiles(const polyMesh &mesh)
Helper: remove all procAddressing files from mesh instance.
static void removeFiles(const polyMesh &)
Helper: remove all sets files from mesh instance.
Definition topoSet.C:693
A class for handling words, derived from Foam::string.
Definition word.H:66
dynamicFvMesh & mesh
engineTime & runTime
Required Classes.
return returnReduce(nRefine-oldNRefine, sumOp< label >())
Namespace for OpenFOAM.
wordList ReadFields(const typename GeoMesh::Mesh &mesh, const IOobjectList &objects, PtrList< GeometricField< Type, PatchField, GeoMesh > > &fields, const bool syncPar=true, const bool readOldTime=false)
Read Geometric fields of templated type.
List< label > labelList
A List of labels.
Definition List.H:62
messageStream Info
Information stream (stdout output on master, null elsewhere).
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
MinMax< Type > gMinMax(const FieldField< Field, Type > &f)
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
Foam::argList args(argc, argv)
Foam::surfaceFields.