G+Smo  25.01.0
Geometry + Simulation Modules
 
Loading...
Searching...
No Matches
gsAdaptiveMeshing.h
1
14#pragma once
15
16
17#include <iostream>
19#include <gsAssembler/gsAdaptiveMeshingCompare.h>
20#include <gsIO/gsOptionList.h>
21#include <gsCore/gsMultiPatch.h>
22#include <gsCore/gsMultiBasis.h>
23#include <gsHSplines/gsHBox.h>
26
27namespace gismo
28{
29
40template <class T>
42{
43public:
44 typedef gsHBox<2,T> HBox;
45 typedef gsHBox<2,T> * HBox_ptr;
47 typedef typename HBox::SortedContainer boxContainer;
48 typedef std::map<gsHBox<2,T>,index_t,gsHBoxCompare<2,T>> indexMapType;
49 typedef std::map<index_t,gsHBox<2,T>*> boxMapType;
51
52public:
53
55
57
58 // ~gsAdaptiveMeshing();
59
60 gsOptionList & options() {return m_options;}
61
62 void defaultOptions();
63
64 void getOptions();
65
66 void rebuild();
67
68 void container_into(const std::vector<T> & elError, HBoxContainer & result);
69
70 void markRef_into(const std::vector<T> & elError, HBoxContainer & elMarked);
71
72 void markCrs_into(const std::vector<T> & elError, const HBoxContainer & markedRef, HBoxContainer & elMarked);
73 void markCrs_into(const std::vector<T> & elError, HBoxContainer & elMarked);
74
75 void markRef(const std::vector<T> & errors);
76 void markCrs(const std::vector<T> & errors);
77
78 bool refine(const HBoxContainer & markedRef);
79 bool unrefine(const HBoxContainer & markedCrs);
80
81 bool refine(const std::vector<bool> & markedRef) { return refine(_toContainer(markedRef)); }
82 bool unrefine(const std::vector<bool> & markedCrs) { return unrefine(_toContainer(markedCrs)); };
83
84 bool refine() { return refine(m_markedRef); }
85 bool unrefine() { return unrefine(m_markedRef); };
86
87 bool refineAll();
88 bool unrefineAll();
89
90 // void flatten(const index_t level);
91 // void flatten() { flatten(m_maxLvl); } ;
92
93 // void unrefineThreshold(const index_t level);
94 // void unrefineThreshold(){ unrefineThreshold(m_maxLvl); };
95
96 index_t numBlocked() const;
97 index_t numElements() const;
98
99 void assignErrors(const std::vector<T> & elError);
100 T blockedError() const;
101 T nonBlockedError() const;
102
103private:
104 void _makeMap(const gsFunctionSet<T> * input, typename gsAdaptiveMeshing<T>::indexMapType & indexMap, typename gsAdaptiveMeshing<T>::boxMapType & boxMap);
105
106 void _assignErrors(boxMapType & container, const std::vector<T> & elError);
107
108
109 void _refineMarkedElements( const HBoxContainer & container,
110 index_t refExtension = 0);
111
112 void _unrefineMarkedElements( const HBoxContainer & container,
113 index_t refExtension = 0);
114
115 // void _flattenElementsToLevel( const index_t level);
116
117 // void _unrefineElementsThreshold(const index_t level);
118
119 std::vector<index_t> _sortPermutation( const boxMapType & container);
120 std::vector<index_t> _sortPermutationProjectedRef( const boxMapType & container);
121 std::vector<index_t> _sortPermutationProjectedCrs( const boxMapType & container);
122 // void _sortPermutated( const std::vector<index_t> & permutation, boxContainer & container);
123
124 void _crsPredicates_into( std::vector<gsHBoxCheck<2,T> *> & predicates);
125 void _crsPredicates_into(const HBoxContainer & markedRef, std::vector<gsHBoxCheck<2,T> *> & predicates);
126 void _refPredicates_into( std::vector<gsHBoxCheck<2,T> *> & predicates);
127
128 template<bool _coarsen,bool _admissible>
129 void _markElements( const std::vector<T> & elError, const index_t refCriterion, const std::vector<gsHBoxCheck<2,T> *> & predicates, HBoxContainer & elMarked) const;
130
131 template<bool _coarsen,bool _admissible>
132 void _markFraction( const boxMapType & elements, const std::vector<gsHBoxCheck<2,T> *> predicates, HBoxContainer & elMarked) const
133 {
134 _markFraction_impl<_coarsen,_admissible>(elements,predicates,elMarked);
135 }
136 template<bool _coarsen,bool _admissible>
137 typename std::enable_if< _coarsen && _admissible, void>::type
138 _markFraction_impl( const boxMapType & elements, const std::vector<gsHBoxCheck<2,T> *> predicates, HBoxContainer & elMarked) const;
139
140 template<bool _coarsen,bool _admissible>
141 typename std::enable_if< _coarsen && !_admissible, void>::type
142 _markFraction_impl( const boxMapType & elements, const std::vector<gsHBoxCheck<2,T> *> predicates, HBoxContainer & elMarked) const;
143
144 template<bool _coarsen,bool _admissible>
145 typename std::enable_if<!_coarsen && _admissible, void>::type
146 _markFraction_impl( const boxMapType & elements, const std::vector<gsHBoxCheck<2,T> *> predicates, HBoxContainer & elMarked) const;
147
148 template<bool _coarsen,bool _admissible>
149 typename std::enable_if<!_coarsen && !_admissible, void>::type
150 _markFraction_impl( const boxMapType & elements, const std::vector<gsHBoxCheck<2,T> *> predicates, HBoxContainer & elMarked) const;
151
152 template<bool _coarsen,bool _admissible>
153 void _markProjectedFraction( const boxMapType & elements, const std::vector<gsHBoxCheck<2,T> *> predicates, HBoxContainer & elMarked) const
154 {
155 _markProjectedFraction_impl<_coarsen,_admissible>(elements,predicates,elMarked);
156 }
157 template<bool _coarsen,bool _admissible>
158 typename std::enable_if< _coarsen && _admissible, void>::type
159 _markProjectedFraction_impl( const boxMapType & elements, const std::vector<gsHBoxCheck<2,T> *> predicates, HBoxContainer & elMarked) const;
160
161 template<bool _coarsen,bool _admissible>
162 typename std::enable_if< _coarsen && !_admissible, void>::type
163 _markProjectedFraction_impl( const boxMapType & elements, const std::vector<gsHBoxCheck<2,T> *> predicates, HBoxContainer & elMarked) const;
164
165 template<bool _coarsen,bool _admissible>
166 typename std::enable_if<!_coarsen && _admissible, void>::type
167 _markProjectedFraction_impl( const boxMapType & elements, const std::vector<gsHBoxCheck<2,T> *> predicates, HBoxContainer & elMarked) const;
168
169 template<bool _coarsen,bool _admissible>
170 typename std::enable_if<!_coarsen && !_admissible, void>::type
171 _markProjectedFraction_impl( const boxMapType & elements, const std::vector<gsHBoxCheck<2,T> *> predicates, HBoxContainer & elMarked) const;
172
173
174 template<bool _coarsen,bool _admissible>
175 void _markPercentage( const boxMapType & elements, const std::vector<gsHBoxCheck<2,T> *> predicates, HBoxContainer & elMarked) const
176 {
177 _markPercentage_impl<_coarsen,_admissible>(elements,predicates,elMarked);
178 }
179 template<bool _coarsen,bool _admissible>
180 typename std::enable_if< _coarsen && _admissible, void>::type
181 _markPercentage_impl( const boxMapType & elements, const std::vector<gsHBoxCheck<2,T> *> predicates, HBoxContainer & elMarked) const;
182
183 template<bool _coarsen,bool _admissible>
184 typename std::enable_if< _coarsen && !_admissible, void>::type
185 _markPercentage_impl( const boxMapType & elements, const std::vector<gsHBoxCheck<2,T> *> predicates, HBoxContainer & elMarked) const;
186
187 template<bool _coarsen,bool _admissible>
188 typename std::enable_if<!_coarsen && _admissible, void>::type
189 _markPercentage_impl( const boxMapType & elements, const std::vector<gsHBoxCheck<2,T> *> predicates, HBoxContainer & elMarked) const;
190
191 template<bool _coarsen,bool _admissible>
192 typename std::enable_if<!_coarsen && !_admissible, void>::type
193 _markPercentage_impl( const boxMapType & elements, const std::vector<gsHBoxCheck<2,T> *> predicates, HBoxContainer & elMarked) const;
194
195 template<bool _coarsen,bool _admissible>
196 void _markThreshold( const boxMapType & elements, const std::vector<gsHBoxCheck<2,T> *> predicates, HBoxContainer & elMarked) const
197 {
198 _markThreshold_impl<_coarsen,_admissible>(elements,predicates,elMarked);
199 }
200 template<bool _coarsen,bool _admissible>
201 typename std::enable_if< _coarsen && _admissible, void>::type
202 _markThreshold_impl( const boxMapType & elements, const std::vector<gsHBoxCheck<2,T> *> predicates, HBoxContainer & elMarked) const;
203
204 template<bool _coarsen,bool _admissible>
205 typename std::enable_if< _coarsen && !_admissible, void>::type
206 _markThreshold_impl( const boxMapType & elements, const std::vector<gsHBoxCheck<2,T> *> predicates, HBoxContainer & elMarked) const;
207
208 template<bool _coarsen,bool _admissible>
209 typename std::enable_if<!_coarsen && _admissible, void>::type
210 _markThreshold_impl( const boxMapType & elements, const std::vector<gsHBoxCheck<2,T> *> predicates, HBoxContainer & elMarked) const;
211
212 template<bool _coarsen,bool _admissible>
213 typename std::enable_if<!_coarsen && !_admissible, void>::type
214 _markThreshold_impl( const boxMapType & elements, const std::vector<gsHBoxCheck<2,T> *> predicates, HBoxContainer & elMarked) const;
215
216 bool _checkBox ( const HBox & box , const std::vector<gsHBoxCheck<2,T> *> predicates) const;
217 bool _checkBoxes( const typename HBox::Container & boxes, const std::vector<gsHBoxCheck<2,T> *> predicates) const;
218
219 T _totalError(const boxMapType & elements);
220
221 T _maxError( const boxMapType & elements);
222
223 void _addAndMark( HBox & box , HBoxContainer & elMarked) const;
224 void _addAndMark( typename HBox::Container & boxes, HBoxContainer & elMarked) const;
225
226 void _setContainerProperties( typename HBox::Container & boxes ) const;
227
228 HBox * _boxPtr(const HBox & box) const;
229
230 typename gsAdaptiveMeshing<T>::HBoxContainer _toContainer( const std::vector<bool> & bools) const;
231
232protected:
233 // M & m_basis;
234 gsFunctionSet<T> * m_input;
235 // const gsMultiPatch<T> & m_patches;
236 gsOptionList m_options;
237
238 T m_crsParam, m_crsParamExtra, m_refParam, m_refParamExtra;
239 MarkingStrategy m_crsRule, m_refRule;
240 index_t m_crsExt, m_refExt;
241 index_t m_maxLvl;
242
243 index_t m_alpha, m_beta;
244
245 index_t m_m;
246
247 bool m_admissible;
248
249 index_t m_verbose;
250
251 HBoxContainer m_markedRef, m_markedCrs;
252 // m_boxes is a container that does not contain patch IDs
253
254 indexMapType m_indices;
255 boxMapType m_boxes;
256
257 T m_totalError, m_maxError, m_uniformRefError, m_uniformCrsError;
258
259 std::vector<index_t> m_refPermutation, m_crsPermutation;
260
261 /*
262 The plan:
263 Make std::map<box,index> m_indices
264 Make std::map<index,box*> m_boxes
265 Which can be used to obtain the index of a box via m_indices[box] = index
266 And to obtain the box corresponding to an index m_boxes[index] = *box
267 THe latter can be used to obtain the neighborhood etc.
268
269 */
270
271 // std::map<index_t,std::shared_ptr<gsHBox<d,T>>> m_toindices;
272 // std::map<std::shared_ptr<gsHBox<d,T>>,index_t> m_fromindices;
273
274
275};
276
277} // namespace gismo
278
279#ifndef GISMO_BUILD_LIB
280#include GISMO_HPP_HEADER(gsAdaptiveMeshing.hpp)
281#else
282#ifdef gsAdaptiveMeshing_EXPORT
283#include GISMO_HPP_HEADER(gsAdaptiveMeshing.hpp)
284#undef EXTERN_CLASS_TEMPLATE
285#define EXTERN_CLASS_TEMPLATE CLASS_TEMPLATE_INST
286#endif
287namespace gismo
288{
289 EXTERN_CLASS_TEMPLATE gsAdaptiveMeshing<real_t>;
290 // EXTERN_CLASS_TEMPLATE gsHBoxCheck<1,real_t>;
291 // EXTERN_CLASS_TEMPLATE gsHBoxCheck<2,real_t>;
292 // EXTERN_CLASS_TEMPLATE gsHBoxCheck<3,real_t>;
293 // EXTERN_CLASS_TEMPLATE gsHBoxCheck<4,real_t>;
294
295 // EXTERN_CLASS_TEMPLATE gsLvlCompare<1,real_t>;
296 // EXTERN_CLASS_TEMPLATE gsLvlCompare<2,real_t>;
297 // EXTERN_CLASS_TEMPLATE gsLvlCompare<3,real_t>;
298 // EXTERN_CLASS_TEMPLATE gsLvlCompare<4,real_t>;
299
300 // EXTERN_CLASS_TEMPLATE gsSmallerErrCompare<1,real_t>;
301 // EXTERN_CLASS_TEMPLATE gsSmallerErrCompare<2,real_t>;
302 // EXTERN_CLASS_TEMPLATE gsSmallerErrCompare<3,real_t>;
303 // EXTERN_CLASS_TEMPLATE gsSmallerErrCompare<4,real_t>;
304
305 // EXTERN_CLASS_TEMPLATE gsLargerErrCompare<1,real_t>;
306 // EXTERN_CLASS_TEMPLATE gsLargerErrCompare<2,real_t>;
307 // EXTERN_CLASS_TEMPLATE gsLargerErrCompare<3,real_t>;
308 // EXTERN_CLASS_TEMPLATE gsLargerErrCompare<4,real_t>;
309
310 // EXTERN_CLASS_TEMPLATE gsOverlapCompare<1,real_t>;
311 // EXTERN_CLASS_TEMPLATE gsOverlapCompare<2,real_t>;
312 // EXTERN_CLASS_TEMPLATE gsOverlapCompare<3,real_t>;
313 // EXTERN_CLASS_TEMPLATE gsOverlapCompare<4,real_t>;
314}
315#endif
Provides adaptive meshing routines.
Definition gsAdaptiveMeshing.h:42
Interface for the set of functions defined on a domain (the total number of functions in the set equa...
Definition gsFunctionSet.h:219
Base class for performing checks on gsHBox objects.
Definition gsAdaptiveMeshingCompare.h:32
The Hierarchical Box Container provides a container for gsHBox objects.
Definition gsHBoxContainer.h:40
This class provides a Hierarchical Box (gsHBox)
Definition gsHBox.h:55
Class which holds a list of parameters/options, and provides easy access to them.
Definition gsOptionList.h:33
void _markElements(const std::vector< T > &elError, const index_t refCriterion, const std::vector< gsHBoxCheck< 2, T > * > &predicates, HBoxContainer &elMarked) const
Marks elements/cells for refinement.
Definition gsAdaptiveMeshing.hpp:201
Provides class for adaptive refinement.
#define index_t
Definition gsConfig.h:32
Provides a container for gsHBox.
Provides utility functions for gsHBox and gsHBoxContainer.
Provides gsHBox: smart boxes for HTensorBases.
Provides declaration of MultiBasis class.
Provides declaration of the MultiPatch class.
Provides a list of labeled parameters/options that can be set and accessed easily.
The G+Smo namespace, containing all definitions for the library.
The gsHBoxUtils provide basic utilities to modify HBoxes.
Definition gsHBoxUtils.h:46