11 #include "Teuchos_Tuple.hpp"
15 #include "PanzerAdaptersSTK_config.hpp"
18 #include "Teuchos_FancyOStream.hpp"
22 namespace panzer_stk {
23 namespace periodic_helpers {
25 template <
typename Matcher>
29 const Matcher & matcher,
30 const std::vector<std::pair<std::size_t,std::size_t> > & ownedToMapped,
const std::string type_)
54 std::pair<RCP<std::vector<std::size_t> >,
56 std::vector<std::size_t> & sideIds = *idsAndCoords.first;
57 std::vector<Tuple<double,3> > & sideCoords = *idsAndCoords.second;
67 }
catch(std::logic_error & e) {
68 locallyMatchedIds =
Teuchos::rcp(
new std::vector<std::pair<std::size_t,std::size_t> >);
75 out <<
"Not all sides matched expect failure: \n" << e.what() << std::endl;
88 std::map<std::size_t,std::vector<std::size_t> > reverseMap;
89 for(std::size_t i=0;i<ownedToMapped.size();i++)
90 reverseMap[ownedToMapped[i].second].push_back(ownedToMapped[i].first);
93 std::vector<std::size_t> saved_locallyRequiredIds = *locallyRequiredIds;
96 std::vector<std::pair<std::size_t,std::size_t> > unusedOwnedToMapped;
99 for(std::size_t i=0;i<ownedToMapped.size();i++) {
100 std::size_t owned = ownedToMapped[i].first;
101 std::size_t mapped = ownedToMapped[i].second;
103 std::vector<std::size_t>::iterator itr
104 = std::find(locallyRequiredIds->begin(),locallyRequiredIds->end(),owned);
108 if(itr!=locallyRequiredIds->end())
111 unusedOwnedToMapped.push_back(ownedToMapped[i]);
115 std::vector<std::size_t> unique_locallyRequiredIds;
117 std::set<std::size_t> s;
118 s.insert(locallyRequiredIds->begin(),locallyRequiredIds->end());
119 unique_locallyRequiredIds.insert(unique_locallyRequiredIds.begin(),s.begin(),s.end());
124 =
getGlobalPairing(unique_locallyRequiredIds,*locallyMatchedIds,mesh,failure);
133 std::set<std::pair<std::size_t,std::size_t> > gmi_set;
134 gmi_set.insert(globallyMatchedIds->begin(),globallyMatchedIds->end());
138 for(std::size_t i=0;i<globallyMatchedIds->size();i++) {
139 std::pair<std::size_t,std::size_t> pair = (*globallyMatchedIds)[i];
140 const std::vector<std::size_t> & others = reverseMap[pair.first];
144 for(std::size_t j=0;j<others.size();j++)
145 gmi_set.insert(std::make_pair(others[j],pair.second));
148 if(std::find(saved_locallyRequiredIds.begin(),
149 saved_locallyRequiredIds.end(),
150 pair.first)==saved_locallyRequiredIds.end()) {
156 globallyMatchedIds->clear();
157 globallyMatchedIds->insert(globallyMatchedIds->begin(),gmi_set.begin(),gmi_set.end());
162 globallyMatchedIds->insert(globallyMatchedIds->end(),unusedOwnedToMapped.begin(),unusedOwnedToMapped.end());
164 return globallyMatchedIds;
167 template <
typename Matcher>
171 const Matcher & matcher,
const std::string type_)
195 std::pair<RCP<std::vector<std::size_t> >,
197 std::vector<std::size_t> & sideIds = *idsAndCoords.first;
198 std::vector<Tuple<double,3> > & sideCoords = *idsAndCoords.second;
205 bool failure =
false;
208 }
catch(std::logic_error & e) {
209 locallyMatchedIds =
Teuchos::rcp(
new std::vector<std::pair<std::size_t,std::size_t> >);
216 out <<
"Not all sides matched expect failure: \n" << e.what() << std::endl;
232 return globallyMatchedIds;
235 template <
typename Matcher>
240 const std::string & sideName,
const Matcher & matcher, std::string type_)
246 =
Teuchos::rcp(
new std::vector<std::pair<std::size_t,std::size_t> >);
251 std::pair<Teuchos::RCP<std::vector<std::size_t> >,
255 std::vector<std::size_t> & local_side_ids = *sidePair.first;
256 std::vector<Teuchos::Tuple<double,3> > & local_side_coords = *sidePair.second;
258 bool checkProb =
false;
259 std::vector<bool> side_flags(side_ids.size(),
false);
264 for(std::size_t localNode=0;localNode<local_side_ids.size();localNode++) {
265 std::size_t local_gid = local_side_ids[localNode];
266 const Tuple<double,3> & local_coord = local_side_coords[localNode];
269 for(std::size_t globalNode=0;globalNode<side_ids.size();globalNode++) {
270 std::size_t global_gid = side_ids[globalNode];
271 const Tuple<double,3> & global_coord = side_coords[globalNode];
273 if(matcher(global_coord,local_coord)) {
274 if(side_flags[globalNode])
277 result->push_back(std::make_pair(global_gid,local_gid));
278 side_flags[globalNode] =
true;
287 "getLocallyMatchedSideIds: checkProb failed");
290 "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")