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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "attachPolyTopoChanger.H"
29 #include "polyMesh.H"
30 #include "polyTopoChange.H"
31 
32 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
33 
34 Foam::attachPolyTopoChanger::attachPolyTopoChanger
35 (
36  const IOobject& io,
37  polyMesh& mesh
38 )
39 :
41 {}
42 
43 
44 Foam::attachPolyTopoChanger::attachPolyTopoChanger
45 (
46  polyMesh& mesh
47 )
48 :
50 {}
51 
52 
53 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
54 
55 void Foam::attachPolyTopoChanger::attach(const bool removeEmptyPatches)
56 {
57  if (debug)
58  {
59  Pout<< "void attachPolyTopoChanger::attach(): "
60  << "Attaching mesh" << endl;
61  }
62 
63  // Save current file instance
64  const fileName oldInst = mesh_.facesInstance();
65 
66  // Execute all polyMeshModifiers
67  changeMesh(false); // no inflation
68 
69  const pointField p = mesh_.oldPoints();
70 
72 
73  if (debug)
74  {
75  Pout<< "Clearing mesh." << endl;
76  }
77 
78  if (removeEmptyPatches)
79  {
80  // Re-do the boundary patches, removing the ones with zero size
81  const polyBoundaryMesh& oldPatches = mesh_.boundaryMesh();
82 
83  List<polyPatch*> newPatches(oldPatches.size());
84  label nNewPatches = 0;
85 
86  forAll(oldPatches, patchi)
87  {
88  if (oldPatches[patchi].size())
89  {
90  newPatches[nNewPatches] = oldPatches[patchi].clone
91  (
93  nNewPatches,
94  oldPatches[patchi].size(),
95  oldPatches[patchi].start()
96  ).ptr();
97 
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  }
109 
110  newPatches.setSize(nNewPatches);
111 
113  mesh_.addPatches(newPatches);
114  }
115 
116  // Reset the file instance to overwrite the original mesh
117  mesh_.setInstance(oldInst);
118 
119  if (debug)
120  {
121  Pout<< "void attachPolyTopoChanger::attach(): "
122  << "Finished attaching mesh" << endl;
123  }
124 
125  mesh_.checkMesh();
126 }
127 
128 
129 // ************************************************************************* //
Foam::expressions::patchExpr::debug
int debug
Static debugging option.
Foam::polyMesh::addPatches
void addPatches(PtrList< polyPatch > &plist, const bool validBoundary=true)
Add boundary patches.
Definition: polyMesh.C:961
Foam::attachPolyTopoChanger::attach
void attach(const bool removeEmptyPatches=true)
Attach mesh. By default filter out empty patches.
Definition: attachPolyTopoChanger.C:55
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:169
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::fileName
A class for handling file names.
Definition: fileName.H:73
Foam::polyBoundaryMesh
A polyBoundaryMesh is a polyPatch list with additional search methods and registered IO.
Definition: polyBoundaryMesh.H:63
Foam::primitiveMesh::checkMesh
virtual bool checkMesh(const bool report=false) const
Check mesh for correctness. Returns false for no error.
Definition: primitiveMeshCheck.C:1825
Foam::polyMesh::movePoints
virtual tmp< scalarField > movePoints(const pointField &)
Move points, returns volumes swept by faces in motion.
Definition: polyMesh.C:1160
Foam::polyTopoChanger
List of mesh modifiers defining the mesh dynamics.
Definition: polyTopoChanger.H:62
polyTopoChange.H
Foam::polyMesh::facesInstance
const fileName & facesInstance() const
Return the current instance directory for faces.
Definition: polyMesh.C:852
Foam::polyMesh::boundaryMesh
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:444
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::Pout
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
polyMesh.H
Foam::polyBoundaryMesh::start
label start() const
The start label of the boundary faces in the polyMesh face list.
Definition: polyBoundaryMesh.C:611
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::polyTopoChanger::mesh_
polyMesh & mesh_
Reference to mesh.
Definition: polyTopoChanger.H:83
Foam::Field< vector >
Foam::polyTopoChanger::changeMesh
autoPtr< mapPolyMesh > changeMesh(const bool inflate, const bool syncParallel=true, const bool orderCells=false, const bool orderPoints=false)
Definition: polyTopoChanger.C:248
Foam::polyMesh::oldPoints
virtual const pointField & oldPoints() const
Return old points (mesh motion)
Definition: polyMesh.C:1119
Foam::PtrList::clone
PtrList< T > clone(Args &&... args) const
Make a copy by cloning each of the list elements.
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::polyMesh::removeBoundary
void removeBoundary()
Remove boundary patches.
Definition: polyMeshClear.C:39
Foam::IOobject::name
const word & name() const noexcept
Return name.
Definition: IOobjectI.H:65
attachPolyTopoChanger.H
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:63
Foam::polyMesh::setInstance
void setInstance(const fileName &instance, const IOobject::writeOption wOpt=IOobject::AUTO_WRITE)
Set the instance for mesh files.
Definition: polyMeshIO.C:36