decompositionInformation.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) 2017 OpenCFD Ltd.
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 
29 #include "ListOps.H"
30 
31 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
32 
33 void Foam::decompositionInformation::populate
34 (
35  const labelUList& adjncy,
36  const labelUList& xadj,
37  const labelUList& decomp,
38  const label nDomain
39 )
40 {
41  nDomains_ = nDomain;
42 
43  distrib_.clear();
44  distrib_.resize(nDomain);
45 
46  for (labelList& subdist : distrib_)
47  {
48  subdist.clear();
49  subdist.resize(nDomain, Zero);
50  }
51 
52  const label nCells = max(0, xadj.size()-1);
53  for (label celli = 0; celli < nCells; ++celli)
54  {
55  const label ownProc = decomp[celli];
56 
57  labelList& subdist = distrib_[ownProc];
58 
59  // Number of cells
60  ++subdist[ownProc];
61 
62  for (label i = xadj[celli]; i < xadj[celli+1]; ++i)
63  {
64  const label neiProc = decomp[adjncy[i]];
65 
66  if (neiProc != ownProc)
67  {
68  // Number of processor faces
69  ++subdist[neiProc];
70  }
71  }
72  }
73 
74  // Build summary
75 
76  labelList cellsCount(nDomains_, Zero);
77  labelList neighCount(nDomains_, Zero);
78  labelList facesCount(nDomains_, Zero);
79 
80  forAll(distrib_, ownProc)
81  {
82  const labelList& subdist = distrib_[ownProc];
83 
84  cellsCount[ownProc] = subdist[ownProc];
85 
86  forAll(subdist, neiProc)
87  {
88  const label n = subdist[neiProc];
89 
90  if (n && ownProc != neiProc)
91  {
92  ++neighCount[ownProc];
93  facesCount[ownProc] += n;
94  }
95  }
96  }
97 
98  const label n2 = (nDomains_ / 2);
99 
100  sort(cellsCount);
101  cellsInfo_.min = cellsCount.first();
102  cellsInfo_.max = cellsCount.last();
103  cellsInfo_.median = cellsCount[n2];
104 
105  sort(neighCount);
106  neighInfo_.min = neighCount.first();
107  neighInfo_.max = neighCount.last();
108  neighInfo_.median = neighCount[n2];
109 
110  sort(facesCount);
111  facesInfo_.min = facesCount.first();
112  facesInfo_.max = facesCount.last();
113  facesInfo_.median = facesCount[n2];
114 }
115 
116 
117 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
118 
119 Foam::decompositionInformation::decompositionInformation
120 (
121  const labelUList& adjncy,
122  const labelUList& xadj,
123  const labelUList& decomp,
124  const label nDomains
125 )
126 :
127  distrib_(),
128  nDomains_(0)
129 {
130  populate(adjncy, xadj, decomp, nDomains);
131 }
132 
133 
134 Foam::decompositionInformation::decompositionInformation
135 (
136  const CompactListList<label>& cellCells,
137  const labelUList& decomp,
138  const label nDomains
139 )
140 :
141  distrib_(),
142  nDomains_(0)
143 {
144  populate(cellCells.m(), cellCells.offsets(), decomp, nDomains);
145 }
146 
147 
148 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
149 
151 {
152  distrib_.clear();
153  cellsInfo_.clear();
154  neighInfo_.clear();
155  facesInfo_.clear();
156 }
157 
158 
160 {
161  os << "Cells "; cellsInfo_.print(os) << nl;
162  os << "Neigh "; neighInfo_.print(os)<< nl;
163  os << "Faces "; facesInfo_.print(os)<< nl;
164 }
165 
166 
168 {
169  os << "Decomposition details with (proc faces) "
170  "for each processor connection" << nl << nl;
171 
172  forAll(distrib_, ownProc)
173  {
174  const labelList& subdist = distrib_[ownProc];
175 
176  // First pass:
177  label neighCount = 0;
178  label facesCount = 0;
179 
180  forAll(subdist, neiProc)
181  {
182  const label n = subdist[neiProc];
183 
184  if (n && ownProc != neiProc)
185  {
186  ++neighCount;
187  facesCount += n;
188  }
189  }
190 
191  os << "Part[" << ownProc << "] cells:" << subdist[ownProc]
192  << " neigh:" << neighCount
193  << " faces:" << facesCount;
194 
195  // Second pass with details:
196  if (facesCount)
197  {
198  os << ' ';
199 
200  forAll(subdist, neiProc)
201  {
202  const label n = subdist[neiProc];
203 
204  if (n && ownProc != neiProc)
205  {
206  os << " (" << neiProc << ' ' << n << ')';
207  }
208  }
209  }
210 
211  os << nl;
212  }
213 }
214 
215 
217 {
218  printDetails(os);
219  printSummary(os);
220 }
221 
222 
223 // * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
224 
226 {
227  os << "min:" << this->min
228  << " max:" << this->max
229  << " median:" << this->median;
230 
231  if (this->median)
232  {
233  const scalar ratio = scalar(100*this->max)/this->median;
234 
235  os << " (" << ratio << "%)";
236  }
237 
238  return os;
239 }
240 
241 
242 // ************************************************************************* //
Foam::CompactListList::offsets
const List< label > & offsets() const
Return the offset table (= size()+1)
Definition: CompactListListI.H:142
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:67
Foam::CompactListList::m
const List< T > & m() const
Return the packed matrix of data.
Definition: CompactListListI.H:156
Foam::decompositionInformation::printAll
void printAll(Ostream &os) const
Definition: decompositionInformation.C:216
Foam::List::resize
void resize(const label len)
Adjust allocated size of list.
Definition: ListI.H:139
Foam::decompositionInformation::clear
void clear()
Definition: decompositionInformation.C:150
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
Foam::CompactListList
A packed storage unstructured matrix of objects of type <T> using an offset table for access.
Definition: CompactListList.H:63
Foam::min
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:33
Foam::decompositionInformation::printDetails
void printDetails(Ostream &os) const
Definition: decompositionInformation.C:167
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::OFstream::print
void print(Ostream &os) const
Print stream description.
Definition: OFstream.C:163
n
label n
Definition: TABSMDCalcMethod2.H:31
Foam::decompositionInformation::printSummary
void printSummary(Ostream &os) const
Definition: decompositionInformation.C:159
Foam::sort
void sort(UList< T > &a)
Definition: UList.C:261
Foam::max
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:47
os
OBJstream os(runTime.globalPath()/outputName)
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::List< label >
Foam::BitOps::print
Ostream & print(Ostream &os, UIntType value, char off='0', char on='1')
Print 0/1 bits in the (unsigned) integral type.
Definition: BitOps.H:199
Foam::UList< label >
Foam::List::clear
void clear()
Clear the list, i.e. set size to zero.
Definition: ListI.H:116
ListOps.H
Various functions to operate on Lists.
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::labelUList
UList< label > labelUList
A UList of labels.
Definition: UList.H:85
decompositionInformation.H