Skip to content

Commit 20f7f15

Browse files
wind analyzing
1 parent 4531b12 commit 20f7f15

File tree

5 files changed

+156
-94
lines changed

5 files changed

+156
-94
lines changed

data/slope.csv

Lines changed: 102 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,103 @@
1-
-20,0,0.675232
2-
17,0,1.422260
3-
-27,1,0.683119
4-
10,0,1.185208
5-
19,0,1.344144
6-
14,0,1.258360
7-
15,0,1.276099
8-
16,0,1.293566
9-
31,0,1.515261
10-
21,0,1.376205
11-
-21,0,0.726636
12-
-15,0,0.724879
13-
12,0,1.222165
14-
11,0,1.285852
15-
-18,0,0.693220
16-
9,0,1.235440
17-
-14,0,0.736856
18-
25,1,1.436084
19-
21,1,1.376205
20-
18,0,1.327604
21-
18,1,1.327604
22-
-19,1,0.743968
23-
13,0,1.334008
24-
-20,1,0.735107
25-
14,1,1.357118
26-
19,1,1.344144
27-
8,0,1.147771
28-
6,0,1.156882
29-
-25,0,0.696338
30-
-14,1,0.794685
31-
-16,1,0.773057
32-
-21,1,0.726636
33-
22,1,1.391711
34-
-10,1,0.793086
35-
2,0,1.035927
36-
31,1,1.515261
37-
10,1,1.185208
38-
-2,1,0.951387
39-
1,0,1.017827
40-
-11,0,0.777694
41-
-8,0,0.826750
42-
-5,0,0.916233
43-
-2,0,0.965319
44-
-1,1,0.975330
45-
0,1,1.000000
46-
1,1,1.025294
47-
-6,1,0.900760
48-
6,1,1.156882
49-
-7,1,0.885763
50-
5,1,1.091425
51-
3,1,1.077286
52-
-1,0,0.975330
1+
0,-23,0.652120
2+
0,23,1.406861
3+
0,-24,0.703407
4+
1,-23,0.652120
5+
1,-25,0.696338
6+
0,26,1.580198
7+
0,-22,0.718540
8+
1,-18,0.753236
9+
0,-26,0.689581
10+
0,-19,0.743968
11+
1,27,1.463874
12+
1,26,1.580198
13+
0,-20,0.675232
14+
0,17,1.310740
15+
1,-27,0.683119
16+
0,10,1.260898
17+
0,19,1.462111
18+
0,14,1.258360
19+
0,15,1.276099
20+
0,16,1.401258
21+
0,31,1.515261
22+
0,21,1.376205
23+
0,-21,0.726636
24+
0,-15,0.724879
25+
0,12,1.222165
26+
0,11,1.285852
27+
0,-18,0.693220
28+
0,9,1.235440
29+
0,-14,0.736856
30+
1,25,1.436084
31+
1,21,1.376205
32+
0,18,1.327604
33+
1,18,1.327604
34+
1,-19,0.743968
35+
0,13,1.334008
36+
1,-20,0.735107
37+
1,14,1.258360
38+
1,19,1.344144
39+
0,8,1.209556
40+
0,6,1.156882
41+
0,-25,0.696338
42+
1,-14,0.794685
43+
1,-16,0.773057
44+
1,-21,0.726636
45+
1,22,1.391711
46+
1,-10,0.843734
47+
0,2,1.035927
48+
1,31,1.515261
49+
1,10,1.185208
50+
1,-2,0.965319
51+
0,1,1.017827
52+
0,-8,0.871254
53+
0,-5,0.884715
54+
0,-2,0.951387
55+
1,-1,0.975330
56+
1,0,1.000000
57+
1,-6,0.900760
58+
1,6,1.110174
59+
1,-7,0.885763
60+
1,5,1.091425
61+
1,3,1.077286
62+
0,3,1.054256
63+
1,1,1.017827
64+
0,-11,0.777694
65+
0,-1,0.975330
5366
0,0,1.000000
54-
-3,1,0.948536
55-
2,1,1.051097
56-
9,1,1.235440
57-
3,0,1.077286
58-
-3,0,0.948536
59-
23,1,1.406861
60-
-9,1,0.857243
61-
7,1,1.128971
62-
-5,1,0.916233
63-
8,1,1.147771
64-
-4,1,0.932166
65-
15,1,1.276099
66-
-17,1,0.762928
67-
-7,0,0.845069
68-
-8,1,0.826750
69-
24,1,1.421652
70-
4,0,1.072771
71-
20,1,1.360347
72-
-12,1,0.763219
73-
5,0,1.091425
74-
-4,0,0.932166
75-
-9,0,0.809428
76-
7,0,1.128971
77-
4,1,1.103733
78-
-6,0,0.864392
79-
-10,0,0.843734
80-
17,1,1.310740
81-
-15,1,0.783638
82-
-16,0,0.713644
83-
-17,0,0.762928
84-
11,1,1.203765
85-
12,1,1.222165
86-
16,1,1.293566
87-
13,1,1.240373
88-
-11,1,0.830727
89-
-13,1,0.806209
90-
-13,0,0.749621
91-
-12,0,0.818220
67+
1,-3,0.928259
68+
1,2,1.051097
69+
1,9,1.166530
70+
0,-3,0.948536
71+
1,23,1.406861
72+
1,-9,0.857243
73+
1,7,1.128971
74+
1,-5,0.884715
75+
1,8,1.147771
76+
1,-4,0.932166
77+
1,15,1.276099
78+
1,-17,0.703106
79+
0,-7,0.885763
80+
1,-8,0.871254
81+
1,24,1.421652
82+
0,4,1.072771
83+
1,20,1.360347
84+
1,-12,0.763219
85+
0,5,1.091425
86+
0,-4,0.932166
87+
0,-9,0.857243
88+
0,7,1.128971
89+
1,4,1.072771
90+
0,-6,0.900760
91+
0,-10,0.793086
92+
1,17,1.310740
93+
1,-15,0.783638
94+
0,-16,0.713644
95+
0,-17,0.703106
96+
1,11,1.203765
97+
1,12,1.222165
98+
1,16,1.293566
99+
1,13,1.240373
100+
1,-11,0.777694
101+
1,-13,0.806209
102+
0,-13,0.749621
103+
0,-12,0.818220

data/wind.csv

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
0,5.000000,1.000000
2+
1,5.000000,0.093164
3+
2,5.000000,0.000717
4+
3,5.000000,0.000046
5+
4,5.000000,0.000338
6+
5,5.000000,0.042282

include/Math.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ struct SlopeMetaData
1919
struct WindMetaData
2020
{
2121
int direction_difference_;
22-
double wind_speed_;
22+
float wind_speed_;
2323
bool operator==(const WindMetaData &rhs) const
2424
{
2525
return direction_difference_ == rhs.direction_difference_ &&
@@ -85,6 +85,11 @@ class Math1 final : public Math
8585
mutable std::map<int, int> result_overall;
8686
mutable clock_t slope_timer;
8787
mutable int slope_counter;
88+
89+
mutable clock_t wind_timer_;
90+
mutable int wind_counter_;
91+
mutable std::unordered_map<WindMetaData, double> wind_result_;
92+
8893
double calculateKoef(float windSpeed, double slopeAngleRad) const;
8994
double calculateWindKoef(const cell *c, directions InvestigatedDirection) const;
9095
double calculateGroundSlopeKoef(directions InvestigatedDirection, int altitudeDifference) const;

src/Math.cpp

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <fstream>
66
#include <sstream>
77
#include <vector>
8+
#include <bits/stdc++.h>
89

910
Math::Math(/* args */)
1011
{
@@ -23,14 +24,29 @@ double Math1::calculateKoef(float windSpeed, double slopeAngleRad) const
2324

2425
double 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

115148
Math1::~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

src/main.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ int main()
3434
w = std::make_shared<const Wind>(directions::SouthEast, float(2.0));
3535
s.setWindToArea(xRange, yRange, w);
3636

37+
for (size_t i = 0; i < 10; i++)
38+
{
39+
3740
c.setStatesToStorage(s);
3841

3942
clock_t tStart = clock();
@@ -51,6 +54,8 @@ int main()
5154
// std::cout << "WorkingSetSize " << memCounter.PeakWorkingSetSize << std::endl;
5255

5356
printf("Time taken: %.2fs\n", (double)(clock() - tStart) / CLOCKS_PER_SEC);
57+
58+
};
5459
s.printCurrentStates();
5560
// s.saveFiresToJson();
5661

0 commit comments

Comments
 (0)