Skip to content

Commit

Permalink
read 'habitatTypeExitConditionHours' for configurable consecutive Nea…
Browse files Browse the repository at this point in the history
…rshore hours to exit (#13)

* use number of consecutive nearshore hours for exit criteria
* read 'habitatTypeExitConditionHours' from config file
* defaults to 2 hours if not found in config file
  • Loading branch information
troyfrever-NOAA authored Dec 17, 2024
1 parent 272607a commit 7e71692
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 15 deletions.
2 changes: 2 additions & 0 deletions .idea/Skagit-IBM2.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 0 additions & 8 deletions .idea/modules.xml

This file was deleted.

3 changes: 2 additions & 1 deletion run6_config/config_map_2013_data_2014.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@
"flowSpeedFile": "data/mod_flow_condensed.nc",
"distribWseTempFile": "data/wse.temp.full.nc",
"threadCount": 96,
"blindChannelSimplificationRadius": 15.0
"blindChannelSimplificationRadius": 15.0,
"habitatTypeExitConditionHours": 6.0
}
18 changes: 13 additions & 5 deletions src/fish.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ inline float forkLengthFromMass(float mass) {
// This is a sustained swim speed
const float SWIM_SPEED_BODY_LENGTHS_PER_SEC = 2.0f;

const float SECONDS_PER_TIMESTEP = 60.0f*60.0f;
constexpr float HOURS_PER_TIMESTEP = 1.0f;
constexpr float SECONDS_PER_TIMESTEP = HOURS_PER_TIMESTEP * 60.0f*60.0f;

// Calculate a sustained-movement swim range (in m) from a fork length (in mm)
inline float swimSpeedFromForkLength(float forkLength) {
Expand All @@ -89,6 +90,7 @@ Fish::Fish(
travel(0),
status(FishStatus::Alive),
exitStatus(FishStatus::Alive),
numExitHabitatHours(0),
lastGrowth(0),
lastPmax(0),
lastMortality(0),
Expand Down Expand Up @@ -351,6 +353,9 @@ float Fish::getFitness(Model &model, MapNode &loc, float cost) {
return this->getGrowth(model, loc, cost) / this->getMortality(model, loc);
}

void Fish::incrementExitHabitatHoursByOneTimestep() {
this->numExitHabitatHours += HOURS_PER_TIMESTEP;
}

/*
* Perform the movement simulation for this fish
Expand Down Expand Up @@ -435,7 +440,6 @@ bool Fish::move(Model &model) {
break;
}
}
MapNode *oldLocation = this->location;
this->location = point;
this->travel = cost;

Expand All @@ -444,12 +448,16 @@ bool Fish::move(Model &model) {
this->locationHistory->push_back(this->location->id);
}

if (oldLocation->type == HabitatType::Nearshore && this->location->type == HabitatType::Nearshore) {
// Exit if at nearshore (TODO verify this behavior)
if (this->location->type == HabitatType::Nearshore) {
this->incrementExitHabitatHoursByOneTimestep();
} else {
this->numExitHabitatHours = 0;
}
if (this->numExitHabitatHours >= model.habitatTypeExitConditionHours) {
this->exit(model);
return false;
}

/*
// simplistic approach to exiting fish when they reach 75mm length or less than 30
if (this->forkLength >= 75 || this->forkLength < 30) {
Expand Down
5 changes: 5 additions & 0 deletions src/fish.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class Fish {
FishStatus status;
// status on model exit; only used for keeping track of fish replays
FishStatus exitStatus;
//number of hours currently spent in an exit habitat (Nearshore)
float numExitHabitatHours;
// last timestep's growth (g) and Pmax
float lastGrowth;
float lastPmax;
Expand Down Expand Up @@ -88,6 +90,9 @@ class Fish {
* probability of arriving at the location
*/
void getDestinationProbs(Model &model, std::unordered_map<MapNode *, float> &out);
// increment the number of hours in an exit habitat
void incrementExitHabitatHoursByOneTimestep();

/*
* Run this fish's movement update:
* Get all reachable nodes and their costs,
Expand Down
7 changes: 7 additions & 0 deletions src/model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
// default mortality constants
constexpr float MORT_CONST_C = 0.03096;
constexpr float MORT_CONST_A = -0.42;
constexpr float DEFAULT_EXIT_CONDITION_HOURS = 2.0;

/*
* Constructs a model instance from parameters and data filenames.
Expand Down Expand Up @@ -46,6 +47,7 @@ Model::Model(
std::string recSizeDistsFilename,
// List of map node IDs where new recruits enter the model
std::vector<unsigned> recPointIds,
float habitatTypeExitConditionHours,
// Path of the file containing map node descriptions (area, habitat type, elevation, among other columns)
std::string mapLocationFilename,
// Path of the file containing map edge descriptions (source and target nodes, path lengths, among other columns)
Expand Down Expand Up @@ -74,6 +76,7 @@ Model::Model(
exitedCount(0),
mortConstA(MORT_CONST_A),
mortConstC(MORT_CONST_C),
habitatTypeExitConditionHours(habitatTypeExitConditionHours),
nextFishID(0UL),
maxThreads(maxThreads),
recruitTagRate(0.5f)
Expand Down Expand Up @@ -127,6 +130,7 @@ Model::Model(
exitedCount(0),
mortConstA(MORT_CONST_A),
mortConstC(MORT_CONST_C),
habitatTypeExitConditionHours(DEFAULT_EXIT_CONDITION_HOURS),
nextFishID(0UL),
maxThreads(maxThreads),
recruitTagRate(0.5f)
Expand Down Expand Up @@ -1083,6 +1087,9 @@ Model *modelFromConfig(std::string configPath) {
std::string(d["recruitCountsFile"].GetString()),
std::string(d["recruitSizesFile"].GetString()),
recPoints,
d.HasMember("habitatTypeExitConditionHours")
? d["habitatTypeExitConditionHours"].GetFloat()
: DEFAULT_EXIT_CONDITION_HOURS,
std::string(d["mapNodesFile"].GetString()),
std::string(d["mapEdgesFile"].GetString()),
std::string(d["mapGeometryFile"].GetString()),
Expand Down
6 changes: 5 additions & 1 deletion src/model.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ class Model {
// Mortality constants overridden by ABC
float mortConstA;
float mortConstC;

// number of consecutive Nearshore hours to satisfy exit condition
float habitatTypeExitConditionHours;

Model(
int globalTimeIntercept,
int hydroTimeIntercept,
Expand All @@ -96,6 +100,7 @@ class Model {
std::string recCountFilename,
std::string recSizeDistsFilename,
std::vector<unsigned> recPointIds,
float habitatTypeExitConditionHours,
std::string mapLocationFilename,
std::string mapEdgeFilename,
std::string mapGeometryFilename,
Expand Down Expand Up @@ -171,7 +176,6 @@ class Model {
unsigned long nextFishID;
size_t maxThreads;
float recruitTagRate;

};
#define __FISH_MODEL_CLS

Expand Down

0 comments on commit 7e71692

Please sign in to comment.