https://mooseframework.inl.gov
Loading...
Searching...
No Matches
PorousFlowConnectedNodes.C
Go to the documentation of this file.
1//* This file is part of the MOOSE framework
2//* https://mooseframework.inl.gov
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
16void
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();
28}
29
30std::size_t
32{
34 return _set_of_global_ids.size();
35 return _global_id.size();
36}
37
38void
39PorousFlowConnectedNodes::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
49void
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
68std::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
77dof_id_type
78PorousFlowConnectedNodes::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
86dof_id_type
87PorousFlowConnectedNodes::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
95void
96PorousFlowConnectedNodes::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
107void
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
122const 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
132const 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
142const 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
152const 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
162const 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
171unsigned
173 dof_id_type global_node_ID_to) const
174{
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
188unsigned
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}
void mooseError(Args &&... args)
std::vector< dof_id_type > _sequential_id
void finalizeAddingConnections()
Signal that all global node IDs have been added to the internal data structures.
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 ...
std::vector< std::vector< dof_id_type > > _global_neighbors
const std::vector< dof_id_type > & globalIDs() const
Vector of all global node IDs (node numbers in the mesh)
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.
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 ...
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.
std::size_t numNodes() const
number of nodes known by this class
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_...
std::vector< dof_id_type > _global_id
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.
void finalizeAddingGlobalNodes()
Signal that all global node IDs have been added to the internal data structures.
void clear()
clear all data in readiness for adding global nodes and connections
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...
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.
std::set< dof_id_type > _set_of_global_ids
std::size_t sizeSequential() const
Return the size of _sequential_id, for checking memory efficiency.
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...
std::vector< std::vector< dof_id_type > > _sequential_neighbors
std::vector< std::set< dof_id_type > > _neighbor_sets
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.
std::string stringify(const T &t)