Hermes2D  2.0
Hermes::Hermes2D::Adapt< Scalar > Class Template Reference

Evaluation of an error between a (coarse) solution and a reference solution and adaptivity. More...

#include <adapt.h>

+ Inheritance diagram for Hermes::Hermes2D::Adapt< Scalar >:

Classes

struct  ElementReference
 A reference to an element. More...
 
class  MatrixFormVolError
 Matrix forms for error calculation. More...
 

Public Member Functions

 Adapt (Hermes::vector< Space< Scalar > * > spaces, Hermes::vector< ProjNormType > proj_norms=Hermes::vector< ProjNormType >())
 
 Adapt (Space< Scalar > *space, ProjNormType proj_norm=HERMES_UNSET_NORM)
 
virtual ~Adapt ()
 Destructor. Deallocates allocated private data.
 
void set_error_form (int i, int j, MatrixFormVolError *form)
 Sets user defined bilinear form which is used to calculate error. More...
 
void set_error_form (MatrixFormVolError *form)
 i = j = 0
 
void set_norm_form (int i, int j, MatrixFormVolError *form)
 
void set_norm_form (MatrixFormVolError *form)
 i = j = 0
 
double calc_err_est (Solution< Scalar > *sln, Solution< Scalar > *rsln, bool solutions_for_adapt=true, unsigned int error_flags=HERMES_TOTAL_ERROR_REL|HERMES_ELEMENT_ERROR_REL)
 
double calc_err_est (Hermes::vector< Solution< Scalar > * > slns, Hermes::vector< Solution< Scalar > * > rslns, Hermes::vector< double > *component_errors=NULL, bool solutions_for_adapt=true, unsigned int error_flags=HERMES_TOTAL_ERROR_REL|HERMES_ELEMENT_ERROR_REL)
 
double calc_err_exact (Solution< Scalar > *sln, Solution< Scalar > *rsln, bool solutions_for_adapt=true, unsigned int error_flags=HERMES_TOTAL_ERROR_REL|HERMES_ELEMENT_ERROR_REL)
 
double calc_err_exact (Hermes::vector< Solution< Scalar > * > slns, Hermes::vector< Solution< Scalar > * > rslns, Hermes::vector< double > *component_errors=NULL, bool solutions_for_adapt=true, unsigned int error_flags=HERMES_TOTAL_ERROR_REL|HERMES_ELEMENT_ERROR_REL)
 
bool adapt (Hermes::vector< RefinementSelectors::Selector< Scalar > * > refinement_selectors, double thr, int strat=0, int regularize=-1, double to_be_processed=0.0)
 Refines elements based on results from calc_err_est(). More...
 
bool adapt (RefinementSelectors::Selector< Scalar > *refinement_selector, double thr, int strat=0, int regularize=-1, double to_be_processed=0.0)
 Refines elements based on results from calc_err_est(). More...
 
double get_element_error_squared (int component, int id) const
 Returns a squared error of an element. More...
 

Protected Member Functions

const Hermes::vector
< ElementReference > & 
get_regular_queue () const
 Returns regular queue of elements. More...
 
void apply_refinement (const ElementToRefine &elem_ref)
 Apply a single refinement. More...
 
virtual void apply_refinements (std::vector< ElementToRefine > &elems_to_refine)
 Apply a vector of refinements. More...
 
const std::vector
< ElementToRefine > & 
get_last_refinements () const
 Returns a vector of refinements generated during the last execution of the method adapt(). More...
 
void fix_shared_mesh_refinements (Mesh **meshes, std::vector< ElementToRefine > &elems_to_refine, int **idx, RefinementSelectors::Selector< Scalar > ***refinement_selectors)
 Fixes refinements of a mesh which is shared among multiple components of a multimesh. More...
 
void homogenize_shared_mesh_orders (Mesh **meshes)
 Enforces the same order to an element of a mesh which is shared among multiple components. More...
 
virtual double calc_err_internal (Hermes::vector< Solution< Scalar > * > slns, Hermes::vector< Solution< Scalar > * > rslns, Hermes::vector< double > *component_errors, bool solutions_for_adapt, unsigned int error_flags)
 Calculates error between a coarse solution and a reference solution and sorts components according to the error. More...
 
virtual double calc_err_internal (Solution< Scalar > *sln, Solution< Scalar > *rsln, Hermes::vector< double > *component_errors, bool solutions_for_adapt, unsigned int error_flags)
 One Space version.
 
virtual double eval_error (MatrixFormVolError *form, MeshFunction< Scalar > *sln1, MeshFunction< Scalar > *sln2, MeshFunction< Scalar > *rsln1, MeshFunction< Scalar > *rsln2)
 Evaluates a square of an absolute error of an active element among a given pair of components. More...
 
virtual double eval_error_norm (MatrixFormVolError *form, MeshFunction< Scalar > *rsln1, MeshFunction< Scalar > *rsln2)
 Evaluates the square of a norm of an active element in the reference solution among a given pair of components. More...
 
virtual void fill_regular_queue (const Mesh **meshes)
 Builds an ordered queue of elements that are be examined. More...
 

Protected Attributes

Exceptions::Exception * caughtException
 
std::queue< ElementReferencepriority_queue
 A queue of priority elements. Elements in this queue are processed before the elements in the Adapt::regular_queue.
 
Hermes::vector< ElementReferenceregular_queue
 A queue of elements which should be processes. The queue had to be filled by the method fill_regular_queue().
 
std::vector< ElementToRefinelast_refinements
 A vector of refinements generated during the last finished execution of the method adapt().
 
int num
 Number of solution components (as in wf->neq).
 
Hermes::vector< Space< Scalar > * > spaces
 Spaces.
 
bool ** own_forms
 
int num_act_elems
 A total number of active elements across all provided meshes.
 
Solution< Scalar > * sln [H2D_MAX_COMPONENTS]
 Coarse solution.
 
Solution< Scalar > * rsln [H2D_MAX_COMPONENTS]
 Reference solutions.
 
bool have_errors
 True if errors of elements were calculated.
 
bool have_coarse_solutions
 True if the coarse solutions were set.
 
bool have_reference_solutions
 True if the reference solutions were set.
 
double * errors [H2D_MAX_COMPONENTS]
 method calc_errors_internal() was calls. Initialized in the method calc_errors_internal(). More...
 
double errors_squared_sum
 Sum of errors in the array Adapt::errors_squared. Used by a method adapt() in some strategies.
 
double error_time
 Time needed to calculate the error.
 
MatrixFormVolErrorerror_form [H2D_MAX_COMPONENTS][H2D_MAX_COMPONENTS]
 Bilinear forms to calculate error.
 
MatrixFormVolErrornorm_form [H2D_MAX_COMPONENTS][H2D_MAX_COMPONENTS]
 Bilinear forms to calculate norm (set to error_form by default).
 

Static Protected Attributes

static const unsigned char HERMES_TOTAL_ERROR_MASK = 0x0F
 A mask which masks-out total error type. Used by Adapt::calc_err_internal().
 
static const unsigned char HERMES_ELEMENT_ERROR_MASK = 0xF0
 A mask which masks-out element error type. Used by Adapt::calc_err_internal().
 

Detailed Description

template<typename Scalar>
class Hermes::Hermes2D::Adapt< Scalar >

Evaluation of an error between a (coarse) solution and a reference solution and adaptivity.

The class provides basic functionality necessary to adaptively refine elements. Given a reference solution and a coarse solution, it calculates error estimates and it acts as a container for the calculated errors.

Definition at line 57 of file adapt.h.

Constructor & Destructor Documentation

template<typename Scalar >
Hermes::Hermes2D::Adapt< Scalar >::Adapt ( Hermes::vector< Space< Scalar > * >  spaces,
Hermes::vector< ProjNormType proj_norms = Hermes::vector<ProjNormType>() 
)

Constructor. Suitable for problems where various solution components belong to different spaces (L2, H1, Hcurl, Hdiv). If proj_norms are not specified, they are defined according to the spaces.

Definition at line 34 of file adapt.cpp.

Member Function Documentation

template<typename Scalar >
bool Hermes::Hermes2D::Adapt< Scalar >::adapt ( Hermes::vector< RefinementSelectors::Selector< Scalar > * >  refinement_selectors,
double  thr,
int  strat = 0,
int  regularize = -1,
double  to_be_processed = 0.0 
)

Refines elements based on results from calc_err_est().

Parameters
[in]refinement_selectorsVector of selectors.
[in]thrA threshold. The meaning of the threshold is defined by the parameter strat.
[in]stratA strategy. It specifies a stop condition which quits processing elements in the Adapt::regular_queue. Possible values are 0, 1, 2, and 3.
[in]regularizeRegularizing of a mesh.
[in]same_orderTrue if all element have to have same orders after all refinements are applied.
[in]to_be_processedError which has to be processed. Used in strategy number 3.
Returns
True if no element was refined. In usual case, this indicates that adaptivity is not able to refine anything and the adaptivity loop should end.

Definition at line 158 of file adapt.cpp.

Referenced by Hermes::Hermes2D::Adapt< Scalar >::adapt(), and Hermes::Hermes2D::KellyTypeAdapt< Scalar >::adapt().

template<typename Scalar >
bool Hermes::Hermes2D::Adapt< Scalar >::adapt ( RefinementSelectors::Selector< Scalar > *  refinement_selector,
double  thr,
int  strat = 0,
int  regularize = -1,
double  to_be_processed = 0.0 
)

Refines elements based on results from calc_err_est().

Parameters
[in]refinement_selectorA pointer to a selector which will select a refinement.
[in]thrA threshold. The meaning of the threshold is defined by the parameter strat.
[in]stratA strategy. It specifies a stop condition which quits processing elements in the Adapt::regular_queue. Possible values are 0, 1, 2, and 3.
[in]regularizeRegularizing of a mesh.
[in]same_orderTrue if all element have to have same orders after all refinements are applied.
[in]to_be_processedError which has to be processed. Used in strategy number 3.
Returns
True if no element was refined. In usual case, this indicates that adaptivity is not able to refine anything and the adaptivity loop should end.

Definition at line 688 of file adapt.cpp.

template<typename Scalar >
void Hermes::Hermes2D::Adapt< Scalar >::apply_refinement ( const ElementToRefine elem_ref)
protected

Apply a single refinement.

Parameters
[in]Arefinement to apply.

Definition at line 828 of file adapt.cpp.

Referenced by Hermes::Hermes2D::Adapt< Scalar >::apply_refinements().

template<typename Scalar >
void Hermes::Hermes2D::Adapt< Scalar >::apply_refinements ( std::vector< ElementToRefine > &  elems_to_refine)
protectedvirtual

Apply a vector of refinements.

Parameters
[in]Avector of refinements to apply.

Definition at line 820 of file adapt.cpp.

template<typename Scalar >
double Hermes::Hermes2D::Adapt< Scalar >::calc_err_est ( Solution< Scalar > *  sln,
Solution< Scalar > *  rsln,
bool  solutions_for_adapt = true,
unsigned int  error_flags = HERMES_TOTAL_ERROR_REL | HERMES_ELEMENT_ERROR_REL 
)

Type-safe version of calc_err_est() for one solution.

Parameters
[in]solutions_for_adapt- if sln and rsln are the solutions error of which is used in the function adapt().

Definition at line 601 of file adapt.cpp.

template<typename Scalar >
double Hermes::Hermes2D::Adapt< Scalar >::calc_err_est ( Hermes::vector< Solution< Scalar > * >  slns,
Hermes::vector< Solution< Scalar > * >  rslns,
Hermes::vector< double > *  component_errors = NULL,
bool  solutions_for_adapt = true,
unsigned int  error_flags = HERMES_TOTAL_ERROR_REL | HERMES_ELEMENT_ERROR_REL 
)

Calculates the error of the solution. 'n' must be the same as 'num' in the constructor. After that, n coarse solution pointers are passed, followed by n fine solution pointers.

Parameters
[in]solutions_for_adapt- if slns and rslns are the solutions error of which is used in the function adapt().

Definition at line 614 of file adapt.cpp.

template<typename Scalar >
double Hermes::Hermes2D::Adapt< Scalar >::calc_err_exact ( Solution< Scalar > *  sln,
Solution< Scalar > *  rsln,
bool  solutions_for_adapt = true,
unsigned int  error_flags = HERMES_TOTAL_ERROR_REL | HERMES_ELEMENT_ERROR_REL 
)

Type-safe version of calc_err_exact() for one solution.

Parameters
[in]solutions_for_adapt- if sln and rsln are the solutions error of which is used in the function adapt().

Definition at line 630 of file adapt.cpp.

template<typename Scalar >
double Hermes::Hermes2D::Adapt< Scalar >::calc_err_exact ( Hermes::vector< Solution< Scalar > * >  slns,
Hermes::vector< Solution< Scalar > * >  rslns,
Hermes::vector< double > *  component_errors = NULL,
bool  solutions_for_adapt = true,
unsigned int  error_flags = HERMES_TOTAL_ERROR_REL | HERMES_ELEMENT_ERROR_REL 
)

Calculates the error of the solution.

Parameters
[in]solutions_for_adapt- if slns and rslns are the solutions error of which is used in the function adapt().

Definition at line 652 of file adapt.cpp.

template<typename Scalar >
double Hermes::Hermes2D::Adapt< Scalar >::calc_err_internal ( Hermes::vector< Solution< Scalar > * >  slns,
Hermes::vector< Solution< Scalar > * >  rslns,
Hermes::vector< double > *  component_errors,
bool  solutions_for_adapt,
unsigned int  error_flags 
)
protectedvirtual

Calculates error between a coarse solution and a reference solution and sorts components according to the error.

If overridden, this method has to initialize errors (Array::errors), sum of errors (Array::error_sum), norms of components (Array::norm), number of active elements (Array::num_act_elems). Also, it has to fill the regular queue through the method fill_regular_queue().

Parameters
[in]error_flagsFlags which calculates the error. It can be a combination of HERMES_TOTAL_ERROR_REL, HERMES_TOTAL_ERROR_ABS, HERMES_ELEMENT_ERROR_REL, HERMES_ELEMENT_ERROR_ABS.
Returns
The total error. Interpretation of the error is specified by the parameter error_flags.

Definition at line 1028 of file adapt.cpp.

Referenced by Hermes::Hermes2D::Adapt< Scalar >::calc_err_est(), Hermes::Hermes2D::Adapt< Scalar >::calc_err_exact(), and Hermes::Hermes2D::Adapt< Scalar >::calc_err_internal().

template<typename Scalar >
double Hermes::Hermes2D::Adapt< Scalar >::eval_error ( MatrixFormVolError form,
MeshFunction< Scalar > *  sln1,
MeshFunction< Scalar > *  sln2,
MeshFunction< Scalar > *  rsln1,
MeshFunction< Scalar > *  rsln2 
)
protectedvirtual

Evaluates a square of an absolute error of an active element among a given pair of components.

The method uses a bilinear forms to calculate the error. This is done by supplying a differences (f1 - v1) and (f2 - v2) at integration points to the bilinear form, where f1 and f2 are values of (coarse) solutions of the first and the second component respectively, v1 and v2 are values of reference solutions of the first and the second component respectively.

Parameters
[in]formA bilinear form.
[in]sln1A (coarse) solution corresponding to the first component.
[in]sln2A (coarse) solution corresponding to the second component.
[in]rsln1A reference solution corresponding to the first component.
[in]rsln2A reference solution corresponding to the second component.
[in]rv1A reference map of a (coarse) solution sln1.
[in]rv2A reference map of a (coarse) solution sln2.
[in]rrv1A reference map of a reference solution rsln1.
[in]rrv2A reference map of a reference solution rsln2.
Returns
A square of an absolute error.

Definition at line 904 of file adapt.cpp.

Referenced by Hermes::Hermes2D::Adapt< Scalar >::calc_err_internal().

template<typename Scalar >
double Hermes::Hermes2D::Adapt< Scalar >::eval_error_norm ( MatrixFormVolError form,
MeshFunction< Scalar > *  rsln1,
MeshFunction< Scalar > *  rsln2 
)
protectedvirtual

Evaluates the square of a norm of an active element in the reference solution among a given pair of components.

The method uses a bilinear forms to calculate the norm. This is done by supplying a v1 and v2 at integration points to the bilinear form, where v1 and v2 are values of reference solutions of the first and the second component respectively.

Parameters
[in]formA bilinear form.
[in]rsln1A reference solution corresponding to the first component.
[in]rsln2A reference solution corresponding to the second component.
[in]rrv1A reference map of a reference solution rsln1.
[in]rrv2A reference map of a reference solution rsln2.
Returns
A square of a norm.

Definition at line 971 of file adapt.cpp.

Referenced by Hermes::Hermes2D::Adapt< Scalar >::calc_err_internal().

template<typename Scalar >
void Hermes::Hermes2D::Adapt< Scalar >::fill_regular_queue ( const Mesh **  meshes)
protectedvirtual

Builds an ordered queue of elements that are be examined.

The method fills Adapt::standard_queue by elements sorted accordin to their error descending. The method assumes that Adapt::errors_squared contains valid values. If a special order of elements is requested, this method has to be overridden. /param[in] meshes An array of pointers to meshes of a (coarse) solution. An index into the array is an index of a component. /param[in] meshes An array of pointers to meshes of a reference solution. An index into the array is an index of a component.

Definition at line 1242 of file adapt.cpp.

Referenced by Hermes::Hermes2D::Adapt< Scalar >::calc_err_internal().

template<typename Scalar >
void Hermes::Hermes2D::Adapt< Scalar >::fix_shared_mesh_refinements ( Mesh **  meshes,
std::vector< ElementToRefine > &  elems_to_refine,
int **  idx,
RefinementSelectors::Selector< Scalar > ***  refinement_selectors 
)
protected

Fixes refinements of a mesh which is shared among multiple components of a multimesh.

If a mesh is shared among components, it has to be refined similarly in order to avoid inconsistency.

Parameters
[in]meshesAn array of meshes of components.
[in]elems_to_refineA vector of refinements.
[in]idxA 2D array that translates a pair (a component index, an element id) to an index of a refinement in the vector of refinements. If the index is below zero, a given element was not refined.
[in]refinement_selectorA selected used by the adaptivity. The selector is used to correct orders of modified refinements using RefinementSelectors::Selector::update_shared_mesh_orders().

Definition at line 699 of file adapt.cpp.

template<typename Scalar >
double Hermes::Hermes2D::Adapt< Scalar >::get_element_error_squared ( int  component,
int  id 
) const

Returns a squared error of an element.

Parameters
[in]Acomponent index.
[in]Anelement index.
Returns
Squared error. Meaning of the error depends on parameters of the function calc_errors_internal().

Definition at line 776 of file adapt.cpp.

template<typename Scalar >
const std::vector< ElementToRefine > & Hermes::Hermes2D::Adapt< Scalar >::get_last_refinements ( ) const
protected

Returns a vector of refinements generated during the last execution of the method adapt().

Returns
A vector of refinements generated during the last execution of the method adapt(). The returned vector might change or become invalid after the next execution of the method adadpt(). Returns last refinements.

Definition at line 814 of file adapt.cpp.

template<typename Scalar >
const Hermes::vector< typename Adapt< Scalar >::ElementReference > & Hermes::Hermes2D::Adapt< Scalar >::get_regular_queue ( ) const
protected

Returns regular queue of elements.

Returns
A regular queue.

Definition at line 784 of file adapt.cpp.

template<typename Scalar >
void Hermes::Hermes2D::Adapt< Scalar >::homogenize_shared_mesh_orders ( Mesh **  meshes)
protected

Enforces the same order to an element of a mesh which is shared among multiple components.

Parameters
[in]meshesAn array of meshes of components.

Definition at line 790 of file adapt.cpp.

template<typename Scalar >
void Hermes::Hermes2D::Adapt< Scalar >::set_error_form ( int  i,
int  j,
MatrixFormVolError form 
)

Sets user defined bilinear form which is used to calculate error.

By default, all inherited class should set default bilinear forms for each element (i.e. i = j). This method can change it or set forms that can combine components (e.g. energy error).

Parameters
[in]iThe first component index.
[in]jThe second component index.
[in]bi_formA bilinear form which calculates value.
[in]bi_ordA bilinear form which calculates order.

Member Data Documentation

template<typename Scalar >
double* Hermes::Hermes2D::Adapt< Scalar >::errors[H2D_MAX_COMPONENTS]
protected

method calc_errors_internal() was calls. Initialized in the method calc_errors_internal().

Errors of elements. Meaning of the error depeds on flags used when the

Definition at line 237 of file adapt.h.

Referenced by Hermes::Hermes2D::Adapt< Scalar >::Adapt(), Hermes::Hermes2D::Adapt< Scalar >::calc_err_internal(), and Hermes::Hermes2D::Adapt< Scalar >::get_element_error_squared().


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