Skip to content

Commit d3574f8

Browse files
modelling wildfire in Surgut
1 parent 7bf81f2 commit d3574f8

File tree

9 files changed

+29
-24
lines changed

9 files changed

+29
-24
lines changed

include/CellStorage.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@ class CellStorage
3131

3232
public:
3333

34-
double_t latitudeMin;
35-
double_t longtitudeMin;
36-
3734
CellStorage(Math* formula);
3835
CellStorage(Math* formula, int16_t x_size, int16_t y_size);
3936
~CellStorage();

include/Math.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class Math
1616
};
1717

1818
constexpr int ignitionPercentage(){
19-
return 150; // in formula there is smth wrong I suppose
19+
return 50; // in formula there is smth wrong I suppose
2020
}
2121

2222
constexpr int throughPercentage(){

include/ProfilingDecorator.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class ProfilingDecorator final : public Math
3939
mutable int positive_counter_;
4040
mutable int counter_;
4141
mutable std::unordered_map<metaData, int> results_;
42+
mutable std::unordered_map<directions, int> results_directions_;
4243

4344
public:
4445
ProfilingDecorator(Math *formula);

include/Properties.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77

88

99
constexpr int getXArea(){
10-
return 110;
10+
return 1000;
1111
}
1212

1313
constexpr int getYArea(){
14-
return 110;
14+
return 1000;
1515
}
1616

1717
constexpr size_t numberOfSimulations(){
@@ -56,7 +56,8 @@ constexpr int minutesPerIteration(){
5656
}
5757

5858
constexpr std::string analyzedPolygon(){
59-
return "ST_GeomFromText('POLYGON((36.7 55.3, 36.75 55.3, 36.75 55.35, 36.7 55.35, 36.7 55.3))', 4326)";
59+
// return "ST_GeomFromText('POLYGON((36.7 55.3, 36.75 55.3, 36.75 55.35, 36.7 55.35, 36.7 55.3))', 4326)";
60+
return "ST_GeomFromText('POLYGON((70 60.5, 70.5 60.5, 70.5 61, 70 61, 70 60.5))', 4326)";
6061
}
6162

6263
constexpr double pi() { return std::atan(1) * 4; }

src/Connection.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ void Connection::setDemToStorage(CellStorage& storage)
3737
SELECT\
3838
q.*\
3939
FROM\
40-
(SELECT ST_Rescale(rast, 0.0005, 0.0005) as rast from dem) r,\
40+
(SELECT ST_Rescale(rast, 0.00025, 0.00025) as rast from dem_s) r,\
4141
LATERAL ST_PixelAsCentroids(ST_Clip(r.rast, {}), 1) as q\
4242
WHERE \
4343
ST_Intersects(r.rast, {})\
4444
) as t\
45-
WHERE val > 0;", analyzedPolygon(), analyzedPolygon());
45+
WHERE val > 0 and x < {} and y < {};", analyzedPolygon(), analyzedPolygon(), getXArea(), getYArea());
4646

4747
printf("Query started: %d\n", 1);
4848
PGresult *res = this->runQuery(formatted_dem_query.c_str());
@@ -67,12 +67,12 @@ void Connection::setBiomassToStorage(CellStorage& storage)
6767
SELECT\
6868
q.*\
6969
FROM\
70-
(SELECT ST_Rescale(rast, 0.0005, 0.00025) as rast from biomass) r,\
70+
(SELECT ST_Rescale(rast, 0.0005, 0.00025) as rast from biomass_s) r,\
7171
LATERAL ST_PixelAsCentroids(ST_Clip(r.rast, {}), 1) as q\
7272
WHERE \
7373
ST_Intersects(r.rast, {})\
7474
) as t\
75-
WHERE val > 80 and y < {};", analyzedPolygon(), analyzedPolygon(), getYArea());
75+
WHERE val > 80 and x < {} and y < {};", analyzedPolygon(), analyzedPolygon(), getXArea(), getYArea());
7676
PGresult *res = this->runQuery(formatted_biomass_query.c_str());
7777
printf("biomass %d\t", PQntuples(res));
7878
for (int i = 0; i < PQntuples(res); i++)
@@ -87,7 +87,9 @@ void Connection::setBiomassToStorage(CellStorage& storage)
8787
void Connection::setFireToStorage(CellStorage& storage)
8888
{
8989
const std::string formatted_fire_query = std::format("\
90-
SELECT brightness, ST_X(geom), ST_Y(geom)\
90+
SELECT brightness,\
91+
ROUND(ST_Distance(f.geom::geography, ST_SetSRID(ST_MakePoint('70', ST_Y(f.geom)), 4326)::geography)/30),\
92+
ROUND(ST_Distance(f.geom::geography, ST_SetSRID(ST_MakePoint(ST_X(f.geom),'60.5'), 4326)::geography)/30)\
9193
FROM FIRE f\
9294
WHERE ST_Intersects(f.geom, {})", analyzedPolygon());
9395
PGresult *res = this->runQuery(formatted_fire_query.c_str());
@@ -96,8 +98,8 @@ void Connection::setFireToStorage(CellStorage& storage)
9698
{
9799
double_t k = atof(PQgetvalue(res, i, 1));
98100
storage.setNewState(cellState::Fire,
99-
(atof(PQgetvalue(res, i, 1)) - storage.latitudeMin) * 2,
100-
(atof(PQgetvalue(res, i, 2)) - storage.longtitudeMin) * 2);
101+
(atoi(PQgetvalue(res, i, 1))),
102+
(atoi(PQgetvalue(res, i, 2))));
101103
};
102104
}
103105

src/Math.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ double Math1::calculateWindKoef(const cell *c, directions InvestigatedDirection)
2424
if (wind == nullptr){
2525
return double(1);
2626
}
27-
float angleRadians = wind->angleBetweenDirections(InvestigatedDirection) * pi() / 180;
28-
double result = std::exp(wind->getWindSpeed() * (cos(cos(angleRadians)) - 1));
27+
float angleRadians = wind->angleBetweenDirections(InvestigatedDirection);// * pi() / 180;
28+
double result = std::exp(wind->getWindSpeed() * (cos(angleRadians) - 1));
2929
result_wind_[result]++;
3030
return result;
3131
}
@@ -51,7 +51,7 @@ bool Math1::willSpread(const cell *c, directions InvestigatedDirection, int alti
5151
{
5252
double fireKoeff = calculateWindKoef(c, InvestigatedDirection);
5353
double slopeKoeff = calculateGroundSlopeKoef(InvestigatedDirection, altitudeDifference);
54-
int result = fireKoeff * slopeKoeff * 100;
54+
int result = fireKoeff * slopeKoeff * 100 - 40;
5555
result_overall[result]++;
5656
return result + (rand() % 100) > ignitionPercentage();
5757
}

src/ProfilingDecorator.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ bool ProfilingDecorator::willSpread(const cell *c, directions InvestigatedDirect
1515
this->counter_++;
1616
if (result)
1717
{
18+
results_directions_[InvestigatedDirection]++;
1819
this->positive_counter_++;
1920
};
2021
return result;
@@ -46,6 +47,11 @@ ProfilingDecorator::~ProfilingDecorator()
4647
{
4748
printf("%d;%d\n", i.first, i.second);
4849
};
50+
printf("Distribution direction\n");
51+
for (auto &&i : results_directions_)
52+
{
53+
printf("%d;%d\n", static_cast<int>(i.first), i.second);
54+
};
4955

5056
primary_class_->~Math();
5157
}

src/Wind.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ double Wind::CalculateWindKoef(directions InvestigatedDirection) const
3636
int Wind::angleBetweenDirections(directions d) const
3737
{
3838
int differenceInDirections = abs(static_cast<int>(d) - static_cast<int>(this->direction_));
39-
if (differenceInDirections > 4)
40-
{
41-
return (8 - differenceInDirections) * numberOfDegreesPerDirection();
42-
};
39+
// if (differenceInDirections > 4)
40+
// {
41+
// return (8 - differenceInDirections) * numberOfDegreesPerDirection();
42+
// };
4343
return differenceInDirections * numberOfDegreesPerDirection();
4444
}
4545

src/main.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,9 @@ int main()
2525
Math1 formula = Math1();
2626
auto formulaDecorator = ProfilingDecorator(&formula);
2727
CellStorage s = CellStorage(&formulaDecorator);
28-
s.latitudeMin = 10.0;
29-
s.longtitudeMin = 30.0;
3028
auto xRange = std::make_pair<int, int>(0, getXArea());
3129
auto yRange = std::make_pair<int, int>(0, getYArea()/2);
32-
auto w = std::make_shared<const Wind>(directions::North, float(1.0));
30+
auto w = std::make_shared<const Wind>(directions::SouthWest, float(5.0));
3331
s.setWindToArea(xRange, yRange, w);
3432

3533
yRange = std::make_pair<int, int>(getYArea()/2, getYArea());

0 commit comments

Comments
 (0)