Skip to content

Commit c46e6f8

Browse files
committed
for each interaction type, implemented a binary (one-on-one) interaction kernel between an infectious and a susceptible agent; calling that in the main interaction function
1 parent 42bdd56 commit c46e6f8

File tree

4 files changed

+238
-263
lines changed

4 files changed

+238
-263
lines changed

src/InteractionLocHome.H

Lines changed: 54 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,49 @@
1313
#include <AMReX_Particles.H>
1414

1515
#include "Locations.H"
16+
#include "DiseaseParm.H"
1617
#include "AgentDefinitions.H"
1718

1819
using namespace amrex;
1920

21+
/*! \brief One-on-one interaction between an infectious agent and a susceptible agent.
22+
*
23+
* This function defines the one-on-one interaction between an infectious agent and a
24+
* susceptible agent at home. */
25+
AMREX_GPU_DEVICE AMREX_FORCE_INLINE
26+
static void binaryInteractionHome ( const int a_i, /*!< Index of infectious agent */
27+
const int a_j, /*!< Index of susceptible agent */
28+
const DiseaseParm* const a_lparm, /*!< disease paramters */
29+
const int* const a_age_group_ptr, /*!< age group */
30+
const int* const a_family_ptr, /*!< family */
31+
const int* const a_nborhood_ptr, /*!< neighborhood */
32+
const int* const a_school_ptr, /*!< school */
33+
ParticleReal* const a_prob_ptr /*!< infection probability */)
34+
{
35+
Real infect = a_lparm->infect;
36+
infect *= a_lparm->vac_eff;
37+
//infect *= i_mask;
38+
//infect *= j_mask;
39+
auto prob = a_prob_ptr[a_j];
40+
if ( (a_nborhood_ptr[a_i] == a_nborhood_ptr[a_j])
41+
&& (a_family_ptr[a_i] == a_family_ptr[a_j]) ) {
42+
if (a_age_group_ptr[a_i] <= 1) { /* Transmitter i is a child */
43+
if (a_school_ptr[a_i] < 0) { // not attending school, use _SC contacts
44+
prob *= 1.0 - infect * a_lparm->xmit_child_SC[a_age_group_ptr[a_j]];
45+
} else {
46+
prob *= 1.0 - infect * a_lparm->xmit_child[a_age_group_ptr[a_j]];
47+
}
48+
} else {
49+
if (a_school_ptr[a_i] < 0) { // not attending school, use _SC contacts
50+
prob *= 1.0 - infect * a_lparm->xmit_adult_SC[a_age_group_ptr[a_j]];
51+
} else {
52+
prob *= 1.0 - infect * a_lparm->xmit_adult[a_age_group_ptr[a_j]];
53+
}
54+
}
55+
}
56+
Gpu::Atomic::Multiply(&a_prob_ptr[a_j], prob);
57+
}
58+
2059
/*! \brief Class describing agent interactions at home */
2160
template <typename ACType /*!< agent container type */, typename AType /*!< agent type */>
2261
class InteractionLocHome : public InteractionLocation<ACType,AType>
@@ -153,61 +192,25 @@ void InteractionLocHome<ACType,AType>::interactAgents(ACType& a_agents, /*!<
153192
if ( isInfectious( i, status_ptr,counter_ptr,lparm->incubation_length )
154193
&& isSusceptible( j, status_ptr ) ) {
155194

156-
// i can infect j
157-
Real infect = lparm->infect;
158-
infect *= lparm->vac_eff;
159-
//infect *= i_mask;
160-
//infect *= j_mask;
161-
162-
auto prob = prob_ptr[j];
163-
if ( (nborhood_ptr[i] == nborhood_ptr[j])
164-
&& (family_ptr[i] == family_ptr[j]) ) {
165-
if (age_group_ptr[i] <= 1) { /* Transmitter i is a child */
166-
if (school_ptr[i] < 0) { // not attending school, use _SC contacts
167-
prob *= 1.0 - infect * lparm->xmit_child_SC[age_group_ptr[j]];
168-
} else {
169-
prob *= 1.0 - infect * lparm->xmit_child[age_group_ptr[j]];
170-
}
171-
}
172-
else {
173-
if (school_ptr[i] < 0) { // not attending school, use _SC contacts
174-
prob *= 1.0 - infect * lparm->xmit_adult_SC[age_group_ptr[j]];
175-
} else {
176-
prob *= 1.0 - infect * lparm->xmit_adult[age_group_ptr[j]];
177-
}
178-
}
179-
}
180-
Gpu::Atomic::Multiply(&prob_ptr[j], prob);
195+
binaryInteractionHome( i, j,
196+
lparm,
197+
age_group_ptr,
198+
family_ptr,
199+
nborhood_ptr,
200+
school_ptr,
201+
prob_ptr );
181202

182203
} else if ( isInfectious( j, status_ptr,counter_ptr,lparm->incubation_length )
183204
&& isSusceptible( i, status_ptr ) ) {
184205

185-
// j can infect i
186-
Real infect = lparm->infect;
187-
infect *= lparm->vac_eff;
188-
//infect *= i_mask;
189-
//infect *= j_mask;
190-
191-
auto prob = prob_ptr[i];
192-
/* Determine what connections these individuals have */
193-
if ( (nborhood_ptr[i] == nborhood_ptr[j])
194-
&& (family_ptr[i] == family_ptr[j]) ) {
195-
if (age_group_ptr[j] <= 1) { /* Transmitter j is a child */
196-
if (school_ptr[j] < 0) { // not attending school, use _SC contacts
197-
prob *= 1.0 - infect * lparm->xmit_child_SC[age_group_ptr[i]];
198-
} else {
199-
prob *= 1.0 - infect * lparm->xmit_child[age_group_ptr[i]];
200-
}
201-
} else {
202-
if (school_ptr[j] < 0) { // not attending school, use _SC contacts
203-
prob *= 1.0 - infect * lparm->xmit_adult_SC[age_group_ptr[i]];
204-
} else {
205-
prob *= 1.0 - infect * lparm->xmit_adult[age_group_ptr[i]];
206-
}
207-
}
208-
}
209-
210-
Gpu::Atomic::Multiply(&prob_ptr[i], prob);
206+
binaryInteractionHome( j, i,
207+
lparm,
208+
age_group_ptr,
209+
family_ptr,
210+
nborhood_ptr,
211+
school_ptr,
212+
prob_ptr );
213+
211214
}
212215
}
213216
});

src/InteractionLocNborhood.H

Lines changed: 79 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,64 @@
1717

1818
using namespace amrex;
1919

20+
/*! \brief One-on-one interaction between an infectious agent and a susceptible agent.
21+
*
22+
* This function defines the one-on-one interaction between an infectious agent and a
23+
* susceptible agent in a neighborhood. */
24+
AMREX_GPU_DEVICE AMREX_FORCE_INLINE
25+
static void binaryInteractionNborhood ( const int a_i, /*!< Index of infectious agent */
26+
const int a_j, /*!< Index of susceptible agent */
27+
const DiseaseParm* const a_lparm, /*!< disease paramters */
28+
const Real a_social_scale, /*!< Social scale */
29+
const int* const a_age_group_ptr, /*!< age group */
30+
const int* const a_family_ptr, /*!< family */
31+
const int* const a_nborhood_ptr, /*!< neighborhood */
32+
const int* const a_school_ptr, /*!< school */
33+
ParticleReal* const a_prob_ptr /*!< infection probability */)
34+
{
35+
Real infect = a_lparm->infect;
36+
infect *= a_lparm->vac_eff;
37+
//infect *= i_mask;
38+
//infect *= j_mask;
39+
auto prob = a_prob_ptr[a_j];
40+
41+
/* check for common neighborhood cluster: */
42+
if ( (a_nborhood_ptr[a_i] == a_nborhood_ptr[a_j])
43+
&& ((a_family_ptr[a_i] / 4) == (a_family_ptr[a_j] / 4)) ) {
44+
if (a_age_group_ptr[a_i] <= 1) { /* Transmitter i is a child */
45+
if (a_school_ptr[a_i] < 0) // not attending school, use _SC contacts
46+
prob *= 1.0 - infect * a_lparm->xmit_nc_child_SC[a_age_group_ptr[a_j]] * a_social_scale;
47+
else
48+
prob *= 1.0 - infect * a_lparm->xmit_nc_child[a_age_group_ptr[a_j]] * a_social_scale;
49+
}
50+
else {
51+
if (a_school_ptr[a_i] < 0) // not attending school, use _SC contacts
52+
prob *= 1.0 - infect * a_lparm->xmit_nc_adult_SC[a_age_group_ptr[a_j]] * a_social_scale;
53+
else
54+
prob *= 1.0 - infect * a_lparm->xmit_nc_adult[a_age_group_ptr[a_j]] * a_social_scale;
55+
}
56+
}
57+
58+
// school < 0 means a child normally attends school, but not today
59+
/* Should always be in the same community = same cell */
60+
if (a_school_ptr[a_i] < 0) { // not attending school, use _SC contacts
61+
prob *= 1.0 - infect * a_lparm->xmit_comm_SC[a_age_group_ptr[a_j]] * a_social_scale;
62+
} else {
63+
prob *= 1.0 - infect * a_lparm->xmit_comm[a_age_group_ptr[a_j]] * a_social_scale;
64+
}
65+
// /* Neighborhood? */
66+
if (a_nborhood_ptr[a_i] == a_nborhood_ptr[a_j]) {
67+
if (a_school_ptr[a_i] < 0) {
68+
// not attending school, use _SC contacts
69+
prob *= 1.0 - infect * a_lparm->xmit_hood_SC[a_age_group_ptr[a_j]] * a_social_scale;
70+
} else {
71+
prob *= 1.0 - infect * a_lparm->xmit_hood[a_age_group_ptr[a_j]] * a_social_scale;
72+
}
73+
}
74+
75+
Gpu::Atomic::Multiply(&a_prob_ptr[a_j], prob);
76+
}
77+
2078
/*! \brief Class describing agent interactions at neighborhood */
2179
template <typename ACType /*!< agent container type */, typename AType /*!< agent type */>
2280
class InteractionLocNborhood : public InteractionLocation<ACType,AType>
@@ -136,6 +194,9 @@ void InteractionLocNborhood<ACType,AType>::interactAgents(ACType& a_agents, /
136194
|| notSusceptible( i, status_ptr ) ) {
137195
return;
138196
}
197+
if (withdrawn_ptr[i]) {
198+
return;
199+
}
139200

140201
//Real i_mask = mask_arr(home_i_ptr[i], home_j_ptr[i], 0);
141202
for (unsigned int jj = cell_start; jj < cell_stop; ++jj) {
@@ -147,112 +208,34 @@ void InteractionLocNborhood<ACType,AType>::interactAgents(ACType& a_agents, /
147208
|| notSusceptible( j, status_ptr ) ) {
148209
continue;
149210
}
211+
if (withdrawn_ptr[j]) {
212+
continue;
213+
}
150214

151215
if ( isInfectious( i, status_ptr,counter_ptr,lparm->incubation_length )
152216
&& isSusceptible( j, status_ptr ) ) {
153217

154-
// i can infect j
155-
Real infect = lparm->infect;
156-
infect *= lparm->vac_eff;
157-
//infect *= i_mask;
158-
//infect *= j_mask;
159-
160218
Real social_scale = 1.0; // TODO this should vary based on cell
161-
auto prob = prob_ptr[j];
162-
163-
/* check for common neighborhood cluster: */
164-
if ( (nborhood_ptr[i] == nborhood_ptr[j])
165-
&& (!withdrawn_ptr[i]) && (!withdrawn_ptr[j])
166-
&& ((family_ptr[i] / 4) == (family_ptr[j] / 4)) ) {
167-
if (age_group_ptr[i] <= 1) { /* Transmitter i is a child */
168-
if (school_ptr[i] < 0) // not attending school, use _SC contacts
169-
prob *= 1.0 - infect * lparm->xmit_nc_child_SC[age_group_ptr[j]] * social_scale;
170-
else
171-
prob *= 1.0 - infect * lparm->xmit_nc_child[age_group_ptr[j]] * social_scale;
172-
}
173-
else {
174-
if (school_ptr[i] < 0) // not attending school, use _SC contacts
175-
prob *= 1.0 - infect * lparm->xmit_nc_adult_SC[age_group_ptr[j]] * social_scale;
176-
else
177-
prob *= 1.0 - infect * lparm->xmit_nc_adult[age_group_ptr[j]] * social_scale;
178-
}
179-
}
180-
181-
// /* Home isolation or household quarantine? */
182-
if ( (!withdrawn_ptr[i]) && (!withdrawn_ptr[j]) ) {
183-
// school < 0 means a child normally attends school, but not today
184-
/* Should always be in the same community = same cell */
185-
if (school_ptr[i] < 0) { // not attending school, use _SC contacts
186-
prob *= 1.0 - infect * lparm->xmit_comm_SC[age_group_ptr[j]] * social_scale;
187-
} else {
188-
prob *= 1.0 - infect * lparm->xmit_comm[age_group_ptr[j]] * social_scale;
189-
}
190-
// /* Neighborhood? */
191-
if (nborhood_ptr[i] == nborhood_ptr[j]) {
192-
if (school_ptr[i] < 0) {
193-
// not attending school, use _SC contacts
194-
prob *= 1.0 - infect * lparm->xmit_hood_SC[age_group_ptr[j]] * social_scale;
195-
} else {
196-
prob *= 1.0 - infect * lparm->xmit_hood[age_group_ptr[j]] * social_scale;
197-
}
198-
}
199-
}
200-
201-
Gpu::Atomic::Multiply(&prob_ptr[j], prob);
219+
binaryInteractionNborhood( i, j,
220+
lparm, social_scale,
221+
age_group_ptr,
222+
family_ptr,
223+
nborhood_ptr,
224+
school_ptr,
225+
prob_ptr );
202226

203227
} else if ( isInfectious( j, status_ptr,counter_ptr,lparm->incubation_length )
204228
&& isSusceptible( i, status_ptr ) ) {
205229

206-
// j can infect i
207-
Real infect = lparm->infect;
208-
infect *= lparm->vac_eff;
209-
//infect *= i_mask;
210-
//infect *= j_mask;
211-
212230
Real social_scale = 1.0; // TODO this should vary based on cell
213-
auto prob = prob_ptr[i];
214-
215-
/* check for common neighborhood cluster: */
216-
if ( (nborhood_ptr[i] == nborhood_ptr[j])
217-
&& (!withdrawn_ptr[i])
218-
&& (!withdrawn_ptr[j])
219-
&& ((family_ptr[i] / 4) == (family_ptr[j] / 4)) ) {
220-
if (age_group_ptr[j] <= 1) { /* Transmitter i is a child */
221-
if (school_ptr[j] < 0) { // not attending school, use _SC contacts
222-
prob *= 1.0 - infect * lparm->xmit_nc_child_SC[age_group_ptr[i]] * social_scale;
223-
} else {
224-
prob *= 1.0 - infect * lparm->xmit_nc_child[age_group_ptr[i]] * social_scale;
225-
}
226-
} else {
227-
if (school_ptr[j] < 0) { // not attending school, use _SC contacts
228-
prob *= 1.0 - infect * lparm->xmit_nc_adult_SC[age_group_ptr[i]] * social_scale;
229-
} else {
230-
prob *= 1.0 - infect * lparm->xmit_nc_adult[age_group_ptr[i]] * social_scale;
231-
}
232-
}
233-
}
234-
235-
/* Home isolation or household quarantine? */
236-
// TODO - be careful about withdrawn versus at home...
237-
if ( (!withdrawn_ptr[i]) && (!withdrawn_ptr[j]) ) {
238-
// school < 0 means a child normally attends school, but not today
239-
/* Should always be in the same community = same cell */
240-
if (school_ptr[j] < 0) { // not attending school, use _SC contacts
241-
prob *= 1.0 - infect * lparm->xmit_comm_SC[age_group_ptr[i]] * social_scale;
242-
} else {
243-
prob *= 1.0 - infect * lparm->xmit_comm[age_group_ptr[i]] * social_scale;
244-
}
245-
/* Neighborhood? */
246-
if (nborhood_ptr[i] == nborhood_ptr[j]) {
247-
if (school_ptr[j] < 0) { // not attending school, use _SC contacts
248-
prob *= 1.0 - infect * lparm->xmit_hood_SC[age_group_ptr[i]] * social_scale;
249-
} else {
250-
prob *= 1.0 - infect * lparm->xmit_hood[age_group_ptr[i]] * social_scale;
251-
}
252-
}
253-
}
254-
255-
Gpu::Atomic::Multiply(&prob_ptr[i], prob);
231+
binaryInteractionNborhood( j, i,
232+
lparm, social_scale,
233+
age_group_ptr,
234+
family_ptr,
235+
nborhood_ptr,
236+
school_ptr,
237+
prob_ptr );
238+
256239
}
257240
}
258241
});

0 commit comments

Comments
 (0)