11#include < hydroc/helper.h>
22#include < hydroc/hydro_forces.h>
33
4- #include < chrono/core/ChRealtimeStep.h>
54#include < chrono/physics/ChBodyEasy.h>
65#include < chrono/physics/ChSystemSMC.h>
76
8- #include " chrono_postprocess/ChGnuPlot.h"
9-
107#include < chrono> // std::chrono::high_resolution_clock::now
118#include < iomanip> // std::setprecision
129#include < vector> // std::vector<double>
@@ -17,15 +14,8 @@ using namespace chrono;
1714int main (int argc, char * argv[]) {
1815 std::cout << " Chrono version: " << CHRONO_VERSION << " \n\n " ;
1916
20- // Parse CLI arguments and initialize environment
21- bool profilingOn = true ;
22- bool saveDataOn = true ;
23- bool plotOn = true ;
24- bool visualizationOn = true ;
17+ // Initialize environment
2518 std::string data_dir;
26- if (!hydroc::GetCLIArguments (argc, argv, " F3OF DT1 regression test" , saveDataOn, profilingOn, plotOn,
27- visualizationOn, data_dir))
28- return 1 ;
2919 if (!hydroc::SetInitialEnvironment (data_dir)) return 1 ;
3020
3121 // Get model file names
@@ -42,116 +32,98 @@ int main(int argc, char* argv[]) {
4232 system.SetGravitationalAcceleration (ChVector3d (0.0 , 0.0 , -9.81 ));
4333 double timestep = 0.02 ;
4434 system.SetSolverType (ChSolver::Type::SPARSE_QR);
45- ChRealtimeStepTimer realtime_timer;
4635 double simulationDuration = 300.0 ;
4736
48- // some io/viz options
37+ // Output timeseries
4938 std::vector<double > time_vector;
5039 std::vector<double > base_surge;
5140 std::vector<double > base_pitch;
5241 std::vector<double > fore_pitch;
5342 std::vector<double > aft_pitch;
5443
55- // Output file names
56- std::string filename = " CHRONO_F3OF_DT1_SURGE.txt" ;
57- std::string filename_duration = " CHRONO_F3OF_DT1_SURGE_DURATION.txt" ;
58-
5944 // set up body from a mesh
6045 std::cout << " Attempting to open mesh file: " << body1_meshfame << std::endl;
61- std::shared_ptr<ChBody> base = chrono_types::make_shared<ChBodyEasyMesh>( //
46+ std::shared_ptr<ChBody> base = chrono_types::make_shared<ChBodyEasyMesh>(
6247 body1_meshfame,
6348 0 , // density
6449 false , // do not evaluate mass automatically
6550 true , // create visualization asset
6651 false // collisions
6752 );
6853
69- // Create a visualization material
70- auto red = chrono_types::make_shared<ChVisualMaterial>();
71- red->SetDiffuseColor (ChColor (0 .3f , 0 .1f , 0 .1f ));
72- base->GetVisualShape (0 )->SetMaterial (0 , red);
73-
74- // define the base's initial conditions (position and rotation defined later for specific test)
54+ // define the base's initial conditions
7555 system.Add (base);
7656 base->SetName (" body1" );
7757 base->SetMass (1089825.0 );
7858 base->SetInertiaXX (ChVector3d (100000000.0 , 76300000.0 , 100000000.0 ));
7959
8060 std::cout << " Attempting to open mesh file: " << body2_meshfame << std::endl;
81- std::shared_ptr<ChBody> flapFore = chrono_types::make_shared<ChBodyEasyMesh>( //
61+ std::shared_ptr<ChBody> flapFore = chrono_types::make_shared<ChBodyEasyMesh>(
8262 body2_meshfame,
8363 0 , // density
8464 false , // do not evaluate mass automatically
8565 true , // create visualization asset
8666 false // collisions
8767 );
8868
89- // Create a visualization material
90- auto blue = chrono_types::make_shared<ChVisualMaterial>();
91- blue->SetDiffuseColor (ChColor (0 .3f , 0 .1f , 0 .6f ));
92- flapFore->GetVisualShape (0 )->SetMaterial (0 , blue);
93-
94- // define the fore flap's initial conditions (position and rotation defined later for specific tests
69+ // define the fore flap's initial conditions
9570 system.Add (flapFore);
9671 flapFore->SetName (" body2" );
9772 flapFore->SetMass (179250.0 );
9873 flapFore->SetInertiaXX (ChVector3d (100000000.0 , 1300000.0 , 100000000.0 ));
9974
10075 std::cout << " Attempting to open mesh file: " << body3_meshfame << std::endl;
101- std::shared_ptr<ChBody> flapAft = chrono_types::make_shared<ChBodyEasyMesh>( //
76+ std::shared_ptr<ChBody> flapAft = chrono_types::make_shared<ChBodyEasyMesh>(
10277 body3_meshfame,
10378 0 , // density
10479 false , // do not evaluate mass automatically
10580 true , // create visualization asset
10681 false // collisions
10782 );
10883
109- // Create a visualization material
110- auto green = chrono_types::make_shared<ChVisualMaterial>();
111- green->SetDiffuseColor (ChColor (0 .3f , 0 .6f , 0 .1f ));
112- flapAft->GetVisualShape (0 )->SetMaterial (0 , green);
113-
114- // define the aft flap's initial conditions (position and rotation defined later for specific tests
84+ // define the aft flap's initial conditions
11585 system.Add (flapAft);
11686 flapAft->SetName (" body3" );
11787 flapAft->SetMass (179250.0 );
11888 flapAft->SetInertiaXX (ChVector3d (100000000.0 , 1300000.0 , 100000000.0 ));
11989
120- // ---------------- DT1 set up (surge decay, flaps locked, no waves) ------------------------------
121- // set up pos/rotations
90+ // DT1 set up (surge decay, flaps locked, no waves)
12291 base->SetPos (ChVector3d (5.0 , 0.0 , -9.0 ));
12392 flapFore->SetPos (ChVector3d (5.0 + -12.5 , 0.0 , -9.0 + 3.5 ));
12493 flapAft->SetPos (ChVector3d (5.0 + 12.5 , 0.0 , -9.0 + 3.5 ));
94+
12595 // set up revolute joints and lock them
12696 auto revoluteFore = chrono_types::make_shared<ChLinkLockRevolute>();
12797 auto revoluteAft = chrono_types::make_shared<ChLinkLockRevolute>();
128- ChQuaternion<> revoluteRot = QuatFromAngleX (CH_PI / 2.0 ); // do not change
98+ ChQuaternion<> revoluteRot = QuatFromAngleX (CH_PI / 2.0 );
12999 revoluteFore->Initialize (base, flapFore, ChFramed (ChVector3d (5.0 - 12.5 , 0.0 , -9.0 ), revoluteRot));
130100 system.AddLink (revoluteFore);
131101 revoluteAft->Initialize (base, flapAft, ChFramed (ChVector3d (5.0 + 12.5 , 0.0 , -9.0 ), revoluteRot));
132102 system.AddLink (revoluteAft);
133103 revoluteFore->Lock (true );
134104 revoluteAft->Lock (true );
105+
135106 // create ground
136107 auto ground = chrono_types::make_shared<ChBody>();
137108 system.AddBody (ground);
138109 ground->SetPos (ChVector3d (0 , 0 , -9.0 ));
139110 ground->SetTag (-1 );
140111 ground->SetFixed (true );
141112 ground->EnableCollision (false );
113+
142114 // add prismatic joint between the base and ground
143115 auto prismatic = chrono_types::make_shared<ChLinkLockPrismatic>();
144116 prismatic->Initialize (ground, base, ChFramed (ChVector3d (0.0 , 0.0 , -9.0 ), QuatFromAngleY (CH_PI_2)));
145117 system.AddLink (prismatic);
118+
146119 // add damping to prismatic joint
147120 auto prismatic_pto = chrono_types::make_shared<ChLinkTSDA>();
148121 prismatic_pto->Initialize (ground, base, true , ChVector3d (0.0 , 0.0 , 0.0 ), ChVector3d (0.0 , 0.0 , 0.0 ));
149122 prismatic_pto->SetSpringCoefficient (1e5 );
150123 prismatic_pto->SetRestLength (0.0 );
151124 system.AddLink (prismatic_pto);
152- // ---------------- End DT specific set up, now add hydro forces ----------------------------------
153125
154- // define wave parameters (not used in this demo TODO have hydroforces constructor without hydro inputs)
126+ // define wave parameters
155127 auto default_dont_add_waves = std::make_shared<NoWave>(3 );
156128
157129 // set up hydro forces
@@ -179,53 +151,26 @@ int main(int argc, char* argv[]) {
179151 // for profiling
180152 auto end = std::chrono::high_resolution_clock::now ();
181153 unsigned duration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count ();
182-
183- std::string out_dir = hydroc::getTestOutDir ();
184- if (profilingOn || saveDataOn) {
185- out_dir = out_dir + " /" + RESULTS_DIR_NAME;
186- std::filesystem::create_directory (std::filesystem::path (out_dir));
187- }
188-
189- if (profilingOn) {
190- std::ofstream profilingFile (out_dir + " /" + RESULTS_FILE_NAME + " _duration.txt" );
191- if (profilingFile.is_open ()) {
192- profilingFile << duration << " ms\n " ;
193- profilingFile.close ();
194- } else {
195- std::cout << " Error: Could not open profiling file for writing." << std::endl;
154+ std::cout << " Simulation completed in " << duration << " ms" << std::endl;
155+
156+ // Save results
157+ std::string out_dir = hydroc::getTestOutDir () + " /" + RESULTS_DIR_NAME;
158+ std::filesystem::create_directories (std::filesystem::path (out_dir));
159+
160+ std::ofstream outputFile (out_dir + " /" + RESULTS_FILE_NAME + " .txt" );
161+ if (outputFile.is_open ()) {
162+ outputFile
163+ << " Time (s) Base Surge (m)Base Pitch (radians)Flap Fore Pitch (radians)Flap Aft Pitch (radians)"
164+ << std::endl;
165+ for (size_t i = 0 ; i < time_vector.size (); i++) {
166+ outputFile << std::fixed << std::setprecision (4 ) << time_vector[i] << " "
167+ << base_surge[i] << " " << base_pitch[i] << " " << fore_pitch[i]
168+ << " " << aft_pitch[i] << std::endl;
196169 }
197- }
198-
199- if (saveDataOn) {
200- std::ofstream outputFile (out_dir + " /" + RESULTS_FILE_NAME + " .txt" );
201- if (outputFile.is_open ()) {
202- outputFile
203- << " Time (s) Base Surge (m)Base Pitch (radians)Flap Fore Pitch (radians)Flap Aft Pitch (radians)"
204- << std::endl;
205- for (size_t i = 0 ; i < time_vector.size (); i++) {
206- outputFile << std::fixed << std::setprecision (4 ) << time_vector[i] << " "
207- << base_surge[i] << " " << base_pitch[i] << " " << fore_pitch[i]
208- << " " << aft_pitch[i] << std::endl;
209- }
210- outputFile.close ();
211- } else {
212- std::cout << " Error: Could not open output file for writing." << std::endl;
213- return 1 ; // Return an error code
214- }
215- }
216-
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" );
170+ outputFile.close ();
171+ } else {
172+ std::cout << " Error: Could not open output file for writing." << std::endl;
173+ return 1 ;
229174 }
230175
231176 return 0 ;
0 commit comments