Panzer  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Panzer_STK_PeriodicBC_Matcher.hpp
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 
11 #ifndef __Panzer_STK_PeriodicBC_Matcher_hpp__
12 #define __Panzer_STK_PeriodicBC_Matcher_hpp__
13 
14 #include "Teuchos_Tuple.hpp"
15 #include "Teuchos_RCP.hpp"
16 
17 #include "Panzer_STK_Version.hpp"
18 #include "PanzerAdaptersSTK_config.hpp"
19 #include "Panzer_STK_Interface.hpp"
20 
21 #ifdef PANZER_HAVE_STKSEARCH
22 #include "stk_search/CoarseSearch.hpp"
23 #endif
24 
25 namespace panzer_stk {
26 
31 namespace periodic_helpers {
32 
33 #ifdef PANZER_HAVE_STKSEARCH
34  // Copied from PeriodicBoundarySearch
35  typedef stk::search::IdentProc<stk::mesh::EntityKey> SearchId;
36  typedef stk::search::Sphere<double> Sphere;
37  typedef std::vector< std::pair<Sphere,SearchId> > SphereIdVector;
38  typedef std::vector<std::pair<SearchId,SearchId> > SearchPairVector;
39  typedef std::vector<std::pair<stk::mesh::EntityKey,stk::mesh::EntityKey> > SearchPairSet;
40 #endif
41 
46  template <typename Matcher>
48  matchPeriodicSides(const std::string & left,const std::string & right,
49  const STK_Interface & mesh,
50  const Matcher & matcher, const std::string type_ = "coord");
51 
52  template <typename Matcher>
54  matchPeriodicSides(const std::string & left,const std::string & right,
55  const STK_Interface & mesh,
56  const Matcher & matcher,
57  const std::vector<std::pair<std::size_t,std::size_t> > & current, const std::string type_ = "coord");
58 
62  std::pair<Teuchos::RCP<std::vector<std::size_t> >,
64  getSideIdsAndCoords(const STK_Interface & mesh,
65  const std::string & sideName, const std::string type_ = "coord");
66 
70  std::pair<Teuchos::RCP<std::vector<std::size_t> >,
72  getLocalSideIdsAndCoords(const STK_Interface & mesh,
73  const std::string & sideName, const std::string type_ = "coord");
74 
79  getLocalSideIds(const STK_Interface & mesh,
80  const std::string & sideName, const std::string type_ = "coord");
81 
86  template <typename Matcher>
88  getLocallyMatchedSideIds(const std::vector<std::size_t> & side_ids,
89  const std::vector<Teuchos::Tuple<double,3> > & side_coords,
90  const STK_Interface & mesh,
91  const std::string & sideName,const Matcher & matcher, const std::string type_ = "coord");
92 
103  getGlobalPairing(const std::vector<std::size_t> & locallyRequiredIds,
104  const std::vector<std::pair<std::size_t,std::size_t> > & locallyMatchedIds,
105  const STK_Interface & mesh,bool failure);
106 
107 #ifdef PANZER_HAVE_STKSEARCH
108 
122  void fillLocalSearchVector(const STK_Interface & mesh, SphereIdVector & searchVector, const double & error,
123  const std::string & sideName, const std::string & type_, const bool & getGhostedIDs,
124  const std::vector<std::string> & matchedSides, std::vector<SearchId> & potentialIDsToRemap);
125 
126  void fillLocalSearchVector(const STK_Interface & mesh, SphereIdVector & searchVector, const double & error,
127  const std::string & sideName, const std::string & type_, const bool & getGhostedIDs = false);
128 
135  const std::vector<double> computeGlobalCentroid(const STK_Interface & mesh, const std::string & sideName);
136 
143  template<typename Matcher> void
144  transformLocalSearchVector(SphereIdVector & searchVectorSideA, const Matcher & matcher, const std::vector<double> & centroidSideB );
145 
160  template <typename Matcher>
162  matchPeriodicSidesSearch(const std::string & sideA,const std::string & sideB,
163  const STK_Interface & mesh,
164  const Matcher & matcher, const std::vector<std::string> & matchedSides,
165  const std::vector<std::pair<size_t,size_t> > & previousMatches,
166  const std::string type_ = "coord");
167 
168  template <typename Matcher>
170  matchPeriodicSidesSearch(const std::string & sideA, const std::string & sideB,
171  const STK_Interface & mesh,
172  const Matcher & matcher, const std::string type_ = "coord");
173 
183  void updateMapping(Teuchos::RCP<std::vector<std::pair<size_t,size_t> > > & currentMatches,
184  const std::vector<std::pair<size_t,size_t> > & previousMatches,
185  const std::vector<SearchId> & IDsToRemap, const STK_Interface & mesh);
186 
194  void appendMapping(Teuchos::RCP<std::vector<std::pair<size_t,size_t> > > & currentMatches,
195  const std::vector<std::pair<size_t,size_t> > & previousMatches);
196 #endif
197 } // end periodic_helpers
198 
208 public:
210 
221  virtual
223  getMatchedPair(const STK_Interface & mesh,
224  const Teuchos::RCP<const std::vector<std::pair<std::size_t,std::size_t> > > & currentState = Teuchos::null
225  ) const = 0;
226 
227 #ifdef PANZER_HAVE_STKSEARCH
228 
244  virtual
246  getMatchedPair(const STK_Interface & mesh, const std::vector<std::string> & matchedSides,
247  const Teuchos::RCP<const std::vector<std::pair<std::size_t,std::size_t> > > & currentState = Teuchos::null
248  ) const = 0;
249 #endif
250 
254  virtual std::string getString() const = 0;
255 
259  virtual std::string getType() const = 0;
260 
262  virtual std::string getLeftSidesetName() const = 0;
263 
265  virtual std::string getRightSidesetName() const = 0;
266 
268  template<typename T>
269  const T* getAs() const {return dynamic_cast<const T*>(this);}
270 };
271 
277 template <typename Matcher>
279 public:
280  PeriodicBC_Matcher(const std::string & left, const std::string & right,const Matcher & matcher, const std::string type = "coord")
281  : left_(left), right_(right), matcher_(matcher), type_(type) {}
283  : left_(src.left_), right_(src.right_), matcher_(src.matcher_), type_(src.type_) {}
284 
297  const Teuchos::RCP<const std::vector<std::pair<std::size_t,std::size_t> > > & currentState = Teuchos::null
298  ) const
299  {
300  if(currentState==Teuchos::null)
302  else
303  return periodic_helpers::matchPeriodicSides(left_,right_,mesh,matcher_,*currentState,type_);
304  }
305 
306 #ifdef PANZER_HAVE_STKSEARCH
307 
324  getMatchedPair(const STK_Interface & mesh, const std::vector<std::string> & matchedSides,
325  const Teuchos::RCP<const std::vector<std::pair<std::size_t,std::size_t> > > & currentState = Teuchos::null
326  ) const
327  {
328  if(currentState==Teuchos::null)
330  else
331  return periodic_helpers::matchPeriodicSidesSearch(left_,right_,mesh,matcher_,matchedSides,*currentState,type_);
332  }
333 #endif
334 
335  std::string getString() const
336  {
337  std::stringstream ss;
338  ss << "condition: " << matcher_.getString() << ", sides = [ "
339  << "\"" << left_ << "\", "
340  << "\"" << right_ << "\" ]";
341  return ss.str();
342  }
343 
344  std::string getType() const
345  {return type_;}
346 
347  std::string getLeftSidesetName() const
348  {return left_;}
349 
350  std::string getRightSidesetName() const
351  {return right_;}
352 
353  const Matcher& getMatcher() const
354  {return matcher_;}
355 
356 private:
357  PeriodicBC_Matcher(); // hidden!
358 
359  std::string left_; // here left & right are stand in names just so
360  std::string right_; // that we realize that these boundaries are
361  // opposite of each other.
362  Matcher matcher_;
363 
364  std::string type_; // type of periodic BC: coord, edge, face
365 
366 };
367 
372 template <typename Matcher>
374 buildPeriodicBC_Matcher(const std::string & left, const std::string & right, const Matcher & matcher, const std::string type = "coord")
375 { return Teuchos::rcp(new PeriodicBC_Matcher<Matcher>(left,right,matcher,type)); }
376 
377 } // end panzer_stk
378 
380 
381 #ifdef PANZER_HAVE_STKSEARCH
383 #endif
384 
385 #endif
PeriodicBC_Matcher(const std::string &left, const std::string &right, const Matcher &matcher, const std::string type="coord")
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")
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_)
virtual std::string getString() const =0
void transformLocalSearchVector(SphereIdVector &searchVectorSideA, const Matcher &matcher, const std::vector< double > &centroidSideB)
PeriodicBC_Matcher(const PeriodicBC_Matcher &src)
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_)
std::string getLeftSidesetName() const
Returns the sideset name for the left side.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
virtual std::string getLeftSidesetName() const =0
Returns the sideset name for the left side.
Teuchos::RCP< PeriodicBC_MatcherBase > buildPeriodicBC_Matcher(const std::string &left, const std::string &right, const Matcher &matcher, const std::string type="coord")
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)
virtual std::string getRightSidesetName() const =0
Returns the sideset name for the right side.
Teuchos::RCP< std::vector< std::pair< std::size_t, std::size_t > > > getMatchedPair(const STK_Interface &mesh, const Teuchos::RCP< const std::vector< std::pair< std::size_t, std::size_t > > > &currentState=Teuchos::null) const
virtual std::string getType() const =0
virtual Teuchos::RCP< std::vector< std::pair< std::size_t, std::size_t > > > getMatchedPair(const STK_Interface &mesh, const Teuchos::RCP< const std::vector< std::pair< std::size_t, std::size_t > > > &currentState=Teuchos::null) const =0
std::string getRightSidesetName() const
Returns the sideset name for the right side.
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")
const T * getAs() const
Attempts to cast the underlying matcher to type T. Returns nullptr if cast fails. ...