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