| 1 |
// Copyright 2002 - 2008, 2010, 2011 National Technology Engineering |
| 2 |
// Solutions of Sandia, LLC (NTESS). Under the terms of Contract |
| 3 |
// DE-NA0003525 with NTESS, the U.S. Government retains certain rights |
| 4 |
// in this software. |
| 5 |
// |
| 6 |
// Redistribution and use in source and binary forms, with or without |
| 7 |
// modification, are permitted provided that the following conditions are |
| 8 |
// met: |
| 9 |
// |
| 10 |
// * Redistributions of source code must retain the above copyright |
| 11 |
// notice, this list of conditions and the following disclaimer. |
| 12 |
// |
| 13 |
// * Redistributions in binary form must reproduce the above |
| 14 |
// copyright notice, this list of conditions and the following |
| 15 |
// disclaimer in the documentation and/or other materials provided |
| 16 |
// with the distribution. |
| 17 |
// |
| 18 |
// * Neither the name of NTESS nor the names of its contributors |
| 19 |
// may be used to endorse or promote products derived from this |
| 20 |
// software without specific prior written permission. |
| 21 |
// |
| 22 |
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 23 |
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 24 |
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 25 |
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 26 |
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 27 |
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 28 |
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 29 |
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 30 |
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 31 |
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 32 |
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 33 |
|
| 34 |
#ifndef elementgraphtester_hpp |
| 35 |
#define elementgraphtester_hpp |
| 36 |
|
| 37 |
#include <stddef.h> // for size_t |
| 38 |
#include <stk_mesh/base/BulkData.hpp> // for BulkData |
| 39 |
#include <stk_mesh/base/MetaData.hpp> // for MetaData |
| 40 |
#include <stk_topology/topology.hpp> // for topology, etc |
| 41 |
#include <stk_util/util/ReportHandler.hpp> // for ThrowRequire |
| 42 |
#include <vector> // for allocator, vector |
| 43 |
#include "stk_mesh/base/Bucket.hpp" // for Bucket |
| 44 |
#include "stk_mesh/base/Entity.hpp" // for Entity |
| 45 |
#include "stk_mesh/base/Selector.hpp" // for Selector |
| 46 |
#include "stk_mesh/base/Types.hpp" // for EntityId, EntityVector |
| 47 |
#include <stk_mesh/baseImpl/elementGraph/ElemElemGraph.hpp> // for ElemElemGraph |
| 48 |
#include <stk_mesh/baseImpl/elementGraph/ElemElemGraphImpl.hpp> |
| 49 |
namespace stk { namespace mesh { class Part; } } |
| 50 |
|
| 51 |
struct GraphEdgeMock |
| 52 |
{ |
| 53 |
stk::mesh::EntityId element1; |
| 54 |
stk::mesh::EntityId element2; |
| 55 |
int sideOrdinalConnectingElement1ToElement2; |
| 56 |
}; |
| 57 |
typedef std::vector<GraphEdgeMock> GraphEdges; |
| 58 |
|
| 59 |
|
| 60 |
class ElemElemGraphTester : public stk::mesh::ElemElemGraph |
| 61 |
{ |
| 62 |
public: |
| 63 |
ElemElemGraphTester(stk::mesh::BulkData& bulkData) : ElemElemGraph(bulkData) {} |
| 64 |
|
| 65 |
virtual ~ElemElemGraphTester() {} |
| 66 |
|
| 67 |
void fill_graph() { ElemElemGraph::fill_graph(); } |
| 68 |
|
| 69 |
void write_graph(const std::string& preamble) const { ElemElemGraph::write_graph(std::cout, preamble); } |
| 70 |
void write_graph(std::ostream& out) const { ElemElemGraph::write_graph(out); } |
| 71 |
|
| 72 |
stk::mesh::Graph & get_graph() { return m_graph; } |
| 73 |
stk::mesh::impl::ParallelGraphInfo & get_parallel_graph_info() { return m_parallelInfoForGraphEdges.get_parallel_graph_info(); } |
| 74 |
stk::mesh::ParallelInfoForGraphEdges& get_parallel_graph() { return m_parallelInfoForGraphEdges; } |
| 75 |
|
| 76 |
stk::mesh::BulkData & get_bulk_data() { return m_bulk_data; } |
| 77 |
size_t get_graph_size() { return m_graph.get_num_elements_in_graph(); } |
| 78 |
|
| 79 |
stk::mesh::EntityId get_entity_id(stk::mesh::impl::LocalId localId) |
| 80 |
{ |
| 81 |
stk::mesh::EntityId id = -localId; |
| 82 |
if(localId >= 0) |
| 83 |
id = get_bulk_data().identifier(m_idMapper.local_to_entity(localId)); |
| 84 |
return id; |
| 85 |
} |
| 86 |
|
| 87 |
int get_first_encountered_side_between_elems(stk::mesh::impl::LocalId elemId, stk::mesh::EntityId elem2Id) |
| 88 |
{ |
| 89 |
for(size_t i=0; i<m_graph.get_num_edges_for_element(elemId); i++) |
| 90 |
{ |
| 91 |
if(get_entity_id(m_graph.get_edge_for_element(elemId, i).elem2()) == elem2Id) |
| 92 |
{ |
| 93 |
return m_graph.get_edge_for_element(elemId, i).side1(); |
| 94 |
} |
| 95 |
} |
| 96 |
return -1; |
| 97 |
} |
| 98 |
|
| 99 |
int check_local_connectivity(stk::mesh::Entity elem1, stk::mesh::Entity elem2) |
| 100 |
{ |
| 101 |
int side=-1; |
| 102 |
if (is_valid_graph_element(elem1) && is_valid_graph_element(elem2)) { |
| 103 |
side = get_first_encountered_side_between_elems(get_local_element_id(elem1), get_bulk_data().identifier(elem2)); |
| 104 |
} |
| 105 |
return side; |
| 106 |
} |
| 107 |
|
| 108 |
int check_remote_connectivity(stk::mesh::Entity elem, stk::mesh::EntityId other_elem_id) |
| 109 |
{ |
| 110 |
int side=-1; |
| 111 |
if (is_valid_graph_element(elem)) { |
| 112 |
side = get_first_encountered_side_between_elems(get_local_element_id(elem), other_elem_id); |
| 113 |
} |
| 114 |
return side; |
| 115 |
} |
| 116 |
int get_side_from_element1_to_element2(stk::mesh::EntityId elem1_id, stk::mesh::EntityId elem2_id) |
| 117 |
{ |
| 118 |
int side = -1; |
| 119 |
stk::mesh::Entity elem1 = m_bulk_data.get_entity(stk::topology::ELEM_RANK, elem1_id); |
| 120 |
stk::mesh::Entity elem2 = m_bulk_data.get_entity(stk::topology::ELEM_RANK, elem2_id); |
| 121 |
bool isElem1Local = m_bulk_data.is_valid(elem1) && m_bulk_data.bucket(elem1).owned(); |
| 122 |
bool isElem2Local = m_bulk_data.is_valid(elem2) && m_bulk_data.bucket(elem2).owned(); |
| 123 |
|
| 124 |
STK_ThrowRequire(isElem1Local); |
| 125 |
|
| 126 |
if(isElem2Local) |
| 127 |
{ |
| 128 |
side = check_local_connectivity(elem1, elem2); |
| 129 |
} |
| 130 |
else |
| 131 |
{ |
| 132 |
side = check_remote_connectivity(elem1, elem2_id); |
| 133 |
} |
| 134 |
|
| 135 |
return side; |
| 136 |
} |
| 137 |
}; |
| 138 |
|
| 139 |
#endif |