www.mooseframework.org
PorousFlowConnectedNodes.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
11 #include "Conversion.h" // for stringify
12 #include "MooseError.h"
13 
15 
16 void
18 {
20  _min_global_id = std::numeric_limits<dof_id_type>::max();
21  _max_global_id = std::numeric_limits<dof_id_type>::lowest();
22  _set_of_global_ids.clear();
23  _global_id.clear();
24  _sequential_id.clear();
26  _neighbor_sets.clear();
27  _sequential_neighbors.clear();
28 }
29 
30 std::size_t
32 {
34  return _set_of_global_ids.size();
35  return _global_id.size();
36 }
37 
38 void
39 PorousFlowConnectedNodes::addGlobalNode(dof_id_type global_node_ID)
40 {
42  mooseError("PorousFlowConnectedNodes: addGlobalNode called, but _still_adding_global_nodes is "
43  "false. You possibly called finalizeAddingGlobalNodes too soon.");
44  _set_of_global_ids.insert(global_node_ID);
45  _min_global_id = std::min(_min_global_id, global_node_ID);
46  _max_global_id = std::max(_max_global_id, global_node_ID);
47 }
48 
49 void
51 {
52  // populate the _global_id vector with the values in the set of global IDs
53  _global_id.clear();
54  for (const auto & n : _set_of_global_ids)
55  _global_id.push_back(n);
57  _set_of_global_ids.clear();
58 
59  // populate the _sequential_id
61  for (std::size_t i = 0; i < _global_id.size(); ++i)
63 
64  // prepare the _neighbor_sets
65  _neighbor_sets.assign(_global_id.size(), std::set<dof_id_type>());
66 }
67 
68 std::size_t
70 {
72  mooseError("PorousFlowConnectedNodes: sizeSequential called, but _still_adding_global_nodes is "
73  "true. Probably you should have called finalizeAddingGlobalNodes.");
74  return _sequential_id.size();
75 }
76 
77 dof_id_type
78 PorousFlowConnectedNodes::globalID(dof_id_type sequential_node_ID) const
79 {
81  mooseError("PorousFlowConnectedNodes: globalID called, but _still_adding_global_nodes is true. "
82  " Probably you should have called finalizeAddingGlobalNodes.");
83  return _global_id[sequential_node_ID];
84 }
85 
86 dof_id_type
87 PorousFlowConnectedNodes::sequentialID(dof_id_type global_node_ID) const
88 {
90  mooseError("PorousFlowConnectedNodes: sequentialID called, but _still_adding_global_nodes is "
91  "true. Probably you should have called finalizeAddingGlobalNodes.");
92  return _sequential_id[global_node_ID - _min_global_id];
93 }
94 
95 void
96 PorousFlowConnectedNodes::addConnection(dof_id_type global_node_from, dof_id_type global_node_to)
97 {
99  mooseError("PorousFlowConnectedNodes: addConnection called, but _still_adding_global_nodes is "
100  "true. Probably you should have called finalizeAddingGlobalNodes.");
102  mooseError("PorousFlowConnectedNodes: addConnection called, but _still_adding_connections is "
103  "false. Probably you should have called finalizeAddingConnections.");
104  _neighbor_sets[sequentialID(global_node_from)].insert(global_node_to);
105 }
106 
107 void
109 {
110  _sequential_neighbors.assign(_global_id.size(), std::vector<dof_id_type>());
111  _global_neighbors.assign(_global_id.size(), std::vector<dof_id_type>());
112  for (std::size_t i = 0; i < _global_id.size(); ++i)
113  for (const auto & n : _neighbor_sets[i])
114  {
115  _sequential_neighbors[i].push_back(sequentialID(n));
116  _global_neighbors[i].push_back(n);
117  }
119  _neighbor_sets.clear();
120 }
121 
122 const std::vector<dof_id_type> &
124 {
126  mooseError("PorousFlowConnectedNodes: sequentialConnectionsToGlobalID called, but "
127  "_still_adding_connections is true. Probably you should have called "
128  "finalizeAddingConnections.");
129  return _sequential_neighbors[sequentialID(global_node_ID)];
130 }
131 
132 const std::vector<dof_id_type> &
134 {
136  mooseError("PorousFlowConnectedNodes: sequentialConnectionsToSequentialID called, but "
137  "_still_adding_connections is true. Probably you should have called "
138  "finalizeAddingConnections.");
139  return _sequential_neighbors[sequential_node_ID];
140 }
141 
142 const std::vector<dof_id_type> &
144 {
146  mooseError("PorousFlowConnectedNodes: globalConnectionsToGlobalID called, but "
147  "_still_adding_connections is true. Probably you should have called "
148  "finalizeAddingConnections.");
149  return _global_neighbors[sequentialID(global_node_ID)];
150 }
151 
152 const std::vector<dof_id_type> &
154 {
156  mooseError("PorousFlowConnectedNodes: globalConnectionsToSequentialID called, but "
157  "_still_adding_connections is true. Probably you should have called "
158  "finalizeAddingConnections.");
159  return _global_neighbors[sequential_node_ID];
160 }
161 
162 const std::vector<dof_id_type> &
164 {
166  mooseError("PorousFlowConnectedNodes: globalIDs called, but _still_adding_global_nodes is "
167  "true. Probably you should have called finalizeAddingGlobalNodes.");
168  return _global_id;
169 }
170 
171 unsigned
173  dof_id_type global_node_ID_to) const
174 {
176  mooseError(
177  "PorousFlowConnectedNodes: indexOfGlobalConnection called, but _still_adding_connections "
178  "is true. Probably you should have called finalizeAddingConnections.");
179  const std::vector<dof_id_type> con = _global_neighbors[sequentialID(global_node_ID_from)];
180  const auto it = std::find(con.begin(), con.end(), global_node_ID_to);
181  if (it == con.end())
182  mooseError("PorousFlowConnectedNode: global_node_ID_from " +
183  Moose::stringify(global_node_ID_from) + " has no connection to global_node_ID_to " +
184  Moose::stringify(global_node_ID_to));
185  return std::distance(con.begin(), it);
186 }
187 
188 unsigned
189 PorousFlowConnectedNodes::indexOfSequentialConnection(dof_id_type sequential_node_ID_from,
190  dof_id_type sequential_node_ID_to) const
191 {
193  mooseError("PorousFlowConnectedNodes: indexOfSequentialConnection called, but "
194  "_still_adding_connections is true. Probably you should have called "
195  "finalizeAddingConnections.");
196  const std::vector<dof_id_type> con = _sequential_neighbors[sequential_node_ID_from];
197  const auto it = std::find(con.begin(), con.end(), sequential_node_ID_to);
198  if (it == con.end())
199  mooseError("PorousFlowConnectedNode: sequential_node_ID_from " +
200  Moose::stringify(sequential_node_ID_from) +
201  " has no connection to sequential_node_ID_to " +
202  Moose::stringify(sequential_node_ID_to));
203  return std::distance(con.begin(), it);
204 }
PorousFlowConnectedNodes::_sequential_neighbors
std::vector< std::vector< dof_id_type > > _sequential_neighbors
Definition: PorousFlowConnectedNodes.h:144
PorousFlowConnectedNodes::_global_id
std::vector< dof_id_type > _global_id
Definition: PorousFlowConnectedNodes.h:139
PorousFlowConnectedNodes::_still_adding_connections
bool _still_adding_connections
Definition: PorousFlowConnectedNodes.h:142
PorousFlowConnectedNodes::globalConnectionsToSequentialID
const std::vector< dof_id_type > & globalConnectionsToSequentialID(dof_id_type sequential_node_ID) const
Return all the nodes (global node IDs) connected to the given sequential node ID.
Definition: PorousFlowConnectedNodes.C:153
PorousFlowConnectedNodes::numNodes
std::size_t numNodes() const
number of nodes known by this class
Definition: PorousFlowConnectedNodes.C:31
PorousFlowConnectedNodes::globalID
dof_id_type globalID(dof_id_type sequential_node_ID) const
Return the global node ID (node number in the mesh) corresponding to the provided sequential node ID.
Definition: PorousFlowConnectedNodes.C:78
PorousFlowConnectedNodes::sequentialConnectionsToSequentialID
const std::vector< dof_id_type > & sequentialConnectionsToSequentialID(dof_id_type sequential_node_ID) const
Return all the nodes (sequential node IDs) connected to the given sequential node ID All elements of ...
Definition: PorousFlowConnectedNodes.C:133
PorousFlowConnectedNodes::_sequential_id
std::vector< dof_id_type > _sequential_id
Definition: PorousFlowConnectedNodes.h:140
PorousFlowConnectedNodes::indexOfSequentialConnection
unsigned indexOfSequentialConnection(dof_id_type sequential_node_ID_from, dof_id_type sequential_node_ID_to) const
Return the index of sequential_node_ID_to in the sequentialConnectionsToSequentialID(sequential_node_...
Definition: PorousFlowConnectedNodes.C:189
PorousFlowConnectedNodes::_global_neighbors
std::vector< std::vector< dof_id_type > > _global_neighbors
Definition: PorousFlowConnectedNodes.h:145
PorousFlowConnectedNodes::_still_adding_global_nodes
bool _still_adding_global_nodes
Definition: PorousFlowConnectedNodes.h:135
PorousFlowConnectedNodes::clear
void clear()
clear all data in readiness for adding global nodes and connections
Definition: PorousFlowConnectedNodes.C:17
PorousFlowConnectedNodes::_min_global_id
dof_id_type _min_global_id
Definition: PorousFlowConnectedNodes.h:136
PorousFlowConnectedNodes::_max_global_id
dof_id_type _max_global_id
Definition: PorousFlowConnectedNodes.h:137
PorousFlowConnectedNodes::indexOfGlobalConnection
unsigned indexOfGlobalConnection(dof_id_type global_node_ID_from, dof_id_type global_node_ID_to) const
Return the index of global_node_ID_to in the globalConnectionsToGlobalID(global_node_ID_from) vector.
Definition: PorousFlowConnectedNodes.C:172
PorousFlowConnectedNodes::globalConnectionsToGlobalID
const std::vector< dof_id_type > & globalConnectionsToGlobalID(dof_id_type global_node_ID) const
Return all the nodes (global node IDs) connected to the given global node ID.
Definition: PorousFlowConnectedNodes.C:143
PorousFlowConnectedNodes.h
PorousFlowConnectedNodes::finalizeAddingGlobalNodes
void finalizeAddingGlobalNodes()
Signal that all global node IDs have been added to the internal data structures.
Definition: PorousFlowConnectedNodes.C:50
PorousFlowConnectedNodes::sequentialConnectionsToGlobalID
const std::vector< dof_id_type > & sequentialConnectionsToGlobalID(dof_id_type global_node_ID) const
Return all the nodes (sequential node IDs) connected to the given global node ID All elements of the ...
Definition: PorousFlowConnectedNodes.C:123
PorousFlowConnectedNodes::sequentialID
dof_id_type sequentialID(dof_id_type global_node_ID) const
Return the sequential node ID corresponding to the global node ID This is guaranteed to lie in the ra...
Definition: PorousFlowConnectedNodes.C:87
PorousFlowConnectedNodes::finalizeAddingConnections
void finalizeAddingConnections()
Signal that all global node IDs have been added to the internal data structures.
Definition: PorousFlowConnectedNodes.C:108
PorousFlowConnectedNodes::addGlobalNode
void addGlobalNode(dof_id_type global_node_ID)
Add the given global_node_ID to the internal data structures If the global node ID has already been a...
Definition: PorousFlowConnectedNodes.C:39
PorousFlowConnectedNodes::addConnection
void addConnection(dof_id_type global_node_from, dof_id_type global_node_to)
Specifies that global_node_to is connected to global_node_from.
Definition: PorousFlowConnectedNodes.C:96
PorousFlowConnectedNodes::globalIDs
const std::vector< dof_id_type > & globalIDs() const
Vector of all global node IDs (node numbers in the mesh)
Definition: PorousFlowConnectedNodes.C:163
PorousFlowConnectedNodes::PorousFlowConnectedNodes
PorousFlowConnectedNodes()
Definition: PorousFlowConnectedNodes.C:14
PorousFlowConnectedNodes::_set_of_global_ids
std::set< dof_id_type > _set_of_global_ids
Definition: PorousFlowConnectedNodes.h:138
PorousFlowConnectedNodes::_neighbor_sets
std::vector< std::set< dof_id_type > > _neighbor_sets
Definition: PorousFlowConnectedNodes.h:143
PorousFlowConnectedNodes::sizeSequential
std::size_t sizeSequential() const
Return the size of _sequential_id, for checking memory efficiency.
Definition: PorousFlowConnectedNodes.C:69