setLayerPairing.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) 2020 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
27Description
28 Remove a layer of cells and prepare addressing data
29
30\*---------------------------------------------------------------------------*/
31
33#include "polyMesh.H"
34#include "primitiveMesh.H"
35#include "polyTopoChange.H"
36#include "oppositeFace.H"
37#include "polyTopoChanger.H"
38
39// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
40
41bool Foam::layerAdditionRemoval::setLayerPairing() const
42{
43 // Note:
44 // This is also the most complex part of the topological change.
45 // Therefore it will be calculated here and stored as temporary
46 // data until the actual topological change, after which it will
47 // be cleared.
48
49 // Algorithm for point collapse
50 // 1) Go through the master cell layer and for every face of
51 // the face zone find the opposite face in the master cell.
52 // Check the direction of the opposite face and adjust as
53 // necessary. Check other faces to find an edge defining
54 // relative orientation of the two faces and adjust the face
55 // as necessary. Once the face is adjusted, record the
56 // addressing between the master and slave vertex layer.
57
58 const polyMesh& mesh = topoChanger().mesh();
59
60 const labelList& mc =
61 mesh.faceZones()[faceZoneID_.index()].masterCells();
62
63 const labelList& mf = mesh.faceZones()[faceZoneID_.index()];
64
65 const boolList& mfFlip =
66 mesh.faceZones()[faceZoneID_.index()].flipMap();
67
68 const faceList& faces = mesh.faces();
69 const cellList& cells = mesh.cells();
70
71 // Grab the local faces from the master zone
72 const faceList& mlf =
73 mesh.faceZones()[faceZoneID_.index()]().localFaces();
74
75 const labelList& meshPoints =
76 mesh.faceZones()[faceZoneID_.index()]().meshPoints();
77
78 // Create a list of points to collapse for every point of
79 // the master patch
80 if (pointsPairingPtr_ || facesPairingPtr_)
81 {
83 << "Problem with layer pairing data"
84 << abort(FatalError);
85 }
86
87 pointsPairingPtr_.reset(new labelList(meshPoints.size(), -1));
88 facesPairingPtr_.reset(new labelList(mf.size(), -1));
89
90 auto& ptc = *pointsPairingPtr_;
91 auto& ftc = *facesPairingPtr_;
92
93 if (debug > 1)
94 {
95 Pout<< "meshPoints: " << meshPoints << nl
96 << "localPoints: "
97 << mesh.faceZones()[faceZoneID_.index()]().localPoints()
98 << endl;
99 }
100
101 // For all faces, create the mapping
102 label nPointErrors = 0;
103 label nFaceErrors = 0;
104
105 forAll(mf, facei)
106 {
107 // Get the local master face
108 face curLocalFace = mlf[facei];
109
110 // Flip face based on flip index to recover original orientation
111 if (mfFlip[facei])
112 {
113 curLocalFace.flip();
114 }
115
116 // Get the opposing face from the master cell
117 oppositeFace lidFace =
118 cells[mc[facei]].opposingFace(mf[facei], faces);
119
120 if (!lidFace.found())
121 {
122 // This is not a valid layer; cannot continue
123 nFaceErrors++;
124 continue;
125 }
126
127 if (debug > 1)
128 {
129 Pout<< "curMasterFace: " << faces[mf[facei]] << nl
130 << "cell shape: " << mesh.cellShapes()[mc[facei]] << nl
131 << "curLocalFace: " << curLocalFace << nl
132 << "lidFace: " << lidFace
133 << " master index: " << lidFace.masterIndex()
134 << " oppositeIndex: " << lidFace.oppositeIndex() << endl;
135 }
136
137 // Grab the opposite face for face collapse addressing
138 ftc[facei] = lidFace.oppositeIndex();
139
140 // Using the local face insert the points into the lid list
141 forAll(curLocalFace, pointi)
142 {
143 const label clp = curLocalFace[pointi];
144
145 if (ptc[clp] == -1)
146 {
147 // Point not mapped yet. Insert the label
148 ptc[clp] = lidFace[pointi];
149 }
150 else
151 {
152 // Point mapped from some other face. Check the label
153 if (ptc[clp] != lidFace[pointi])
154 {
155 nPointErrors++;
156
157 if (debug > 1)
158 {
159 Pout<< "Topological error in cell layer pairing. "
160 << "This mesh is either topologically incorrect "
161 << "or the master face layer is not defined "
162 << "consistently. Please check the "
163 << "face zone flip map." << nl
164 << "First index: " << ptc[clp]
165 << " new index: " << lidFace[pointi] << endl;
166 }
167 }
168 }
169 }
170 }
171
172 reduce(nPointErrors, sumOp<label>());
173 reduce(nFaceErrors, sumOp<label>());
174
175 if (nPointErrors > 0 || nFaceErrors > 0)
176 {
177 clearAddressing();
178
179 return false;
180 }
181
182 // Valid layer
183 return true;
184}
185
186
187const Foam::labelList& Foam::layerAdditionRemoval::pointsPairing() const
188{
189 if (!pointsPairingPtr_)
190 {
192 << "Problem with layer pairing data for object " << name()
193 << abort(FatalError);
194 }
195
196 return *pointsPairingPtr_;
197}
198
199
200const Foam::labelList& Foam::layerAdditionRemoval::facesPairing() const
201{
202 if (!facesPairingPtr_)
203 {
205 << "Problem with layer pairing data for object " << name()
206 << abort(FatalError);
207 }
208
209 return *facesPairingPtr_;
210}
211
212
213// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
214
216(
217 pointField& motionPoints
218) const
219{
220 if (debug)
221 {
222 Pout<< "void layerAdditionRemoval::modifyMotionPoints("
223 << "pointField& motionPoints) const for object "
224 << name() << " : ";
225 }
226
227 if (debug)
228 {
229 Pout<< "No motion point adjustment" << endl;
230 }
231}
232
233
234// ************************************************************************* //
label index() const
The index of the first matching items, -1 if no matches.
Definition: DynamicID.H:123
virtual void modifyMotionPoints(pointField &motionPoints) const
Modify motion points to comply with the topological change.
const polyTopoChanger & topoChanger() const
Return reference to morph engine.
const faceZoneMesh & faceZones() const noexcept
Return face zone mesh.
Definition: polyMesh.H:498
virtual const faceList & faces() const
Return raw faces.
Definition: polyMesh.C:1108
const polyMesh & mesh() const
Return the mesh reference.
const cellShapeList & cellShapes() const
Return cell shapes.
const cellList & cells() const
dynamicFvMesh & mesh
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
const cellShapeList & cells
List< label > labelList
A List of labels.
Definition: List.H:66
List< cell > cellList
A List of cells.
Definition: cellListFwd.H:47
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
void reduce(const List< UPstream::commsStruct > &comms, T &value, const BinaryOp &bop, const int tag, const label comm)
errorManip< error > abort(error &err)
Definition: errorManip.H:144
List< bool > boolList
A List of bools.
Definition: List.H:64
error FatalError
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
List< face > faceList
A List of faces.
Definition: faceListFwd.H:47
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333