276 {
277
280 util::io::print(std::format(
"Initialized MPI. MPI size = {}, MPI rank = {}\n", mpiSize, mpiRank));
282
284
285 unsigned int nThreads;
286 if (input.cmdOptionExists("-nThreads"))
287 nThreads = std::stoi(input.getCmdOption("-nThreads"));
288 else {
289 nThreads = std::thread::hardware_concurrency();
290 util::io::print(std::format(
"Running test with default number of threads = {}\n", nThreads));
291 }
294
295 namespace fs = std::filesystem;
296 const fs::path cwd = fs::current_path();
297
298 fs::path run_base = cwd;
299 if (input.cmdOptionExists("-outputDir")) {
300 fs::path p = input.getCmdOption("-outputDir");
301 run_base = p.is_absolute() ? std::move(p) : cwd / p;
302 }
303
304 fs::path inp_base = run_base;
305 if (input.cmdOptionExists("-inputDir")) {
306 fs::path p = input.getCmdOption("-inputDir");
307 inp_base = p.is_absolute() ? std::move(p) : cwd / p;
308 }
309
310 std::vector<std::string> geometriesToRun;
311 if (input.cmdOptionExists("-allGeometries")) {
313 util::io::print(
"twop_general_inbuilt: -allGeometries — running full geometry list.\n");
314 } else if (input.cmdOptionExists("-geometry")) {
315 const std::string g = input.getCmdOption("-geometry");
317 throw std::runtime_error(
318 "twop_general_inbuilt: -geometry \"" + g +
319 "\" is not in geom::acceptable_geometries.");
320 geometriesToRun = {g};
321 util::io::print(std::format(
"twop_general_inbuilt: single geometry = {}.\n", g));
322 } else {
323 geometriesToRun = {"circle"};
324 util::io::print(
"twop_general_inbuilt: default geometry = circle (use -geometry <name> or -allGeometries).\n");
325 }
326
327 for (const std::string &geomName : geometriesToRun) {
328 util::io::print(std::format(
"--- twop_general_inbuilt: geometry = {} ---\n", geomName));
329
330 const fs::path out_dir = run_base / geomName / "out";
331 const fs::path inp_dir = inp_base / geomName / "inp";
332 fs::create_directories(out_dir);
333 fs::create_directories(inp_dir);
334
336
337 const fs::path mesh1 = inp_dir / (std::string("mesh_gen_1_") + geomName + ".msh");
338 const fs::path mesh2 = inp_dir / (std::string("mesh_gen_2_") + geomName + ".msh");
339
340 auto inputJson =
buildInputJson(geomName, output_path_for_deck, mesh1, mesh2);
341
342 const fs::path input_json_path = inp_dir / (std::string("input_") + geomName + ".json");
343 {
344 std::ofstream os(input_json_path);
345 if (!os)
346 throw std::runtime_error("Failed to open " + input_json_path.string() + " for writing.");
347 os << inputJson.dump(2);
348 }
349 util::io::print(std::format(
"Output directory (VTU, log.txt): {}\n", fs::absolute(out_dir).
string()));
350 util::io::print(std::format(
"Input directory (input.json, meshes): {}\n", fs::absolute(inp_dir).
string()));
351 util::io::print(std::format(
"Wrote deck to {}\n", fs::absolute(input_json_path).
string()));
352
353
354
355
356 if (input.cmdOptionExists("-deckOnly"))
357 continue;
358
359 auto deck = std::make_shared<inp::Input>(inputJson);
360
362 dem.run(deck);
363 }
364
365 return EXIT_SUCCESS;
366}
std::string directoryPathWithTrailingSep(const std::filesystem::path &dir)
json buildInputJson(const std::string &geomName, const std::string &output_path_for_deck, const std::filesystem::path &mesh_file_1, const std::filesystem::path &mesh_file_2)
bool isAcceptableGeometryName(const std::string &g)
const std::vector< std::string > & getAcceptableGeometries()
Returns list of acceptable geometries for PeriDEM simulation.
std::string printStr(const T &msg, int nt=print_default_tab)
Returns formatted string for output.
void print(const T &msg, int nt=print_default_tab, int printMpiRank=print_default_mpi_rank)
Prints formatted information.
unsigned int getNThreads()
Get number of threads to be used by taskflow.
void initNThreads(unsigned int nThreads=std::thread::hardware_concurrency())
Initializes MpiStatus struct.
const MpiStatus * getMpiStatus()
Returns pointer to MpiStatus struct.
void initMpi(int argc=0, char *argv[]=nullptr)
Initializes MPI and also creates MpiStatus struct.
int mpiSize()
Get size (number) of processors.
int mpiRank()
get rank (id) of this processor