Skip to content

Commit 83399b1

Browse files
committed
Add optional plotting for f3of demos and tests
1 parent 87e4db2 commit 83399b1

9 files changed

Lines changed: 134 additions & 24 deletions

File tree

demos/f3of/demo_F3OF_DT1.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#include <chrono/physics/ChBodyEasy.h>
77
#include <chrono/physics/ChSystemSMC.h>
88

9+
#include "chrono_postprocess/ChGnuPlot.h"
10+
911
#include <chrono> // std::chrono::high_resolution_clock::now
1012
#include <iomanip> // std::setprecision
1113
#include <vector> // std::vector<double>
@@ -214,6 +216,19 @@ int main(int argc, char* argv[]) {
214216
outputFile.close();
215217
}
216218

217-
std::cout << "Simulation finished." << std::endl;
219+
if (plotOn) {
220+
postprocess::ChGnuPlot gplot(out_dir + "/f3of_dt1.gpl");
221+
gplot.SetGrid();
222+
gplot.SetLabelX("time (s)");
223+
gplot.SetLabelY("surge");
224+
gplot.SetLabelY2("pitch");
225+
gplot.SetRangeX(0, simulationDuration);
226+
gplot.SetTitle("F3OF DT3");
227+
gplot.Plot(time_vector, base_surge, "base surge", " with lines lw 2");
228+
gplot.Plot(time_vector, base_pitch, "base pitch", " axes x1y2 with lines lw 2");
229+
gplot.Plot(time_vector, fore_pitch, "fore pitch", " axes x1y2 with lines lw 2");
230+
gplot.Plot(time_vector, aft_pitch, "aft pitch", " axes x1y2 with lines lw 2");
231+
}
232+
218233
return 0;
219234
}

demos/f3of/demo_F3OF_DT2.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#include <chrono/physics/ChBodyEasy.h>
77
#include <chrono/physics/ChSystemSMC.h>
88

9+
#include "chrono_postprocess/ChGnuPlot.h"
10+
911
#include <chrono> // std::chrono::high_resolution_clock::now
1012
#include <iomanip> // std::setprecision
1113
#include <vector> // std::vector<double>
@@ -220,6 +222,19 @@ int main(int argc, char* argv[]) {
220222
outputFile.close();
221223
}
222224

223-
std::cout << "Simulation finished." << std::endl;
225+
if (plotOn) {
226+
postprocess::ChGnuPlot gplot(out_dir + "/f3of_dt2.gpl");
227+
gplot.SetGrid();
228+
gplot.SetLabelX("time (s)");
229+
gplot.SetLabelY("surge");
230+
gplot.SetLabelY2("pitch");
231+
gplot.SetRangeX(0, simulationDuration);
232+
gplot.SetTitle("F3OF DT3");
233+
gplot.Plot(time_vector, base_surge, "base surge", " with lines lw 2");
234+
gplot.Plot(time_vector, base_pitch, "base pitch", " axes x1y2 with lines lw 2");
235+
gplot.Plot(time_vector, fore_pitch, "fore pitch", " axes x1y2 with lines lw 2");
236+
gplot.Plot(time_vector, aft_pitch, "aft pitch", " axes x1y2 with lines lw 2");
237+
}
238+
224239
return 0;
225-
}
240+
}

demos/f3of/demo_F3OF_DT3.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#include <chrono/physics/ChBodyEasy.h>
77
#include <chrono/physics/ChSystemSMC.h>
88

9+
#include "chrono_postprocess/ChGnuPlot.h"
10+
911
#include <chrono> // std::chrono::high_resolution_clock::now
1012
#include <iomanip> // std::setprecision
1113
#include <vector> // std::vector<double>
@@ -215,6 +217,19 @@ int main(int argc, char* argv[]) {
215217
outputFile.close();
216218
}
217219

218-
std::cout << "Simulation finished." << std::endl;
220+
if (plotOn) {
221+
postprocess::ChGnuPlot gplot(out_dir + "/f3of_dt3.gpl");
222+
gplot.SetGrid();
223+
gplot.SetLabelX("time (s)");
224+
gplot.SetLabelY("surge");
225+
gplot.SetLabelY2("pitch");
226+
gplot.SetRangeX(0, simulationDuration);
227+
gplot.SetTitle("F3OF DT3");
228+
gplot.Plot(time_vector, base_surge, "base surge", " with lines lw 2");
229+
gplot.Plot(time_vector, base_pitch, "base pitch", " axes x1y2 with lines lw 2");
230+
gplot.Plot(time_vector, fore_pitch, "fore pitch", " axes x1y2 with lines lw 2");
231+
gplot.Plot(time_vector, aft_pitch, "aft pitch", " axes x1y2 with lines lw 2");
232+
}
233+
219234
return 0;
220-
}
235+
}

demos/oswec/demo_oswec_reg_waves.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#include <chrono/physics/ChBodyEasy.h>
77
#include <chrono/physics/ChSystemNSC.h>
88

9+
#include "chrono_postprocess/ChGnuPlot.h"
10+
911
#include <chrono> // std::chrono::high_resolution_clock::now
1012
#include <iomanip> // std::setprecision
1113
#include <vector> // std::vector<double>
@@ -269,6 +271,16 @@ int main(int argc, char* argv[]) {
269271
<< std::endl;
270272
outputFile.close();
271273
}
274+
275+
if (plotOn) {
276+
postprocess::ChGnuPlot gplot(out_dir + "/owsec_reg_waves_" + std::to_string(reg_wave_num) + ".gpl");
277+
gplot.SetGrid();
278+
gplot.SetLabelX("time (s)");
279+
gplot.SetLabelY("pitch (rad)");
280+
gplot.SetTitle("OSWEC reg waves " + std::to_string(reg_wave_num));
281+
gplot.Plot(time_vector, flap_rot, "", " with lines lt rgb '#FF5500' lw 2");
282+
}
272283
}
284+
273285
return 0;
274-
}
286+
}

tests/regression/f3of/test_f3of_dt1.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#include <chrono/physics/ChBodyEasy.h>
66
#include <chrono/physics/ChSystemSMC.h>
77

8+
#include "chrono_postprocess/ChGnuPlot.h"
9+
810
#include <chrono> // std::chrono::high_resolution_clock::now
911
#include <iomanip> // std::setprecision
1012
#include <vector> // std::vector<double>
@@ -212,6 +214,19 @@ int main(int argc, char* argv[]) {
212214
}
213215
}
214216

215-
std::cout << "Simulation completed in " << duration << " milliseconds." << std::endl;
217+
if (plotOn) {
218+
postprocess::ChGnuPlot gplot(out_dir + "/f3of_dt1.gpl");
219+
gplot.SetGrid();
220+
gplot.SetLabelX("time (s)");
221+
gplot.SetLabelY("surge");
222+
gplot.SetLabelY2("pitch");
223+
gplot.SetRangeX(0, simulationDuration);
224+
gplot.SetTitle("F3OF DT3");
225+
gplot.Plot(time_vector, base_surge, "base surge", " with lines lw 2");
226+
gplot.Plot(time_vector, base_pitch, "base pitch", " axes x1y2 with lines lw 2");
227+
gplot.Plot(time_vector, fore_pitch, "fore pitch", " axes x1y2 with lines lw 2");
228+
gplot.Plot(time_vector, aft_pitch, "aft pitch", " axes x1y2 with lines lw 2");
229+
}
230+
216231
return 0;
217-
}
232+
}

tests/regression/f3of/test_f3of_dt2.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#include <chrono/physics/ChBodyEasy.h>
66
#include <chrono/physics/ChSystemSMC.h>
77

8+
#include "chrono_postprocess/ChGnuPlot.h"
9+
810
#include <chrono> // std::chrono::high_resolution_clock::now
911
#include <iomanip> // std::setprecision
1012
#include <vector> // std::vector<double>
@@ -224,6 +226,19 @@ int main(int argc, char* argv[]) {
224226
}
225227
}
226228

227-
std::cout << "Simulation completed in " << duration << " milliseconds." << std::endl;
229+
if (plotOn) {
230+
postprocess::ChGnuPlot gplot(out_dir + "/f3of_dt2.gpl");
231+
gplot.SetGrid();
232+
gplot.SetLabelX("time (s)");
233+
gplot.SetLabelY("surge");
234+
gplot.SetLabelY2("pitch");
235+
gplot.SetRangeX(0, simulationDuration);
236+
gplot.SetTitle("F3OF DT3");
237+
gplot.Plot(time_vector, base_surge, "base surge", " with lines lw 2");
238+
gplot.Plot(time_vector, base_pitch, "base pitch", " axes x1y2 with lines lw 2");
239+
gplot.Plot(time_vector, fore_pitch, "fore pitch", " axes x1y2 with lines lw 2");
240+
gplot.Plot(time_vector, aft_pitch, "aft pitch", " axes x1y2 with lines lw 2");
241+
}
242+
228243
return 0;
229-
}
244+
}

tests/regression/f3of/test_f3of_dt3.cpp

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#include <chrono/physics/ChBodyEasy.h>
77
#include <chrono/physics/ChSystemSMC.h>
88

9+
#include "chrono_postprocess/ChGnuPlot.h"
10+
911
#include <chrono> // std::chrono::high_resolution_clock::now
1012
#include <iomanip> // std::setprecision
1113
#include <vector> // std::vector<double>
@@ -222,12 +224,29 @@ int main(int argc, char* argv[]) {
222224
<< std::right << std::setw(16) << std::setprecision(4) << std::fixed << aft_pitch[i]
223225
<< std::endl;
224226
outputFile.close();
227+
228+
229+
230+
225231
} else {
226232
std::cout << "Error: Could not open output file for writing." << std::endl;
227233
return 1; // Return an error code
228234
}
229235
}
230236

231-
std::cout << "Simulation finished." << std::endl;
237+
if (plotOn) {
238+
postprocess::ChGnuPlot gplot(out_dir + "/f3of_dt3.gpl");
239+
gplot.SetGrid();
240+
gplot.SetLabelX("time (s)");
241+
gplot.SetLabelY("surge");
242+
gplot.SetLabelY2("pitch");
243+
gplot.SetRangeX(0, simulationDuration);
244+
gplot.SetTitle("F3OF DT3");
245+
gplot.Plot(time_vector, base_surge, "base surge", " with lines lw 2");
246+
gplot.Plot(time_vector, base_pitch, "base pitch", " axes x1y2 with lines lw 2");
247+
gplot.Plot(time_vector, fore_pitch, "fore pitch", " axes x1y2 with lines lw 2");
248+
gplot.Plot(time_vector, aft_pitch, "aft pitch", " axes x1y2 with lines lw 2");
249+
}
250+
232251
return 0;
233-
}
252+
}

tests/regression/oswec/test_oswec_reg_waves.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#include <chrono/physics/ChBodyEasy.h>
77
#include <chrono/physics/ChSystemNSC.h>
88

9+
#include "chrono_postprocess/ChGnuPlot.h"
10+
911
#include <chrono> // std::chrono::high_resolution_clock::now
1012
#include <iomanip> // std::setprecision
1113
#include <vector> // std::vector<double>
@@ -65,7 +67,7 @@ int main(int argc, char* argv[]) {
6567
int reg_wave_num_max = periods.size();
6668

6769
for (int reg_wave_num = 1; reg_wave_num <= reg_wave_num_max; ++reg_wave_num) {
68-
std::cout << "Chrono version: " << CHRONO_VERSION << "\n\n";
70+
std::cout << "Wave number: " << reg_wave_num << " of " << reg_wave_num_max << std::endl;
6971

7072
// Parse CLI arguments and initialize environment
7173
bool profilingOn = true;
@@ -124,7 +126,7 @@ int main(int argc, char* argv[]) {
124126
// << std::endl;
125127

126128
// set up body from a mesh
127-
std::cout << "Attempting to open mesh file: " << body1_meshfname << std::endl;
129+
std::cout << " Attempting to open mesh file: " << body1_meshfname << std::endl;
128130
std::shared_ptr<ChBody> flap_body = chrono_types::make_shared<ChBodyEasyMesh>( //
129131
body1_meshfname,
130132
1000, // density
@@ -150,7 +152,7 @@ int main(int argc, char* argv[]) {
150152
// notes: mass and inertia added to added mass and system mass correctly.
151153

152154
// set up body from a mesh
153-
std::cout << "Attempting to open mesh file: " << body2_meshfname << std::endl;
155+
std::cout << " Attempting to open mesh file: " << body2_meshfname << std::endl;
154156
std::shared_ptr<ChBody> base_body = chrono_types::make_shared<ChBodyEasyMesh>( //
155157
body2_meshfname,
156158
1000, // density
@@ -271,6 +273,17 @@ int main(int argc, char* argv[]) {
271273
return 1; // Return an error code
272274
}
273275
}
276+
277+
if (plotOn) {
278+
postprocess::ChGnuPlot gplot(out_dir + "/owsec_reg_waves_" + std::to_string(reg_wave_num) + ".gpl");
279+
gplot.SetCanvasSize(1000, 600);
280+
gplot.SetGrid();
281+
gplot.SetLabelX("time (s)");
282+
gplot.SetLabelY("pitch (rad)");
283+
gplot.SetRangeX(0, simulationDuration);
284+
gplot.SetTitle("OSWEC reg waves " + std::to_string(reg_wave_num));
285+
gplot.Plot(time_vector, flap_rot, "", " with lines lt rgb '#FF5500' lw 2");
286+
}
274287
}
275288

276289
return 0;

tests/regression/rm3/test_rm3_reg_waves.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -162,24 +162,15 @@ int main(int argc, char* argv[]) {
162162
// for profiling
163163
auto start = std::chrono::high_resolution_clock::now();
164164

165-
std::cout << "Entering simulation loop..." << std::endl;
166165
// main simulation loop (headless, no GUI)
167-
int step = 0;
168166
while (system.GetChTime() <= simulationDuration) {
169-
if (step % 100 == 0) {
170-
std::cout << "Step " << step << ", t = " << system.GetChTime() << std::endl;
171-
}
172-
173167
system.DoStepDynamics(timestep);
174-
++step;
175-
176168
// append data to output vector
177169
time_vector.push_back(system.GetChTime());
178170
float_heave_position.push_back(float_body1->GetPos().z());
179171
float_drift_position.push_back(float_body1->GetPos().x());
180172
plate_heave_position.push_back(plate_body2->GetPos().z());
181173
}
182-
std::cout << "Exited simulation loop at t = " << system.GetChTime() << std::endl;
183174

184175
// for profiling
185176
auto end = std::chrono::high_resolution_clock::now();

0 commit comments

Comments
 (0)