Panzer Version of the Day
Loading...
Searching...
No Matches
Panzer_STK_PeriodicBC_MatchConditions.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_MatchConditions_hpp__
12#define __Panzer_STK_PeriodicBC_MatchConditions_hpp__
13
14#include "Teuchos_Tuple.hpp"
15
16#include <vector>
17#include <string>
18
19namespace panzer_stk {
20
24 double error_;
25 int index_;
26 bool relative_; // compute error relative to length of domain
27 char labels_[3];
28
30 { labels_[0] = 'x'; labels_[1] = 'y'; labels_[2] = 'z'; }
31
32 void parseParams(const std::vector<std::string> & params)
33 {
34 std::string errStr = "CoordMatcher \"" + std::string(1,labels_[index_]) + "-coord\" takes at most two parameters <tol, relative>";
35 TEUCHOS_TEST_FOR_EXCEPTION(params.size()>2,std::logic_error,errStr);
36
37 // read in string, get double
38 if(params.size()>0) {
39 std::stringstream ss;
40 ss << params[0];
41 ss >> error_;
42 if(params.size()==2){
43 std::string errStr2 = params[1] + " is not a valid periodic option (try \"relative\")";
44 TEUCHOS_TEST_FOR_EXCEPTION(params[1]!="relative",std::logic_error,errStr2);
45 relative_ = true;
46 }
47 }
48 // else use default value for error
49 }
50
51public:
53 CoordMatcher(int index) : error_(1e-8),index_(index),relative_(false) { buildLabels(); }
55 CoordMatcher(int index,double error) : error_(error),index_(index),relative_(false) { buildLabels(); }
57 CoordMatcher(int index,const std::vector<std::string> & params) : error_(1e-8),index_(index),relative_(false)
58 { buildLabels(); parseParams(params); }
59
62
64 bool operator()(const Teuchos::Tuple<double,3> & a,
65 const Teuchos::Tuple<double,3> & b) const
66 {
67 double error = error_;
68 if(relative_) // scale error by length of domain
69 error*=std::fabs(a[1-index_]-b[1-index_]);
70 return std::fabs(a[index_]-b[index_])<error; /* I'm being lazy here! */
71 }
72
74 std::string getString() const
75 {
76 std::stringstream ss;
77 ss << labels_[index_] << "-coord <tol=" << error_ << ">";
78 return ss.str();
79 }
80
82 int getIndex() const {return index_;}
83
86 {
87 // This assumes a 2D x-y mesh even though the object supports the
88 // z direction. Once in 3D you need the PlaneMatcher.
89 TEUCHOS_ASSERT(index_ != 2);
90 if (index_ == 0)
91 return 1;
92 return 0;
93 }
94
96 double getAbsoluteTolerance() const {return error_;}
97
99 void transform(double * ptB, const std::vector<double> & centroidA) const
100 {
101 // Instead of matching directly, shift pt B given the centroid
102 // of side A
103 // For now, we assume at 2D x-y mesh as above so just need
104 // to overwrite the coordinate in the periodic direction
105
106 const int periodicIndex = this->getPeriodicDirection();
107 ptB[periodicIndex] = centroidA[periodicIndex];
108
109 return;
110 }
111};
112
116 double error_;
118 bool relative_; // compute error relative to length of domain
119 char labels_[3];
120
122 { labels_[0] = 'x'; labels_[1] = 'y'; labels_[2] = 'z'; }
123
124 void parseParams(const std::vector<std::string> & params)
125 {
126 std::string errStr = "PlaneMatcher \"" + std::string(1,labels_[index0_])+std::string(1,labels_[index1_])
127 + "-coord\" takes at most two parameter <tol, relative>";
128 TEUCHOS_TEST_FOR_EXCEPTION(params.size()>2,std::logic_error,errStr);
129
130 // read in string, get double
131 if(params.size()>0) {
132 std::stringstream ss;
133 ss << params[0];
134 ss >> error_;
135 if(params.size()==2){
136 if (params[1] == "3D") {
137 // Warn user but continue
138 std::cout << "WARNING : Keyword " << params[1] << " not needed for PlaneMatcher" << std::endl;
139 return;
140 }
141 std::string errStr2 = params[1] + " is not a valid periodic option (try \"relative\")";
142 TEUCHOS_TEST_FOR_EXCEPTION(params[1]!="relative",std::logic_error,errStr2);
143 relative_ = true;
144 }
145 }
146 // else use default value for error
147 return;
148 }
149
150public:
152 PlaneMatcher(int index0,int index1) : error_(1e-8),index0_(index0), index1_(index1), relative_(false)
153 { TEUCHOS_ASSERT(index0!=index1); buildLabels(); }
154
156 PlaneMatcher(int index0,int index1,double error) : error_(error),index0_(index0), index1_(index1), relative_(false)
157 { TEUCHOS_ASSERT(index0!=index1); buildLabels(); }
158
160 PlaneMatcher(int index0,int index1,const std::vector<std::string> & params)
161 : error_(1e-8), index0_(index0), index1_(index1), relative_(false)
162 { TEUCHOS_ASSERT(index0!=index1); buildLabels(); parseParams(params); }
163
167
169 bool operator()(const Teuchos::Tuple<double,3> & a,
170 const Teuchos::Tuple<double,3> & b) const
171 {
172 double error = error_;
173 if(relative_) // scale error by length of domain in normal direction
174 error*=std::fabs(a[3-index0_-index1_]-b[3-index0_-index1_]);
175 return (std::fabs(a[index0_]-b[index0_])<error_)
176 && (std::fabs(a[index1_]-b[index1_])<error_) ; /* I'm being lazy here! */
177 }
178
180 std::string getString() const
181 {
182 std::stringstream ss;
183 ss << labels_[index0_] << labels_[index1_] << "-coord <tol=" << error_ << ">";
184 return ss.str();
185 }
186
188 int getIndex0() const {return index0_;}
190 int getIndex1() const {return index1_;}
193 {
194 if (index0_ ==0) {
195 if (index1_ == 1)
196 return 2; // match x,y=periodic in z
197 else
198 return 1; // match x,z=periodic in y
199 }
200 else if (index0_ == 1) {
201 if (index1_ == 0)
202 return 2; // match y,x=periodic in z
203 else
204 return 0; // match y,z=periodic in x
205 }
206 else {
207 if (index1_ == 0)
208 return 1; // match z,x=periodic in y
209 else
210 return 0; // match z,y=periodic in x
211 }
212 }
213
215 double getAbsoluteTolerance() const {return error_;}
216
218 void transform(double * ptB, const std::vector<double> & centroidA) const
219 {
220 // Instead of matching directly, shift pt B given the centroid
221 // of side A
222 // For now, we assume the planes are aligned with one of the
223 // coordinate axes so we just need to overwrite the coordinate
224 // in the periodic direction
225
226 const int periodicIndex = this->getPeriodicDirection();
227 ptB[periodicIndex] = centroidA[periodicIndex];
228
229 return;
230 }
231};
232
236 double error_;
238 char labels_[3];
239
241 { labels_[0] = 'x'; labels_[1] = 'y'; labels_[2] = 'z'; }
242
243 void parseParams(const std::vector<std::string> & params)
244 {
245 std::string errStr = "QuarterPlaneMatcher \"(" + std::string(1,labels_[index0a_])+std::string(1,labels_[index0b_])+")"+std::string(1,labels_[index1_])
246 + "-quarter-coord\" takes only one parameter <tol>";
247 TEUCHOS_TEST_FOR_EXCEPTION(params.size()>1,std::logic_error,errStr);
248
249 // read in string, get double
250 if(params.size()==1) {
251 std::stringstream ss;
252 ss << params[0];
253 ss >> error_;
254 }
255 // else use default value for error
256 }
257
258public:
260 QuarterPlaneMatcher(int index0a,int index0b,int index1)
261 : error_(1e-8), index0a_(index0a), index0b_(index0b), index1_(index1)
262 { TEUCHOS_ASSERT(index0a!=index1); TEUCHOS_ASSERT(index0b!=index1); buildLabels(); }
263
265 QuarterPlaneMatcher(int index0a,int index0b,int index1,double error)
266 : error_(error), index0a_(index0a), index0b_(index0b), index1_(index1)
267 { TEUCHOS_ASSERT(index0a!=index1); TEUCHOS_ASSERT(index0b!=index1); buildLabels(); }
268
270 QuarterPlaneMatcher(int index0a,int index0b,int index1,const std::vector<std::string> & params)
271 : error_(1e-8), index0a_(index0a), index0b_(index0b), index1_(index1)
272 { TEUCHOS_ASSERT(index0a!=index1); TEUCHOS_ASSERT(index0b!=index1); buildLabels(); parseParams(params); }
273
278
280 bool operator()(const Teuchos::Tuple<double,3> & a,
281 const Teuchos::Tuple<double,3> & b) const
282 { return (std::fabs(a[index0a_]-b[index0b_])<error_)
283 && (std::fabs(a[index1_]-b[index1_])<error_) ; /* I'm being lazy here! */ }
284
286 std::string getString() const
287 {
288 std::stringstream ss;
289 ss << "(" << labels_[index0a_] << labels_[index0b_] << ")" << labels_[index1_] << "-quarter-coord <tol=" << error_ << ">";
290 return ss.str();
291 }
292
294 double getAbsoluteTolerance() const {return error_;}
295
297 void transform(double * ptB, const std::vector<double> & centroidA) const
298 {
299 // Instead of matching directly, shift pt B given the centroid
300 // of side A
301 // For now, we assume the planes are aligned with one of the
302 // coordinate axes
303 // We leave ptB[index1_] alone,
304 // put ptB[index0b_] in the index0a_ slot and replace it with
305 // centroidA[index0b_] which is the fixed value for plane B
306
307 ptB[index0a_] = ptB[index0b_];
308 ptB[index0b_] = centroidA[index0b_];
309
310 return;
311 }
312};
313
322 double error_;
327public:
328 enum class MirrorPlane : int {
329 XZ_PLANE=0,
330 YZ_PLANE=1
331 };
338 WedgeMatcher(MirrorPlane mp,const std::vector<std::string> & params )
339 : error_(1e-8),index0_(0),is_three_d_(true)
340 {
341 if (mp == MirrorPlane::XZ_PLANE)
342 index0_ = 1;
343 else // YZ_PLANE
344 index0_ = 0;
345
346 TEUCHOS_TEST_FOR_EXCEPTION(params.size() > 2,std::logic_error,"WedgeMatcher can only have one or two option parameters (tolerance and dimension)!");
347
348 // read in string, get double
349 if (params.size() > 0)
350 error_ = std::stod(params[0]);
351
352 if (params.size() > 1) {
353 if (params[1] == "2D")
354 is_three_d_ = false;
355 else if (params[1] == "3D")
356 is_three_d_ = true;
357 else {
358 TEUCHOS_TEST_FOR_EXCEPTION(true,std::runtime_error,"ERROR: WedgeMatcher::parsParams() - the second params must be iether \"2D\" or \"3D\", param=" << params[1] << "\n");
359 }
360 }
361 }
363 WedgeMatcher(const WedgeMatcher & cm) = default;
364
366 bool operator()(const Teuchos::Tuple<double,3> & a,
367 const Teuchos::Tuple<double,3> & b) const
368 {
369 if (is_three_d_) {
370 return ( (std::fabs(a[index0_]+b[index0_])<error_) &&
371 (std::fabs(a[1-index0_]-b[1-index0_])<error_) &&
372 (std::fabs(a[2]-b[2])<error_) );
373 }
374
375 // else 2D
376 return ( (std::fabs(a[index0_]+b[index0_])<error_) &&
377 (std::fabs(a[1-index0_]-b[1-index0_])<error_) );
378 }
379
381 std::string getString() const
382 {
383 std::stringstream ss;
384 if (index0_ == 0)
385 ss << "wy-coord <tol=" << error_ << ">";
386 else
387 ss << "wx-coord <tol=" << error_ << ">";
388 return ss.str();
389 }
390
392 int getIndex() const {return index0_;}
393
396 {
397 if (index0_ == 0)
400 }
401
403 bool isThreeD() const {return is_three_d_;}
404
406 double getAbsoluteTolerance() const {return error_;}
407
409 void transform(double * ptB, const std::vector<double> & centroidA) const
410 {
411 // Instead of matching directly, shift pt B given the centroid
412 // of side A
413 // For now, we assume the wedge is mirrored over the yz or xz plane
414 // Then we just need to mirror over the plane
415
416 ptB[index0_] = -ptB[index0_];
417
418 return;
419 }
420};
421
422} // end panzer_stk
423
424#endif
void parseParams(const std::vector< std::string > &params)
bool operator()(const Teuchos::Tuple< double, 3 > &a, const Teuchos::Tuple< double, 3 > &b) const
Returns true if points a and b match, i.e. their coordinates in the compared direction are within tol...
CoordMatcher(int index, const std::vector< std::string > &params)
Construct with tolerance and "relative" option parsed from strings, as accepted by parseParams().
std::string getString() const
Returns a human-readable description of this matcher's compared coordinate and tolerance.
void transform(double *ptB, const std::vector< double > &centroidA) const
Shifts ptB's periodic-direction coordinate to match centroidA's, in place.
CoordMatcher(int index)
Constructor where the index is the coordinate axis that will be compared to find matching nodes.
int getIndex() const
Returns the coordinate axis/direction being compared.
CoordMatcher(int index, double error)
Construct with an explicit absolute tolerance.
CoordMatcher(const CoordMatcher &cm)
Copy constructor.
double getAbsoluteTolerance() const
Returns the absolute matching tolerance.
int getPeriodicDirection() const
Returns the direction (0=x, 1=y) in which the boundary condition is periodic; the direction orthogona...
bool operator()(const Teuchos::Tuple< double, 3 > &a, const Teuchos::Tuple< double, 3 > &b) const
Returns true if points a and b match, i.e. their coordinates in both compared directions are within t...
PlaneMatcher(int index0, int index1)
index0 and index1 are the two coordinate directions defining the plane compared to find matching node...
PlaneMatcher(int index0, int index1, double error)
Construct with an explicit absolute tolerance.
int getIndex0() const
Returns the first coordinate direction being compared.
double getAbsoluteTolerance() const
Returns the absolute matching tolerance.
PlaneMatcher(int index0, int index1, const std::vector< std::string > &params)
Construct with tolerance and "relative" option parsed from strings, as accepted by parseParams().
void transform(double *ptB, const std::vector< double > &centroidA) const
Shifts ptB's periodic-direction coordinate to match centroidA's, in place.
PlaneMatcher(const PlaneMatcher &cm)
Copy constructor.
std::string getString() const
Returns a human-readable description of this matcher's compared coordinates and tolerance.
int getPeriodicDirection() const
Returns the direction orthogonal to the compared plane, in which the boundary condition is periodic.
void parseParams(const std::vector< std::string > &params)
int getIndex1() const
Returns the second coordinate direction being compared.
QuarterPlaneMatcher(int index0a, int index0b, int index1)
index0a/index0b are the coordinate directions compared across the two quarter-symmetry planes; index1...
std::string getString() const
Returns a human-readable description of this matcher's compared coordinates and tolerance.
double getAbsoluteTolerance() const
Returns the absolute matching tolerance.
void transform(double *ptB, const std::vector< double > &centroidA) const
Shifts ptB in place to reflect it into plane A's quarter-symmetry orientation, given plane A's centro...
QuarterPlaneMatcher(int index0a, int index0b, int index1, const std::vector< std::string > &params)
Construct with tolerance parsed from strings, as accepted by parseParams().
QuarterPlaneMatcher(int index0a, int index0b, int index1, double error)
Construct with an explicit absolute tolerance.
QuarterPlaneMatcher(const QuarterPlaneMatcher &cm)
Copy constructor.
void parseParams(const std::vector< std::string > &params)
bool operator()(const Teuchos::Tuple< double, 3 > &a, const Teuchos::Tuple< double, 3 > &b) const
Returns true if points a and b match across the quarter-symmetry planes, within tolerance.
int index0_
index to compare - 0 for wy (mirrored over yz), 1 for wx (mirrored over xz)
bool operator()(const Teuchos::Tuple< double, 3 > &a, const Teuchos::Tuple< double, 3 > &b) const
Returns true if points a and b match across the mirror plane, within tolerance.
WedgeMatcher::MirrorPlane getMirrorPlane() const
Returns which plane the wedge is mirrored over.
bool is_three_d_
Set to true if a 3D problem, set to false if 2D.
WedgeMatcher(const WedgeMatcher &cm)=default
Copy constructor.
std::string getString() const
Returns a human-readable description of this matcher's mirror plane and tolerance.
void transform(double *ptB, const std::vector< double > &centroidA) const
Mirrors ptB's compared coordinate over the mirror plane, in place.
int getIndex() const
Returns the coordinate direction being compared.
WedgeMatcher(MirrorPlane mp, const std::vector< std::string > &params)
Construct for the given mirror plane, with tolerance and dimensionality ("2D"/"3D") options parsed fr...
bool isThreeD() const
Returns true if this matcher was constructed for a 3D problem.
double getAbsoluteTolerance() const
Returns the absolute matching tolerance.