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

attachPolyTopoChanger.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 \*---------------------------------------------------------------------------*/
00026 
00027 #include "attachPolyTopoChanger.H"
00028 #include "polyMesh.H"
00029 #include "polyTopoChange.H"
00030 
00031 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00032 
00033 Foam::attachPolyTopoChanger::attachPolyTopoChanger
00034 (
00035     const IOobject& io,
00036     polyMesh& mesh
00037 )
00038 :
00039     polyTopoChanger(io, mesh)
00040 {}
00041 
00042 
00043 Foam::attachPolyTopoChanger::attachPolyTopoChanger
00044 (
00045     polyMesh& mesh
00046 )
00047 :
00048     polyTopoChanger(mesh)
00049 {}
00050 
00051 
00052 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00053 
00054 //- Attach mesh
00055 void Foam::attachPolyTopoChanger::attach(const bool removeEmptyPatches)
00056 {
00057     if (debug)
00058     {
00059         Pout<< "void attachPolyTopoChanger::attach(): "
00060             << "Attaching mesh" << endl;
00061     }
00062 
00063     // Save current file instance
00064     const fileName oldInst = mesh_.facesInstance();
00065 
00066     // Execute all polyMeshModifiers
00067     changeMesh(false);  // no inflation
00068 
00069     const pointField p = mesh_.oldPoints();
00070 
00071     mesh_.movePoints(p);
00072 
00073     if (debug)
00074     {
00075         Pout << "Clearing mesh." << endl;
00076     }
00077 
00078     if (removeEmptyPatches)
00079     {
00080         // Re-do the boundary patches, removing the ones with zero size
00081         const polyBoundaryMesh& oldPatches = mesh_.boundaryMesh();
00082 
00083         List<polyPatch*> newPatches(oldPatches.size());
00084         label nNewPatches = 0;
00085 
00086         forAll (oldPatches, patchI)
00087         {
00088             if (oldPatches[patchI].size())
00089             {
00090                 newPatches[nNewPatches] = oldPatches[patchI].clone
00091                 (
00092                     mesh_.boundaryMesh(),
00093                     nNewPatches,
00094                     oldPatches[patchI].size(),
00095                     oldPatches[patchI].start()
00096                 ).ptr();
00097 
00098                 nNewPatches++;
00099             }
00100             else
00101             {
00102                 if (debug)
00103                 {
00104                     Pout<< "Removing zero-sized patch " << patchI
00105                         << " named " << oldPatches[patchI].name() << endl;
00106                 }
00107             }
00108         }
00109 
00110         newPatches.setSize(nNewPatches);
00111 
00112         mesh_.removeBoundary();
00113         mesh_.addPatches(newPatches);
00114     }
00115 
00116     // Reset the file instance to overwrite the original mesh
00117     mesh_.setInstance(oldInst);
00118 
00119     if (debug)
00120     {
00121         Pout<< "void attachPolyTopoChanger::attach(): "
00122             << "Finished attaching mesh" << endl;
00123     }
00124 
00125     mesh_.checkMesh();
00126 }
00127 
00128 
00129 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd