-
Notifications
You must be signed in to change notification settings - Fork 0
/
BalanceSnowModel.h
89 lines (70 loc) · 3.25 KB
/
BalanceSnowModel.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#ifndef BALANCE_SNOW_MODEL
#define BALANCE_SNOW_MODEL
#include <datastr/GeographicMap.h>
#include <datastr/ConstantGeographicMap.h>
using namespace std;
namespace openworld {
class BalanceSnowModel : public SnowModel {
protected:
MatrixGeographicMap<double> volumes;
time_t initialTime;
double lastCoverCoefficient;
double lastSnowsCoefficient;
double lastMeltsCoefficient;
double lastMassCoefficient;
int lastIndex;
MatrixGeographicMap<double> sinceLastSnows;
MatrixGeographicMap<double> sinceLastMelts;
MatrixGeographicMap<double> lastCover;
public:
BalanceSnowModel(GeographicMap<double>& initialVolumes, GeographicMap<double>& initialCover, DividedRange time, double lastCoverCoefficient, double lastSnowsCoefficient, double lastMeltsCoefficient, double lastMassCoefficient)
: SnowModel(time), volumes(initialVolumes), sinceLastSnows(ConstantGeographicMap<double>(initialVolumes.getLatitudes(), initialVolumes.getLongitudes(), 0)), sinceLastMelts(ConstantGeographicMap<double>(initialVolumes.getLatitudes(), initialVolumes.getLongitudes(), 0)), lastCover(initialCover) {
this->lastCoverCoefficient = lastCoverCoefficient;
this->lastSnowsCoefficient = lastSnowsCoefficient;
this->lastMeltsCoefficient = lastMeltsCoefficient;
this->lastMassCoefficient = lastMassCoefficient;
lastIndex = 0;
}
virtual SnowModel* clone() {
return new BalanceSnowModel(volumes, lastCover, time, lastCoverCoefficient, lastSnowsCoefficient,
lastMeltsCoefficient, lastMassCoefficient);
}
virtual DividedRange getLongitudes() {
return volumes.getLongitudes();
}
virtual DividedRange getLatitudes() {
return volumes.getLatitudes();
}
// returns the snowcover
virtual GeographicMap<double>& operator[](Measure tt) {
int tIndex = time.inRange(tt);
if (tIndex == -1)
throw runtime_error("Time is before start in BalanceSnowModel");
if (tIndex != lastIndex) {
/*cout << "SNOW COMPARE" << endl;
for (unsigned rr = 0; rr < volumes.getLatitudes().count(); rr++)
for (unsigned cc = 0; cc < volumes.getLongitudes().count(); cc++) {
cout << rr << ", " << cc << ": " << debugInfo(rr, cc) << endl;
}*/
lastCover = lastCoverCoefficient*lastCover + lastSnowsCoefficient*sinceLastSnows + lastMeltsCoefficient*sinceLastMelts + lastMassCoefficient*volumes;
lastCover = lastCover * ((lastCover > 0) * (lastCover < 100)) + 100 * (lastCover > 100);
volumes += sinceLastSnows - sinceLastMelts;
volumes = volumes * (volumes > 0);
sinceLastMelts.loadConstantInto(0);
sinceLastSnows.loadConstantInto(0);
lastIndex = tIndex;
}
return lastCover;
}
virtual string debugInfo(unsigned rr, unsigned cc) {
stringstream out;
out << lastCover.getCellConst(rr, cc) << "\t" << sinceLastSnows.getCellConst(rr, cc) << "\t" << sinceLastMelts.getCellConst(rr, cc) << "\t" << volumes.getCellConst(rr, cc);
return out.str();
}
virtual void inform(GeographicMap<double>& newMeltVolume, GeographicMap<double>& newSnowVolume) {
sinceLastMelts += newMeltVolume;
sinceLastSnows += newSnowVolume;
}
};
}
#endif