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) 2011 OpenFOAM Foundation
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 "polyMesh.H"
28 #include "polyTopoChange.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 // ************************************************************************* //
virtual tmp< scalarField > movePoints(const pointField &)
Move points, returns volumes swept by faces in motion.
Definition: polyMesh.C:1105
void removeBoundary()
Remove boundary patches.
Definition: polyMeshClear.C:36
void attach(const bool removeEmptyPatches=true)
Attach mesh. By default filter out empty patches.
label size() const
Return the number of elements in the PtrList.
Definition: PtrListI.H:32
Foam::autoPtr< IOobject > clone() const
Clone.
Definition: IOobject.H:239
void setInstance(const fileName &)
Set the instance for mesh files.
Definition: polyMeshIO.C:32
virtual const pointField & oldPoints() const
Return old points for mesh motion.
Definition: polyMesh.C:1085
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
autoPtr< mapPolyMesh > changeMesh(const bool inflate, const bool syncParallel=true, const bool orderCells=false, const bool orderPoints=false)
void addPatches(const List< polyPatch * > &, const bool validBoundary=true)
Add boundary patches.
Definition: polyMesh.C:925
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
Foam::polyBoundaryMesh.
volScalarField & p
Definition: createFields.H:51
#define forAll(list, i)
Definition: UList.H:421
polyMesh & mesh_
Reference to mesh.
List of mesh modifiers defining the mesh dynamics.
const word & name() const
Return name.
Definition: IOobject.H:260
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:421
const fileName & facesInstance() const
Return the current instance directory for faces.
Definition: polyMesh.C:824
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
virtual bool checkMesh(const bool report=false) const
Check mesh for correctness. Returns false for no error.
A class for handling file names.
Definition: fileName.H:69
prefixOSstream Pout(cout,"Pout")
Definition: IOstreams.H:53