FreeFOAM The Cross-Platform CFD Toolkit
attachPolyTopoChanger.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
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.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "attachPolyTopoChanger.H"
27 #include <OpenFOAM/polyMesh.H>
29 
30 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
31 
32 Foam::attachPolyTopoChanger::attachPolyTopoChanger
33 (
34  const IOobject& io,
35  polyMesh& mesh
36 )
37 :
38  polyTopoChanger(io, mesh)
39 {}
40 
41 
42 Foam::attachPolyTopoChanger::attachPolyTopoChanger
43 (
44  polyMesh& mesh
45 )
46 :
47  polyTopoChanger(mesh)
48 {}
49 
50 
51 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
52 
53 //- Attach mesh
54 void Foam::attachPolyTopoChanger::attach(const bool removeEmptyPatches)
55 {
56  if (debug)
57  {
58  Pout<< "void attachPolyTopoChanger::attach(): "
59  << "Attaching mesh" << endl;
60  }
61 
62  // Save current file instance
63  const fileName oldInst = mesh_.facesInstance();
64 
65  // Execute all polyMeshModifiers
66  changeMesh(false); // no inflation
67 
68  const pointField p = mesh_.oldPoints();
69 
70  mesh_.movePoints(p);
71 
72  if (debug)
73  {
74  Pout << "Clearing mesh." << endl;
75  }
76 
77  if (removeEmptyPatches)
78  {
79  // Re-do the boundary patches, removing the ones with zero size
80  const polyBoundaryMesh& oldPatches = mesh_.boundaryMesh();
81 
82  List<polyPatch*> newPatches(oldPatches.size());
83  label nNewPatches = 0;
84 
85  forAll (oldPatches, patchI)
86  {
87  if (oldPatches[patchI].size())
88  {
89  newPatches[nNewPatches] = oldPatches[patchI].clone
90  (
92  nNewPatches,
93  oldPatches[patchI].size(),
94  oldPatches[patchI].start()
95  ).ptr();
96 
97  nNewPatches++;
98  }
99  else
100  {
101  if (debug)
102  {
103  Pout<< "Removing zero-sized patch " << patchI
104  << " named " << oldPatches[patchI].name() << endl;
105  }
106  }
107  }
108 
109  newPatches.setSize(nNewPatches);
110 
112  mesh_.addPatches(newPatches);
113  }
114 
115  // Reset the file instance to overwrite the original mesh
116  mesh_.setInstance(oldInst);
117 
118  if (debug)
119  {
120  Pout<< "void attachPolyTopoChanger::attach(): "
121  << "Finished attaching mesh" << endl;
122  }
123 
124  mesh_.checkMesh();
125 }
126 
127 
128 // ************************ vim: set sw=4 sts=4 et: ************************ //