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-------------------------------------------------------------------------------
10License
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
36namespace Foam
37{
39}
40
41
42// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
43
44Foam::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
86void 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:
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);
143 }
144
145 return *ptr;
146}
147
148
149void 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// ************************************************************************* //
Various functions to operate on Lists.
bool insert(const Key &key)
Insert a new entry, not overwriting existing entries.
Definition: HashSet.H:191
List< Key > toc() const
The table of contents (the keys) in unsorted order.
Definition: HashTable.C:122
bool insert(const Key &key, const T &obj)
Copy insert a new entry, not overwriting existing entries.
Definition: HashTableI.H:180
void clear()
Clear all entries from table.
Definition: HashTable.C:678
A HashTable to objects of type <T> with a label key.
Definition: Map.H:60
Templated abstract base-class for optional mesh objects used to automate their allocation to the mesh...
Definition: MeshObject.H:91
static autoPtr< Time > New()
Construct (dummy) Time - no functionObjects or libraries.
Definition: Time.C:717
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:91
virtual const objectRegistry & thisDb() const
Return the object registry - resolve conflict polyMesh/lduMesh.
Definition: fvMesh.H:302
Type * getObjectPtr(const word &name, const bool recursive=false) const
const labelListList & pointCells() const
static void syncPointMap(const polyMesh &mesh, Map< T > &pointValues, const CombineOp &cop, const TransformOp &top)
Synchronize values on selected points.
computes a cell point cell stencil in a narrow band. resizes in case of topological change
base class for cell stencil in a narrow band
Base class for mesh zones.
Definition: zone.H:67
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
dynamicFvMesh & mesh
Dummy transform to be used with syncTools.
Namespace for OpenFOAM.
List< label > labelList
A List of labels.
Definition: List.H:66
List< labelList > labelListList
A List of labelList.
Definition: labelList.H:56
List< bool > boolList
A List of bools.
Definition: List.H:64
HashSet< label, Hash< label > > labelHashSet
A HashSet of labels, uses label hasher.
Definition: HashSet.H:85
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333