Chombo + EB  3.2
RefinementCriterion.H
Go to the documentation of this file.
1 #ifdef CH_LANG_CC
2 /*
3  * _______ __
4  * / ___/ / ___ __ _ / / ___
5  * / /__/ _ \/ _ \/ V \/ _ \/ _ \
6  * \___/_//_/\___/_/_/_/_.__/\___/
7  * Please refer to Copyright.txt, in Chombo's root directory.
8  */
9 #endif
10 
11 #ifndef _REFINEMENTCRITERION_H_
12 #define _REFINEMENTCRITERION_H_
13 
14 #include "IndexTM.H"
15 #include "CutCellMoments.H"
16 
17 #include "NamespaceHeader.H"
18 
19 ///
20 /**
21  This is the base class for refinement criterion used for the subdivision of
22  cells in geometry generation. If the result if "doRefine()" is true, the
23  cell is subdivided in the directions in which "a_refineInDir" is non-zero.
24  The results of this subdivision are then combined to get results for the
25  original cell.
26 */
27 template <int dim> class RefinementCriterion
28 {
29 public:
30 
31  // empty constructor
33  {
36  }
37 
38  // constructor
39  RefinementCriterion(const int& a_baseMaxNumberOfRefinements)
40  {
42  m_baseMaxNumberOfRefinements = a_baseMaxNumberOfRefinements;
43  }
44 
45  // copy constructor
46  RefinementCriterion(const RefinementCriterion<dim>& a_RefinementCriterion)
47  :m_constraintsSucceeded (a_RefinementCriterion.m_constraintsSucceeded),
49  {
50  }
51 
52  // Destructor
54  {
55  }
56 
57  /// Should a cell be subdivided and in which directions
58  /**
59  This method returns true if the current cell should be subdivided. The
60  subdivsion should occur in all the directions where "a_refineInDir" is
61  non-zero.
62  */
63  virtual bool baseDoRefine(IndexTM<int,dim> & a_refineInDir,
64  const CutCellMoments<dim> & a_ccm,
65  const int & a_numberOfRefinements)
66  {
67  //false = don't refine
68  bool baseRetval = false;
69 
70  //refine in no directions
71  a_refineInDir = IndexTM<int,dim>::Zero;
72 
73  //check whether a priori limit has been reached
74  bool exceededMaxNumber = false;
75  if (a_numberOfRefinements >= m_baseMaxNumberOfRefinements)
76  {
77  exceededMaxNumber = true;
78  }
79 
80  if (!exceededMaxNumber)
81  {
82  //check whether normal equals the zero vector or whether constraints were active
83  if (a_ccm.m_badNormal || !m_constraintsSucceeded)
84  {
85  baseRetval = true;
86  a_refineInDir = IndexTM<int,dim>::Unit;
87  }
88  }
89 
90  bool derivedRetval = doRefine(a_refineInDir,
91  a_ccm,
92  a_numberOfRefinements);
93 
94 
95  bool retval = baseRetval || derivedRetval;
96 
97  //true = refine
98  return retval;
99  }
100 
101  virtual bool doRefine(IndexTM<int,dim> & a_refineInDir,
102  const CutCellMoments<dim> & a_ccm,
103  const int & a_numberOfRefinements)
104  {
105  //empty implementation, which is useful if the refinement criterion is just the base class
106  return false;
107  }
108 
109  //Records "lsCode" from the least squares calculation
110  void setConstrantSuccessStatus(const bool& a_status)
111  {
112  m_constraintsSucceeded = a_status;
113  }
114 
115  //Retrieves "lsCode" from the least squares calculation
117  {
118  return m_constraintsSucceeded;
119  }
120 
121  //set max number of refinements
122  void setBaseMaxNumberOfRefinements(const int & a_baseMaxNumberOfRefinements)
123  {
124  if (a_baseMaxNumberOfRefinements < 0)
125  {
126  MayDay::Abort("FixedRefinement<dim>::setNumberOfRefinements - maxNumberOfRefinements must be >= 0");
127  }
128 
129  m_baseMaxNumberOfRefinements = a_baseMaxNumberOfRefinements;
130  }
131 
132  //get max number of refinements
134  {
136  }
137 
138  void print(ostream& a_out) const
139  {
140  a_out << "m_constraintsSucceeded = " << m_constraintsSucceeded << "\n";
141  }
142 
143  // equals operator
144  void operator=(const RefinementCriterion & a_RefinementCriterion)
145  {
146  m_constraintsSucceeded = a_RefinementCriterion.m_constraintsSucceeded;
148  }
149 
150 protected:
153 };
154 
155 template<int dim> ostream& operator<<(ostream & a_out,
156  const RefinementCriterion<dim> & a_RefinementCriterion)
157  {
158  a_RefinementCriterion.print(a_out);
159  return a_out;
160  }
161 
162 #include "NamespaceFooter.H"
163 
164 #endif
bool getConstrantSuccessStatus()
Definition: RefinementCriterion.H:116
int getBaseMaxNumberOfRefinements()
Definition: RefinementCriterion.H:133
virtual bool doRefine(IndexTM< int, dim > &a_refineInDir, const CutCellMoments< dim > &a_ccm, const int &a_numberOfRefinements)
Definition: RefinementCriterion.H:101
bool m_badNormal
Definition: CutCellMoments.H:153
void setConstrantSuccessStatus(const bool &a_status)
Definition: RefinementCriterion.H:110
Definition: RefinementCriterion.H:27
Definition: IndexTM.H:36
RefinementCriterion(const RefinementCriterion< dim > &a_RefinementCriterion)
Definition: RefinementCriterion.H:46
RefinementCriterion()
Definition: RefinementCriterion.H:32
ostream & operator<<(ostream &a_out, const RefinementCriterion< dim > &a_RefinementCriterion)
Definition: RefinementCriterion.H:155
bool m_constraintsSucceeded
Definition: RefinementCriterion.H:151
int m_baseMaxNumberOfRefinements
Definition: RefinementCriterion.H:152
~RefinementCriterion()
Definition: RefinementCriterion.H:53
void operator=(const RefinementCriterion &a_RefinementCriterion)
Definition: RefinementCriterion.H:144
Definition: CutCellMoments.H:32
virtual bool baseDoRefine(IndexTM< int, dim > &a_refineInDir, const CutCellMoments< dim > &a_ccm, const int &a_numberOfRefinements)
Should a cell be subdivided and in which directions.
Definition: RefinementCriterion.H:63
void setBaseMaxNumberOfRefinements(const int &a_baseMaxNumberOfRefinements)
Definition: RefinementCriterion.H:122
void print(ostream &a_out) const
Definition: RefinementCriterion.H:138
RefinementCriterion(const int &a_baseMaxNumberOfRefinements)
Definition: RefinementCriterion.H:39
static void Abort(const char *const a_msg=m_nullString)
Print out message to cerr and exit via abort() (if serial) or MPI_Abort() (if parallel).