deltaFlow
ArgumentParser Class Referencefinal

Parses and stores command-line arguments for deltaFlow. More...

#include <Argparse.H>

Public Member Functions

 ArgumentParser (int argc, char *argv[])
 Constructor: parses command-line arguments.
 
 ~ArgumentParser ()=default
 Destructor (default).
 
 ArgumentParser (const ArgumentParser &)=delete
 
ArgumentParseroperator= (const ArgumentParser &)=delete
 
 ArgumentParser (const ArgumentParser &&)=delete
 
ArgumentParseroperator= (ArgumentParser &&)=delete
 
std::string getInputFile () const noexcept
 Get the input CDF file path.
 
std::string getJobName () const noexcept
 Get the job name.
 
double getTolerance () const noexcept
 Get the convergence tolerance ($$ \epsilon $$).
 
int getMaxIterations () const noexcept
 Get the maximum number of iterations ($$ N_{max} $$).
 
double getRelaxationCoefficient () const noexcept
 Get the relaxation coefficient ($$ \omega $$).
 
SolverType getSolverType () const noexcept
 Get the solver type.
 
InputFormat getInputFormat () const noexcept
 Get the input file format.
 

Private Member Functions

void parse_args (int argc, char *argv[])
 Parse the provided arguments.
 
void help () const noexcept
 Print help message to stdout.
 

Private Attributes

std::string inputFile
 Path to input CDF file.
 
std::string jobName
 Job name (defaults to input filename)
 
double tolerance = 1E-8
 Convergence tolerance ($$ \epsilon $$)
 
int maxIterations = 1024
 Maximum number of iterations ($$ N_{max} $$)
 
double relaxation = 1.0
 Relaxation coefficient ($$ \omega $$)
 
SolverType method
 Solver type.
 
InputFormat format
 Input file format.
 

Detailed Description

Parses and stores command-line arguments for deltaFlow.

The ArgumentParser extracts command-line arguments related to the input CDF file, job name, solver selection, convergence tolerance ($$ \epsilon $$), maximum iterations ($$ N_{max} $$), and relaxation coefficient ($$ \omega $$).

Definition at line 62 of file Argparse.H.

Constructor & Destructor Documentation

◆ ArgumentParser() [1/3]

ArgumentParser::ArgumentParser ( int  argc,
char *  argv[] 
)

Constructor: parses command-line arguments.

Parameters
argcArgument count.
argvArgument vector.

Definition at line 36 of file Argparse.C.

36 {
37 parse_args(argc, argv);
38}
void parse_args(int argc, char *argv[])
Parse the provided arguments.
Definition Argparse.C:40

References parse_args().

Here is the call graph for this function:

◆ ~ArgumentParser()

ArgumentParser::~ArgumentParser ( )
default

Destructor (default).

◆ ArgumentParser() [2/3]

ArgumentParser::ArgumentParser ( const ArgumentParser )
delete

◆ ArgumentParser() [3/3]

ArgumentParser::ArgumentParser ( const ArgumentParser &&  )
delete

Member Function Documentation

◆ getInputFile()

std::string ArgumentParser::getInputFile ( ) const
noexcept

Get the input CDF file path.

Returns
File path as std::string.

Definition at line 130 of file Argparse.C.

130 {
131 return this->inputFile;
132}
std::string inputFile
Path to input CDF file.
Definition Argparse.H:125

References inputFile.

Here is the caller graph for this function:

◆ getInputFormat()

InputFormat ArgumentParser::getInputFormat ( ) const
noexcept

Get the input file format.

Returns
InputFormat enum (IEEE or PSSE).

Definition at line 154 of file Argparse.C.

154 {
155 return this->format;
156}
InputFormat format
Input file format.
Definition Argparse.H:131

References format.

Here is the caller graph for this function:

◆ getJobName()

std::string ArgumentParser::getJobName ( ) const
noexcept

Get the job name.

Returns
Job name as std::string.

Definition at line 134 of file Argparse.C.

134 {
135 return this->jobName;
136}
std::string jobName
Job name (defaults to input filename)
Definition Argparse.H:126

References jobName.

Here is the caller graph for this function:

◆ getMaxIterations()

int ArgumentParser::getMaxIterations ( ) const
noexcept

Get the maximum number of iterations ($$ N_{max} $$).

Returns
Maximum iterations as int.

Definition at line 142 of file Argparse.C.

142 {
143 return this->maxIterations;
144}
int maxIterations
Maximum number of iterations ($$ N_{max} $$)
Definition Argparse.H:128

References maxIterations.

Here is the caller graph for this function:

◆ getRelaxationCoefficient()

double ArgumentParser::getRelaxationCoefficient ( ) const
noexcept

Get the relaxation coefficient ($$ \omega $$).

Returns
Relaxation coefficient as double.

Definition at line 146 of file Argparse.C.

146 {
147 return this->relaxation;
148}
double relaxation
Relaxation coefficient ($$ \omega $$)
Definition Argparse.H:129

References relaxation.

Here is the caller graph for this function:

◆ getSolverType()

SolverType ArgumentParser::getSolverType ( ) const
noexcept

Get the solver type.

Returns
Solver enum (GaussSeidel or NewtonRaphson).

Definition at line 150 of file Argparse.C.

150 {
151 return this->method;
152}
SolverType method
Solver type.
Definition Argparse.H:130

References method.

Here is the caller graph for this function:

◆ getTolerance()

double ArgumentParser::getTolerance ( ) const
noexcept

Get the convergence tolerance ($$ \epsilon $$).

Returns
Tolerance as double.

Definition at line 138 of file Argparse.C.

138 {
139 return this->tolerance;
140}
double tolerance
Convergence tolerance ($$ \epsilon $$)
Definition Argparse.H:127

References tolerance.

Here is the caller graph for this function:

◆ help()

void ArgumentParser::help ( ) const
privatenoexcept

Print help message to stdout.

Definition at line 158 of file Argparse.C.

158 {
159 LOG_MESSAGE(R"(
160Usage:
161 deltaFlow [OPTIONS] <input-file> <solver>
162
163Required:
164 <input-file> Path to input file (.cdf, .txt or .raw)
165 <solver> Solver method: GAUSS | NEWTON
166
167Options:
168 -j, --job <name> Job name
169 -t, --tolerance <value> Convergence tolerance (default: 1E-8)
170 -m, --max-iterations <int> Maximum number of iterations (default: 1024)
171 -h, --help Display help message
172 -v, --version Show program version and exit
173
174Solvers:
175 GAUSS Gauss-Seidel Method
176 -r, --relaxation <value> Relaxation coefficient (default: 1.0)
177
178 NEWTON Newton-Raphson Method
179)");
180}
#define LOG_MESSAGE(msg,...)
Macro for printing messages to stdout.
Definition Logger.H:90

References LOG_MESSAGE.

Here is the caller graph for this function:

◆ operator=() [1/2]

ArgumentParser & ArgumentParser::operator= ( ArgumentParser &&  )
delete

◆ operator=() [2/2]

ArgumentParser & ArgumentParser::operator= ( const ArgumentParser )
delete

◆ parse_args()

void ArgumentParser::parse_args ( int  argc,
char *  argv[] 
)
private

Parse the provided arguments.

Parameters
argcArgument count.
argvArgument vector.

Definition at line 40 of file Argparse.C.

40 {
41 bool methodFound = false;
42 bool inputFileFound = false;
43
44 for (int i = 1; i < argc; ++i) {
45 std::string arg = argv[i];
46
47 if ((arg == "--job" || arg == "-j") && i + 1 < argc) {
48 this->jobName = argv[++i];
49 }
50 else if ((arg == "--tolerance" || arg == "-t") && i + 1 < argc) {
51 this->tolerance = std::stod(argv[++i]);
52 }
53 else if ((arg == "--max-iterations" || arg == "-m") && i + 1 < argc) {
54 this->maxIterations = std::stoi(argv[++i]);
55 }
56 else if ((arg == "--relaxation" || arg == "-r") && i + 1 < argc) {
57 this->relaxation = std::stod(argv[++i]);
58 }
59 else if (arg == "--version" || arg == "-v") {
60 std::exit(0);
61 }
62 else if (arg == "--help" || arg == "-h") {
63 help();
64 std::exit(0);
65 }
66 else if (!inputFileFound) {
67 this->inputFile = arg;
68
71 }
72 else if (Utilities::isRawFormat(arg))
73 {
75 }
76 else {
77 LOG_MESSAGE("ERROR: Invalid format '{}'", arg);
78 help();
79 std::exit(1);
80 }
81
82 inputFileFound = true;
83 }
84 else if (!methodFound) {
85 if (arg == "GAUSS") {
87 methodFound = true;
88 }
89 else if (arg == "NEWTON") {
91 methodFound = true;
92 }
93 else {
94 LOG_MESSAGE("ERROR: Invalid method '{}'", arg);
95 help();
96 std::exit(1);
97 }
98 }
99 else {
100 LOG_MESSAGE("ERROR: Unexpected argument '{}'", arg);
101 help();
102 std::exit(1);
103 }
104 }
105
106 if (!inputFileFound) {
107 LOG_MESSAGE("ERROR: Input CDF file (.txt or .cdf) is required.");
108 help();
109 std::exit(1);
110 }
111
112 if (!methodFound) {
113 LOG_MESSAGE("ERROR: Missing required solver argument (GAUSS or NEWTON).");
114 help();
115 std::exit(1);
116 }
117
118 if (jobName.empty()) {
119 jobName = std::filesystem::path(inputFile).stem().string();
120 }
121
123 LOG_MESSAGE("Warning: Relaxation coefficient ignored for method 'NEWTON'");
124 }
125
126 LOG_DEBUG("deltaFlow v{}", deltaFlow_VERSION);
127 LOG_DEBUG("CMake v{}, GCC v{}", CMake_VERSION, gcc_VERSION);
128}
@ IEEE
IEEE Common Data Format (.cdf, .txt)
@ PSSE
PSS/E Raw Data Format (.raw)
@ NewtonRaphson
Newton-Raphson iterative method.
@ GaussSeidel
Gauss-Seidel iterative method.
#define LOG_DEBUG(msg,...)
Macro for logging a debug-level message.
Definition Logger.H:85
void help() const noexcept
Print help message to stdout.
Definition Argparse.C:158
bool isCommonDataFormat(const std::string &filePath)
Check if filepath is IEEE Common Data Format.
Definition Utils.H:43
bool isRawFormat(const std::string &filePath)
Check if filepath is PSS/E Raw format.
Definition Utils.H:53

References format, GaussSeidel, help(), IEEE, inputFile, Utilities::isCommonDataFormat(), Utilities::isRawFormat(), jobName, LOG_DEBUG, LOG_MESSAGE, maxIterations, method, NewtonRaphson, PSSE, relaxation, and tolerance.

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ format

InputFormat ArgumentParser::format
private

Input file format.

Definition at line 131 of file Argparse.H.

◆ inputFile

std::string ArgumentParser::inputFile
private

Path to input CDF file.

Definition at line 125 of file Argparse.H.

◆ jobName

std::string ArgumentParser::jobName
private

Job name (defaults to input filename)

Definition at line 126 of file Argparse.H.

◆ maxIterations

int ArgumentParser::maxIterations = 1024
private

Maximum number of iterations ($$ N_{max} $$)

Definition at line 128 of file Argparse.H.

◆ method

SolverType ArgumentParser::method
private

Solver type.

Definition at line 130 of file Argparse.H.

◆ relaxation

double ArgumentParser::relaxation = 1.0
private

Relaxation coefficient ($$ \omega $$)

Definition at line 129 of file Argparse.H.

◆ tolerance

double ArgumentParser::tolerance = 1E-8
private

Convergence tolerance ($$ \epsilon $$)

Definition at line 127 of file Argparse.H.


The documentation for this class was generated from the following files: