66#include < chrono/physics/ChBodyEasy.h>
77#include < chrono/physics/ChSystemNSC.h>
88
9- #include " chrono_postprocess/ChGnuPlot.h"
9+ #include < chrono/utils/ChUtils.h>
10+
11+ #include " ../test_utils.h"
1012
1113#include < chrono> // std::chrono::high_resolution_clock::now
1214#include < iomanip> // std::setprecision
1315#include < vector> // std::vector<double>
1416
1517// Use the namespaces of Chrono
1618using namespace chrono ;
19+ using namespace chrono ::utils;
1720
1821int main (int argc, char * argv[]) {
1922 std::cout << " Chrono version: " << CHRONO_VERSION << " \n\n " ;
@@ -53,14 +56,8 @@ int main(int argc, char* argv[]) {
5356
5457 // Create user interface
5558 std::shared_ptr<hydroc::gui::UI> pui = hydroc::gui::CreateUI (visualizationOn);
56-
5759 hydroc::gui::UI& ui = *pui.get ();
5860
59- // some io/viz options
60- std::vector<double > time_vector;
61- std::vector<double > float_heave_position;
62- std::vector<double > plate_heave_position;
63-
6461 // set up body from a mesh
6562 std::cout << " Attempting to open mesh file: " << body1_meshfame << std::endl;
6663 std::shared_ptr<ChBody> float_body1 = chrono_types::make_shared<ChBodyEasyMesh>( //
@@ -127,10 +124,10 @@ int main(int argc, char* argv[]) {
127124
128125 HydroForces hydroForces (bodies, h5fname, default_dont_add_waves);
129126
130- // // Debug printing added mass matrix and system mass matrix
131- // ChSparseMatrix M ;
132- // system.GetMassMatrix(&M) ;
133- // std::cout << M << std::endl ;
127+ // Result arrays
128+ std::vector< double > time_vector ;
129+ std::vector< double > float_heave_position ;
130+ std::vector< double > plate_heave_position ;
134131
135132 // for profiling
136133 auto start = std::chrono::high_resolution_clock::now ();
@@ -190,14 +187,39 @@ int main(int argc, char* argv[]) {
190187 }
191188 }
192189
190+ // Read reference data
191+ ChValidation::Headers col_headers;
192+ ChValidation::Data ref_data = ChValidation::ReadDataFile (REFERENCE_FILE_NAME, col_headers);
193+ ChAssertAlways (ref_data.size () == 3 );
194+
195+ // Simulation data
196+ ChValidation::Data res_data = ChValidation::CreateData ({time_vector, float_heave_position, plate_heave_position});
197+
198+ // Perform validation
199+ auto norm_type = ChValidation::NormType::RMS;
200+ double tolerance = 1e-8 ;
201+ ChValidation::DataVector error_norms;
202+ bool passed = ChValidation::Test (res_data, ref_data, ChValidation::NormType::RMS, tolerance, error_norms);
203+
204+ std::cout << " \n Validation" ;
205+ std::cout << " \n Reference file: " << REFERENCE_FILE_NAME;
206+ std::cout << " \n Data series: " ;
207+ for (const auto & c : col_headers)
208+ std::cout << c << " " ;
209+ std::cout << " \n Ref. data points: " << ref_data[0 ].size ();
210+ std::cout << " \n Sim. data points: " << res_data[0 ].size ();
211+ std::cout << " \n Validation norm: " << ChValidation::GetNormTypeAsString (norm_type);
212+ std::cout << " \n Tolerance: " << tolerance;
213+ std::cout << " \n " << (passed ? " Passed" : " Failed" );
214+ std::cout << " [ " ;
215+ for (const auto & nrm : error_norms)
216+ std::cout << nrm << " " ;
217+ std::cout << " ]" << std::endl;
218+
219+ // Plot simulation and reference results
193220 if (plotOn) {
194- postprocess::ChGnuPlot gplot (out_dir + " /rm3_decay.gpl" );
195- gplot.SetGrid ();
196- gplot.SetLabelX (" time (s)" );
197- gplot.SetLabelY (" heave (m)" );
198- gplot.SetTitle (" RM3 decay" );
199- gplot.Plot (time_vector, plate_heave_position, " " , " with lines lt rgb '#FF5500' lw 2" );
221+ PlotValidation (out_dir + " /rm3_decay.gpl" , " RM3 decay" , col_headers, ref_data, res_data, simulationDuration);
200222 }
201223
202- return 0 ;
203- }
224+ return !passed ;
225+ }
0 commit comments