Hermes2D  2.0
traverse.h
1 // This file is part of Hermes2D.
2 //
3 // Hermes2D is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 2 of the License, or
6 // (at your option) any later version.
7 //
8 // Hermes2D is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with Hermes2D. If not, see <http://www.gnu.org/licenses/>.
15 
16 #ifndef __H2D_TRAVERSE_H
17 #define __H2D_TRAVERSE_H
18 
19 #include "hermes_common.h"
20 
21 namespace Hermes
22 {
23  namespace Hermes2D
24  {
25  namespace Views{
26  class Orderizer;
27  class Linearizer;
28  class Vectorizer;
29  };
30 
35 
36 
37 
38 
39 
40  struct SurfPos
41  {
42  int marker;
43  int surf_num;
44 
46 
47  int v1, v2;
48  double t;
49  double lo, hi;
50  };
51 
52  class Mesh;
53  class Transformable;
54  struct State;
55  struct Rect;
56 
58  struct UniData
59  {
60  Element* e;
61  uint64_t idx;
62  };
63 
65  static const uint64_t ONE = (uint64_t) 1 << 63;
66 
68  struct Rect
69  {
70  uint64_t l, b, r, t;
71  };
72 
78  class HERMES_API Traverse : public Hermes::Mixins::Loggable
79  {
80  public:
81  Traverse(bool master = false);
82  private:
83  class State
84  {
85  public:
86  Element** e;
87  bool bnd[H2D_MAX_NUMBER_EDGES];
88  bool isBnd;
89  Element* rep;
90  ~State();
91  private:
92  State();
93  void operator=(const State * other);
94  void push_transform(int son, int i, bool is_triangle = false);
95  uint64_t get_transform(int i);
96  bool visited;
97  uint64_t* sub_idx;
98  Rect cr;
99  Rect* er;
100  int num;
101  int isurf;
102  friend class Traverse;
103  friend class Views::Linearizer;
104  friend class Views::Vectorizer;
105  template<typename Scalar> friend class DiscreteProblem;
106  template<typename Scalar> friend class DiscreteProblemLinear;
107  };
108 
109  void begin(int n, const Mesh** meshes, Transformable** fn = NULL);
110  void finish();
111 
112  State* get_next_state(int* top_by_ref = NULL, int* id_by_ref = NULL);
113  int get_num_states(Hermes::vector<const Mesh*> meshes);
114  inline Element* get_base() const { return base; }
115 
116  void init_transforms(State* s, int i);
117 
118  UniData** construct_union_mesh(Mesh* unimesh);
119 
120  int num;
121  const Mesh** meshes;
122  Transformable** fn;
123 
124  State* stack;
125  int top, size;
126 
127  int id;
128  bool tri;
129  Element* base;
130  int4* sons;
131  uint64_t* subs;
132 
133  UniData** unidata;
134  int udsize;
135 
136  State* push_state(int* top_by_ref = NULL);
137  void set_boundary_info(State* s);
138  void union_recurrent(Rect* cr, Element** e, Rect* er, uint64_t* idx, Element* uni);
139  uint64_t init_idx(Rect* cr, Rect* er);
140 
141  void free_state(State* state);
142 
143  bool master;
144 
145  Mesh* unimesh;
146  template<typename T> friend class Adapt;
147  template<typename T> friend class KellyTypeAdapt;
148  template<typename T> friend class DiscreteProblem;
149  template<typename T> friend class DiscreteProblemLinear;
150  template<typename T> friend class Filter;
151  template<typename T> friend class SimpleFilter;
152  template<typename T> friend class Global;
153  friend class Views::Orderizer;
154  friend class Views::Vectorizer;
155  friend class Views::Linearizer;
156  };
157  }
158 }
159 #endif