libMesh
Functions
splitter.C File Reference

Go to the source code of this file.

Functions

std::string remove_extension (const std::string &filename)
 
int main (int argc, char **argv)
 

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 41 of file splitter.C.

References libMesh::MeshBase::add_ghosting_functor(), libMesh::command_line_value(), libMesh::command_line_vector(), libMesh::TriangleWrapper::init(), mesh, libMesh::on_command_line(), libMesh::out, libMesh::MeshBase::read(), remove_extension(), libMesh::DefaultCoupling::set_n_levels(), and libMesh::split_mesh().

42 {
43  LibMeshInit init (argc, argv);
44 
45  if (libMesh::on_command_line("--help") || argc < 3)
46  {
47  libMesh::out << "Example: " << argv[0] << " --mesh=filename.e --n-procs='4 8 16' "
48  "[--num-ghost-layers <n>] [--dry-run] [--ascii]\n\n"
49  << "--mesh Full name of the mesh file to read in. \n"
50  << "--n-procs Vector of number of processors.\n"
51  << "--num-ghost-layers Number of layers to ghost when partitioning (Default: 1).\n"
52  << "--dry-run Only test the partitioning, don't write any files.\n"
53  << "--ascii Write ASCII cpa files rather than binary cpr files.\n"
54  << "--gz Compress written files in gzip format.\n"
55  << std::endl;
56 
57  return 0;
58  }
59 
60  std::string filename = libMesh::command_line_value("--mesh", std::string());
61 
62  std::vector<processor_id_type> all_n_procs;
63  libMesh::command_line_vector("--n-procs", all_n_procs);
64 
65  unsigned int num_ghost_layers = libMesh::command_line_value("--num-ghost-layers", 1);
66 
67  ReplicatedMesh mesh(init.comm());
68 
69  // If the user has requested additional ghosted layers, we need to add a ghosting functor.
70  DefaultCoupling default_coupling;
71  if (num_ghost_layers > 1)
72  {
73  default_coupling.set_n_levels(num_ghost_layers);
74  mesh.add_ghosting_functor(default_coupling);
75  }
76 
77  libMesh::out << "Reading " << filename << std::endl;
78 
79  mesh.read(filename);
80 
81  for (const auto & n_procs : all_n_procs)
82  {
83  libMesh::out << "splitting " << n_procs << " ways..." << std::endl;
84 
85  auto cpr = split_mesh(mesh, n_procs);
86 
87  if (!libMesh::on_command_line("--dry-run"))
88  {
89  libMesh::out << " * writing " << cpr->current_processor_ids().size() << " files per process..." << std::endl;
90 
91  const bool binary = !libMesh::on_command_line("--ascii");
92 
93  const bool gzip = libMesh::on_command_line("--gz");
94 
95  cpr->binary() = binary;
96  std::ostringstream outputname;
97  outputname << remove_extension(filename) << (binary ? ".cpr" : ".cpa") << (gzip ? ".gz" : "");
98  cpr->write(outputname.str());
99  }
100  }
101 
102  return 0;
103 }
virtual void read(const std::string &name, void *mesh_data=nullptr, bool skip_renumber_nodes_and_elements=false, bool skip_find_neighbors=false)=0
Interfaces for reading/writing a mesh to/from a file.
The ReplicatedMesh class is derived from the MeshBase class, and is used to store identical copies of...
std::string remove_extension(const std::string &filename)
Definition: splitter.C:31
MeshBase & mesh
The LibMeshInit class, when constructed, initializes the dependent libraries (e.g.
Definition: libmesh.h:90
This class implements the default algebraic coupling in libMesh: elements couple to themselves...
T command_line_value(const std::string &, T)
Definition: libmesh.C:1024
void init(triangulateio &t)
Initializes the fields of t to nullptr/0 as necessary.
std::unique_ptr< CheckpointIO > split_mesh(MeshBase &mesh, processor_id_type nsplits)
split_mesh takes the given initialized/opened mesh and partitions it into nsplits pieces or chunks...
void command_line_vector(const std::string &, std::vector< T > &)
Definition: libmesh.C:1097
OStreamProxy out
void set_n_levels(unsigned int n_levels)
bool on_command_line(std::string arg)
Definition: libmesh.C:987
void add_ghosting_functor(GhostingFunctor &ghosting_functor)
Adds a functor which can specify ghosting requirements for use on distributed meshes.
Definition: mesh_base.h:1267

◆ remove_extension()

std::string remove_extension ( const std::string &  filename)

Definition at line 31 of file splitter.C.

Referenced by main().

32 {
33  size_t lastdot = filename.find_last_of(".");
34 
35  if (lastdot == std::string::npos)
36  return filename;
37 
38  return filename.substr(0, lastdot);
39 }