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.
 
PowerFlowOptions getOptions () const noexcept
 Get all parsed options as a plain data struct (ISP).
 

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 64 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 37 of file Argparse.C.

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

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 131 of file Argparse.C.

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

References inputFile.

◆ getInputFormat()

InputFormat ArgumentParser::getInputFormat ( ) const
noexcept

Get the input file format.

Returns
InputFormat enum (IEEE or PSSE).

Definition at line 155 of file Argparse.C.

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

References format.

◆ getJobName()

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

Get the job name.

Returns
Job name as std::string.

Definition at line 135 of file Argparse.C.

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

References jobName.

◆ getMaxIterations()

int ArgumentParser::getMaxIterations ( ) const
noexcept

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

Returns
Maximum iterations as int.

Definition at line 143 of file Argparse.C.

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

References maxIterations.

◆ getOptions()

PowerFlowOptions ArgumentParser::getOptions ( ) const
noexcept

Get all parsed options as a plain data struct (ISP).

Lets consumers that only need the parsed values (e.g. PowerFlowApplication) depend on a small data type instead of the full ArgumentParser interface.

Returns
PowerFlowOptions populated from the parsed arguments.

Definition at line 159 of file Argparse.C.

159 {
160 PowerFlowOptions opts;
161 opts.inputFile = this->inputFile;
162 opts.jobName = this->jobName;
163 opts.tolerance = this->tolerance;
164 opts.maxIterations = this->maxIterations;
165 opts.relaxation = this->relaxation;
166 opts.solverType = this->method;
167 opts.inputFormat = this->format;
168 return opts;
169}
double relaxation
Relaxation coefficient ($$ \omega $$)
Definition Argparse.H:140
double tolerance
Convergence tolerance ($$ \epsilon $$)
Definition Argparse.H:138
SolverType method
Solver type.
Definition Argparse.H:141
Plain data holder for parsed command-line options.
std::string inputFile
Path to input file.
std::string jobName
Job name (defaults to input filename)
int maxIterations
Maximum number of iterations ($$ N_{max} $$)
double tolerance
Convergence tolerance ($$ \epsilon $$)
SolverType solverType
Solver type.
InputFormat inputFormat
Input file format.
double relaxation
Relaxation coefficient ($$ \omega $$)

References format, inputFile, PowerFlowOptions::inputFile, PowerFlowOptions::inputFormat, jobName, PowerFlowOptions::jobName, maxIterations, PowerFlowOptions::maxIterations, method, relaxation, PowerFlowOptions::relaxation, PowerFlowOptions::solverType, tolerance, and PowerFlowOptions::tolerance.

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 147 of file Argparse.C.

147 {
148 return this->relaxation;
149}

References relaxation.

◆ getSolverType()

SolverType ArgumentParser::getSolverType ( ) const
noexcept

Get the solver type.

Returns
Solver enum (GaussSeidel or NewtonRaphson).

Definition at line 151 of file Argparse.C.

151 {
152 return this->method;
153}

References method.

◆ getTolerance()

double ArgumentParser::getTolerance ( ) const
noexcept

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

Returns
Tolerance as double.

Definition at line 139 of file Argparse.C.

139 {
140 return this->tolerance;
141}

References tolerance.

◆ help()

void ArgumentParser::help ( ) const
privatenoexcept

Print help message to stdout.

Definition at line 171 of file Argparse.C.

171 {
172 LOG_MESSAGE(R"(
173Usage:
174 deltaFlow [OPTIONS] <input-file> <solver>
175
176Required:
177 <input-file> Path to input file (.cdf, .txt or .raw)
178 <solver> Solver method: GAUSS | NEWTON
179
180Options:
181 -j, --job <name> Job name
182 -t, --tolerance <value> Convergence tolerance (default: 1E-8)
183 -m, --max-iterations <int> Maximum number of iterations (default: 1024)
184 -h, --help Display help message
185 -v, --version Show program version and exit
186
187Solvers:
188 GAUSS Gauss-Seidel Method
189 -r, --relaxation <value> Relaxation coefficient (default: 1.0)
190
191 NEWTON Newton-Raphson Method
192)");
193}
#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 41 of file Argparse.C.

41 {
42 bool methodFound = false;
43 bool inputFileFound = false;
44
45 for (int i = 1; i < argc; ++i) {
46 std::string arg = argv[i];
47
48 if ((arg == "--job" || arg == "-j") && i + 1 < argc) {
49 this->jobName = argv[++i];
50 }
51 else if ((arg == "--tolerance" || arg == "-t") && i + 1 < argc) {
52 this->tolerance = std::stod(argv[++i]);
53 }
54 else if ((arg == "--max-iterations" || arg == "-m") && i + 1 < argc) {
55 this->maxIterations = std::stoi(argv[++i]);
56 }
57 else if ((arg == "--relaxation" || arg == "-r") && i + 1 < argc) {
58 this->relaxation = std::stod(argv[++i]);
59 }
60 else if (arg == "--version" || arg == "-v") {
61 std::exit(0);
62 }
63 else if (arg == "--help" || arg == "-h") {
64 help();
65 std::exit(0);
66 }
67 else if (!inputFileFound) {
68 this->inputFile = arg;
69
72 }
73 else if (Utilities::isRawFormat(arg))
74 {
76 }
77 else {
78 LOG_MESSAGE("ERROR: Invalid format '{}'", arg);
79 help();
80 std::exit(1);
81 }
82
83 inputFileFound = true;
84 }
85 else if (!methodFound) {
86 if (arg == "GAUSS") {
88 methodFound = true;
89 }
90 else if (arg == "NEWTON") {
92 methodFound = true;
93 }
94 else {
95 LOG_MESSAGE("ERROR: Invalid method '{}'", arg);
96 help();
97 std::exit(1);
98 }
99 }
100 else {
101 LOG_MESSAGE("ERROR: Unexpected argument '{}'", arg);
102 help();
103 std::exit(1);
104 }
105 }
106
107 if (!inputFileFound) {
108 LOG_MESSAGE("ERROR: Input CDF file (.txt or .cdf) is required.");
109 help();
110 std::exit(1);
111 }
112
113 if (!methodFound) {
114 LOG_MESSAGE("ERROR: Missing required solver argument (GAUSS or NEWTON).");
115 help();
116 std::exit(1);
117 }
118
119 if (jobName.empty()) {
120 jobName = std::filesystem::path(inputFile).stem().string();
121 }
122
124 LOG_MESSAGE("Warning: Relaxation coefficient ignored for method 'NEWTON'");
125 }
126
127 LOG_DEBUG("deltaFlow v{}", deltaFlow_VERSION);
128 LOG_DEBUG("CMake v{}, GCC v{}", CMake_VERSION, gcc_VERSION);
129}
@ 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:171
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 142 of file Argparse.H.

◆ inputFile

std::string ArgumentParser::inputFile
private

Path to input CDF file.

Definition at line 136 of file Argparse.H.

◆ jobName

std::string ArgumentParser::jobName
private

Job name (defaults to input filename)

Definition at line 137 of file Argparse.H.

◆ maxIterations

int ArgumentParser::maxIterations = 1024
private

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

Definition at line 139 of file Argparse.H.

◆ method

SolverType ArgumentParser::method
private

Solver type.

Definition at line 141 of file Argparse.H.

◆ relaxation

double ArgumentParser::relaxation = 1.0
private

Relaxation coefficient ($$ \omega $$)

Definition at line 140 of file Argparse.H.

◆ tolerance

double ArgumentParser::tolerance = 1E-8
private

Convergence tolerance ($$ \epsilon $$)

Definition at line 138 of file Argparse.H.


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