zoneCPCStencil.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) 2020 DLR
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 \*---------------------------------------------------------------------------*/
27 
28 #include "zoneCPCStencil.H"
29 #include "syncTools.H"
30 #include "ListOps.H"
31 #include "dummyTransform.H"
32 #include "emptyPolyPatch.H"
33 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38  defineTypeNameAndDebug(zoneCPCStencil, 0);
39 }
40 
41 
42 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
43 
44 Foam::Map<bool> Foam::zoneCPCStencil::syncCoupledBoundaryPoints
45 (
46  const boolList& zone,
47  const labelList& boundaryPoints
48 ) const
49 {
50  const labelListList& pCells = mesh_.pointCells();
51 
52  Map<bool> syncPoints;
53 
54  for (const label pointi : boundaryPoints)
55  {
56  bool updatePoint = false;
57 
58  // Check if point needs to be updated
59  for (const label celli : pCells[pointi])
60  {
61  if (zone[celli])
62  {
63  updatePoint = true;
64  break;
65  }
66  }
67 
68  if (updatePoint)
69  {
70  syncPoints.insert(pointi, true);
71  }
72  }
73 
75  (
76  mesh_,
77  syncPoints,
78  orEqOp<bool>(),
80  );
81 
82  return syncPoints;
83 }
84 
85 
86 void Foam::zoneCPCStencil::calcPointBoundaryData
87 (
88  const boolList& zone,
89  const boolList& isValidBFace,
90  const labelList& boundaryPoints,
91  Map<labelList>& neiGlobal
92 ) const
93 {
94  neiGlobal.resize(2*boundaryPoints.size());
95 
96  labelHashSet pointGlobals;
97 
98  for (const label pointi : boundaryPoints)
99  {
100  neiGlobal.insert
101  (
102  pointi,
103  calcFaceCells
104  (
105  isValidBFace,
106  mesh_.pointFaces()[pointi],
107  pointGlobals
108  )
109  );
110  }
111 
113  (
114  mesh_,
115  neiGlobal,
116  ListOps::unionEqOp(),
118  );
119 }
120 
121 
122 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
123 
125 :
127  nonEmptyBoundaryPoints_(nonEmptyFacesPatch()().meshPoints()),
128  uptodate_(mesh.nCells(), false)
129 {
130  // Mark boundary faces to be included in stencil (i.e. not coupled or empty)
131  validBoundaryFaces(isValidBFace_);
132 }
133 
134 
135 void Foam::zoneCPCStencil::calculateStencil
136 (
137  const boolList& zone,
138  labelListList& globalCellCells
139 )
140 {
141  // Swap pointCells for coupled points
142  Map<bool> syncPoints = syncCoupledBoundaryPoints
143  (
144  zone,
145  nonEmptyBoundaryPoints_
146  );
147 
148  labelList boundaryPoints(syncPoints.toc());
149 
150  Map<labelList> neiGlobal;
151  calcPointBoundaryData
152  (
153  zone,
154  isValidBFace_,
155  boundaryPoints,
156  neiGlobal
157  );
158 
159  // add boundary Points first
160 
161  for (const label pointi : boundaryPoints)
162  {
163  const labelList& pGlobals = neiGlobal[pointi];
164 
165  // Distribute to all pointCells
166  const labelList& pCells = mesh_.pointCells(pointi);
167 
168  for (const label celli : pCells)
169  {
170  // Insert pGlobals into globalCellCells
171  if (zone[celli] && !uptodate_[celli])
172  {
173  merge
174  (
175  globalNumbering().toGlobal(celli),
176  pGlobals,
177  globalCellCells[celli]
178  );
179 
180  for (const label gblIdx : globalCellCells[celli])
181  {
182  if (!globalNumbering().isLocal(gblIdx))
183  {
184  needComm_.insert(celli);
185  }
186  }
187  }
188  }
189  }
190 
191 
192  neiGlobal.clear();
193 
194  // Do remaining points cells
195  const labelListList& cPoints = mesh_.cellPoints();
196 
197  forAll(zone,celli)
198  {
199  if (zone[celli] && !uptodate_[celli])
200  {
201  for (const label pointi : cPoints[celli])
202  {
203  labelList pCells = mesh_.pointCells(pointi);
204 
205  for (label& neiCelli : pCells)
206  {
207  neiCelli = globalNumbering().toGlobal(neiCelli);
208  }
209 
210  if (!uptodate_[celli])
211  {
212  merge
213  (
214  globalNumbering().toGlobal(celli),
215  pCells,
216  globalCellCells[celli]
217  );
218  }
219  }
220 
221  uptodate_[celli] = true;
222  }
223  }
224 }
225 
226 
228 {
229  if (mesh_.topoChanging())
230  {
231  // resize map and globalIndex
233 
234  nonEmptyBoundaryPoints_ = nonEmptyFacesPatch()().meshPoints();
235  uptodate_.resize(mesh_.nCells());
236  uptodate_ = false;
237  validBoundaryFaces(isValidBFace_);
238  }
239 }
240 
241 
242 // ************************************************************************* //
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:71
Foam::syncTools::syncPointMap
static void syncPointMap(const polyMesh &mesh, Map< T > &pointValues, const CombineOp &cop, const TransformOp &top)
Synchronize values on selected points.
Definition: syncToolsTemplates.C:84
Foam::zoneCellStencils::validBoundaryFaces
void validBoundaryFaces(boolList &isValidBFace) const
Valid boundary faces (not empty and not coupled)
Definition: zoneCellStencils.C:127
Foam::zone
Base class for mesh zones.
Definition: zone.H:63
dummyTransform.H
Dummy transform to be used with syncTools.
Foam::Map
A HashTable to objects of type <T> with a label key.
Definition: lumpedPointController.H:69
Foam::boolList
List< bool > boolList
A List of bools.
Definition: List.H:69
Foam::dummyTransform
Definition: dummyTransform.H:47
Foam::zoneCPCStencil::zoneCPCStencil
zoneCPCStencil(const fvMesh &)
Construct from all cells and boundary faces.
Definition: zoneCPCStencil.C:124
syncTools.H
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
zoneCPCStencil.H
Foam::MeshObject< fvMesh, UpdateableMeshObject, zoneCellStencils >::mesh_
const fvMesh & mesh_
Definition: MeshObject.H:96
Foam::zoneCellStencils
base class for cell stencil in a narrow band
Definition: zoneCellStencils.H:58
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:83
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
emptyPolyPatch.H
Foam::labelListList
List< labelList > labelListList
A List of labelList.
Definition: labelList.H:56
Foam::zoneCPCStencil::updateMesh
virtual void updateMesh(const mapPolyMesh &mpm)
Definition: zoneCPCStencil.C:227
Foam::List< bool >
Foam::primitiveMesh::pointCells
const labelListList & pointCells() const
Definition: primitiveMeshPointCells.C:110
Foam::HashSet::insert
bool insert(const Key &key)
Insert a new entry, not overwriting existing entries.
Definition: HashSet.H:181
Foam::mapPolyMesh
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:161
ListOps.H
Various functions to operate on Lists.
Foam::labelHashSet
HashSet< label, Hash< label > > labelHashSet
A HashSet with label keys and label hasher.
Definition: HashSet.H:409
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::zoneCellStencils::updateMesh
virtual void updateMesh(const mapPolyMesh &mpm)
Definition: zoneCellStencils.C:270