Panzer Version of the Day
Loading...
Searching...
No Matches
Panzer_STK_CheckSidesetOverlap.cpp
Go to the documentation of this file.
1// @HEADER
2// ***********************************************************************
3//
4// Panzer: A partial differential equation assembly
5// engine for strongly coupled complex multiphysics systems
6// Copyright (2011) Sandia Corporation
7//
8// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9// the U.S. Government retains certain rights in this software.
10//
11// Redistribution and use in source and binary forms, with or without
12// modification, are permitted provided that the following conditions are
13// met:
14//
15// 1. Redistributions of source code must retain the above copyright
16// notice, this list of conditions and the following disclaimer.
17//
18// 2. Redistributions in binary form must reproduce the above copyright
19// notice, this list of conditions and the following disclaimer in the
20// documentation and/or other materials provided with the distribution.
21//
22// 3. Neither the name of the Corporation nor the names of the
23// contributors may be used to endorse or promote products derived from
24// this software without specific prior written permission.
25//
26// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37//
38// Questions? Contact Roger P. Pawlowski (rppawlo@sandia.gov) and
39// Eric C. Cyr (eccyr@sandia.gov)
40// ***********************************************************************
41// @HEADER
42
44#include <vector>
45#include <algorithm>
46
47namespace panzer_stk {
48
50 bool checkSidesetOverlap(const std::string& side_a_name,
51 const std::string& side_b_name,
52 const panzer_stk::STK_Interface& mesh) {
53
54 const bool print_debug = false;
55
56 // Get the locally owned nodes of sideset a
57 std::vector<stk::mesh::EntityId> gids_a;
58 {
59 std::vector<stk::mesh::Entity> nodes_a;
60 stk::mesh::Part* part_a = mesh.getSideset(side_a_name);
61 TEUCHOS_TEST_FOR_EXCEPTION(part_a==nullptr,std::runtime_error,
62 "panzer::checkSidesetOverlap: Unknown side set name \"" << side_a_name << "\"");
63 stk::mesh::Selector selector_a = *part_a & mesh.getMetaData()->locally_owned_part();
64 const bool sort_by_gid = true;
65 stk::mesh::get_selected_entities(selector_a,mesh.getBulkData()->buckets(mesh.getNodeRank()),nodes_a,sort_by_gid);
66 // convert the entities to global ids
67 gids_a.resize(nodes_a.size());
68 size_t i = 0;
69 for (auto&& node : nodes_a) {
70 gids_a[i] = mesh.getBulkData()->identifier(node);
71 ++i;
72 }
73 }
74
75 // Get all nodes of sideset b (including nodes from all mpi processes)
76 std::vector<stk::mesh::EntityId> gids_b;
77 {
78 std::vector<stk::mesh::Entity> nodes_b;
79 stk::mesh::Part* part_b = mesh.getSideset(side_b_name);
80 TEUCHOS_TEST_FOR_EXCEPTION(part_b==nullptr,std::runtime_error,
81 "panzer::checkSidesetOverlap: Unknown side set name \"" << side_b_name << "\"");
82 stk::mesh::Selector selector_b = *part_b;
83 const bool sort_by_gid = true;
84 stk::mesh::get_selected_entities(selector_b,mesh.getBulkData()->buckets(mesh.getNodeRank()),nodes_b,sort_by_gid);
85 // convert the entities to global ids
86 gids_b.resize(nodes_b.size());
87 size_t i = 0;
88 for (auto&& node : nodes_b) {
89 gids_b[i] = mesh.getBulkData()->identifier(node);
90 ++i;
91 }
92 }
93
94 // Sort the element gids so we can use binary search
95 std::sort(gids_b.begin(),gids_b.end());
96
97 if (print_debug) {
98 Teuchos::FancyOStream os(Teuchos::rcpFromRef(std::cout));
99 os.setShowProcRank(true);
100 os << std::endl;
101 os << "gids_a.size()=" << gids_a.size() << std::endl;
102 for (auto&& gid : gids_a)
103 os << "gid_a=" << gid << std::endl;
104 os << "gids_b.size()=" << gids_b.size() << std::endl;
105 for (auto&& gid : gids_b)
106 os << "gid_b=" << gid << std::endl;
107 }
108
109 // Search for each node in a in b
110 // 0 = no overlap, 1 = overlap
111 // We use int for MPI communication
112 int has_local_overlap = 0;
113 for (auto&& a : gids_a) {
114 if (std::binary_search(gids_b.begin(),gids_b.end(),a)) {
115 has_local_overlap = 1;
116 break;
117 }
118 }
119 int has_overlap = 0;
120 Teuchos::reduceAll(*mesh.getComm(),Teuchos::REDUCE_SUM,1,&has_local_overlap,&has_overlap);
121 if (has_overlap == 0)
122 return false;
123
124 return true;
125 }
126}
stk::mesh::EntityRank getNodeRank() const
Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
get the comm associated with this mesh
Teuchos::RCP< stk::mesh::MetaData > getMetaData() const
Teuchos::RCP< stk::mesh::BulkData > getBulkData() const
stk::mesh::Part * getSideset(const std::string &name) const
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.