PeriDEM 0.2.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 "inp/input.h"
#include "model/dem/demModel.h"
#include "util/io.h"
#include "util/parallelUtil.h"
#include "util/methods.h"
#include <fmt/format.h>
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 26 of file main.cpp.

26 {
27
28 // init parallel
29 util::parallel::initMpi(argc, argv);
31 util::io::print(fmt::format("Initialized MPI. MPI size = {}, MPI rank = {}\n", mpiSize, mpiRank));
33
34 util::io::InputParser input(argc, argv);
35
36 if (input.cmdOptionExists("-h") or !input.cmdOptionExists("-i")) {
37 // print help
38 std::cout << "Syntax to run PeriDEM: PeriDEM -i <input file> -nThreads <number of threads>" << std::endl;
39 std::cout << "Example: PeriDEM -i input.yaml -nThreads 4" << std::endl;
40 exit(EXIT_FAILURE);
41 }
42
43 unsigned int nThreads;
44 if (input.cmdOptionExists("-nThreads")) nThreads = std::stoi(input.getCmdOption("-nThreads"));
45 else {
46 nThreads = std::thread::hardware_concurrency();
47 util::io::print(fmt::format("Running test with default number of threads = {}\n", nThreads));
48 }
49 // set number of threads
51 util::io::print(fmt::format("Number of threads = {}\n", util::parallel::getNThreads()));
52
53 // print program version
54 std::cout << "PeriDEM"
55 << " (Version " << MAJOR_VERSION << "." << MINOR_VERSION << "."
56 << UPDATE_VERSION << ")" << std::endl;
57
58 // current time
59 auto begin = steady_clock::now();
60
61 // read input data
62 std::string filename = input.getCmdOption("-i");
63 auto *deck = new inp::Input(filename);
64
65 // check which model to run
66 if (deck->isPeriDEM()) {
67 model::DEMModel dem(deck);
68 dem.run(deck);
69 } else {
70 std::cout << "PeriDEM model not found in input file.\n";
71 }
72
73 // get time elapsed
74 auto end = steady_clock::now();
75
76 std::cout << "Total simulation time (s) = "
77 << util::methods::timeDiff(begin, end, "seconds")
78 << std::endl;
79}
size_t const MINOR_VERSION
size_t const UPDATE_VERSION
size_t const MAJOR_VERSION
A class to read input file.
Definition input.h:61
A class for discrete element particle simulation with peridynamic model
Definition demModel.h:32
Input command line argument parser.
Definition io.h:355
std::string printStr(const T &msg, int nt=print_default_tab)
Returns formatted string for output.
Definition io.h:54
void print(const T &msg, int nt=print_default_tab, int printMpiRank=print_default_mpi_rank)
Prints formatted information.
Definition io.h:108
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 methods.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

References util::io::InputParser::cmdOptionExists(), util::io::InputParser::getCmdOption(), util::parallel::getMpiStatus(), util::parallel::getNThreads(), util::parallel::initMpi(), util::parallel::initNThreads(), MAJOR_VERSION, MINOR_VERSION, util::parallel::mpiRank(), util::parallel::mpiSize(), util::io::print(), model::DEMModel::run(), util::methods::timeDiff(), and UPDATE_VERSION.

Here is the call graph for this function: