PeriDEM 0.3.0
PeriDEM -- Peridynamics-based high-fidelity model for granular media
Loading...
Searching...
No Matches
main.cpp File Reference
#include <PeriDEMConfig.h>
#include <iostream>
#include <algorithm>
#include <ctime>
#include <filesystem>
#include "inp/input.h"
#include "periDEMModel.h"
#include "util/io.h"
#include "util/json.h"
#include "util/parallelUtil.h"
#include "util/vecMethods.h"
#include <format>
Include dependency graph for main.cpp:

Go to the source code of this file.

Functions

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

Function Documentation

◆ main()

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

Definition at line 28 of file main.cpp.

28 {
29
30 // init parallel
31 util::parallel::initMpi(argc, argv);
33 util::io::print(std::format("Initialized MPI. MPI size = {}, MPI rank = {}\n", mpiSize, mpiRank));
35
36 util::io::InputParser input(argc, argv);
37
38 if (input.cmdOptionExists("-h") or !input.cmdOptionExists("-i")) {
39 // print help
40 std::cout << "Syntax to run PeriDEM: PeriDEM -i <input file> -nThreads <number of threads>" << std::endl;
41 std::cout << "Example: PeriDEM -i input.json -nThreads 4" << std::endl;
42 exit(EXIT_FAILURE);
43 }
44
45 unsigned int nThreads;
46 if (input.cmdOptionExists("-nThreads")) nThreads = std::stoi(input.getCmdOption("-nThreads"));
47 else {
48 nThreads = std::thread::hardware_concurrency();
49 util::io::print(std::format("Running test with default number of threads = {}\n", nThreads));
50 }
51 // set number of threads
53 util::io::print(std::format("Number of threads = {}\n", util::parallel::getNThreads()));
54
55 // print program version
56 std::cout << "PeriDEM"
57 << " (Version " << MAJOR_VERSION << "." << MINOR_VERSION << "."
58 << UPDATE_VERSION << ")" << std::endl;
59
60 // current time
61 auto begin = steady_clock::now();
62
63 // read input data
64 std::string filename = input.getCmdOption("-i");
65 if (!std::filesystem::exists(filename)) {
66 throw std::runtime_error(std::format("Input file {} does not exist.", filename));
67 }
68 std::ifstream f(filename);
69 auto j = json::parse(f);
70 auto deck = std::make_shared<inp::Input>(j);
71
72 // run model
73 if (deck->isPeriDEM()) {
74 PeriDEMModel dem(deck);
75 dem.run(deck);
76 } else {
77 std::cout << "PeriDEM model not found in input file.\n";
78 }
79
80 // get time elapsed
81 auto end = steady_clock::now();
82
83 std::cout << "Total simulation time (s) = "
84 << util::methods::timeDiff(begin, end, "seconds")
85 << std::endl;
86
88 return 0;
89}
Input command line argument parser.
Definition inputParser.h:28
std::string printStr(const T &msg, int nt=print_default_tab)
Returns formatted string for output.
Definition io.h:53
void print(const T &msg, int nt=print_default_tab, int printMpiRank=print_default_mpi_rank)
Prints formatted information.
Definition io.h:128
float timeDiff(std::chrono::steady_clock::time_point begin, std::chrono::steady_clock::time_point end, std::string unit="microseconds")
Returns difference between two times.
Definition vecMethods.h:304
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
void finalizeMpi()
Call MPI_Finalize if this process initialized MPI.

References util::io::InputParser::cmdOptionExists(), util::parallel::finalizeMpi(), util::io::InputParser::getCmdOption(), util::parallel::getMpiStatus(), util::parallel::getNThreads(), util::parallel::initMpi(), util::parallel::initNThreads(), util::parallel::mpiRank(), util::parallel::mpiSize(), util::io::print(), PeriDEMModel::run(), and util::methods::timeDiff().

Here is the call graph for this function: