1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2008 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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 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, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 Utility to refine cells next to patches. Takes a patchName
27 and number of layers to refine. Works out cells within these layers
28 and refines those in the wall-normal direction.
30 \*---------------------------------------------------------------------------*/
34 #include "polyTopoChange.H"
35 #include "polyTopoChanger.H"
36 #include "mapPolyMesh.H"
40 #include "meshCutter.H"
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47 int main(int argc, char *argv[])
49 Foam::argList::noParallel();
50 Foam::argList::validArgs.append("patchName");
51 Foam::argList::validArgs.append("edgeWeight");
52 Foam::argList::validOptions.insert("useSet", "cellSet");
53 Foam::argList::validOptions.insert("overwrite", "");
55 # include "setRootCase.H"
56 # include "createTime.H"
57 # include "createPolyMesh.H"
59 word patchName(args.additionalArgs()[0]);
61 scalar weight(readScalar(IStringStream(args.additionalArgs()[1])()));
62 bool overwrite = args.options().found("overwrite");
65 label patchID = mesh.boundaryMesh().findPatchID(patchName);
69 FatalErrorIn(args.executable())
70 << "Cannot find patch " << patchName << endl
71 << "Valid patches are " << mesh.boundaryMesh().names()
74 const polyPatch& pp = mesh.boundaryMesh()[patchID];
79 labelHashSet cutCells(4*pp.size());
81 const labelList& meshPoints = pp.meshPoints();
83 forAll(meshPoints, pointI)
85 label meshPointI = meshPoints[pointI];
87 const labelList& pCells = mesh.pointCells()[meshPointI];
89 forAll(pCells, pCellI)
91 cutCells.insert(pCells[pCellI]);
95 Info<< "Selected " << cutCells.size()
96 << " cells connected to patch " << pp.name() << endl << endl;
99 // List of cells to refine
102 bool useSet = args.options().found("useSet");
106 word setName(args.options()["useSet"]);
108 Info<< "Subsetting cells to cut based on cellSet" << setName << endl
111 cellSet cells(mesh, setName);
113 Info<< "Read " << cells.size() << " cells from cellSet "
114 << cells.instance()/cells.local()/cells.name()
119 cellSet::const_iterator iter = cells.begin();
124 cutCells.erase(iter.key());
126 Info<< "Removed from cells to cut all the ones not in set " << setName
130 // Mark all meshpoints on patch
132 boolList vertOnPatch(mesh.nPoints(), false);
134 forAll(meshPoints, pointI)
136 label meshPointI = meshPoints[pointI];
138 vertOnPatch[meshPointI] = true;
144 DynamicList<label> allCutEdges(pp.nEdges());
146 DynamicList<scalar> allCutEdgeWeights(pp.nEdges());
148 forAll(meshPoints, pointI)
150 label meshPointI = meshPoints[pointI];
152 const labelList& pEdges = mesh.pointEdges()[meshPointI];
154 forAll(pEdges, pEdgeI)
156 label edgeI = pEdges[pEdgeI];
158 const edge& e = mesh.edges()[edgeI];
160 label otherPointI = e.otherVertex(meshPointI);
162 if (!vertOnPatch[otherPointI])
164 allCutEdges.append(edgeI);
166 if (e.start() == meshPointI)
168 allCutEdgeWeights.append(weight);
172 allCutEdgeWeights.append(1 - weight);
178 allCutEdges.shrink();
179 allCutEdgeWeights.shrink();
181 Info<< "Cutting:" << endl
182 << " cells:" << cutCells.size() << endl
183 << " edges:" << allCutEdges.size() << endl
186 // Transfer DynamicLists to straight ones.
188 cutEdges.transfer(allCutEdges);
191 scalarField cutEdgeWeights;
192 cutEdgeWeights.transfer(allCutEdgeWeights);
193 allCutEdgeWeights.clear();
196 // Gets cuts across cells from cuts through edges.
200 cutCells.toc(), // cells candidate for cutting
201 labelList(0), // cut vertices
202 cutEdges, // cut edges
203 cutEdgeWeights // weight on cut edges
206 polyTopoChange meshMod(mesh);
209 meshCutter cutter(mesh);
211 // Insert mesh refinement into polyTopoChange.
212 cutter.setRefinement(cuts, meshMod);
215 Info<< "Morphing ..." << endl;
222 autoPtr<mapPolyMesh> morphMap = meshMod.changeMesh(mesh, false);
224 if (morphMap().hasMotionPoints())
226 mesh.movePoints(morphMap().preMotionPoints());
229 // Update stored labels on meshCutter.
230 cutter.updateMesh(morphMap());
232 // Write resulting mesh
233 Info << "Writing refined morphMesh to time " << runTime.value() << endl;
237 Info << "End\n" << endl;
243 // ************************************************************************* //