CArl
Code Arlequin / C++ implementation
stitch_meshes.h
Go to the documentation of this file.
1 /*
2  * stitch_meshes.h
3  *
4  * Created on: Jun 2, 2016
5  * Author: Thiago Milanetto Schlittler
6  */
7 
8 #ifndef COMMON_INTERSECTIONS_PARALLEL_STITCH_MESHES_H_
9 #define COMMON_INTERSECTIONS_PARALLEL_STITCH_MESHES_H_
10 
11 #include "carl_headers.h"
12 #include "mesh_tables.h"
14 
15 namespace carl
16 {
17 
18 // *******************
19 // Stitch_Meshes class
20 // *******************
21 
36 {
37 protected:
38  // Communicators and parallel data.
39  const libMesh::Parallel::Communicator& m_world_comm;
40  const unsigned int m_nodes;
41  const unsigned int m_rank;
42 
44  libMesh::ReplicatedMesh& m_Stitched_mesh;
45 
47  std::vector<std::string> m_mesh_filenames;
48 
50  std::vector<std::string> m_table_filenames;
51 
53  unsigned int m_nb_files;
54 
55  // Output files
56  std::string m_base_output;
57  std::string m_mesh_output;
58  std::string m_table_output;
59 
61  std::vector<std::pair<unsigned int, unsigned int> > m_intersection_pairs;
62 
63  // Unordered sets containing the elements from each mesh involved
64  // in the intersection
65  std::unordered_set<unsigned int> m_restriction_set_first;
66  std::unordered_set<unsigned int> m_restriction_set_second;
67 
69  std::vector<unsigned int> m_intersection_nb_of_elements;
70 
71  // Data structure and variables associated to the "grid" used to collapse
72  // elements that are too small - reproduces the Mesh_Intersection class!
73 
75  double m_eps;
76 
78  double m_vol_tol;
79 
81  std::vector<long > m_GridN;
82 
83  std::vector<long > m_dummy_discrete_point;
84 
86  libMesh::Point m_Grid_MinPoint;
87 
89  libMesh::Point m_Grid_MaxPoint;
90 
92  std::unordered_map<std::vector<long>, unsigned int, PointHash_3D, PointHash_3D_Equal >
94 
97 
98  // Parameters of the final mesh
99  unsigned int m_nb_of_intersections;
100  unsigned int m_nb_of_elements;
101  unsigned int m_nb_of_nodes;
102  unsigned int m_maximum_nb_of_nodes;
103 
104  // Boolean set when the filename base is also set
106 
107  // Boolean set when the grid is defined
110 
111  // Boolean controlling if the stitched intersection mesh was finished
113 
114  // Perflog and debug variables
116 
117  // PROTECTED constructor
118  Stitch_Meshes();
119 
120  // PROTECTED methods
121 
122 public:
123 
124  // Constructors
125  Stitch_Meshes( libMesh::Mesh& output_mesh, const std::string output_filename = "test_stitched", long grid_n_min = static_cast<long>(1E9), bool debugOutput = true) :
126  m_world_comm { output_mesh.comm() },
127  m_nodes { m_world_comm.size() },
128  m_rank { m_world_comm.rank() },
129  m_Stitched_mesh { output_mesh },
130  m_nb_files { 0 },
131  m_base_output { output_filename },
132  m_eps { -1 },
133  m_vol_tol { -1 },
134  m_GridN { std::vector<long> (3,-1) },
135  m_dummy_discrete_point { std::vector<long> (3,-1) },
136  m_Grid_MinPoint { libMesh::Point(0,0,0) },
137  m_Grid_MaxPoint { libMesh::Point(1,1,1) },
138  m_GridN_min { grid_n_min },
139  m_nb_of_intersections { 0 },
140  m_nb_of_elements { 0 },
141  m_nb_of_nodes { 0 },
142  m_maximum_nb_of_nodes { 0 },
143  m_bFilenamesSet { false },
144  m_bGridDefined { false },
145  m_bGridPreallocated { false },
146  m_bMeshFinalized { false },
147  m_bPrintDebug { debugOutput }
148  {
149  m_Stitched_mesh.allow_renumbering(false);
150  };
151 
153  const libMesh::ReplicatedMesh & mesh();
154 
156  const std::unordered_set<unsigned int>* get_restricted_set_pointer_first();
157 
159  const std::unordered_set<unsigned int>* get_restricted_set_pointer_second();
160 
161  // PUBLIC methods
163  void set_base_filenames(std::vector<std::string> & mesh_filenames, std::vector<std::string> & table_filenames);
164 
166  void set_base_filenames(const std::string & filename_base = std::string("test_r_"), const std::string & mesh_format = std::string(".msh"), unsigned int nb_of_files = 0);
167 
169  void preallocate_grid(int map_preallocation);
170 
172  void set_grid_constraints(const libMesh::Mesh & mesh_A, const libMesh::Mesh & mesh_B, double vol_tol = -1);
173 
175  void set_grid_constraints(Mesh_Intersection & mesh_inter_obj);
176 
178  void join_tables();
179 
181  void stitch_meshes();
182 
184  void convert_to_discrete(const libMesh::Point& iPoint, std::vector<long>& oPoint);
185 
186 
187 };
188 }
189 
190 #endif /* COMMON_INTERSECTIONS_PARALLEL_STITCH_MESHES_H_ */
std::vector< long > m_GridN
Dimensions of the discrete point grid.
Definition: stitch_meshes.h:81
long m_GridN_min
Minimal number of integers over each dimension of the discrete grid.
Definition: stitch_meshes.h:96
const unsigned int m_nodes
Number of processors.
Definition: stitch_meshes.h:40
unsigned int m_nb_files
Number of files.
Definition: stitch_meshes.h:53
std::vector< std::pair< unsigned int, unsigned int > > m_intersection_pairs
Vector containing all the intersection pairs.
Definition: stitch_meshes.h:61
bool m_bGridDefined
Is the grid defined?
std::string m_table_output
Intersection table output filename.
Definition: stitch_meshes.h:58
double m_eps
Precision of the discrete point grid.
Definition: stitch_meshes.h:75
unsigned int m_nb_of_elements
Final mesh's number of elements.
std::unordered_set< unsigned int > m_restriction_set_second
Set of elements used for the restriction of the second mesh.
Definition: stitch_meshes.h:66
bool m_bGridPreallocated
Is the grid preallocated?
bool m_bFilenamesSet
Have the filenames been set?
std::vector< unsigned int > m_intersection_nb_of_elements
Nmber of elements inside each intersection.
Definition: stitch_meshes.h:69
void preallocate_grid(int map_preallocation)
Preallocate the discrete points grid.
unsigned int m_nb_of_intersections
Final mesh's number of intersections.
Definition: stitch_meshes.h:99
std::string m_base_output
Base output filename.
Definition: stitch_meshes.h:56
unsigned int m_nb_of_nodes
Final mesh's number of nodes.
void set_base_filenames(std::vector< std::string > &mesh_filenames, std::vector< std::string > &table_filenames)
Set by hand the filenames used to build the stitched mesh.
std::unordered_set< unsigned int > m_restriction_set_first
Set of elements used for the restriction of the first mesh.
Definition: stitch_meshes.h:65
std::vector< long > m_dummy_discrete_point
Definition: stitch_meshes.h:83
void stitch_meshes()
Stitch the meshes.
libMesh::ReplicatedMesh & m_Stitched_mesh
Final, stitched mesh.
Definition: stitch_meshes.h:44
void set_grid_constraints(const libMesh::Mesh &mesh_A, const libMesh::Mesh &mesh_B, double vol_tol=-1)
Set the boundaries of the discrete points grid, using the intersected meshes as a base...
void join_tables()
Join the intersection tables.
std::unordered_map< std::vector< long >, unsigned int, PointHash_3D, PointHash_3D_Equal > m_discrete_vertices
Unordered map (or hash) for the discrete points (key).
Definition: stitch_meshes.h:93
void convert_to_discrete(const libMesh::Point &iPoint, std::vector< long > &oPoint)
Convert a real valued point to a discrete point.
libMesh::Point m_Grid_MinPoint
Minimal point of the discrete grid.
Definition: stitch_meshes.h:86
const unsigned int m_rank
Processor rank.
Definition: stitch_meshes.h:41
Class used to stitch together different meshes.
Definition: stitch_meshes.h:35
double m_vol_tol
Grid minimum volume.
Definition: stitch_meshes.h:78
const std::unordered_set< unsigned int > * get_restricted_set_pointer_second()
Returns the pointer to the set with the elements used to form the second restricted mesh...
std::string m_mesh_output
Mesh output filename.
Definition: stitch_meshes.h:57
bool m_bPrintDebug
Print debug information? Default: false.
const libMesh::Parallel::Communicator & m_world_comm
MPI Communicator.
Definition: stitch_meshes.h:39
bool m_bMeshFinalized
Is final mesh finalized?
libMesh::Point m_Grid_MaxPoint
Maximum point of the discrete grid.
Definition: stitch_meshes.h:89
const std::unordered_set< unsigned int > * get_restricted_set_pointer_first()
Returns the pointer to the set with the elements used to form the first restricted mesh...
unsigned int m_maximum_nb_of_nodes
Upper limit for the final mesh's number of nodes.
std::vector< std::string > m_mesh_filenames
File names of the meshes to be stitched.
Definition: stitch_meshes.h:47
const libMesh::ReplicatedMesh & mesh()
Returns the stitched mesh.
std::vector< std::string > m_table_filenames
File names of intersection tables to joined.
Definition: stitch_meshes.h:50
Stitch_Meshes(libMesh::Mesh &output_mesh, const std::string output_filename="test_stitched", long grid_n_min=static_cast< long >(1E9), bool debugOutput=true)