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:
85  CoordMatcher(int index) : error_(1e-8),index_(index),relative_(false) { buildLabels(); }
86  CoordMatcher(int index,double error) : error_(error),index_(index),relative_(false) { buildLabels(); }
87  CoordMatcher(int index,const std::vector<std::string> & params) : error_(1e-8),index_(index),relative_(false)
88  { buildLabels(); parseParams(params); }
89 
91 
93  const Teuchos::Tuple<double,3> & b) const
94  {
95  double error = error_;
96  if(relative_) // scale error by length of domain
97  error*=std::fabs(a[1-index_]-b[1-index_]);
98  return std::fabs(a[index_]-b[index_])<error; /* I'm being lazy here! */
99  }
100 
101  std::string getString() const
102  {
103  std::stringstream ss;
104  ss << labels_[index_] << "-coord <tol=" << error_ << ">";
105  return ss.str();
106  }
107 
108  int getIndex() const {return index_;}
109 
111  {
112  // This assumes a 2D x-y mesh even though the object supports the
113  // z direction. Once in 3D you need the PlaneMatcher.
114  TEUCHOS_ASSERT(index_ != 2);
115  if (index_ == 0)
116  return 1;
117  return 0;
118  }
119 };
120 
124  double error_;
126  bool relative_; // compute error relative to length of domain
127  char labels_[3];
128 
129  void buildLabels()
130  { labels_[0] = 'x'; labels_[1] = 'y'; labels_[2] = 'z'; }
131 
132  void parseParams(const std::vector<std::string> & params)
133  {
134  std::string errStr = "PlaneMatcher \"" + std::string(1,labels_[index0_])+std::string(1,labels_[index1_])
135  + "-coord\" takes at most two parameter <tol, relative>";
136  TEUCHOS_TEST_FOR_EXCEPTION(params.size()>2,std::logic_error,errStr);
137 
138  // read in string, get double
139  if(params.size()==1) {
140  std::stringstream ss;
141  ss << params[0];
142  ss >> error_;
143  if(params.size()==2){
144  std::string errStr2 = params[1] + " is not a valid periodic option (try \"relative\")";
145  TEUCHOS_TEST_FOR_EXCEPTION(params[1]!="relative",std::logic_error,errStr2);
146  relative_ = true;
147  }
148  }
149  // else use default value for error
150  }
151 
152 public:
153  PlaneMatcher(int index0,int index1) : error_(1e-8),index0_(index0), index1_(index1), relative_(false)
154  { TEUCHOS_ASSERT(index0!=index1); buildLabels(); }
155 
156  PlaneMatcher(int index0,int index1,double error) : error_(error),index0_(index0), index1_(index1), relative_(false)
157  { TEUCHOS_ASSERT(index0!=index1); buildLabels(); }
158 
159  PlaneMatcher(int index0,int index1,const std::vector<std::string> & params)
160  : error_(1e-8), index0_(index0), index1_(index1), relative_(false)
161  { TEUCHOS_ASSERT(index0!=index1); buildLabels(); parseParams(params); }
162 
164  { buildLabels(); }
165 
167  const Teuchos::Tuple<double,3> & b) const
168  {
169  double error = error_;
170  if(relative_) // scale error by length of domain in normal direction
171  error*=std::fabs(a[3-index0_-index1_]-b[3-index0_-index1_]);
172  return (std::fabs(a[index0_]-b[index0_])<error_)
173  && (std::fabs(a[index1_]-b[index1_])<error_) ; /* I'm being lazy here! */
174  }
175 
176  std::string getString() const
177  {
178  std::stringstream ss;
179  ss << labels_[index0_] << labels_[index1_] << "-coord <tol=" << error_ << ">";
180  return ss.str();
181  }
182 
183  int getIndex0() const {return index0_;}
184  int getIndex1() const {return index1_;}
186  {
187  if (index0_ ==0) {
188  if (index1_ == 1)
189  return 2; // match x,y=periodic in z
190  else
191  return 1; // match x,z=periodic in y
192  }
193  else if (index0_ == 1) {
194  if (index1_ == 0)
195  return 2; // match y,x=periodic in z
196  else
197  return 0; // match y,z=periodic in x
198  }
199  else {
200  if (index1_ == 0)
201  return 1; // match z,x=periodic in y
202  else
203  return 0; // match z,y=periodic in x
204  }
205  }
206 };
207 
211  double error_;
213  char labels_[3];
214 
215  void buildLabels()
216  { labels_[0] = 'x'; labels_[1] = 'y'; labels_[2] = 'z'; }
217 
218  void parseParams(const std::vector<std::string> & params)
219  {
220  std::string errStr = "QuarterPlaneMatcher \"(" + std::string(1,labels_[index0a_])+std::string(1,labels_[index0b_])+")"+std::string(1,labels_[index1_])
221  + "-quarter-coord\" takes only one parameter <tol>";
222  TEUCHOS_TEST_FOR_EXCEPTION(params.size()>1,std::logic_error,errStr);
223 
224  // read in string, get double
225  if(params.size()==1) {
226  std::stringstream ss;
227  ss << params[0];
228  ss >> error_;
229  }
230  // else use default value for error
231  }
232 
233 public:
234  QuarterPlaneMatcher(int index0a,int index0b,int index1)
235  : error_(1e-8), index0a_(index0a), index0b_(index0b), index1_(index1)
236  { TEUCHOS_ASSERT(index0a!=index1); TEUCHOS_ASSERT(index0b!=index1); buildLabels(); }
237 
238  QuarterPlaneMatcher(int index0a,int index0b,int index1,double error)
239  : error_(error), index0a_(index0a), index0b_(index0b), index1_(index1)
240  { TEUCHOS_ASSERT(index0a!=index1); TEUCHOS_ASSERT(index0b!=index1); buildLabels(); }
241 
242  QuarterPlaneMatcher(int index0a,int index0b,int index1,const std::vector<std::string> & params)
243  : error_(1e-8), index0a_(index0a), index0b_(index0b), index1_(index1)
244  { TEUCHOS_ASSERT(index0a!=index1); TEUCHOS_ASSERT(index0b!=index1); buildLabels(); parseParams(params); }
245 
248  { buildLabels(); }
249 
251  const Teuchos::Tuple<double,3> & b) const
252  { return (std::fabs(a[index0a_]-b[index0b_])<error_)
253  && (std::fabs(a[index1_]-b[index1_])<error_) ; /* I'm being lazy here! */ }
254 
255  std::string getString() const
256  {
257  std::stringstream ss;
258  ss << "(" << labels_[index0a_] << labels_[index0b_] << ")" << labels_[index1_] << "-quarter-coord <tol=" << error_ << ">";
259  return ss.str();
260  }
261 };
262 
271  double error_;
273  int index0_;
276 public:
277  enum class MirrorPlane : int {
278  XZ_PLANE=0,
279  YZ_PLANE=1
280  };
281  WedgeMatcher(MirrorPlane mp,const std::vector<std::string> & params )
282  : error_(1e-8),index0_(0),is_three_d_(true)
283  {
284  if (mp == MirrorPlane::XZ_PLANE)
285  index0_ = 1;
286  else // YZ_PLANE
287  index0_ = 0;
288 
289  TEUCHOS_TEST_FOR_EXCEPTION(params.size() > 2,std::logic_error,"WedgeMatcher can only have one or two option parameters (tolerance and dimension)!");
290 
291  // read in string, get double
292  if (params.size() > 0)
293  error_ = std::stod(params[0]);
294 
295  if (params.size() > 1) {
296  if (params[1] == "2D")
297  is_three_d_ = false;
298  else if (params[1] == "3D")
299  is_three_d_ = true;
300  else {
301  TEUCHOS_TEST_FOR_EXCEPTION(true,std::runtime_error,"ERROR: WedgeMatcher::parsParams() - the second params must be iether \"2D\" or \"3D\", param=" << params[1] << "\n");
302  }
303  }
304  }
305  WedgeMatcher(const WedgeMatcher & cm) = default;
306 
308  const Teuchos::Tuple<double,3> & b) const
309  {
310  if (is_three_d_) {
311  return ( (std::fabs(a[index0_]+b[index0_])<error_) &&
312  (std::fabs(a[1-index0_]-b[1-index0_])<error_) &&
313  (std::fabs(a[2]-b[2])<error_) );
314  }
315 
316  // else 2D
317  return ( (std::fabs(a[index0_]+b[index0_])<error_) &&
318  (std::fabs(a[1-index0_]-b[1-index0_])<error_) );
319  }
320 
321  std::string getString() const
322  {
323  std::stringstream ss;
324  if (index0_ == 0)
325  ss << "wy-coord <tol=" << error_ << ">";
326  else
327  ss << "wx-coord <tol=" << error_ << ">";
328  return ss.str();
329  }
330 
331  int getIndex() const {return index0_;}
332 
334  {
335  if (index0_ == 0)
336  return MirrorPlane::YZ_PLANE;
337  return MirrorPlane::XZ_PLANE;
338  }
339 
340  bool isThreeD() const {return is_three_d_;}
341 };
342 
343 } // end panzer_stk
344 
345 #endif
QuarterPlaneMatcher(int index0a, int index0b, int index1)
bool is_three_d_
Set to true if a 3D problem, set to false if 2D.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
WedgeMatcher::MirrorPlane getMirrorPlane() const
int index0_
index to compare - 0 for wy (mirrored over yz), 1 for wx (mirrored over xz)
CoordMatcher(int index, 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, 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)
WedgeMatcher(MirrorPlane mp, const std::vector< std::string > &params)
CoordMatcher(int index)
index is the coordinate direction that will be compared to find matching nodes.
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)