Hermes2D  3.0
optimum_selector.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_REFINEMENT_OPTIMUM_SELECTOR_H
17 #define __H2D_REFINEMENT_OPTIMUM_SELECTOR_H
18 
19 #include <ostream>
20 #include "selector.h"
21 #include "../shapeset/shapeset.h"
22 #include "candidates.h"
23 
24 namespace Hermes
25 {
26  namespace Hermes2D
27  {
28  namespace RefinementSelectors
29  {
31 
33  template<typename Scalar>
34  class HERMES_API OptimumSelector : public Selector < Scalar >
35  {
36  public:
38  virtual ~OptimumSelector();
39 
41  void set_dof_score_exponent(double exponent);
42 
43  protected:
45 
51  OptimumSelector(CandList cand_list, int max_order, Shapeset* shapeset, const Range& vertex_order, const Range& edge_bubble_order);
52 
53  //candidates
55  struct CandsInfo
56  {
63 
65  CandsInfo() : uniform_orders(true), min_quad_order(-1), max_quad_order(-1) {};
66 
68 
69  bool is_empty() const { return (min_quad_order < 0 || max_quad_order < 0); };
70  };
71 
74 
76 
79  void update_cands_info(std::vector<Cand>& candidates, CandsInfo& info_h, CandsInfo& info_p, CandsInfo& info_aniso) const;
80 
82 
88  void append_candidates_split(std::vector<Cand>& candidates, const int start_quad_order, const int last_order, const RefinementType split, bool iso_p);
89 
91 
100  virtual std::vector<Cand> create_candidates(Element* e, int quad_order);
101 
103 
107  void evaluate_candidates(std::vector<Cand>& candidates, Element* e, MeshFunction<Scalar>* rsln);
108 
110 
124  virtual void select_best_candidate(std::vector<Cand>& candidates, Element* e, Cand*& best_candidate, Cand* best_candidates_specific_type[4]);
125 
127 
131  virtual void evaluate_cands_error(std::vector<Cand>& candidates, Element* e, MeshFunction<Scalar>* rsln) = 0;
132 
134 
138  virtual void evaluate_cands_dof(std::vector<Cand>& candidates, Element* e, MeshFunction<Scalar>* rsln);
139 
141 
149  virtual void evaluate_cands_score(std::vector<Cand>& candidates, Element* e);
150 
156  int ****num_shapes;
157 
159 
162  static bool compare_cand_score(const Cand& a, const Cand& b);
163 
164  //orders and their range
166 
169  virtual void get_current_order_range(Element* element, int& min_order, int& max_order) = 0;
170 
171  //shape functions
173  enum ShapeType {
174  H2DST_VERTEX = 0x01,
175  H2DST_HORIZ_EDGE = 0x02,
176  H2DST_VERT_EDGE = 0x04,
177  H2DST_TRI_EDGE = 0x08,
178  H2DST_BUBBLE = 0x10
179  };
180 
181  enum ShapeTypeInt {
182  H2DSI_VERTEX,
183  H2DSI_HORIZ_EDGE,
184  H2DSI_VERT_EDGE,
185  H2DSI_TRI_EDGE,
186  H2DSI_BUBBLE,
187  H2DSI_ANY
188  };
189 
191 
192  struct ShapeInx {
194  int order_h;
196  int order_v;
198  int inx;
201 
203 
207  ShapeInx(int order_h, int order_v, int inx, ShapeType type) : order_h(order_h), order_v(order_v), inx(inx), type(type) {};
208  };
209 
212 
214  std::vector<ShapeInx> shape_indices[H2D_NUM_MODES];
216  int max_shape_inx[H2D_NUM_MODES];
218  int next_order_shape[H2D_NUM_MODES][H2DRS_MAX_ORDER + 1];
220  bool has_vertex_shape[H2D_NUM_MODES];
222  bool has_edge_shape[H2D_NUM_MODES];
224  bool has_bubble_shape[H2D_NUM_MODES];
225 
227 
236  void add_bubble_shape_index(int order_h, int order_v, std::map<int, bool>& used_shape_index, std::vector<ShapeInx>& indices, ElementMode2D mode);
237 
239 
244  void build_shape_indices(const ElementMode2D mode, const Range& vertex_order, const Range& edge_bubble_order);
245 
247 
252  int calc_num_shapes(int mode, int order_h, int order_v, int allowed_type_mask);
253 
255 
256  virtual bool select_refinement(Element* element, int quad_order, MeshFunction<Scalar>* rsln, ElementToRefine& refinement);
258 
261  };
262  }
263  }
264 }
265 
266 #endif
Definition: adapt.h:24
int order_v
A minimal vertical order of an element that can use this shape function.
Stores one element of a mesh.
Definition: element.h:107
CandsInfo()
Default constructor. Creates info that declares no candidates and uniform orders. ...
bool uniform_orders
True if all elements of all examined candidates have uniform orders.
#define H2DRS_MAX_ORDER
A maximum order suported by refinement selectors.
Definition: global.h:104
Represents a function defined on a mesh.
Definition: mesh_function.h:56
ShapeType type
A type of the shape function. It is used to calculate DOF in Optimum::evaluate_cands_dof().
RefinementType
Possible refinements of an element.
double dof_score_exponent
Score DOF exponent. Used in evaluate_cands_score.
ShapeInx(int order_h, int order_v, int inx, ShapeType type)
Constructor.
#define H2D_NUM_MODES
Internal.
Definition: global.h:35
CandList
Predefined list of candidates.
Definition: candidates.h:46
int min_quad_order
Minimum quad order of all elements of all examined candidates.
Shapeset * shapeset
A shapeset used to calculate error.
Should be exactly the same as is the count of enum ShapesetType.
Definition: shapeset.h:95
int max_quad_order
Maximum quad order of all elements of all examined candidates. If less than zero, no candidate is gen...
int order_h
A minimal horizonal order of an element that can use this shape function.
bool is_empty() const
Returns true if there are no candidates.