Hermes2D  3.0
Hermes::Hermes2D::RefinementSelectors::OptimumSelector< Scalar > Singleton Referenceabstract

A selector that chooses an optimal candidates based on a score. More...

#include <optimum_selector.h>

+ Inheritance diagram for Hermes::Hermes2D::RefinementSelectors::OptimumSelector< Scalar >:

Classes

struct  CandsInfo
 Information about candidates. More...
 
struct  ShapeInx
 A shape index. More...
 

Public Member Functions

virtual ~OptimumSelector ()
 Destructor.
 
void set_dof_score_exponent (double exponent)
 Set the score DOF exponent.
 

Protected Types

enum  ShapeType {
  H2DST_VERTEX = 0x01, H2DST_HORIZ_EDGE = 0x02, H2DST_VERT_EDGE = 0x04, H2DST_TRI_EDGE = 0x08,
  H2DST_BUBBLE = 0x10
}
 A shape function type. More...
 
enum  ShapeTypeInt {
  H2DSI_VERTEX, H2DSI_HORIZ_EDGE, H2DSI_VERT_EDGE, H2DSI_TRI_EDGE,
  H2DSI_BUBBLE, H2DSI_ANY
}
 

Protected Member Functions

 OptimumSelector (CandList cand_list, int max_order, Shapeset *shapeset, const Range &vertex_order, const Range &edge_bubble_order)
 Constructor. More...
 
void update_cands_info (std::vector< Cand > &candidates, CandsInfo &info_h, CandsInfo &info_p, CandsInfo &info_aniso) const
 Updates information about candidates. Initial information is provided. More...
 
void append_candidates_split (std::vector< Cand > &candidates, const int start_quad_order, const int last_order, const RefinementType split, bool iso_p)
 Appends cancidates of a given refinement and a given range of orders. More...
 
virtual std::vector< Candcreate_candidates (Element *e, int quad_order)
 Fill a list of candidates. More...
 
void evaluate_candidates (std::vector< Cand > &candidates, Element *e, MeshFunction< Scalar > *rsln)
 Calculates error, dofs, and score of candidates. More...
 
virtual void select_best_candidate (std::vector< Cand > &candidates, Element *e, Cand *&best_candidate, Cand *best_candidates_specific_type[4])
 Sorts and selects the best candidate and the best H-candidate according to the score. More...
 
virtual void evaluate_cands_error (std::vector< Cand > &candidates, Element *e, MeshFunction< Scalar > *rsln)=0
 Calculates error of candidates. More...
 
virtual void evaluate_cands_dof (std::vector< Cand > &candidates, Element *e, MeshFunction< Scalar > *rsln)
 Calculates DOF of candidates. More...
 
virtual void evaluate_cands_score (std::vector< Cand > &candidates, Element *e)
 Evalutes score of candidates. More...
 
virtual void get_current_order_range (Element *element, int &min_order, int &max_order)=0
 Sets OptimumSelector::current_max_order and OptimumSelector::current_min_order. More...
 
void add_bubble_shape_index (int order_h, int order_v, std::map< int, bool > &used_shape_index, std::vector< ShapeInx > &indices, ElementMode2D mode)
 Adds an index (or indices) of a bubble function of a given order if the shape index was not used yet. More...
 
void build_shape_indices (const ElementMode2D mode, const Range &vertex_order, const Range &edge_bubble_order)
 Builds shape index table OptimumSelector::shape_indices. More...
 
int calc_num_shapes (int mode, int order_h, int order_v, int allowed_type_mask)
 Returns a number of shapes that may be contained in an element of a given order. More...
 
virtual bool select_refinement (Element *element, int quad_order, MeshFunction< Scalar > *rsln, ElementToRefine &refinement)
 Selects a refinement. More...
 
- Protected Member Functions inherited from Hermes::Hermes2D::RefinementSelectors::Selector< Scalar >
 Selector (int min_order=1, int max_order=H2DRS_DEFAULT_ORDER)
 Constructor. More...
 

Static Protected Member Functions

static bool compare_cand_score (const Cand &a, const Cand &b)
 Compares scores. Used to sort scores ascending. More...
 

Protected Attributes

CandList cand_list
 Allowed candidate types.
 
int **** num_shapes
 
Shapesetshapeset
 A shapeset used to calculate error.
 
std::vector< ShapeInxshape_indices [H2D_NUM_MODES]
 Shape indices. The first index is a mode (ElementMode2D).
 
int max_shape_inx [H2D_NUM_MODES]
 A maximum index of a shape function. The first index is a mode (ElementMode2D).
 
int next_order_shape [H2D_NUM_MODES][H2DRS_MAX_ORDER+1]
 An index to the array OptimumSelector::shape_indices of a shape function of the next uniform order. The first index is a mode (ElementMode2D), the second index is an order.
 
bool has_vertex_shape [H2D_NUM_MODES]
 True if the shapeset OptimumSelector::shapeset contains vertex functions. The index is a mode (ElementMode2D).
 
bool has_edge_shape [H2D_NUM_MODES]
 True if the shapeset OptimumSelector::shapeset contains edge functions. The index is a mode (ElementMode2D).
 
bool has_bubble_shape [H2D_NUM_MODES]
 True if the shapeset OptimumSelector::shapeset contains bubble functions. The index is a mode (ElementMode2D).
 
double dof_score_exponent
 Score DOF exponent. Used in evaluate_cands_score.
 
- Protected Attributes inherited from Hermes::Hermes2D::RefinementSelectors::Selector< Scalar >
const int min_order
 A minimum allowed order.
 
const int max_order
 A maximum allowed order.
 

Detailed Description

template<typename Scalar>
singleton Hermes::Hermes2D::RefinementSelectors::OptimumSelector< Scalar >

A selector that chooses an optimal candidates based on a score.

This is a base class for all selectors that chooses an candidate based on some evaluated criteria. Currently, the criteria is based on an error change per DOF.

Definition at line 32 of file function.h.

Constructor & Destructor Documentation

template<typename Scalar >
Hermes::Hermes2D::RefinementSelectors::OptimumSelector< Scalar >::OptimumSelector ( CandList  cand_list,
int  max_order,
Shapeset shapeset,
const Range &  vertex_order,
const Range &  edge_bubble_order 
)
protected

Constructor.

Note
Parameters vertex_order and edge_bubble_order fixes the fact that a shapeset returns a valid index even though a given shape is not invalid in the space.
Parameters
[in]cand_listA predefined list of candidates.
[in]max_orderA maximum order which considered. If H2DRS_DEFAULT_ORDER, a maximum order supported by the selector is used.
[in]shapesetA shapeset. It cannot be nullptr.
[in]vertex_orderA range of orders for vertex functions. Use an empty range (i.e. Range()) to skip vertex functions.
[in]edge_bubble_orderA range of orders for edge and bubble functions. Use an empty range (i.e. Range()) to skip edge and bubble functions.

Why H2DRS_MAX_ORDER + 3? Because H2DRS_MAX_ORDER ( = 9 ) is the max order refinement selectors support (

Todo:
verify the purpose of this). But we need to know number of shapes for polynomial degrees 0, ..., 10 ( = 11 ) + 1 special (any order - at 0th position).

Definition at line 15 of file optimum_selector.cpp.

Member Function Documentation

template<typename Scalar >
void Hermes::Hermes2D::RefinementSelectors::OptimumSelector< Scalar >::add_bubble_shape_index ( int  order_h,
int  order_v,
std::map< int, bool > &  used_shape_index,
std::vector< ShapeInx > &  indices,
ElementMode2D  mode 
)
protected

Adds an index (or indices) of a bubble function of a given order if the shape index was not used yet.

This function adds indices of bubble functions that were not added yet on a quadrilateral. Since a shapeset allows only to retrieve a list of all possible bubbles based on an order of an element, this functions allows to create a back-mapping table which converts shape index to the smallest element order that uses the shape function. The function assumes that all shapes of a lower element order than a given combinations were already added. Used by build_shape_indices().

Parameters
[in]order_hA horizontal order of an element.
[in]order_vA vertical order of an element.
[in,out]used_shape_indexA vector of used shape indices. If a shape index is present in the map, a shape was already added and it will not be added again.
[in,out]indicesA vector of shape indices. The vector is updated by the function.

Definition at line 64 of file optimum_selector.cpp.

template<typename Scalar >
void Hermes::Hermes2D::RefinementSelectors::OptimumSelector< Scalar >::append_candidates_split ( std::vector< Cand > &  candidates,
const int  start_quad_order,
const int  last_order,
const RefinementType  split,
bool  iso_p 
)
protected

Appends cancidates of a given refinement and a given range of orders.

If either borders or a ranges is invalid (i.e. smaller than zero) or if a upper boundary is below the lower boudary, no candidate is appended.

Parameters
[in]start_quad_orderA lower boundary of a range in a form of an encoded order.
[in]last_orderThe upper boundery of a range in a form of an encoded order.
[in]splitA refinement, see the enum RefinementTypes.
[in]iso_pTrue if both orders (horizontal and vertical) should be modified uniformly. Used in a case of a triangle.

Definition at line 305 of file optimum_selector.cpp.

template<typename Scalar >
void Hermes::Hermes2D::RefinementSelectors::OptimumSelector< Scalar >::build_shape_indices ( const ElementMode2D  mode,
const Range &  vertex_order,
const Range &  edge_bubble_order 
)
protected

Builds shape index table OptimumSelector::shape_indices.

The method fills the array OptimumSelector::shape_indices for a given mode. The method is called by the constructor.

Parameters
[in]modeA mode (ElementMode2D).
[in]vertex_orderA range of orders in which to search for vertex functions.
[in]edge_bubble_orderA range of order in which to search for edge and bubble functions.

Definition at line 89 of file optimum_selector.cpp.

Referenced by Hermes::Hermes2D::RefinementSelectors::OptimumSelector< Scalar >::OptimumSelector().

template<typename Scalar >
int Hermes::Hermes2D::RefinementSelectors::OptimumSelector< Scalar >::calc_num_shapes ( int  mode,
int  order_h,
int  order_v,
int  allowed_type_mask 
)
protected

Returns a number of shapes that may be contained in an element of a given order.

Parameters
[in]modeA mode (ElementMode2D).
[in]order_hA horizontal order of the element. If H2DRS_ORDER_ANY, any order is allowed.
[in]order_vA horizontal order of the element. If H2DRS_ORDER_ANY, any order is allowed.
[in]allowed_type_maskA combination of flags specifying which orders are allowed. Flags are defined in the enum ShapeType.
Returns
Returns a number of shape functions that satisfies given parameters.

Definition at line 272 of file optimum_selector.cpp.

template<typename Scalar >
bool Hermes::Hermes2D::RefinementSelectors::OptimumSelector< Scalar >::compare_cand_score ( const Cand a,
const Cand b 
)
staticprotected

Compares scores. Used to sort scores ascending.

Parameters
[in]aThe first candidate.
[in]bThe second candidate.
Returns
True if score of a is greater than the score of b.

Definition at line 594 of file optimum_selector.cpp.

template<typename Scalar >
std::vector< Cand > Hermes::Hermes2D::RefinementSelectors::OptimumSelector< Scalar >::create_candidates ( Element e,
int  quad_order 
)
protectedvirtual

Fill a list of candidates.

Override to generate or adjust generated candidates. The method has to initialize the array OptimumSelector::candidates. If triangle, all generated candidates have to have the vertical order equal to the horizontal order. An order of any element of any candidate has to fit into a range[OptimumSelector::current_min_order, OptimumSelector::current_max_order].

Parameters
[in]eAn element that is being refined.
[in]quad_orderAn encoded order of the element. If triangle, the vertical order is equal to the horizontal order.
[in]max_ha_quad_orderA maximum encoded order of an element of a H-candidate or an ANISO-candidate. In the case of ANIO-candidates, the maximum is applied only to modified orders.
[in]max_p_quad_orderA maximum encoded order of an element of a P-candidate.
Returns
A vector of candidates. The first candidate has to be equal to the original element with a refinement H2D_REFINEMENT_P.
Todo:
Find and why is iro_cache compared with the number 8. What does the number 8 mean?

Definition at line 352 of file optimum_selector.cpp.

template<typename Scalar >
void Hermes::Hermes2D::RefinementSelectors::OptimumSelector< Scalar >::evaluate_candidates ( std::vector< Cand > &  candidates,
Element e,
MeshFunction< Scalar > *  rsln 
)
protected

Calculates error, dofs, and score of candidates.

Parameters
[in]eAn element that is being refined.
[in]rslnA reference solution which is used to calculate the error.
[out]avg_errorAn average of $\log_{10} e$ where $e$ is an error of a candidate. It cannot be nullptr.
[out]dev_errorA deviation of $\log_{10} e$ where $e$ is an error of a candidate. It cannot be nullptr.

Definition at line 558 of file optimum_selector.cpp.

template<typename Scalar >
void Hermes::Hermes2D::RefinementSelectors::OptimumSelector< Scalar >::evaluate_cands_dof ( std::vector< Cand > &  candidates,
Element e,
MeshFunction< Scalar > *  rsln 
)
protectedvirtual

Calculates DOF of candidates.

It uses a list of shape indices (OptimumSelector::shape_indices) to count a number of DOFs. No number of DOFs cannot be zero.

Parameters
[in]eAn element that is being refined.
[in]rslnA reference solution which is used to calculate the error.

Definition at line 470 of file optimum_selector.cpp.

template<typename Scalar >
virtual void Hermes::Hermes2D::RefinementSelectors::OptimumSelector< Scalar >::evaluate_cands_error ( std::vector< Cand > &  candidates,
Element e,
MeshFunction< Scalar > *  rsln 
)
protectedpure virtual

Calculates error of candidates.

This method has to be implemented in inherited classes.

Parameters
[in]eAn element that is being refined.
[in]rslnA reference solution which is used to calculate the error.

Implemented in Hermes::Hermes2D::RefinementSelectors::ProjBasedSelector< Scalar >.

template<typename Scalar >
void Hermes::Hermes2D::RefinementSelectors::OptimumSelector< Scalar >::evaluate_cands_score ( std::vector< Cand > &  candidates,
Element e 
)
protectedvirtual

Evalutes score of candidates.

It calculates score $s$ of a candidate as

\[s = \frac{\log_{10} e_0 - \log_{10} e}{(d - d_0)^c},\]

where $e$ and $e_0$ are errors of a candidate and the original element (i.e. a candidate at the index 0) respectively, $d$ and $d_0$ are number of DOFs of a candidate and the original element (i.e. a candidate at the index 0) respectively. If the score is zero, the score is invalid.

If overridden, the higher score the better candidate.

Parameters
[in]eAn element that is being refined.

Definition at line 574 of file optimum_selector.cpp.

template<typename Scalar >
virtual void Hermes::Hermes2D::RefinementSelectors::OptimumSelector< Scalar >::get_current_order_range ( Element element,
int &  min_order,
int &  max_order 
)
protectedpure virtual

Sets OptimumSelector::current_max_order and OptimumSelector::current_min_order.

This method has to be implemented by derived classes and it is mean to be space dependent, i.e., it should differ in a case of H1, L2, and Hcurl.

Parameters
[in]elementAn element that is being refined.

Implemented in Hermes::Hermes2D::RefinementSelectors::HcurlProjBasedSelector< Scalar >, Hermes::Hermes2D::RefinementSelectors::H1ProjBasedSelector< Scalar >, and Hermes::Hermes2D::RefinementSelectors::L2ProjBasedSelector< Scalar >.

template<typename Scalar >
void Hermes::Hermes2D::RefinementSelectors::OptimumSelector< Scalar >::select_best_candidate ( std::vector< Cand > &  candidates,
Element e,
Cand *&  best_candidate,
Cand best_candidates_specific_type[4] 
)
protectedvirtual

Sorts and selects the best candidate and the best H-candidate according to the score.

Any two candidates with the same score are skipped since it is not possible to decide between them. The method assumes that the candidate at the index 0 is the original element therefore it skips this candidate. The selected H-candidate is used to handle a case when a mesh is shared amond multiple components.

Override to redefined the algoritm of the selecting. If overridden, the implementation has to select both the best candidate and the best H-candidate.

Parameters
[in]eAn element that is being refined.
[in]avg_errorAn average of $\log_{10} e$ where $e$ is an error of a candidate.
[in]dev_errorA deviation of $\log_{10} e$ where $e$ is an error of a candidate.
[out]best_candidatesFour best candidates \ 0 - overall 1 - 4 : indexed by enum RefinementType.

Definition at line 600 of file optimum_selector.cpp.

template<typename Scalar >
bool Hermes::Hermes2D::RefinementSelectors::OptimumSelector< Scalar >::select_refinement ( Element element,
int  quad_order,
MeshFunction< Scalar > *  rsln,
ElementToRefine refinement 
)
protectedvirtual

Selects a refinement.

Overriden function. For details, see Selector::select_refinement(). Selects refinement.

Implements Hermes::Hermes2D::RefinementSelectors::Selector< Scalar >.

Definition at line 654 of file optimum_selector.cpp.

template<typename Scalar >
void Hermes::Hermes2D::RefinementSelectors::OptimumSelector< Scalar >::update_cands_info ( std::vector< Cand > &  candidates,
CandsInfo info_h,
CandsInfo info_p,
CandsInfo info_aniso 
) const
protected

Updates information about candidates. Initial information is provided.

Parameters
[in,out]info_hInformation about all H-candidates.
[in,out]info_pInformation about all P-candidates.
[in,out]info_anisoInformation about all ANISO-candidates.

Definition at line 440 of file optimum_selector.cpp.

Referenced by Hermes::Hermes2D::RefinementSelectors::ProjBasedSelector< Scalar >::evaluate_cands_error().

Member Data Documentation

template<typename Scalar >
int**** Hermes::Hermes2D::RefinementSelectors::OptimumSelector< Scalar >::num_shapes
protected

Number of shape functions for

  • mode
  • horizontal order + 1 (any)
  • vertical order + 1 (any)
  • shape function type

Definition at line 156 of file optimum_selector.h.

Referenced by Hermes::Hermes2D::RefinementSelectors::ProjBasedSelector< Scalar >::calc_error_cand_element(), and Hermes::Hermes2D::RefinementSelectors::OptimumSelector< Scalar >::OptimumSelector().


The documentation for this singleton was generated from the following files: