From df70230056d8341f50556fa46aa6d3925db8c97c Mon Sep 17 00:00:00 2001 From: Andrew Myers Date: Fri, 5 Apr 2024 12:51:44 -0700 Subject: [PATCH] Fix formatting and timing of the output.dat files --- src/AgentContainer.cpp | 20 +++++++++++--------- src/main.cpp | 41 +++++++++++++++++++++-------------------- 2 files changed, 32 insertions(+), 29 deletions(-) diff --git a/src/AgentContainer.cpp b/src/AgentContainer.cpp index a76cff9..6d56997 100644 --- a/src/AgentContainer.cpp +++ b/src/AgentContainer.cpp @@ -841,12 +841,14 @@ void AgentContainer::updateStatus (MultiFab& disease_stats /*!< Community-wise d } else if (status_ptr[i] == Status::infected) { counter_ptr[i] += 1; - if (amrex::Random(engine) < lparm->p_asymp[0]) { - symptomatic_ptr[i] = 2; - } else { - symptomatic_ptr[i] = 0; + if (counter_ptr[i] == 1) { + if (amrex::Random(engine) < lparm->p_asymp[0]) { + symptomatic_ptr[i] = 2; + } else { + symptomatic_ptr[i] = 0; + } } - if (counter_ptr[i] == amrex::Math::ceil(symptomdev_period_ptr[i])) { + if (counter_ptr[i] == amrex::Math::floor(symptomdev_period_ptr[i])) { if (symptomatic_ptr[i] != 2) { symptomatic_ptr[i] = 1; } @@ -858,7 +860,7 @@ void AgentContainer::updateStatus (MultiFab& disease_stats /*!< Community-wise d // incubation phase return; } - if (counter_ptr[i] == amrex::Math::ceil(incubation_period_ptr[i])) { + if (counter_ptr[i] == amrex::Math::floor(incubation_period_ptr[i])) { // decide if hospitalized Real p_hosp = CHR[age_group_ptr[i]]; if (amrex::Random(engine) < p_hosp) { @@ -1312,7 +1314,7 @@ void AgentContainer::interactAgentsHomeWork ( MultiFab& /*mask_behavior*/ /*!< M AMREX_ALWAYS_ASSERT( (Long) i < np); if (status_ptr[i] == Status::immune) { return; } if (status_ptr[i] == Status::dead) { return; } - if (status_ptr[i] == Status::infected && counter_ptr[i] < incubation_period_ptr[i]) { return; } // incubation stage + if ((status_ptr[i] == Status::infected) && (counter_ptr[i] < incubation_period_ptr[i])) { return; } // incubation stage //amrex::Real i_mask = mask_arr(home_i_ptr[i], home_j_ptr[i], 0); for (unsigned int jj = cell_start; jj < cell_stop; ++jj) { auto j = inds[jj]; @@ -1321,7 +1323,7 @@ void AgentContainer::interactAgentsHomeWork ( MultiFab& /*mask_behavior*/ /*!< M //amrex::Real j_mask = mask_arr(home_i_ptr[j], home_j_ptr[j], 0); if (status_ptr[j] == Status::immune) {continue;} if (status_ptr[j] == Status::dead) {continue;} - if (status_ptr[j] == Status::infected && counter_ptr[j] < incubation_period_ptr[j]) { continue; } // incubation stage + if ((status_ptr[j] == Status::infected) && (counter_ptr[j] < incubation_period_ptr[j])) { continue; } // incubation stage if (status_ptr[j] == Status::infected && (status_ptr[i] != Status::infected && status_ptr[i] != Status::dead)) { @@ -1494,7 +1496,7 @@ std::array AgentContainer::getTotals () { AMREX_ALWAYS_ASSERT(p.idata(IntIdx::status) <= 4); s[p.idata(IntIdx::status)] = 1; if (p.idata(IntIdx::status) == 1) { // exposed - if (p.rdata(RealIdx::disease_counter) <= amrex::Math::ceil(p.rdata(RealIdx::incubation_period))) { + if (p.rdata(RealIdx::disease_counter) <= p.rdata(RealIdx::incubation_period)) { s[5] = 1; // exposed, but not infectious } else { // infectious if (p.idata(IntIdx::symptomatic) == 2) { diff --git a/src/main.cpp b/src/main.cpp index c7f3c13..fd8ae48 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -125,7 +125,7 @@ void runAgent () amrex::FileOpenFailed(output_filename); } - File << "Day Never Infected Immune Deaths Hospitalized Ventilated ICU Exposed Asymptomatic Presymptomatic Symptomatic\n"; + File << std::setw(5) << "Day" << std::setw(10) << "Never" << std::setw(10) << "Infected" << std::setw(10) << "Immune" << std::setw(10) << "Deaths" << std::setw(15) << "Hospitalized" << std::setw(15) << "Ventilated" << std::setw(10) << "ICU" << std::setw(10) << "Exposed" << std::setw(15) << "Asymptomatic" << std::setw(15) << "Presymptomatic" << std::setw(15) << "Symptomatic\n"; File.flush(); @@ -191,25 +191,7 @@ void runAgent () ExaEpi::IO::writeFIPSData(pc, unit_mf, FIPS_mf, comm_mf, demo, params.aggregated_diag_prefix, i); } - if (params.shelter_start > 0 && params.shelter_start == i) { - pc.shelterStart(); - } - - if (params.shelter_start > 0 && params.shelter_start + params.shelter_length == i) { - pc.shelterStop(); - } - pc.updateStatus(disease_stats); - pc.moveAgentsToWork(); - pc.interactAgentsHomeWork(mask_behavior, false); - pc.moveAgentsToHome(); - pc.interactAgentsHomeWork(mask_behavior, true); - pc.infectAgents(); - - // if ((params.random_travel_int > 0) && (i % params.random_travel_int == 0)) { - // pc.moveRandomTravel(); - // } - // pc.Redistribute(); auto counts = pc.getTotals(); if (counts[1] > num_infected_peak) { @@ -254,7 +236,7 @@ void runAgent () amrex::FileOpenFailed(output_filename); } - File << i << " " << counts[0] << " " << counts[1] << " " << counts[2] << " " << counts[4] << " " << mmc[0] << " " << mmc[1] << " " << mmc[2] << " " << counts[5] << " " << counts[6] << " " << counts[7] << " " << counts[8] << "\n"; + File << std::setw(5) << i << std::setw(10) << counts[0] << std::setw(10) << counts[1] << std::setw(10) << counts[2] << std::setw(10) << counts[4] << std::setw(15) << mmc[0] << std::setw(15) << mmc[1] << std::setw(10) << mmc[2] << std::setw(10) << counts[5] << std::setw(15) << counts[6] << std::setw(15) << counts[7] << std::setw(15) << counts[8] << "\n"; File.flush(); @@ -265,6 +247,25 @@ void runAgent () } } + if (params.shelter_start > 0 && params.shelter_start == i) { + pc.shelterStart(); + } + + if (params.shelter_start > 0 && params.shelter_start + params.shelter_length == i) { + pc.shelterStop(); + } + + pc.moveAgentsToWork(); + pc.interactAgentsHomeWork(mask_behavior, false); + pc.moveAgentsToHome(); + pc.interactAgentsHomeWork(mask_behavior, true); + pc.infectAgents(); + + // if ((params.random_travel_int > 0) && (i % params.random_travel_int == 0)) { + // pc.moveRandomTravel(); + // } + // pc.Redistribute(); + cur_time += 1.0; // time step is one day } }