OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

refineWallLayer.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 Description
00026     Utility to refine cells next to patches.
00027 
00028     Takes a patchName and number of layers to refine. Works out cells within
00029     these layers and refines those in the wall-normal direction.
00030 
00031 \*---------------------------------------------------------------------------*/
00032 
00033 #include "argList.H"
00034 #include "Time.H"
00035 #include "polyTopoChange.H"
00036 #include "polyTopoChanger.H"
00037 #include "mapPolyMesh.H"
00038 #include "polyMesh.H"
00039 #include "cellCuts.H"
00040 #include "cellSet.H"
00041 #include "meshCutter.H"
00042 
00043 using namespace Foam;
00044 
00045 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00046 // Main program:
00047 
00048 int main(int argc, char *argv[])
00049 {
00050     Foam::argList::noParallel();
00051     Foam::argList::validArgs.append("patchName");
00052     Foam::argList::validArgs.append("edgeWeight");
00053     Foam::argList::validOptions.insert("useSet", "cellSet");
00054     Foam::argList::validOptions.insert("overwrite", "");
00055 
00056 #   include "setRootCase.H"
00057 #   include "createTime.H"
00058     runTime.functionObjects().off();
00059 #   include "createPolyMesh.H"
00060     const word oldInstance = mesh.pointsInstance();
00061 
00062     word patchName(args.additionalArgs()[0]);
00063 
00064     scalar weight(readScalar(IStringStream(args.additionalArgs()[1])()));
00065     bool overwrite = args.optionFound("overwrite");
00066 
00067 
00068     label patchID = mesh.boundaryMesh().findPatchID(patchName);
00069 
00070     if (patchID == -1)
00071     {
00072         FatalErrorIn(args.executable())
00073             << "Cannot find patch " << patchName << endl
00074             << "Valid patches are " << mesh.boundaryMesh().names()
00075             << exit(FatalError);
00076     }
00077     const polyPatch& pp = mesh.boundaryMesh()[patchID];
00078 
00079 
00080     // Cells cut
00081 
00082     labelHashSet cutCells(4*pp.size());
00083 
00084     const labelList& meshPoints = pp.meshPoints();
00085 
00086     forAll(meshPoints, pointI)
00087     {
00088         label meshPointI = meshPoints[pointI];
00089 
00090         const labelList& pCells = mesh.pointCells()[meshPointI];
00091 
00092         forAll(pCells, pCellI)
00093         {
00094             cutCells.insert(pCells[pCellI]);
00095         }
00096     }
00097 
00098     Info<< "Selected " << cutCells.size()
00099         << " cells connected to patch " << pp.name() << endl << endl;
00100 
00101     //
00102     // List of cells to refine
00103     //
00104 
00105     bool useSet = args.optionFound("useSet");
00106 
00107     if (useSet)
00108     {
00109         word setName(args.option("useSet"));
00110 
00111         Info<< "Subsetting cells to cut based on cellSet" << setName << endl
00112             << endl;
00113 
00114         cellSet cells(mesh, setName);
00115 
00116         Info<< "Read " << cells.size() << " cells from cellSet "
00117             << cells.instance()/cells.local()/cells.name()
00118             << endl << endl;
00119 
00120         for
00121         (
00122             cellSet::const_iterator iter = cells.begin();
00123             iter != cells.end();
00124             ++iter
00125         )
00126         {
00127             cutCells.erase(iter.key());
00128         }
00129         Info<< "Removed from cells to cut all the ones not in set " << setName
00130             << endl << endl;
00131     }
00132 
00133     // Mark all meshpoints on patch
00134 
00135     boolList vertOnPatch(mesh.nPoints(), false);
00136 
00137     forAll(meshPoints, pointI)
00138     {
00139         label meshPointI = meshPoints[pointI];
00140 
00141         vertOnPatch[meshPointI] = true;
00142     }
00143 
00144 
00145     // Mark cut edges.
00146 
00147     DynamicList<label> allCutEdges(pp.nEdges());
00148 
00149     DynamicList<scalar> allCutEdgeWeights(pp.nEdges());
00150 
00151     forAll(meshPoints, pointI)
00152     {
00153         label meshPointI = meshPoints[pointI];
00154 
00155         const labelList& pEdges = mesh.pointEdges()[meshPointI];
00156 
00157         forAll(pEdges, pEdgeI)
00158         {
00159             label edgeI = pEdges[pEdgeI];
00160 
00161             const edge& e = mesh.edges()[edgeI];
00162 
00163             label otherPointI = e.otherVertex(meshPointI);
00164 
00165             if (!vertOnPatch[otherPointI])
00166             {
00167                 allCutEdges.append(edgeI);
00168 
00169                 if (e.start() == meshPointI)
00170                 {
00171                     allCutEdgeWeights.append(weight);
00172                 }
00173                 else
00174                 {
00175                     allCutEdgeWeights.append(1 - weight);
00176                 }
00177             }
00178         }
00179     }
00180 
00181     allCutEdges.shrink();
00182     allCutEdgeWeights.shrink();
00183 
00184     Info<< "Cutting:" << endl
00185         << "    cells:" << cutCells.size() << endl
00186         << "    edges:" << allCutEdges.size() << endl
00187         << endl;
00188 
00189     // Transfer DynamicLists to straight ones.
00190     scalarField cutEdgeWeights;
00191     cutEdgeWeights.transfer(allCutEdgeWeights);
00192     allCutEdgeWeights.clear();
00193 
00194 
00195     // Gets cuts across cells from cuts through edges.
00196     cellCuts cuts
00197     (
00198         mesh,
00199         cutCells.toc(),     // cells candidate for cutting
00200         labelList(0),       // cut vertices
00201         allCutEdges,        // cut edges
00202         cutEdgeWeights      // weight on cut edges
00203     );
00204 
00205     polyTopoChange meshMod(mesh);
00206 
00207     // Cutting engine
00208     meshCutter cutter(mesh);
00209 
00210     // Insert mesh refinement into polyTopoChange.
00211     cutter.setRefinement(cuts, meshMod);
00212 
00213     // Do all changes
00214     Info<< "Morphing ..." << endl;
00215 
00216     if (!overwrite)
00217     {
00218         runTime++;
00219     }
00220 
00221     autoPtr<mapPolyMesh> morphMap = meshMod.changeMesh(mesh, false);
00222 
00223     if (morphMap().hasMotionPoints())
00224     {
00225         mesh.movePoints(morphMap().preMotionPoints());
00226     }
00227 
00228     // Update stored labels on meshCutter.
00229     cutter.updateMesh(morphMap());
00230 
00231     if (overwrite)
00232     {
00233         mesh.setInstance(oldInstance);
00234     }
00235 
00236     // Write resulting mesh
00237     Info << "Writing refined morphMesh to time " << runTime.timeName() << endl;
00238 
00239     mesh.write();
00240 
00241     Info << "End\n" << endl;
00242 
00243     return 0;
00244 }
00245 
00246 
00247 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd