FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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-2010 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
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your 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, see <http://www.gnu.org/licenses/>.
00023 
00024 Application
00025     refineWallLayer
00026 
00027 Description
00028     Utility to refine cells next to patches.
00029 
00030     Takes a patchName and number of layers to refine. Works out cells within
00031     these layers and refines those in the wall-normal direction.
00032 
00033 Usage
00034 
00035     - refineWallLayer [OPTIONS] <patchName> <edgeWeight>
00036 
00037     @param <patchName> \n
00038     @todo Detailed description of argument.
00039 
00040     @param <edgeWeight> \n
00041     @todo Detailed description of argument.
00042 
00043     @param -useSet <cellSet name>\n
00044     Refine named cell set.
00045 
00046     @param -overwrite \n
00047     Overwrite existing data.
00048 
00049     @param -case <dir>\n
00050     Case directory.
00051 
00052     @param -help \n
00053     Display help message.
00054 
00055     @param -doc \n
00056     Display Doxygen API documentation page for this application.
00057 
00058     @param -srcDoc \n
00059     Display Doxygen source documentation page for this application.
00060 
00061 \*---------------------------------------------------------------------------*/
00062 
00063 #include <OpenFOAM/argList.H>
00064 #include <OpenFOAM/Time.H>
00065 #include <dynamicMesh/polyTopoChange.H>
00066 #include <dynamicMesh/polyTopoChanger.H>
00067 #include <OpenFOAM/mapPolyMesh.H>
00068 #include <OpenFOAM/polyMesh.H>
00069 #include <dynamicMesh/cellCuts.H>
00070 #include <meshTools/cellSet.H>
00071 #include <dynamicMesh/meshCutter.H>
00072 
00073 using namespace Foam;
00074 
00075 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00076 // Main program:
00077 
00078 int main(int argc, char *argv[])
00079 {
00080     Foam::argList::noParallel();
00081     Foam::argList::validArgs.append("patchName");
00082     Foam::argList::validArgs.append("edgeWeight");
00083     Foam::argList::validOptions.insert("useSet", "cellSet");
00084     Foam::argList::validOptions.insert("overwrite", "");
00085 
00086 #   include <OpenFOAM/setRootCase.H>
00087 #   include <OpenFOAM/createTime.H>
00088     runTime.functionObjects().off();
00089 #   include <OpenFOAM/createPolyMesh.H>
00090     const word oldInstance = mesh.pointsInstance();
00091 
00092     word patchName(args.additionalArgs()[0]);
00093 
00094     scalar weight(readScalar(IStringStream(args.additionalArgs()[1])()));
00095     bool overwrite = args.optionFound("overwrite");
00096 
00097 
00098     label patchID = mesh.boundaryMesh().findPatchID(patchName);
00099 
00100     if (patchID == -1)
00101     {
00102         FatalErrorIn(args.executable())
00103             << "Cannot find patch " << patchName << endl
00104             << "Valid patches are " << mesh.boundaryMesh().names()
00105             << exit(FatalError);
00106     }
00107     const polyPatch& pp = mesh.boundaryMesh()[patchID];
00108 
00109 
00110     // Cells cut
00111 
00112     labelHashSet cutCells(4*pp.size());
00113 
00114     const labelList& meshPoints = pp.meshPoints();
00115 
00116     forAll(meshPoints, pointI)
00117     {
00118         label meshPointI = meshPoints[pointI];
00119 
00120         const labelList& pCells = mesh.pointCells()[meshPointI];
00121 
00122         forAll(pCells, pCellI)
00123         {
00124             cutCells.insert(pCells[pCellI]);
00125         }
00126     }
00127 
00128     Info<< "Selected " << cutCells.size()
00129         << " cells connected to patch " << pp.name() << endl << endl;
00130 
00131     //
00132     // List of cells to refine
00133     //
00134 
00135     bool useSet = args.optionFound("useSet");
00136 
00137     if (useSet)
00138     {
00139         word setName(args.option("useSet"));
00140 
00141         Info<< "Subsetting cells to cut based on cellSet" << setName << endl
00142             << endl;
00143 
00144         cellSet cells(mesh, setName);
00145 
00146         Info<< "Read " << cells.size() << " cells from cellSet "
00147             << cells.instance()/cells.local()/cells.name()
00148             << endl << endl;
00149 
00150         for
00151         (
00152             cellSet::const_iterator iter = cells.begin();
00153             iter != cells.end();
00154             ++iter
00155         )
00156         {
00157             cutCells.erase(iter.key());
00158         }
00159         Info<< "Removed from cells to cut all the ones not in set " << setName
00160             << endl << endl;
00161     }
00162 
00163     // Mark all meshpoints on patch
00164 
00165     boolList vertOnPatch(mesh.nPoints(), false);
00166 
00167     forAll(meshPoints, pointI)
00168     {
00169         label meshPointI = meshPoints[pointI];
00170 
00171         vertOnPatch[meshPointI] = true;
00172     }
00173 
00174 
00175     // Mark cut edges.
00176 
00177     DynamicList<label> allCutEdges(pp.nEdges());
00178 
00179     DynamicList<scalar> allCutEdgeWeights(pp.nEdges());
00180 
00181     forAll(meshPoints, pointI)
00182     {
00183         label meshPointI = meshPoints[pointI];
00184 
00185         const labelList& pEdges = mesh.pointEdges()[meshPointI];
00186 
00187         forAll(pEdges, pEdgeI)
00188         {
00189             label edgeI = pEdges[pEdgeI];
00190 
00191             const edge& e = mesh.edges()[edgeI];
00192 
00193             label otherPointI = e.otherVertex(meshPointI);
00194 
00195             if (!vertOnPatch[otherPointI])
00196             {
00197                 allCutEdges.append(edgeI);
00198 
00199                 if (e.start() == meshPointI)
00200                 {
00201                     allCutEdgeWeights.append(weight);
00202                 }
00203                 else
00204                 {
00205                     allCutEdgeWeights.append(1 - weight);
00206                 }
00207             }
00208         }
00209     }
00210 
00211     allCutEdges.shrink();
00212     allCutEdgeWeights.shrink();
00213 
00214     Info<< "Cutting:" << endl
00215         << "    cells:" << cutCells.size() << endl
00216         << "    edges:" << allCutEdges.size() << endl
00217         << endl;
00218 
00219     // Transfer DynamicLists to straight ones.
00220     scalarField cutEdgeWeights;
00221     cutEdgeWeights.transfer(allCutEdgeWeights);
00222     allCutEdgeWeights.clear();
00223 
00224 
00225     // Gets cuts across cells from cuts through edges.
00226     cellCuts cuts
00227     (
00228         mesh,
00229         cutCells.toc(),     // cells candidate for cutting
00230         labelList(0),       // cut vertices
00231         allCutEdges,        // cut edges
00232         cutEdgeWeights      // weight on cut edges
00233     );
00234 
00235     polyTopoChange meshMod(mesh);
00236 
00237     // Cutting engine
00238     meshCutter cutter(mesh);
00239 
00240     // Insert mesh refinement into polyTopoChange.
00241     cutter.setRefinement(cuts, meshMod);
00242 
00243     // Do all changes
00244     Info<< "Morphing ..." << endl;
00245 
00246     if (!overwrite)
00247     {
00248         runTime++;
00249     }
00250 
00251     autoPtr<mapPolyMesh> morphMap = meshMod.changeMesh(mesh, false);
00252 
00253     if (morphMap().hasMotionPoints())
00254     {
00255         mesh.movePoints(morphMap().preMotionPoints());
00256     }
00257 
00258     // Update stored labels on meshCutter.
00259     cutter.updateMesh(morphMap());
00260 
00261     if (overwrite)
00262     {
00263         mesh.setInstance(oldInstance);
00264     }
00265 
00266     // Write resulting mesh
00267     Info << "Writing refined morphMesh to time " << runTime.timeName() << endl;
00268 
00269     mesh.write();
00270 
00271     Info << "End\n" << endl;
00272 
00273     return 0;
00274 }
00275 
00276 
00277 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines