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 
124 Foam::zoneCPCStencil::zoneCPCStencil(const fvMesh& mesh)
125 :
128  nonEmptyBoundaryPoints_(nonEmptyFacesPatch()().meshPoints()),
129  uptodate_(mesh.nCells(), false)
130 {
131  // Mark boundary faces to be included in stencil (i.e. not coupled or empty)
132  validBoundaryFaces(isValidBFace_);
133 }
134 
136 {
137  auto* ptr = mesh.thisDb().getObjectPtr<zoneCPCStencil>("zoneCPCStencil");
138 
139  if (!ptr)
140  {
141  ptr = new zoneCPCStencil(mesh);
142  regIOobject::store(ptr);
143  }
144 
145  return *ptr;
146 }
147 
148 
149 void Foam::zoneCPCStencil::calculateStencil
150 (
151  const boolList& zone,
152  labelListList& globalCellCells
153 )
154 {
155  // Swap pointCells for coupled points
156  Map<bool> syncPoints = syncCoupledBoundaryPoints
157  (
158  zone,
159  nonEmptyBoundaryPoints_
160  );
161 
162  labelList boundaryPoints(syncPoints.toc());
163 
164  Map<labelList> neiGlobal;
165  calcPointBoundaryData
166  (
167  zone,
168  isValidBFace_,
169  boundaryPoints,
170  neiGlobal
171  );
172 
173  // add boundary Points first
174 
175  for (const label pointi : boundaryPoints)
176  {
177  const labelList& pGlobals = neiGlobal[pointi];
178 
179  // Distribute to all pointCells
180  const labelList& pCells = mesh_.pointCells(pointi);
181 
182  for (const label celli : pCells)
183  {
184  // Insert pGlobals into globalCellCells
185  if (zone[celli] && !uptodate_[celli])
186  {
187  merge
188  (
189  globalNumbering().toGlobal(celli),
190  pGlobals,
191  globalCellCells[celli]
192  );
193 
194  for (const label gblIdx : globalCellCells[celli])
195  {
196  if (!globalNumbering().isLocal(gblIdx))
197  {
198  needComm_.insert(celli);
199  }
200  }
201  }
202  }
203  }
204 
205 
206  neiGlobal.clear();
207 
208  // Do remaining points cells
209  const labelListList& cPoints = mesh_.cellPoints();
210 
211  forAll(zone,celli)
212  {
213  if (zone[celli] && !uptodate_[celli])
214  {
215  for (const label pointi : cPoints[celli])
216  {
217  labelList pCells = mesh_.pointCells(pointi);
218 
219  for (label& neiCelli : pCells)
220  {
221  neiCelli = globalNumbering().toGlobal(neiCelli);
222  }
223 
224  if (!uptodate_[celli])
225  {
226  merge
227  (
228  globalNumbering().toGlobal(celli),
229  pCells,
230  globalCellCells[celli]
231  );
232  }
233  }
234 
235  uptodate_[celli] = true;
236  }
237  }
238 }
239 
240 
241 // ************************************************************************* //
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:67
Foam::objectRegistry::getObjectPtr
Type * getObjectPtr(const word &name, const bool recursive=false) const
Definition: objectRegistryTemplates.C:423
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::fvMesh::thisDb
virtual const objectRegistry & thisDb() const
Return the object registry - resolve conflict polyMesh/lduMesh.
Definition: fvMesh.H:292
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:65
Foam::dummyTransform
Definition: dummyTransform.H:47
syncTools.H
Foam::regIOobject::store
bool store()
Definition: regIOobjectI.H:37
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
zoneCPCStencil.H
Foam::MeshObject< fvMesh, TopologicalMeshObject, zoneCPCStencil >::mesh_
const fvMesh & mesh_
Definition: MeshObject.H:96
zoneCellStencils
base class for cell stencil in a narrow band
Foam::zoneCPCStencil::New
static zoneCPCStencil & New(const fvMesh &)
Definition: zoneCPCStencil.C:135
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:85
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
emptyPolyPatch.H
Foam::labelListList
List< labelList > labelListList
A List of labelList.
Definition: labelList.H:56
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:191
Foam::TopologicalMeshObject
Definition: MeshObject.H:182
Foam::MeshObject
Templated abstract base-class for optional mesh objects used to automate their allocation to the mesh...
Definition: MeshObject.H:88
ListOps.H
Various functions to operate on Lists.
Foam::labelHashSet
HashSet< label, Hash< label > > labelHashSet
A HashSet of labels, uses label hasher.
Definition: HashSet.H:85
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::zoneCPCStencil
computes a cell point cell stencil in a narrow band. resizes in case of topological change
Definition: zoneCPCStencil.H:58