Skip to content

Commit

Permalink
Implement start and stop for shelter-in-place (#36)
Browse files Browse the repository at this point in the history
* implement start and stop for shelter-in-place

* remove unused

* document new parameters
  • Loading branch information
atmyers authored Mar 28, 2024
1 parent 9d3e586 commit a3d5c70
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 0 deletions.
6 changes: 6 additions & 0 deletions docs/source/usage/how_to_run.rst
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ In addition to the ExaEpi inputs, there are also a number of runtime options tha
aggregated data files will be named `cases000010`, etc.
* ``agent.seed`` (`long integer`)
Use this to specify the random seed to use for the run.
* ``agent.shelter_start`` (`integer`)
Day on which to start shelter-in-place.
* ``agent.shelter_length`` (`integer`)
Number of days shelter in-place-is in effect.
* ``agent.symptomatic_withdraw`` (`integer`)
Whether or not to have symptomatic agents withdraw.
* ``contact.pSC`` (`float`, default: 0.2)
This is contact matrix scaling factor for schools.
* ``contact.pCO`` (`float`, default: 1.45)
Expand Down
4 changes: 4 additions & 0 deletions src/AgentContainer.H
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ public:

void infectAgents ();

void shelterStart ();

void shelterStop ();

void generateCellData (amrex::MultiFab& mf) const;

std::array<amrex::Long, 5> getTotals ();
Expand Down
63 changes: 63 additions & 0 deletions src/AgentContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1039,6 +1039,69 @@ void AgentContainer::interactAgents ()
}
}

void AgentContainer::shelterStart ()
{
BL_PROFILE("AgentContainer::shelterStart");

amrex::Print() << "Starting shelter in place order \n";

for (int lev = 0; lev <= finestLevel(); ++lev)
{
auto& plev = GetParticles(lev);

#ifdef AMREX_USE_OMP
#pragma omp parallel if (Gpu::notInLaunchRegion())
#endif
for(MFIter mfi = MakeMFIter(lev, TilingIfNotGPU()); mfi.isValid(); ++mfi)
{
int gid = mfi.index();
int tid = mfi.LocalTileIndex();
auto& ptile = plev[std::make_pair(gid, tid)];
auto& soa = ptile.GetStructOfArrays();
const auto np = ptile.numParticles();
auto withdrawn_ptr = soa.GetIntData(IntIdx::withdrawn).data();

amrex::ParallelForRNG( np,
[=] AMREX_GPU_DEVICE (int i, amrex::RandomEngine const& engine) noexcept
{
if (amrex::Random(engine) < 0.95) {
withdrawn_ptr[i] = 1;
}
});
}
}
}

void AgentContainer::shelterStop ()
{
BL_PROFILE("AgentContainer::shelterStop");

amrex::Print() << "Stopping shelter in place order \n";

for (int lev = 0; lev <= finestLevel(); ++lev)
{
auto& plev = GetParticles(lev);

#ifdef AMREX_USE_OMP
#pragma omp parallel if (Gpu::notInLaunchRegion())
#endif
for(MFIter mfi = MakeMFIter(lev, TilingIfNotGPU()); mfi.isValid(); ++mfi)
{
int gid = mfi.index();
int tid = mfi.LocalTileIndex();
auto& ptile = plev[std::make_pair(gid, tid)];
auto& soa = ptile.GetStructOfArrays();
const auto np = ptile.numParticles();
auto withdrawn_ptr = soa.GetIntData(IntIdx::withdrawn).data();

amrex::ParallelFor( np, [=] AMREX_GPU_DEVICE (int i) noexcept
{
withdrawn_ptr[i] = 0;
});
}
}
}

/*! \brief Infect agents based on their current status and the computed probability of infection.
The infection probability is computed in AgentContainer::interactAgentsHomeWork() or
AgentContainer::interactAgents()
Expand Down
3 changes: 3 additions & 0 deletions src/Utils.H
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ struct TestParams
(see: ExaEpi::IO::writeFIPSData) */
std::string aggregated_diag_prefix; /*!< filename prefix for diagnostic data
(see: ExaEpi::IO::writeFIPSData) */

int shelter_start = -1;
int shelter_length = 0;
};

/**
Expand Down
3 changes: 3 additions & 0 deletions src/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ void ExaEpi::Utils::get_test_params ( TestParams& params, /*!< Test pa
pp.get("aggregated_diag_prefix", params.aggregated_diag_prefix);
}

pp.query("shelter_start", params.shelter_start);
pp.query("shelter_length", params.shelter_length);

Long seed = 0;
bool reset_seed = pp.query("seed", seed);
if (reset_seed) {
Expand Down
8 changes: 8 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,14 @@ 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);
Expand Down

0 comments on commit a3d5c70

Please sign in to comment.