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 
33 (
34  const IOobject& io,
35  polyMesh& mesh
36 )
37 :
39 {}
40 
41 
43 (
44  polyMesh& mesh
45 )
46 :
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 
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 // ************************************************************************* //
Foam::attachPolyTopoChanger::attach
void attach(const bool removeEmptyPatches=true)
Attach mesh. By default filter out empty patches.
Definition: attachPolyTopoChanger.C:54
Foam::IOobject
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
p
p
Definition: pEqn.H:62
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
Foam::polyBoundaryMesh
Foam::polyBoundaryMesh.
Definition: polyBoundaryMesh.H:60
Foam::primitiveMesh::checkMesh
bool checkMesh(const bool report=false) const
Check mesh for correctness. Returns false for no error.
Definition: primitiveMeshCheck.C:2131
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::polyMesh::movePoints
virtual tmp< scalarField > movePoints(const pointField &)
Move points, returns volumes swept by faces in motion.
Definition: polyMesh.C:1048
Foam::polyTopoChanger
List of mesh modifiers defining the mesh dynamics.
Definition: polyTopoChanger.H:56
polyTopoChange.H
Foam::polyMesh::facesInstance
const fileName & facesInstance() const
Return the current instance directory for faces.
Definition: polyMesh.C:778
Foam::polyMesh::boundaryMesh
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:421
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
polyMesh.H
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
Foam::polyTopoChanger::mesh_
polyMesh & mesh_
Reference to mesh.
Definition: polyTopoChanger.H:77
Foam::label
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
Foam::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
Foam::polyTopoChanger::changeMesh
autoPtr< mapPolyMesh > changeMesh(const bool inflate, const bool syncParallel=true, const bool orderCells=false, const bool orderPoints=false)
Definition: polyTopoChanger.C:259
Foam::IOobject::name
const word & name() const
Return name.
Definition: IOobject.H:273
Foam::polyMesh::oldPoints
virtual const pointField & oldPoints() const
Return old points for mesh motion.
Definition: polyMesh.C:1029
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
Foam::attachPolyTopoChanger::attachPolyTopoChanger
attachPolyTopoChanger(const attachPolyTopoChanger &)
Disallow default bitwise copy construct.
Foam::polyMesh::removeBoundary
void removeBoundary()
Remove boundary patches.
Definition: polyMeshClear.C:36
Foam::polyMesh::setInstance
void setInstance(const fileName &)
Set the instance for mesh files.
Definition: polyMeshIO.C:32
Foam::List::setSize
void setSize(const label)
Reset size of List.
attachPolyTopoChanger.H
Foam::Pout
prefixOSstream Pout(cout, "Pout")
Definition: IOstreams.H:53
Foam::polyMesh::addPatches
void addPatches(const List< polyPatch * > &, const bool validBoundary=true)
Add boundary patches.
Definition: polyMesh.C:878
Foam::List
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
Foam::IOobject::clone
Foam::autoPtr< IOobject > clone() const
Clone.
Definition: IOobject.H:252
Foam::PtrList::size
label size() const
Return the number of elements in the PtrList.
Definition: PtrListI.H:32