43 #include "Teuchos_Tuple.hpp"
47 #include "PanzerAdaptersSTK_config.hpp"
50 #include "Teuchos_FancyOStream.hpp"
54 namespace panzer_stk {
55 namespace periodic_helpers {
57 template <
typename Matcher>
61 const Matcher & matcher,
62 const std::vector<std::pair<std::size_t,std::size_t> > & ownedToMapped,
const std::string type_)
86 std::pair<RCP<std::vector<std::size_t> >,
88 std::vector<std::size_t> & sideIds = *idsAndCoords.first;
89 std::vector<Tuple<double,3> > & sideCoords = *idsAndCoords.second;
99 }
catch(std::logic_error & e) {
100 locallyMatchedIds =
Teuchos::rcp(
new std::vector<std::pair<std::size_t,std::size_t> >);
107 out <<
"Not all sides matched expect failure: \n" << e.what() << std::endl;
120 std::map<std::size_t,std::vector<std::size_t> > reverseMap;
121 for(std::size_t i=0;i<ownedToMapped.size();i++)
122 reverseMap[ownedToMapped[i].second].push_back(ownedToMapped[i].first);
125 std::vector<std::size_t> saved_locallyRequiredIds = *locallyRequiredIds;
128 std::vector<std::pair<std::size_t,std::size_t> > unusedOwnedToMapped;
131 for(std::size_t i=0;i<ownedToMapped.size();i++) {
132 std::size_t owned = ownedToMapped[i].first;
133 std::size_t mapped = ownedToMapped[i].second;
135 std::vector<std::size_t>::iterator itr
136 = std::find(locallyRequiredIds->begin(),locallyRequiredIds->end(),owned);
140 if(itr!=locallyRequiredIds->end())
143 unusedOwnedToMapped.push_back(ownedToMapped[i]);
147 std::vector<std::size_t> unique_locallyRequiredIds;
149 std::set<std::size_t> s;
150 s.insert(locallyRequiredIds->begin(),locallyRequiredIds->end());
151 unique_locallyRequiredIds.insert(unique_locallyRequiredIds.begin(),s.begin(),s.end());
156 =
getGlobalPairing(unique_locallyRequiredIds,*locallyMatchedIds,mesh,failure);
165 std::set<std::pair<std::size_t,std::size_t> > gmi_set;
166 gmi_set.insert(globallyMatchedIds->begin(),globallyMatchedIds->end());
170 for(std::size_t i=0;i<globallyMatchedIds->size();i++) {
171 std::pair<std::size_t,std::size_t> pair = (*globallyMatchedIds)[i];
172 const std::vector<std::size_t> & others = reverseMap[pair.first];
176 for(std::size_t j=0;j<others.size();j++)
177 gmi_set.insert(std::make_pair(others[j],pair.second));
180 if(std::find(saved_locallyRequiredIds.begin(),
181 saved_locallyRequiredIds.end(),
182 pair.first)==saved_locallyRequiredIds.end()) {
188 globallyMatchedIds->clear();
189 globallyMatchedIds->insert(globallyMatchedIds->begin(),gmi_set.begin(),gmi_set.end());
194 globallyMatchedIds->insert(globallyMatchedIds->end(),unusedOwnedToMapped.begin(),unusedOwnedToMapped.end());
196 return globallyMatchedIds;
199 template <
typename Matcher>
203 const Matcher & matcher,
const std::string type_)
227 std::pair<RCP<std::vector<std::size_t> >,
229 std::vector<std::size_t> & sideIds = *idsAndCoords.first;
230 std::vector<Tuple<double,3> > & sideCoords = *idsAndCoords.second;
237 bool failure =
false;
240 }
catch(std::logic_error & e) {
241 locallyMatchedIds =
Teuchos::rcp(
new std::vector<std::pair<std::size_t,std::size_t> >);
248 out <<
"Not all sides matched expect failure: \n" << e.what() << std::endl;
264 return globallyMatchedIds;
267 template <
typename Matcher>
272 const std::string & sideName,
const Matcher & matcher, std::string type_)
278 =
Teuchos::rcp(
new std::vector<std::pair<std::size_t,std::size_t> >);
283 std::pair<Teuchos::RCP<std::vector<std::size_t> >,
287 std::vector<std::size_t> & local_side_ids = *sidePair.first;
288 std::vector<Teuchos::Tuple<double,3> > & local_side_coords = *sidePair.second;
290 bool checkProb =
false;
291 std::vector<bool> side_flags(side_ids.size(),
false);
296 for(std::size_t localNode=0;localNode<local_side_ids.size();localNode++) {
297 std::size_t local_gid = local_side_ids[localNode];
298 const Tuple<double,3> & local_coord = local_side_coords[localNode];
301 for(std::size_t globalNode=0;globalNode<side_ids.size();globalNode++) {
302 std::size_t global_gid = side_ids[globalNode];
303 const Tuple<double,3> & global_coord = side_coords[globalNode];
305 if(matcher(global_coord,local_coord)) {
306 if(side_flags[globalNode])
309 result->push_back(std::make_pair(global_gid,local_gid));
310 side_flags[globalNode] =
true;
319 "getLocallyMatchedSideIds: checkProb failed");
322 "getLocallyMatchedSideIds: not all local side ids are satisfied!");
Teuchos::RCP< std::vector< std::size_t > > getLocalSideIds(const STK_Interface &mesh, const std::string &sideName, const std::string type_)
Teuchos::RCP< std::vector< std::pair< std::size_t, std::size_t > > > matchPeriodicSides(const std::string &left, const std::string &right, const STK_Interface &mesh, const Matcher &matcher, const std::string type_="coord")
basic_FancyOStream & setShowProcRank(const bool showProcRank)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
std::pair< Teuchos::RCP< std::vector< std::size_t > >, Teuchos::RCP< std::vector< Teuchos::Tuple< double, 3 > > > > getLocalSideIdsAndCoords(const STK_Interface &mesh, const std::string &sideName, const std::string type_)
PHX::MDField< ScalarT, panzer::Cell, panzer::IP > result
A field that will be used to build up the result of the integral we're performing.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
basic_FancyOStream & setOutputToRootOnly(const int rootRank)
Teuchos::RCP< std::vector< std::pair< std::size_t, std::size_t > > > getGlobalPairing(const std::vector< std::size_t > &locallyRequiredIds, const std::vector< std::pair< std::size_t, std::size_t > > &locallyMatchedIds, const STK_Interface &mesh, bool failure)
std::pair< Teuchos::RCP< std::vector< std::size_t > >, Teuchos::RCP< std::vector< Teuchos::Tuple< double, 3 > > > > getSideIdsAndCoords(const STK_Interface &mesh, const std::string &sideName, const std::string type_)
Teuchos::RCP< std::vector< std::pair< std::size_t, std::size_t > > > getLocallyMatchedSideIds(const std::vector< std::size_t > &side_ids, const std::vector< Teuchos::Tuple< double, 3 > > &side_coords, const STK_Interface &mesh, const std::string &sideName, const Matcher &matcher, const std::string type_="coord")