19 homemade_assert_msg(mesh_filenames.size() == table_filenames.size(),
"File lists have different sizes!\n");
27 for(
unsigned int iii = 0; iii <
m_nb_files; ++iii)
52 for(
unsigned int iii = 0; iii <
m_nb_files; ++iii)
54 m_mesh_filenames[iii] = filename_base +
"_r_" + std::to_string(iii) +
"_n_" + std::to_string(m_nb_files) + mesh_format;
55 m_table_filenames[iii] = filename_base +
"_r_" + std::to_string(iii) +
"_n_" + std::to_string(m_nb_files) +
"_inter_table.dat";
73 libMesh::MeshTools::BoundingBox bbox_A = libMesh::MeshTools::bounding_box(mesh_A);
74 libMesh::MeshTools::BoundingBox bbox_B = libMesh::MeshTools::bounding_box(mesh_B);
80 std::vector<double> eps_candidates(3,0);
81 for(
unsigned int iii = 0; iii < 3; ++iii)
88 m_eps = *std::min_element(eps_candidates.begin(),eps_candidates.end());
90 for(
unsigned int iii = 0; iii < 3; ++iii)
96 for(
unsigned int iii = 0; iii < 3; ++iii)
109 double fraction_vol_A = (bbox_A.max()(0) - bbox_A.min()(0)) *
110 (bbox_A.max()(1) - bbox_A.min()(1)) *
111 (bbox_A.max()(2) - bbox_A.min()(2)) /
114 double fraction_vol_B = (bbox_B.max()(0) - bbox_B.min()(0)) *
115 (bbox_B.max()(1) - bbox_B.min()(1)) *
116 (bbox_B.max()(2) - bbox_B.min()(2)) /
119 unsigned int est_elem = std::max(fraction_vol_A * mesh_A.n_elem(),fraction_vol_B * mesh_B.n_elem());
121 m_vol_tol = 1E-6 * grid_volume / est_elem;
133 std::cout <<
" DEBUG: discrete grid" << std::endl;
134 std::cout <<
" -> eps : " <<
m_eps << std::endl;
135 std::cout <<
" -> volume : " <<
m_vol_tol << std::endl;
136 std::cout <<
" -> Grid dimensions : " <<
m_GridN[0] <<
" " <<
m_GridN[1] <<
" " <<
m_GridN[2] <<
" " << std::endl << std::endl;
155 std::cout <<
" DEBUG: discrete grid" << std::endl;
156 std::cout <<
" -> eps : " <<
m_eps << std::endl;
157 std::cout <<
" -> volume : " <<
m_vol_tol << std::endl;
158 std::cout <<
" -> Grid dimensions : " <<
m_GridN[0] <<
" " <<
m_GridN[1] <<
" " <<
m_GridN[2] <<
" " << std::endl << std::endl;
171 std::ifstream table_file;
176 unsigned int temp_nb_of_intersections = 0;
177 unsigned int temp_nb_of_elements = 0;
178 unsigned int temp_nb_of_nodes = 0;
180 for(
unsigned int iii = 0; iii <
m_nb_files; ++iii)
183 table_file >> temp_nb_of_intersections;
184 table_file >> temp_nb_of_elements;
185 table_file >> temp_nb_of_nodes;
208 unsigned int intersection_idx = 0;
209 unsigned int dummy_uint = 0;
210 unsigned int nb_of_elems = 0;
211 for(
unsigned int iii = 0; iii <
m_nb_files; ++iii)
214 table_file >> temp_nb_of_intersections;
215 table_file >> temp_nb_of_elements;
216 table_file >> temp_nb_of_nodes;
218 for(
unsigned int jjj = 0; jjj < temp_nb_of_intersections; ++jjj)
220 table_file >> dummy_uint;
227 nb_of_elems += m_intersection_nb_of_elements[intersection_idx];
237 unsigned int intersection_elem_idx = 0;
241 << nb_of_elems << std::endl;
258 joined_tables_file.close();
267 temp_mesh.allow_renumbering(
false);
269 unsigned int full_mesh_nb_elems = 0;
270 unsigned int full_mesh_nb_nodes = 0;
272 libMesh::Elem * copy_elem = NULL;
273 libMesh::Elem * mesh_elem = NULL;
274 libMesh::Node * mesh_node = NULL;
276 double dummy_volume = 0;
279 for(
unsigned int iii = 0; iii <
m_nb_files; ++iii)
285 libMesh::ReplicatedMesh::element_iterator it_mesh = temp_mesh.elements_begin();
287 for( ; it_mesh != temp_mesh.elements_end(); ++it_mesh)
289 copy_elem = * it_mesh;
292 mesh_elem = libMesh::Elem::build(libMesh::TET4).release();
293 mesh_elem->set_id(full_mesh_nb_elems);
294 mesh_elem->processor_id(0);
297 for(
unsigned int jjj = 0; jjj < 4; ++jjj)
304 mesh_node =
m_Stitched_mesh.add_point(copy_elem->point(jjj),full_mesh_nb_nodes,0);
305 ++full_mesh_nb_nodes;
313 mesh_elem->set_node(jjj) = mesh_node;
318 dummy_volume += mesh_elem->volume();
320 ++full_mesh_nb_elems;
327 size_t collisions = 0;
336 std::cout <<
" DEBUG: discrete grid hash collisions" << std::endl;
337 std::cout <<
" -> Nb. of collisions / size : " << collisions <<
" / " <<
m_discrete_vertices.size()
348 std::cout <<
" DEBUG: stitched mesh" << std::endl;
349 std::cout <<
" -> Volume : " << dummy_volume << std::endl << std::endl;
352 int wrong_volume = 0;
353 libMesh::ReplicatedMesh::element_iterator elem_begin =
m_Stitched_mesh.local_elements_begin();
354 libMesh::ReplicatedMesh::element_iterator elem_end =
m_Stitched_mesh.local_elements_end();
356 for( ; elem_begin != elem_end; ++elem_begin)
358 libMesh::Elem * dummy_elem = * elem_begin;
359 if(std::abs(dummy_elem->volume()) <
m_vol_tol)
365 std::cout <<
" -> bad volumes : " << wrong_volume <<
" ( " <<
m_vol_tol <<
" ) " << std::endl;
std::vector< long > m_GridN
Dimensions of the discrete point grid.
long m_GridN_min
Minimal number of integers over each dimension of the discrete grid.
libMesh::Point & min_point()
Returns the minimal point of the discrete grid.
const unsigned int m_nodes
Number of processors.
unsigned int m_nb_files
Number of files.
std::vector< std::pair< unsigned int, unsigned int > > m_intersection_pairs
Vector containing all the intersection pairs.
bool m_bGridDefined
Is the grid defined?
libMesh::Point & max_point()
Returns the maximum point of the discrete grid.
std::string m_table_output
Intersection table output filename.
double m_eps
Precision of the discrete point grid.
unsigned int m_nb_of_elements
Final mesh's number of elements.
long grid_min_size()
Returns the minimum discrete grid size.
std::unordered_set< unsigned int > m_restriction_set_second
Set of elements used for the restriction of the second mesh.
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.
void preallocate_grid(int map_preallocation)
Preallocate the discrete points grid.
unsigned int m_nb_of_intersections
Final mesh's number of intersections.
std::string m_base_output
Base output filename.
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.
double eps()
Returns the discrete grid step.
std::unordered_set< unsigned int > m_restriction_set_first
Set of elements used for the restriction of the first mesh.
std::vector< long > m_dummy_discrete_point
void stitch_meshes()
Stitch the meshes.
libMesh::ReplicatedMesh & m_Stitched_mesh
Final, stitched mesh.
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).
void convert_to_discrete(const libMesh::Point &iPoint, std::vector< long > &oPoint)
Convert a real valued point to a discrete point.
double min_vol()
Returns the minimal polyhedron volume.
libMesh::Point m_Grid_MinPoint
Minimal point of the discrete grid.
std::vector< long > & grid_sizes()
Returns the discrete grid sizes.
double m_vol_tol
Grid minimum volume.
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...
Class used to construct the intersection meshes.
std::string m_mesh_output
Mesh output filename.
bool m_bPrintDebug
Print debug information? Default: false.
const libMesh::Parallel::Communicator & m_world_comm
MPI Communicator.
libMesh::Point m_Grid_MaxPoint
Maximum point of the discrete grid.
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.
void jump_lines(T &filestream, unsigned int numberOfLines=1)
const libMesh::ReplicatedMesh & mesh()
Returns the stitched mesh.
std::vector< std::string > m_table_filenames
File names of intersection tables to joined.