decomposeCellsDecomposition.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 "decomposeCells.H"
29 #include "demandDrivenData.H"
30 #include "polyMeshGenAddressing.H"
31 #include "meshSurfaceEngine.H"
32 #include "decomposeFaces.H"
33 #include "labelLongList.H"
34 
35 //#define DEBUGDecompose
36 
37 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
38 
39 namespace Foam
40 {
41 
42 void decomposeCells::decomposeMesh(const boolList& decomposeCell)
43 {
44  checkFaceConnections(decomposeCell);
45 
46  createPointsAndCellFaces(decomposeCell);
47 
48  storeBoundaryFaces(decomposeCell);
49 
50  removeDecomposedCells(decomposeCell);
51 
52  addNewCells();
53 
54  # ifdef DEBUGDecompose
55  mesh_.addressingData().checkMesh();
56  # endif
57 }
58 
60 {
61  const faceListPMG& faces = mesh_.faces();
62  const cellListPMG& cells = mesh_.cells();
63 
64  boolList decomposeFace(faces.size(), false);
65  forAll(cells, cellI)
66  {
67  if( decomposeCell[cellI] )
68  {
70  DynList<edge, 64> edges;
71  DynList<DynList<label, 8> > faceEdges;
72  DynList<DynList<label, 2>, 64> edgeFaces;
73 
74  findAddressingForCell(cellI, vrt, edges, faceEdges, edgeFaces);
75 
76  forAll(faceEdges, fI)
77  {
78  const DynList<label, 8>& fEdges = faceEdges[fI];
79 
80  labelHashSet neiFaces;
81  forAll(fEdges, feI)
82  {
83  label neiFace = edgeFaces[fEdges[feI]][0];
84  if( neiFace == fI )
85  neiFace = edgeFaces[fEdges[feI]][1];
86 
87  if( neiFaces.found(neiFace) )
88  {
89  decomposeFace[cells[cellI][fI]] = true;
90  }
91  else
92  {
93  neiFaces.insert(neiFace);
94  }
95  }
96  }
97  }
98  }
99 
100  if( Pstream::parRun() )
101  {
102  const PtrList<processorBoundaryPatch>& procBoundaries =
104 
105  //- send information to the neighbour processor
106  forAll(procBoundaries, patchI)
107  {
108  const label start = procBoundaries[patchI].patchStart();
109  boolList decFace(procBoundaries[patchI].patchSize(), false);
110  const label size = decFace.size();
111 
112  for(label i=0;i<size;++i)
113  {
114  if( decomposeFace[start+i] )
115  decFace[i] = true;
116  }
117 
118  OPstream toOtherProc
119  (
121  procBoundaries[patchI].neiProcNo(),
122  decFace.byteSize()
123  );
124 
125  toOtherProc << decFace;
126  }
127 
128  //- receive information from the neighbour processor
129  forAll(procBoundaries, patchI)
130  {
131  boolList decFace;
132 
133  IPstream fromOtherProc
134  (
136  procBoundaries[patchI].neiProcNo()
137  );
138 
139  fromOtherProc >> decFace;
140 
141  const label start = procBoundaries[patchI].patchStart();
142  forAll(decFace, i)
143  {
144  if( decFace[i] )
145  decomposeFace[start+i] = true;
146  }
147  }
148  }
149 
150  //- decompose faces which would cause invalid connections
151  decomposeFaces(mesh_).decomposeMeshFaces(decomposeFace);
152 }
153 
155 {
157 
158  forAll(decomposeCell, cI)
159  if( decomposeCell[cI] )
160  {
162  }
163 }
164 
165 void decomposeCells::storeBoundaryFaces(const boolList& /*decomposeCell*/)
166 {
168  const faceList::subList& bFaces = mse.boundaryFaces();
169  const labelList& facePatch = mse.boundaryFacePatches();
170 
171  forAll(bFaces, bfI)
172  {
173  newBoundaryFaces_.appendList(bFaces[bfI]);
174  newBoundaryPatches_.append(facePatch[bfI]);
175  }
176 }
177 
179 {
180  # ifdef DEBUGDecompose
181  Info << "Number of cells before removal " << mesh_.cells().size() << endl;
182  # endif
183 
184  polyMeshGenModifier meshModifier(mesh_);
185  meshModifier.removeCells(decomposeCell, false);
186 
187  # ifdef DEBUGDecompose
188  Info << "Number of cells after removal " << mesh_.cells().size() << endl;
189  # endif
190 }
191 
193 {
194  Info << "Adding new cells " << endl;
197  Info << "Reordering bnd faces" << endl;
199 
200  Info << "Finding bnd faces" << endl;
201  const faceListPMG& faces = mesh_.faces();
202  const labelList& owner = mesh_.owner();
203  const VRWGraph& pointFaces = mesh_.addressingData().pointFaces();
204 
205  labelLongList newBoundaryOwners;
206 
207  forAll(newBoundaryFaces_, faceI)
208  {
209  face bf(newBoundaryFaces_.sizeOfRow(faceI));
210  forAllRow(newBoundaryFaces_, faceI, pI)
211  bf[pI] = newBoundaryFaces_(faceI, pI);
212 
213  # ifdef DEBUGDecompose
214  Info << "Finding cell for boundary face " << bf << endl;
215  bool found(false);
216  forAllRow(pointFaces, bf[0], pfI)
217  if( bf == faces[pointFaces(bf[0], pfI)] )
218  found = true;
219  if( !found )
221  (
222  "void decomposeCells::addNewCells()"
223  ) << "Face " << bf << " does not exist in the mesh"
224  << abort(FatalError);
225  #endif
226 
227  forAllRow(pointFaces, bf[0], pfI)
228  {
229  const label fLabel = pointFaces(bf[0], pfI);
230  if( (mesh_.faceIsInPatch(fLabel) != -1) && (bf == faces[fLabel]) )
231  {
232  # ifdef DEBUGDecompose
233  Info << "Boundary face " << bf << " is in cell "
234  << owner[fLabel]] << endl;
235  # endif
236 
237  newBoundaryOwners.append(owner[fLabel]);
238  }
239  }
240  }
241 
243  (
244  patchNames_,
246  newBoundaryOwners,
248  );
249 
252 
253  PtrList<boundaryPatch>& boundaries =
255  forAll(boundaries, patchI)
256  boundaries[patchI].patchType() = patchTypes_[patchI];
257 }
258 
259 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *//
260 
261 } // End namespace Foam
262 
263 // ************************************************************************* //
Foam::polyMeshGenFaces::owner
const labelList & owner() const
owner and neighbour cells for faces
Definition: polyMeshGenFacesI.H:67
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::decomposeFaces
Definition: decomposeFaces.H:47
Foam::decomposeCells::facesOfNewCells_
VRWGraphList facesOfNewCells_
Definition: decomposeCells.H:60
Foam::decomposeCells::decomposeMesh
void decomposeMesh(const boolList &)
perform decomposition of selected cell into pyramids
Definition: decomposeCellsDecomposition.C:42
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::decomposeCells::patchTypes_
wordList patchTypes_
Definition: decomposeCells.H:56
Foam::OPstream
Output inter-processor communications stream.
Definition: OPstream.H:50
Foam::decomposeCells::newBoundaryFaces_
VRWGraph newBoundaryFaces_
Definition: decomposeCells.H:57
demandDrivenData.H
Template functions to aid in the implementation of demand driven data.
Foam::SubList
A List obtained as a section of another List.
Definition: SubList.H:53
decomposeCells.H
Foam::UPstream::parRun
static bool & parRun()
Is this a parallel run?
Definition: UPstream.H:377
Foam::meshSurfaceEngine::boundaryFacePatches
const labelList & boundaryFacePatches() const
patch label for each boundary face
Definition: meshSurfaceEngineI.H:123
decomposeFaces.H
Foam::polyMeshGenModifier::replaceBoundary
void replaceBoundary(const wordList &patchNames, const VRWGraph &boundaryFaces, const labelLongList &faceOwners, const labelLongList &facePatches)
replace the boundary with new boundary faces
Definition: polyMeshGenModifierReplaceBoundary.C:42
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::decomposeCells::removeDecomposedCells
void removeDecomposedCells(const boolList &decomposeCell)
Definition: decomposeCellsDecomposition.C:178
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::polyMeshGenModifier::boundariesAccess
PtrList< boundaryPatch > & boundariesAccess()
access to boundary data
Definition: polyMeshGenModifier.H:131
Foam::LongList< label >
Foam::polyMeshGenAddressing::pointFaces
const VRWGraph & pointFaces() const
Definition: polyMeshGenAddressingPointFaces.C:60
Foam::UPstream::blocking
@ blocking
Definition: UPstream.H:66
Foam::decomposeCells::mesh_
polyMeshGen & mesh_
reference to the mesh
Definition: decomposeCells.H:52
Foam::meshSurfaceEngine::boundaryFaces
const faceList::subList & boundaryFaces() const
Definition: meshSurfaceEngineI.H:103
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::polyMeshGenModifier::reorderBoundaryFaces
void reorderBoundaryFaces()
Definition: polyMeshGenModifierReorderBoundaryFaces.C:44
Foam::decomposeCells::patchNames_
wordList patchNames_
new boundary faces
Definition: decomposeCells.H:55
Foam::decomposeCells::storeBoundaryFaces
void storeBoundaryFaces(const boolList &decomposeCell)
Definition: decomposeCellsDecomposition.C:165
Foam::Info
messageStream Info
Foam::decomposeCells::addNewCells
void addNewCells()
Definition: decomposeCellsDecomposition.C:192
Foam::polyMeshGenCells::cells
const cellListPMG & cells() const
access to cells
Definition: polyMeshGenCellsI.H:39
Foam::PtrList
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: List.H:61
forAllRow
#define forAllRow(graph, rowI, index)
Definition: VRWGraph.H:277
Foam::polyMeshGenModifier::removeUnusedVertices
void removeUnusedVertices()
remove unused vertices
Definition: polyMeshGenModifierRemoveUnusedVertices.C:37
Foam::VRWGraph::sizeOfRow
label sizeOfRow(const label rowI) const
Returns the number of elements in the given row.
Definition: VRWGraphI.H:127
Foam::FatalError
error FatalError
Foam::decomposeCells::decomposeCellIntoPyramids
void decomposeCellIntoPyramids(const label cellI)
Definition: decomposeCellsPyramids.C:160
Foam::HashTable::found
bool found(const Key &) const
Return true if hashedEntry is found in table.
Definition: HashTable.C:109
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
meshSurfaceEngine.H
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:131
Foam::DynList
Definition: DynList.H:53
Foam::decomposeFaces::decomposeMeshFaces
void decomposeMeshFaces(const boolList &decomposeFace)
decompose selected faces into triangles using midnode subdivision
Definition: decomposeFaces.C:62
found
bool found
Definition: TABSMDCalcMethod2.H:32
Foam::polyMeshGenModifier
Definition: polyMeshGenModifier.H:52
Foam::VRWGraphList::clear
void clear()
Clear the graph.
Definition: VRWGraphListI.H:115
Foam::decomposeCells::findAddressingForCell
void findAddressingForCell(const label cellI, DynList< label, 32 > &vrt, DynList< edge, 64 > &edges, DynList< DynList< label, 8 > > &faceEdges, DynList< DynList< label, 2 >, 64 > &edgeFaces) const
create addressing needed to decompose the cell
Definition: decomposeCellsPyramids.C:40
Foam::faceListPMG::size
label size() const
return the number of used elements
Definition: faceListPMGI.H:73
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
labelLongList.H
Foam::HashSet::insert
bool insert(const Key &key)
Insert a new entry.
Definition: HashSet.H:116
Foam::decomposeCells::checkFaceConnections
void checkFaceConnections(const boolList &decomposeCell)
Definition: decomposeCellsDecomposition.C:59
Foam::polyMeshGenFaces::procBoundaries
const PtrList< processorBoundaryPatch > & procBoundaries() const
inter-processor boundaries
Definition: polyMeshGenFacesI.H:106
Foam::polyMeshGenModifier::clearAll
void clearAll()
clear out all allocated data
Definition: polyMeshGenModifier.H:200
Foam::polyMeshGenModifier::addCells
void addCells(const LongList< faceList > &cellFaces)
add cells (vertices must be added)
Definition: polyMeshGenModifierAddCells.C:37
Foam::decomposeCells::createPointsAndCellFaces
void createPointsAndCellFaces(const boolList &decomposeCell)
Definition: decomposeCellsDecomposition.C:154
Foam::decomposeCells::newBoundaryPatches_
labelLongList newBoundaryPatches_
Definition: decomposeCells.H:58
Foam::IPstream
Input inter-processor communications stream.
Definition: IPstream.H:50
FatalErrorIn
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:313
Foam::face
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:75
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::VRWGraph
Definition: VRWGraph.H:101
polyMeshGenAddressing.H
Foam::meshSurfaceEngine
Definition: meshSurfaceEngine.H:54
Foam::cellListPMG::size
label size() const
return the number of used elements
Definition: cellListPMGI.H:56
Foam::polyMeshGenModifier::removeCells
void removeCells(const boolList &removeCell, const bool removeProcFaces=true)
remove cells
Definition: polyMeshGenModifierRemoveCells.C:41