polyMeshGenModifierRemoveCells.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 "polyMeshGenModifier.H"
29 #include "demandDrivenData.H"
30 
31 # ifdef USE_OMP
32 #include <omp.h>
33 # endif
34 
35 namespace Foam
36 {
37 
38 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
39 
41 (
42  const boolList& removeCell,
43  const bool removeProcFaces
44 )
45 {
46  Info << "Removing selected cells from the mesh" << endl;
47 
48  //mesh_.clearOut();
49 
50  faceListPMG& faces = mesh_.faces_;
51  cellListPMG& cells = mesh_.cells_;
52 
53  if( removeCell.size() != cells.size() )
54  {
55  Info << "Size of cells " << cells.size() << endl;
56  Info << "Size of list for removal " << removeCell.size() << endl;
58  (
59  "void polyMeshGenModifier::removeCells(const boolList& removeCell)"
60  ) << "Incorrect number of entries in removeCell list!"
61  << abort(FatalError);
62  }
63 
64  //- flip internal faces which will become boundary ones
65  const labelList& owner = mesh_.owner();
66  const labelList& neighbour = mesh_.neighbour();
67 
68  # ifdef USE_OMP
69  # pragma omp parallel for schedule(dynamic, 40)
70  # endif
71  forAll(faces, faceI)
72  {
73  if( neighbour[faceI] == -1 )
74  {
75  faceI = faces.size();
76  continue;
77  }
78 
79  if( removeCell[owner[faceI]] && !removeCell[neighbour[faceI]] )
80  faces[faceI] = faces[faceI].reverseFace();
81  }
82 
83  mesh_.clearOut();
84 
85  //- remove unwanted cells
86  label nCells(0);
87  labelLongList newCellLabel(cells.size(), -1);
88  forAll(newCellLabel, cellI)
89  if( !removeCell[cellI] )
90  newCellLabel[cellI] = nCells++;
91 
92  forAll(cells, cellI)
93  if( (newCellLabel[cellI] != -1) && (newCellLabel[cellI] < cellI) )
94  {
95  cells[newCellLabel[cellI]].transfer(cells[cellI]);
96  }
97 
98  cells.setSize(nCells);
99 
100  //- update cell subsets in the mesh
101  mesh_.updateCellSubsets(newCellLabel);
102 
103  reduce(nCells, sumOp<label>());
104  Info << "New cells size " << nCells << endl;
105 
106  //- reorder positions of boundary faces
107  //- this outs the newly-created bnd faces at the end of the list
108  this->reorderBoundaryFaces();
109 
110  mesh_.clearOut();
111  //- remove unused faces
112  boolList removeFace(faces.size(), true);
113 
114  # ifdef USE_OMP
115  # pragma omp parallel if( cells.size() > 1000 )
116  # endif
117  {
118  # ifdef USE_OMP
119  # pragma omp for schedule(dynamic, 40)
120  # endif
121  forAll(cells, cellI)
122  {
123  const cell& c = cells[cellI];
124 
125  forAll(c, fI)
126  removeFace[c[fI]] = false;
127  }
128 
129  if( Pstream::parRun() && !removeProcFaces )
130  {
131  const PtrList<processorBoundaryPatch>& procBoundaries =
132  mesh_.procBoundaries_;
133 
134  # ifdef USE_OMP
135  # pragma omp for
136  # endif
137  for(label fI=procBoundaries[0].patchStart();fI<faces.size();++fI)
138  removeFace[fI] = false;
139  }
140  }
141 
142  mesh_.clearOut();
143 
144  this->removeFaces(removeFace);
145 
146  Info << "Finished removing selected cells from the mesh" << endl;
147 }
148 
149 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
150 
151 } // End namespace Foam
152 
153 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
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
polyMeshGenModifier.H
Foam::List::transfer
void transfer(List< T > &)
Transfer the contents of the argument List into this list.
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::cellListPMG
Definition: cellListPMG.H:49
Foam::LongList< label >
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::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::removeFaces
Given list of faces to remove insert all the topology changes. Contains helper function to get consis...
Definition: removeFaces.H:62
Foam::Info
messageStream Info
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
Foam::FatalError
error FatalError
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:131
Foam::List::setSize
void setSize(const label)
Reset size of List.
Foam::sumOp
Definition: ops.H:162
Foam::faceListPMG::size
label size() const
return the number of used elements
Definition: faceListPMGI.H:73
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::constant::universal::c
const dimensionedScalar c
Speed of light in a vacuum.
FatalErrorIn
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:313
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