Skip to content

Commit

Permalink
distribute cases to all units sharing a FIPS (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
tannguyen153 authored Dec 4, 2023
1 parent bac1fba commit aafce3a
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions src/Initialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,8 @@ namespace Initialization

int ntry = 0;
int ni = 0;
unsigned int stop = std::min(cell_start + ninfect, cell_stop);
for (unsigned int ip = cell_start; ip < stop; ++ip) {
/*unsigned*/ int stop = std::min(cell_start + ninfect, cell_stop);
for (/*unsigned*/ int ip = cell_start; ip < stop; ++ip) {
int ind = cell_start + amrex::Random_int(num_this_community, engine);
auto pindex = inds[ind];
if (status_ptr[pindex] == Status::infected
Expand All @@ -254,6 +254,9 @@ namespace Initialization

Gpu::Device::streamSynchronize();
num_infected += num_infected_d.dataValue();
if(num_infected>=ninfect) {
break;
}
}

ParallelDescriptor::ReduceIntSum(num_infected);
Expand All @@ -265,30 +268,35 @@ namespace Initialization
const CaseData& cases, const DemographicData& demo)
{
BL_PROFILE("setInitialCases");

/*
amrex::Vector<int> FIPS_code_to_i(57000, -1);
for (int i = 0; i < demo.FIPS.size(); ++i) {
FIPS_code_to_i[demo.FIPS[i]] = i;
printf("Unit %d has FIPS %d and num Comm %d and population %d\n", i, demo.FIPS[i], demo.Start[i+1]-demo.Start[i], demo.Population[i]);
}

*/
std::map<std::pair<int, int>, amrex::DenseBins<AgentContainer::ParticleType> > bin_map;

int ntry = 5;
int ninf = 0;
for (int ihub = 0; ihub < cases.N_hubs; ++ihub) {
if (cases.Size_hubs[ihub] > 0) {
int FIPS = cases.FIPS_hubs[ihub];
int unit = FIPS_code_to_i[FIPS];
if (unit > 0) {
amrex::Print() << "Infecting " << cases.Size_hubs[ihub] << " in unit " << unit << " \n";
for (int i = 0; i < cases.Size_hubs[ihub]; i+=5) {
if (infect_random_community(pc, unit_mf, FIPS_mf, comm_mf, bin_map,
cases, demo, unit, ntry) < ntry) {
i--; // try again
} else {
ninf += ntry;
}
std::vector<int> units;
units.resize(0);
for (int i = 0; i < demo.Nunit; ++i) if(demo.FIPS[i]==FIPS)units.push_back(i);
//int unit = FIPS_code_to_i[FIPS];
if (units.size() > 0) {
printf("Infecting %d people in FIPS %d\n", cases.Size_hubs[ihub], FIPS);
int u=0;
int i=0;
while(i < cases.Size_hubs[ihub]) {
int nSuccesses= infect_random_community(pc, unit_mf, FIPS_mf, comm_mf, bin_map, cases, demo, units[u], ntry);
ninf += nSuccesses;
i+= nSuccesses;
u=(u+1)%units.size(); //sometimes we infect fewer than ntry, but switch to next unit anyway
}
amrex::Print() << "Infected " << i<< "total " << ninf << " after processing FIPS " << FIPS<< " \n";
}
}
}
Expand Down

0 comments on commit aafce3a

Please sign in to comment.