Loading...
Searching...
No Matches
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-------------------------------------------------------------------------------
11License
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\*---------------------------------------------------------------------------*/
30#include "polyMesh.H"
31#include "polyTopoChange.H"
32
33// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
34
36(
37 const IOobject& io,
39)
40:
41 polyTopoChanger(io, mesh)
42{}
43
44
46(
48)
50 polyTopoChanger(mesh)
51{}
52
53
54// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
55
56void 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// ************************************************************************* //
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition IOobject.H:191
const word & name() const noexcept
Return the object name.
Definition IOobjectI.H:205
const T * set(const label i) const
Return const pointer to element (can be nullptr), or nullptr for out-of-range access (ie,...
Definition PtrList.H:171
Foam::PtrList< polyMeshModifier > clone(Args &&... args) const
Definition PtrList.C:103
void resize(const label newLen)
Adjust size of PtrList.
Definition PtrList.C:124
label size() const noexcept
The number of entries in the list.
Definition UPtrListI.H:106
void attach(const bool removeEmptyPatches=true)
Attach mesh. By default filter out empty patches.
attachPolyTopoChanger(const attachPolyTopoChanger &)=delete
No copy construct.
A class for handling file names.
Definition fileName.H:75
A polyBoundaryMesh is a polyPatch list with registered IO, a reference to the associated polyMesh,...
label start() const noexcept
The start label of boundary faces in the polyMesh face list.
Mesh consisting of general polyhedral cells.
Definition polyMesh.H:79
const polyMesh & mesh() const
Return the mesh reference.
polyMesh & mesh_
Reference to mesh.
autoPtr< mapPolyMesh > changeMesh(const bool inflate, const bool syncParallel=true, const bool orderCells=false, const bool orderPoints=false)
A class for handling words, derived from Foam::string.
Definition word.H:66
volScalarField & p
dynamicFvMesh & mesh
const auto & io
Namespace for handling debugging switches.
Definition debug.C:45
PtrList< polyPatch > polyPatchList
Store lists of polyPatch as a PtrList.
Definition polyPatch.H:61
bool returnReduceOr(const bool value, const int communicator=UPstream::worldComm)
Perform logical (or) MPI Allreduce on a copy. Uses UPstream::reduceOr.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
vectorField pointField
pointField is a vectorField.
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299