Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make const for MASS_MIN; refactor to remove various warnings #8

Merged
merged 1 commit into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 16 additions & 17 deletions src/fish.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ const float CONS_Y = log(CQ) * (CTM - CTO + 2.0);
const float CONS_X = (pow(CONS_Z, 2.0) * pow(1.0 + sqrt(1.0 + 40/CONS_Y), 2.0))/400.0;

const float AVG_LOCAL_ABUNDANCE = 7.5839;
//const float MORT_CONST_C = 0.01939742; // old constant
// reparameterized:
const float MORT_CONST_C = 0.03096;
const float MORT_CONST_A = -0.42;

#define DEPTH_CUTOFF 0.2f

Expand Down Expand Up @@ -540,19 +536,20 @@ void Fish::dieStarvation(Model &model) {
this->exitTime = model.time;
}

float Fish::getPmax(const MapNode &loc) {
// ReSharper disable once CppMemberFunctionMayBeStatic
float Fish::getPmax(const MapNode &loc) { // NOLINT(*-convert-member-functions-to-static)
constexpr float SQ_METER_TO_HECTARE_CONVERSION = 10000.0;
constexpr float GROWTH_FACTOR = 0.0007;

constexpr float growth_factor = 0.0007;
constexpr float PMAX_MIN = 0.2;
constexpr float PMAX_MAX = 1.0;
float Pmax = 0.8f - ((loc.popDensity * SQ_METER_TO_HECTARE_CONVERSION) * GROWTH_FACTOR);

float Pmax = 0.8f - ((loc.popDensity * SQ_METER_TO_HECTARE_CONVERSION) * growth_factor);
constexpr float PMAX_MIN = 0.2;
if (Pmax < PMAX_MIN) {
Pmax = PMAX_MIN;
}
if (isNearshore(loc.type)) {
Pmax = PMAX_MAX;
constexpr float PMAX_NEARSHORE = 1.0;
Pmax = PMAX_NEARSHORE;
}
return Pmax;
}
Expand Down Expand Up @@ -635,19 +632,21 @@ bool Fish::growAndDie(Model &model) {
this->mortalityHistory->push_back(m);
}
this->mass = this->mass + g;

// Sample from bernoulli(m) to check if fish should die from mortality risk,
// and check to make sure fish hasn't reached a critically low mass
if (unit_rand() > m && this->mass > 0.381f) {
constexpr float MASS_MIN = 0.381;
if (unit_rand() > m && this->mass > MASS_MIN) {
this->forkLength = forkLengthFromMass(this->mass);
return true;
}

if (this->mass <= MASS_MIN) {
this->dieStarvation(model);
} else {
if (this->mass <= 0.381f) {
this->dieStarvation(model);
} else {
this->dieMortality(model);
}
return false;
this->dieMortality(model);
}
return false;
}

void Fish::addHistoryBuffers() {
Expand Down
2 changes: 1 addition & 1 deletion src/fish.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class Fish {
// Register this fish as dead due to starvation
void dieStarvation(Model &model);

static float getPmax(const MapNode &loc);
float getPmax(const MapNode &loc);
// Compute the growth (g) for a given location and movement cost (meters swum) and pmax
float getGrowth(Model &model, MapNode &loc, float cost, float pmax);
// compute growth, pmax calculated internally
Expand Down
19 changes: 10 additions & 9 deletions src/model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
#include <iostream>

// default mortality constants
const float MORT_CONST_C = 0.03096;
const float MORT_CONST_A = -0.42;
constexpr float MORT_CONST_C = 0.03096;
constexpr float MORT_CONST_A = -0.42;

/*
* Constructs a model instance from parameters and data filenames.
Expand Down Expand Up @@ -72,11 +72,11 @@ Model::Model(
time(0UL),
deadCount(0),
exitedCount(0),
mortConstA(MORT_CONST_A),
mortConstC(MORT_CONST_C),
nextFishID(0UL),
maxThreads(maxThreads),
recruitTagRate(0.5f),
mortConstA(MORT_CONST_A),
mortConstC(MORT_CONST_C)
recruitTagRate(0.5f)
{
// Load the map
loadMap(
Expand Down Expand Up @@ -116,19 +116,20 @@ Model::Model(
float distFlow
) : map(map),
hydroModel(map, depths, temps, distFlow),
recCounts(recCounts), recSizeDists(recSizeDists),
recCounts(recCounts),
recSizeDists(recSizeDists),
recPoints(recPoints),
recTimeIntercept(0),
globalTimeIntercept(0),
firstHighTide(false),
time(0UL),
deadCount(0),
exitedCount(0),
mortConstA(MORT_CONST_A),
mortConstC(MORT_CONST_C),
nextFishID(0UL),
maxThreads(maxThreads),
recruitTagRate(0.5f),
mortConstA(MORT_CONST_A),
mortConstC(MORT_CONST_C)
recruitTagRate(0.5f)
{
// Make room in the recruit plan vector (per-timestep recruit counts for the current day)
this->recDayPlan.resize(24, 0UL);
Expand Down
Loading