Skip to content

Commit 7ec81e6

Browse files
committed
Better docstrings and help output for runtime executable
1 parent 8abf29c commit 7ec81e6

File tree

3 files changed

+70
-58
lines changed

3 files changed

+70
-58
lines changed

profile/models/run_time_standard/run_time_standard.cpp

+28-24
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,28 @@ int main(int argc, char* argv[]) {
1313
MPI_Init_thread(&argc, &argv, MPI_THREAD_SERIALIZED, &provided);
1414
log_set_ranks(MPI_COMM_WORLD);
1515
if (provided < MPI_THREAD_SERIALIZED) {
16-
log_printf(ERROR, "Not enough thread support level in the MPI library");
16+
log_printf(ERROR, "Not enough thread support level in the MPI library");
1717
}
1818
#endif
19-
19+
2020
int arg_index = 0;
2121
std::string msg_string;
2222
while (arg_index < argc) {
2323
msg_string += argv[arg_index];
2424
msg_string += " ";
2525
arg_index++;
2626
}
27-
27+
2828
RuntimeParameters runtime;
2929
runtime.setRuntimeParameters(argc, argv);
30-
30+
31+
/* Exit early if only asked to display help message */
32+
if (runtime._print_usage)
33+
return 0;
34+
3135
/* stuck here for debug tools to attach */
3236
while (runtime._debug_flag) ;
33-
37+
3438
/* Define simulation parameters */
3539
#ifdef OPENMP
3640
int num_threads = runtime._num_threads;
@@ -57,25 +61,25 @@ int main(int argc, char* argv[]) {
5761
log_printf(ERROR, "No geometry file is provided");
5862
geometry->loadFromFile(runtime._geo_filename);
5963
#ifdef MPIx
60-
geometry->setDomainDecomposition(runtime._NDx, runtime._NDy, runtime._NDz,
61-
MPI_COMM_WORLD);
64+
geometry->setDomainDecomposition(runtime._NDx, runtime._NDy, runtime._NDz,
65+
MPI_COMM_WORLD);
6266
#endif
6367
geometry->setNumDomainModules(runtime._NMx, runtime._NMy, runtime._NMz);
6468

6569
if ((runtime._NCx >0 && runtime._NCy > 0 && runtime._NCz > 0) ||
6670
(!runtime._cell_widths_x.empty() && !runtime._cell_widths_y.empty() &&
6771
!runtime._cell_widths_z.empty())) {
68-
72+
6973
/* Create CMFD mesh */
7074
log_printf(NORMAL, "Creating CMFD mesh...");
7175
Cmfd* cmfd = new Cmfd();
7276
cmfd->setSORRelaxationFactor(runtime._SOR_factor);
7377
cmfd->setCMFDRelaxationFactor(runtime._CMFD_relaxation_factor);
7478
if(runtime._cell_widths_x.empty() || runtime._cell_widths_y.empty() ||
75-
runtime._cell_widths_z.empty())
79+
runtime._cell_widths_z.empty())
7680
cmfd->setLatticeStructure(runtime._NCx, runtime._NCy, runtime._NCz);
7781
else {
78-
std::vector< std::vector<double> > cmfd_widths{runtime._cell_widths_x,
82+
std::vector< std::vector<double> > cmfd_widths{runtime._cell_widths_x,
7983
runtime._cell_widths_y, runtime._cell_widths_z};
8084
cmfd->setWidths(cmfd_widths);
8185
}
@@ -84,7 +88,7 @@ int main(int argc, char* argv[]) {
8488
cmfd->setKNearest(runtime._knearest);
8589
cmfd->setCentroidUpdateOn(runtime._CMFD_centroid_update_on);
8690
cmfd->useAxialInterpolation(runtime._use_axial_interpolation);
87-
91+
8892
geometry->setCmfd(cmfd);
8993
}
9094

@@ -103,7 +107,7 @@ int main(int argc, char* argv[]) {
103107

104108
quad->setNumAzimAngles(runtime._num_azim);
105109
quad->setNumPolarAngles(runtime._num_polar);
106-
TrackGenerator3D track_generator(geometry, runtime._num_azim,
110+
TrackGenerator3D track_generator(geometry, runtime._num_azim,
107111
runtime._num_polar, runtime._azim_spacing,
108112
runtime._polar_spacing);
109113
track_generator.setNumThreads(num_threads);
@@ -124,7 +128,7 @@ int main(int argc, char* argv[]) {
124128
solver->setVerboseIterationReport();
125129
solver->setNumThreads(num_threads);
126130
solver->setConvergenceThreshold(runtime._tolerance);
127-
solver->computeEigenvalue(runtime._max_iters,
131+
solver->computeEigenvalue(runtime._max_iters,
128132
(residualType)runtime._MOC_src_residual_type);
129133
if(runtime._time_report)
130134
solver->printTimerReport();
@@ -135,23 +139,23 @@ int main(int argc, char* argv[]) {
135139
MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
136140
#endif
137141
std::string rxtype[4] = {"FISSION_RX", "TOTAL_RX", "ABSORPTION_RX", "FLUX_RX"};
138-
142+
139143

140144
for(int m=0; m< runtime._output_mesh_lattices.size(); m++) {
141145
Mesh mesh(solver);
142-
mesh.createLattice(runtime._output_mesh_lattices[m][0],
143-
runtime._output_mesh_lattices[m][1],
146+
mesh.createLattice(runtime._output_mesh_lattices[m][0],
147+
runtime._output_mesh_lattices[m][1],
144148
runtime._output_mesh_lattices[m][2]);
145149
Vector3D rx_rates = mesh.getFormattedReactionRates
146150
((RxType)runtime._output_types[m]);
147-
151+
148152
if (my_rank == 0) {
149-
std::cout << "Output " << m << ", reaction type: "
153+
std::cout << "Output " << m << ", reaction type: "
150154
<< rxtype[runtime._output_types[m]]
151155
<< ", lattice: " << runtime._output_mesh_lattices[m][0] << ","
152156
<< runtime._output_mesh_lattices[m][1] << ","
153157
<< runtime._output_mesh_lattices[m][2] << std::endl;
154-
for (int k=0; k < rx_rates.at(0).at(0).size(); k++) {
158+
for (int k=0; k < rx_rates.at(0).at(0).size(); k++) {
155159
for (int j=rx_rates.at(0).size()-1; j >= 0 ; j--) {
156160
for (int i=0; i < rx_rates.size(); i++) {
157161
std::cout << rx_rates.at(i).at(j).at(k) << " ";
@@ -165,17 +169,17 @@ int main(int argc, char* argv[]) {
165169
for(int m=0; m<runtime._non_uniform_mesh_lattices.size(); m++) {
166170
Mesh mesh(solver);
167171
Vector3D rx_rates = mesh.getNonUniformFormattedReactionRates
168-
(runtime._non_uniform_mesh_lattices[m],
172+
(runtime._non_uniform_mesh_lattices[m],
169173
(RxType)runtime._output_types[m+runtime._output_mesh_lattices.size()]);
170174
if (my_rank == 0) {
171-
std::cout <<"Output " << m+runtime._output_mesh_lattices.size()
172-
<< ", reaction type: "
175+
std::cout <<"Output " << m+runtime._output_mesh_lattices.size()
176+
<< ", reaction type: "
173177
<< rxtype[runtime._output_types[m+runtime._output_mesh_lattices.size()]]
174-
<< ", lattice: "
178+
<< ", lattice: "
175179
<< runtime._non_uniform_mesh_lattices[m][0].size() << ","
176180
<< runtime._non_uniform_mesh_lattices[m][1].size() << ","
177181
<< runtime._non_uniform_mesh_lattices[m][2].size() << std::endl;
178-
for (int k=0; k < rx_rates.at(0).at(0).size(); k++) {
182+
for (int k=0; k < rx_rates.at(0).at(0).size(); k++) {
179183
for (int j=rx_rates.at(0).size()-1; j >= 0 ; j--) {
180184
for (int i=0; i < rx_rates.size(); i++) {
181185
std::cout << rx_rates.at(i).at(j).at(k) << " ";

src/RunTime.cpp

+17-18
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
int RuntimeParameters::setRuntimeParameters(int argc, char *argv[]) {
1212

1313
int arg_index = 0;
14-
int print_usage = 0;
1514

1615
/* Parse the run time commands*/
1716
while (arg_index < argc) {
@@ -121,16 +120,16 @@ int RuntimeParameters::setRuntimeParameters(int argc, char *argv[]) {
121120
else if(strcmp(argv[arg_index], "-CMFD_centroid_update_on") == 0) {
122121
arg_index++;
123122
_CMFD_centroid_update_on = atoi(argv[arg_index++]);
124-
}
123+
}
125124
else if(strcmp(argv[arg_index], "-use_axial_interpolation") == 0) {
126125
arg_index++;
127126
_use_axial_interpolation = atoi(argv[arg_index++]);
128-
}
127+
}
129128
else if(strcmp(argv[arg_index], "-help") == 0 ||
130129
strcmp(argv[arg_index], "--help") == 0 ||
131130
strcmp(argv[arg_index], "-h") == 0 ||
132131
strcmp(argv[arg_index], "--h") == 0) {
133-
print_usage = 1;
132+
_print_usage = 1;
134133
break;
135134
}
136135
else if(strcmp(argv[arg_index], "-log_filename") == 0) {
@@ -153,7 +152,7 @@ int RuntimeParameters::setRuntimeParameters(int argc, char *argv[]) {
153152
for(int i=0; i< atoi(qr); i++)
154153
_cell_widths_x.push_back(atof(ql));
155154
}
156-
else
155+
else
157156
_cell_widths_x.push_back(atof(p));
158157
buf = NULL;
159158
}
@@ -171,11 +170,11 @@ int RuntimeParameters::setRuntimeParameters(int argc, char *argv[]) {
171170
for(int i=0; i< atoi(qr); i++)
172171
_cell_widths_y.push_back(atof(ql));
173172
}
174-
else
173+
else
175174
_cell_widths_y.push_back(atof(p));
176175
buf = NULL;
177176
}
178-
arg_index++;
177+
arg_index++;
179178
}
180179
else if(strcmp(argv[arg_index], "-widths_z") == 0) {
181180
arg_index++;
@@ -189,7 +188,7 @@ int RuntimeParameters::setRuntimeParameters(int argc, char *argv[]) {
189188
for(int i=0; i< atoi(qr); i++)
190189
_cell_widths_z.push_back(atof(ql));
191190
}
192-
else
191+
else
193192
_cell_widths_z.push_back(atof(p));
194193
buf = NULL;
195194
}
@@ -211,7 +210,7 @@ int RuntimeParameters::setRuntimeParameters(int argc, char *argv[]) {
211210
for(int i=0; i< atoi(qr); i++)
212211
_seg_zones.push_back(atof(ql));
213212
}
214-
else
213+
else
215214
_seg_zones.push_back(atof(p));
216215
buf = NULL;
217216
}
@@ -249,16 +248,16 @@ int RuntimeParameters::setRuntimeParameters(int argc, char *argv[]) {
249248
for(int i=atoi(ql); i<= atoi(qr); i++)
250249
tmp.push_back(i);
251250
}
252-
else
251+
else
253252
tmp.push_back(atoi(p));
254253
buf = NULL;
255254
}
256-
255+
257256
_CMFD_group_structure.push_back(tmp);
258257
buf = NULL;
259258
}
260259
arg_index++;
261-
}
260+
}
262261
else if(strcmp(argv[arg_index], "-verbose_report") == 0) {
263262
arg_index++;
264263
_verbose_report = atoi(argv[arg_index++]);
@@ -274,7 +273,7 @@ int RuntimeParameters::setRuntimeParameters(int argc, char *argv[]) {
274273
else if(strcmp(argv[arg_index], "-quadraturetype") == 0) {
275274
arg_index++;
276275
_quadraturetype = atoi(argv[arg_index++]);
277-
}
276+
}
278277
else if(strcmp(argv[arg_index], "-non_uniform_output") == 0) {
279278
arg_index++;
280279
char *buf = argv[arg_index];
@@ -292,7 +291,7 @@ int RuntimeParameters::setRuntimeParameters(int argc, char *argv[]) {
292291
for(int i=0; i< atoi(qr); i++)
293292
tmp.push_back(atof(ql));
294293
}
295-
else
294+
else
296295
tmp.push_back(atof(p));
297296
buf = NULL;
298297
}
@@ -301,7 +300,7 @@ int RuntimeParameters::setRuntimeParameters(int argc, char *argv[]) {
301300
}
302301
_non_uniform_mesh_lattices.push_back(widths_offset);
303302
arg_index++;
304-
}
303+
}
305304
else {
306305
arg_index++;
307306
}
@@ -310,7 +309,7 @@ int RuntimeParameters::setRuntimeParameters(int argc, char *argv[]) {
310309
#ifdef MPIx
311310
MPI_Comm_rank(MPI_COMM_WORLD, &myid);
312311
#endif
313-
if ((print_usage) && (myid == 0)) {
312+
if ((_print_usage) && (myid == 0)) {
314313
printf("Usage: %s [<options>], default value in (). Example commands as "
315314
"below\n", argv[0]);
316315
printf("\n");
@@ -439,10 +438,10 @@ int RuntimeParameters::setRuntimeParameters(int argc, char *argv[]) {
439438
printf("\n");
440439
}
441440

442-
if (print_usage) {
441+
if (_print_usage) {
443442
#ifdef MPIx
444443
MPI_Finalize();
445444
#endif
446-
return 0;
447445
}
446+
return 0;
448447
}

src/RunTime.h

+25-16
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ typedef std::vector<std::vector<std::vector<double> > > DoubleVector3D;
3737
* @brief Structure for run time options.
3838
*/
3939
struct RuntimeParameters {
40-
RuntimeParameters() : _debug_flag(false), _NDx(1), _NDy(1), _NDz(1),
41-
_NMx(1), _NMy(1), _NMz(1), _NCx(0), _NCy(0), _NCz(0),
40+
RuntimeParameters() : _print_usage(false), _debug_flag(false), _NDx(1),
41+
_NDy(1), _NDz(1), _NMx(1), _NMy(1), _NMz(1), _NCx(0), _NCy(0), _NCz(0),
4242
_num_threads(1), _azim_spacing(0.05), _num_azim(64), _polar_spacing(0.75),
4343
_num_polar(10), _tolerance(1.0E-4), _max_iters(1000), _knearest(1),
4444
_CMFD_flux_update_on(true), _CMFD_centroid_update_on(false),
@@ -47,8 +47,13 @@ struct RuntimeParameters {
4747
_segmentation_type(3), _verbose_report(true), _time_report(true),
4848
_log_level((char*)"NORMAL"), _quadraturetype(2), _test_run(false) {}
4949

50-
/* To debug or not when running, dead while loop */
50+
/* Only display help message */
51+
bool _print_usage;
52+
53+
/* To debug or not when running, infinite while loop */
5154
bool _debug_flag;
55+
56+
/* Level of verbosity for the execution */
5257
char* _log_level;
5358

5459
/* Domain decomposition structure */
@@ -72,10 +77,10 @@ struct RuntimeParameters {
7277
double _polar_spacing;
7378
int _num_polar;
7479

75-
/* Segmentation zones for 2D extruded segmentation*/
80+
/* Segmentation zones for 2D extruded segmentation */
7681
std::vector<double> _seg_zones;
7782

78-
/* Segmentation type of track generation*/
83+
/* Segmentation type of track generation */
7984
int _segmentation_type;
8085

8186
/* Polar quadrature type */
@@ -92,51 +97,55 @@ struct RuntimeParameters {
9297
std::vector<double> _cell_widths_y;
9398
std::vector<double> _cell_widths_z;
9499

95-
/* CMFD flux update on or not */
100+
/* Whether to update MOC fluxes with the CMFD transport acceleration */
96101
bool _CMFD_flux_update_on;
97102

98-
/* The order of k-nearest update */
103+
/* The order of the k-nearest update */
99104
int _knearest;
100105

101106
/* K-nearest update or conventional update */
102107
bool _CMFD_centroid_update_on;
103108

104-
/* Whether to use axial interpolation for CMFD update */
105-
int _use_axial_interpolation;
109+
/* Whether to use axial interpolation for the CMFD update */
110+
int _use_axial_interpolation;
106111

107112
/* CMFD linear solver SOR factor */
108113
double _SOR_factor;
109114

110115
/* CMFD relaxation factor */
111116
double _CMFD_relaxation_factor;
112117

113-
/* Linear source solver if true*/
118+
/* Linear source solver if true */
114119
bool _linear_solver;
115120

116121
/* The maximum number of MOC source iterations */
117122
int _max_iters;
118123

119-
/* Type of MOC source residual for convergence check */
124+
/* Type of MOC source residual for assessing convergence */
120125
int _MOC_src_residual_type;
121126

122-
/* MOC source convergence tolerance */
127+
/* MOC source residual convergence criterion */
123128
double _tolerance;
124129

125-
/* uniform lattice output */
130+
/* Mesh dimension for reaction rate output on a uniform lattice */
126131
std::vector<std::vector<int> > _output_mesh_lattices;
127132

128133
/* widths and offsets of multiple output meshes with non-uniform lattice */
129134
DoubleVector3D _non_uniform_mesh_lattices;
130135

131-
/* output reaction types for both uniform and non-uniform */
136+
/* Reaction types for mesh outputs, both uniform and non-uniform */
132137
std::vector<int> _output_types;
138+
139+
/* Print a verbose report at every transport iteration */
133140
bool _verbose_report;
141+
142+
/* Print a solver execution time report */
134143
bool _time_report;
135144

136-
/* whether to run the code for test */
145+
/* Whether to run the code for a test */
137146
bool _test_run;
138147

139-
/* Setter, can be used from command line */
148+
/* Setter, parses command line input */
140149
int setRuntimeParameters(int argc, char *argv[]);
141150
};
142151

0 commit comments

Comments
 (0)