G+Smo  24.08.0
Geometry + Simulation Modules
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gsAdaptiveMeshingCompare.h
1 /*
14 #pragma once
15 
16 
17 #include <iostream>
18 #include <gsHSplines/gsHBoxUtils.h>
19 
20 namespace gismo
21 {
22 
23 
30 template <short_t d, class T>
31 class gsHBoxCheck
32 {
33 public:
34  virtual ~gsHBoxCheck() {};
35 
36  virtual bool check(const gsHBox<d,T> & box) const = 0;
37 };
38 
45 template <short_t d, class T>
46 class gsMinLvlCompare : public gsHBoxCheck<d,T>
47 {
48 public:
49  explicit gsMinLvlCompare(index_t minlevel = 0)
50  :
51  m_minLevel(minlevel)
52  {}
53 
55  bool check(const gsHBox<d,T> & box) const { return box.level() > m_minLevel; }
56 
57 protected:
58  index_t m_minLevel;
59 };
60 
67 template <short_t d, class T>
68 class gsMaxLvlCompare : public gsHBoxCheck<d,T>
69 {
70 public:
71  explicit gsMaxLvlCompare(index_t maxLevel)
72  :
73  m_maxLevel(maxLevel)
74  {}
75 
76  bool check(const gsHBox<d,T> & box) const { return box.level() < m_maxLevel; }
77 
78 protected:
79  index_t m_maxLevel;
80 };
81 
88 template <short_t d, class T>
89 class gsSmallerErrCompare : public gsHBoxCheck<d,T>
90 {
91 public:
92  gsSmallerErrCompare(const T & threshold)
93  :
94  m_threshold(threshold)
95  {}
96 
97  bool check(const gsHBox<d,T> & box) const { return box.error() < m_threshold; }
98 
99 protected:
100  T m_threshold;
101 };
102 
109 template <short_t d, class T>
110 class gsLargerErrCompare : public gsHBoxCheck<d,T>
111 {
112 public:
113  gsLargerErrCompare(const T & threshold)
114  :
115  m_threshold(threshold)
116  {}
117 
118  bool check(const gsHBox<d,T> & box) const { return box.error() > m_threshold; }
119 
120 protected:
121  T m_threshold;
122 };
123 
133 template <short_t d, class T>
134 class gsOverlapCompare : public gsHBoxCheck<d,T>
135 {
136 public:
143  gsOverlapCompare(const gsHBoxContainer<d,T> & markedRef, index_t m) //, patchHContainer & markedCrs
144  :
145  m_m(m)
146  {
147  gsHBoxContainer<d,T> tmp(markedRef);
148  m_markedRefChildren = gsHBoxUtils<d,T>::Unique(tmp.getChildren());
149  }
150 
151  bool check(const gsHBox<d,T> & box) const
152  {
153  // We are going to check if the coarsening extension (closely related to the coarsening neighborhood) of the parent of \a box (since it will be elevated) fulfills the conditions of an empty coarsening neighborhood, as well as the condition of an empty coasening neighborhood provided that there is no element that will be refined herein.
154  bool clean = true;
155 
156  // if (m_m>=2) // admissiblity part
157  // {
158  // 1) Check if the coarsening neighborhood is empty
159  gsHBox<d,T> parent = box.getParent();
160  typename gsHBox<d,T>::Container Cextension = parent.getCextension(m_m);
161  Cextension = gsHBoxUtils<d,T>::Unique(Cextension);
162 
163  for (typename gsHBox<d,T>::Iterator it = Cextension.begin(); it != Cextension.end() && clean; it++)
164  {
165  it->computeCenter();
166  clean &=
167  // the level is even larger (i.e. even higher decendant); then it is not clean
168  (!((it->levelInCenter()>=it->level()))
169  )
170  ;
171  }
172 
173  if (!clean) return clean;
174  // }
175 
176  // 2) Now we check if the parents of any of the cells in the extensions overlap with the marked cells. If so, it would cause a problem with the coarsening.
177  typename gsHBox<d,T>::Container intersection = gsHBoxUtils<d,T>::ContainedIntersection(Cextension,m_markedRefChildren);
178  clean = intersection.size()==0;
179  return clean;
180  }
181 
182 protected:
183  typename gsHBox<d,T>::Container m_markedRefChildren;
184  index_t m_m;
185 };
186 
187 
188 } // namespace gismo