Panzer  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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  bool relative_; // compute error relative to length of domain
59  char labels_[3];
60 
61  void buildLabels()
62  { labels_[0] = 'x'; labels_[1] = 'y'; labels_[2] = 'z'; }
63 
64  void parseParams(const std::vector<std::string> & params)
65  {
66  std::string errStr = "CoordMatcher \"" + std::string(1,labels_[index_]) + "-coord\" takes at most two parameters <tol, relative>";
67  TEUCHOS_TEST_FOR_EXCEPTION(params.size()>2,std::logic_error,errStr);
68 
69  // read in string, get double
70  if(params.size()>0) {
71  std::stringstream ss;
72  ss << params[0];
73  ss >> error_;
74  if(params.size()==2){
75  std::string errStr2 = params[1] + " is not a valid periodic option (try \"relative\")";
76  TEUCHOS_TEST_FOR_EXCEPTION(params[1]!="relative",std::logic_error,errStr2);
77  relative_ = true;
78  }
79  }
80  // else use default value for error
81  }
82 
83 public:
84  CoordMatcher(int index) : error_(1e-8),index_(index),relative_(false) { buildLabels(); }
85  CoordMatcher(int index,double error) : error_(error),index_(index),relative_(false) { buildLabels(); }
86  CoordMatcher(int index,const std::vector<std::string> & params) : error_(1e-8),index_(index),relative_(false)
87  { buildLabels(); parseParams(params); }
88 
90 
92  const Teuchos::Tuple<double,3> & b) const
93  {
94  double error = error_;
95  if(relative_) // scale error by length of domain
96  error*=std::fabs(a[1-index_]-b[1-index_]);
97  return std::fabs(a[index_]-b[index_])<error; /* I'm being lazy here! */
98  }
99 
100  std::string getString() const
101  {
102  std::stringstream ss;
103  ss << labels_[index_] << "-coord <tol=" << error_ << ">";
104  return ss.str();
105  }
106 };
107 
111  double error_;
113  bool relative_; // compute error relative to length of domain
114  char labels_[3];
115 
116  void buildLabels()
117  { labels_[0] = 'x'; labels_[1] = 'y'; labels_[2] = 'z'; }
118 
119  void parseParams(const std::vector<std::string> & params)
120  {
121  std::string errStr = "PlaneMatcher \"" + std::string(1,labels_[index0_])+std::string(1,labels_[index1_])
122  + "-coord\" takes at most two parameter <tol, relative>";
123  TEUCHOS_TEST_FOR_EXCEPTION(params.size()>2,std::logic_error,errStr);
124 
125  // read in string, get double
126  if(params.size()==1) {
127  std::stringstream ss;
128  ss << params[0];
129  ss >> error_;
130  if(params.size()==2){
131  std::string errStr2 = params[1] + " is not a valid periodic option (try \"relative\")";
132  TEUCHOS_TEST_FOR_EXCEPTION(params[1]!="relative",std::logic_error,errStr2);
133  relative_ = true;
134  }
135  }
136  // else use default value for error
137  }
138 
139 public:
140  PlaneMatcher(int index0,int index1) : error_(1e-8),index0_(index0), index1_(index1), relative_(false)
141  { TEUCHOS_ASSERT(index0!=index1); buildLabels(); }
142 
143  PlaneMatcher(int index0,int index1,double error) : error_(error),index0_(index0), index1_(index1), relative_(false)
144  { TEUCHOS_ASSERT(index0!=index1); buildLabels(); }
145 
146  PlaneMatcher(int index0,int index1,const std::vector<std::string> & params)
147  : error_(1e-8), index0_(index0), index1_(index1), relative_(false)
148  { TEUCHOS_ASSERT(index0!=index1); buildLabels(); parseParams(params); }
149 
151  { buildLabels(); }
152 
154  const Teuchos::Tuple<double,3> & b) const
155  {
156  double error = error_;
157  if(relative_) // scale error by length of domain in normal direction
158  error*=std::fabs(a[3-index0_-index1_]-b[3-index0_-index1_]);
159  return (std::fabs(a[index0_]-b[index0_])<error_)
160  && (std::fabs(a[index1_]-b[index1_])<error_) ; /* I'm being lazy here! */
161  }
162 
163  std::string getString() const
164  {
165  std::stringstream ss;
166  ss << labels_[index0_] << labels_[index1_] << "-coord <tol=" << error_ << ">";
167  return ss.str();
168  }
169 };
170 
174  double error_;
176  char labels_[3];
177 
178  void buildLabels()
179  { labels_[0] = 'x'; labels_[1] = 'y'; labels_[2] = 'z'; }
180 
181  void parseParams(const std::vector<std::string> & params)
182  {
183  std::string errStr = "QuarterPlaneMatcher \"(" + std::string(1,labels_[index0a_])+std::string(1,labels_[index0b_])+")"+std::string(1,labels_[index1_])
184  + "-quarter-coord\" takes only one parameter <tol>";
185  TEUCHOS_TEST_FOR_EXCEPTION(params.size()>1,std::logic_error,errStr);
186 
187  // read in string, get double
188  if(params.size()==1) {
189  std::stringstream ss;
190  ss << params[0];
191  ss >> error_;
192  }
193  // else use default value for error
194  }
195 
196 public:
197  QuarterPlaneMatcher(int index0a,int index0b,int index1)
198  : error_(1e-8), index0a_(index0a), index0b_(index0b), index1_(index1)
199  { TEUCHOS_ASSERT(index0a!=index1); TEUCHOS_ASSERT(index0b!=index1); buildLabels(); }
200 
201  QuarterPlaneMatcher(int index0a,int index0b,int index1,double error)
202  : error_(error), index0a_(index0a), index0b_(index0b), index1_(index1)
203  { TEUCHOS_ASSERT(index0a!=index1); TEUCHOS_ASSERT(index0b!=index1); buildLabels(); }
204 
205  QuarterPlaneMatcher(int index0a,int index0b,int index1,const std::vector<std::string> & params)
206  : error_(1e-8), index0a_(index0a), index0b_(index0b), index1_(index1)
207  { TEUCHOS_ASSERT(index0a!=index1); TEUCHOS_ASSERT(index0b!=index1); buildLabels(); parseParams(params); }
208 
211  { buildLabels(); }
212 
214  const Teuchos::Tuple<double,3> & b) const
215  { return (std::fabs(a[index0a_]-b[index0b_])<error_)
216  && (std::fabs(a[index1_]-b[index1_])<error_) ; /* I'm being lazy here! */ }
217 
218  std::string getString() const
219  {
220  std::stringstream ss;
221  ss << "(" << labels_[index0a_] << labels_[index0b_] << ")" << labels_[index1_] << "-quarter-coord <tol=" << error_ << ">";
222  return ss.str();
223  }
224 };
225 
226 } // end panzer_stk
227 
228 #endif
QuarterPlaneMatcher(int index0a, int index0b, int index1)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
CoordMatcher(int index, const std::vector< std::string > &params)
PlaneMatcher(int index0, int index1, 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)
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
#define TEUCHOS_ASSERT(assertion_test)
PlaneMatcher(int index0, int index1, double error)