CArl
Code Arlequin / C++ implementation
CArl_build_intersections.cpp File Reference

Implementation of the parallel intersection search. More...

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 

Detailed Description

Implementation of the parallel intersection search.

Usage: ./CArl_build_intersections -i [input file]

This program finds and constructs all the intersections between the meshes provided by the user. The input file is parsed by the carl::get_input_params(GetPot& field_parser, parallel_intersection_test_params& input_params) function, and it contains the following parameters.

Required parameters:

  • MeshA, -mA or --meshA : path to the mesh A.
  • MeshB, -mB or --meshB : path to the mesh B.
  • MeshC, -mC or --meshC : path to the coupling mesh C.

Optional parameters:

  • OutputBase, -mO or --output : base of the output files (including folders). Default: test_inter.
  • MeshingMethod or --meshingMethodType : intersection meshing method. Values: CGAL or LIBMESH_TETGEN. Default: CGAL.

Boolean flags:

  • StitchInterMeshes : do not stich together the intersection meshes.
  • VerboseOutput or --verbose : print some extra information, such as the coupling mesh partitioning.

Definition in file CArl_build_intersections.cpp.

Function Documentation

int main ( int  argc,
char *  argv[] 
)

Definition at line 33 of file CArl_build_intersections.cpp.

34 {
35  // --- Initialize libMesh
36  libMesh::LibMeshInit init(argc, argv);
37 
38  // libMesh's C++ / MPI communicator wrapper
39  libMesh::Parallel::Communicator& WorldComm = init.comm();
40 
41  // Number of processors and processor rank.
42  unsigned int nodes = WorldComm.size();
43  unsigned int rank = WorldComm.rank();
44 
45  // Create local communicator
46  libMesh::Parallel::Communicator LocalComm;
47  WorldComm.split(rank,rank,LocalComm);
48 
49  // Main program performance log
50  libMesh::PerfLog perf_log("Main program");
51 
52  // --- Set up inputs
53 
54  // Command line parser
55  GetPot command_line(argc, argv);
56 
57  // File parser
58  GetPot field_parser;
59 
60  // If there is an input file, parse it to get the parameters. Else, parse the command line
61  std::string input_filename;
62  if (command_line.search(2, "--inputfile", "-i")) {
63  input_filename = command_line.next(input_filename);
64  field_parser.parse_input_file(input_filename, "#", "\n", " \t\n");
65  } else {
66  field_parser = command_line;
67  }
68 
70  carl::get_intersection_input_params(field_parser, input_params);
71 
72  // Declare the three meshes to be intersected
73  libMesh::Mesh test_mesh_A(WorldComm);
74  libMesh::Mesh test_mesh_B(WorldComm);
75  libMesh::Mesh test_mesh_C(WorldComm);
76 
77  // Declare the LOCAL output mesh
78  libMesh::Mesh test_mesh_I(LocalComm);
79 
80  // Read the mesh files and prepare for use
81  test_mesh_A.read(input_params.mesh_A);
82  test_mesh_B.read(input_params.mesh_B);
83  test_mesh_C.read(input_params.mesh_C);
84 
85  test_mesh_A.prepare_for_use();
86  test_mesh_B.prepare_for_use();
87  test_mesh_C.prepare_for_use();
88 
89  // --- Set up the Intersection_search object
90  /*
91  * This object is the main userinterface with the intersection search algorithms.
92  */
93  perf_log.push("Set up");
94  carl::Intersection_Search search_coupling_intersections(
95  test_mesh_A, // Input meshes
96  test_mesh_B, //
97  test_mesh_C, //
98 
99  test_mesh_I, // LOCAL output mesh
100 
101  input_params.output_base, // Common output filename path
102  input_params.inter_meshing_method // Intersection meshing method
103  );
104  perf_log.pop("Set up");
105 
106 
107  // If set to do "verbose" output, print the current partitioning of the intersection search
108  if(input_params.bVerbose)
109  {
110  std::cout << " -> Nb. coupling elements before repartitioning (intersection partition) : "
111  << test_mesh_C.n_partitions() << " ( ";
112  for(unsigned int iii = 0; iii < nodes; ++iii)
113  {
114  std::cout << test_mesh_C.n_elem_on_proc(iii) << " ";
115  }
116  std::cout << ")" << std::endl << std::endl;
117  }
118 
119  // Preallocate the intersection data structures (intersection tables, etc ...)
120  perf_log.push("Prepare intersection load");
121  search_coupling_intersections.PreparePreallocationAndLoad(/* SearchMethod = BRUTE */);
122  search_coupling_intersections.PreallocateAndPartitionCoupling();
123  perf_log.push("Prepare intersection load");
124 
125  // Print the current partitioning of the intersection search
126  if(input_params.bVerbose)
127  {
128  std::cout << " -> Nb. coupling elements after repartitioning (intersection partition) : "
129  << test_mesh_C.n_partitions() << " ( ";
130  for(unsigned int iii = 0; iii < nodes; ++iii)
131  {
132  std::cout << test_mesh_C.n_elem_on_proc(iii) << " ";
133  }
134  std::cout << ")" << std::endl << std::endl;
135  }
136 
137  // --- Do the intersection search!
138  perf_log.push("Search intersection");
139  search_coupling_intersections.BuildIntersections(/* SearchMethod = BRUTE */);
140  search_coupling_intersections.CalculateGlobalVolume();
141  perf_log.pop("Search intersection");
142 
143  // --- Join the intersection tables, stitch the meshes, build the restrictions!
144  // - Declarations
145  // LOCAL stitched mesh
146  libMesh::Mesh test_mesh_full_I(LocalComm,3);
147 
148  // Object used to stitch the meshes and to join the local intersection tables into a global one
149  carl::Stitch_Meshes join_meshes(test_mesh_full_I,input_params.output_base + "_global");
150  join_meshes.set_grid_constraints(test_mesh_A,test_mesh_B);
151 
152  // Set filenames
153  if(rank == 0)
154  {
155  join_meshes.set_base_filenames(input_params.output_base,".e",nodes);
156 
157  // Join the intersection tables
158  perf_log.push("Join intersection tables");
159  join_meshes.join_tables();
160  perf_log.pop("Join intersection tables");
161 
162  // Stitch the intersection meshes
163  if(input_params.bStitchInterMeshes)
164  {
165  perf_log.push("Stitch intersection meshes");
166  join_meshes.stitch_meshes();
167  perf_log.pop("Stitch intersection meshes");
168  }
169  }
170 
171  // Build and save the mesh restrictions
172 
173  // Get set of elements forming the restricted mesh
174  const std::unordered_set<unsigned int> * restrict_set_A_ptr = join_meshes.get_restricted_set_pointer_first();
175  const std::unordered_set<unsigned int> * restrict_set_B_ptr = join_meshes.get_restricted_set_pointer_second();
176 
177  // Export the meshes and the element equivalence tables
178  perf_log.push("Restrict meshes");
179  carl::Mesh_restriction restrict_A(test_mesh_A,LocalComm);
180  restrict_A.BuildRestrictionFromSet(restrict_set_A_ptr);
181  restrict_A.export_restriction_mesh(input_params.output_base + "_A_restriction");
182 
183  carl::Mesh_restriction restrict_B(test_mesh_B,LocalComm);
184  restrict_B.BuildRestrictionFromSet(restrict_set_B_ptr);
185  restrict_B.export_restriction_mesh(input_params.output_base + "_B_restriction");
186  perf_log.pop("Restrict meshes");
187 
188  return 0;
189 }
bool bStitchInterMeshes
Stitch the intersection meshes?
void get_intersection_input_params(GetPot &field_parser, parallel_intersection_params &input_params)
Parser function for the parallel intersection search program (source: CArl_build_intersections.cpp)
Class used to build a restriction of a parent mesh to the coupling region.
Definition: restrict_mesh.h:31
Class containing the structure needed to find all the intersections between two meshes, inside the coupling region mesh.
carl::IntersectionMeshingMethod inter_meshing_method
Intersection meshing method. Values: carl::IntersectionMeshingMethod::CGAL or carl::IntersectionMeshi...
std::string output_base
Output filename base.
Class used to stitch together different meshes.
Definition: stitch_meshes.h:35
Structure containing the parameters for the parallel intersection search test program (source: CArl_b...
bool bVerbose
Print coupling partitioning?
std::string mesh_C
Coupling mesh path.