PeriDEM 0.3.0
PeriDEM -- Peridynamics-based high-fidelity model for granular media
Loading...
Searching...
No Matches
main.cpp File Reference
#include "inp/deckIncludes.h"
#include "material/materialUtil.h"
#include "periDEMModel.h"
#include "util/function.h"
#include "util/io.h"
#include "util/parallelUtil.h"
#include <cmath>
#include <cstdlib>
#include <filesystem>
#include <format>
#include <fstream>
#include <iomanip>
#include <memory>
#include <stdexcept>
#include <string>
#include <thread>
#include <vector>
Include dependency graph for main.cpp:

Go to the source code of this file.

Namespaces

namespace  anonymous_namespace{main.cpp}
 

Functions

std::string anonymous_namespace{main.cpp}::directoryPathWithTrailingSep (const std::filesystem::path &dir)
 
json anonymous_namespace{main.cpp}::buildInputJson (const std::string &output_path, const std::filesystem::path &mesh_tri, const std::filesystem::path &mesh_ell, double final_time, size_t num_steps, double mesh_size, double horizon)
 
int main (int argc, char *argv[])
 

Function Documentation

◆ main()

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

Definition at line 264 of file main.cpp.

264 {
265 util::parallel::initMpi(argc, argv);
266 util::io::InputParser input(argc, argv);
267
268 unsigned int n_threads = std::thread::hardware_concurrency();
269 if (input.cmdOptionExists("-nThreads"))
270 n_threads = std::stoul(input.getCmdOption("-nThreads"));
272 util::io::print(std::format("Number of threads = {}\n", util::parallel::getNThreads()));
273
274 double final_time = 0.0030;
275 size_t num_steps = 30000;
276 if (input.cmdOptionExists("-finalTime"))
277 final_time = std::stod(input.getCmdOption("-finalTime"));
278 if (input.cmdOptionExists("-numSteps"))
279 num_steps = std::stoul(input.getCmdOption("-numSteps"));
280
281 const double mesh_size = 0.00010;
282 const double horizon = 3.0 * mesh_size;
283
284 namespace fs = std::filesystem;
285 const fs::path cwd = fs::current_path();
286 fs::path out_dir = cwd / "out";
287 fs::path inp_dir = cwd / "inp";
288 if (input.cmdOptionExists("-outputDir")) {
289 fs::path p = input.getCmdOption("-outputDir");
290 out_dir = p.is_absolute() ? std::move(p) : cwd / p;
291 }
292 if (input.cmdOptionExists("-inputDir")) {
293 fs::path p = input.getCmdOption("-inputDir");
294 inp_dir = p.is_absolute() ? std::move(p) : cwd / p;
295 } else if (input.cmdOptionExists("-outputDir")) {
296 inp_dir = out_dir.parent_path() / "inp";
297 }
298 fs::create_directories(out_dir);
299 fs::create_directories(inp_dir);
300
301 const std::string output_path = directoryPathWithTrailingSep(out_dir);
302 const fs::path mesh_tri = inp_dir / "mesh_triangle.msh";
303 const fs::path mesh_ell = inp_dir / "mesh_hollow_ellipse.msh";
304
305 auto j = buildInputJson(output_path, mesh_tri, mesh_ell, final_time, num_steps, mesh_size,
306 horizon);
307 {
308 std::ofstream ofs(inp_dir / "input.json");
309 ofs << std::setw(2) << j << std::endl;
310 }
311
312 // -deckOnly stops after the deck is written. The Python comparison reads
313 // the deck and does not need this driver to run the simulation.
314 if (input.cmdOptionExists("-deckOnly")) {
315 util::io::print("deck written; -deckOnly, not running\n");
317 return 0;
318 }
319
320 // Hard check: deck must request a hollow ellipse, not a rectangle plate.
321 if (j["Particle"]["Set_2"]["Type"] != "ellipse_minus_ellipse")
322 throw std::runtime_error("ellipse_triangle: Particle Set_2 must be ellipse_minus_ellipse");
323
324 util::io::print(std::format(
325 "[ellipse_triangle] Type={}, T={}, Nt={}, mesh={:.4e}, out={}\n",
326 j["Particle"]["Set_2"]["Type"].get<std::string>(), final_time, num_steps, mesh_size,
327 out_dir.string()));
328
329 auto deck = std::make_shared<inp::Input>(j);
330 PeriDEMModel dem(deck);
331 dem.run(deck);
332
333 return 0;
334}
Input command line argument parser.
Definition inputParser.h:28
std::string directoryPathWithTrailingSep(const std::filesystem::path &dir)
Definition main.cpp:34
json buildInputJson(const std::string &output_path, const std::filesystem::path &mesh_tri, const std::filesystem::path &mesh_ell, double final_time, size_t num_steps, double mesh_size, double horizon)
Definition main.cpp:43
void print(const T &msg, int nt=print_default_tab, int printMpiRank=print_default_mpi_rank)
Prints formatted information.
Definition io.h:171
unsigned int getNThreads()
Get number of threads to be used by taskflow.
void initNThreads(unsigned int nThreads=std::thread::hardware_concurrency())
Initializes MpiStatus struct.
void initMpi(int argc=0, char *argv[]=nullptr)
Initializes MPI and also creates MpiStatus struct.
void finalizeMpi()
Call MPI_Finalize if this process initialized MPI.

References anonymous_namespace{main.cpp}::buildInputJson(), util::io::InputParser::cmdOptionExists(), anonymous_namespace{main.cpp}::directoryPathWithTrailingSep(), util::parallel::finalizeMpi(), util::io::InputParser::getCmdOption(), util::parallel::getNThreads(), util::parallel::initMpi(), util::parallel::initNThreads(), main(), util::io::print(), and PeriDEMModel::run().

Here is the call graph for this function: