From b7b6bc4c0368834769d4605e96bea5fa68af81b7 Mon Sep 17 00:00:00 2001 From: hmorzaria Date: Sun, 6 Sep 2026 02:45:19 +0000 Subject: [PATCH 1/7] Fixed timing issue with contaminant transfer --- .RData | Bin 0 -> 717 bytes .Rhistory | 136 ++++++++++++++++++++++++++ atlantis/atecology/atContaminants.c | 129 +++++++++++++++++++----- atlantis/atecology/atGroupProcesses.c | 4 + atlantis/atecology/atprocess.c | 10 +- atlantis/atlantisUtil/atUtilGroupIO.c | 5 +- atlantis/outamps | 1 + 7 files changed, 252 insertions(+), 33 deletions(-) create mode 100644 .RData create mode 100644 .Rhistory create mode 100644 atlantis/outamps diff --git a/.RData b/.RData new file mode 100644 index 0000000000000000000000000000000000000000..4ca4a59150b9aab40c403cd99157aae80b0d29ba GIT binary patch literal 717 zcmb7C+fKqj5M882!Rtr(YD;6H_#^`9qalb1Z_Prdm$2=Y-7SH?^i%u-*ggojGTBC!^VYXVxKvG>Kt0Nz+6~%=f8#*CWI@!Jt75(#G{{9wuH8GeCTEkaz8f zCty>>XsTjqzf@o<@^rb6yzy}0I6ZruhoIhgp88(zY3_9&yN>f3!HRS zOnd&sZ)qAU(~486FkfhBp*Mba?WgmEZd9CrRFGkL*}uR3Kvo5!hE*AKB iG;-IwqX-17a!40jq`13{TSTR4<+T=CXgPWologFile, "\n=== DEBUG_INITIAL_CONCENTRATIONS ===\n"); + fprintf(bm->logFile, "Time: %e, Habitat: %d, Box: %d, Layer: %d\n", bm->dayt, habitat, bm->current_box, bm->current_layer); + + if (habitat == EPIFAUNA) { + tracerArray = getTracerArray(boxLayerInfo, WC); + } else { + tracerArray = getTracerArray(boxLayerInfo, habitat); + } + + /* Log all Macroalgae concentrations */ + for (sp = 0; sp < bm->K_num_tot_sp; sp++) { + if (strstr(FunctGroupArray[sp].groupCode, "MA") != NULL) { + if ((FunctGroupArray[sp].speciesParams[flag_id] == TRUE) && (FunctGroupArray[sp].habitatCoeffs[habitat] > 0)) { + for (cIndex = 0; cIndex < bm->num_contaminants; cIndex++) { + for (cohort = 0; cohort < FunctGroupArray[sp].numCohortsXnumGenes; cohort++) { + cGroupLevel = tracerArray[FunctGroupArray[sp].contaminantTracers[cohort][cIndex]]; + fprintf(bm->logFile, "DEBUG_INIT_CONC: %s-%d, %s, cGroupLevel=%e, tracerID=%d\n", + FunctGroupArray[sp].groupCode, cohort, bm->contaminantStructure[cIndex]->contaminant_name, + cGroupLevel, FunctGroupArray[sp].contaminantTracers[cohort][cIndex]); + } + } + } + } + } + fprintf(bm->logFile, "=== END DEBUG_INITIAL_CONCENTRATIONS ===\n\n"); +} + /** * Free up the contaminant structure. * @@ -422,10 +459,16 @@ void Move_Vert_Contaminated(MSEBoxModel *bm, int sp, int cohort, double ****this */ void Change_Contaminant_Levels(MSEBoxModel *bm, BoxLayerValues *boxLayerInfo, HABITAT_TYPES habitat, double dtsz, int offset) { - int cIndex; + int cIndex, sp, cohort; double cLevel; double *tracerArray = getTracerArray(boxLayerInfo, habitat); + /* DEBUG: Log when contaminant processing happens */ + if (bm->dayt < 2.0 && habitat == WC) { + fprintf(bm->logFile, "DEBUG_TIMING: Change_Contaminant_Levels START for habitat WC at time=%e\n", bm->dayt); + } + + for (cIndex = 0; cIndex < bm->num_contaminants; cIndex++) { /* Grab the level in the water column or the sediment */ cLevel = tracerArray[bm->contaminantStructure[cIndex]->contaminant_tracer]; @@ -436,6 +479,11 @@ void Change_Contaminant_Levels(MSEBoxModel *bm, BoxLayerValues *boxLayerInfo, HA } Calculate_Contaminants_Flux(bm, boxLayerInfo, habitat); + /* DEBUG: Log when contaminant processing ends */ + if (bm->dayt < 2.0 && habitat == WC) { + fprintf(bm->logFile, "DEBUG_TIMING: Change_Contaminant_Levels END for habitat WC at time=%e\n", bm->dayt); + } + return; } @@ -742,32 +790,46 @@ int Species_Contaminant_Uptake(MSEBoxModel *bm, BoxLayerValues *boxLayerInfo, HA int sp, pid, cohort = 0; double cLevel = 0, uptake_rate = 0, cUptake = 0, cGroupLevel = 0, Cnew = 0, propLevel = 0, avoidLevel = 0, chronicLevel = 0, testLevel = 0, propContam = 0, time_step = 0; - double *tracerArray; + double *environmentTracerArray, *organismTracerArray; CONTAMINANT_UPTAKE_OPTION uptake_option; + /* For EPIFAUNA groups: environmental concentration comes from WC, but organism concentration lives in EPIFAUNA */ if (habitat == EPIFAUNA) { - tracerArray = getTracerArray(boxLayerInfo, WC); + environmentTracerArray = getTracerArray(boxLayerInfo, WC); /* Water column concentration (forced from outside) */ + organismTracerArray = getTracerArray(boxLayerInfo, EPIFAUNA); /* Organism concentration in EPIFAUNA */ } else { - tracerArray = getTracerArray(boxLayerInfo, habitat); + /* For other habitats, both come from the same habitat */ + environmentTracerArray = getTracerArray(boxLayerInfo, habitat); + organismTracerArray = getTracerArray(boxLayerInfo, habitat); } + /* For each contaminant calculate the uptake */ - /* Grab the level in the water column or the sediment */ - cLevel = tracerArray[bm->contaminantStructure[cIndex]->contaminant_tracer]; + /* Grab the level in the water column or the sediment (environmental concentration) */ + cLevel = environmentTracerArray[bm->contaminantStructure[cIndex]->contaminant_tracer]; + if(cLevel > bm->min_pool_cont){ //fprintf(bm->logFile, "time %e, box %d, layer %d, cLevel = %e\n", bm->dayt, bm->current_box, bm->current_layer, cLevel); for (sp = 0; sp < bm->K_num_tot_sp; sp++) { /* Contact can occur for all active groups that are present in this habitat */ if ((FunctGroupArray[sp].speciesParams[flag_id] == TRUE) && (FunctGroupArray[sp].isDetritus == FALSE) && (FunctGroupArray[sp].habitatCoeffs[habitat] > 0)) { - + uptake_option = (CONTAMINANT_UPTAKE_OPTION)bm->contaminantStructure[cIndex]->sp_uptake_option[sp]; uptake_rate = bm->contaminantStructure[cIndex]->sp_uptake_rate[sp]; for(cohort = 0; cohort < FunctGroupArray[sp].numCohortsXnumGenes; cohort++){ - /* The current concentration in the group */ - cGroupLevel = tracerArray[FunctGroupArray[sp].contaminantTracers[cohort][cIndex]]; + int h; + /* The current concentration in the group (from organism's habitat) */ + cGroupLevel = organismTracerArray[FunctGroupArray[sp].contaminantTracers[cohort][cIndex]]; + /* Add any transfers from this timestep that haven't been integrated into tracer yet */ + /* sp_transfer is indexed by prey habitat, not predator habitat, so sum across all habitats */ + for (h = 0; h < bm->num_active_habitats; h++) { + if (bm->contaminantStructure[cIndex]->sp_transfer[sp][cohort][h] > 0) { + cGroupLevel += bm->contaminantStructure[cIndex]->sp_transfer[sp][cohort][h]; + } + } cUptake = 0; switch (uptake_option) { @@ -791,12 +853,12 @@ int Species_Contaminant_Uptake(MSEBoxModel *bm, BoxLayerValues *boxLayerInfo, HA } if ((time_step > 0) && (uptake_rate > 0)) { - /* Have the calculate the actual new tracer value and from this we calculate the flux values + /* Have the calculate the actual new tracer value and from this we calculate the flux values contam_sig_uptake_const set to 0.99 by default */ - + //fprintf(bm->logFile,"Time: %e box %d-%d contam_sig_uptake_const: %e\n", bm->dayt, bm->current_box, bm->current_layer, bm->contam_sig_uptake_const); - + Cnew = pow((pow(cLevel,(1.0 - bm->contam_sig_uptake_const))- (pow(cLevel,(1.0 - bm->contam_sig_uptake_const)) - pow(cGroupLevel, (1.0 - bm->contam_sig_uptake_const))) * exp(-uptake_rate * time_step * (bm->contam_sig_uptake_const + 1.0))),(1.0 / (1.0 - bm->contam_sig_uptake_const))); cUptake = (Cnew - cGroupLevel) / time_step; //cUptake = 0; @@ -830,9 +892,9 @@ int Species_Contaminant_Uptake(MSEBoxModel *bm, BoxLayerValues *boxLayerInfo, HA break; } - + //fprintf(bm->logFile,"Time: %e box%d-%d %s-%d vs %s has uptake_option: %d cUptake: %e uptake_rate: %e cLevel: %e\n", bm->dayt, bm->current_box, bm->current_layer, FunctGroupArray[sp].groupCode, cohort, bm->contaminantStructure[cIndex]->contaminant_name, uptake_option, cUptake, uptake_rate, cLevel); - + bm->contaminantStructure[cIndex]->sp_uptake[sp][cohort][habitat] = cUptake; // Initiate exposure time @@ -940,7 +1002,7 @@ int Init_Contaminant_Transfer_Values(MSEBoxModel *bm) { int Group_Transfer_Contaminant(MSEBoxModel *bm, BoxLayerValues *boxLayerInfo, HABITAT_TYPES globalHabitat, HABITAT_TYPES habitat, int toGuild, int toCohort, int fromGuild, int fromCohort, double amountTransfer, double ***spSPinfo, double initialBiomass, double dtsz, int need_prop, int caseGTC) { int cIndex, pid, this_habitat; - double *tracerArray; + double *preyTracerArray, *predatorTracerArray; double cGroupLevel = 0, transfer = 0, totalBiomass, amt_exchanged, toGuild_totalBiomass = 0.0, prop_exchanged, propContam, min_num, this_num; int isGlobal = (FunctGroupArray[toGuild].diagTol == 2 && it_count == 1); @@ -949,15 +1011,22 @@ int Group_Transfer_Contaminant(MSEBoxModel *bm, BoxLayerValues *boxLayerInfo, HA */ if (amountTransfer == 0.0) return 0; - + if(isnan(dtsz)){ quit("Group_Transfer_Contaminant - from group %s-%d, to group %s-%d, dtsz: %e\n", FunctGroupArray[fromGuild].groupCode, fromCohort, FunctGroupArray[toGuild].groupCode, toCohort, dtsz); } + /* Get tracer arrays - separate for prey and predator since they may be in different habitats */ if(FunctGroupArray[fromGuild].habitatType == EPIFAUNA){ - tracerArray = getTracerArray(boxLayerInfo, EPIFAUNA); + preyTracerArray = getTracerArray(boxLayerInfo, EPIFAUNA); + } else { + preyTracerArray = getTracerArray(boxLayerInfo, habitat); + } + + if(FunctGroupArray[toGuild].habitatType == EPIFAUNA){ + predatorTracerArray = getTracerArray(boxLayerInfo, EPIFAUNA); } else { - tracerArray = getTracerArray(boxLayerInfo, habitat); + predatorTracerArray = getTracerArray(boxLayerInfo, habitat); } /* Work out the proportion transfered */ @@ -994,8 +1063,8 @@ int Group_Transfer_Contaminant(MSEBoxModel *bm, BoxLayerValues *boxLayerInfo, HA quit("Time: %e %s-%d returning nan biomass in box%d-%d for Group_Transfer_Contaminant - SN: %e RN: %e DEN: %e cell_vol: %e\n", bm->dayt, FunctGroupArray[toGuild].groupCode, toCohort, bm->current_box, bm->current_layer, spSPinfo[toGuild][toCohort][SN_id], spSPinfo[toGuild][toCohort][RN_id], spSPinfo[toGuild][toCohort][DEN_id], bm->cell_vol); } } else { - toGuild_totalBiomass = tracerArray[FunctGroupArray[toGuild].totNTracers[toCohort]]; - + toGuild_totalBiomass = predatorTracerArray[FunctGroupArray[toGuild].totNTracers[toCohort]]; + if(isnan(toGuild_totalBiomass)) { quit("Time: %e %s-%d returning nan biomass in box%d-%d for Group_Transfer_Contaminant\n", bm->dayt, FunctGroupArray[toGuild].groupCode, toCohort, bm->current_box, bm->current_layer); } @@ -1004,9 +1073,10 @@ int Group_Transfer_Contaminant(MSEBoxModel *bm, BoxLayerValues *boxLayerInfo, HA for (cIndex = 0; cIndex < bm->num_contaminants; cIndex++) { - /* The current concentration in the group */ - cGroupLevel = tracerArray[FunctGroupArray[fromGuild].contaminantTracers[fromCohort][cIndex]]; + /* The current concentration in the prey */ + cGroupLevel = preyTracerArray[FunctGroupArray[fromGuild].contaminantTracers[fromCohort][cIndex]]; + /* DEBUG: Log feeding with timestamps */ /* This used to have an if-else statement using the test (cGroupLevel > bm->min_pool) but removed so got sediment transferal and accumualtion even if low amounts Use of Contamflag means it won't get reset in Integrate_Tracer_Variables() */ @@ -1032,6 +1102,19 @@ int Group_Transfer_Contaminant(MSEBoxModel *bm, BoxLayerValues *boxLayerInfo, HA bm->contaminantStructure[cIndex]->sp_transfer[toGuild][toCohort][habitat] += transfer; bm->contaminantStructure[cIndex]->sp_transfer[fromGuild][fromCohort][habitat] -= transfer; + /* CRITICAL FIX: Apply transfer immediately to tracer arrays so predators see updated concentrations */ + /* This ensures BIV sees BB's contaminants immediately after eating, not one timestep later */ + /* Validate tracer indices before accessing to prevent out-of-bounds access */ + int toGuild_tracer_idx = FunctGroupArray[toGuild].contaminantTracers[toCohort][cIndex]; + int fromGuild_tracer_idx = FunctGroupArray[fromGuild].contaminantTracers[fromCohort][cIndex]; + + if (toGuild_tracer_idx >= 0 && toGuild_tracer_idx < bm->ntracer) { + predatorTracerArray[toGuild_tracer_idx] += transfer; + } + if (fromGuild_tracer_idx >= 0 && fromGuild_tracer_idx < bm->ntracer) { + preyTracerArray[fromGuild_tracer_idx] -= transfer; + } + /** //if((((toGuild == 54) || (fromGuild == 54)) && (bm->contaminantStructure[cIndex]->sp_transfer[toGuild][toCohort][habitat] > 0.0)) && (cIndex == 3)) { fprintf(bm->logFile, "prey = %s, to %s-%d gaining %e, cGroupLevel= %e, propTransfer= %e, totalTransfer = %e amountTransfer = %e, totalBiomass= %e\n", FunctGroupArray[fromGuild].groupCode, FunctGroupArray[toGuild].groupCode, toCohort, transfer, cGroupLevel, propTransfer, bm->contaminantStructure[cIndex]->sp_transfer[toGuild][toCohort][habitat], amountTransfer, totalBiomass); @@ -1055,7 +1138,7 @@ int Group_Transfer_Contaminant(MSEBoxModel *bm, BoxLayerValues *boxLayerInfo, HA min_num = 0.0; if(FunctGroupArray[toGuild].groupAgeType == AGE_STRUCTURED ){ - this_num = tracerArray[FunctGroupArray[toGuild].NumsTracers[toCohort]]; + this_num = predatorTracerArray[FunctGroupArray[toGuild].NumsTracers[toCohort]]; min_num = 1.0 / (this_num + small_num); } else { min_num = bm->min_pool_cont; // Just using this as a proxy for a small number here diff --git a/atlantis/atecology/atGroupProcesses.c b/atlantis/atecology/atGroupProcesses.c index 3984b93..04eb040 100644 --- a/atlantis/atecology/atGroupProcesses.c +++ b/atlantis/atecology/atGroupProcesses.c @@ -158,6 +158,10 @@ static void Update_Detritus(MSEBoxModel *bm, BoxLayerValues *boxLayerInfo, HABIT //fprintf(bm->logFile,"Calling Group_Transfer_Contaminant from Update_Detritus WC WC - %s-%d with initialBiomass: %e prodnDR: %e prodnDL: %e\n", FunctGroupArray[guild].groupCode, cohort, initialBiomass, FunctGroupArray[guild].prodnDR[cohort], FunctGroupArray[guild].prodnDL[cohort]); Group_Transfer_Contaminant(bm, boxLayerInfo, WC, WC, RefDetIndex, 0, guild, cohort, FunctGroupArray[guild].prodnDR[cohort], 0, initialBiomass, bm->dtsz_stored, 0, 0); Group_Transfer_Contaminant(bm, boxLayerInfo, WC, WC, LabDetIndex, 0, guild, cohort, FunctGroupArray[guild].prodnDL[cohort] + FunctGroupArray[guild].lysis[cohort], 0, initialBiomass, bm->dtsz_stored, 0, 1); + /* Transfer contaminants to CARRION (dead organic matter) from total mortality */ + /* Use total detritus production (DL + DR) as the mortality amount */ + double totalMortality = FunctGroupArray[guild].prodnDL[cohort] + FunctGroupArray[guild].prodnDR[cohort]; + Group_Transfer_Contaminant(bm, boxLayerInfo, WC, WC, CarrionIndex, 0, guild, cohort, totalMortality, 0, initialBiomass, bm->dtsz_stored, 0, 2); /* Release contaminants back into the water column */ //fprintf(bm->logFile,"Calling Gain_Contaminants from Update_Detritus WC WC - %s-%d with initialBiomass: %e releaseNH: %e\n", FunctGroupArray[guild].groupCode, cohort, initialBiomass, FunctGroupArray[guild].releaseNH[cohort]); diff --git a/atlantis/atecology/atprocess.c b/atlantis/atecology/atprocess.c index f347481..e063a43 100755 --- a/atlantis/atecology/atprocess.c +++ b/atlantis/atecology/atprocess.c @@ -2262,15 +2262,11 @@ void UpdateTrackedMort(MSEBoxModel *bm, FILE *llogfp, int guildcase, int cohort, } if(bm->track_contaminants){ - - //fprintf(llogfp, "Time: %e box %d-%d %s-%d eaten by %s-%d habitat %d GRAZEinfo: %e scalar: %e EATINGinfo: %e\n", bm->dayt, bm->current_box, bm->current_layer, FunctGroupArray[prey].groupCode, prey_chrt, FunctGroupArray[guildcase].groupCode, cohort, habitat, GRAZEinfo[prey][prey_chrt][habitat], scalar, EATINGinfo[prey][prey_chrt][habitat]); - + if(FunctGroupArray[guildcase].isOncePerDt == TRUE) { - - Group_Transfer_Contaminant(bm, boxLayerInfo, habitat, habitat, guildcase, cohort, prey, prey_chrt, (GRAZEinfo[prey][prey_chrt][habitat] * scalar), VERTinfo, EATINGinfo[prey][prey_chrt][habitat], bm->dtsz_stored, 1, 31); + Group_Transfer_Contaminant(bm, boxLayerInfo, level_id, habitat, guildcase, cohort, prey, prey_chrt, (GRAZEinfo[prey][prey_chrt][habitat] * scalar), VERTinfo, EATINGinfo[prey][prey_chrt][habitat], bm->dtsz_stored, 1, 31); } else { - - Group_Transfer_Contaminant(bm, boxLayerInfo, habitat, habitat, guildcase, cohort, prey, prey_chrt, (GRAZEinfo[prey][prey_chrt][habitat] * scalar), VERTinfo, EATINGinfo[prey][prey_chrt][habitat], bm->dt, 1, 32); + Group_Transfer_Contaminant(bm, boxLayerInfo, level_id, habitat, guildcase, cohort, prey, prey_chrt, (GRAZEinfo[prey][prey_chrt][habitat] * scalar), VERTinfo, EATINGinfo[prey][prey_chrt][habitat], bm->dt, 1, 32); } } diff --git a/atlantis/atlantisUtil/atUtilGroupIO.c b/atlantis/atlantisUtil/atUtilGroupIO.c index 8e860bb..cfcfa13 100755 --- a/atlantis/atlantisUtil/atUtilGroupIO.c +++ b/atlantis/atlantisUtil/atUtilGroupIO.c @@ -664,16 +664,15 @@ int Util_Read_Functional_Group_XML(MSEBoxModel *bm, char *fileName, FILE *llogfp FunctGroupArray[guild].diagTol = 2; } else { if (FunctGroupArray[guild].groupType == CARRION) - FunctGroupArray[guild].diagTol = 3; + FunctGroupArray[guild].diagTol = 1; // Changed from 3 to 1 so CARRION can process multiple times per timestep for contaminant accumulation else if (FunctGroupArray[guild].groupType == SED_EP_OTHER || FunctGroupArray[guild].groupType == MOB_EP_OTHER || - FunctGroupArray[guild].groupType == PWN || FunctGroupArray[guild].groupType == CEP || FunctGroupArray[guild].groupType == LG_ZOO || FunctGroupArray[guild].groupType == LG_INF) FunctGroupArray[guild].diagTol = 2; else { - FunctGroupArray[guild].diagTol = 1; // So all phytoplankton, small zooplankton and filter feeders set the adaptive time step + FunctGroupArray[guild].diagTol = 1; // So all phytoplankton, small zooplankton, filter feeders, and PWN set the adaptive time step to allow multiple feeding/uptake cycles if(FunctGroupArray[guild].isCultured) // Except if an aquaculture species then just have it inflicted upon them FunctGroupArray[guild].diagTol = 0; } diff --git a/atlantis/outamps b/atlantis/outamps new file mode 100644 index 0000000..a85bc93 --- /dev/null +++ b/atlantis/outamps @@ -0,0 +1 @@ +bash: cd: too many arguments From 2b537e2493d10c09c0e99c022d306497fc011aea Mon Sep 17 00:00:00 2001 From: hmorzaria Date: Sun, 6 Sep 2026 17:47:10 +0000 Subject: [PATCH 2/7] eliminated debugging function Debug_Log_Initial_Concentrations --- atlantis/atecology/atContaminants.c | 37 ----------------------------- 1 file changed, 37 deletions(-) diff --git a/atlantis/atecology/atContaminants.c b/atlantis/atecology/atContaminants.c index 6d4f798..027d17c 100644 --- a/atlantis/atecology/atContaminants.c +++ b/atlantis/atecology/atContaminants.c @@ -36,44 +36,7 @@ static FILE *contaminantContactFile; * Debug function: Track initial contaminant concentrations in organisms at simulation start * Call this once at the very beginning of the simulation */ -void Debug_Log_Initial_Concentrations(MSEBoxModel *bm, BoxLayerValues *boxLayerInfo, HABITAT_TYPES habitat) { - int sp, cohort, cIndex, box, layer; - double cGroupLevel = 0; - double *tracerArray; - - fprintf(bm->logFile, "\n=== DEBUG_INITIAL_CONCENTRATIONS ===\n"); - fprintf(bm->logFile, "Time: %e, Habitat: %d, Box: %d, Layer: %d\n", bm->dayt, habitat, bm->current_box, bm->current_layer); - - if (habitat == EPIFAUNA) { - tracerArray = getTracerArray(boxLayerInfo, WC); - } else { - tracerArray = getTracerArray(boxLayerInfo, habitat); - } - /* Log all Macroalgae concentrations */ - for (sp = 0; sp < bm->K_num_tot_sp; sp++) { - if (strstr(FunctGroupArray[sp].groupCode, "MA") != NULL) { - if ((FunctGroupArray[sp].speciesParams[flag_id] == TRUE) && (FunctGroupArray[sp].habitatCoeffs[habitat] > 0)) { - for (cIndex = 0; cIndex < bm->num_contaminants; cIndex++) { - for (cohort = 0; cohort < FunctGroupArray[sp].numCohortsXnumGenes; cohort++) { - cGroupLevel = tracerArray[FunctGroupArray[sp].contaminantTracers[cohort][cIndex]]; - fprintf(bm->logFile, "DEBUG_INIT_CONC: %s-%d, %s, cGroupLevel=%e, tracerID=%d\n", - FunctGroupArray[sp].groupCode, cohort, bm->contaminantStructure[cIndex]->contaminant_name, - cGroupLevel, FunctGroupArray[sp].contaminantTracers[cohort][cIndex]); - } - } - } - } - } - fprintf(bm->logFile, "=== END DEBUG_INITIAL_CONCENTRATIONS ===\n\n"); -} - -/** - * Free up the contaminant structure. - * - * - * - */ void Free_Contaminants(MSEBoxModel *bm) { int cIndex; From dc73474065cd6f3033a78eff913344181e82acb7 Mon Sep 17 00:00:00 2001 From: hmorzaria Date: Sun, 6 Sep 2026 21:21:51 +0000 Subject: [PATCH 3/7] Commented remaining debug statements --- atlantis/atecology/atContaminants.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/atlantis/atecology/atContaminants.c b/atlantis/atecology/atContaminants.c index 027d17c..bd70cb1 100644 --- a/atlantis/atecology/atContaminants.c +++ b/atlantis/atecology/atContaminants.c @@ -32,10 +32,6 @@ static FILE *contaminantContactFile; -/** - * Debug function: Track initial contaminant concentrations in organisms at simulation start - * Call this once at the very beginning of the simulation - */ void Free_Contaminants(MSEBoxModel *bm) { int cIndex; @@ -426,11 +422,10 @@ void Change_Contaminant_Levels(MSEBoxModel *bm, BoxLayerValues *boxLayerInfo, HA double cLevel; double *tracerArray = getTracerArray(boxLayerInfo, habitat); - /* DEBUG: Log when contaminant processing happens */ + /* DEBUG: Log when contaminant processing happens if (bm->dayt < 2.0 && habitat == WC) { fprintf(bm->logFile, "DEBUG_TIMING: Change_Contaminant_Levels START for habitat WC at time=%e\n", bm->dayt); - } - + } */ for (cIndex = 0; cIndex < bm->num_contaminants; cIndex++) { /* Grab the level in the water column or the sediment */ @@ -442,10 +437,10 @@ void Change_Contaminant_Levels(MSEBoxModel *bm, BoxLayerValues *boxLayerInfo, HA } Calculate_Contaminants_Flux(bm, boxLayerInfo, habitat); - /* DEBUG: Log when contaminant processing ends */ + /* DEBUG: Log when contaminant processing ends if (bm->dayt < 2.0 && habitat == WC) { fprintf(bm->logFile, "DEBUG_TIMING: Change_Contaminant_Levels END for habitat WC at time=%e\n", bm->dayt); - } + } */ return; } From 7471bad83a398ad6bef2046bf440e3e960e5f77b Mon Sep 17 00:00:00 2001 From: hmorzaria Date: Sun, 6 Sep 2026 21:26:26 +0000 Subject: [PATCH 4/7] Cleaned comments --- atlantis/atecology/atContaminants.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/atlantis/atecology/atContaminants.c b/atlantis/atecology/atContaminants.c index bd70cb1..4e12e32 100644 --- a/atlantis/atecology/atContaminants.c +++ b/atlantis/atecology/atContaminants.c @@ -1061,7 +1061,7 @@ int Group_Transfer_Contaminant(MSEBoxModel *bm, BoxLayerValues *boxLayerInfo, HA bm->contaminantStructure[cIndex]->sp_transfer[fromGuild][fromCohort][habitat] -= transfer; /* CRITICAL FIX: Apply transfer immediately to tracer arrays so predators see updated concentrations */ - /* This ensures BIV sees BB's contaminants immediately after eating, not one timestep later */ + /* This ensures inverts see prey contaminants immediately after eating, not one timestep later */ /* Validate tracer indices before accessing to prevent out-of-bounds access */ int toGuild_tracer_idx = FunctGroupArray[toGuild].contaminantTracers[toCohort][cIndex]; int fromGuild_tracer_idx = FunctGroupArray[fromGuild].contaminantTracers[fromCohort][cIndex]; From 11ef963548b1907a4434b879dda8fcf7fc970cad Mon Sep 17 00:00:00 2001 From: Hem Nalini Morzaria-Luna Date: Tue, 22 Sep 2026 16:45:10 -0700 Subject: [PATCH 5/7] Delete .Rhistory --- .Rhistory | 136 ------------------------------------------------------ 1 file changed, 136 deletions(-) delete mode 100644 .Rhistory diff --git a/.Rhistory b/.Rhistory deleted file mode 100644 index 198e635..0000000 --- a/.Rhistory +++ /dev/null @@ -1,136 +0,0 @@ -rm(list = ls()) # clear memory -library("devtools") -library("ReactiveAtlantis") -library("proj4") -library("here") -####### Compare outputs and Biomass visualization ####### -nc.current <- here::here("example","outputFolder_original","outputSETAS.nc") -nc.old <- here::here("example","outputFolder_mum","outputSETAS.nc") -grp.csv <- 'SETasGroupsDem.csv' -bgm.file <- 'VMPA_setas.bgm' -cum.depths <- c(0,20,50,100,250,700,2000) ## This should be the cummulative depth of your model -## individual file -compare(nc.current, nc.out.old = NULL, grp.csv, bgm.file, cum.depths) -grp.csv <- here::here("example","SETasGroupsDem.csv") -bgm.file <- here::here("example","VMPA_setas.bgm") -cum.depths <- c(0,20,50,100,250,700,2000) ## This should be the cummulative depth of your model -## individual file -compare(nc.current, nc.out.old = NULL, grp.csv, bgm.file, cum.depths) -## compare to previous run -compare(nc.current, nc.old, grp.csv, bgm.file, cum.depths) -biom <- here::here("example","outputFolder_original","outputSETASBiomIndx.txt") -diet.file <- here::here("example","outputFolder_original","outputSETASDietCheck.txt") -bio.age <- here::here("example","outputFolder_original","outputSETASAgeBiomIndx.txt") ## optional file. just if you want to check the predation by age -grp.csv <- here::here("example","SETasGroupsDem.csv") -## Predation by Age -predation(biom, grp.csv, diet.file, bio.age) -## No predation by Age -predation(biom, grp.csv, diet.file, bio.age = NULL) -prm.file <- here::here("example","outputFolder_original","VMPA_setas_biol_fishing_Trunk.prm") -nc.initial <- here::here("example","outputFolder_original","INIT_VMPA_Jan2015.nc") -grp.csv <- here::here("example","SETasGroupsDem.csv") -bgm.file <- here::here("example","VMPA_setas.bgm") -cum.depths <- c(0,20,50,100,250,700,2000) ## This should be the cummulative depth of your model -feeding.mat(prm.file, grp.csv, nc.initial, bgm.file, cum.depths) -prm.file <- here::here("example","VMPA_setas_biol_fishing_Trunk.prm") -nc.initial <- here::here("example","INIT_VMPA_Jan2015.nc") -grp.csv <- here::here("example","SETasGroupsDem.csv") -bgm.file <- here::here("example","VMPA_setas.bgm") -cum.depths <- c(0,20,50,100,250,700,2000) ## This should be the cummulative depth of your model -feeding.mat(prm.file, grp.csv, nc.initial, bgm.file, cum.depths) -grp.csv <- here::here("example","SETasGroupsDem.csv") -prm.file <- here::here("example","VMPA_setas_biol_fishing_Trunk.prm") -diet.file <- here::here("example","outputFolder_original","outputSETASDietCheck.txt") -food.web(diet.file, grp.csv) -## optional you can explore the food web by polygon -food.web(diet.file, grp.file, diet.file.bypol) -food.web(diet.file, grp.csv) -nc.initial <- here::here("example","INIT_VMPA_Jan2015.nc") -nc.current <- here::here("example","outputFolder_original","outputSETAS.nc") -grp.csv <- here::here("example","SETasGroupsDem.csv") -prm.file <- here::here("example","VMPA_setas_biol_fishing_Trunk.prm") -growth.pp(nc.initial, grp.csv, prm.file, nc.current) -rm(list = ls()) # clear memory -library("devtools") -library("ReactiveAtlantis") -library("proj4") -library("here") -####### Compare outputs and Biomass visualization ####### -nc.current <- here::here("example","outputFolder_original","outputSETAS.nc") -nc.old <- here::here("example","outputFolder_mum","outputSETAS.nc") -grp.csv <- here::here("example","SETasGroupsDem.csv") -bgm.file <- here::here("example","VMPA_setas.bgm") -cum.depths <- c(0,20,50,100,250,700,2000) ## This should be the cummulative depth of your model -## individual file -compare(nc.current, nc.out.old = NULL, grp.csv, bgm.file, cum.depths) -## compare to previous run -compare(nc.current, nc.old, grp.csv, bgm.file, cum.depths) -####### Predation analysis from the Atlantis output ####### -biom <- here::here("example","outputFolder_original","outputSETASBiomIndx.txt") -diet.file <- here::here("example","outputFolder_original","outputSETASDietCheck.txt") -bio.age <- here::here("example","outputFolder_original","outputSETASAgeBiomIndx.txt") ## optional file. just if you want to check the predation by age -grp.csv <- here::here("example","SETasGroupsDem.csv") -## Predation by Age -predation(biom, grp.csv, diet.file, bio.age) -## No predation by Age -predation(biom, grp.csv, diet.file, bio.age = NULL) -prm.file <- here::here("example","VMPA_setas_biol_fishing_Trunk.prm") -nc.initial <- here::here("example","INIT_VMPA_Jan2015.nc") -grp.csv <- here::here("example","SETasGroupsDem.csv") -bgm.file <- here::here("example","VMPA_setas.bgm") -cum.depths <- c(0,20,50,100,250,700,2000) ## This should be the cummulative depth of your model -feeding.mat(prm.file, grp.csv, nc.initial, bgm.file, cum.depths) -feeding.mat(prm.file, grp.csv, nc.initial, bgm.file, cum.depths) -grp.csv <- here::here("example","SETasGroupsDem.csv") -prm.file <- here::here("example","VMPA_setas_biol_fishing_Trunk.prm") -diet.file <- here::here("example","outputFolder_original","outputSETASDietCheck.txt") -food.web(diet.file, grp.csv) -nc.initial <- here::here("example","INIT_VMPA_Jan2015.nc") -nc.current <- here::here("example","outputFolder_original","outputSETAS.nc") -grp.csv <- here::here("example","SETasGroupsDem.csv") -prm.file <- here::here("example","VMPA_setas_biol_fishing_Trunk.prm") -growth.pp(nc.initial, grp.csv, prm.file, nc.current) -# -nc.initial <- here::here("example","INIT_VMPA_Jan2015.nc") -nc.current <- here::here("example","outputFolder_original","outputSETAS.nc") -yoy.file <- here::here("example","outputFolder_original","outputSETASYOY.txt") -grp.csv <- here::here("example","SETasGroupsDem.csv") -prm.file <- here::here("example","VMPA_setas_biol_fishing_Trunk.prm") -recruitment.cal(nc.initial, nc.current, yoy.file, grp.csv, prm.file) -rm(list = ls()) # clear memory -rm(list = ls()) # clear memory -library("devtools") -library("ReactiveAtlantis") -library("proj4") -library("here") -####### Compare outputs and Biomass visualization ####### -nc.current <- here::here("example","outputFolder_original","outputSETAS.nc") -nc.old <- here::here("example","outputFolder_mum","outputSETAS.nc") -grp.csv <- here::here("example","SETasGroupsDem.csv") -bgm.file <- here::here("example","VMPA_setas.bgm") -cum.depths <- c(0,20,50,100,250,700,2000) ## This should be the cummulative depth of your model -## individual file -compare(nc.current, nc.out.old = NULL, grp.csv, bgm.file, cum.depths) -compare(nc.current, nc.old, grp.csv, bgm.file, cum.depths) -biom <- here::here("example","outputFolder_original","outputSETASBiomIndx.txt") -diet.file <- here::here("example","outputFolder_original","outputSETASDietCheck.txt") -bio.age <- here::here("example","outputFolder_original","outputSETASAgeBiomIndx.txt") ## optional file. just if you want to check the predation by age -grp.csv <- here::here("example","SETasGroupsDem.csv") -## Predation by Age -predation(biom, grp.csv, diet.file, bio.age) -####### Atlantis food web and trophic level composition ####### -grp.csv <- here::here("example","SETasGroupsDem.csv") -prm.file <- here::here("example","VMPA_setas_biol_fishing_Trunk.prm") -diet.file <- here::here("example","outputFolder_original","outputSETASDietCheck.txt") -food.web(diet.file, grp.csv) -biom <- here::here("example","outputFolder_original","outputSETASBiomIndx.txt") -diet.file <- here::here("example","outputFolder_original","outputSETASDietCheck.txt") -bio.age <- here::here("example","outputFolder_original","outputSETASAgeBiomIndx.txt") ## optional file. just if you want to check the predation by age -grp.csv <- here::here("example","SETasGroupsDem.csv") -## Predation by Age -predation(biom, grp.csv, diet.file, bio.age) -claude -1850/365 -source("~/psatlantismodel/PS_runs_PCBs.R") -source("~/psatlantismodel/PS_runs_PCBs.R") -source("~/psatlantismodel/PS_runs_PCBs.R") From 78e98d8dc08842572fa9e130a0eba13ef95f9c5c Mon Sep 17 00:00:00 2001 From: Hem Nalini Morzaria-Luna Date: Tue, 22 Sep 2026 16:48:09 -0700 Subject: [PATCH 6/7] Delete .RData --- .RData | Bin 717 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 .RData diff --git a/.RData b/.RData deleted file mode 100644 index 4ca4a59150b9aab40c403cd99157aae80b0d29ba..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 717 zcmb7C+fKqj5M882!Rtr(YD;6H_#^`9qalb1Z_Prdm$2=Y-7SH?^i%u-*ggojGTBC!^VYXVxKvG>Kt0Nz+6~%=f8#*CWI@!Jt75(#G{{9wuH8GeCTEkaz8f zCty>>XsTjqzf@o<@^rb6yzy}0I6ZruhoIhgp88(zY3_9&yN>f3!HRS zOnd&sZ)qAU(~486FkfhBp*Mba?WgmEZd9CrRFGkL*}uR3Kvo5!hE*AKB iG;-IwqX-17a!40jq`13{TSTR4<+T=CXgPWo Date: Tue, 22 Sep 2026 16:53:44 -0700 Subject: [PATCH 7/7] Fix AMPS project link in README.md Updated the link for AMPS project in the README. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3c73551..1a983ce 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ The Atlantis version represents smaller fixes and new features and follows the h | Icelantis | Iceland | Iceland | [Jacob Kasper](https://github.com/jacobkasper) | | | | South Australia | Australia | [Beth Fulton](https://github.com/eafulton) | NA | | SSAM | Salish Sea | Canada | [Raisha Lovindeer](https://github.com/raishalovindeer) | | -| AMPS | Puget Sound | USA; Canada | [Hem Nalini Morzaria-Luna](https://github.com/hmorzaria) | NA | +| AMPS | Puget Sound | USA; Canada | [Hem Nalini Morzaria-Luna](https://github.com/hmorzaria) | | | | Southern Benguela | South Africa | [Kelly Cisneros](https://github.com/kortegac) | NA | | | Tasman and Golden Bays | New Zealand | | NA | | | Korean Peninsula | South Korea | [Junggil Seo]() | NA |