initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / dynamicMesh / polyTopoChange / attachPolyTopoChanger / attachPolyTopoChanger.C
blob73b285f74edb2293d03bf051ad12cc733550e398
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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
25 \*---------------------------------------------------------------------------*/
27 #include "attachPolyTopoChanger.H"
28 #include "polyMesh.H"
29 #include "polyTopoChange.H"
31 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
33 Foam::attachPolyTopoChanger::attachPolyTopoChanger
35     const IOobject& io,
36     polyMesh& mesh
39     polyTopoChanger(io, mesh)
43 Foam::attachPolyTopoChanger::attachPolyTopoChanger
45     polyMesh& mesh
48     polyTopoChanger(mesh)
52 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
54 //- Attach mesh
55 void Foam::attachPolyTopoChanger::attach(const bool removeEmptyPatches)
57     if (debug)
58     {
59         Pout<< "void attachPolyTopoChanger::attach(): "
60             << "Attaching mesh" << endl;
61     }
63     // Save current file instance
64     const fileName oldInst = mesh_.facesInstance();
66     // Execute all polyMeshModifiers
67     changeMesh(false);  // no inflation
69     const pointField p = mesh_.oldPoints();
71     mesh_.movePoints(p);
73     if (debug)
74     {
75         Pout << "Clearing mesh." << endl;
76     }
78     if (removeEmptyPatches)
79     {
80         // Re-do the boundary patches, removing the ones with zero size
81         const polyBoundaryMesh& oldPatches = mesh_.boundaryMesh();
83         List<polyPatch*> newPatches(oldPatches.size());
84         label nNewPatches = 0;
86         forAll (oldPatches, patchI)
87         {
88             if (oldPatches[patchI].size())
89             {
90                 newPatches[nNewPatches] = oldPatches[patchI].clone
91                 (
92                     mesh_.boundaryMesh(),
93                     nNewPatches,
94                     oldPatches[patchI].size(),
95                     oldPatches[patchI].start()
96                 ).ptr();
98                 nNewPatches++;
99             }
100             else
101             {
102                 if (debug)
103                 {
104                     Pout<< "Removing zero-sized patch " << patchI
105                         << " named " << oldPatches[patchI].name() << endl;
106                 }
107             }
108         }
110         newPatches.setSize(nNewPatches);
112         mesh_.removeBoundary();
113         mesh_.addPatches(newPatches);
114     }
116     // Reset the file instance to overwrite the original mesh
117     mesh_.setInstance(oldInst);
119     if (debug)
120     {
121         Pout<< "void attachPolyTopoChanger::attach(): "
122             << "Finished attaching mesh" << endl;
123     }
125     mesh_.checkMesh();
129 // ************************************************************************* //