Adapt Class Reference
[Adaptivity]

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

#include <adapt.h>

Inherited by H1Adapt, and L2Adapt.

List of all members.

Classes

class  CompareElements
 A functor that compares elements accoring to their error. Used by std::sort().
struct  ElementReference
 A reference to an element. More...

Public Types

typedef scalar(* biform_val_t )(int n, double *wt, Func< scalar > *u, Func< scalar > *v, Geom< double > *e, ExtData< scalar > *)
 A bilinear form callback function.
typedef Ord(* biform_ord_t )(int n, double *wt, Func< Ord > *u, Func< Ord > *v, Geom< Ord > *e, ExtData< Ord > *)
 A bilinear form to estimate order of a function.

Public Member Functions

virtual ~Adapt ()
 Destruktor. Deallocates allocated private data.
void set_biform (int i, int j, biform_val_t bi_form, biform_ord_t bi_ord)
 Sets user defined bilinear form which is used to calculate error.
void set_biform (biform_val_t bi_form, biform_ord_t bi_ord)
void set_solutions (Tuple< Solution * > solutions, Tuple< Solution * > ref_solutions)
 Sets solutions and reference solutions.
virtual double calc_error (unsigned int error_flags=H2D_TOTAL_ERROR_REL|H2D_ELEMENT_ERROR_ABS)
 Calculates error between a coarse solution and a reference solution and sorts components according to the error.
bool adapt (RefinementSelectors::Selector *refinement_selector, double thr, int strat=0, int regularize=-1, bool same_orders=false, double to_be_processed=0.0)
 Refines elements based on results from calc_error().
void unrefine (double thr)
 Unrefines the elements with the smallest error.
double get_element_error_squared (int component, int id) const
 Returns a squared error of an element.
const std::vector
< ElementReference > & 
get_regular_queue () const
 Returns regular queue of elements.
int get_total_active_elements () const
 Returns a total number of active elements.
void apply_refinement (const ElementToRefine &elem_ref)
 Apply a single refienement.
virtual void apply_refinements (std::vector< ElementToRefine > &elems_to_refine)
 Apply a vector of refinements.
const std::vector
< ElementToRefine > & 
get_last_refinements () const
 Returns a vector of refinements generated during the last execution of the method adapt().

Protected Member Functions

 Adapt (const Tuple< Space * > &spaces)
 Constructor. Used by children of the class.
virtual bool should_ignore_element (const int inx_element, const Mesh *mesh, const Element *element)
 Returns true if a given element should be ignored and not processed through refinement selection.
virtual bool can_refine_element (Mesh *mesh, Element *e, bool refined, ElementToRefine &elem_ref)
 Returns true if a given element can be refined using proposed refinement.
void fix_shared_mesh_refinements (Mesh **meshes, std::vector< ElementToRefine > &elems_to_refine, AutoLocalArray2< int > &idx, RefinementSelectors::Selector *refinement_selector)
 Fixes refinements of a mesh which is shared among multiple components of a multimesh.
void homogenize_shared_mesh_orders (Mesh **meshes)
 Enforces the same order to an element of a mesh which is shared among multiple compoenets.
virtual scalar eval_error (biform_val_t bi_fn, biform_ord_t bi_ord, MeshFunction *sln1, MeshFunction *sln2, MeshFunction *rsln1, MeshFunction *rsln2, RefMap *rv1, RefMap *rv2, RefMap *rrv1, RefMap *rrv2)
 Evaluates a square of an absolute error of an active element among a given pair of components.
virtual scalar eval_norm (biform_val_t bi_fn, biform_ord_t bi_ord, MeshFunction *rsln1, MeshFunction *rsln2, RefMap *rrv1, RefMap *rrv2)
 Evaluates a square of a norm of an active element in the reference solution among a given pair of components.
virtual void fill_regular_queue (Mesh **meshes, Mesh **ref_meshes)
 Builds an ordered queue of elements that are be examined.

Protected Attributes

int num_act_elems
 A total number of active elements across all provided meshes.
std::queue< ElementReferencepriority_queue
 A queue of priority elements. Elements in this queue are processed before the elements in the Adapt::regular_queue.
std::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().
bool have_errors
 True if errors of elements were calculated.
bool have_solutions
 True if solutions were set.
const int num_comps
 A number of components.
Spacespaces [H2D_MAX_COMPONENTS]
 Spaces. A first unused index in equal to an attribute Adapt::num_comps.
Solutionsln [H2D_MAX_COMPONENTS]
 Coarse solution. A first unused index in equal to an attribute Adapt::num_comps.
Solutionrsln [H2D_MAX_COMPONENTS]
 Reference solutions. A first unused index in equal to an attribute Adapt::num_comps.
double * errors_squared [H2D_MAX_COMPONENTS]
 Errors of elements. Meaning of the error depeds on flags used when the method calc_error() was calls. Initialized in the method calc_error().
double errors_squared_sum
 Sum of errors in the array Adapt::errors_squared. Used by a method adapt() in some strategies.
biform_val_t form [H2D_MAX_COMPONENTS][H2D_MAX_COMPONENTS]
 Bilinear forms to calculate error.
biform_ord_t ord [H2D_MAX_COMPONENTS][H2D_MAX_COMPONENTS]
 Bilinear forms to calculate error.

Detailed Description

Evaluation of an error between a (coarse) solution and a refernece 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. The class has to be inherited in order to be used.


Member Typedef Documentation

typedef Ord(* Adapt::biform_ord_t)(int n, double *wt, Func< Ord > *u, Func< Ord > *v, Geom< Ord > *e, ExtData< Ord > *)

A bilinear form to estimate order of a function.

typedef scalar(* Adapt::biform_val_t)(int n, double *wt, Func< scalar > *u, Func< scalar > *v, Geom< double > *e, ExtData< scalar > *)

A bilinear form callback function.


Constructor & Destructor Documentation

Adapt::Adapt ( const Tuple< Space * > &  spaces  )  [protected]

Constructor. Used by children of the class.

Adapt::~Adapt (  )  [virtual]

Destruktor. Deallocates allocated private data.


Member Function Documentation

bool Adapt::adapt ( RefinementSelectors::Selector refinement_selector,
double  thr,
int  strat = 0,
int  regularize = -1,
bool  same_orders = false,
double  to_be_processed = 0.0 
)

Refines elements based on results from calc_error().

The behavior of adaptivity can be controlled through methods should_ignore_element() and can_refine_element() which are inteteded to be overriden if neccessary.

Parameters:
[in] refinement_selector A point to a selector which will select a refinement.
[in] thr A threshold. The meaning of the threshold is defined by the parameter strat.
[in] strat A strategy. It specifies a stop condition which quits processing elements in the Adapt::regular_queue. Possible values are 0, 1, 2, and 3.
[in] regularize Regularizing of a mesh.
[in] same_order True if all element have to have same orders after all refinements are applied.
[in] to_be_processed Error 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.
void Adapt::apply_refinement ( const ElementToRefine elem_ref  ) 

Apply a single refienement.

Parameters:
[in] A refinement to apply.
void Adapt::apply_refinements ( std::vector< ElementToRefine > &  elems_to_refine  )  [virtual]

Apply a vector of refinements.

Parameters:
[in] A vector of refinements to apply.
double Adapt::calc_error ( unsigned int  error_flags = H2D_TOTAL_ERROR_REL | H2D_ELEMENT_ERROR_ABS  )  [virtual]

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

If overrided, 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_flags Flags which calculates the error. It can be a combination of H2D_TOTAL_ERROR_REL, H2D_TOTAL_ERROR_ABS, H2D_ELEMENT_ERROR_REL, H2D_ELEMENT_ERROR_ABS.
Returns:
The total error. Interpretation of the error is specified by the parameter error_flags.
virtual bool Adapt::can_refine_element ( Mesh mesh,
Element e,
bool  refined,
ElementToRefine elem_ref 
) [inline, protected, virtual]

Returns true if a given element can be refined using proposed refinement.

Overload this method to

  • avoid application of a refinement even thought a selector considered this refinement as the optimal one,
  • suggest a new refinement despite that the selector was not able to select a refinement.
    Parameters:
    [in] mesh A mesh that contains the element.
    [in] e A point to the element.
    [in] refined True if a refinement of the element was found.
    [in,out] elem_ref The proposed refinement. Change a value of this parameter to select a different refinement.
    Returns:
    True if the element should not be refined using the refinement.
scalar Adapt::eval_error ( biform_val_t  bi_fn,
biform_ord_t  bi_ord,
MeshFunction sln1,
MeshFunction sln2,
MeshFunction rsln1,
MeshFunction rsln2,
RefMap rv1,
RefMap rv2,
RefMap rrv1,
RefMap rrv2 
) [protected, virtual]

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] bi_fn A bilinear form.
[in] bi_ord A bilinear form which is used to calculate the order of a quadrature.
[in] sln1 A (coarse) solution corresponding to the first component.
[in] sln2 A (coarse) solution corresponding to the second component.
[in] rsln1 A reference solution corresponding to the first component.
[in] rsln2 A reference solution corresponding to the second component.
[in] rv1 A reference map of a (coarse) solution sln1.
[in] rv2 A reference map of a (coarse) solution sln2.
[in] rrv1 A reference map of a reference solution rsln1.
[in] rrv2 A reference map of a reference solution rsln2.
Returns:
A square of an absolute error.
scalar Adapt::eval_norm ( biform_val_t  bi_fn,
biform_ord_t  bi_ord,
MeshFunction rsln1,
MeshFunction rsln2,
RefMap rrv1,
RefMap rrv2 
) [protected, virtual]

Evaluates a 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] bi_fn A bilinear form.
[in] bi_ord A bilinear form which is used to calculate the order of a quadrature.
[in] rsln1 A reference solution corresponding to the first component.
[in] rsln2 A reference solution corresponding to the second component.
[in] rrv1 A reference map of a reference solution rsln1.
[in] rrv2 A reference map of a reference solution rsln2.
Returns:
A square of a norm.
void Adapt::fill_regular_queue ( Mesh **  meshes,
Mesh **  ref_meshes 
) [protected, virtual]

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 overriden. /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.

void Adapt::fix_shared_mesh_refinements ( Mesh **  meshes,
std::vector< ElementToRefine > &  elems_to_refine,
AutoLocalArray2< int > &  idx,
RefinementSelectors::Selector refinement_selector 
) [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 incosistency.

Parameters:
[in] meshes An array of meshes of components.
[in] elems_to_refine A vector of refinements.
[in] idx A 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_selector A selected used by the adaptivity. The selector is used to correct orders of modified refinements using RefinementSelectors::Selector::update_shared_mesh_orders().
double Adapt::get_element_error_squared ( int  component,
int  id 
) const [inline]

Returns a squared error of an element.

Parameters:
[in] A component index.
[in] An element index.
Returns:
Squared error. Meaning of the error depends on parameters of a function calc_error().
const std::vector< ElementToRefine > & Adapt::get_last_refinements (  )  const

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.
const std::vector<ElementReference>& Adapt::get_regular_queue (  )  const [inline]

Returns regular queue of elements.

Returns:
A regular queue.
int Adapt::get_total_active_elements (  )  const [inline]

Returns a total number of active elements.

Returns:
A total number of active elements. If below 0, errors were not calculated yet, see set_solutions()
void Adapt::homogenize_shared_mesh_orders ( Mesh **  meshes  )  [protected]

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

Parameters:
[in] meshes An arrat of meshes of components.
void Adapt::set_biform ( biform_val_t  bi_form,
biform_ord_t  bi_ord 
)
void Adapt::set_biform ( int  i,
int  j,
biform_val_t  bi_form,
biform_ord_t  bi_ord 
)

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] i The first component index.
[in] j The second component index.
[in] bi_form A bilinear form which calculates value.
[in] bi_ord A bilinear form which calculates order.
void Adapt::set_solutions ( Tuple< Solution * >  solutions,
Tuple< Solution * >  ref_solutions 
)

Sets solutions and reference solutions.

Parameters:
[in] solutions Coarse solutions. The number of solutions has to match a number of components.
[in] ref_solutions Reference solutions. The number of reference solutions has to match a number of components.
virtual bool Adapt::should_ignore_element ( const int  inx_element,
const Mesh mesh,
const Element element 
) [inline, protected, virtual]

Returns true if a given element should be ignored and not processed through refinement selection.

Overload this method to omit some elements from processing.

Parameters:
[in] inx_element An index of an element in the regular queue. -1 if the element cames from the priority queue.
[in] mesh A mesh that contains the element. [in] element A pointer to the element.
Returns:
True if the element should be skipped.
void Adapt::unrefine ( double  thr  ) 

Unrefines the elements with the smallest error.

Note:
This method is provided just for backward compatibility reasons. Currently, it is not used by the library.
Parameters:
[in] thr A stop condition relative error threshold.

Member Data Documentation

double* Adapt::errors_squared[H2D_MAX_COMPONENTS] [protected]

Errors of elements. Meaning of the error depeds on flags used when the method calc_error() was calls. Initialized in the method calc_error().

double Adapt::errors_squared_sum [protected]

Sum of errors in the array Adapt::errors_squared. Used by a method adapt() in some strategies.

biform_val_t Adapt::form[H2D_MAX_COMPONENTS][H2D_MAX_COMPONENTS] [protected]

Bilinear forms to calculate error.

bool Adapt::have_errors [protected]

True if errors of elements were calculated.

bool Adapt::have_solutions [protected]

True if solutions were set.

std::vector<ElementToRefine> Adapt::last_refinements [protected]

A vector of refinements generated during the last finished execution of the method adapt().

int Adapt::num_act_elems [protected]

A total number of active elements across all provided meshes.

const int Adapt::num_comps [protected]

A number of components.

biform_ord_t Adapt::ord[H2D_MAX_COMPONENTS][H2D_MAX_COMPONENTS] [protected]

Bilinear forms to calculate error.

std::queue<ElementReference> Adapt::priority_queue [protected]

A queue of priority elements. Elements in this queue are processed before the elements in the Adapt::regular_queue.

std::vector<ElementReference> Adapt::regular_queue [protected]

A queue of elements which should be processes. The queue had to be filled by the method fill_regular_queue().

Solution* Adapt::rsln[H2D_MAX_COMPONENTS] [protected]

Reference solutions. A first unused index in equal to an attribute Adapt::num_comps.

Solution* Adapt::sln[H2D_MAX_COMPONENTS] [protected]

Coarse solution. A first unused index in equal to an attribute Adapt::num_comps.

Space* Adapt::spaces[H2D_MAX_COMPONENTS] [protected]

Spaces. A first unused index in equal to an attribute Adapt::num_comps.


The documentation for this class was generated from the following files:
Generated on Sat Jun 5 15:17:43 2010 for Hermes2D Library: Real Version by  doxygen 1.6.3