19#include <unordered_map>
35 using ErrorHandler = std::function<void(
const std::ostringstream &)>;
37 template <
typename EntityId,
typename Topology>
struct TextMeshData;
39 template <
typename EntityId,
typename Topology>
struct ElementData;
145 typename std::set<FaceConnection>::iterator lowerBound =
148 return (lowerBound !=
connections.end() && lowerBound->thisSide == thisSide);
154 typename std::set<FaceConnection>::iterator lowerBound =
157 return (lowerBound !=
connections.end() && lowerBound->thisSide == thisSide &&
158 lowerBound->thatElement == thatElem);
201 ErrorHandler errorHandler = [](
const std::ostringstream &errmsg) {
214 std::vector<size_t> localAndAuraElementIndex =
216 std::unordered_map<EntityId, std::set<size_t>> elementsForNode =
223 void dump(std::ostream &out = std::cout)
226 if (!iter.second.connections.empty()) {
227 out <<
"Element index: " << iter.first << std::endl;
229 for (
const auto &entry : iter.second.connections) {
230 out <<
"\tConnected on side: " << entry.thisSide
231 <<
" to element index: " << entry.thatElement <<
" and side: " << entry.thatSide
238 std::ostream &out = std::cout)
241 if (!iter.second.connections.empty()) {
242 out <<
"Element: " << elemDataVec[iter.first].identifier <<
" {"
243 << elemDataVec[iter.first].topology <<
"}" << std::endl;
245 for (
const auto &entry : iter.second.connections) {
246 out <<
"\tConnected on side: " << entry.thisSide
247 <<
" to element: " << elemDataVec[entry.thatElement].identifier <<
" {"
248 << elemDataVec[entry.thatElement].topology <<
"}" <<
" and side: " << entry.thatSide
259 std::ostringstream errmsg;
260 errmsg <<
"Could not find element index " << elemIndex;
269 typename std::unordered_map<size_t, FaceConnections>::const_iterator
begin()
const
273 typename std::unordered_map<size_t, FaceConnections>::const_iterator
end()
const
284 bool operator()(
const std::string &lhs,
const std::string &rhs)
286 return (strcasecmp(lhs.c_str(), rhs.c_str()) < 0);
305 const size_t elemIndex,
int side,
306 const std::unordered_map<
EntityId, std::set<size_t>> &elementsForNode)
308 std::set<size_t> neighbors;
309 std::vector<OrdinalType> sideNodeIndices =
314 if (!sideNodeIndices.empty()) {
315 EntityId firstSideNode = elementNodeIds[sideNodeIndices[0]];
316 neighbors = elementsForNode.at(firstSideNode);
319 for (
size_t i = 1; i < sideNodeIndices.size(); ++i) {
321 EntityId sideNode = elementNodeIds[sideNodeIndex];
322 const std::set<size_t> &sideNodeElementIndices = elementsForNode.at(sideNode);
324 std::set<size_t> intersection;
325 std::set_intersection(neighbors.begin(), neighbors.end(), sideNodeElementIndices.begin(),
326 sideNodeElementIndices.end(),
327 std::inserter(intersection, intersection.begin()));
329 neighbors = intersection;
337 std::vector<OrdinalType> sideNodeIndices =
339 std::vector<EntityId> sideNodes(sideNodeIndices.size());
342 for (
size_t i = 0; i < sideNodeIndices.size(); ++i) {
344 sideNodes[i] = elementNodeIds[sideNodeIndex];
352 std::vector<EntityId> sideNodes =
get_side_nodes(elemIndex, side);
353 std::sort(sideNodes.begin(), sideNodes.end());
360 size_t neighborElementIndex)
364 std::vector<EntityId> sideNodes =
367 for (
int otherSide = 1;
370 std::vector<EntityId> otherSideNodes =
372 if (sideNodes == otherSideNodes) {
380 size_t neighborElementIndex)
385 std::ostringstream errmsg;
386 errmsg <<
"Neighboring reciprocity check for elements "
395 const std::vector<EntityId> &permutedNodes,
396 const std::vector<OrdinalType> &permutationOrdinals)
398 const size_t numNodes = permutationOrdinals.size();
400 if ((numNodes > permutedNodes.size()) || (numNodes > controlNodes.size())) {
404 bool equivalent =
true;
405 for (
size_t i = 0; equivalent && i < numNodes; ++i) {
406 equivalent = controlNodes[permutationOrdinals[i]] == permutedNodes[i];
414 const std::vector<EntityId> &controlNodes,
415 const std::vector<EntityId> &permutedNodes,
419 bool equivalent =
false;
421 if (controlNodes.size() != permutedNodes.size())
422 return std::make_pair(equivalent, permutation);
425 std::ostringstream errmsg;
426 errmsg <<
"Invalid number of permutations to check: " << numPermutations;
430 std::vector<OrdinalType> permutationOrdinals;
442 return std::make_pair(equivalent, permutation);
446 const std::vector<EntityId> &controlNodes,
447 const std::vector<EntityId> &permutedNodes)
452 std::pair<bool, PermutationType>
454 const std::vector<EntityId> &permutedNodes)
463 std::vector<EntityId> thisNodes =
get_side_nodes(thisElem, thisSide);
464 std::vector<EntityId> thatNodes =
get_side_nodes(thatElem, thatSide);
467 std::pair<bool, PermutationType> result =
470 bool samePolarity = result.first;
484 int numSides = it->second.numSides;
485 if (side < 1 || side > numSides)
494 std::vector<FaceConnection> reciprocity;
499 int thatSide = connectionToThatElement.
thatSide;
508 connectionToThisElement)) {
509 reciprocity.push_back(connectionToThatElement);
521 if (!reciprocity.empty()) {
524 for (
const FaceConnection &connectionToThatElement : reciprocity) {
525 IndexType thatIndex = connectionToThatElement.thatElement;
526 int thatSide = connectionToThatElement.thatSide;
532 thisEntry.
remove(connectionToThatElement);
533 thatEntry.
remove(connectionToThisElement);
609 return topo2.is_shell();
654 const size_t thatElem = connectedElementIndex;
656 bool doConnect =
false;
657 bool breakConnection =
false;
663 breakConnection = doConnect;
670 breakConnection = doConnect;
679 if (breakConnection) {
706 std::ostringstream errmsg;
707 errmsg <<
"Invalid proc ownership for co-incident shells "
712 <<
" Co-incident shells must all exist on the same processor";
720 const std::unordered_map<
EntityId, std::set<size_t>> &elementsForNode)
722 int side = adjacency.
side;
724 std::set<size_t> elementIndicesConnectedToSide =
727 for (
size_t connectedElementIndex : elementIndicesConnectedToSide) {
736 const std::vector<size_t> &elementIndices,
737 const std::unordered_map<
EntityId, std::set<size_t>> &elementsForNode)
741 for (
size_t elementIndex : elementIndices) {
743 for (
int side = 1; side <= numSides; ++side) {
744 if (
m_indexGraph[elementIndex].sideReference[side - 1] == 0) {
754 for (
size_t elementIndex : elementIndices) {
760 std::unordered_map<EntityId, std::set<size_t>>
763 std::unordered_map<EntityId, std::set<size_t>> elementsForNode;
764 for (
size_t index : elementIndices) {
766 elementsForNode[nodeId].insert(index);
770 return elementsForNode;
774 const std::vector<std::string> &sortedSelectedBlocks)
776 if (sortedSelectedBlocks.empty())
781 return std::binary_search(sortedSelectedBlocks.begin(), sortedSelectedBlocks.end(),
786 const std::vector<std::string> &sortedSelectedBlocks,
int proc)
788 bool isGloballySelected = (
ANY_PROC == proc);
793 return isInSelectedBlocks && (isGloballySelected || isLocallySelected || hasLocalNode);
799 std::vector<size_t> localAndAuraElementIndex;
802 std::vector<std::string> sortedSelectedBlocks;
803 for (
const std::string &block : selectedBlocks) {
804 sortedSelectedBlocks.push_back(block);
806 std::sort(sortedSelectedBlocks.begin(), sortedSelectedBlocks.end(),
StringCaseCompLess());
810 localAndAuraElementIndex.push_back(i);
814 localAndAuraElementIndex.resize(localAndAuraElementIndex.size());
815 return localAndAuraElementIndex;
Definition Iotm_TextMeshTopologyMapping.h:33
std::vector< Ordinal > side_topology_node_indices(unsigned side) const
Definition Iotm_TextMeshTopologyMapping.h:131
static constexpr Permutation InvalidPermutation
Definition Iotm_TextMeshTopologyMapping.h:39
uint8_t Permutation
Definition Iotm_TextMeshTopologyMapping.h:36
unsigned num_positive_permutations() const
Definition Iotm_TextMeshTopologyMapping.h:152
bool is_shell() const
Definition Iotm_TextMeshTopologyMapping.h:148
bool fill_permutation_indices(Permutation permutation, std::vector< Ordinal > &nodeOrdinalVector) const
Definition Iotm_TextMeshTopologyMapping.h:167
int num_face_sides() const
Definition Iotm_TextMeshTopologyMapping.h:83
uint16_t Ordinal
Definition Iotm_TextMeshTopologyMapping.h:35
unsigned num_permutations() const
Definition Iotm_TextMeshTopologyMapping.h:150
const TopologyMapEntry & side_topology(unsigned side) const
Definition Iotm_TextMeshTopologyMapping.h:115
Definition Iotm_TextMeshAdjacencyGraph.h:86
void create_graph(int proc=ANY_PROC)
Definition Iotm_TextMeshAdjacencyGraph.h:209
size_t size() const
Definition Iotm_TextMeshAdjacencyGraph.h:267
void add_connection(CurrentAdjacency &adjacency, size_t connectedElementIndex, int otherSide)
Definition Iotm_TextMeshAdjacencyGraph.h:651
bool element_is_in_selected_blocks(const size_t elemIndex, const std::vector< std::string > &sortedSelectedBlocks)
Definition Iotm_TextMeshAdjacencyGraph.h:773
static constexpr int INVALID_SIDE
Definition Iotm_TextMeshAdjacencyGraph.h:91
virtual size_t get_num_elements() const =0
ErrorHandler m_errorHandler
Definition Iotm_TextMeshAdjacencyGraph.h:818
virtual const Topology & get_element_topology(const size_t elemIndex) const =0
bool is_shell_shell_connection(const size_t thisElem, const size_t thatElem)
Definition Iotm_TextMeshAdjacencyGraph.h:544
bool is_shell_solid_connection(const size_t thisElem, const size_t thatElem)
Definition Iotm_TextMeshAdjacencyGraph.h:556
void create_graph(const std::vector< std::string > &selectedBlocks, int proc=ANY_PROC)
Definition Iotm_TextMeshAdjacencyGraph.h:211
bool is_selected_element(const size_t elemIndex, const std::vector< std::string > &sortedSelectedBlocks, int proc)
Definition Iotm_TextMeshAdjacencyGraph.h:785
virtual const std::string & get_element_block_name(const size_t elemIndex) const =0
virtual ~SideAdjacencyGraph()=default
bool has_any_shell_connection_on_side(size_t thisIndex, int thisSide)
Definition Iotm_TextMeshAdjacencyGraph.h:606
void fill_sides_for_connected_element(CurrentAdjacency &adjacency, size_t neighborElementIndex)
Definition Iotm_TextMeshAdjacencyGraph.h:379
void break_reciprocal_connections(CurrentAdjacency &adjacency)
Definition Iotm_TextMeshAdjacencyGraph.h:517
void build_side_connectivity_graph(const std::vector< size_t > &elementIndices, const std::unordered_map< EntityId, std::set< size_t > > &elementsForNode)
Definition Iotm_TextMeshAdjacencyGraph.h:735
const FaceConnections & operator[](const IndexType elemIndex) const
Definition Iotm_TextMeshAdjacencyGraph.h:254
std::vector< FaceConnection > get_reciprocity(CurrentAdjacency &adjacency)
Definition Iotm_TextMeshAdjacencyGraph.h:492
bool has_same_polarity(const size_t thisElem, const int thisSide, const size_t thatElem, const int thatSide)
Definition Iotm_TextMeshAdjacencyGraph.h:460
std::pair< bool, PermutationType > get_permutation(const Topology &topology, const std::vector< EntityId > &controlNodes, const std::vector< EntityId > &permutedNodes, PermutationType numPermutations)
Definition Iotm_TextMeshAdjacencyGraph.h:413
void initialize_side_connectivity_graph(const std::vector< size_t > &elementIndices)
Definition Iotm_TextMeshAdjacencyGraph.h:752
virtual EntityId get_element_id(const size_t elemIndex) const =0
std::unordered_map< EntityId, std::set< size_t > > get_elements_for_node_map(const std::vector< size_t > &elementIndices)
Definition Iotm_TextMeshAdjacencyGraph.h:761
typename Topology::Ordinal OrdinalType
Definition Iotm_TextMeshAdjacencyGraph.h:279
std::vector< size_t > get_local_and_aura_elements(const std::vector< std::string > &selectedBlocks, int proc)
Definition Iotm_TextMeshAdjacencyGraph.h:797
virtual int get_element_proc(const size_t elemIndex) const =0
bool equivalent_node_permutation(const std::vector< EntityId > &controlNodes, const std::vector< EntityId > &permutedNodes, const std::vector< OrdinalType > &permutationOrdinals)
Definition Iotm_TextMeshAdjacencyGraph.h:394
void internal_fill_sides_for_connected_element(CurrentAdjacency &adjacency, size_t neighborElementIndex)
Definition Iotm_TextMeshAdjacencyGraph.h:359
bool has_solid_solid_connection_on_side(size_t thisIndex, int thisSide)
Definition Iotm_TextMeshAdjacencyGraph.h:642
bool is_shell_solid_connection(const Topology &thisElemTopology, const Topology &thatElemTopology)
Definition Iotm_TextMeshAdjacencyGraph.h:550
void enforce_coincident_shell_ownership(IndexType connectedElemIndex1, IndexType connectedElemIndex2)
Definition Iotm_TextMeshAdjacencyGraph.h:700
std::unordered_map< size_t, FaceConnections >::const_iterator end() const
Definition Iotm_TextMeshAdjacencyGraph.h:273
std::pair< bool, PermutationType > get_permutation(const Topology &topology, const std::vector< EntityId > &controlNodes, const std::vector< EntityId > &permutedNodes)
Definition Iotm_TextMeshAdjacencyGraph.h:445
bool has_solid_shell_connection_on_side(size_t thisIndex, int thisSide)
Definition Iotm_TextMeshAdjacencyGraph.h:633
int64_t IndexType
Definition Iotm_TextMeshAdjacencyGraph.h:88
void dump(std::ostream &out=std::cout)
Definition Iotm_TextMeshAdjacencyGraph.h:223
void dump(const std::vector< ElementData< EntityId, Topology > > &elemDataVec, std::ostream &out=std::cout)
Definition Iotm_TextMeshAdjacencyGraph.h:237
std::vector< EntityId > get_side_nodes(const size_t elemIndex, const int side)
Definition Iotm_TextMeshAdjacencyGraph.h:335
bool verify_entry(IndexType elemIndex, int side)
Definition Iotm_TextMeshAdjacencyGraph.h:475
bool is_solid_shell_connection(const size_t thisElem, const size_t thatElem)
Definition Iotm_TextMeshAdjacencyGraph.h:568
static constexpr IndexType INVALID_INDEX
Definition Iotm_TextMeshAdjacencyGraph.h:92
std::unordered_map< size_t, FaceConnections >::const_iterator begin() const
Definition Iotm_TextMeshAdjacencyGraph.h:269
std::pair< bool, PermutationType > get_positive_permutation(const Topology &topology, const std::vector< EntityId > &controlNodes, const std::vector< EntityId > &permutedNodes)
Definition Iotm_TextMeshAdjacencyGraph.h:453
std::function< bool(const Topology &topo1, const Topology &topo2)> Criterion
Definition Iotm_TextMeshAdjacencyGraph.h:586
bool is_solid_shell_connection(const Topology &thisElemTopology, const Topology &thatElemTopology)
Definition Iotm_TextMeshAdjacencyGraph.h:562
void process_side_connectivity(CurrentAdjacency &adjacency, const std::unordered_map< EntityId, std::set< size_t > > &elementsForNode)
Definition Iotm_TextMeshAdjacencyGraph.h:718
bool has_shell_shell_connection_on_side(size_t thisIndex, int thisSide)
Definition Iotm_TextMeshAdjacencyGraph.h:615
virtual bool element_has_any_node_on_proc(const size_t elemIndex, int proc) const =0
std::unordered_map< size_t, FaceConnections > m_indexGraph
Definition Iotm_TextMeshAdjacencyGraph.h:819
bool has_shell_solid_connection_on_side(size_t thisIndex, int thisSide)
Definition Iotm_TextMeshAdjacencyGraph.h:624
bool is_solid_solid_connection(const size_t thisElem, const size_t thatElem)
Definition Iotm_TextMeshAdjacencyGraph.h:580
typename Topology::Permutation PermutationType
Definition Iotm_TextMeshAdjacencyGraph.h:280
virtual const std::vector< EntityId > & get_element_node_ids(const size_t elemIndex) const =0
static constexpr int ANY_PROC
Definition Iotm_TextMeshAdjacencyGraph.h:90
void set_side_connectivity(CurrentAdjacency &adjacency, size_t connectedElementIndex)
Definition Iotm_TextMeshAdjacencyGraph.h:691
bool has_connection_type_on_side(size_t thisIndex, int thisSide, Criterion criterion)
Definition Iotm_TextMeshAdjacencyGraph.h:588
void set_error_handler(ErrorHandler errorHandler)
Definition Iotm_TextMeshAdjacencyGraph.h:221
bool is_shell_shell_connection(const Topology &thisElemTopology, const Topology &thatElemTopology)
Definition Iotm_TextMeshAdjacencyGraph.h:538
bool is_solid_solid_connection(const Topology &thisElemTopology, const Topology &thatElemTopology)
Definition Iotm_TextMeshAdjacencyGraph.h:574
std::vector< EntityId > get_sorted_side_nodes(const size_t elemIndex, const int side)
Definition Iotm_TextMeshAdjacencyGraph.h:350
std::set< size_t > get_element_indices_with_common_nodes_on_side(const size_t elemIndex, int side, const std::unordered_map< EntityId, std::set< size_t > > &elementsForNode)
Definition Iotm_TextMeshAdjacencyGraph.h:304
SideAdjacencyGraph()
Definition Iotm_TextMeshAdjacencyGraph.h:199
std::function< void(const std::ostringstream &)> ErrorHandler
Definition Iotm_TextMeshAdjacencyGraph.h:35
void default_error_handler(const std::ostringstream &message)
Definition Iotm_TextMeshFuncs.h:32
A namespace for the textmesh database format.
Definition Iotm_DatabaseIO.C:95
int64_t EntityId
Definition Iotm_TextMesh.h:33
Definition Iotm_TextMeshDataTypes.h:277
Definition Iotm_TextMeshAdjacencyGraph.h:292
std::vector< int > connectedSides
Definition Iotm_TextMeshAdjacencyGraph.h:301
size_t elementIndex
Definition Iotm_TextMeshAdjacencyGraph.h:297
CurrentAdjacency(size_t elementIndex_, int side_)
Definition Iotm_TextMeshAdjacencyGraph.h:293
int side
Definition Iotm_TextMeshAdjacencyGraph.h:298
Definition Iotm_TextMeshAdjacencyGraph.h:95
bool operator==(const FaceConnection &rhs) const
Definition Iotm_TextMeshAdjacencyGraph.h:104
bool operator<(const FaceConnection &rhs) const
Definition Iotm_TextMeshAdjacencyGraph.h:116
bool operator!=(const FaceConnection &rhs) const
Definition Iotm_TextMeshAdjacencyGraph.h:110
int thisSide
Definition Iotm_TextMeshAdjacencyGraph.h:129
IndexType thatElement
Definition Iotm_TextMeshAdjacencyGraph.h:130
int thatSide
Definition Iotm_TextMeshAdjacencyGraph.h:131
FaceConnection()
Definition Iotm_TextMeshAdjacencyGraph.h:96
FaceConnection(int thisSide_, IndexType otherElement_, int otherSide_)
Definition Iotm_TextMeshAdjacencyGraph.h:99
Definition Iotm_TextMeshAdjacencyGraph.h:135
FaceConnections(unsigned numSides_)
Definition Iotm_TextMeshAdjacencyGraph.h:137
std::vector< int > sideReference
Definition Iotm_TextMeshAdjacencyGraph.h:184
bool has_any_connection(int thisSide, IndexType thatElem) const
Definition Iotm_TextMeshAdjacencyGraph.h:151
bool has_any_connection(int thisSide) const
Definition Iotm_TextMeshAdjacencyGraph.h:142
std::set< FaceConnection > connections
Definition Iotm_TextMeshAdjacencyGraph.h:188
FaceConnections()
Definition Iotm_TextMeshAdjacencyGraph.h:136
unsigned numSides
Definition Iotm_TextMeshAdjacencyGraph.h:180
void remove(const FaceConnection &connection)
Definition Iotm_TextMeshAdjacencyGraph.h:170
void add(const FaceConnection &connection)
Definition Iotm_TextMeshAdjacencyGraph.h:161
Definition Iotm_TextMeshAdjacencyGraph.h:283
bool operator()(const std::string &lhs, const std::string &rhs)
Definition Iotm_TextMeshAdjacencyGraph.h:284
Definition Iotm_TextMeshDataTypes.h:315