Hermes2D  3.0
neighbor_search.h
1 #ifndef __H2D_NEIGHBOR_H
2 #define __H2D_NEIGHBOR_H
3 
4 #include "mesh/mesh.h"
5 #include "quadrature/quad.h"
6 #include "function/solution.h"
7 #include "forms.h"
8 #include "mesh/refmap.h"
9 #include "asmlist.h"
10 #include "space/space.h"
11 #include "adapt/error_thread_calculator.h"
12 
13 namespace Hermes
14 {
15  namespace Hermes2D
16  {
17  template<typename Scalar> class ErrorThreadCalculator;
18 
19  /*** Class NeighborSearch. ***/
20 
71  template<typename Scalar>
72  class HERMES_API NeighborSearch
73  {
74  public:
75 
81  NeighborSearch(Element* el, MeshSharedPtr mesh);
82  NeighborSearch(const NeighborSearch& ns);
83 
85  ~NeighborSearch();
86 
87  void free();
88 
89  /*** Methods for changing active state for further calculations. ***/
90 
111  void set_active_edge(int edge);
112 
114  bool set_active_edge_multimesh(const int& edge);
115 
117  std::vector<unsigned int> get_transforms(uint64_t sub_idx) const;
118 
120  bool is_inter_edge(const int& edge, const std::vector<unsigned int>& transformations) const;
121 
123  void update_according_to_sub_idx(const std::vector<unsigned int>& transformations);
124 
126  void handle_sub_idx_way_down(const std::vector<unsigned int>& transformations);
127 
130  bool compatible_transformations(unsigned int a, unsigned int b, int edge) const;
131 
134  void clear_initial_sub_idx();
135 
137  void delete_neighbor(unsigned int position);
138 
145  DiscontinuousFunc<Scalar>* init_ext_fn(MeshFunction<Scalar>* fu);
146 
151 
162  ExtendedShapeset* create_extended_asmlist(SpaceSharedPtr<Scalar> space, AsmList<Scalar>* al);
163  ExtendedShapeset* create_extended_asmlist_multicomponent(SpaceSharedPtr<Scalar> space, AsmList<Scalar>* al);
164 
165  /*** Methods for working with quadrature on the active edge. ***/
166 
171  void set_quad_order(int order);
172 
178  int get_quad_eo(bool on_neighbor = false) const;
179 
180  /*** Methods for retrieving additional information about the neighborhood. ***/
181 
186  int get_num_neighbors() const;
187 
192  const std::vector<Element*>* get_neighbors() const;
193 
195  void clear_supported_shapes();
196 
198  void set_ignore_errors(bool value);
199 
203  {
204  public:
212 
213  ExtendedShapeset(const ExtendedShapeset & other);
214 
216  ~ExtendedShapeset();
217 
218  void free_central_al();
219 
221  void combine_assembly_lists();
222 
228  void update(NeighborSearch* neighborhood, SpaceSharedPtr<Scalar> space);
229 
230  public:
232  int cnt;
234  int *dof;
235 
236  bool has_support_on_neighbor(unsigned int index) const;
237 
242 
243  // Only a NeighborSearch is allowed to create an ExtendedShapeset.
244  friend class NeighborSearch;
245  };
246 
247  /*** Neighborhood information. ***/
250  {
251  public:
252  NeighborEdgeInfo() : local_num_of_edge(-1), orientation(false) {};
253 
255  int local_num_of_edge;
259  };
260 
264 
266  int get_active_segment() const;
267 
269  void set_active_segment(unsigned int index);
270 
272  Element* get_neighb_el() const;
273 
275  NeighborEdgeInfo get_neighbor_edge() const;
276 
278  unsigned int get_central_n_trans(unsigned int index) const;
279 
281  unsigned int get_central_transformations(unsigned int index_1, unsigned int index_2) const;
282 
284  unsigned int get_neighbor_n_trans(unsigned int index) const;
285 
287  unsigned int get_neighbor_transformations(unsigned int index_1, unsigned int index_2) const;
288 
290  class HERMES_API Transformations
291  {
292  public:
294  static const int max_level = Transformable::H2D_MAX_TRN_LEVEL;
296 
298  unsigned int transf[max_level];
300  unsigned int num_levels;
301 
302  Transformations();
304  void operator=(const Transformations* t);
305  Transformations(const std::vector<unsigned int>& t);
306 
307  void copy_from(const std::vector<unsigned int>& t);
308 
309  void copy_from(const Transformations* t);
310 
311  void copy_to(std::vector<unsigned int>* t);
312 
313  void reset();
314 
315  void strip_initial_transformations(unsigned int number_of_stripped);
316 
317  void apply_on(Transformable* tr) const;
318 
319  void apply_on(const std::vector<Transformable*>& tr) const;
320 
321  template<typename T> friend class NeighborSearch;
322  template<typename T> friend class KellyTypeAdapt;
323  template<typename T> friend class Adapt;
324  template<typename T> friend class Func;
325  template<typename T> friend class DiscontinuousFunc;
326  template<typename T> friend class MultimeshDGNeighborTree;
327  };
328 
329  MeshSharedPtr mesh;
330 
331  /*** Transformations. ***/
332  static const unsigned int H2D_INITIAL_NEIGHBOR_NUMBER_GUESS = 32;
333 
338 
339  void add_central_transformations(Transformations* to_add, int position, bool replace = false);
340  unsigned int central_transformations_size;
341  unsigned int central_transformations_alloc_size;
344 
345  void add_neighbor_transformations(Transformations* to_add, int position, bool replace = false);
346  unsigned int neighbor_transformations_size;
347  unsigned int neighbor_transformations_alloc_size;
351 
352  /*** Significant objects of the neighborhood. ***/
357 
358  private:
360  int active_edge;
362  NeighborEdgeInfo neighbor_edge;
364  int active_segment;
365 
367  std::vector<NeighborEdgeInfo> neighbor_edges;
369  std::vector<Element*> neighbors;
371  unsigned int n_neighbors;
372 
376  enum NeighborhoodType
377  {
378  H2D_DG_NOT_INITIALIZED = -1,
379  H2D_DG_NO_TRANSF = 0,
380  H2D_DG_GO_DOWN = 1,
382  H2D_DG_GO_UP = 2
384  };
386  NeighborhoodType neighborhood_type;
387 
403  void find_act_elem_up(Element* elem, int* orig_vertex_id, Node** par_mid_vertices, int n_parents);
404 
421  void find_act_elem_down(Node* vertex, int* bounding_verts_id, int* sons, unsigned int n_sons);
422 
441  bool neighbor_edge_orientation(int bounding_vert1, int bounding_vert2, int segment) const;
442 
444  void reset_neighb_info();
445 
446  /*** Quadrature on the active edge. ***/
447  Quad2D* quad;
448 
450  int central_quad_order;
452  int neighb_quad_order;
453 
454  template<typename T> friend class KellyTypeAdapt;
455  template<typename T> friend class Adapt;
456  template<typename T> friend class Func;
457  template<typename T> friend class DiscontinuousFunc;
458  template<typename T> friend class MultimeshDGNeighborTree;
459  template<typename T> friend class DiscreteProblemDGAssembler;
460  template<typename T> friend class DiscreteProblemIntegrationOrderCalculator;
461  template<typename T> friend class ErrorThreadCalculator<T>::DGErrorCalculator;
462  };
463  }
464 }
465 #endif
ExtendedShapeset * supported_shapes
Object allowing to set/get a particular shape function from the extended.
Definition: adapt.h:24
Stores one element of a mesh.
Definition: element.h:107
This class represents a function with jump discontinuity on an interface of two elements.
Definition: forms.h:335
Element * neighb_el
Currently selected neighbor element (on the other side of active segment).
Element * central_el
Central (currently assembled) element.
Used to pass the instances of Space around.
Definition: space.h:34
Stores one node of a mesh.
Definition: element.h:45
Transformations ** central_transformations
Array of transformations of the central element to each neighbor.
uint64_t original_central_el_transform
Sub-element transformation of any function that comes from the.
unsigned int num_levels
Number of transformation levels actually used in transf.
int cnt
Number of shape functions in the extended shapeset.
Transformations of an element to one of its neighbors.
int * dof
Array of global DOF numbers of shape functions in the extended shapeset.
static const unsigned int H2D_MAX_TRN_LEVEL
If this changes, NeighborSearch::H2D_MAX_NEIGHBORS must change too.
Definition: transformable.h:71
Transformations ** neighbor_transformations
Array of transformations of the neighbor to the central element (go-up).
AsmList< Scalar > * central_al
Assembly list for the currently assembled edge on the central elem.
This class characterizes a neighborhood of a given edge in terms of adjacent elements and provides me...
AsmList< Scalar > * neighbor_al
Assembly list for the currently assembled edge on the neighbor elem.
bool orientation
Relative orientation of the neighbor edge with respect to the active edge.
Structure containing all the needed information about the active edge from the neighbor's side...