manifoldCellsMeshObject.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) 2022 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
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
29
30// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31
32namespace Foam
33{
35}
36
37// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
38
39namespace Foam
40{
41
42// Change entries in labelList
43static inline void replaceAll
44(
45 const label oldVal,
46 const label newVal,
47 labelUList& list
48)
49{
50 for (label& val : list)
51 {
52 if (val == oldVal)
53 {
54 val = newVal;
55 }
56 }
57}
58
59} // End namespace Foam
60
61
62// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
63
65(
66 const polyMesh& mesh,
67 label& nCellsCorrected
68)
69{
70 const auto& oldCells = mesh.cells();
71
72 // Start with copy of existing cell list
73 auto tnewCells = refPtr<cellList>::New(oldCells);
74 auto& newCells = tnewCells.ref();
75
76 DynamicList<label> removed;
77
78 nCellsCorrected = 0;
79 forAll(oldCells, celli)
80 {
81 const auto& oldCFaces = oldCells[celli];
82 auto& newCFaces = newCells[celli];
83
84 removed.clear();
85
86 forAll(oldCFaces, cFacei)
87 {
88 const label facei = oldCFaces[cFacei];
89 const label masteri = newCFaces[cFacei];
90
91 const face& f = mesh.faces()[facei];
92
93 forAll(oldCFaces, cFacej)
94 {
95 const label facej = oldCFaces[cFacej];
96 const label masterj = newCFaces[cFacej];
97
98 if (facej != facei)
99 {
100 if (face::sameVertices(f, mesh.faces()[facej]))
101 {
102 //Pout<< "Same face:" << facei
103 // << " master:" << masteri
104 // << " verts:" << f << nl
105 // << " :" << facej
106 // << " master:" << masterj
107 // << " verts:" << mesh.faces()[facej]
108 // << endl;
109
110 if (masteri < masterj)
111 {
112 replaceAll(masterj, masteri, newCFaces);
113 removed.append(masterj);
114 }
115 else if (masterj < masteri)
116 {
117 replaceAll(masteri, masterj, newCFaces);
118 removed.append(masteri);
119 }
120 }
121 }
122 }
123 }
124
125 if (removed.size())
126 {
127 // Compact out removed faces
128 label newi = 0;
129 for (const label facei : oldCFaces)
130 {
131 if (!removed.found(facei))
132 {
133 newCFaces[newi++] = facei;
134 }
135 }
136 newCFaces.resize(newi);
137 ++nCellsCorrected;
138 }
139 }
140
141 // Not needed (locally)
142 if (nCellsCorrected == 0)
143 {
144 // Just use the existing mesh
145 tnewCells.cref(mesh.cells());
146 }
147
148 // Number of cells corrected (globally)
149 reduce(nCellsCorrected, sumOp<label>());
150
151 return tnewCells;
152}
153
154
156(
157 const polyMesh& mesh
158)
159{
160 label count = 0;
161 return filter(mesh, count);
162}
163
164
165// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
166
168:
170 cellsPtr_(nullptr),
171 nCorrected_(-1)
172{}
173
174
175// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
176
178{
179 if (nCorrected_ < 0)
180 {
181 cellsPtr_ = filter(mesh(), nCorrected_);
182 }
183
184 return (nCorrected_ > 0);
185}
186
187
189{
190 if (nCorrected_ < 0)
191 {
192 cellsPtr_ = filter(mesh(), nCorrected_);
193 }
194
195 return (cellsPtr_ ? cellsPtr_.cref() : mesh().cells());
196}
197
198
200{
201 cellsPtr_.reset(nullptr);
202 nCorrected_ = -1;
203}
204
205
206// ************************************************************************* //
Templated abstract base-class for optional mesh objects used to automate their allocation to the mesh...
Definition: MeshObject.H:91
static autoPtr< Time > New()
Construct (dummy) Time - no functionObjects or libraries.
Definition: Time.C:717
static bool sameVertices(const face &a, const face &b)
Return true if the faces have the same vertices.
Definition: face.C:382
Provides cell-to-faces ('cells()') with duplicate faces removed.
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:162
void updateMesh()
Update for new mesh topology.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:81
virtual const faceList & faces() const
Return raw faces.
Definition: polyMesh.C:1108
const cellList & cells() const
A class for managing references or pointers (no reference counting)
Definition: refPtr.H:58
#define defineTypeName(Type)
Define the typeName.
Definition: className.H:96
dynamicFvMesh & mesh
const cellShapeList & cells
Namespace for OpenFOAM.
void reduce(const List< UPstream::commsStruct > &comms, T &value, const BinaryOp &bop, const int tag, const label comm)
static void replaceAll(const label oldVal, const label newVal, labelUList &list)
labelList f(nPoints)
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333
Functor wrapper of allow/deny lists of wordRe for filtering.
Definition: wordRes.H:174