Panzer Version of the Day
Loading...
Searching...
No Matches
Panzer_STK_PeriodicBC_Search_impl.hpp
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
43#include "Teuchos_Tuple.hpp"
44#include "Teuchos_RCP.hpp"
45
47#include "PanzerAdaptersSTK_config.hpp"
49
50#include "Teuchos_FancyOStream.hpp"
51
52#include <set>
53
54namespace panzer_stk {
55namespace periodic_helpers {
56
57template <typename Matcher>
58Teuchos::RCP<std::vector<std::pair<size_t,size_t> > >
59matchPeriodicSidesSearch(const std::string & sideA,const std::string & sideB,
60 const STK_Interface & mesh,
61 const Matcher & matcher, const std::string type_)
62{
63
64 // this function should be called the first time a match is made
65 // we create a few empty objects for the previous mapping
66
67 std::vector<std::string> matchedSides;
68 std::vector<std::pair<size_t,size_t> > previousMatches;
69
70 // then pass along
71
72 return matchPeriodicSidesSearch(sideA,sideB,mesh,matcher,matchedSides,previousMatches,type_);
73
74}
75
76
77template <typename Matcher>
78Teuchos::RCP<std::vector<std::pair<size_t,size_t> > >
79matchPeriodicSidesSearch(const std::string & sideA,const std::string & sideB,
80 const STK_Interface & mesh,
81 const Matcher & matcher, const std::vector<std::string> & matchedSides,
82 const std::vector<std::pair<size_t,size_t> > & previousMatches,
83 const std::string type_)
84{
85 using Teuchos::Tuple;
86 using Teuchos::RCP;
87 using Teuchos::rcp;
88
89 auto myRank = mesh.getBulkData()->parallel_rank();
90
91 SphereIdVector coordsIdsA, coordsIdsB;
92 std::vector<SearchId> IDsToRemap;
93
94 // populate the search vectors with the node coordinates and ids
95 // we will always search for ghosted IDs and repeats only on side A
96
97 auto error = matcher.getAbsoluteTolerance();
98
99 fillLocalSearchVector(mesh,coordsIdsA,error,sideA,type_,true,matchedSides,IDsToRemap);
100 fillLocalSearchVector(mesh,coordsIdsB,error,sideB,type_,false);
101
102 // apply the matcher transform to side B to effectively align the periodic entities
103 // to do so we need the centroid of the other side
104
105 // requires communication
106 std::vector<double> centroidA = computeGlobalCentroid(mesh,sideA);
107
108 // now transform
109 transformLocalSearchVector(coordsIdsB,matcher,centroidA);
110
111 // now we find the matches
112 SearchPairVector results;
113 stk::search::coarse_search(coordsIdsA,coordsIdsB,stk::search::KDTREE,mesh.getBulkData()->parallel(),results);
114
115 // the results are pairs of matched A and B entity keys
116 // if my process has a match, it will be stored
117 // hence, we only keep the results if the A key proc matches our rank
118 // so each process has a map myAIDs --> BIDs
119
120 // we store this A to B map, adding it to the pre-existing
121 // map of local periodic nodes to their matches, if necessary
122 // note the ids have been adjusted for entity type already
123 Teuchos::RCP<std::vector<std::pair<size_t,size_t> > > myMap
124 = Teuchos::rcp(new std::vector<std::pair<size_t,size_t>>());
125
126 for (size_t i=0; i<results.size(); ++i) {
127 if (results[i].first.proc() == myRank) {
128 // first id grabs the entity key which has another id and the entity rank
129 (*myMap).emplace_back(
130 std::pair<size_t,size_t>(results[i].first.id().id(),results[i].second.id().id()) );
131 }
132 }
133
134 TEUCHOS_TEST_FOR_EXCEPTION((*myMap).size()!=coordsIdsA.size(),std::logic_error,
135 "matchPeriodicSidesSearch: error in local match. "
136 "Number of matched IDs not equal to number of requested matches!");
137
138 if (matchedSides.size()>0) {
139 // guaranteed to have previous matches and they are of the same entity type
140 // in this case we need to handle multiperiodicity
141 updateMapping(myMap,previousMatches,IDsToRemap,mesh);
142 } else if (previousMatches.size()>0) {
143 // we have previous matches, but they are of a different entity type
144 // in this case we just append the previous matches unaltered
145 appendMapping(myMap,previousMatches);
146 }
147
148 return myMap;
149
150}
151
152template<typename Matcher> void
153transformLocalSearchVector( SphereIdVector & searchVectorSideA, const Matcher & matcher, const std::vector<double> & centroidSideB)
154{
155
156 // loop over sphereIds objects and shift center according to the matcher's periodic transform
157
158 for (auto && sphereIdSideA : searchVectorSideA )
159 matcher.transform(&sphereIdSideA.first.center()[0],centroidSideB);
160
161 return;
162}
163
164} // end periodic_helpers
165} // end panzer_stk
Teuchos::RCP< stk::mesh::BulkData > getBulkData() const
Teuchos::RCP< std::vector< std::pair< size_t, size_t > > > matchPeriodicSidesSearch(const std::string &sideA, const std::string &sideB, const STK_Interface &mesh, const Matcher &matcher, const std::string type_)
void transformLocalSearchVector(SphereIdVector &searchVectorSideA, const Matcher &matcher, const std::vector< double > &centroidSideB)