22#include < vector>
33#include < Eigen/Dense>
44#include < fstream>
5+ #include < chrono>
6+ #include < string>
57#include " json.hpp"
68#include " VectorOperations.h"
79#include " geometry.h"
@@ -18,8 +20,18 @@ using namespace std;
1820using namespace Eigen ;
1921using json = nlohmann::json;
2022
23+ // Helper function to convert double to string without trailing zeros
24+ string double_to_string (double val, int precision = 3 ) {
25+ ostringstream out;
26+ out << fixed << setprecision (precision) << val;
27+ string s = out.str ();
28+ s.erase (s.find_last_not_of (' 0' ) + 1 , string::npos);
29+ if (s.back () == ' .' ) s.pop_back ();
30+ return s;
31+ }
2132int main (int argc, char *argv[])
2233{
34+
2335 if (argc < 2 )
2436 {
2537 cerr << " Usage:" << argv[0 ] << " <input_file.json>" << endl;
@@ -141,8 +153,12 @@ int main(int argc, char *argv[])
141153 j_cap (0 ) = 0.0 ;
142154 j_cap (1 ) = 1.0 ;
143155
144- ofstream myfile_load_cal, wake_last_time_step, wake_panel, wakefile, motionfile, pressurefile, gammafile, potentialfile, amatrixfile, bvectorfile, airfoilnormalfile;
145- myfile_load_cal.open (" output_files/cl_cd_pitch_plunge_k=1.2_n=101.dat" );
156+ ofstream wake_last_time_step, wake_panel, wakefile, motionfile, pressurefile, gammafile, potentialfile, amatrixfile, bvectorfile, airfoilnormalfile;
157+
158+ string motion_type = " pitch_plunge" ; // subjected to change manually
159+ string myfile_load_cal = " output_files/cl_cd_" + motion_type + " _k=" + double_to_string (k, 3 )+ " _n=" + to_string (n)+ " .dat" ;
160+ ofstream file (myfile_load_cal);
161+
146162 wake_last_time_step.open (" output_files/wake at last time step.dat" );
147163 wake_panel.open (" output_files/wake panel at last time step.dat" );
148164
@@ -235,7 +251,6 @@ int main(int argc, char *argv[])
235251 airfoilnormalfile << unit_normal (i, 0 ) << " \t " << unit_normal (i, 1 ) << endl;
236252 }
237253
238- cout << " percentage completed =" << iter / iterMax * 100.0 << endl;
239254 /* self induced portion and kutta conditon...*/
240255 for (int i = 0 ; i < n; i++)
241256 {
@@ -312,8 +327,8 @@ int main(int argc, char *argv[])
312327 /* fill the coefficient matrix or the jacobian matrix */
313328 rhs_vector (0 ) = -residuals (0 );
314329 rhs_vector (1 ) = -residuals (1 );
315- length_and_angle = jacobian.fullPivHouseholderQr ().solve (rhs_vector);
316-
330+ // length_and_angle = jacobian.colPivHouseholderQr ().solve(rhs_vector);
331+ length_and_angle = jacobian. partialPivLu (). solve (rhs_vector);
317332 delta_lwp = length_and_angle (0 );
318333 delta_theta_wp = length_and_angle (1 );
319334 convergence = magnitude (length_and_angle);
@@ -345,7 +360,7 @@ int main(int argc, char *argv[])
345360 /* Once the Iterative Procedure to calculate the length and orientation of the wake panel has converged,we can now calculate the aerodynamic loads ......*/
346361
347362 /* For that first compute the pressure distribution on the surface of the airfoil and then integrate that pressure to obtain the lift and drag forces ...*/
348- int z = 200 ; // number of panels..
363+ // int z = 200; // number of panels..
349364 VectorXd x_forward_stag_streamline (z + 1 ); // z+1 is the number of nodes in forward stagnation streamline.
350365 VectorXd y_forward_stag_streamline (z + 1 );
351366 VectorXd xcp_forward_stag_streamline (z);
@@ -573,7 +588,7 @@ int main(int argc, char *argv[])
573588 }
574589
575590 // myfile_load_cal << 2.0*t*Qinf/c << "\t" << cn_tilda / cl_tilda_steady << "\t" << ca_tilda << endl; //uncomment this for sudden acceleration case.
576- myfile_load_cal << t / T << " \t " << cn_tilda << " \t " << ca_tilda << endl;
591+ file << t / T << " \t " << cn_tilda << " \t " << ca_tilda << endl;
577592
578593 xdata.push_back (t / T);
579594 ydata.push_back (cn_tilda);
@@ -663,10 +678,17 @@ int main(int argc, char *argv[])
663678 }
664679 pclose (gnuplotPipe);
665680 pclose (gnuplotPipe1);
666-
681+ file.close ();
682+
667683 /* plotting the flowfield at the last time step.*/
668684 for (size_t j = 0 ; j < gamma_wake_strength.size (); j++)
669685 {
670686 wake_last_time_step << gamma_wake_x_location[j] << " \t " << gamma_wake_y_location[j] << endl;
671687 }
688+ // End timer
689+
690+ cout << " The code was run for" << " \t " << ncycles << " cycles" << endl;
691+
692+
693+ return 0 ;
672694}
0 commit comments