www.mooseframework.org
Public Member Functions | Private Attributes | List of all members
PorousFlowConnectedNodes Class Reference

Class designed to hold node ID information and information about nodal connectivity. More...

#include <PorousFlowConnectedNodes.h>

Public Member Functions

 PorousFlowConnectedNodes ()
 
void clear ()
 clear all data in readiness for adding global nodes and connections More...
 
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 added this method does nothing. More...
 
void finalizeAddingGlobalNodes ()
 Signal that all global node IDs have been added to the internal data structures. More...
 
std::size_t numNodes () const
 number of nodes known by this class More...
 
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. More...
 
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 range [0, numNodes() - 1]. More...
 
const std::vector< dof_id_type > & globalIDs () const
 Vector of all global node IDs (node numbers in the mesh) More...
 
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. More...
 
void finalizeAddingConnections ()
 Signal that all global node IDs have been added to the internal data structures. More...
 
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 returned vector are guaranteed to be unique and lie in the range [0, numNodes() - 1]. More...
 
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 the returned vector are guaranteed to be unique and lie in the range [0, numNodes() - 1]. More...
 
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. More...
 
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. More...
 
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. More...
 
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_ID_from) vector. More...
 
std::size_t sizeSequential () const
 Return the size of _sequential_id, for checking memory efficiency. More...
 

Private Attributes

bool _still_adding_global_nodes
 
dof_id_type _min_global_id
 
dof_id_type _max_global_id
 
std::set< dof_id_type > _set_of_global_ids
 
std::vector< dof_id_type > _global_id
 
std::vector< dof_id_type > _sequential_id
 
bool _still_adding_connections
 
std::vector< std::set< dof_id_type > > _neighbor_sets
 
std::vector< std::vector< dof_id_type > > _sequential_neighbors
 
std::vector< std::vector< dof_id_type > > _global_neighbors
 

Detailed Description

Class designed to hold node ID information and information about nodal connectivity.

Node ID is either:

The use case of interest in PorousFlow is where many quantities are recorded at each node in the mesh. To record this, a std::vector<quantity> may be used. But if the global node IDs are sparsely distributed between zero and the maximum node number, then basing the std::vector on global ID is inefficient because there are many elements in the std::vector that are unused. Instead, a std::vector based on the sequential node ID may be used, which is optimally memory efficient. (A std::map<dof_id_type, quantity> may be used, but it is slow.)

Nodal connectivity is defined between two global node IDs. Note that it is uni-directional, meaning that if node 12 is connected to node 321, then node 321 is not necessarily connected to node 12 (the user must explicitly add both the 12->321 and 321->12 connections if that is desired).

This class is designed to be used as follows: (1) instantiation (2) populate the nodal information using addGlobalNode (3) finalizeAddingGlobalNodes() (4) populate the connectivity using addConnection (5) finalizeAddingConnections() (6) functions like sequentialID and sequentialNeighborsOfGlobalID are now ready for use

Definition at line 45 of file PorousFlowConnectedNodes.h.

Constructor & Destructor Documentation

◆ PorousFlowConnectedNodes()

PorousFlowConnectedNodes::PorousFlowConnectedNodes ( )

Definition at line 14 of file PorousFlowConnectedNodes.C.

14 { clear(); }
void clear()
clear all data in readiness for adding global nodes and connections

Member Function Documentation

◆ addConnection()

void PorousFlowConnectedNodes::addConnection ( dof_id_type  global_node_from,
dof_id_type  global_node_to 
)

Specifies that global_node_to is connected to global_node_from.

Hence, globalConnectionsToGlobalID(global_node_from) will contain global_node_to. If the connection has already been added this method does nothing Recall that connections are uni-directional, so if you desire bi-directional connectivity you must call addConnection twice (the second time with arguments swapped)

Parameters
global_node_fromglobal node ID of the 'from' node
global_node_toglobal node ID of the 'to' node

Definition at line 96 of file PorousFlowConnectedNodes.C.

Referenced by AdvectiveFluxCalculatorBase::timestepSetup().

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 }
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::set< dof_id_type > > _neighbor_sets

◆ addGlobalNode()

void PorousFlowConnectedNodes::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 added this method does nothing.

Parameters
global_node_IDnode number in the mesh

Definition at line 39 of file PorousFlowConnectedNodes.C.

Referenced by AdvectiveFluxCalculatorBase::timestepSetup().

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 }
std::set< dof_id_type > _set_of_global_ids

◆ clear()

void PorousFlowConnectedNodes::clear ( )

clear all data in readiness for adding global nodes and connections

Definition at line 17 of file PorousFlowConnectedNodes.C.

Referenced by PorousFlowConnectedNodes(), and AdvectiveFluxCalculatorBase::timestepSetup().

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 }
std::vector< dof_id_type > _sequential_id
std::vector< std::vector< dof_id_type > > _sequential_neighbors
std::vector< dof_id_type > _global_id
std::set< dof_id_type > _set_of_global_ids
std::vector< std::set< dof_id_type > > _neighbor_sets

◆ finalizeAddingConnections()

void PorousFlowConnectedNodes::finalizeAddingConnections ( )

Signal that all global node IDs have been added to the internal data structures.

Definition at line 108 of file PorousFlowConnectedNodes.C.

Referenced by AdvectiveFluxCalculatorBase::timestepSetup().

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 }
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< dof_id_type > _global_id
std::vector< std::vector< dof_id_type > > _global_neighbors
std::vector< std::set< dof_id_type > > _neighbor_sets

◆ finalizeAddingGlobalNodes()

void PorousFlowConnectedNodes::finalizeAddingGlobalNodes ( )

Signal that all global node IDs have been added to the internal data structures.

Definition at line 50 of file PorousFlowConnectedNodes.C.

Referenced by AdvectiveFluxCalculatorBase::timestepSetup().

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 }
std::vector< dof_id_type > _sequential_id
std::vector< dof_id_type > _global_id
std::set< dof_id_type > _set_of_global_ids
std::vector< std::set< dof_id_type > > _neighbor_sets

◆ globalConnectionsToGlobalID()

const std::vector< dof_id_type > & PorousFlowConnectedNodes::globalConnectionsToGlobalID ( dof_id_type  global_node_ID) const

Return all the nodes (global node IDs) connected to the given global node ID.

Definition at line 143 of file PorousFlowConnectedNodes.C.

Referenced by AdvectiveFluxCalculatorBase::finalize(), PorousFlowAdvectiveFluxCalculatorBase::finalize(), and AdvectiveFluxCalculatorBase::zeroedConnection().

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 }
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 > > _global_neighbors

◆ globalConnectionsToSequentialID()

const std::vector< dof_id_type > & PorousFlowConnectedNodes::globalConnectionsToSequentialID ( dof_id_type  sequential_node_ID) const

Return all the nodes (global node IDs) connected to the given sequential node ID.

Definition at line 153 of file PorousFlowConnectedNodes.C.

Referenced by AdvectiveFluxCalculatorBase::finalize(), PorousFlowAdvectiveFluxCalculatorBase::initialize(), PorousFlowAdvectiveFluxCalculatorBase::threadJoin(), and PorousFlowAdvectiveFluxCalculatorBase::timestepSetup().

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 }
std::vector< std::vector< dof_id_type > > _global_neighbors

◆ globalID()

dof_id_type PorousFlowConnectedNodes::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.

Parameters
sequential_node_IDthe sequential node ID

Definition at line 78 of file PorousFlowConnectedNodes.C.

Referenced by AdvectiveFluxCalculatorBase::finalize(), and AdvectiveFluxCalculatorBase::timestepSetup().

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 }
std::vector< dof_id_type > _global_id

◆ globalIDs()

const std::vector< dof_id_type > & PorousFlowConnectedNodes::globalIDs ( ) const

Vector of all global node IDs (node numbers in the mesh)

Definition at line 163 of file PorousFlowConnectedNodes.C.

Referenced by PorousFlowAdvectiveFluxCalculatorBase::finalize().

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 }
std::vector< dof_id_type > _global_id

◆ indexOfGlobalConnection()

unsigned PorousFlowConnectedNodes::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 at line 172 of file PorousFlowConnectedNodes.C.

Referenced by PorousFlowAdvectiveFluxCalculatorBase::executeOnElement(), AdvectiveFluxCalculatorBase::executeOnElement(), and PorousFlowAdvectiveFluxCalculatorBase::getdK_dvar().

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 }
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 > > _global_neighbors

◆ indexOfSequentialConnection()

unsigned PorousFlowConnectedNodes::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_ID_from) vector.

Definition at line 189 of file PorousFlowConnectedNodes.C.

Referenced by AdvectiveFluxCalculatorBase::finalize(), and AdvectiveFluxCalculatorBase::PQPlusMinus().

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 }
std::vector< std::vector< dof_id_type > > _sequential_neighbors

◆ numNodes()

std::size_t PorousFlowConnectedNodes::numNodes ( ) const

◆ sequentialConnectionsToGlobalID()

const std::vector< dof_id_type > & PorousFlowConnectedNodes::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 returned vector are guaranteed to be unique and lie in the range [0, numNodes() - 1].

Definition at line 123 of file PorousFlowConnectedNodes.C.

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 }
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

◆ sequentialConnectionsToSequentialID()

const std::vector< dof_id_type > & PorousFlowConnectedNodes::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 the returned vector are guaranteed to be unique and lie in the range [0, numNodes() - 1].

Definition at line 133 of file PorousFlowConnectedNodes.C.

Referenced by AdvectiveFluxCalculatorBase::finalize(), AdvectiveFluxCalculatorBase::initialize(), AdvectiveFluxCalculatorBase::PQPlusMinus(), AdvectiveFluxCalculatorBase::rMinus(), AdvectiveFluxCalculatorBase::rPlus(), AdvectiveFluxCalculatorBase::threadJoin(), and AdvectiveFluxCalculatorBase::timestepSetup().

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 }
std::vector< std::vector< dof_id_type > > _sequential_neighbors

◆ sequentialID()

dof_id_type PorousFlowConnectedNodes::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 range [0, numNodes() - 1].

Parameters
global_node_IDglobal node ID (ie the node number in the mesh)

Definition at line 87 of file PorousFlowConnectedNodes.C.

Referenced by addConnection(), PorousFlowAdvectiveFluxCalculatorBase::execute(), AdvectiveFluxCalculatorBase::execute(), PorousFlowAdvectiveFluxCalculatorBase::executeOnElement(), AdvectiveFluxCalculatorBase::executeOnElement(), PorousFlowAdvectiveFluxCalculatorBase::finalize(), finalizeAddingConnections(), PorousFlowAdvectiveFluxCalculatorBase::getdFluxOut_dvars(), AdvectiveFluxCalculatorBase::getdFluxOutdKjk(), AdvectiveFluxCalculatorBase::getdFluxOutdu(), PorousFlowAdvectiveFluxCalculatorBase::getdK_dvar(), AdvectiveFluxCalculatorBase::getFluxOut(), AdvectiveFluxCalculatorBase::getValence(), globalConnectionsToGlobalID(), indexOfGlobalConnection(), sequentialConnectionsToGlobalID(), and AdvectiveFluxCalculatorBase::timestepSetup().

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 }
std::vector< dof_id_type > _sequential_id

◆ sizeSequential()

std::size_t PorousFlowConnectedNodes::sizeSequential ( ) const

Return the size of _sequential_id, for checking memory efficiency.

The memory wasted by this class is (sizeSequential() - numNodes()) * (size of dof_id_type). finalizeAddingGlobalNodes() must have been called prior to calling this method

Definition at line 69 of file PorousFlowConnectedNodes.C.

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 }
std::vector< dof_id_type > _sequential_id

Member Data Documentation

◆ _global_id

std::vector<dof_id_type> PorousFlowConnectedNodes::_global_id
private

◆ _global_neighbors

std::vector<std::vector<dof_id_type> > PorousFlowConnectedNodes::_global_neighbors
private

◆ _max_global_id

dof_id_type PorousFlowConnectedNodes::_max_global_id
private

Definition at line 138 of file PorousFlowConnectedNodes.h.

Referenced by addGlobalNode(), clear(), and finalizeAddingGlobalNodes().

◆ _min_global_id

dof_id_type PorousFlowConnectedNodes::_min_global_id
private

◆ _neighbor_sets

std::vector<std::set<dof_id_type> > PorousFlowConnectedNodes::_neighbor_sets
private

◆ _sequential_id

std::vector<dof_id_type> PorousFlowConnectedNodes::_sequential_id
private

◆ _sequential_neighbors

std::vector<std::vector<dof_id_type> > PorousFlowConnectedNodes::_sequential_neighbors
private

◆ _set_of_global_ids

std::set<dof_id_type> PorousFlowConnectedNodes::_set_of_global_ids
private

◆ _still_adding_connections

bool PorousFlowConnectedNodes::_still_adding_connections
private

◆ _still_adding_global_nodes

bool PorousFlowConnectedNodes::_still_adding_global_nodes
private

The documentation for this class was generated from the following files: