Hermes2D  2.0
Hermes::Hermes2D::RefinementSelectors::OptimumSelector< Scalar > Class Template 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  Cand
 A candidate. More...
 
struct  CandsInfo
 Information about candidates. More...
 
class  Range
 Range of values. More...
 
struct  ShapeInx
 A shape index. More...
 

Public Member Functions

virtual void set_option (const SelOption option, bool enable)
 Enables or disables an option. More...
 
const Hermes::vector< Cand > & get_candidates () const
 Returns a vector of the last generated candidates. More...
 
virtual ~OptimumSelector ()
 Destructor.
 

Public Attributes

int **** num_shapes
 

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

void update_cands_info (CandsInfo &info_h, CandsInfo &info_p, CandsInfo &info_aniso) const
 Updates information about candidates. Initial information is provided. More...
 
void append_candidates_split (const int start_quad_order, const int last_order, const int split, bool iso_p)
 Appends cancidates of a given refinement and a given range of orders. More...
 
virtual void create_candidates (Element *e, int quad_order, int max_ha_quad_order, int max_p_quad_order)
 Fill a list of candidates. More...
 
void evaluate_candidates (Element *e, Solution< Scalar > *rsln, double *avg_error, double *dev_error)
 Calculates error, dofs, and score of candidates. More...
 
virtual void select_best_candidate (Element *e, const double avg_error, const double dev_error, int *selected_cand, int *selected_h_cand)
 Sorts and selects the best candidate and the best H-candidate according to the score. More...
 
virtual void evaluate_cands_error (Element *e, Solution< Scalar > *rsln, double *avg_error, double *dev_error)=0
 Calculates error of candidates. More...
 
virtual void evaluate_cands_dof (Element *e, Solution< Scalar > *rsln)
 Calculates DOF of candidates. More...
 
virtual void evaluate_cands_score (Element *e)
 Evalutes score of candidates. More...
 
virtual void set_current_order_range (Element *element)=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, Hermes::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...
 
 OptimumSelector (CandList cand_list, double conv_exp, int max_order, Shapeset *shapeset, const Range &vertex_order, const Range &edge_bubble_order)
 Constructor. More...
 
virtual bool select_refinement (Element *element, int quad_order, Solution< Scalar > *rsln, ElementToRefine &refinement)
 Selects a refinement. More...
 
virtual void generate_shared_mesh_orders (const Element *element, const int orig_quad_order, const int refinement, int tgt_quad_orders[H2D_MAX_ELEMENT_SONS], const int *suggested_quad_orders)
 Generates orders of elements which will be created due to a proposed refinement in another component that shares the same a mesh. More...
 
- Protected Member Functions inherited from Hermes::Hermes2D::RefinementSelectors::Selector< Scalar >
 Selector (int max_order=H2DRS_DEFAULT_ORDER)
 Constructor. More...
 
virtual Selector< Scalar > * clone ()=0
 Cloning for paralelism.
 

Protected Attributes

bool opt_symmetric_mesh
 True if H2D_PREFER_SYMMETRIC_MESH is set. True by default.
 
bool opt_apply_exp_dof
 True if H2D_APPLY_CONV_EXP_DOF is set. False by default.
 
CandList cand_list
 Allowed candidate types.
 
double conv_exp
 Convergence power. Modifies difference between DOFs before they are used to calculate the score.
 
Hermes::vector< Candcandidates
 A vector of candidates. The first candidate has to be equal to the original element with a refinement ::H2D_REFINEMENT_P.
 
int current_max_order
 Current maximum order.
 
int current_min_order
 Current minimum order.
 
Shapesetshapeset
 A shapeset used to calculate error.
 
Hermes::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).
 
- Protected Attributes inherited from Hermes::Hermes2D::RefinementSelectors::Selector< Scalar >
const int max_order
 
bool isAClone
 Internal.
 

Detailed Description

template<typename Scalar>
class 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 33 of file function.h.

Member Enumeration Documentation

template<typename Scalar >
enum Hermes::Hermes2D::RefinementSelectors::OptimumSelector::ShapeType
protected

A shape function type.

Enumerator
H2DST_VERTEX 

Vertex function.

H2DST_HORIZ_EDGE 

Horizontal edge function.

H2DST_VERT_EDGE 

Verical edge function.

H2DST_TRI_EDGE 

Triangle edge.

H2DST_BUBBLE 

Bubble function.

Definition at line 252 of file optimum_selector.h.

Constructor & Destructor Documentation

template<typename Scalar >
Hermes::Hermes2D::RefinementSelectors::OptimumSelector< Scalar >::OptimumSelector ( CandList  cand_list,
double  conv_exp,
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]conv_expA conversion exponent, see evaluate_cands_score().
[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 NULL.
[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.

Definition at line 68 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,
Hermes::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 123 of file optimum_selector.cpp.

template<typename Scalar >
void Hermes::Hermes2D::RefinementSelectors::OptimumSelector< Scalar >::append_candidates_split ( const int  start_quad_order,
const int  last_order,
const int  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 361 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 148 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 328 of file optimum_selector.cpp.

template<typename Scalar >
void Hermes::Hermes2D::RefinementSelectors::OptimumSelector< Scalar >::create_candidates ( Element e,
int  quad_order,
int  max_ha_quad_order,
int  max_p_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.
Todo:
Find and why is iro_cache compared with the number 8. What does the number 8 mean?

Reimplemented in Hermes::Hermes2D::RefinementSelectors::L2ProjBasedSelector< Scalar >.

Definition at line 407 of file optimum_selector.cpp.

template<typename Scalar >
void Hermes::Hermes2D::RefinementSelectors::OptimumSelector< Scalar >::evaluate_candidates ( Element e,
Solution< Scalar > *  rsln,
double *  avg_error,
double *  dev_error 
)
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 NULL.
[out]dev_errorA deviation of $\log_{10} e$ where $e$ is an error of a candidate. It cannot be NULL.

Definition at line 597 of file optimum_selector.cpp.

template<typename Scalar >
void Hermes::Hermes2D::RefinementSelectors::OptimumSelector< Scalar >::evaluate_cands_dof ( Element e,
Solution< 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 519 of file optimum_selector.cpp.

template<typename Scalar >
virtual void Hermes::Hermes2D::RefinementSelectors::OptimumSelector< Scalar >::evaluate_cands_error ( Element e,
Solution< Scalar > *  rsln,
double *  avg_error,
double *  dev_error 
)
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.
[out]avg_errorAn average of $\log_{10} e$ where $e$ is an error of a candidate. It cannot be NULL.
[out]dev_errorA deviation of $\log_{10} e$ where $e$ is an error of a candidate. It cannot be NULL.

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

template<typename Scalar >
void Hermes::Hermes2D::RefinementSelectors::OptimumSelector< Scalar >::evaluate_cands_score ( 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, and $c$ is a convergence exponent (OptimumSelector::conv_exp). 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 607 of file optimum_selector.cpp.

template<typename Scalar >
void Hermes::Hermes2D::RefinementSelectors::OptimumSelector< Scalar >::generate_shared_mesh_orders ( const Element element,
const int  orig_quad_order,
const int  refinement,
int  tgt_quad_orders[H2D_MAX_ELEMENT_SONS],
const int *  suggested_quad_orders 
)
protectedvirtual

Generates orders of elements which will be created due to a proposed refinement in another component that shares the same a mesh.

Overriden function. For details, see Selector::generate_shared_mesh_orders(). Updates orders of a refinement in another multimesh component which shares a mesh.

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

Definition at line 748 of file optimum_selector.cpp.

template<typename Scalar >
const Hermes::vector<Cand>& Hermes::Hermes2D::RefinementSelectors::OptimumSelector< Scalar >::get_candidates ( ) const
inline

Returns a vector of the last generated candidates.

Returns
A vector of last generated candidates. The vector will change if a new list is generated.

Definition at line 131 of file optimum_selector.h.

template<typename Scalar >
void Hermes::Hermes2D::RefinementSelectors::OptimumSelector< Scalar >::select_best_candidate ( Element e,
const double  avg_error,
const double  dev_error,
int *  selected_cand,
int *  selected_h_cand 
)
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]selected_candA pointer to a selected index of the best candidate. If the index is 0, the algorithm was not able to decide.
[out]selected_h_candA pointer to a selected index of the best H-candidate. If the index is 0, the algorithm was not able to decide.

Definition at line 636 of file optimum_selector.cpp.

template<typename Scalar >
bool Hermes::Hermes2D::RefinementSelectors::OptimumSelector< Scalar >::select_refinement ( Element element,
int  quad_order,
Solution< 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 678 of file optimum_selector.cpp.

template<typename Scalar >
virtual void Hermes::Hermes2D::RefinementSelectors::OptimumSelector< Scalar >::set_current_order_range ( Element element)
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 >::set_option ( const SelOption  option,
bool  enable 
)
virtual

Enables or disables an option.

If overridden, the implementation has to call a parent implementation.

Parameters
[in]optionAn option that is going to be enabled. For possible values, see SelOption.
[in]enableTrue to enable, false to disable.

Definition at line 788 of file optimum_selector.cpp.

template<typename Scalar >
void Hermes::Hermes2D::RefinementSelectors::OptimumSelector< Scalar >::update_cands_info ( 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 486 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

Number of shape functions for

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

Definition at line 131 of file optimum_selector.h.

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


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