55#include < fstream>
66#include < sstream>
77#include < vector>
8+ #include < bits/stdc++.h>
89
910Math::Math (/* args */ )
1011{
@@ -23,14 +24,29 @@ double Math1::calculateKoef(float windSpeed, double slopeAngleRad) const
2324
2425double Math1::calculateWindKoef (const cell *c, directions InvestigatedDirection) const
2526{
27+ clock_t start = clock ();
2628 auto wind = c->getWind ().get ();
2729 if (wind == nullptr )
2830 {
2931 return double (1 );
3032 }
31- float angleRadians = wind->angleBetweenDirections (InvestigatedDirection); // * pi() / 180;
33+ WindMetaData meta = {abs (static_cast <int >(wind->getWindDirection ()) - static_cast <int >(InvestigatedDirection)), wind->getWindSpeed ()};
34+ auto a = wind_result_[meta];
35+ if (a != 0 ){
36+ clock_t per_iteration = clock () - start;
37+ wind_timer_ = per_iteration+wind_timer_;
38+ wind_counter_++;
39+ return wind_result_[meta];
40+ };
41+ float angleRadians = wind->angleBetweenDirections (InvestigatedDirection);
3242 double result = std::exp (wind->getWindSpeed () * (cos (angleRadians) - 1 ));
3343 result_wind_[result]++;
44+
45+ wind_result_[meta] = result;
46+ clock_t per_iteration = clock () - start;
47+ wind_timer_ = per_iteration+wind_timer_;
48+ wind_counter_++;
49+
3450 return result;
3551}
3652
@@ -104,17 +120,35 @@ Math1::Math1()
104120 {
105121 cols.push_back (col);
106122 }
107- auto a = atoi (cols[0 ].c_str ());
123+ auto a = atoi (cols[1 ].c_str ());
108124 slope_result_[SlopeMetaData{to_bool (cols[0 ].c_str ()), a}] = atof (cols[2 ].c_str ());
109125 }
110126 csvFile.close ();
127+ std::ifstream csvFile2{" data/wind.csv" };
128+ while (std::getline (csvFile2, row))
129+ {
130+ std::stringstream rowStream (row);
131+ std::string col;
132+ std::vector<std::string> cols;
133+ while (std::getline (rowStream, col, ' ,' ))
134+ {
135+ cols.push_back (col);
136+ }
137+ float a = atof (cols[1 ].c_str ());
138+
139+ wind_result_[WindMetaData{atoi (cols[0 ].c_str ()), a}] = atof (cols[2 ].c_str ());
140+ }
141+ csvFile2.close ();
111142 slope_counter = 0 ;
112143 slope_timer = 0 ;
144+ wind_counter_ = 0 ;
145+ wind_timer_ = 0 ;
113146}
114147
115148Math1::~Math1 ()
116149{
117- printf (" total time %f, overall counts %d" , (double )(slope_timer), slope_counter);
150+ printf (" total time %f, overall counts %d\n " , (double )(slope_timer), slope_counter);
151+ printf (" total time %f, overall counts %d\n " , (double )(wind_timer_), wind_counter_);
118152 // printf("slope profiling\n");
119153 // std::map<int, int> slope_distribution;
120154
0 commit comments