44#include < chrono/physics/ChBodyEasy.h>
55#include < chrono/physics/ChSystemNSC.h>
66
7- #include < chrono/utils/ChUtils.h>
8-
9- #include " ../test_utils.h"
10-
117#include < chrono> // std::chrono::high_resolution_clock::now
128#include < iomanip> // std::setprecision
139#include < vector> // std::vector<double>
1410
1511// Use the namespaces of Chrono
1612using namespace chrono ;
17- using namespace chrono ::utils;
1813
1914int main (int argc, char * argv[]) {
2015 std::cout << " Chrono version: " << CHRONO_VERSION << " \n\n " ;
@@ -26,11 +21,27 @@ int main(int argc, char* argv[]) {
2621 // Get model file names
2722 std::filesystem::path DATADIR (hydroc::getDataDir ());
2823
29- auto body1_meshfame =
30- (DATADIR / " demos" / " rm3" / " geometry" / " float_cog.obj" ).lexically_normal ().generic_string ();
31- auto body2_meshfame =
32- (DATADIR / " demos" / " rm3" / " geometry" / " plate_cog.obj" ).lexically_normal ().generic_string ();
33- auto h5fname = (DATADIR / " demos" / " rm3" / " hydroData" / " rm3.h5" ).lexically_normal ().generic_string ();
24+ std::filesystem::path body1_path = DATADIR / " demos" / " rm3" / " geometry" / " float_cog.obj" ;
25+ std::filesystem::path body2_path = DATADIR / " demos" / " rm3" / " geometry" / " plate_cog.obj" ;
26+ std::filesystem::path h5_path = DATADIR / " demos" / " rm3" / " hydroData" / " rm3.h5" ;
27+
28+ // Early sanity check
29+ if (!std::filesystem::exists (body1_path)) {
30+ std::cerr << " ERROR: float_cog mesh not found at " << body1_path << std::endl;
31+ return 1 ;
32+ }
33+ if (!std::filesystem::exists (body2_path)) {
34+ std::cerr << " ERROR: plate_cog mesh not found at " << body2_path << std::endl;
35+ return 1 ;
36+ }
37+ if (!std::filesystem::exists (h5_path)) {
38+ std::cerr << " ERROR: rm3.h5 not found at " << h5_path << std::endl;
39+ return 1 ;
40+ }
41+
42+ auto body1_meshfame = body1_path.lexically_normal ().generic_string ();
43+ auto body2_meshfame = body2_path.lexically_normal ().generic_string ();
44+ auto h5fname = h5_path.lexically_normal ().generic_string ();
3445
3546 // system/solver settings
3647 ChSystemNSC system;
@@ -42,9 +53,10 @@ int main(int argc, char* argv[]) {
4253 system.SetSolverType (ChSolver::Type::SPARSE_QR);
4354 double simulationDuration = 40.0 ;
4455
45- // Create user interface
46- std::shared_ptr<hydroc::gui::UI> pui = hydroc::gui::CreateUI (visualizationOn);
47- hydroc::gui::UI& ui = *pui.get ();
56+ // Output timeseries
57+ std::vector<double > time_vector;
58+ std::vector<double > float_heave_position;
59+ std::vector<double > plate_heave_position;
4860
4961 // set up body from a mesh
5062 std::cout << " Attempting to open mesh file: " << body1_meshfame << std::endl;
@@ -98,12 +110,8 @@ int main(int argc, char* argv[]) {
98110 bodies.push_back (float_body1);
99111 bodies.push_back (plate_body2);
100112
101- HydroForces hydroForces (bodies, h5fname, default_dont_add_waves);
102-
103- // Result arrays
104- std::vector<double > time_vector;
105- std::vector<double > float_heave_position;
106- std::vector<double > plate_heave_position;
113+ HydroForces hydro_forces (bodies, h5fname);
114+ hydro_forces.AddWaves (default_dont_add_waves);
107115
108116 // for profiling
109117 auto start = std::chrono::high_resolution_clock::now ();
@@ -127,66 +135,20 @@ int main(int argc, char* argv[]) {
127135 std::string out_dir = hydroc::getTestOutDir () + " /" + RESULTS_DIR_NAME;
128136 std::filesystem::create_directories (std::filesystem::path (out_dir));
129137
130- if (profilingOn) {
131- std::ofstream profilingFile (out_dir + " /" + RESULTS_FILE_NAME + " _duration.txt" );
132- if (profilingFile.is_open ()) {
133- profilingFile << duration << " ms\n " ;
134- profilingFile.close ();
135- } else {
136- std::cout << " Error: Could not open profiling file for writing." << std::endl;
137- }
138- }
139-
140- if (saveDataOn) {
141- std::ofstream outputFile (out_dir + " /" + RESULTS_FILE_NAME + " .txt" );
142- if (outputFile.is_open ()) {
143- outputFile << std::left << std::setw (10 ) << " Time (s)" << std::right << std::setw (16 ) << " Float Heave (m)"
144- << std::right << std::setw (16 ) << " Plate Heave (m)" << std::endl;
145- for (size_t i = 0 ; i < time_vector.size (); ++i)
146- outputFile << std::left << std::setw (10 ) << std::setprecision (2 ) << std::fixed << time_vector[i]
147- << std::right << std::setw (16 ) << std::setprecision (8 ) << std::fixed
148- << float_heave_position[i] << std::right << std::setw (16 ) << std::setprecision (8 )
149- << std::fixed << plate_heave_position[i] << std::endl;
150- outputFile.close ();
151- } else {
152- std::cout << " Error: Could not open output file for writing." << std::endl;
153- return 1 ; // Return an error code
154- }
155- }
156-
157- // Read reference data
158- ChValidation::Headers col_headers;
159- ChValidation::Data ref_data = ChValidation::ReadDataFile (REFERENCE_FILE_NAME, col_headers);
160- ChAssertAlways (ref_data.size () == 3 );
161-
162- // Simulation data
163- ChValidation::Data res_data = ChValidation::CreateData ({time_vector, float_heave_position, plate_heave_position});
164-
165- // Perform validation
166- auto norm_type = ChValidation::NormType::RMS;
167- double tolerance = 1e-8 ;
168- ChValidation::DataVector error_norms;
169- bool passed = ChValidation::Test (res_data, ref_data, ChValidation::NormType::RMS, tolerance, error_norms);
170-
171- std::cout << " \n Validation" ;
172- std::cout << " \n Reference file: " << REFERENCE_FILE_NAME;
173- std::cout << " \n Data series: " ;
174- for (const auto & c : col_headers)
175- std::cout << c << " " ;
176- std::cout << " \n Ref. data points: " << ref_data[0 ].size ();
177- std::cout << " \n Sim. data points: " << res_data[0 ].size ();
178- std::cout << " \n Validation norm: " << ChValidation::GetNormTypeAsString (norm_type);
179- std::cout << " \n Tolerance: " << tolerance;
180- std::cout << " \n " << (passed ? " Passed" : " Failed" );
181- std::cout << " [ " ;
182- for (const auto & nrm : error_norms)
183- std::cout << nrm << " " ;
184- std::cout << " ]" << std::endl;
185-
186- // Plot simulation and reference results
187- if (plotOn) {
188- PlotValidation (out_dir + " /rm3_decay.gpl" , " RM3 decay" , col_headers, ref_data, res_data, simulationDuration);
138+ std::ofstream outputFile (out_dir + " /" + RESULTS_FILE_NAME + " .txt" );
139+ if (outputFile.is_open ()) {
140+ outputFile << std::left << std::setw (10 ) << " Time (s)" << std::right << std::setw (16 ) << " Float Heave (m)"
141+ << std::right << std::setw (16 ) << " Plate Heave (m)" << std::endl;
142+ for (size_t i = 0 ; i < time_vector.size (); ++i)
143+ outputFile << std::left << std::setw (10 ) << std::setprecision (2 ) << std::fixed << time_vector[i]
144+ << std::right << std::setw (16 ) << std::setprecision (8 ) << std::fixed
145+ << float_heave_position[i] << std::right << std::setw (16 ) << std::setprecision (8 )
146+ << std::fixed << plate_heave_position[i] << std::endl;
147+ outputFile.close ();
148+ } else {
149+ std::cout << " Error: Could not open output file for writing." << std::endl;
150+ return 1 ;
189151 }
190152
191- return !passed ;
153+ return 0 ;
192154}
0 commit comments