33#include < hydroc/hydro_forces.h>
44
55#include < chrono/core/ChRealtimeStep.h>
6- #include < chrono/physics/ChSystemNSC.h>
76#include < chrono/physics/ChBodyEasy.h>
7+ #include < chrono/physics/ChSystemNSC.h>
88
99#include < chrono> // std::chrono::high_resolution_clock::now
1010#include < iomanip> // std::setprecision
@@ -59,31 +59,33 @@ std::array<double, 3> add_vectors(std::array<double, 3> v1, std::array<double, 3
5959 return {v1[0 ] + v2[0 ], v1[1 ] + v2[1 ], v1[2 ] + v2[2 ]};
6060}
6161
62-
6362int main (int argc, char * argv[]) {
64-
65- std::vector< double > periods = { 4.0 , 6.0 , 8.0 , 10.0 , 12.0 , 14.0 , 16.0 , 18.0 , 18.5 , 19.0 , 19.25 , 19.5 , 20.0 , 21.0 , 22.0 , 24.0 };
63+ std::vector< double > periods = { 4.0 , 6.0 , 8.0 , 10.0 , 12.0 , 14.0 , 16.0 , 18.0 ,
64+ 18.5 , 19.0 , 19.25 , 19.5 , 20.0 , 21.0 , 22.0 , 24.0 };
6665 int reg_wave_num_max = periods.size ();
6766
6867 for (int reg_wave_num = 1 ; reg_wave_num <= reg_wave_num_max; ++reg_wave_num) {
6968 std::cout << " Chrono version: " << CHRONO_VERSION << " \n\n " ;
7069
7170 // Parse CLI arguments and initialize environment
71+ bool plotOn = true ;
7272 bool visualizationOn = true ;
7373 bool profilingOn = true ;
7474 bool saveDataOn = true ;
7575 std::string data_dir;
76- if (!hydroc::GetCLIArguments (argc, argv, " OSWEC regular waves demo" , saveDataOn, profilingOn, visualizationOn ,
77- data_dir))
76+ if (!hydroc::GetCLIArguments (argc, argv, " OSWEC regular waves demo" , saveDataOn, profilingOn, plotOn ,
77+ visualizationOn, data_dir))
7878 return 1 ;
7979 if (!hydroc::SetInitialEnvironment (data_dir)) return 1 ;
8080
8181 // Get model file names
8282 std::filesystem::path DATADIR (hydroc::getDataDir ());
8383
84- auto body1_meshfname = (DATADIR / " demos" / " oswec" / " geometry" / " flap.obj" ).lexically_normal ().generic_string ();
85- auto body2_meshfname = (DATADIR / " demos" / " oswec" / " geometry" / " base.obj" ).lexically_normal ().generic_string ();
86- auto h5fname = (DATADIR / " demos" / " oswec" / " hydroData" / " oswec.h5" ).lexically_normal ().generic_string ();
84+ auto body1_meshfname =
85+ (DATADIR / " demos" / " oswec" / " geometry" / " flap.obj" ).lexically_normal ().generic_string ();
86+ auto body2_meshfname =
87+ (DATADIR / " demos" / " oswec" / " geometry" / " base.obj" ).lexically_normal ().generic_string ();
88+ auto h5fname = (DATADIR / " demos" / " oswec" / " hydroData" / " oswec.h5" ).lexically_normal ().generic_string ();
8789
8890 // system/solver settings
8991 ChSystemNSC system;
@@ -92,7 +94,7 @@ int main(int argc, char* argv[]) {
9294 double timestep = 0.03 ;
9395 // system.SetTimestepperType(ChTimestepper::Type::HHT);
9496 system.SetSolverType (ChSolver::Type::GMRES);
95- // system.GetSolver()->AsIterative()->SetMaxIterations(300); // the higher, the easier to keep the constraints satisfied.
97+ // system.GetSolver()->AsIterative()->SetMaxIterations(300);
9698 ChRealtimeStepTimer realtime_timer;
9799 double simulationDuration = 1000.0 ;
98100
@@ -109,16 +111,16 @@ int main(int argc, char* argv[]) {
109111 std::array<double , 3 > axis = {0 , 1 , 0 };
110112 double angle_in_degrees = 0.0 ;
111113
112- // std::array<double, 3> rotated_hinge_to_cg = rotate_vector_3d(hinge_to_cg, axis, angle_in_degrees);
114+ // std::array<double, 3> rotated_hinge_to_cg = rotate_vector_3d(hinge_to_cg, axis, angle_in_degrees);
113115
114- // std::array<double, 3> new_cg = add_vectors(origin_to_hinge, rotated_hinge_to_cg);
116+ // std::array<double, 3> new_cg = add_vectors(origin_to_hinge, rotated_hinge_to_cg);
115117
116- // std::cout << "The original vector is [" << hinge_to_cg[0] << ", " << hinge_to_cg[1] << ", " << hinge_to_cg[2]
117- // << "]" << std::endl;
118- // std::cout << "The rotated vector is [" << rotated_hinge_to_cg[0] << ", " << rotated_hinge_to_cg[1] << ", "
119- // << rotated_hinge_to_cg[2] << "]" << std::endl;
120- // std::cout << "The new vector is [" << new_cg[0] << ", " << new_cg[1] << ", " << new_cg[2] << "]"
121- // << std::endl;
118+ // std::cout << "The original vector is [" << hinge_to_cg[0] << ", " << hinge_to_cg[1] << ", " << hinge_to_cg[2]
119+ // << "]" << std::endl;
120+ // std::cout << "The rotated vector is [" << rotated_hinge_to_cg[0] << ", " << rotated_hinge_to_cg[1] << ", "
121+ // << rotated_hinge_to_cg[2] << "]" << std::endl;
122+ // std::cout << "The new vector is [" << new_cg[0] << ", " << new_cg[1] << ", " << new_cg[2] << "]"
123+ // << std::endl;
122124
123125 // set up body from a mesh
124126 std::cout << " Attempting to open mesh file: " << body1_meshfname << std::endl;
@@ -141,7 +143,7 @@ int main(int argc, char* argv[]) {
141143 auto ang_rad = CH_PI / 18.0 ;
142144 // flap_body->SetPos(ChVector3d(new_cg[0], new_cg[1], new_cg[2]));
143145 flap_body->SetPos (ChVector3d (0.0 , 0.0 , -3.9 ));
144- // flap_body->SetRot(QuatFromAngleY(ang_rad));
146+ // flap_body->SetRot(QuatFromAngleY(ang_rad));
145147 flap_body->SetMass (127000.0 );
146148 flap_body->SetInertiaXX (ChVector3d (1.85e6 , 1.85e6 , 1.85e6 ));
147149 // notes: mass and inertia added to added mass and system mass correctly.
@@ -196,9 +198,9 @@ int main(int argc, char* argv[]) {
196198 bodies.push_back (flap_body);
197199 bodies.push_back (base_body);
198200
199- auto my_hydro_inputs = std::make_shared<RegularWave>(static_cast <unsigned int >(bodies.size ()));
201+ auto my_hydro_inputs = std::make_shared<RegularWave>(static_cast <unsigned int >(bodies.size ()));
200202 my_hydro_inputs->regular_wave_amplitude_ = 0.01 ;
201- my_hydro_inputs->regular_wave_omega_ = (2 * CH_PI)/ (periods[reg_wave_num - 1 ]);
203+ my_hydro_inputs->regular_wave_omega_ = (2 * CH_PI) / (periods[reg_wave_num - 1 ]);
202204
203205 // // attach hydrodynamic forces to body
204206 /* std::vector<std::shared_ptr<ChBody>> bodies;
@@ -244,23 +246,22 @@ int main(int argc, char* argv[]) {
244246
245247 if (saveDataOn) {
246248 std::ofstream outputFile (out_dir + " /reg_waves_" + std::to_string (reg_wave_num) + " .txt" );
247- // outputFile << std::left << std::setw(10) << "Time (s)" << std::right << std::setw(16)
248- // << "Flap Rotation y (radians)" << std::right << std::setw(16) << "Flap Rotation y (degrees)"
249- // << std::endl;
250- // for (int i = 0; i < time_vector.size(); ++i)
251- // outputFile << std::left << std::setw(10) << std::setprecision(2) << std::fixed << time_vector[i]
252- // << std::right << std::setw(16) << std::setprecision(4) << std::fixed << flap_rot[i]
253- // << std::right << std::setw(16) << std::setprecision(4) << std::fixed
254- // << flap_rot[i] * 360.0 / 6.28 << std::endl;
255- // outputFile.close();
249+ // outputFile << std::left << std::setw(10) << "Time (s)" << std::right << std::setw(16)
250+ // << "Flap Rotation y (radians)" << std::right << std::setw(16) << "Flap Rotation y (degrees)"
251+ // << std::endl;
252+ // for (int i = 0; i < time_vector.size(); ++i)
253+ // outputFile << std::left << std::setw(10) << std::setprecision(2) << std::fixed << time_vector[i]
254+ // << std::right << std::setw(16) << std::setprecision(4) << std::fixed << flap_rot[i]
255+ // << std::right << std::setw(16) << std::setprecision(4) << std::fixed
256+ // << flap_rot[i] * 360.0 / 6.28 << std::endl;
257+ // outputFile.close();
256258
257259 outputFile.precision (10 );
258260 outputFile.width (12 );
259261 outputFile << " Wave #: \t " << reg_wave_num << " \n " ;
260262 outputFile << " Wave amplitude (m): \t " << my_hydro_inputs->regular_wave_amplitude_ << " \n " ;
261263 outputFile << " Wave omega (rad/s): \t " << my_hydro_inputs->regular_wave_omega_ << " \n " ;
262- outputFile << std::left << std::setw (10 ) << " Time (s)" << std::right << std::setw (12 )
263- << " Pitch (rads)"
264+ outputFile << std::left << std::setw (10 ) << " Time (s)" << std::right << std::setw (12 ) << " Pitch (rads)"
264265 << std::endl;
265266 for (int i = 0 ; i < time_vector.size (); ++i)
266267 outputFile << std::left << std::setw (10 ) << std::setprecision (2 ) << std::fixed << time_vector[i]
0 commit comments