SloanRenumber.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2012-2026 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM 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 OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24  Adapted from Boost graph/example/sloan_ordering.cpp
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "SloanRenumber.H"
30 #include "decompositionMethod.H"
31 #include "processorPolyPatch.H"
32 #include "syncTools.H"
33 
34 #include <boost/config.hpp>
35 #include <vector>
36 #include <iostream>
37 #include <boost/graph/adjacency_list.hpp>
38 #include <boost/graph/sloan_ordering.hpp>
39 #include <boost/graph/properties.hpp>
40 #include <boost/graph/bandwidth.hpp>
41 #include <boost/graph/profile.hpp>
42 #include <boost/graph/wavefront.hpp>
43 
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 
46 using namespace boost;
47 using namespace std;
48 
49 //Defining the graph type
50 typedef adjacency_list
51 <
52  setS,
53  vecS,
54  undirectedS,
55  property
56  <
57  vertex_color_t,
58  default_color_type,
59  property
60  <
61  vertex_degree_t,
63  property
64  <
65  vertex_priority_t,
66  Foam::scalar
67  >
68  >
69  >
71 
72 typedef graph_traits<Graph>::vertex_descriptor Vertex;
73 typedef graph_traits<Graph>::vertices_size_type size_type;
74 
75 namespace Foam
76 {
78 
80  (
84  );
85 }
86 
87 
88 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
89 
91 :
92  renumberMethod(renumberDict),
93  reverse_
94  (
95  renumberDict.optionalTypeDict(typeName)
96  .lookupOrDefault<Switch>("reverse", false)
97  )
98 {}
99 
100 
101 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
102 
104 (
105  const polyMesh& mesh,
106  const pointField& points
107 ) const
108 {
109  const polyBoundaryMesh& pbm = mesh.boundary();
110 
111  // Construct graph : faceOwner + connections across cyclics.
112 
113  // Determine neighbour cell
114  labelList nbr(mesh.nFaces()-mesh.nInternalFaces(), -1);
115  forAll(pbm, patchi)
116  {
117  if (pbm[patchi].coupled() && !isA<processorPolyPatch>(pbm[patchi]))
118  {
120  (
121  nbr,
122  pbm[patchi].size(),
123  pbm[patchi].start()-mesh.nInternalFaces()
124  ) = pbm[patchi].faceCells();
125  }
126  }
128 
129 
130  Graph G(mesh.nCells());
131 
132  // Add internal faces
133  forAll(mesh.faceNeighbour(), facei)
134  {
135  add_edge(mesh.faceOwner()[facei], mesh.faceNeighbour()[facei], G);
136  }
137  // Add cyclics
138  forAll(pbm, patchi)
139  {
140  if
141  (
142  pbm[patchi].coupled()
143  && !isA<processorPolyPatch>(pbm[patchi])
144  && refCast<const coupledPolyPatch>(pbm[patchi]).owner()
145  )
146  {
147  const labelUList& faceCells = pbm[patchi].faceCells();
148  forAll(faceCells, i)
149  {
150  label bFacei = pbm[patchi].start()+i-mesh.nInternalFaces();
151  label nbrCelli = nbr[bFacei];
152 
153  if (faceCells[i] < nbrCelli)
154  {
155  add_edge(faceCells[i], nbrCelli, G);
156  }
157  else
158  {
159  add_edge(nbrCelli, faceCells[i], G);
160  }
161  }
162  }
163  }
164 
165 
166  // Creating two iterators over the vertices
167  graph_traits<Graph>::vertex_iterator ui, ui_end;
168 
169  // Creating a property_map with the degrees of the degrees of each vertex
170  property_map<Graph,vertex_degree_t>::type deg = get(vertex_degree, G);
171  for (boost::tie(ui, ui_end) = vertices(G); ui != ui_end; ++ui)
172  deg[*ui] = degree(*ui, G);
173 
174  // Creating a property_map for the indices of a vertex
175  property_map<Graph, vertex_index_t>::type index_map = get(vertex_index, G);
176 
177  // Creating a vector of vertices
178  std::vector<Vertex> sloan_order(num_vertices(G));
179 
180  sloan_ordering
181  (
182  G,
183  sloan_order.begin(),
184  get(vertex_color, G),
185  make_degree_map(G),
186  get(vertex_priority, G)
187  );
188 
189  labelList orderedToOld(sloan_order.size());
190  forAll(orderedToOld, c)
191  {
192  orderedToOld[c] = index_map[sloan_order[c]];
193  }
194 
195  if (reverse_)
196  {
197  reverse(orderedToOld);
198  }
199 
200  return orderedToOld;
201 }
202 
203 
205 (
206  const labelListList& cellCells,
207  const pointField& points
208 ) const
209 {
210  Graph G(cellCells.size());
211 
212  forAll(cellCells, celli)
213  {
214  const labelList& nbrs = cellCells[celli];
215  forAll(nbrs, i)
216  {
217  if (nbrs[i] > celli)
218  {
219  add_edge(celli, nbrs[i], G);
220  }
221  }
222  }
223 
224  // Creating two iterators over the vertices
225  graph_traits<Graph>::vertex_iterator ui, ui_end;
226 
227  // Creating a property_map with the degrees of the degrees of each vertex
228  property_map<Graph,vertex_degree_t>::type deg = get(vertex_degree, G);
229  for (boost::tie(ui, ui_end) = vertices(G); ui != ui_end; ++ui)
230  deg[*ui] = degree(*ui, G);
231 
232  // Creating a property_map for the indices of a vertex
233  property_map<Graph, vertex_index_t>::type index_map = get(vertex_index, G);
234 
235  // Creating a vector of vertices
236  std::vector<Vertex> sloan_order(num_vertices(G));
237 
238  sloan_ordering
239  (
240  G,
241  sloan_order.begin(),
242  get(vertex_color, G),
243  make_degree_map(G),
244  get(vertex_priority, G)
245  );
246 
247  labelList orderedToOld(sloan_order.size());
248  forAll(orderedToOld, c)
249  {
250  orderedToOld[c] = index_map[sloan_order[c]];
251  }
252 
253  if (reverse_)
254  {
255  reverse(orderedToOld);
256  }
257 
258  return orderedToOld;
259 }
260 
261 
262 // ************************************************************************* //
adjacency_list< setS, vecS, undirectedS, property< vertex_color_t, default_color_type, property< vertex_degree_t, Foam::label, property< vertex_priority_t, Foam::scalar > > >> Graph
Definition: SloanRenumber.C:70
graph_traits< Graph >::vertices_size_type size_type
Definition: SloanRenumber.C:73
graph_traits< Graph >::vertex_descriptor Vertex
Definition: SloanRenumber.C:72
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:449
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to hash-table of functions with typename as the key.
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
Sloan renumbering algorithm.
Definition: SloanRenumber.H:52
SloanRenumber(const dictionary &renumberDict)
Construct given the renumber dictionary.
Definition: SloanRenumber.C:90
virtual labelList renumber(const pointField &) const
Return the order in which cells need to be visited, i.e.
Definition: SloanRenumber.H:83
A List obtained as a section of another List.
Definition: SubList.H:56
A simple wrapper around bool so that it can be read as a word: true/false, on/off,...
Definition: Switch.H:61
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
const fvBoundaryMesh & boundary() const
Return reference to boundary mesh.
Definition: fvMesh.C:932
Foam::polyBoundaryMesh.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:78
virtual const labelList & faceOwner() const
Return face owner.
Definition: polyMesh.C:1321
virtual const labelList & faceNeighbour() const
Return face neighbour.
Definition: polyMesh.C:1327
label nInternalFaces() const
label nCells() const
label nFaces() const
Abstract base class for renumbering.
static void swapBoundaryFaceList(const polyMesh &mesh, UList< T > &l)
Swap coupled boundary face values.
Definition: syncTools.H:436
Template function which returns the un-mangled name of a given type. Useful for types which do not ha...
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:139
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
label patchi
const pointField & points
const dimensionedScalar G
Newtonian constant of gravitation.
const dimensionedScalar c
Speed of light in a vacuum.
Namespace for OpenFOAM.
pointField vertices(const blockVertexList &bvl)
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
void reverse(UList< T > &, const label n)
Definition: UListI.H:334
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488