Panzer  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Panzer_STK_CheckSidesetOverlap.cpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Panzer: A partial differential equation assembly
4 // engine for strongly coupled complex multiphysics systems
5 //
6 // Copyright 2011 NTESS and the Panzer contributors.
7 // SPDX-License-Identifier: BSD-3-Clause
8 // *****************************************************************************
9 // @HEADER
10 
12 #include <vector>
13 #include <algorithm>
14 
15 namespace panzer_stk {
16 
18  bool checkSidesetOverlap(const std::string& side_a_name,
19  const std::string& side_b_name,
20  const panzer_stk::STK_Interface& mesh) {
21 
22  const bool print_debug = false;
23 
24  // Get the locally owned nodes of sideset a
25  std::vector<stk::mesh::EntityId> gids_a;
26  {
27  std::vector<stk::mesh::Entity> nodes_a;
28  stk::mesh::Part* part_a = mesh.getSideset(side_a_name);
29  TEUCHOS_TEST_FOR_EXCEPTION(part_a==nullptr,std::runtime_error,
30  "panzer::checkSidesetOverlap: Unknown side set name \"" << side_a_name << "\"");
31  stk::mesh::Selector selector_a = *part_a & mesh.getMetaData()->locally_owned_part();
32  const bool sort_by_gid = true;
33  stk::mesh::get_selected_entities(selector_a,mesh.getBulkData()->buckets(mesh.getNodeRank()),nodes_a,sort_by_gid);
34  // convert the entities to global ids
35  gids_a.resize(nodes_a.size());
36  size_t i = 0;
37  for (auto&& node : nodes_a) {
38  gids_a[i] = mesh.getBulkData()->identifier(node);
39  ++i;
40  }
41  }
42 
43  // Get all nodes of sideset b (including nodes from all mpi processes)
44  std::vector<stk::mesh::EntityId> gids_b;
45  {
46  std::vector<stk::mesh::Entity> nodes_b;
47  stk::mesh::Part* part_b = mesh.getSideset(side_b_name);
48  TEUCHOS_TEST_FOR_EXCEPTION(part_b==nullptr,std::runtime_error,
49  "panzer::checkSidesetOverlap: Unknown side set name \"" << side_b_name << "\"");
50  stk::mesh::Selector selector_b = *part_b;
51  const bool sort_by_gid = true;
52  stk::mesh::get_selected_entities(selector_b,mesh.getBulkData()->buckets(mesh.getNodeRank()),nodes_b,sort_by_gid);
53  // convert the entities to global ids
54  gids_b.resize(nodes_b.size());
55  size_t i = 0;
56  for (auto&& node : nodes_b) {
57  gids_b[i] = mesh.getBulkData()->identifier(node);
58  ++i;
59  }
60  }
61 
62  // Sort the element gids so we can use binary search
63  std::sort(gids_b.begin(),gids_b.end());
64 
65  if (print_debug) {
66  Teuchos::FancyOStream os(Teuchos::rcpFromRef(std::cout));
67  os.setShowProcRank(true);
68  os << std::endl;
69  os << "gids_a.size()=" << gids_a.size() << std::endl;
70  for (auto&& gid : gids_a)
71  os << "gid_a=" << gid << std::endl;
72  os << "gids_b.size()=" << gids_b.size() << std::endl;
73  for (auto&& gid : gids_b)
74  os << "gid_b=" << gid << std::endl;
75  }
76 
77  // Search for each node in a in b
78  // 0 = no overlap, 1 = overlap
79  // We use int for MPI communication
80  int has_local_overlap = 0;
81  for (auto&& a : gids_a) {
82  if (std::binary_search(gids_b.begin(),gids_b.end(),a)) {
83  has_local_overlap = 1;
84  break;
85  }
86  }
87  int has_overlap = 0;
88  Teuchos::reduceAll(*mesh.getComm(),Teuchos::REDUCE_SUM,1,&has_local_overlap,&has_overlap);
89  if (has_overlap == 0)
90  return false;
91 
92  return true;
93  }
94 }
bool checkSidesetOverlap(const std::string &side_a_name, const std::string &side_b_name, const panzer_stk::STK_Interface &mesh)
Returns true if the sidesets overlap.
basic_FancyOStream & setShowProcRank(const bool showProcRank)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
stk::mesh::Part * getSideset(const std::string &name) const
Teuchos::RCP< stk::mesh::BulkData > getBulkData() const
Teuchos::RCP< stk::mesh::MetaData > getMetaData() const
Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
get the comm associated with this mesh
stk::mesh::EntityRank getNodeRank() const