surfaceMorpherCellsCreateBoundaryFaces.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | cfMesh: A library for mesh generation
4  \\ / O peration |
5  \\ / A nd | Author: Franjo Juretic (franjo.juretic@c-fields.com)
6  \\/ M anipulation | Copyright (C) Creative Fields, Ltd.
7 -------------------------------------------------------------------------------
8 License
9  This file is part of cfMesh.
10 
11  cfMesh is free software; you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by the
13  Free Software Foundation; either version 3 of the License, or (at your
14  option) any later version.
15 
16  cfMesh is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with cfMesh. If not, see <http://www.gnu.org/licenses/>.
23 
24 Description
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "surfaceMorpherCells.H"
29 #include "demandDrivenData.H"
30 #include "helperFunctions.H"
31 #include "primitiveMesh.H"
32 
33 //#define DEBUGMorph
34 
35 # ifdef DEBUGMorph
36 #include "HashSet.H"
37 # endif
38 
39 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
40 
41 namespace Foam
42 {
43 
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 
47 {
49 
50  const faceListPMG& faces = mesh_.faces();
51  const cellListPMG& cells = mesh_.cells();
52 
53  bool changed(false);
54 
55  label nRemoved(0);
56  forAll(cellFlags_, cellI)
57  if( cellFlags_[cellI] & BOUNDARY )
58  {
59  const cell& c = cells[cellI];
60  //- remove cells which have all their vertices at the boundary
61  bool allBoundary(true);
62 
63  const labelList labels = c.labels(faces);
64 
65  forAll(labels, lI)
66  if( !boundaryVertex_[labels[lI]] )
67  {
68  allBoundary = false;
69  break;
70  }
71 
72  if( allBoundary )
73  {
74  ++nRemoved;
75  changed = true;
76  removeCells[cellI] = true;
77  }
78 
79  //- remove cells which are not topologically closed
80  DynList<edge> edges;
81  DynList<direction> nAppearances;
82 
83  forAll(c, fI)
84  {
85  const face& f = faces[c[fI]];
86  forAll(f, eI)
87  {
88  const label pos = edges.containsAtPosition(f.faceEdge(eI));
89 
90  if( pos == -1 )
91  {
92  edges.append(f.faceEdge(eI));
93  nAppearances.append(1);
94  }
95  else
96  {
97  ++nAppearances[pos];
98  }
99  }
100  }
101 
102  forAll(nAppearances, eI)
103  if( nAppearances[eI] != 2 )
104  {
105  ++nRemoved;
106  changed = true;
107  removeCells[cellI] = true;
108  }
109 
110  }
111 
112  if( Pstream::parRun() )
113  reduce(nRemoved, sumOp<label>());
114 
115  if( nRemoved != 0 )
116  {
117  Info << "Removing " << nRemoved
118  << " cells which cannot be morphed" << endl;
120  }
121 
122  if( Pstream::parRun() )
123  {
124  reduce(changed, maxOp<bool>());
125  }
126 
127  return changed;
128 }
129 
131 {
132  Info << "Morphing boundary faces" << endl;
133 
137 
138  const faceListPMG& faces = mesh_.faces();
139  const cellListPMG& cells = mesh_.cells();
140 
141  bool changed(false);
142 
143  forAll(cells, cellI)
144  if( cellFlags_[cellI] & BOUNDARY )
145  {
146  const cell& c = cells[cellI];
147 
148  DynList<label> bFaces;
149 
150  forAll(c, fI)
151  if( mesh_.faceIsInPatch(c[fI]) != -1 )
152  bFaces.append(c[fI]);
153 
154  # ifdef DEBUGMorph
155  Info << "Boundary faces in cell " << cellI
156  << " are " << bFaces << endl;
157  forAll(bFaces, bfI)
158  Info << "Face " << bFaces[bfI] << " is "
159  << faces[bFaces[bfI]] << endl;
160  # endif
161 
162  boolList mergedFaces(bFaces.size(), false);
163 
164  face mf = faces[bFaces[0]];
165  mergedFaces[0] = true;
166 
167  bool finished;
168  do
169  {
170  finished = true;
171  for(label i=1;i<bFaces.size();++i)
172  {
173  if( mergedFaces[i] ) continue;
174 
175  const face& bf = faces[bFaces[i]];
176  const edgeList bEdges = bf.edges();
177  const edgeList mEdges = mf.edges();
178 
179  direction nSharedEdges(0);
180  forAll(bEdges, eI)
181  forAll(mEdges, eJ)
182  if( bEdges[eI] == mEdges[eJ] )
183  ++nSharedEdges;
184 
185  direction nSharedPoints(0);
186  forAll(bf, pI)
187  forAll(mf, pJ)
188  if( bf[pI] == mf[pJ] )
189  ++nSharedPoints;
190 
191  if(
192  nSharedEdges &&
193  ((nSharedEdges + 1) == nSharedPoints)
194  )
195  {
196  mf = help::mergeTwoFaces(mf, bf);
197  mergedFaces[i] = true;
198  changed = true;
199  finished = false;
200 
201  //- set CHANGED flag
202  cellFlags_[cellI] |= CHANGED;
203  }
204  }
205  } while( !finished );
206 
208  newBoundaryOwners_.append(cellI);
210 
211  # ifdef DEBUGMorph
212  Info << "Adding merged face " << mf << endl;
213  # endif
214 
215  for(label i=1;i<bFaces.size();++i)
216  if( !mergedFaces[i] )
217  {
218  newBoundaryFaces_.appendList(faces[bFaces[i]]);
219  newBoundaryOwners_.append(cellI);
221 
222  # ifdef DEBUGMorph
223  Info << "Adding untouched boundary face "
224  << faces[bFaces[i]] << endl;
225  # endif
226  }
227  }
228 
229  if( Pstream::parRun() )
230  {
231  reduce(changed, maxOp<bool>());
232  }
233 
234  if( changed )
235  {
237  }
238 
239  # ifdef DEBUGMorph
240  labelHashSet zipCells;
241  mesh_.addressingData().checkCellsZipUp(true, &zipCells);
242  if( zipCells.size() )
243  {
244  Info << "Cells " << zipCells << " are not zipped!!" << endl;
245  ::exit(EXIT_FAILURE);
246  }
248  # endif
249 
250  Info << "Finished morphing boundary faces" << endl;
251 
252  return changed;
253 }
254 
255 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
256 
257 } // End namespace Foam
258 
259 // ************************************************************************* //
Foam::surfaceMorpherCells::cellFlags_
List< direction > cellFlags_
true for cells which are at the boundary
Definition: surfaceMorpherCells.H:64
Foam::maxOp
Definition: ops.H:172
Foam::polyMeshGenCells::addressingData
const polyMeshGenAddressing & addressingData() const
addressing which may be needed
Definition: polyMeshGenCells.C:327
Foam::LongList::append
void append(const T &e)
Append an element at the end of the list.
Definition: LongListI.H:265
Foam::surfaceMorpherCells::mesh_
polyMeshGen & mesh_
mesh modifier
Definition: surfaceMorpherCells.H:55
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::removeCells
Given list of cells to remove insert all the topology changes.
Definition: removeCells.H:59
demandDrivenData.H
Template functions to aid in the implementation of demand driven data.
Foam::UPstream::parRun
static bool & parRun()
Is this a parallel run?
Definition: UPstream.H:377
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::polyMeshGenFaces::faceIsInPatch
label faceIsInPatch(const label faceLabel) const
return patch label for the given face label
Definition: polyMeshGenFaces.C:190
Foam::cellListPMG
Definition: cellListPMG.H:49
Foam::HashSet< label, Hash< label > >
Foam::polyMeshGenFaces::faces
const faceListPMG & faces() const
access to faces
Definition: polyMeshGenFacesI.H:43
Foam::LongList::setSize
void setSize(const label)
Reset size of List.
Definition: LongListI.H:223
Foam::reduce
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
Definition: PstreamReduceOps.H:43
Foam::surfaceMorpherCells::removeCellsWithAllVerticesAtTheBoundary
bool removeCellsWithAllVerticesAtTheBoundary()
remove cells with all vertices at the boundary
Definition: surfaceMorpherCellsCreateBoundaryFaces.C:46
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:59
Foam::Info
messageStream Info
Foam::surfaceMorpherCells::newBoundaryFaces_
VRWGraph newBoundaryFaces_
new boundary faces and owner cells
Definition: surfaceMorpherCells.H:67
Foam::polyMeshGenCells::cells
const cellListPMG & cells() const
access to cells
Definition: polyMeshGenCellsI.H:39
Foam::surfaceMorpherCells::BOUNDARY
@ BOUNDARY
Definition: surfaceMorpherCells.H:75
Foam::surfaceMorpherCells::morphBoundaryFaces
bool morphBoundaryFaces()
morph boundary faces
Definition: surfaceMorpherCellsCreateBoundaryFaces.C:130
Foam::polyMeshGenCells::clearAddressingData
void clearAddressingData() const
clear addressing data
Definition: polyMeshGenCells.C:346
surfaceMorpherCells.H
Foam::VRWGraph::setSize
void setSize(const label)
Reset the number of rows.
Definition: VRWGraphI.H:132
Foam::help::mergeTwoFaces
face mergeTwoFaces(const faceType1 &f1, const faceType2 &f2)
returns a merged face
Definition: helperFunctionsTopologyManipulationI.H:128
HashSet.H
Foam::HashTable::size
label size() const
Return number of elements in table.
Definition: HashTableI.H:65
Foam::face::edges
edgeList edges() const
Return edges in face point ordering,.
Definition: face.C:761
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::surfaceMorpherCells::newBoundaryPatches_
labelLongList newBoundaryPatches_
Definition: surfaceMorpherCells.H:69
Foam::DynList
Definition: DynList.H:53
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
Foam::polyMeshGenModifier
Definition: polyMeshGenModifier.H:52
Foam::DynList::containsAtPosition
label containsAtPosition(const T &e) const
Definition: DynListI.H:356
Foam::sumOp
Definition: ops.H:162
helperFunctions.H
f
labelList f(nPoints)
Foam::VRWGraph::appendList
void appendList(const ListType &l)
Append a list as a row at the end of the graph.
Definition: VRWGraphI.H:286
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Foam::surfaceMorpherCells::newBoundaryOwners_
labelLongList newBoundaryOwners_
Definition: surfaceMorpherCells.H:68
Foam::surfaceMorpherCells::boundaryVertex_
boolList boundaryVertex_
true for vertices which are at the boundary
Definition: surfaceMorpherCells.H:61
Foam::direction
unsigned char direction
Definition: direction.H:43
Foam::constant::universal::c
const dimensionedScalar c
Speed of light in a vacuum.
Foam::face
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:75
Foam::DynList::size
label size() const
Definition: DynListI.H:235
cells
const cellShapeList & cells
Definition: gmvOutputHeader.H:3
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.
Foam::faceListPMG
Definition: faceListPMG.H:50
Foam::cell
A cell is defined as a list of faces with extra functionality.
Definition: cell.H:56
Foam::polyMeshGenModifier::removeCells
void removeCells(const boolList &removeCell, const bool removeProcFaces=true)
remove cells
Definition: polyMeshGenModifierRemoveCells.C:41
Foam::surfaceMorpherCells::CHANGED
@ CHANGED
Definition: surfaceMorpherCells.H:76
Foam::surfaceMorpherCells::replaceMeshBoundary
void replaceMeshBoundary()
replace the boundary of the mesh with the newly created one
Definition: surfaceMorpherCells.C:45
Foam::DynList::append
void append(const T &e)
Append an element at the end of the list.
Definition: DynListI.H:304
Foam::pos
dimensionedScalar pos(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:190