26 #ifndef OOMPH_REFINEABLE_MESH_HEADER
27 #define OOMPH_REFINEABLE_MESH_HEADER
131 outfile << std::endl;
132 outfile <<
"Targets for mesh adaptation: " << std::endl;
133 outfile <<
"---------------------------- " << std::endl;
137 <<
" elements need unrefinement." << std::endl;
138 outfile << std::endl;
258 std::ostringstream err_stream;
259 err_stream <<
"p_adapt() called in base class RefineableMeshBase."
261 <<
"This needs to be implemented in the derived class."
264 err_stream.str(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
284 std::ostringstream err_stream;
286 <<
"p_refine_uniformly() called in base class RefineableMeshBase."
288 <<
"This needs to be implemented in the derived class." << std::endl;
290 err_stream.str(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
312 std::ostringstream err_stream;
314 <<
"p_unrefine_uniformly() called in base class RefineableMeshBase."
316 <<
"This needs to be implemented in the derived class." << std::endl;
318 err_stream.str(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
469 outfile << std::endl;
470 outfile <<
"Targets for mesh adaptation: " << std::endl;
471 outfile <<
"---------------------------- " << std::endl;
481 <<
" elements need unrefinement." << std::endl;
482 outfile << std::endl;
606 virtual void refine(std::ifstream& restart_file);
636 const bool& report_stats)
645 double t_start = 0.0;
657 unsigned local_ncont_interpolated_values = 0;
663 local_ncont_interpolated_values =
665 ->ncont_interpolated_values();
667 unsigned ncont_interpolated_values = 0;
668 MPI_Allreduce(&local_ncont_interpolated_values,
669 &ncont_interpolated_values,
683 <<
"TreeBasedRefineableMeshBase::synchronise_hanging_nodes() "
684 <<
"incl. time for initial allreduce in "
685 <<
"TreeBasedRefineableMeshBase::classify_halo_and_haloed_nodes(): "
686 << t_end - t_start << std::endl;
721 const unsigned& ncont_interpolated_values) = 0;
807 template<
class ELEMENT>
820 for (
unsigned long e = 0;
e < n_tree;
e++)
823 &Tree::split_if_required<ELEMENT>);
834 Mesh* mesh_pt =
this;
839 for (
unsigned long e = 0;
e < n_tree;
e++)
842 &Tree::p_refine_if_required<ELEMENT>, mesh_pt);
856 const unsigned& ncont_interpolated_values);
905 outfile << std::endl;
906 outfile <<
"Targets for mesh adaptation: " << std::endl;
907 outfile <<
"---------------------------- " << std::endl;
915 <<
" elements need unrefinement." << std::endl;
916 outfile << std::endl;
925 double max_edge_ratio = 0.0;
926 unsigned count_unrefined = 0;
927 unsigned count_refined = 0;
931 for (
unsigned e = 0;
e < nel;
e++)
937 double volume = el_pt->
size();
942 for (
unsigned n = 0; n < 4; ++n)
944 for (
unsigned i = 0;
i < 3; ++
i)
953 for (
unsigned i = 0;
i < 3; ++
i)
955 A(0,
i) = vertex[1][
i] - vertex[0][
i];
956 A(1,
i) = vertex[2][
i] - vertex[0][
i];
957 A(2,
i) = vertex[3][
i] - vertex[0][
i];
962 for (
unsigned i = 0;
i < 3; ++
i)
965 for (
unsigned k = 0; k < 3; ++k)
967 rhs[
i] += A(
i, k) * A(
i, k);
977 double circum_radius =
978 sqrt(rhs[0] * rhs[0] + rhs[1] * rhs[1] + rhs[2] * rhs[2]);
982 double min_length = DBL_MAX;
985 for (
unsigned end =
start + 1; end < 4; ++end)
987 for (
unsigned i = 0;
i < 3; ++
i)
989 edge[
i] = vertex[
start][
i] - vertex[end][
i];
992 sqrt(edge[0] * edge[0] + edge[1] * edge[1] + edge[2] * edge[2]);
993 if (length < min_length)
1001 double local_max_edge_ratio = circum_radius / min_length;
1002 if (local_max_edge_ratio > max_edge_ratio)
1004 max_edge_ratio = local_max_edge_ratio;
1042 return max_edge_ratio;
Class of matrices containing doubles, and stored as a DenseMatrix<double>, but with solving functiona...
Information for documentation of results: Directory and file number to enable output in the form RESL...
void disable_doc()
Disable documentation.
std::string directory() const
Output directory.
void solve(DoubleVector &rhs)
Complete LU solve (replaces matrix by its LU decomposition and overwrites RHS with solution)....
Base class for spatial error estimators.
A general Finite Element class.
Node *& node_pt(const unsigned &n)
Return a pointer to the local node n.
double size() const
Calculate the size of the element (length, area, volume,...) in Eulerian computational coordinates....
Class that contains data for hanging nodes.
FiniteElement * finite_element_pt(const unsigned &e) const
Upcast (downcast?) to FiniteElement (needed to access FiniteElement member functions).
virtual void classify_halo_and_haloed_nodes(DocInfo &doc_info, const bool &report_stats)
Classify the halo and haloed nodes in the mesh. Virtual so it can be overloaded to perform additional...
OomphCommunicator * Comm_pt
Pointer to communicator – set to NULL if mesh is not distributed.
const Vector< GeneralisedElement * > & element_pt() const
Return reference to the Vector of elements.
bool Resize_halo_nodes_not_required
Set this to true to suppress resizing of halo nodes (at your own risk!)
void resize_halo_nodes()
Helper function that resizes halo nodes to the same size as their non-halo counterparts if required....
unsigned long nelement() const
Return number of elements in the mesh.
Nodes are derived from Data, but, in addition, have a definite (Eulerian) position in a space of a gi...
double & x(const unsigned &i)
Return the i-th nodal coordinate.
An OomphLibError object which should be thrown when an run-time error is encountered....
RefineableElements are FiniteElements that may be subdivided into children to provide a better local ...
Base class for refineable meshes. Provides standardised interfaces for the following standard mesh ad...
virtual void p_adapt(const Vector< double > &elemental_error)
p-adapt mesh: Refine elements whose error is lager than err_max and (try to) unrefine those whose err...
bool P_adapt_flag
Flag that requests p-adaptation.
unsigned Nrefined
Stats: Number of elements that were refined.
void enable_p_adaptation()
Enable adaptation.
unsigned nunrefined()
Access fct for number of elements that were unrefined.
unsigned & max_keep_unrefined()
Max. number of elements that we allow to remain unrefined if no other mesh adaptation is required (to...
DocInfo doc_info()
Access fct for DocInfo.
RefineableMeshBase()
Constructor sets default values for refinement targets etc. and initialises pointer to spatial error ...
bool Adapt_flag
Flag that requests adaptation.
void operator=(const RefineableMeshBase &)=delete
Broken assignment operator.
void enable_adaptation()
Enable adaptation.
DocInfo * Doc_info_pt
Pointer to DocInfo.
ErrorEstimator * spatial_error_estimator_pt() const
Access to spatial error estimator (const version.
virtual void p_refine_uniformly(DocInfo &doc_info)
p-refine mesh uniformly and doc process
unsigned Max_keep_unrefined
Max. number of elements that can remain unrefined if no other mesh adaptation is required (to avoid m...
virtual unsigned unrefine_uniformly()=0
Unrefine mesh uniformly: Return 0 for success, 1 for failure (if unrefinement has reached the coarses...
double & min_error()
Access fct for min. actual error in present solution (i.e. before re-solve on adapted mesh)
unsigned Nunrefined
Stats: Number of elements that were unrefined.
virtual void p_refine_uniformly()
p-refine mesh uniformly
void p_unrefine_uniformly(DocInfo &doc_info)
p-unrefine mesh uniformly
bool Additional_synchronisation_of_hanging_nodes_not_required
Flag that disables additional synchronisation of hanging nodes.
DocInfo *& doc_info_pt()
Access fct for pointer to DocInfo.
void disable_p_adaptation()
Disable adaptation.
void disable_adaptation()
Disable adaptation.
void enable_additional_synchronisation_of_hanging_nodes()
Enable additional synchronisation of hanging nodes.
bool is_additional_synchronisation_of_hanging_nodes_disabled() const
Return whether additional synchronisation is enabled.
double & max_error()
Access fct for max. actual error in present solution (i.e. before re-solve on adapted mesh)
bool is_adaptation_enabled() const
Return whether the mesh is to be adapted.
ErrorEstimator * Spatial_error_estimator_pt
Pointer to spatial error estimator.
bool is_p_adaptation_enabled() const
Return whether the mesh is to be adapted.
virtual void doc_adaptivity_targets(std::ostream &outfile)
Doc the targets for mesh adaptation.
double Max_error
Max. actual error.
virtual void refine_uniformly()
Refine mesh uniformly.
double Min_error
Min.actual error.
virtual void adapt(const Vector< double > &elemental_error)=0
Adapt mesh: Refine elements whose error is lager than err_max and (try to) unrefine those whose error...
unsigned nrefined()
Access fct for number of elements that were refined.
RefineableMeshBase(const RefineableMeshBase &dummy)=delete
Broken copy constructor.
double Min_permitted_error
Min. error (i.e. (try to) merge elements if their error is smaller)
virtual ~RefineableMeshBase()
Empty Destructor:
double & min_permitted_error()
Access fct for min. error (i.e. (try to) merge elements if their error is smaller)
unsigned Nrefinement_overruled
Number of elements that would like to be refined further but can't because they've reached the max....
void disable_additional_synchronisation_of_hanging_nodes()
Disable additional synchronisation of hanging nodes.
double & max_permitted_error()
Access fct for max. error (i.e. split elements if their error is larger)
unsigned & nrefinement_overruled()
Number of elements that would have liked to be refined further but can't because they've reached the ...
double Max_permitted_error
Max. error (i.e. split elements if their error is larger)
ErrorEstimator *& spatial_error_estimator_pt()
Access to spatial error estimator.
virtual void refine_uniformly(DocInfo &doc_info)=0
Refine mesh uniformly and doc process.
///////////////////////////////////////////////////////////////// ///////////////////////////////////...
void doc_adaptivity_targets(std::ostream &outfile)
Doc the targets for mesh adaptation.
double compute_volume_target(const Vector< double > &elem_error, Vector< double > &target_volume)
Compute target volume based on the elements' error and the error target; return max edge ratio.
double & max_element_size()
Max element size allowed during adaptation.
double & min_element_size()
Min element size allowed during adaptation.
double Max_element_size
Max permitted element size.
double Min_element_size
Min permitted element size.
double Max_permitted_edge_ratio
Max edge ratio before remesh gets triggered.
double & max_permitted_edge_ratio()
Min edge ratio before remesh gets triggered.
///////////////////////////////////////////////////////////////// ///////////////////////////////////...
void synchronise_hanging_nodes(const unsigned &ncont_interpolated_values)
Synchronise the hanging nodes if the mesh is distributed.
virtual void get_elements_at_refinement_level(unsigned &refinement_level, Vector< RefineableElement * > &level_elements)
Extract the elements at a particular refinement level in the refinement pattern - used in Mesh::redis...
void classify_halo_and_haloed_nodes(const bool &report_stats=false)
Classify the halo and haloed nodes in the mesh.
void refine_base_mesh(Vector< Vector< unsigned >> &to_be_refined)
Refine base mesh according to specified refinement pattern.
virtual void refine_selected_elements(const Vector< unsigned > &elements_to_be_refined)
Refine mesh by splitting the elements identified by their numbers.
unsigned & max_refinement_level()
Access fct for max. permissible refinement level (relative to base mesh)
unsigned Uniform_refinement_level_when_pruned
Level to which the mesh was uniformly refined when it was pruned.
unsigned uniform_refinement_level_when_pruned() const
Level to which the mesh was uniformly refined when it was pruned (const version)
virtual void dump_refinement(std::ostream &outfile)
Dump refinement pattern to allow for rebuild.
unsigned Max_p_refinement_level
Max. permissible p-refinement level (relative to base mesh)
TreeForest * forest_pt()
Return pointer to the Forest represenation of the mesh.
unsigned & min_p_refinement_level()
Access fct for min. permissible p-refinement level (relative to base mesh)
virtual void read_refinement(std::ifstream &restart_file, Vector< Vector< unsigned >> &to_be_refined)
Read refinement pattern to allow for rebuild.
unsigned unrefine_uniformly()
Unrefine mesh uniformly: Return 0 for success, 1 for failure (if unrefinement has reached the coarses...
virtual void refine(std::ifstream &restart_file)
Refine mesh according to refinement pattern in restart file.
virtual void additional_synchronise_hanging_nodes(const unsigned &ncont_interpolated_values)=0
Additional synchronisation of hanging nodes Required for reconcilliation of hanging nodes on the oute...
virtual void adapt_mesh()
Perform the actual tree-based mesh adaptation. A simple wrapper to call the function without document...
virtual void refine_base_mesh_as_in_reference_mesh(TreeBasedRefineableMeshBase *const &ref_mesh_pt)
Refine base mesh to same degree as reference mesh (relative to original unrefined mesh).
void complete_hanging_nodes_recursively(Node *&nod_pt, Vector< Node * > &master_nodes, Vector< double > &hang_weights, const int &ival)
Auxiliary routine for recursive hanging node completion.
virtual void refine_as_in_reference_mesh(TreeBasedRefineableMeshBase *const &ref_mesh_pt)
Refine mesh once so that its topology etc becomes that of the (finer!) reference mesh – if possible!...
unsigned & uniform_refinement_level_when_pruned()
Level to which the mesh was uniformly refined when it was pruned.
void operator=(const TreeBasedRefineableMeshBase &)=delete
Broken assignment operator.
void p_refine_selected_elements(const Vector< unsigned > &elements_to_be_refined)
p-refine mesh by refining the elements identified by their numbers.
virtual void split_elements_if_required()=0
Split all the elements in the mesh if required. This template free interface will be overloaded in Re...
void doc_adaptivity_targets(std::ostream &outfile)
Doc the targets for mesh adaptation.
TreeBasedRefineableMeshBase(const TreeBasedRefineableMeshBase &dummy)=delete
Broken copy constructor.
void refine_uniformly()
Refine mesh uniformly.
void p_unrefine_uniformly(DocInfo &doc_info)
p-unrefine mesh uniformly
virtual void get_refinement_levels(unsigned &min_refinement_level, unsigned &max_refinement_level)
Get max/min refinement levels in mesh.
unsigned & max_p_refinement_level()
Access fct for max. permissible p-refinement level (relative to base mesh)
virtual void p_refine_elements_if_required()=0
p-refine all the elements in the mesh if required. This template free interface will be overloaded in...
void complete_hanging_nodes(const int &ncont_interpolated_values)
Complete the hanging node scheme recursively.
virtual void setup_tree_forest()=0
Set up the tree forest associated with the Mesh (if any)
TreeBasedRefineableMeshBase()
Constructor.
TreeForest * Forest_pt
Forest representation of the mesh.
virtual ~TreeBasedRefineableMeshBase()
Empty Destructor:
unsigned Min_p_refinement_level
Min. permissible p-refinement level (relative to base mesh)
void synchronise_nonhanging_nodes()
Synchronise the positions of non-hanging nodes that depend on non-existent neighbours (e....
void adapt(const Vector< double > &elemental_error)
Adapt mesh: Refine elements whose error is lager than err_max and (try to) unrefine those whose error...
unsigned Max_refinement_level
Max. permissible refinement level (relative to base mesh)
void p_adapt(const Vector< double > &elemental_error)
p-adapt mesh: Refine elements whose error is lager than err_max and (try to) unrefine those whose err...
void p_adapt_mesh()
Perform the actual tree-based mesh p-adaptation. A simple wrapper to call the function without docume...
virtual void get_refinement_pattern(Vector< Vector< unsigned >> &to_be_refined)
Extract refinement pattern: Consider the hypothetical mesh obtained by truncating the refinement of t...
virtual bool refine_base_mesh_as_in_reference_mesh_minus_one(TreeBasedRefineableMeshBase *const &ref_mesh_pt)
Refine base mesh to same degree as reference mesh minus one level of refinement (relative to original...
void p_refine_uniformly()
p-refine mesh uniformly
void classify_halo_and_haloed_nodes(DocInfo &doc_info, const bool &report_stats)
Classify all halo and haloed information in the mesh (overloaded version from Mesh base class....
unsigned & min_refinement_level()
Access fct for min. permissible refinement level (relative to base mesh)
unsigned Min_refinement_level
Min. permissible refinement level (relative to base mesh)
///////////////////////////////////////////////////////////////// ///////////////////////////////////...
virtual ~TreeBasedRefineableMesh()
Empty virtual destructor.
void additional_synchronise_hanging_nodes(const unsigned &ncont_interpolated_values)
Additional setup of shared node scheme This is Required for reconcilliation of hanging nodes acrross ...
TreeBasedRefineableMesh(const TreeBasedRefineableMesh &dummy)=delete
Broken copy constructor.
void split_elements_if_required()
Split all the elements if required. Overload the template-free interface so that any new elements tha...
TreeBasedRefineableMesh()
Constructor, call the constructor of the base class.
void p_refine_elements_if_required()
p-refine all the elements if required. Overload the template-free interface so that any temporary cop...
A TreeForest consists of a collection of TreeRoots. Each member tree can have neighbours in various e...
unsigned ntree()
Number of trees in forest.
TreeRoot * tree_pt(const unsigned &i) const
Return pointer to i-th tree in forest.
void traverse_leaves(Tree::VoidMemberFctPt member_function)
Traverse the tree and execute void Tree member function member_function() only at its leaves.
void start(const unsigned &i)
(Re-)start i-th timer
bool Doc_comprehensive_timings
Global boolean to switch on comprehensive timing – can probably be declared const false when developm...
double timer()
returns the time in seconds after some point in past
//////////////////////////////////////////////////////////////////// ////////////////////////////////...
OomphInfo oomph_info
Single (global) instantiation of the OomphInfo object – this is used throughout the library as a "rep...
Helper struct to collate data required during TreeBasedRefineableMeshBase::synchronise_hanging_nodes.
unsigned Shared_node_proc
unsigned Sending_processor
unsigned Shared_node_id_on_sending_processor
unsigned Master_node_index