attachPolyTopoChanger.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 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 
33 (
34  const IOobject& io,
35  polyMesh& mesh
36 )
37 :
38  polyTopoChanger(io, mesh)
39 {}
40 
41 
43 (
44  polyMesh& mesh
45 )
46 :
47  polyTopoChanger(mesh)
48 {}
49 
50 
51 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
52 
53 void Foam::attachPolyTopoChanger::attach(const bool removeEmptyPatches)
54 {
55  if (debug)
56  {
57  Pout<< "void attachPolyTopoChanger::attach(): "
58  << "Attaching mesh" << endl;
59  }
60 
61  // Save current file instance
62  const fileName oldInst = mesh_.facesInstance();
63 
64  // Execute all polyMeshModifiers
65  changeMesh(false); // no inflation
66 
67  const pointField p = mesh_.oldPoints();
68 
69  mesh_.movePoints(p);
70 
71  if (debug)
72  {
73  Pout<< "Clearing mesh." << endl;
74  }
75 
76  if (removeEmptyPatches)
77  {
78  // Re-do the boundary patches, removing the ones with zero size
79  const polyBoundaryMesh& oldPatches = mesh_.boundaryMesh();
80 
81  List<polyPatch*> newPatches(oldPatches.size());
82  label nNewPatches = 0;
83 
84  forAll(oldPatches, patchi)
85  {
86  if (oldPatches[patchi].size())
87  {
88  newPatches[nNewPatches] = oldPatches[patchi].clone
89  (
91  nNewPatches,
92  oldPatches[patchi].size(),
93  oldPatches[patchi].start()
94  ).ptr();
95 
96  nNewPatches++;
97  }
98  else
99  {
100  if (debug)
101  {
102  Pout<< "Removing zero-sized patch " << patchi
103  << " named " << oldPatches[patchi].name() << endl;
104  }
105  }
106  }
107 
108  newPatches.setSize(nNewPatches);
109 
111  mesh_.addPatches(newPatches);
112  }
113 
114  // Reset the file instance to overwrite the original mesh
115  mesh_.setInstance(oldInst);
116 
117  if (debug)
118  {
119  Pout<< "void attachPolyTopoChanger::attach(): "
120  << "Finished attaching mesh" << endl;
121  }
122 
123  mesh_.checkMesh();
124 }
125 
126 
127 // ************************************************************************* //
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:434
autoPtr< IOobject > clone() const
Clone.
Definition: IOobject.H:276
virtual tmp< scalarField > movePoints(const pointField &)
Move points, returns volumes swept by faces in motion.
Definition: polyMesh.C:1287
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
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
const word & name() const
Return name.
Definition: IOobject.H:303
A class for handling file names.
Definition: fileName.H:79
const fileName & facesInstance() const
Return the current instance directory for faces.
Definition: polyMesh.C:808
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
void attach(const bool removeEmptyPatches=true)
Attach mesh. By default filter out empty patches.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
polyMesh & mesh_
Reference to mesh.
autoPtr< mapPolyMesh > changeMesh(const bool inflate, const bool syncParallel=true, const bool orderCells=false, const bool orderPoints=false)
List of mesh modifiers defining the mesh dynamics.
virtual const pointField & oldPoints() const
Return old points for mesh motion.
Definition: polyMesh.C:1181
virtual bool checkMesh(const bool report=false) const
Check mesh for correctness. Returns false for no error.
void addPatches(const List< polyPatch *> &, const bool validBoundary=true)
Add boundary patches.
Definition: polyMesh.C:909
Foam::polyBoundaryMesh.
void removeBoundary()
Remove boundary patches.
Definition: polyMeshClear.C:36
void setInstance(const fileName &)
Set the instance for mesh files.
Definition: polyMeshIO.C:32
label size() const
Return the number of elements in the UPtrList.
Definition: UPtrListI.H:29
label patchi
prefixOSstream Pout(cout, "Pout")
Definition: IOstreams.H:53
attachPolyTopoChanger(const IOobject &io, polyMesh &)
Read constructor from IOobject and a polyMesh.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
volScalarField & p
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:92