Panzer Version of the Day
Loading...
Searching...
No Matches
Panzer_STK_PeriodicBC_Matcher.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#ifndef __Panzer_STK_PeriodicBC_Matcher_hpp__
44#define __Panzer_STK_PeriodicBC_Matcher_hpp__
45
46#include "Teuchos_Tuple.hpp"
47#include "Teuchos_RCP.hpp"
48
50#include "PanzerAdaptersSTK_config.hpp"
52
53#ifdef PANZER_HAVE_STKSEARCH
54#include "stk_search/CoarseSearch.hpp"
55#endif
56
57namespace panzer_stk {
58
63namespace periodic_helpers {
64
65#ifdef PANZER_HAVE_STKSEARCH
66 // Copied from PeriodicBoundarySearch
67 typedef stk::search::IdentProc<stk::mesh::EntityKey> SearchId;
68 typedef stk::search::Sphere<double> Sphere;
69 typedef std::vector< std::pair<Sphere,SearchId> > SphereIdVector;
70 typedef std::vector<std::pair<SearchId,SearchId> > SearchPairVector;
71 typedef std::vector<std::pair<stk::mesh::EntityKey,stk::mesh::EntityKey> > SearchPairSet;
72#endif
73
78 template <typename Matcher>
79 Teuchos::RCP<std::vector<std::pair<std::size_t,std::size_t> > >
80 matchPeriodicSides(const std::string & left,const std::string & right,
81 const STK_Interface & mesh,
82 const Matcher & matcher, const std::string type_ = "coord");
83
84 template <typename Matcher>
85 Teuchos::RCP<std::vector<std::pair<std::size_t,std::size_t> > >
86 matchPeriodicSides(const std::string & left,const std::string & right,
87 const STK_Interface & mesh,
88 const Matcher & matcher,
89 const std::vector<std::pair<std::size_t,std::size_t> > & current, const std::string type_ = "coord");
90
94 std::pair<Teuchos::RCP<std::vector<std::size_t> >,
95 Teuchos::RCP<std::vector<Teuchos::Tuple<double,3> > > >
96 getSideIdsAndCoords(const STK_Interface & mesh,
97 const std::string & sideName, const std::string type_ = "coord");
98
102 std::pair<Teuchos::RCP<std::vector<std::size_t> >,
103 Teuchos::RCP<std::vector<Teuchos::Tuple<double,3> > > >
104 getLocalSideIdsAndCoords(const STK_Interface & mesh,
105 const std::string & sideName, const std::string type_ = "coord");
106
110 Teuchos::RCP<std::vector<std::size_t> >
111 getLocalSideIds(const STK_Interface & mesh,
112 const std::string & sideName, const std::string type_ = "coord");
113
118 template <typename Matcher>
119 Teuchos::RCP<std::vector<std::pair<std::size_t,std::size_t> > >
120 getLocallyMatchedSideIds(const std::vector<std::size_t> & side_ids,
121 const std::vector<Teuchos::Tuple<double,3> > & side_coords,
122 const STK_Interface & mesh,
123 const std::string & sideName,const Matcher & matcher, const std::string type_ = "coord");
124
134 Teuchos::RCP<std::vector<std::pair<std::size_t,std::size_t> > >
135 getGlobalPairing(const std::vector<std::size_t> & locallyRequiredIds,
136 const std::vector<std::pair<std::size_t,std::size_t> > & locallyMatchedIds,
137 const STK_Interface & mesh,bool failure);
138
139#ifdef PANZER_HAVE_STKSEARCH
154 void fillLocalSearchVector(const STK_Interface & mesh, SphereIdVector & searchVector, const double & error,
155 const std::string & sideName, const std::string & type_, const bool & getGhostedIDs,
156 const std::vector<std::string> & matchedSides, std::vector<SearchId> & potentialIDsToRemap);
157
158 void fillLocalSearchVector(const STK_Interface & mesh, SphereIdVector & searchVector, const double & error,
159 const std::string & sideName, const std::string & type_, const bool & getGhostedIDs = false);
160
167 const std::vector<double> computeGlobalCentroid(const STK_Interface & mesh, const std::string & sideName);
168
175 template<typename Matcher> void
176 transformLocalSearchVector(SphereIdVector & searchVectorSideA, const Matcher & matcher, const std::vector<double> & centroidSideB );
177
192 template <typename Matcher>
193 Teuchos::RCP<std::vector<std::pair<size_t,size_t> > >
194 matchPeriodicSidesSearch(const std::string & sideA,const std::string & sideB,
195 const STK_Interface & mesh,
196 const Matcher & matcher, const std::vector<std::string> & matchedSides,
197 const std::vector<std::pair<size_t,size_t> > & previousMatches,
198 const std::string type_ = "coord");
199
200 template <typename Matcher>
201 Teuchos::RCP<std::vector<std::pair<size_t,size_t> > >
202 matchPeriodicSidesSearch(const std::string & sideA, const std::string & sideB,
203 const STK_Interface & mesh,
204 const Matcher & matcher, const std::string type_ = "coord");
205
215 void updateMapping(Teuchos::RCP<std::vector<std::pair<size_t,size_t> > > & currentMatches,
216 const std::vector<std::pair<size_t,size_t> > & previousMatches,
217 const std::vector<SearchId> & IDsToRemap, const STK_Interface & mesh);
218
226 void appendMapping(Teuchos::RCP<std::vector<std::pair<size_t,size_t> > > & currentMatches,
227 const std::vector<std::pair<size_t,size_t> > & previousMatches);
228#endif
229} // end periodic_helpers
230
240public:
242
253 virtual
254 Teuchos::RCP<std::vector<std::pair<std::size_t,std::size_t> > >
256 const Teuchos::RCP<const std::vector<std::pair<std::size_t,std::size_t> > > & currentState = Teuchos::null
257 ) const = 0;
258
259#ifdef PANZER_HAVE_STKSEARCH
276 virtual
277 Teuchos::RCP<std::vector<std::pair<std::size_t,std::size_t> > >
278 getMatchedPair(const STK_Interface & mesh, const std::vector<std::string> & matchedSides,
279 const Teuchos::RCP<const std::vector<std::pair<std::size_t,std::size_t> > > & currentState = Teuchos::null
280 ) const = 0;
281#endif
282
286 virtual std::string getString() const = 0;
287
291 virtual std::string getType() const = 0;
292
294 virtual std::string getLeftSidesetName() const = 0;
295
297 virtual std::string getRightSidesetName() const = 0;
298
300 template<typename T>
301 const T* getAs() const {return dynamic_cast<const T*>(this);}
302};
303
309template <typename Matcher>
311public:
312 PeriodicBC_Matcher(const std::string & left, const std::string & right,const Matcher & matcher, const std::string type = "coord")
313 : left_(left), right_(right), matcher_(matcher), type_(type) {}
316
327 Teuchos::RCP<std::vector<std::pair<std::size_t,std::size_t> > >
329 const Teuchos::RCP<const std::vector<std::pair<std::size_t,std::size_t> > > & currentState = Teuchos::null
330 ) const
331 {
332 if(currentState==Teuchos::null)
334 else
336 }
337
338#ifdef PANZER_HAVE_STKSEARCH
355 Teuchos::RCP<std::vector<std::pair<std::size_t,std::size_t> > >
356 getMatchedPair(const STK_Interface & mesh, const std::vector<std::string> & matchedSides,
357 const Teuchos::RCP<const std::vector<std::pair<std::size_t,std::size_t> > > & currentState = Teuchos::null
358 ) const
359 {
360 if(currentState==Teuchos::null)
362 else
363 return periodic_helpers::matchPeriodicSidesSearch(left_,right_,mesh,matcher_,matchedSides,*currentState,type_);
364 }
365#endif
366
367 std::string getString() const
368 {
369 std::stringstream ss;
370 ss << "condition: " << matcher_.getString() << ", sides = [ "
371 << "\"" << left_ << "\", "
372 << "\"" << right_ << "\" ]";
373 return ss.str();
374 }
375
376 std::string getType() const
377 {return type_;}
378
379 std::string getLeftSidesetName() const
380 {return left_;}
381
382 std::string getRightSidesetName() const
383 {return right_;}
384
385 const Matcher& getMatcher() const
386 {return matcher_;}
387
388private:
389 PeriodicBC_Matcher(); // hidden!
390
391 std::string left_; // here left & right are stand in names just so
392 std::string right_; // that we realize that these boundaries are
393 // opposite of each other.
394 Matcher matcher_;
395
396 std::string type_; // type of periodic BC: coord, edge, face
397
398};
399
404template <typename Matcher>
405Teuchos::RCP<PeriodicBC_MatcherBase>
406buildPeriodicBC_Matcher(const std::string & left, const std::string & right, const Matcher & matcher, const std::string type = "coord")
407{ return Teuchos::rcp(new PeriodicBC_Matcher<Matcher>(left,right,matcher,type)); }
408
409} // end panzer_stk
410
412
413#ifdef PANZER_HAVE_STKSEARCH
415#endif
416
417#endif
virtual std::string getRightSidesetName() const =0
Returns the sideset name for the right side.
virtual std::string getString() const =0
virtual std::string getLeftSidesetName() const =0
Returns the sideset name for the left side.
const T * getAs() const
Attempts to cast the underlying matcher to type T. Returns nullptr if cast fails.
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
virtual std::string getType() const =0
std::string getRightSidesetName() const
Returns the sideset name for the right side.
PeriodicBC_Matcher(const PeriodicBC_Matcher &src)
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
PeriodicBC_Matcher(const std::string &left, const std::string &right, const Matcher &matcher, const std::string type="coord")
std::string getLeftSidesetName() const
Returns the sideset name for the left side.
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_)
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_)
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_)
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")
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")
void transformLocalSearchVector(SphereIdVector &searchVectorSideA, const Matcher &matcher, const std::vector< double > &centroidSideB)
Teuchos::RCP< std::vector< std::size_t > > getLocalSideIds(const STK_Interface &mesh, const std::string &sideName, const std::string type_)
Teuchos::RCP< PeriodicBC_MatcherBase > buildPeriodicBC_Matcher(const std::string &left, const std::string &right, const Matcher &matcher, const std::string type="coord")