PeriDEM 0.2.0
PeriDEM -- Peridynamics-based high-fidelity model for granular media
Loading...
Searching...
No Matches
main.cpp
Go to the documentation of this file.
1/*
2 * -------------------------------------------
3 * Copyright (c) 2021 - 2024 Prashant K. Jha
4 * -------------------------------------------
5 * PeriDEM https://github.com/prashjha/PeriDEM
6 *
7 * Distributed under the Boost Software License, Version 1.0. (See accompanying
8 * file LICENSE)
9 */
10
11#include <PeriDEMConfig.h>
12
13// std includes
14#include <iostream>
15#include <algorithm>
16#include <ctime>
17
18// PeriDEM includes
19#include "inp/input.h" // Input class
20#include "model/dem/demModel.h" // Model class
21#include "util/io.h" // InputParser class
22#include "util/parallelUtil.h" // MPI-related functions
23#include "util/methods.h"
24#include <fmt/format.h>
25
26int main(int argc, char *argv[]) {
27
28 // init parallel
29 util::parallel::initMpi(argc, argv);
30 int mpiSize = util::parallel::mpiSize(), mpiRank = util::parallel::mpiRank();
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
virtual void run(inp::Input *deck)
Main driver to simulate.
Definition demModel.cpp:68
Input command line argument parser.
Definition io.h:355
bool cmdOptionExists(const std::string &option) const
Check if argument exists.
Definition io.h:387
const std::string & getCmdOption(const std::string &option) const
Get value of argument specified by key.
Definition io.h:372
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
int main()