13#include <spdlog/spdlog.h>
16#include <unordered_map>
17#define OPTSTRING "s:e:d:f:g:b:o:p:t:B:D:R:h"
18#define BOLD_ON "\033[1m"
19#define BOLD_OFF "\033[0m"
30static inline std::string_view
filename{
"./MolSim"};
35static inline std::unordered_map<char, std::string>
optionNames = {
36 {
's',
"Start time"}, {
'e',
"End time"},
37 {
'd',
"Timestep"}, {
'b',
"Basename"},
38 {
'f',
"Output frequency"}, {
'g',
"Gravity"},
39 {
'o',
"Output type"}, {
'p',
"Parallelization type"},
40 {
't',
"Simulation type"}, {
'B',
"Boundary Conditions"},
41 {
'D',
"Domain Size"}, {
'R',
"Cutoff Radius"}};
50#if defined(__INTEL_LLVM_COMPILER)
52#elif defined(__clang__)
53 return "Clang " + std::to_string(__clang_major__) +
"." + std::to_string(__clang_minor__) +
"." +
54 std::to_string(__clang_patchlevel__);
55#elif defined(__GNUC__) || defined(__GNUG__)
56 return "GNU " + std::to_string(__GNUC__) +
"." + std::to_string(__GNUC_MINOR__) +
"." +
57 std::to_string(__GNUC_PATCHLEVEL__);
58#elif defined(_MSC_VER)
59 return "Microsoft Visual C++ " + std::to_string(_MSC_VER);
70static inline std::string
getBuildDate() {
return std::string(__DATE__) +
" " + __TIME__; }
84 <<
"The PSE Molecular Dynamics simulation program, developed by Group C.\n"
88 "-s <number> : Sets the start time (decimal) for a specific simulation (default: simulation-specific).\n"
89 "-e <number> : Sets the end time (decimal) for a specific simulation (default: simulation-specific).\n"
90 "-d <number> : Sets the time interval between two iterations of a simulation (default: "
91 "simulation-specific).\n"
92 "-g <number> : Sets the gravitational force (decimal) effective on each particle in the simulation "
94 "-b <name> : Sets the base name of the generated files (default: type-specific).\n"
95 "-B <cccccc> : Sets the conditions to be applied at each boundary (North, South, West, East, Above, "
96 "Below). c is one of:\n"
97 " - o : Outflow (particles get deleted once they leave the domain).\n"
98 " - r : Reflective (particles are reflected off the domain boundaries).\n"
99 "-D <x,y,z> : Sets the domain size (decimal array) for the linked cell method (MUST be specified if not "
100 "present in input!).\n"
101 "-R <number> : Sets the cutoff radius (decimal) for the linked cell method (MUST be specified if not "
102 "present in input!).\n"
103 "-f <number> : Sets the output frequency, i.e. after how many iterations a new VTK file should be "
104 "written (default: 10).\n"
105 "-o <type> : Sets the output file type and directory (default: vtk).\n"
106 " - vtk : Generates VTK Unstructured Grid (.vtu) files.\n"
107 " - xyz : Generates XYZ (.xyz) files.\n"
108 " - nil : Logs to stdout. Used for debugging purposes.\n"
109 "-p <type> : Sets the parallelization strategy used (default: coarse).\n"
110 " If OpenMP support is disabled, this option has no effect.\n"
111 " - coarse : Uses the standard OpenMP for-loop parallelization strategy.\n"
112 " - fine : Uses a finer-grained, task-based parallelization approach.\n"
113 "-t <type> : Sets the desired simulation to be performed (default: lj).\n"
114 " - gravity : Performs a gravitational simulation (t_0 = 0, t_end = 1000, dt = 0.014).\n"
115 " - lj : Performs a simulation of Lennard-Jones potential (t_0 = 0, t_end = 5, dt = 0.0002).\n"
116 "-h : Prints out a help message. Doesn't perform any simulation.\n\n"
119 "Logging must be configured at compile time. To change the log level, read the documentation and "
120 "recompile the program accordingly.\n"
121 "When specifying the domain size, do NOT use whitespaces between the commas and numbers.\n\n"
134 return static_cast<int>((y != 0 ?
static_cast<double>(x) / y : 1.0) * 100.0);
149static inline void error(
const char *msg,
const std::string &opt =
"",
bool usage =
true,
bool close =
true) {
150 SPDLOG_ERROR(
"{}{}{}", msg, (opt.empty() ?
"" :
": "), opt);
154 std::exit(EXIT_FAILURE);
#define BOLD_ON
Definition CLIUtils.h:18
#define BOLD_OFF
Definition CLIUtils.h:19
Namespace defining utility functions for handling console output.
Definition CLIUtils.h:26
static void printUsage()
Prints a usage string explaining the syntax of the main program.
Definition CLIUtils.h:75
static std::string_view filename
The filename of the executable (default: "./MolSim").
Definition CLIUtils.h:30
static void error(const char *msg, const std::string &opt="", bool usage=true, bool close=true)
Prints an error message to stderr with the prefix "ERROR: ", optionally prints the usage string and e...
Definition CLIUtils.h:149
static std::string getCompilerName()
Gets the name of the compiler used to build the program executable (or "unknown" if the compiler is n...
Definition CLIUtils.h:49
static std::string getBuildDate()
Gets the build date and time of the built executable as a string.
Definition CLIUtils.h:70
static int getPercentage(int x, int y)
Gets the percentage as an integer from a fraction x / y.
Definition CLIUtils.h:133
static void printHelp()
Prints a help string explaining the functionality of the main program.
Definition CLIUtils.h:82
static std::unordered_map< char, std::string > optionNames
Mapping from getopt option characters to their full names.
Definition CLIUtils.h:35