SloanRenumber.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) 2012-2017 OpenFOAM Foundation
9  Copyright (C) 2020 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27  Adapted from Boost graph/example/sloan_ordering.cpp
28 
29 \*---------------------------------------------------------------------------*/
30 
31 #include "SloanRenumber.H"
33 #include "decompositionMethod.H"
34 #include "processorPolyPatch.H"
35 #include "syncTools.H"
36 
37 #include <boost/config.hpp>
38 #include <vector>
39 #include <iostream>
40 #include <boost/graph/adjacency_list.hpp>
41 #include <boost/graph/sloan_ordering.hpp>
42 #include <boost/graph/properties.hpp>
43 #include <boost/graph/bandwidth.hpp>
44 #include <boost/graph/profile.hpp>
45 #include <boost/graph/wavefront.hpp>
46 
47 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
48 
49 using namespace boost;
50 using namespace std;
51 
52 //Defining the graph type
53 typedef adjacency_list
54 <
55  setS,
56  vecS,
57  undirectedS,
58  property
59  <
60  vertex_color_t,
61  default_color_type,
62  property
63  <
64  vertex_degree_t,
65  Foam::label,
66  property
67  <
68  vertex_priority_t,
69  Foam::scalar
70  >
71  >
72  >
74 
75 typedef graph_traits<Graph>::vertex_descriptor Vertex;
76 typedef graph_traits<Graph>::vertices_size_type size_type;
77 
78 namespace Foam
79 {
80  defineTypeNameAndDebug(SloanRenumber, 0);
81 
83  (
84  renumberMethod,
85  SloanRenumber,
86  dictionary
87  );
88 }
89 
90 
91 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
92 
93 Foam::SloanRenumber::SloanRenumber(const dictionary& renumberDict)
94 :
95  renumberMethod(renumberDict),
96  reverse_
97  (
98  renumberDict.optionalSubDict
99  (
100  typeName + "Coeffs"
101  ).getOrDefault("reverse", false)
102  )
103 {}
104 
105 
106 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
107 
109 (
110  const polyMesh& mesh,
111  const pointField& points
112 ) const
113 {
114  const polyBoundaryMesh& pbm = mesh.boundaryMesh();
115 
116  // Construct graph : faceOwner + connections across cyclics.
117 
118  // Determine neighbour cell
119  labelList nbr(mesh.nBoundaryFaces(), -1);
120  forAll(pbm, patchi)
121  {
122  if (pbm[patchi].coupled() && !isA<processorPolyPatch>(pbm[patchi]))
123  {
125  (
126  nbr,
127  pbm[patchi].size(),
128  pbm[patchi].start()-mesh.nInternalFaces()
129  ) = pbm[patchi].faceCells();
130  }
131  }
133 
134 
135  Graph G(mesh.nCells());
136 
137  // Add internal faces
138  forAll(mesh.faceNeighbour(), facei)
139  {
140  add_edge(mesh.faceOwner()[facei], mesh.faceNeighbour()[facei], G);
141  }
142  // Add cyclics
143  forAll(pbm, patchi)
144  {
145  if
146  (
147  pbm[patchi].coupled()
148  && !isA<processorPolyPatch>(pbm[patchi])
149  && refCast<const coupledPolyPatch>(pbm[patchi]).owner()
150  )
151  {
152  const labelUList& faceCells = pbm[patchi].faceCells();
153  forAll(faceCells, i)
154  {
155  label bFacei = pbm[patchi].start()+i-mesh.nInternalFaces();
156  label nbrCelli = nbr[bFacei];
157 
158  if (faceCells[i] < nbrCelli)
159  {
160  add_edge(faceCells[i], nbrCelli, G);
161  }
162  else
163  {
164  add_edge(nbrCelli, faceCells[i], G);
165  }
166  }
167  }
168  }
169 
170 
171  //Creating two iterators over the vertices
172  graph_traits<Graph>::vertex_iterator ui, ui_end;
173 
174  //Creating a property_map with the degrees of the degrees of each vertex
175  property_map<Graph,vertex_degree_t>::type deg = get(vertex_degree, G);
176  for (boost::tie(ui, ui_end) = vertices(G); ui != ui_end; ++ui)
177  deg[*ui] = degree(*ui, G);
178 
179  //Creating a property_map for the indices of a vertex
180  property_map<Graph, vertex_index_t>::type index_map = get(vertex_index, G);
181 
182  //Creating a vector of vertices
183  std::vector<Vertex> sloan_order(num_vertices(G));
184 
185  sloan_ordering
186  (
187  G,
188  sloan_order.begin(),
189  get(vertex_color, G),
190  make_degree_map(G),
191  get(vertex_priority, G)
192  );
193 
194  labelList orderedToOld(sloan_order.size());
195  forAll(orderedToOld, c)
196  {
197  orderedToOld[c] = index_map[sloan_order[c]];
198  }
199 
200  if (reverse_)
201  {
202  reverse(orderedToOld);
203  }
204 
205  return orderedToOld;
206 }
207 
208 
210 (
211  const labelListList& cellCells,
212  const pointField& points
213 ) const
214 {
215  Graph G(cellCells.size());
216 
217  forAll(cellCells, celli)
218  {
219  const labelList& nbrs = cellCells[celli];
220  forAll(nbrs, i)
221  {
222  if (nbrs[i] > celli)
223  {
224  add_edge(celli, nbrs[i], G);
225  }
226  }
227  }
228 
229  //Creating two iterators over the vertices
230  graph_traits<Graph>::vertex_iterator ui, ui_end;
231 
232  //Creating a property_map with the degrees of the degrees of each vertex
233  property_map<Graph,vertex_degree_t>::type deg = get(vertex_degree, G);
234  for (boost::tie(ui, ui_end) = vertices(G); ui != ui_end; ++ui)
235  deg[*ui] = degree(*ui, G);
236 
237  //Creating a property_map for the indices of a vertex
238  property_map<Graph, vertex_index_t>::type index_map = get(vertex_index, G);
239 
240  //Creating a vector of vertices
241  std::vector<Vertex> sloan_order(num_vertices(G));
242 
243  sloan_ordering
244  (
245  G,
246  sloan_order.begin(),
247  get(vertex_color, G),
248  make_degree_map(G),
249  get(vertex_priority, G)
250  );
251 
252  labelList orderedToOld(sloan_order.size());
253  forAll(orderedToOld, c)
254  {
255  orderedToOld[c] = index_map[sloan_order[c]];
256  }
257 
258  if (reverse_)
259  {
260  reverse(orderedToOld);
261  }
262 
263  return orderedToOld;
264 }
265 
266 
267 // ************************************************************************* //
Foam::reverse
void reverse(UList< T > &list, const label n)
Definition: UListI.H:396
Foam::polyBoundaryMesh
A polyBoundaryMesh is a polyPatch list with additional search methods and registered IO.
Definition: polyBoundaryMesh.H:62
Foam::constant::universal::G
const dimensionedScalar G
Newtonian constant of gravitation.
Foam::primitiveMesh::nInternalFaces
label nInternalFaces() const
Number of internal faces.
Definition: primitiveMeshI.H:78
Foam::SubList
A List obtained as a section of another List.
Definition: SubList.H:53
Vertex
graph_traits< Graph >::vertex_descriptor Vertex
Definition: SloanRenumber.C:75
SloanRenumber.H
Foam::syncTools::swapBoundaryFaceList
static void swapBoundaryFaceList(const polyMesh &mesh, UList< T > &faceValues)
Swap coupled boundary face values. Uses eqOp.
Definition: syncTools.H:439
Foam::polyMesh::boundaryMesh
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:444
decompositionMethod.H
syncTools.H
Foam::polyBoundaryMesh::start
label start() const
The start label of the boundary faces in the polyMesh face list.
Definition: polyBoundaryMesh.C:638
Foam::SloanRenumber::renumber
virtual labelList renumber(const pointField &) const
Return the order in which cells need to be visited, i.e.
Definition: SloanRenumber.H:90
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Graph
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:73
Foam::primitiveMesh::nCells
label nCells() const
Number of mesh cells.
Definition: primitiveMeshI.H:96
Foam::Field< vector >
addToRunTimeSelectionTable
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to hash-table of functions with typename as the key.
Definition: addToRunTimeSelectionTable.H:37
Foam::polyMesh::faceOwner
virtual const labelList & faceOwner() const
Return face owner.
Definition: polyMesh.C:1107
size_type
graph_traits< Graph >::vertices_size_type size_type
Definition: SloanRenumber.C:76
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
processorPolyPatch.H
Foam::primitiveMesh::nBoundaryFaces
label nBoundaryFaces() const
Number of boundary faces (== nFaces - nInternalFaces)
Definition: primitiveMeshI.H:84
Foam::vertices
pointField vertices(const blockVertexList &bvl)
Definition: blockVertexList.H:49
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::renumberMethod
Abstract base class for renumbering.
Definition: renumberMethod.H:50
Foam::List< label >
Foam::UList< label >
defineTypeNameAndDebug
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::roots::type
type
Types of root.
Definition: Roots.H:54
Foam::constant::universal::c
const dimensionedScalar c
Speed of light in a vacuum.
Foam::faceCells
Smooth ATC in cells next to a set of patches supplied by type.
Definition: faceCells.H:56
Foam::polyMesh::faceNeighbour
virtual const labelList & faceNeighbour() const
Return face neighbour.
Definition: polyMesh.C:1113