Commit 51f9f08d authored by Johannes Leins's avatar Johannes Leins
Browse files

allowing fixed disturbances scenarios with otherwise uniform distribution of disturbances

parent 8cada5cc
Pipeline #25978 passed with stage
in 56 seconds
......@@ -191,6 +191,10 @@ void LifeStage::update(Environment* environment) {
if(dummy) {
return;
}
if(currStatYear < environment->getCycle()) {
currStatYear = environment->getCycle();
yearlyPeakDens = 0.0;
}
bool aliveBefore = isAlive();
density = 0;
gain = 0;
......@@ -232,10 +236,6 @@ void LifeStage::update(Environment* environment) {
gain = 0;
}
}
if(currStatYear < environment->getCycle()) {
currStatYear = environment->getCycle();
yearlyPeakDens = 0.0;
}
// loop to update all existing cohorts
for(std::vector<Cohort*>::iterator it_cohorts = cohorts.begin(); it_cohorts != cohorts.end();) {
Cohort* cohort = (*it_cohorts);
......
......@@ -92,6 +92,7 @@ bool useLoadedCoords = true;
bool interpolateClimate = false; // interpolate climate of subplots (sub cells / habitats) in climate cells
bool uniformDisturbances = false; // apply each potentially disturbances uniformly over grid and create a scheme for each
bool soloPops = false; // if true, run a simulation for each initial population separately
Point currSoloCoord;
int limitShuffleYears = 0; // upper/lower limit to pick years from to shuffle
bool movingShuffleWindow = false; // true: choose year from current year +/- limitShuffleYears; false: choose year from (initialYearTimeFrame - limitShuffleYears) to (initialYearTimeFrame + deltaYearsTimeFrame + limitShuffleYears)
int disturbanceAppType = 2; // 0 = only without disturbance, 1 = only with disturbance, 2 = both
......@@ -280,6 +281,7 @@ void updateClimate() {
void updateDisturbances() {
baseDisturbanceScheme.clear();
unordered_set<Point> fixedCells;
nameBaseScheme = "base";
string nameBaseDist = "";
if(uniformDisturbances || disturbanceAppType == 0) {
......@@ -289,24 +291,36 @@ void updateDisturbances() {
disturbanceSchemes[nameBaseScheme] = map<Point, string>({{Point(), nameBaseDist}});
for(auto coord : grasslandCoords) {
baseDisturbanceScheme[coord] = Constants::NAME_DISTURBANCE_NONE;
if(handlerScheme->isFixedAt(coord)) {
fixedCells.insert(coord);
}
}
if(disturbanceAppType == 0 || handlerDisturbances->isEmpty()) {
return;
}
if(uniformDisturbances) {
unsigned int iCoord = 0;
unsigned int iDist = 0;
for(auto distName : disturbanceNames) {
if(distName == Constants::NAME_DISTURBANCE_NONE) {
continue;
}
if(disturbanceAppType == 1 && iCoord == 0) {
if(disturbanceAppType == 1 && iDist == 0) {
disturbanceSchemes.clear();
nameBaseScheme = distName;
for(auto coord : grasslandCoords) {
baseDisturbanceScheme[coord] = distName;
if((!soloPops || currSoloCoord == coord) && fixedCells.find(coord) != fixedCells.end()) {
baseDisturbanceScheme[coord] = handlerScheme->getDisturbanceNameAt(coord);
} else {
baseDisturbanceScheme[coord] = distName;
}
}
}
disturbanceSchemes[distName] = map<Point, string>({{Point(), distName}});
iCoord++;
map<Point, string> distByCoord({{Point(), distName}});
for(auto coord : fixedCells) {
distByCoord[coord] = handlerScheme->getDisturbanceNameAt(coord);
}
disturbanceSchemes[distName] = distByCoord;
iDist++;
}
return;
}
......@@ -511,6 +525,7 @@ bool handleDisturbances() {
baseDisturbanceScheme.clear();
nameBaseScheme = "base";
string nameBaseDist = "";
// TODO M66 as base disturbance ?
if(uniformDisturbances || disturbanceAppType == 0) {
nameBaseScheme = Constants::NAME_DISTURBANCE_NONE;
nameBaseDist = Constants::NAME_DISTURBANCE_NONE;
......@@ -535,25 +550,40 @@ bool handleDisturbances() {
unordered_set<string> loadedDisturbanceNames = handlerDisturbances->getDisturbanceNames();
disturbanceNames.insert(loadedDisturbanceNames.begin(),
loadedDisturbanceNames.end());
cout << "Loading disturbance scheme from file " << filenameDisturbanceScheme << endl;
handlerScheme = new CSVHandlerDisturbanceScheme(filenameDisturbanceScheme, loadedDisturbanceNames);
if(uniformDisturbances) {
unsigned int iCoord = 0;
unsigned int iDist = 0;
unordered_set<Point> fixedCells;
for(auto coord : grasslandCoords) {
if(handlerScheme->isFixedAt(coord)) {
fixedCells.insert(coord);
}
}
for(auto distName : disturbanceNames) {
if(distName == Constants::NAME_DISTURBANCE_NONE) {
continue;
}
if(disturbanceAppType == 1 && iCoord == 0) {
if(disturbanceAppType == 1 && iDist == 0) {
disturbanceSchemes.clear();
nameBaseScheme = distName;
for(auto coord : grasslandCoords) {
baseDisturbanceScheme[coord] = distName;
if((!soloPops || currSoloCoord == coord) && fixedCells.find(coord) != fixedCells.end()) {
baseDisturbanceScheme[coord] = handlerScheme->getDisturbanceNameAt(coord);
} else {
baseDisturbanceScheme[coord] = distName;
}
}
}
disturbanceSchemes[distName] = map<Point, string>({{Point(), distName}});
iCoord++;
map<Point, string> distByCoord({{Point(), distName}});
for(auto coord : fixedCells) {
distByCoord[coord] = handlerScheme->getDisturbanceNameAt(coord);
}
disturbanceSchemes[distName] = distByCoord;
iDist++;
}
return true;
}
cout << "Loading disturbance scheme from file " << filenameDisturbanceScheme << endl;
handlerScheme = new CSVHandlerDisturbanceScheme(filenameDisturbanceScheme, loadedDisturbanceNames);
if(!handlerScheme->isValid() || handlerScheme->isEmpty()) {
cout << "INFO: No disturbance scheme loaded from file. Skipping disturbances" << endl;
cout << handlerScheme->getMessage() << endl;
......@@ -1477,8 +1507,10 @@ bool setup() {
}
bool firstIteration = true;
unsigned int iDistScheme = 1;
for (auto disturbanceScheme : disturbanceSchemes) { // loop over each disturbance scheme
string disturbanceSchemeName = disturbanceScheme.first;
cout << "INFO: setting up disturbance scheme " << iDistScheme++ << "/" << disturbanceSchemes.size() << ": '" << disturbanceSchemeName << "'" << endl;
unordered_map<Point, Population*> populationByCoord;
unordered_set<Point> schemeCoords;
......@@ -1607,13 +1639,14 @@ int batchRun() {
}
cout << "--- Running simulation for time frame " << initialYear << " to " << finalYear << " ---" << endl;
// TODO loop over each init coord if they ere to be processed separately
// TODO loop over each init coord if they are to be processed separately
unordered_set<Point> soloCoords = {Point()};
if(soloPops) {
soloCoords = handlerDensities->getCoords();
}
unsigned int nSoloCoord = 1;
for(auto soloCoord : soloCoords) {
currSoloCoord = soloCoord;
environment->setSoloPop(soloCoord);
// Initialize the batch run for a new climate scenario and time slice
if(!initBatchRun(initialYear, finalYear)) {
......@@ -1666,6 +1699,10 @@ int batchRun() {
Point currSchemeCoord = pairCoordDist.first;
string newDisturbanceName = pairCoordDist.second;
if(uniformDisturbances) {
if(Point() < currSchemeCoord) {
environment->setDisturbanceAt(currSchemeCoord, newDisturbanceName);
continue;
}
for(auto updCoord : grasslandCoords) {
environment->setDisturbanceAt(updCoord, newDisturbanceName);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment