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

refineHexMesh.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     Refines a hex mesh by 2x2x2 cell splitting.
00027 
00028 \*---------------------------------------------------------------------------*/
00029 
00030 #include "fvMesh.H"
00031 #include "pointMesh.H"
00032 #include "argList.H"
00033 #include "Time.H"
00034 #include "hexRef8.H"
00035 #include "cellSet.H"
00036 #include "OFstream.H"
00037 #include "meshTools.H"
00038 #include "IFstream.H"
00039 #include "polyTopoChange.H"
00040 #include "mapPolyMesh.H"
00041 #include "volMesh.H"
00042 #include "surfaceMesh.H"
00043 #include "volFields.H"
00044 #include "surfaceFields.H"
00045 #include "pointFields.H"
00046 #include "ReadFields.H"
00047 
00048 using namespace Foam;
00049 
00050 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00051 
00052 // Main program:
00053 int main(int argc, char *argv[])
00054 {
00055     argList::validOptions.insert("overwrite", "");
00056     argList::validArgs.append("cellSet");
00057 #   include "setRootCase.H"
00058 #   include "createTime.H"
00059     runTime.functionObjects().off();
00060 #   include "createMesh.H"
00061     const word oldInstance = mesh.pointsInstance();
00062 
00063     pointMesh pMesh(mesh);
00064 
00065     word cellSetName(args.args()[1]);
00066     bool overwrite = args.optionFound("overwrite");
00067 
00068     Info<< "Reading cells to refine from cellSet " << cellSetName
00069         << nl << endl;
00070 
00071     cellSet cellsToRefine(mesh, cellSetName);
00072 
00073     Info<< "Read " << returnReduce(cellsToRefine.size(), sumOp<label>())
00074         << " cells to refine from cellSet " << cellSetName << nl
00075         << endl;
00076 
00077 
00078     // Read objects in time directory
00079     IOobjectList objects(mesh, runTime.timeName());
00080 
00081     // Read vol fields.
00082 
00083     PtrList<volScalarField> vsFlds;
00084     ReadFields(mesh, objects, vsFlds);
00085 
00086     PtrList<volVectorField> vvFlds;
00087     ReadFields(mesh, objects, vvFlds);
00088 
00089     PtrList<volSphericalTensorField> vstFlds;
00090     ReadFields(mesh, objects, vstFlds);
00091 
00092     PtrList<volSymmTensorField> vsymtFlds;
00093     ReadFields(mesh, objects, vsymtFlds);
00094 
00095     PtrList<volTensorField> vtFlds;
00096     ReadFields(mesh, objects, vtFlds);
00097 
00098     // Read surface fields.
00099 
00100     PtrList<surfaceScalarField> ssFlds;
00101     ReadFields(mesh, objects, ssFlds);
00102 
00103     PtrList<surfaceVectorField> svFlds;
00104     ReadFields(mesh, objects, svFlds);
00105 
00106     PtrList<surfaceSphericalTensorField> sstFlds;
00107     ReadFields(mesh, objects, sstFlds);
00108 
00109     PtrList<surfaceSymmTensorField> ssymtFlds;
00110     ReadFields(mesh, objects, ssymtFlds);
00111 
00112     PtrList<surfaceTensorField> stFlds;
00113     ReadFields(mesh, objects, stFlds);
00114 
00115     // Read point fields
00116     PtrList<pointScalarField> psFlds;
00117     ReadFields(pMesh, objects, psFlds);
00118 
00119     PtrList<pointVectorField> pvFlds;
00120     ReadFields(pMesh, objects, pvFlds);
00121 
00122 
00123 
00124     // Construct refiner without unrefinement. Read existing point/cell level.
00125     hexRef8 meshCutter(mesh);
00126 
00127     // Some stats
00128     Info<< "Read mesh:" << nl
00129         << "    cells:" << mesh.globalData().nTotalCells() << nl
00130         << "    faces:" << mesh.globalData().nTotalFaces() << nl
00131         << "    points:" << mesh.globalData().nTotalPoints() << nl
00132         << "    cellLevel :"
00133         << " min:" << gMin(meshCutter.cellLevel())
00134         << " max:" << gMax(meshCutter.cellLevel()) << nl
00135         << "    pointLevel :"
00136         << " min:" << gMin(meshCutter.pointLevel())
00137         << " max:" << gMax(meshCutter.pointLevel()) << nl
00138         << endl;
00139 
00140 
00141     // Maintain 2:1 ratio
00142     labelList newCellsToRefine
00143     (
00144         meshCutter.consistentRefinement
00145         (
00146             cellsToRefine.toc(),
00147             true                  // extend set
00148         )
00149     );
00150 
00151     // Mesh changing engine.
00152     polyTopoChange meshMod(mesh);
00153 
00154     // Play refinement commands into mesh changer.
00155     meshCutter.setRefinement(newCellsToRefine, meshMod);
00156 
00157     if (!overwrite)
00158     {
00159         runTime++;
00160     }
00161 
00162     // Create mesh, return map from old to new mesh.
00163     autoPtr<mapPolyMesh> map = meshMod.changeMesh(mesh, false);
00164 
00165     // Update fields
00166     mesh.updateMesh(map);
00167     pMesh.updateMesh(map);
00168 
00169     // Update numbering of cells/vertices.
00170     meshCutter.updateMesh(map);
00171 
00172     // Optionally inflate mesh
00173     if (map().hasMotionPoints())
00174     {
00175         mesh.movePoints(map().preMotionPoints());
00176         pMesh.movePoints(map().preMotionPoints());
00177     }
00178 
00179     Pout<< "Refined from " << returnReduce(map().nOldCells(), sumOp<label>())
00180         << " to " << mesh.globalData().nTotalCells() << " cells." << nl << endl;
00181 
00182     if (overwrite)
00183     {
00184         mesh.setInstance(oldInstance);
00185         meshCutter.setInstance(oldInstance);
00186     }
00187     Info<< "Writing mesh to " << runTime.timeName() << endl;
00188 
00189     mesh.write();
00190     meshCutter.write();
00191 
00192     Info<< "End\n" << endl;
00193 
00194     return 0;
00195 }
00196 
00197 
00198 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd