CArl
Code Arlequin / C++ implementation
intersection_search.h
Go to the documentation of this file.
1 /*
2  * intersection_search.h
3  *
4  * Created on: Apr 14, 2016
5  * Author: Thiago Milanetto Schlittler
6  */
7 
8 #ifndef COMMON_INTERSECTIONS_PARALLEL_INTERSECTION_SEARCH_H_
9 #define COMMON_INTERSECTIONS_PARALLEL_INTERSECTION_SEARCH_H_
10 
11 #include "carl_headers.h"
12 #include "mesh_tables.h"
13 
15 #include "patch_construction.h"
16 
17 namespace carl
18 {
19 
20 // *************************
21 // Intersection_Search class
22 // *************************
23 
29 {
30 protected:
31 
32  // Mesh addresses
33  libMesh::Mesh& m_Mesh_A;
34  libMesh::Mesh& m_Mesh_B;
35  libMesh::Mesh& m_Mesh_Coupling;
36 
37  // Communicators and parallel data
38  const libMesh::Parallel::Communicator& m_comm;
39  const unsigned int m_nodes;
40  const unsigned int m_rank;
41  const libMesh::Parallel::Communicator& m_local_comm;
42 
43  // Objects containing the two patches
46 
53 
56 
61  std::unordered_multimap<unsigned int,unsigned int> m_Intersection_Pairs_multimap;
62 
65 
68 
70  std::vector<unsigned int> m_Nb_Of_Intersections_Elem_C;
71 
73  libMesh::ErrorVector m_coupling_weights;
74 
77 
80 
83 
86 
89 
92 
95 
96  std::string m_Output_filename_base;
97 
99  libMesh::PerfLog m_perf_log;
104 
105  // PROTECTED methods
110  void BuildCoupledPatches(const libMesh::Elem * Query_elem, int patch_counter = 0);
111 
116  void FindPatchIntersections_Brute(const libMesh::Elem * Query_elem);
117 
121  void FindPatchIntersections_Front(const libMesh::Elem * Query_elem);
122 
132  void FindFirstPair( Patch_construction * Patch_guide,
133  Patch_construction * Patch_probed,
134  std::pair<unsigned int,unsigned int> & First_intersection);
135 
142  void BruteForce_FindFirstPair( Patch_construction * Patch_guide,
143  Patch_construction * Patch_probed,
144  std::pair<unsigned int,unsigned int> & First_intersection);
145 
151 
157 
163 
169 
171  void CalculateIntersectionVolume(const libMesh::Elem * Query_elem);
172 
174  void UpdateCouplingIntersection(const libMesh::Elem * Query_elem);
175 
176 public:
177 
179  Intersection_Search(libMesh::Mesh & mesh_A,
180  libMesh::Mesh & mesh_B,
181  libMesh::Mesh & mesh_Coupling,
182  libMesh::Mesh & mesh_I,
183  const std::string & output_base = std::string("test"),
185  double Min_Inter_Volume = 1E-15,
186  bool bDoPerf_log = true,
187  bool bDebugOutput = false) :
188  m_Mesh_A { mesh_A },
189  m_Mesh_B { mesh_B },
190  m_Mesh_Coupling { mesh_Coupling },
191  m_comm { m_Mesh_Coupling.comm() },
192  m_nodes { m_comm.size() },
193  m_rank { m_comm.rank() },
194  m_local_comm { mesh_I.comm() },
195  m_Patch_Constructor_A { Patch_construction(m_Mesh_A,m_local_comm)},
196  m_Patch_Constructor_B { Patch_construction(m_Mesh_B,m_local_comm)},
197  m_MeshingMethod { MeshingMethod },
198  m_Mesh_Intersection { Mesh_Intersection(mesh_I,m_Mesh_A,m_Mesh_B,m_MeshingMethod)},
199  m_bSaveInterData { true },
200  m_bDidPreliminarySearch { false },
201  m_bHavePreallocData { false },
202  m_bIntersectionsBuilt { false },
203  m_Min_Inter_Volume { Min_Inter_Volume },
204  m_bSkipIntersectionConstruction { false },
205  m_bSkipIntersectionPartitioning { false },
206  m_Output_filename_base { output_base + "_r_" + std::to_string(m_rank) + "_n_" + std::to_string(m_nodes)},
207  MASTER_bPerfLog_intersection_search {bDoPerf_log},
208  m_perf_log { libMesh::PerfLog("Intersection search", MASTER_bPerfLog_intersection_search) },
209  m_bPrintDebug { bDebugOutput },
210  m_bPrintTimingData { false },
211  m_bPrintIntersectionsPerPartData { false }
212  {
213  // Reserve space for the intersection multimap
214  m_Nb_Of_Intersections_Elem_C.resize(mesh_Coupling.n_elem(),0);
215  };
216 
218  libMesh::Mesh & mesh_A();
219 
221  libMesh::Mesh & mesh_B();
222 
224  libMesh::Mesh & mesh_Coupling();
225 
226  // PUBLIC Methods
233  void PreparePreallocationAndLoad(SearchMethod search_type = BRUTE);
234 
237 
239  void BuildIntersections(SearchMethod search_type = BRUTE);
240 
242  void SetScalingFiles(const std::string& timing_data_file_base);
243 
245  void SkipIntersectionConstruction(bool bSkipIntersectionConstruction)
246  {
247  m_bSkipIntersectionConstruction = bSkipIntersectionConstruction;
248  }
249 
251  void SkipIntersectionPartitioning(bool bSkipIntersectionPartitioning)
252  {
253  m_bSkipIntersectionPartitioning = bSkipIntersectionPartitioning;
254  }
255 
257  void CalculateGlobalVolume();
258 };
259 }
260 
261 #endif /* COMMON_INTERSECTIONS_PARALLEL_INTERSECTION_SEARCH_H_ */
bool m_bDidPreliminarySearch
Boolean flag determining if we did a preliminary intersection search, used for the coupling mesh repa...
std::string m_timing_data_file_base
Output filenames base for the timing data.
bool m_bIntersectionsBuilt
Boolean flag indicating if the intersections were built. (A bit useless right now ...
double m_Min_Inter_Volume
Volume cutoff for the intersection polyhedrons. Default: 1E-15.
void SkipIntersectionConstruction(bool bSkipIntersectionConstruction)
Set the "Skip intersection construction" flag.
SearchMethod
Definition: common_enums.h:54
bool m_bSkipIntersectionConstruction
Boolean indicating if we should skip the intersection construction. Default: false.
void FindAndBuildIntersections_Front()
Find and build all the intersections, using the advancing front method.
void FindIntersections_Front()
Find all the intersections, using the advancing front method.
void FindIntersections_Brute()
Find all the intersections, using the brute force method.
const libMesh::Parallel::Communicator & m_local_comm
Local communicator, used for mesh patches.
Class used to build a mesh patch from a parent mesh and an coupling mesh element. ...
std::string m_Output_filename_base
Output filenames base.
bool m_bPrintIntersectionsPerPartData
Print intersections per partition. Default: false.
void FindPatchIntersections_Brute(const libMesh::Elem *Query_elem)
Find all the intersections between the patches associated to the Query_elem, using a brute force meth...
libMesh::Mesh & m_Mesh_Coupling
Mesh representing the coupling region.
const libMesh::Parallel::Communicator & m_comm
Global communicator.
const unsigned int m_nodes
Number of MPI processors.
Intersection_Search(libMesh::Mesh &mesh_A, libMesh::Mesh &mesh_B, libMesh::Mesh &mesh_Coupling, libMesh::Mesh &mesh_I, const std::string &output_base=std::string("test"), IntersectionMeshingMethod MeshingMethod=IntersectionMeshingMethod::CGAL, double Min_Inter_Volume=1E-15, bool bDoPerf_log=true, bool bDebugOutput=false)
Constructor.
void BuildCoupledPatches(const libMesh::Elem *Query_elem, int patch_counter=0)
Build both patches associated a given query element from the coupling region mesh.
void BruteForce_FindFirstPair(Patch_construction *Patch_guide, Patch_construction *Patch_probed, std::pair< unsigned int, unsigned int > &First_intersection)
Find the first intersecting pair from a patch, doing a full scan of the patches.
IntersectionMeshingMethod m_MeshingMethod
Flag defining the intersection meshing algorithm.
void PreparePreallocationAndLoad(SearchMethod search_type=BRUTE)
Do a preliminary search, to optimize the intersection search and construction.
void PreallocateAndPartitionCoupling()
Preallocate Intersection_Search::m_Intersection_Pairs_multimap and repartition the coupling mesh...
bool m_bSkipIntersectionPartitioning
Boolean indicating if we should skip the intersection repartitioning. Default: false.
Patch_construction m_Patch_Constructor_B
Patch_construction object for mesh B.
void UpdateCouplingIntersection(const libMesh::Elem *Query_elem)
Build the intersections associated to the Query_elem and update the intersection mesh.
Class containing the structure needed to find all the intersections between two meshes, inside the coupling region mesh.
libMesh::PerfLog m_perf_log
libMesh::PerfLog object.
Patch_construction m_Patch_Constructor_A
Patch_construction object for mesh A.
IntersectionMeshingMethod
Definition: common_enums.h:47
std::unordered_multimap< unsigned int, unsigned int > m_Intersection_Pairs_multimap
Multimap containing the intersection pairs.
std::vector< unsigned int > m_Nb_Of_Intersections_Elem_C
Vector containing the number of intersections found inside each of the coupling mesh elements...
Class with a series of methods to find the intersections between libMesh's elements, using CGAL internally.
bool m_bHavePreallocData
Boolean flag determining if we have the data for a proper preallocation of m_Intersection_Pairs_multi...
void FindFirstPair(Patch_construction *Patch_guide, Patch_construction *Patch_probed, std::pair< unsigned int, unsigned int > &First_intersection)
Find the first intersecting pair from a patch.
Mesh_Intersection m_Mesh_Intersection
Object containing the intersection mesh.
libMesh::ErrorVector m_coupling_weights
libMesh::ErrorVector used to repartition the coupling mesh.
Intersection_Tools m_Intersection_test
Intersection operations for the main intersection tests.
bool m_bPrintDebug
Print debug data. Default: false.
void CalculateGlobalVolume()
Calculate the total intersection volume over all the processors.
libMesh::Mesh & mesh_A()
Reference to the mesh A.
void SetScalingFiles(const std::string &timing_data_file_base)
Set up timing output file.
libMesh::Mesh & mesh_Coupling()
Reference to the coupling mesh.
void SkipIntersectionPartitioning(bool bSkipIntersectionPartitioning)
Set the "Skip the coupling mesh repartition" flag.
bool MASTER_bPerfLog_intersection_search
Do performance log? Default: true.
void FindPatchIntersections_Front(const libMesh::Elem *Query_elem)
Find all the intersections between the patches associated to the Query_elem, using an advancing front...
Class used to construct the intersection meshes.
bool m_bSaveInterData
Boolean flag determining if we should save the intersection data or not. Default: true...
void CalculateIntersectionVolume(const libMesh::Elem *Query_elem)
Calculate the volume of the intersections associated to Query_elem without updating the intersection ...
Intersection_Tools m_Intersection_test_neighbors
Intersection operations for the neighbor intersection tests. (why do we need both?)
void FindAndBuildIntersections_Brute()
Find and build all the intersections, using the brute force method.
const unsigned int m_rank
This processor's rank (or ID in the communicator)
void BuildIntersections(SearchMethod search_type=BRUTE)
Find and build all the intersections.
libMesh::Mesh & mesh_B()
Reference to the mesh B.
bool m_bPrintTimingData
Print timing data. Default: false.