Skip to content

Commit ce463de

Browse files
committed
Use the Chrono CLI library to parse command line arguments for demo and test programs
1 parent 438093f commit ce463de

26 files changed

Lines changed: 327 additions & 376 deletions

demos/DeepCWind/demo_DeepCWind_decay.cpp

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,18 @@
1111
// Use the namespaces of Chrono
1212
using namespace chrono;
1313

14-
// usage: ./sphere_deca.exe [DATADIR] [--nogui]
15-
//
16-
// If no argument is given user can set HYDROCHRONO_DATA_DIR
17-
// environment variable to give the data_directory.
18-
//
1914
int main(int argc, char* argv[]) {
2015
// auto start = std::chrono::high_resolution_clock::now();
2116
std::cout << "Chrono version: " << CHRONO_VERSION << "\n\n";
2217

23-
if (hydroc::SetInitialEnvironment(argc, argv) != 0) {
24-
return 1;
25-
}
26-
27-
// Check if --nogui option is set as 2nd argument
18+
// Parse CLI arguments and initialize environment
19+
bool profilingOn = true;
20+
bool saveDataOn = true;
2821
bool visualizationOn = true;
29-
if (argc > 2 && std::string("--nogui").compare(argv[2]) == 0) {
30-
visualizationOn = false;
31-
}
22+
std::string data_dir;
23+
if (!hydroc::GetCLIArguments(argc, argv, "DeepC wind demo", saveDataOn, profilingOn, visualizationOn, data_dir))
24+
return 1;
25+
if (!hydroc::SetInitialEnvironment(data_dir)) return 1;
3226

3327
std::filesystem::path DATADIR(hydroc::getDataDir());
3428

@@ -50,8 +44,6 @@ int main(int argc, char* argv[]) {
5044
hydroc::gui::UI& ui = *pui.get();
5145

5246
// some io/viz options
53-
bool profilingOn = true;
54-
bool saveDataOn = true;
5547
std::vector<double> time_vector;
5648
std::vector<double> base_pitch;
5749
std::vector<double> base_surge;

demos/f3of/demo_F3OF_DT1.cpp

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,17 @@
1111
// Use the namespaces of Chrono
1212
using namespace chrono;
1313

14-
// usage: ./<demos>.exe [DATADIR] [--nogui]
15-
//
16-
// If no argument is given user can set HYDROCHRONO_DATA_DIR
17-
// environment variable to give the data_directory.
18-
//
1914
int main(int argc, char* argv[]) {
2015
std::cout << "Chrono version: " << CHRONO_VERSION << "\n\n";
2116

22-
if (hydroc::SetInitialEnvironment(argc, argv) != 0) {
23-
return 1;
24-
}
25-
26-
// Check if --nogui option is set as 2nd argument
17+
// Parse CLI arguments and initialize environment
18+
bool profilingOn = true;
19+
bool saveDataOn = true;
2720
bool visualizationOn = true;
28-
if (argc > 2 && std::string("--nogui").compare(argv[2]) == 0) {
29-
visualizationOn = false;
30-
}
21+
std::string data_dir;
22+
if (!hydroc::GetCLIArguments(argc, argv, "F3OF DT1 demo", saveDataOn, profilingOn, visualizationOn, data_dir))
23+
return 1;
24+
if (!hydroc::SetInitialEnvironment(data_dir)) return 1;
3125

3226
// Get model file names
3327
std::filesystem::path DATADIR(hydroc::getDataDir());
@@ -51,8 +45,6 @@ int main(int argc, char* argv[]) {
5145
hydroc::gui::UI& ui = *pui.get();
5246

5347
// some io/viz options
54-
bool profilingOn = true;
55-
bool saveDataOn = true;
5648
std::vector<double> time_vector;
5749
std::vector<double> base_surge;
5850
std::vector<double> base_pitch;

demos/f3of/demo_F3OF_DT2.cpp

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,17 @@
1111
// Use the namespaces of Chrono
1212
using namespace chrono;
1313

14-
// usage: ./<demos>.exe [DATADIR] [--nogui]
15-
//
16-
// If no argument is given user can set HYDROCHRONO_DATA_DIR
17-
// environment variable to give the data_directory.
18-
//
1914
int main(int argc, char* argv[]) {
2015
std::cout << "Chrono version: " << CHRONO_VERSION << "\n\n";
2116

22-
if (hydroc::SetInitialEnvironment(argc, argv) != 0) {
23-
return 1;
24-
}
25-
26-
// Check if --nogui option is set as 2nd argument
17+
// Parse CLI arguments and initialize environment
18+
bool profilingOn = true;
19+
bool saveDataOn = true;
2720
bool visualizationOn = true;
28-
if (argc > 2 && std::string("--nogui").compare(argv[2]) == 0) {
29-
visualizationOn = false;
30-
}
21+
std::string data_dir;
22+
if (!hydroc::GetCLIArguments(argc, argv, "F3OF DT2 demo", saveDataOn, profilingOn, visualizationOn, data_dir))
23+
return 1;
24+
if (!hydroc::SetInitialEnvironment(data_dir)) return 1;
3125

3226
// Get model file names
3327
std::filesystem::path DATADIR(hydroc::getDataDir());
@@ -51,8 +45,6 @@ int main(int argc, char* argv[]) {
5145
hydroc::gui::UI& ui = *pui.get();
5246

5347
// some io/viz options
54-
bool profilingOn = true;
55-
bool saveDataOn = true;
5648
std::vector<double> time_vector;
5749
std::vector<double> base_surge;
5850
std::vector<double> base_pitch;

demos/f3of/demo_F3OF_DT3.cpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,14 @@ using namespace chrono;
2020
int main(int argc, char* argv[]) {
2121
std::cout << "Chrono version: " << CHRONO_VERSION << "\n\n";
2222

23-
if (hydroc::SetInitialEnvironment(argc, argv) != 0) {
24-
return 1;
25-
}
26-
27-
// Check if --nogui option is set as 2nd argument
23+
// Parse CLI arguments and initialize environment
24+
bool profilingOn = true;
25+
bool saveDataOn = true;
2826
bool visualizationOn = true;
29-
if (argc > 2 && std::string("--nogui").compare(argv[2]) == 0) {
30-
visualizationOn = false;
31-
}
27+
std::string data_dir;
28+
if (!hydroc::GetCLIArguments(argc, argv, "F3OF DT3 demo", saveDataOn, profilingOn, visualizationOn, data_dir))
29+
return 1;
30+
if (!hydroc::SetInitialEnvironment(data_dir)) return 1;
3231

3332
// Get model file names
3433
std::filesystem::path DATADIR(hydroc::getDataDir());
@@ -52,8 +51,6 @@ int main(int argc, char* argv[]) {
5251
hydroc::gui::UI& ui = *pui.get();
5352

5453
// some io/viz options
55-
bool profilingOn = true;
56-
bool saveDataOn = true;
5754
std::vector<double> time_vector;
5855
std::vector<double> base_surge;
5956
std::vector<double> base_pitch;

demos/oswec/demo_oswec_decay.cpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,14 @@ std::array<double, 3> add_vectors(std::array<double, 3> v1, std::array<double, 3
6161
int main(int argc, char* argv[]) {
6262
std::cout << "Chrono version: " << CHRONO_VERSION << "\n\n";
6363

64-
if (hydroc::SetInitialEnvironment(argc, argv) != 0) {
65-
return 1;
66-
}
67-
68-
// Check if --nogui option is set as 2nd argument
64+
// Parse CLI arguments and initialize environment
65+
bool profilingOn = true;
66+
bool saveDataOn = true;
6967
bool visualizationOn = true;
70-
if (argc > 2 && std::string("--nogui").compare(argv[2]) == 0) {
71-
visualizationOn = false;
72-
}
68+
std::string data_dir;
69+
if (!hydroc::GetCLIArguments(argc, argv, "OSWEC decay demo", saveDataOn, profilingOn, visualizationOn, data_dir))
70+
return 1;
71+
if (!hydroc::SetInitialEnvironment(data_dir)) return 1;
7372

7473
// Get model file names
7574
std::filesystem::path DATADIR(hydroc::getDataDir());
@@ -95,8 +94,6 @@ int main(int argc, char* argv[]) {
9594
hydroc::gui::UI& ui = *pui.get();
9695

9796
// some io/viz options
98-
bool profilingOn = true;
99-
bool saveDataOn = true;
10097
std::vector<double> time_vector;
10198
std::vector<double> flap_rot;
10299

demos/oswec/demo_oswec_reg_waves.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,15 @@ int main(int argc, char* argv[]) {
6767
for (int reg_wave_num = 1; reg_wave_num <= reg_wave_num_max; ++reg_wave_num) {
6868
std::cout << "Chrono version: " << CHRONO_VERSION << "\n\n";
6969

70-
if (hydroc::SetInitialEnvironment(argc, argv) != 0) {
70+
// Parse CLI arguments and initialize environment
71+
bool visualizationOn = true;
72+
bool profilingOn = true;
73+
bool saveDataOn = true;
74+
std::string data_dir;
75+
if (!hydroc::GetCLIArguments(argc, argv, "OSWEC regular waves demo", saveDataOn, profilingOn, visualizationOn,
76+
data_dir))
7177
return 1;
72-
}
73-
74-
// Check if --nogui option is set as 2nd argument
75-
bool visualizationOn = false;
76-
if (argc > 2 && std::string("--nogui").compare(argv[2]) == 0) {
77-
visualizationOn = false;
78-
}
78+
if (!hydroc::SetInitialEnvironment(data_dir)) return 1;
7979

8080
// Get model file names
8181
std::filesystem::path DATADIR(hydroc::getDataDir());
@@ -100,8 +100,6 @@ int main(int argc, char* argv[]) {
100100
hydroc::gui::UI& ui = *pui.get();
101101

102102
// some io/viz options
103-
bool profilingOn = true;
104-
bool saveDataOn = true;
105103
std::vector<double> time_vector;
106104
std::vector<double> flap_rot;
107105

demos/rm3/demo_rm3_decay.cpp

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,17 @@
1111
// Use the namespaces of Chrono
1212
using namespace chrono;
1313

14-
// usage: ./<demos>.exe [DATADIR] [--nogui]
15-
//
16-
// If no argument is given user can set HYDROCHRONO_DATA_DIR
17-
// environment variable to give the data_directory.
18-
//
1914
int main(int argc, char* argv[]) {
2015
std::cout << "Chrono version: " << CHRONO_VERSION << "\n\n";
2116

22-
if (hydroc::SetInitialEnvironment(argc, argv) != 0) {
23-
return 1;
24-
}
25-
26-
// Check if --nogui option is set as 2nd argument
17+
// Parse CLI arguments and initialize environment
18+
bool profilingOn = true;
19+
bool saveDataOn = true;
2720
bool visualizationOn = true;
28-
if (argc > 2 && std::string("--nogui").compare(argv[2]) == 0) {
29-
visualizationOn = false;
30-
}
21+
std::string data_dir;
22+
if (!hydroc::GetCLIArguments(argc, argv, "RM3 decay demo", saveDataOn, profilingOn, visualizationOn, data_dir))
23+
return 1;
24+
if (!hydroc::SetInitialEnvironment(data_dir)) return 1;
3125

3226
// Get model file names
3327
std::filesystem::path DATADIR(hydroc::getDataDir());
@@ -55,8 +49,6 @@ int main(int argc, char* argv[]) {
5549
hydroc::gui::UI& ui = *pui.get();
5650

5751
// some io/viz options
58-
bool profilingOn = true;
59-
bool saveDataOn = true;
6052
std::vector<double> time_vector;
6153
std::vector<double> float_heave_position;
6254
std::vector<double> plate_heave_position;

demos/rm3/demo_rm3_reg_waves.cpp

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,20 @@
1212
// Use the namespaces of Chrono
1313
using namespace chrono;
1414

15-
// usage: ./<demos>.exe [DATADIR] [--nogui] [--debug]
16-
//
17-
// If no argument is given user can set HYDROCHRONO_DATA_DIR
18-
// environment variable to give the data_directory.
19-
//
2015
int main(int argc, char* argv[]) {
2116
std::cout << "Chrono version: " << CHRONO_VERSION << "\n\n";
2217

2318
// Initialize logging with command line arguments
2419
// Optional: initialize logging if desired based on args
2520

26-
if (hydroc::SetInitialEnvironment(argc, argv) != 0) {
27-
return 1;
28-
}
29-
30-
// Check for --nogui and --debug flags in any order
21+
// Parse CLI arguments and initialize environment
22+
bool profilingOn = true;
23+
bool saveDataOn = true;
3124
bool visualizationOn = true;
32-
for (int i = 1; i < argc; i++) {
33-
if (std::string("--nogui").compare(argv[i]) == 0) {
34-
visualizationOn = false;
35-
break;
36-
}
37-
}
25+
std::string data_dir;
26+
if (!hydroc::GetCLIArguments(argc, argv, "RM3 regular waves demo", saveDataOn, profilingOn, visualizationOn, data_dir))
27+
return 1;
28+
if (!hydroc::SetInitialEnvironment(data_dir)) return 1;
3829

3930
// Get model file names
4031
std::filesystem::path DATADIR(hydroc::getDataDir());
@@ -71,8 +62,6 @@ int main(int argc, char* argv[]) {
7162
hydroc::gui::UI& ui = *pui.get();
7263

7364
// some io/viz options
74-
bool profilingOn = true;
75-
bool saveDataOn = true;
7665
std::vector<double> time_vector;
7766
std::vector<double> float_heave_position;
7867
std::vector<double> float_drift_position;

demos/sphere/demo_sphere_decay.cpp

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,17 @@
1212
// Use the namespaces of Chrono
1313
using namespace chrono;
1414

15-
// usage: ./sphere_deca.exe [DATADIR] [--nogui]
16-
//
17-
// If no argument is given user can set HYDROCHRONO_DATA_DIR
18-
// environment variable to give the data_directory.
19-
//
2015
int main(int argc, char* argv[]) {
2116
std::cout << "Chrono version: " << CHRONO_VERSION << "\n\n";
2217

23-
if (hydroc::SetInitialEnvironment(argc, argv) != 0) {
24-
return 1;
25-
}
26-
27-
// Check if --nogui option is set as 2nd argument
18+
// Parse CLI arguments and initialize environment
19+
bool profilingOn = true;
20+
bool saveDataOn = true;
2821
bool visualizationOn = true;
29-
if (argc > 2 && std::string("--nogui").compare(argv[2]) == 0) {
30-
visualizationOn = false;
31-
}
22+
std::string data_dir;
23+
if (!hydroc::GetCLIArguments(argc, argv, "Sphere decay demo", saveDataOn, profilingOn, visualizationOn, data_dir))
24+
return 1;
25+
if (!hydroc::SetInitialEnvironment(data_dir)) return 1;
3226

3327
// Get model file names
3428
std::filesystem::path DATADIR(hydroc::getDataDir());
@@ -54,9 +48,6 @@ int main(int argc, char* argv[]) {
5448

5549
hydroc::gui::UI& ui = *pui.get();
5650

57-
bool profilingOn = true;
58-
bool saveDataOn = true;
59-
6051
// Output timeseries
6152
std::vector<double> time_vector;
6253
std::vector<double> heave_position;
@@ -99,7 +90,7 @@ int main(int argc, char* argv[]) {
9990
TestHydro hydro_forces(bodies, h5fname);
10091
hydro_forces.AddWaves(default_dont_add_waves);
10192

102-
// for profilingvisualizationOn = false;
93+
// for profiling
10394
auto start = std::chrono::high_resolution_clock::now();
10495

10596
// main simulation loop

demos/sphere/demo_sphere_irreg_waves.cpp

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,17 @@
1313
// Use the namespaces of Chrono
1414
using namespace chrono;
1515

16-
// usage: ./<demos>.exe [DATADIR] [--nogui]
17-
//
18-
// If no argument is given user can set HYDROCHRONO_DATA_DIR
19-
// environment variable to give the data_directory.
20-
//
2116
int main(int argc, char* argv[]) {
2217
std::cout << "Chrono version: " << CHRONO_VERSION << "\n\n";
2318

24-
if (hydroc::SetInitialEnvironment(argc, argv) != 0) {
25-
return 1;
26-
}
27-
28-
// Check if --nogui option is set as 2nd argument
19+
// Parse CLI arguments and initialize environment
20+
bool profilingOn = true;
21+
bool saveDataOn = true;
2922
bool visualizationOn = true;
30-
if (argc > 2 && std::string("--nogui").compare(argv[2]) == 0) {
31-
visualizationOn = false;
32-
}
23+
std::string data_dir;
24+
if (!hydroc::GetCLIArguments(argc, argv, "Sphere irregular waves demo", saveDataOn, profilingOn, visualizationOn, data_dir))
25+
return 1;
26+
if (!hydroc::SetInitialEnvironment(data_dir)) return 1;
3327

3428
std::filesystem::path DATADIR(hydroc::getDataDir());
3529

@@ -60,8 +54,6 @@ int main(int argc, char* argv[]) {
6054
ground->EnableCollision(false);
6155

6256
// some io/viz options
63-
bool profilingOn = true;
64-
bool saveDataOn = true;
6557
std::vector<double> time_vector;
6658
std::vector<double> heave_position;
6759
//

0 commit comments

Comments
 (0)