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  Copyright (C) 2022 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
30 #include "polyMesh.H"
31 #include "polyTopoChange.H"
32 
33 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
34 
36 (
37  const IOobject& io,
38  polyMesh& mesh
39 )
40 :
42 {}
43 
44 
46 (
47  polyMesh& mesh
48 )
49 :
51 {}
52 
53 
54 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
55 
56 void Foam::attachPolyTopoChanger::attach(const bool removeEmptyPatches)
57 {
58  if (debug)
59  {
60  Pout<< "void attachPolyTopoChanger::attach(): "
61  << "Attaching mesh" << endl;
62  }
63 
64  // Save current file instance
65  const fileName oldInst = mesh_.facesInstance();
66 
67  // Execute all polyMeshModifiers
68  changeMesh(false); // no inflation
69 
70  const pointField p = mesh_.oldPoints();
71 
72  mesh_.movePoints(p);
73 
74  if (debug)
75  {
76  Pout<< "Clearing mesh." << endl;
77  }
78 
79  if (removeEmptyPatches)
80  {
81  // Re-do the boundary patches, removing the ones with zero size
82  const polyBoundaryMesh& oldPatches = mesh_.boundaryMesh();
83 
84  polyPatchList newPatches(oldPatches.size());
85  label nNewPatches = 0;
86 
87  forAll(oldPatches, patchi)
88  {
89  const word& patchName = oldPatches[patchi].name();
90 
91  if (returnReduceOr(oldPatches[patchi].size()))
92  {
93  newPatches.set
94  (
95  nNewPatches,
96  oldPatches[patchi].clone
97  (
98  mesh_.boundaryMesh(),
99  nNewPatches,
100  oldPatches[patchi].size(),
101  oldPatches[patchi].start()
102  )
103  );
104 
105  ++nNewPatches;
106  }
107  else
108  {
109  if (debug)
110  {
111  Pout<< "Removing zero-sized patch " << patchi
112  << " named " << patchName << endl;
113  }
114  }
115  }
116 
117  newPatches.resize(nNewPatches);
118 
119  mesh_.removeBoundary();
120  mesh_.addPatches(newPatches);
121  }
122 
123  // Reset the file instance to overwrite the original mesh
124  mesh_.setInstance(oldInst);
125 
126  if (debug)
127  {
128  Pout<< "void attachPolyTopoChanger::attach(): "
129  << "Finished attaching mesh" << endl;
130  }
131 
132  mesh_.checkMesh();
133 }
134 
135 
136 // ************************************************************************* //
attachPolyTopoChanger(const attachPolyTopoChanger &)=delete
No copy construct.
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:531
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
PtrList< polyPatch > polyPatchList
Store lists of polyPatch as a PtrList.
Definition: polyPatch.H:56
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:38
dynamicFvMesh & mesh
List of mesh modifiers defining the mesh dynamics.
int debug
Static debugging option.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
volScalarField & p
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)
bool returnReduceOr(const bool value, const label comm=UPstream::worldComm)
Perform logical (or) MPI Allreduce on a copy. Uses UPstream::reduceOr.
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:172
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.