Forward compatibility: flex
[foam-extend-3.2.git] / applications / utilities / mesh / manipulation / attachMesh / attachPolyTopoChanger.C
blob223f82f7ffd1dfd8100fabe6ba86059575d089eb
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | foam-extend: Open Source CFD
4    \\    /   O peration     | Version:     3.2
5     \\  /    A nd           | Web:         http://www.foam-extend.org
6      \\/     M anipulation  | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
8 License
9     This file is part of foam-extend.
11     foam-extend 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 3 of the License, or (at your
14     option) any later version.
16     foam-extend is distributed in the hope that it will be useful, but
17     WITHOUT ANY WARRANTY; without even the implied warranty of
18     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19     General Public License for more details.
21     You should have received a copy of the GNU General Public License
22     along with foam-extend.  If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "attachPolyTopoChanger.H"
27 #include "polyMesh.H"
28 #include "polyTopoChange.H"
29 #include "mapPolyMesh.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();
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 // ************************************************************************* //