polyMeshGenModifierAddProcessorFaces.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 VRWGraph& procFaces,
43  const labelLongList& facePatches
44 )
45 {
46  Info << "Adding processor faces" << endl;
47 
48  PtrList<processorBoundaryPatch>& procBoundaries = mesh_.procBoundaries_;
49 
50  labelList nAddedFaces(procBoundaries.size(), 0);
51  forAll(facePatches, fI)
52  ++nAddedFaces[facePatches[fI]];
53 
54  labelList newPatchStart(procBoundaries.size());
55  newPatchStart[0] = procBoundaries[0].patchStart();
56  for(label i=1;i<procBoundaries.size();++i)
57  newPatchStart[i] =
58  newPatchStart[i-1] +
59  procBoundaries[i-1].patchSize() + nAddedFaces[i-1];
60 
61  //- set new size of the faceListPMG
62  faceListPMG& faces = mesh_.faces_;
63  const label nFaces = faces.size();
64  faces.setSize(nFaces+procFaces.size());
65 
66  label endProcFaces(0);
67  forAllReverse(procBoundaries, patchI)
68  {
69  const processorBoundaryPatch& wp = procBoundaries[patchI];
70  endProcFaces = Foam::max(endProcFaces, wp.patchStart()+wp.patchSize());
71  }
72 
73  //- move faces to their new positions
74  labelLongList newFaceLabel(nFaces, -1);
75 
76  if( endProcFaces != nFaces )
77  {
78  for(label faceI=nFaces-1;faceI>=endProcFaces;--faceI)
79  {
80  newFaceLabel[faceI] = faceI+facePatches.size();
81  faces[faceI+facePatches.size()].transfer(faces[faceI]);
82  }
83  }
84 
85  labelList faceIndex(procBoundaries.size());
86  for(label patchI=procBoundaries.size()-1;patchI>=0;--patchI)
87  {
88  const label start = procBoundaries[patchI].patchStart();
89  const label end = start + procBoundaries[patchI].patchSize();
90  const label shift = newPatchStart[patchI] - start;
91 
92  if( shift != 0 )
93  {
94  for(label faceI=end-1;faceI>=start;--faceI)
95  {
96  faces[faceI+shift].transfer(faces[faceI]);
97  newFaceLabel[faceI] = faceI+shift;
98  }
99  }
100 
101  //- set new start for the given patch
102  procBoundaries[patchI].patchStart() = newPatchStart[patchI];
103  faceIndex[patchI] =
104  newPatchStart[patchI] + procBoundaries[patchI].patchSize();
105  procBoundaries[patchI].patchSize() += nAddedFaces[patchI];
106  }
107 
108  //- add new faces into patches
109  forAll(procFaces, fI)
110  {
111  face f(procFaces.sizeOfRow(fI));
112  forAll(f, pI)
113  f[pI] = procFaces(fI, pI);
114 
115  faces[faceIndex[facePatches[fI]]++].transfer(f);
116  }
117 
118  //- renumber cells
119  cellListPMG& cells = mesh_.cells_;
120  # ifdef USE_OMP
121  # pragma omp parallel for schedule(guided)
122  # endif
123  forAll(cells, cellI)
124  {
125  cell& c = cells[cellI];
126 
127  forAll(c, fI)
128  if( newFaceLabel[c[fI]] != -1 )
129  c[fI] = newFaceLabel[c[fI]];
130  }
131 
132  this->clearOut();
133  mesh_.clearOut();
134  mesh_.updateFaceSubsets(newFaceLabel);
135 
136  Info << "Finished adding processor faces" << endl;
137 }
138 
140 {
141  const label nProcPatches = mesh_.procBoundaries().size();
142 
143  PtrList<processorBoundaryPatch>& procBoundaries =
144  this->procBoundariesAccess();
145 
146  procBoundaries.setSize(nProcPatches + 1);
147 
148  std::ostringstream ss;
149  ss << Pstream::myProcNo();
150  std::ostringstream ssNei;
151  ssNei << otherProcLabel;
152  const word name("processor"+ss.str()+"to"+ssNei.str());
153 
154  procBoundaries.set
155  (
156  nProcPatches,
158  (
159  name,
160  "processor",
161  0,
162  0,
164  otherProcLabel
165  )
166  );
167 
168  return nProcPatches;
169 }
170 
172 {
173  PtrList<processorBoundaryPatch>& procBoundaries =
174  this->procBoundariesAccess();
175 
176  label nValidPatches(0);
177  forAll(procBoundaries, patchI)
178  {
179  if( procBoundaries[patchI].patchSize() != 0 )
180  ++nValidPatches;
181  }
182 
183  if( nValidPatches == procBoundaries.size() )
184  return false;
185 
186  PtrList<processorBoundaryPatch> newProcBoundaries(nValidPatches);
187 
188  nValidPatches = 0;
189  forAll(procBoundaries, patchI)
190  {
191  if( procBoundaries[patchI].patchSize() != 0 )
192  {
193  newProcBoundaries.set
194  (
195  nValidPatches++,
196  new processorBoundaryPatch(procBoundaries[patchI])
197  );
198  }
199  }
200 
201  procBoundaries.transfer(newProcBoundaries);
202 
203  return true;
204 }
205 
206 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
207 
208 } // End namespace Foam
209 
210 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::boundaryPatchBase::patchSize
label patchSize() const
Definition: boundaryPatchBase.H:161
Foam::polyMeshGenModifier::removeEmptyProcessorPatches
bool removeEmptyProcessorPatches()
remove empty processor patch
Definition: polyMeshGenModifierAddProcessorFaces.C:171
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::polyMeshGenModifier::addProcessorPatch
label addProcessorPatch(const label otherProcLabel)
add new processor patch and return its label
Definition: polyMeshGenModifierAddProcessorFaces.C:139
Foam::polyMeshGenModifier::addProcessorFaces
void addProcessorFaces(const VRWGraph &procFaces, const labelLongList &facePatches)
add additional faces into processor patches
Definition: polyMeshGenModifierAddProcessorFaces.C:41
polyMeshGenModifier.H
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::LongList::size
label size() const
Size of the active part of the list.
Definition: LongListI.H:203
Foam::polyMeshGenModifier::mesh_
polyMeshGen & mesh_
reference to the mesh
Definition: polyMeshGenModifier.H:56
Foam::cellListPMG
Definition: cellListPMG.H:49
Foam::LongList< label >
Foam::PtrList::set
bool set(const label) const
Is element set.
Foam::polyMeshGenModifier::procBoundariesAccess
PtrList< processorBoundaryPatch > & procBoundariesAccess()
access to processor boundary data
Definition: polyMeshGenModifier.H:125
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::VRWGraph::size
label size() const
Returns the number of rows.
Definition: VRWGraphI.H:122
Foam::faceListPMG::setSize
void setSize(const label nElmts)
set the number of used elements
Definition: faceListPMGI.H:78
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::PtrList::transfer
void transfer(PtrList< T > &)
Transfer the contents of the argument PtrList into this PtrList.
Definition: PtrList.C:200
Foam::VRWGraph::sizeOfRow
label sizeOfRow(const label rowI) const
Returns the number of elements in the given row.
Definition: VRWGraphI.H:127
forAllReverse
#define forAllReverse(list, i)
Reverse loop across all elements in list.
Definition: UList.H:418
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::processorBoundaryPatch
Definition: processorBoundaryPatch.H:47
Foam::UPstream::myProcNo
static int myProcNo(const label communicator=0)
Number of this process (starting from masterNo() = 0)
Definition: UPstream.H:405
Foam::max
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
f
labelList f(nPoints)
Foam::faceListPMG::size
label size() const
return the number of used elements
Definition: faceListPMGI.H:73
Foam::boundaryPatchBase::patchStart
label patchStart() const
Definition: boundaryPatchBase.H:151
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::PtrList::size
label size() const
Return the number of elements in the PtrList.
Definition: PtrListI.H:32
Foam::PtrList::setSize
void setSize(const label)
Reset size of PtrList. If extending the PtrList, new entries are.
Definition: PtrList.C:142
Foam::polyMeshGenFaces::procBoundaries
const PtrList< processorBoundaryPatch > & procBoundaries() const
inter-processor boundaries
Definition: polyMeshGenFacesI.H:106
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
cells
const cellShapeList & cells
Definition: gmvOutputHeader.H:3
Foam::faceListPMG
Definition: faceListPMG.H:50
Foam::VRWGraph
Definition: VRWGraph.H:101
Foam::cell
A cell is defined as a list of faces with extra functionality.
Definition: cell.H:56
Foam::name
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
Foam::faceListPMG::transfer
void transfer(faceList &)