Line data Source code
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 : 10 : #include "PorousFlowConnectedNodes.h" 11 : #include "Conversion.h" // for stringify 12 : #include "MooseError.h" 13 : 14 1688 : PorousFlowConnectedNodes::PorousFlowConnectedNodes() { clear(); } 15 : 16 : void 17 4490 : PorousFlowConnectedNodes::clear() 18 : { 19 4490 : _still_adding_global_nodes = true; 20 4490 : _min_global_id = std::numeric_limits<dof_id_type>::max(); 21 4490 : _max_global_id = std::numeric_limits<dof_id_type>::lowest(); 22 : _set_of_global_ids.clear(); 23 4490 : _global_id.clear(); 24 4490 : _sequential_id.clear(); 25 4490 : _still_adding_connections = true; 26 4490 : _neighbor_sets.clear(); 27 4490 : _sequential_neighbors.clear(); 28 4490 : } 29 : 30 : std::size_t 31 157923 : PorousFlowConnectedNodes::numNodes() const 32 : { 33 157923 : if (_still_adding_global_nodes) 34 1 : return _set_of_global_ids.size(); 35 157922 : return _global_id.size(); 36 : } 37 : 38 : void 39 126607 : PorousFlowConnectedNodes::addGlobalNode(dof_id_type global_node_ID) 40 : { 41 126607 : if (!_still_adding_global_nodes) 42 1 : mooseError("PorousFlowConnectedNodes: addGlobalNode called, but _still_adding_global_nodes is " 43 : "false. You possibly called finalizeAddingGlobalNodes too soon."); 44 126606 : _set_of_global_ids.insert(global_node_ID); 45 126606 : _min_global_id = std::min(_min_global_id, global_node_ID); 46 126606 : _max_global_id = std::max(_max_global_id, global_node_ID); 47 126606 : } 48 : 49 : void 50 2808 : PorousFlowConnectedNodes::finalizeAddingGlobalNodes() 51 : { 52 : // populate the _global_id vector with the values in the set of global IDs 53 2808 : _global_id.clear(); 54 59125 : for (const auto & n : _set_of_global_ids) 55 56317 : _global_id.push_back(n); 56 2808 : _still_adding_global_nodes = false; 57 : _set_of_global_ids.clear(); 58 : 59 : // populate the _sequential_id 60 2808 : _sequential_id.assign(_max_global_id - _min_global_id + 1, 0); 61 59125 : for (std::size_t i = 0; i < _global_id.size(); ++i) 62 56317 : _sequential_id[_global_id[i] - _min_global_id] = i; 63 : 64 : // prepare the _neighbor_sets 65 2808 : _neighbor_sets.assign(_global_id.size(), std::set<dof_id_type>()); 66 2808 : } 67 : 68 : std::size_t 69 2804 : PorousFlowConnectedNodes::sizeSequential() const 70 : { 71 2804 : if (_still_adding_global_nodes) 72 1 : mooseError("PorousFlowConnectedNodes: sizeSequential called, but _still_adding_global_nodes is " 73 : "true. Probably you should have called finalizeAddingGlobalNodes."); 74 2803 : return _sequential_id.size(); 75 : } 76 : 77 : dof_id_type 78 54203313 : PorousFlowConnectedNodes::globalID(dof_id_type sequential_node_ID) const 79 : { 80 54203313 : if (_still_adding_global_nodes) 81 1 : mooseError("PorousFlowConnectedNodes: globalID called, but _still_adding_global_nodes is true. " 82 : " Probably you should have called finalizeAddingGlobalNodes."); 83 54203312 : return _global_id[sequential_node_ID]; 84 : } 85 : 86 : dof_id_type 87 243486744 : PorousFlowConnectedNodes::sequentialID(dof_id_type global_node_ID) const 88 : { 89 243486744 : if (_still_adding_global_nodes) 90 1 : mooseError("PorousFlowConnectedNodes: sequentialID called, but _still_adding_global_nodes is " 91 : "true. Probably you should have called finalizeAddingGlobalNodes."); 92 243486743 : return _sequential_id[global_node_ID - _min_global_id]; 93 : } 94 : 95 : void 96 406084 : PorousFlowConnectedNodes::addConnection(dof_id_type global_node_from, dof_id_type global_node_to) 97 : { 98 406084 : if (_still_adding_global_nodes) 99 1 : mooseError("PorousFlowConnectedNodes: addConnection called, but _still_adding_global_nodes is " 100 : "true. Probably you should have called finalizeAddingGlobalNodes."); 101 406083 : if (!_still_adding_connections) 102 1 : mooseError("PorousFlowConnectedNodes: addConnection called, but _still_adding_connections is " 103 : "false. Probably you should have called finalizeAddingConnections."); 104 406082 : _neighbor_sets[sequentialID(global_node_from)].insert(global_node_to); 105 406082 : } 106 : 107 : void 108 2808 : PorousFlowConnectedNodes::finalizeAddingConnections() 109 : { 110 2808 : _sequential_neighbors.assign(_global_id.size(), std::vector<dof_id_type>()); 111 2808 : _global_neighbors.assign(_global_id.size(), std::vector<dof_id_type>()); 112 59125 : for (std::size_t i = 0; i < _global_id.size(); ++i) 113 333078 : for (const auto & n : _neighbor_sets[i]) 114 : { 115 276761 : _sequential_neighbors[i].push_back(sequentialID(n)); 116 276761 : _global_neighbors[i].push_back(n); 117 : } 118 2808 : _still_adding_connections = false; 119 2808 : _neighbor_sets.clear(); 120 2808 : } 121 : 122 : const std::vector<dof_id_type> & 123 7 : PorousFlowConnectedNodes::sequentialConnectionsToGlobalID(dof_id_type global_node_ID) const 124 : { 125 7 : if (_still_adding_connections) 126 1 : mooseError("PorousFlowConnectedNodes: sequentialConnectionsToGlobalID called, but " 127 : "_still_adding_connections is true. Probably you should have called " 128 : "finalizeAddingConnections."); 129 6 : return _sequential_neighbors[sequentialID(global_node_ID)]; 130 : } 131 : 132 : const std::vector<dof_id_type> & 133 142361328 : PorousFlowConnectedNodes::sequentialConnectionsToSequentialID(dof_id_type sequential_node_ID) const 134 : { 135 142361328 : if (_still_adding_connections) 136 1 : mooseError("PorousFlowConnectedNodes: sequentialConnectionsToSequentialID called, but " 137 : "_still_adding_connections is true. Probably you should have called " 138 : "finalizeAddingConnections."); 139 142361327 : return _sequential_neighbors[sequential_node_ID]; 140 : } 141 : 142 : const std::vector<dof_id_type> & 143 31710908 : PorousFlowConnectedNodes::globalConnectionsToGlobalID(dof_id_type global_node_ID) const 144 : { 145 31710908 : if (_still_adding_connections) 146 1 : mooseError("PorousFlowConnectedNodes: globalConnectionsToGlobalID called, but " 147 : "_still_adding_connections is true. Probably you should have called " 148 : "finalizeAddingConnections."); 149 31710907 : return _global_neighbors[sequentialID(global_node_ID)]; 150 : } 151 : 152 : const std::vector<dof_id_type> & 153 9389495 : PorousFlowConnectedNodes::globalConnectionsToSequentialID(dof_id_type sequential_node_ID) const 154 : { 155 9389495 : if (_still_adding_connections) 156 1 : mooseError("PorousFlowConnectedNodes: globalConnectionsToSequentialID called, but " 157 : "_still_adding_connections is true. Probably you should have called " 158 : "finalizeAddingConnections."); 159 9389494 : return _global_neighbors[sequential_node_ID]; 160 : } 161 : 162 : const std::vector<dof_id_type> & 163 61885 : PorousFlowConnectedNodes::globalIDs() const 164 : { 165 61885 : if (_still_adding_global_nodes) 166 1 : mooseError("PorousFlowConnectedNodes: globalIDs called, but _still_adding_global_nodes is " 167 : "true. Probably you should have called finalizeAddingGlobalNodes."); 168 61884 : return _global_id; 169 : } 170 : 171 : unsigned 172 85753472 : PorousFlowConnectedNodes::indexOfGlobalConnection(dof_id_type global_node_ID_from, 173 : dof_id_type global_node_ID_to) const 174 : { 175 85753472 : if (_still_adding_connections) 176 1 : mooseError( 177 : "PorousFlowConnectedNodes: indexOfGlobalConnection called, but _still_adding_connections " 178 : "is true. Probably you should have called finalizeAddingConnections."); 179 85753471 : const std::vector<dof_id_type> con = _global_neighbors[sequentialID(global_node_ID_from)]; 180 85753471 : const auto it = std::find(con.begin(), con.end(), global_node_ID_to); 181 85753471 : if (it == con.end()) 182 0 : mooseError("PorousFlowConnectedNode: global_node_ID_from " + 183 0 : Moose::stringify(global_node_ID_from) + " has no connection to global_node_ID_to " + 184 0 : Moose::stringify(global_node_ID_to)); 185 85753471 : return std::distance(con.begin(), it); 186 85753471 : } 187 : 188 : unsigned 189 66419989 : PorousFlowConnectedNodes::indexOfSequentialConnection(dof_id_type sequential_node_ID_from, 190 : dof_id_type sequential_node_ID_to) const 191 : { 192 66419989 : if (_still_adding_connections) 193 1 : mooseError("PorousFlowConnectedNodes: indexOfSequentialConnection called, but " 194 : "_still_adding_connections is true. Probably you should have called " 195 : "finalizeAddingConnections."); 196 66419988 : const std::vector<dof_id_type> con = _sequential_neighbors[sequential_node_ID_from]; 197 66419988 : const auto it = std::find(con.begin(), con.end(), sequential_node_ID_to); 198 66419988 : if (it == con.end()) 199 2 : mooseError("PorousFlowConnectedNode: sequential_node_ID_from " + 200 1 : Moose::stringify(sequential_node_ID_from) + 201 1 : " has no connection to sequential_node_ID_to " + 202 1 : Moose::stringify(sequential_node_ID_to)); 203 66419987 : return std::distance(con.begin(), it); 204 66419988 : }