Panzer  Version of the Day
Panzer_STK_PeriodicBC_MatchConditions.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_MatchConditions_hpp__
44 #define __Panzer_STK_PeriodicBC_MatchConditions_hpp__
45 
46 #include "Teuchos_Tuple.hpp"
47 
48 #include <vector>
49 #include <string>
50 
51 namespace panzer_stk {
52 
55 class CoordMatcher {
56  double error_;
57  int index_;
58  char labels_[3];
59 
60  void buildLabels()
61  { labels_[0] = 'x'; labels_[1] = 'y'; labels_[2] = 'z'; }
62 
63  void parseParams(const std::vector<std::string> & params)
64  {
65  std::string errStr = "CoordMatcher \"" + std::string(1,labels_[index_]) + "-coord\" takes at most one parameter <tol>";
66  TEUCHOS_TEST_FOR_EXCEPTION(params.size()>1,std::logic_error,errStr);
67 
68  // read in string, get double
69  if(params.size()==1) {
70  std::stringstream ss;
71  ss << params[0];
72  ss >> error_;
73  }
74  // else use default value for error
75  }
76 
77 public:
78  CoordMatcher(int index) : error_(1e-8),index_(index) { buildLabels(); }
79  CoordMatcher(int index,double error) : error_(error),index_(index) { buildLabels(); }
80  CoordMatcher(int index,const std::vector<std::string> & params) : error_(1e-8),index_(index)
81  { buildLabels(); parseParams(params); }
82 
84 
85  bool operator()(const Teuchos::Tuple<double,3> & a,
86  const Teuchos::Tuple<double,3> & b) const
87  { return std::fabs(a[index_]-b[index_])<error_; /* I'm being lazy here! */ }
88 
89  std::string getString() const
90  {
91  std::stringstream ss;
92  ss << labels_[index_] << "-coord <tol=" << error_ << ">";
93  return ss.str();
94  }
95 };
96 
99 class PlaneMatcher {
100  double error_;
102  char labels_[3];
103 
104  void buildLabels()
105  { labels_[0] = 'x'; labels_[1] = 'y'; labels_[2] = 'z'; }
106 
107  void parseParams(const std::vector<std::string> & params)
108  {
109  std::string errStr = "PlaneMatcher \"" + std::string(1,labels_[index0_])+std::string(1,labels_[index1_])
110  + "-coord\" takes only one parameter <tol>";
111  TEUCHOS_TEST_FOR_EXCEPTION(params.size()>1,std::logic_error,errStr);
112 
113  // read in string, get double
114  if(params.size()==1) {
115  std::stringstream ss;
116  ss << params[0];
117  ss >> error_;
118  }
119  // else use default value for error
120  }
121 
122 public:
123  PlaneMatcher(int index0,int index1) : error_(1e-8),index0_(index0), index1_(index1)
124  { TEUCHOS_ASSERT(index0!=index1); buildLabels(); }
125 
126  PlaneMatcher(int index0,int index1,double error) : error_(error),index0_(index0), index1_(index1)
127  { TEUCHOS_ASSERT(index0!=index1); buildLabels(); }
128 
129  PlaneMatcher(int index0,int index1,const std::vector<std::string> & params)
130  : error_(1e-8), index0_(index0), index1_(index1)
131  { TEUCHOS_ASSERT(index0!=index1); buildLabels(); parseParams(params); }
132 
134  { buildLabels(); }
135 
136  bool operator()(const Teuchos::Tuple<double,3> & a,
137  const Teuchos::Tuple<double,3> & b) const
138  { return (std::fabs(a[index0_]-b[index0_])<error_)
139  && (std::fabs(a[index1_]-b[index1_])<error_) ; /* I'm being lazy here! */ }
140 
141  std::string getString() const
142  {
143  std::stringstream ss;
144  ss << labels_[index0_] << labels_[index1_] << "-coord <tol=" << error_ << ">";
145  return ss.str();
146  }
147 };
148 
152  double error_;
154  char labels_[3];
155 
156  void buildLabels()
157  { labels_[0] = 'x'; labels_[1] = 'y'; labels_[2] = 'z'; }
158 
159  void parseParams(const std::vector<std::string> & params)
160  {
161  std::string errStr = "QuarterPlaneMatcher \"(" + std::string(1,labels_[index0a_])+std::string(1,labels_[index0b_])+")"+std::string(1,labels_[index1_])
162  + "-quarter-coord\" takes only one parameter <tol>";
163  TEUCHOS_TEST_FOR_EXCEPTION(params.size()>1,std::logic_error,errStr);
164 
165  // read in string, get double
166  if(params.size()==1) {
167  std::stringstream ss;
168  ss << params[0];
169  ss >> error_;
170  }
171  // else use default value for error
172  }
173 
174 public:
175  QuarterPlaneMatcher(int index0a,int index0b,int index1)
176  : error_(1e-8), index0a_(index0a), index0b_(index0b), index1_(index1)
177  { TEUCHOS_ASSERT(index0a!=index1); TEUCHOS_ASSERT(index0b!=index1); buildLabels(); }
178 
179  QuarterPlaneMatcher(int index0a,int index0b,int index1,double error)
180  : error_(error), index0a_(index0a), index0b_(index0b), index1_(index1)
181  { TEUCHOS_ASSERT(index0a!=index1); TEUCHOS_ASSERT(index0b!=index1); buildLabels(); }
182 
183  QuarterPlaneMatcher(int index0a,int index0b,int index1,const std::vector<std::string> & params)
184  : error_(1e-8), index0a_(index0a), index0b_(index0b), index1_(index1)
185  { TEUCHOS_ASSERT(index0a!=index1); TEUCHOS_ASSERT(index0b!=index1); buildLabels(); parseParams(params); }
186 
189  { buildLabels(); }
190 
191  bool operator()(const Teuchos::Tuple<double,3> & a,
192  const Teuchos::Tuple<double,3> & b) const
193  { return (std::fabs(a[index0a_]-b[index0b_])<error_)
194  && (std::fabs(a[index1_]-b[index1_])<error_) ; /* I'm being lazy here! */ }
195 
196  std::string getString() const
197  {
198  std::stringstream ss;
199  ss << "(" << labels_[index0a_] << labels_[index0b_] << ")" << labels_[index1_] << "-quarter-coord <tol=" << error_ << ">";
200  return ss.str();
201  }
202 };
203 
204 } // end panzer_stk
205 
206 #endif
QuarterPlaneMatcher(int index0a, int index0b, int index1)
bool operator()(const Teuchos::Tuple< double, 3 > &a, const Teuchos::Tuple< double, 3 > &b) const
CoordMatcher(int index, const std::vector< std::string > &params)
PlaneMatcher(int index0, int index1, const std::vector< std::string > &params)
void parseParams(const std::vector< std::string > &params)
bool operator()(const Teuchos::Tuple< double, 3 > &a, const Teuchos::Tuple< double, 3 > &b) const
void parseParams(const std::vector< std::string > &params)
QuarterPlaneMatcher(int index0a, int index0b, int index1, double error)
void parseParams(const std::vector< std::string > &params)
QuarterPlaneMatcher(int index0a, int index0b, int index1, const std::vector< std::string > &params)
bool operator()(const Teuchos::Tuple< double, 3 > &a, const Teuchos::Tuple< double, 3 > &b) const
PlaneMatcher(int index0, int index1, double error)