CArl
Code Arlequin / C++ implementation
patch_construction.h
Go to the documentation of this file.
1 /*
2  * patch_construction.h
3  *
4  * Created on: Apr 14, 2016
5  * Author: Thiago Milanetto Schlittler
6  */
7 
8 #ifndef COMMON_INTERSECTIONS_PARALLEL_PATCH_CONSTRUCTION_H_
9 #define COMMON_INTERSECTIONS_PARALLEL_PATCH_CONSTRUCTION_H_
10 
11 #include "carl_headers.h"
12 #include "mesh_tables.h"
13 
14 #include "intersection_tools.h"
15 
16 namespace carl
17 {
18 
19 // ************************
20 // Patch_Construction class
21 // ************************
22 
43 {
44 protected:
45 
46  // Communicators and parallel data
47  const libMesh::Parallel::Communicator& m_comm;
48  const unsigned int m_nodes;
49  const unsigned int m_rank;
50 
51  const libMesh::Parallel::Communicator& m_local_comm;
52 
53  // Meshes and point locators
54  libMesh::ReplicatedMesh& m_Mesh_parent;
55  libMesh::ReplicatedMesh m_Mesh_patch;
56  std::unique_ptr<libMesh::PointLocatorBase> m_Parent_Point_Locator;
57 
58  // Object used to do the intersection tests
60 
61  // Data structures used to build the patch
63  std::unordered_set<unsigned int> m_Patch_Elem_indexes;
65  std::unordered_set<unsigned int> m_Patch_Node_indexes;
67  std::unordered_map<unsigned int,std::unordered_set<unsigned int> > m_Patch_Elem_Neighbours;
68 
69  // Data structures used to do the advancing front intersection search (Adv. front)
71  unsigned int m_working_element_id;
72 
75 
83 
89  std::deque<int> m_element_test_queue;
90 
96  std::unordered_map<unsigned int,int> m_element_already_treated;
97 
103  std::unordered_map<unsigned int,int> m_element_inside_intersection_queue;
104 
110  std::unordered_set<unsigned int> m_element_neighbours_to_search;
111 
112  // Maps used to help building a patch mesh
114  std::unordered_map<unsigned int,int> m_node_map_Parent_to_Patch;
115 
117  std::unordered_map<unsigned int,int> m_node_map_Patch_to_Parent;
118 
120  std::unordered_map<unsigned int,int> m_elem_map_Parent_to_Patch;
121 
123  std::unordered_map<unsigned int,int> m_elem_map_Patch_to_Parent;
124 
127 
128  // PROTECTED constructor
129  Patch_construction(); //< Dummy constructor
130 
131  // PROTECTED methods
133  void insert_patch_element(const libMesh::Elem * Patch_elem);
134 
136  void build_patch_mesh();
137 
138 public:
139 
140  // Constructors
142  Patch_construction(libMesh::Mesh & mesh, const libMesh::Parallel::Communicator& local_comm, bool debugOutput = false) :
143  m_comm { mesh.comm() },
144  m_nodes { m_comm.size() },
145  m_rank { m_comm.rank() },
146  m_local_comm { local_comm },
147  m_Mesh_parent { mesh },
148  m_Mesh_patch { libMesh::ReplicatedMesh(m_local_comm) },
149 
150  m_bPrintDebug { debugOutput }
151  {
152  m_Parent_Point_Locator = m_Mesh_parent.sub_point_locator();
153 
154  // Instruction needed to avoid the code from crashing if a query is outside the mesh
155  m_Parent_Point_Locator->enable_out_of_mesh_mode();
156 
157  m_working_element_id = 0;
158  m_bTestNeighsForNewPairs = true;
159 
160  m_Patch_Elem_indexes.reserve(m_Mesh_parent.n_elem());
161  m_Patch_Node_indexes.reserve(m_Mesh_parent.n_nodes());
162  };
163 
164  // Getters
165  libMesh::ReplicatedMesh & parent_mesh();
166  libMesh::ReplicatedMesh & patch_mesh();
167  std::unordered_set<unsigned int> & elem_indexes();
168  std::unordered_set<unsigned int> & node_indexes();
169  unsigned int size();
170  const libMesh::Elem * elem(unsigned int idx);
171  std::unordered_map<unsigned int,std::unordered_set<unsigned int> > & patch_elem_neighbours();
173 
174  // PUBLIC methods
182  void BuildPatch(const libMesh::Elem * Query_elem);
183 
185  unsigned int convert_parent_to_patch_elem_id(unsigned int input);
186 
188  unsigned int convert_patch_to_parent_elem_id(unsigned int input);
189 
191  void export_patch_mesh(std::string & filename_base);
192 
193  unsigned int current_elem_id(); //< \[ADV. FRONT\] Get the current element index.
194  const libMesh::Elem * current_elem_pointer(); //< \[ADV. FRONT\] Get the current element pointer.
195 
196  /*
197  * \[ADV. FRONT\] The following methods are all used by the advancing front algorithm,
198  * found inside the "intersection_search.h" files
199  */
200 
202  void intersection_queue_push_back(unsigned int elem_id);
203 
205  void set_elem_as_treated(unsigned int elem_id);
206 
208  void set_elem_as_inside_queue(unsigned int elem_id);
209 
212 
214  bool test_queue_empty();
215 
218 
220  unsigned int test_queue_extract_front_elem();
221 
223  std::unordered_set<unsigned int> & neighbors_to_search_next_pair();
224 
230 
233 
235  void FrontSearch_initialize();
236 
241  void FrontSearch_reset();
242 
248 };
249 
250 }
251 #endif /* COMMON_INTERSECTIONS_PARALLEL_PATCH_CONSTRUCTION_H_ */
libMesh::ReplicatedMesh m_Mesh_patch
Patch mesh.
std::unordered_map< unsigned int, int > m_node_map_Patch_to_Parent
Mapping between the patch and parent mesh nodes, using the former as keys.
std::unordered_set< unsigned int > & node_indexes()
Returns the set of nodes inside the patch.
std::unordered_set< unsigned int > m_Patch_Elem_indexes
Set of elements inside the patch.
std::unordered_map< unsigned int, int > m_element_already_treated
[ADV. FRONT] Marks if an element was already treated or not
void set_elem_as_inside_queue(unsigned int elem_id)
[ADV. FRONT] Mark element as already inside the deque of elements to be treated.
std::unordered_map< unsigned int, int > m_node_map_Parent_to_Patch
Mapping between the parent and patch mesh nodes, using the former as keys.
Class used to build a mesh patch from a parent mesh and an coupling mesh element. ...
void export_patch_mesh(std::string &filename_base)
Export the patch mesh to a file.
void insert_patch_element(const libMesh::Elem *Patch_elem)
Insert an parent mesh element inside the patch, updating the data structures.
const libMesh::Elem * current_elem_pointer()
unsigned int intersection_queue_extract_front_elem()
[ADV. FRONT] Pop and returns the first element to be treated.
libMesh::ReplicatedMesh & parent_mesh()
Returns the parent mesh.
unsigned int FrontSearch_prepare_for_probed_test()
[ADV. FRONT] Reset the advancing front search data structures, with the exception of list of elements...
std::unordered_map< unsigned int, std::unordered_set< unsigned int > > & patch_elem_neighbours()
Returns the patch mesh element neighbour table.
bool intersection_queue_empty()
[ADV. FRONT] Check if deque of elements to be treated is empty.
Intersection_Tools m_Intersection_Test
Intersection search and construction tools.
const unsigned int m_nodes
Parent mesh number of processors.
const libMesh::Parallel::Communicator & m_local_comm
Patch mesh communicator.
bool test_queue_empty()
[ADV. FRONT] Check if deque of elements to be tested is empty.
std::unordered_set< unsigned int > & elem_indexes()
Returns the set of elements inside the patch.
libMesh::ReplicatedMesh & patch_mesh()
Returns the patch mesh.
libMesh::ReplicatedMesh & m_Mesh_parent
Parent mesh.
const libMesh::Elem * elem(unsigned int idx)
std::unordered_map< unsigned int, std::unordered_set< unsigned int > > m_Patch_Elem_Neighbours
Element neighbour table for the patch.
Patch_construction(libMesh::Mesh &mesh, const libMesh::Parallel::Communicator &local_comm, bool debugOutput=false)
Constructor with a pre-defined parent mesh and a local communicator.
Class with a series of methods to find the intersections between libMesh's elements, using CGAL internally.
std::unordered_map< unsigned int, int > m_element_inside_intersection_queue
[ADV. FRONT] Marks if an element is already inside "m_element_intersection_queue" ...
const libMesh::Parallel::Communicator & m_comm
Parent mesh communicator.
unsigned int convert_patch_to_parent_elem_id(unsigned int input)
Convert an element index from the patch mesh to the parent mesh.
std::unordered_set< unsigned int > m_Patch_Node_indexes
Set of nodes inside the patch.
void BuildPatch(const libMesh::Elem *Query_elem)
Build the patch mesh covering a given "Query_elem".
bool set_neighbors_to_search_next_pairs()
[ADV. FRONT] Set the list of neighbors of the current element that must be tested yet...
void set_elem_as_treated(unsigned int elem_id)
[ADV. FRONT] Mark element as already treated.
void add_neighbors_to_test_list()
[ADV. FRONT] Adds element to test list.
std::unique_ptr< libMesh::PointLocatorBase > m_Parent_Point_Locator
Parent mesh point locator.
unsigned int test_queue_extract_front_elem()
[ADV. FRONT] Pop and returns the first element to be tested.
std::deque< int > m_element_intersection_queue
[ADV. FRONT] Deque containing the elements to be treated.
void FrontSearch_reset()
[ADV. FRONT] Reset the advancing front search data structures, with the exception of list of elements...
unsigned int size()
Returns the number of elements inside the patch.
unsigned int m_working_element_id
[ADV. FRONT] Index of the patch element currently being tested
std::deque< int > m_element_test_queue
[ADV. FRONT] Deque containing the elements to be tested
bool m_bPrintDebug
Print debug information? Default: false.
void intersection_queue_push_back(unsigned int elem_id)
[ADV. FRONT] Push back element to the deque containing the elements to be treated.
std::unordered_set< unsigned int > m_element_neighbours_to_search
[ADV. FRONT] Set containing the current element's neighbors that must be tested yet.
void build_patch_mesh()
Build a patch mesh from the patch data structures.
std::unordered_map< unsigned int, int > m_elem_map_Patch_to_Parent
Mapping between the patch and parent mesh elements, using the former as keys.
unsigned int convert_parent_to_patch_elem_id(unsigned int input)
Convert an element index from the parent mesh to the patch mesh.
const unsigned int m_rank
Parent mesh processor rank.
std::unordered_map< unsigned int, int > m_elem_map_Parent_to_Patch
Mapping between the parent and patch mesh elements, using the former as keys.
void FrontSearch_initialize()
[ADV. FRONT] Initialize the advancing front search data structures.
std::unordered_set< unsigned int > & neighbors_to_search_next_pair()
[ADV. FRONT] Returns the current element's neighbors that must be tested yet.