From 5e73ddc80122017fd1b6037f2b7eadc4466e68a8 Mon Sep 17 00:00:00 2001 From: Nicholas Rodine Date: Wed, 17 Jun 2020 16:06:26 -0500 Subject: [PATCH 1/4] Made SpatialBoundingBox a BoundingBox. Made LocationInitialInfection[] a Vector2. --- src/Param.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Param.h b/src/Param.h index 88b3895b5..847979182 100644 --- a/src/Param.h +++ b/src/Param.h @@ -8,6 +8,7 @@ #include "MicroCellPosition.hpp" #include "Geometry/Size.h" +#include "Geometry/BoundingBox.h" /** @brief Enumeration of bitmap formats. */ enum struct BitmapFormats @@ -80,7 +81,11 @@ struct Param int ResetSeeds,KeepSameSeeds, ResetSeedsPostIntervention, ResetSeedsFlag, TimeToResetSeeds; int OutputBitmap; // Whether to output a bitmap double LongitudeCutLine; // Longitude to image earth is cut at to produce a flat map. Default -360 degrees (effectively -180). Use to ensure countries have a contiguous boundary - double SpatialBoundingBox[4], LocationInitialInfection[MAX_NUM_SEED_LOCATIONS][2], InitialInfectionsAdminUnitWeight[MAX_NUM_SEED_LOCATIONS], TimeStepsPerDay; + + Geometry::BoundingBox SpatialBoundingBox; + Geometry::Vector2 LocationInitialInfection[MAX_NUM_SEED_LOCATIONS]; + + double InitialInfectionsAdminUnitWeight[MAX_NUM_SEED_LOCATIONS], TimeStepsPerDay; double FalsePositiveRate, FalsePositivePerCapitaIncidence, FalsePositiveAgeRate[NUM_AGE_GROUPS]; double latent_icdf[CDF_RES + 1], infectious_icdf[CDF_RES + 1], infectious_prof[INFPROF_RES + 1], infectiousness[MAX_INFECTIOUS_STEPS]; From 6061516cc2deef63803e5645a8f811c2e604269b Mon Sep 17 00:00:00 2001 From: Nicholas Rodine Date: Fri, 19 Jun 2020 16:28:19 -0500 Subject: [PATCH 2/4] Fixed compilation issues from change of SpatialBoundingBox and InitialLocation. --- src/CovidSim.cpp | 33 +++++++++++----------- src/Dist.cpp | 4 +-- src/SetupModel.cpp | 70 ++++++++++++++++++++++++---------------------- src/Update.cpp | 8 +++--- 4 files changed, 58 insertions(+), 57 deletions(-) diff --git a/src/CovidSim.cpp b/src/CovidSim.cpp index 539a8d414..e83e56188 100644 --- a/src/CovidSim.cpp +++ b/src/CovidSim.cpp @@ -34,6 +34,8 @@ #include #endif +using namespace Geometry; + void ReadParams(char*, char*); void ReadInterventions(char*); int GetXMLNode(FILE*, const char*, const char*, char*, int); @@ -953,7 +955,7 @@ void ReadParams(char* ParamFile, char* PreParamFile) P.NumSeedLocations = MAX_NUM_SEED_LOCATIONS; } GetInputParameter(PreParamFile_dat, AdminFile_dat, "Initial number of infecteds", "%i", (void*)P.NumInitialInfections, P.NumSeedLocations, 1, 0); - if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Location of initial infecteds", "%lf", (void*)&(P.LocationInitialInfection[0][0]), P.NumSeedLocations * 2, 1, 0)) P.LocationInitialInfection[0][0] = P.LocationInitialInfection[0][1] = 0.0; + if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Location of initial infecteds", "%lf", (void*)&(P.LocationInitialInfection[0].x), P.NumSeedLocations * 2, 1, 0)) P.LocationInitialInfection[0] = Vector2(0, 0); if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Minimum population in microcell of initial infection", "%i", (void*) & (P.MinPopDensForInitialInfection), 1, 1, 0)) P.MinPopDensForInitialInfection = 0; if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Maximum population in microcell of initial infection", "%i", (void*)&(P.MaxPopDensForInitialInfection), 1, 1, 0)) P.MaxPopDensForInitialInfection = 10000000; if (!GetInputParameter2(PreParamFile_dat, AdminFile_dat, "Randomise initial infection location", "%i", (void*) & (P.DoRandomInitialInfectionLoc), 1, 1, 0)) P.DoRandomInitialInfectionLoc=1; @@ -1220,10 +1222,10 @@ void ReadParams(char* ParamFile, char* PreParamFile) P.BoundingBox[0] = P.BoundingBox[1] = 0.0; P.BoundingBox[2] = P.BoundingBox[3] = 1.0; } - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Spatial domain for simulation", "%lf", (void*) & (P.SpatialBoundingBox[0]), 4, 1, 0)) + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Spatial domain for simulation", "%lf", (void*) & (P.SpatialBoundingBox.start.x), 4, 1, 0)) { - P.SpatialBoundingBox[0] = P.SpatialBoundingBox[1] = 0.0; - P.SpatialBoundingBox[2] = P.SpatialBoundingBox[3] = 1.0; + P.SpatialBoundingBox.start = Vector2(0, 0); + P.SpatialBoundingBox.end = Vector2(1, 1); } if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Grid size", "%lf", (void*) & (P.in_cells_.width), 1, 1, 0)) P.in_cells_.width = 1.0 / 120.0; if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Use long/lat coord system", "%i", (void*) & (P.DoUTM_coords), 1, 1, 0)) P.DoUTM_coords = 1; @@ -2324,16 +2326,16 @@ void ReadAirTravel(char* AirTravelFile) ERR_CRITICAL("fscanf failed in void ReadAirTravel\n"); } traf *= (P.AirportTrafficScale * sc); - if ((Airports[i].loc.x < P.SpatialBoundingBox[0]) || (Airports[i].loc.x >= P.SpatialBoundingBox[2]) - || (Airports[i].loc.y < P.SpatialBoundingBox[1]) || (Airports[i].loc.y >= P.SpatialBoundingBox[3])) + if ((Airports[i].loc.x < P.SpatialBoundingBox.start.x) || (Airports[i].loc.x >= P.SpatialBoundingBox.end.x) + || (Airports[i].loc.y < P.SpatialBoundingBox.start.y) || (Airports[i].loc.y >= P.SpatialBoundingBox.end.y)) { Airports[i].loc.x = Airports[i].loc.y = -1; Airports[i].total_traffic = 0; } else { - Airports[i].loc.x -= (float)P.SpatialBoundingBox[0]; - Airports[i].loc.y -= (float)P.SpatialBoundingBox[1]; + Airports[i].loc.x -= (float)P.SpatialBoundingBox.start.x; + Airports[i].loc.y -= (float)P.SpatialBoundingBox.start.y; Airports[i].total_traffic = (float)traf; } t = 0; @@ -2827,8 +2829,8 @@ void SeedInfection(double t, int* NumSeedingInfections_byLocation, int rf, int r { if ((!P.DoRandomInitialInfectionLoc) || ((P.DoAllInitialInfectioninSameLoc) && (rf))) //// either non-random locations, doing all initial infections in same location, and not initializing. { - k = (int)(P.LocationInitialInfection[i][0] / P.in_microcells_.width); - l = (int)(P.LocationInitialInfection[i][1] / P.in_microcells_.height); + k = (int)(P.LocationInitialInfection[i].x / P.in_microcells_.width); + l = (int)(P.LocationInitialInfection[i].y / P.in_microcells_.height); j = k * P.get_number_of_micro_cells_high() + l; m = 0; for (k = 0; (k < NumSeedingInfections_byLocation[i]) && (m < 10000); k++) @@ -2841,8 +2843,7 @@ void SeedInfection(double t, int* NumSeedingInfections_byLocation, int rf, int r //only reset the initial location if rf==0, i.e. when initial seeds are being set, not when imported cases are being set if (rf == 0) { - P.LocationInitialInfection[i][0] = Households[Hosts[l].hh].loc.x; - P.LocationInitialInfection[i][1] = Households[Hosts[l].hh].loc.y; + P.LocationInitialInfection[i] = Vector2(Households[Hosts[l].hh].loc); } Hosts[l].infector = -2; Hosts[l].infect_type = INFECT_TYPE_MASK - 1; @@ -2874,8 +2875,7 @@ void SeedInfection(double t, int* NumSeedingInfections_byLocation, int rf, int r { if (CalcPersonSusc(l, 0, 0, 0) > 0) { - P.LocationInitialInfection[i][0] = Households[Hosts[l].hh].loc.x; - P.LocationInitialInfection[i][1] = Households[Hosts[l].hh].loc.y; + P.LocationInitialInfection[i] = Vector2(Households[Hosts[l].hh].loc); Hosts[l].infector = -2; Hosts[l].infect_type = INFECT_TYPE_MASK - 1; DoInfect(l, t, 0, run); m = 0; @@ -2910,8 +2910,7 @@ void SeedInfection(double t, int* NumSeedingInfections_byLocation, int rf, int r { if (CalcPersonSusc(l, 0, 0, 0) > 0) { - P.LocationInitialInfection[i][0] = Households[Hosts[l].hh].loc.x; - P.LocationInitialInfection[i][1] = Households[Hosts[l].hh].loc.y; + P.LocationInitialInfection[i] = Vector2(Households[Hosts[l].hh].loc); Hosts[l].infector = -2; Hosts[l].infect_type = INFECT_TYPE_MASK - 1; DoInfect(l, t, 0, run); m = 0; @@ -3409,7 +3408,7 @@ void SaveResults(void) sprintf(outname, "%s.ge" DIRECTORY_SEPARATOR "%s.%i.png", OutFile, OutFile, i + 1); fprintf(dat, "\n%s\n\n", outname); fprintf(dat, "\n%.10f\n%.10f\n%.10f\n%.10f\n\n", - P.SpatialBoundingBox[3], P.SpatialBoundingBox[1], P.SpatialBoundingBox[2], P.SpatialBoundingBox[0]); + P.SpatialBoundingBox.end.y, P.SpatialBoundingBox.start.y, P.SpatialBoundingBox.end.x, P.SpatialBoundingBox.start.x); fprintf(dat, "\n"); } fprintf(dat, "\n\n"); diff --git a/src/Dist.cpp b/src/Dist.cpp index 1c27fb340..4a31a0fb8 100644 --- a/src/Dist.cpp +++ b/src/Dist.cpp @@ -34,11 +34,11 @@ double dist2UTM(double x1, double y1, double x2, double y2) y -= yi; x = (1 - x) * sinx[(int)xi] + x * sinx[((int)xi) + 1]; y = (1 - y) * sinx[(int)yi] + y * sinx[((int)yi) + 1]; - yt = fabs(y1 + P.SpatialBoundingBox[1]); + yt = fabs(y1 + P.SpatialBoundingBox.start.y); yi = floor(yt); cy1 = yt - yi; cy1 = (1 - cy1) * cosx[((int)yi)] + cy1 * cosx[((int)yi) + 1]; - yt = fabs(y2 + P.SpatialBoundingBox[1]); + yt = fabs(y2 + P.SpatialBoundingBox.start.y); yi = floor(yt); cy2 = yt - yi; cy2 = (1 - cy2) * cosx[((int)yi)] + cy2 * cosx[((int)yi) + 1]; diff --git a/src/SetupModel.cpp b/src/SetupModel.cpp index e0e858102..d347a22f7 100644 --- a/src/SetupModel.cpp +++ b/src/SetupModel.cpp @@ -17,6 +17,8 @@ #include "InfStat.h" #include "Bitmap.h" +using namespace Geometry; + void* BinFileBuf; BinFile* BF; int netbuf[NUM_PLACE_TYPES * 1000000]; @@ -109,8 +111,8 @@ void SetupModel(char* DensityFile, char* NetworkFile, char* SchoolFile, char* Re // We will compute a precise spatial bounding box using the population locations. // Initially, set the min values too high, and the max values too low, and then // we will adjust them as we read population data. - P.SpatialBoundingBox[0] = P.SpatialBoundingBox[1] = 1e10; - P.SpatialBoundingBox[2] = P.SpatialBoundingBox[3] = -1e10; + P.SpatialBoundingBox.start = Vector2(1e10, 1e10); + P.SpatialBoundingBox.end = Vector2(-1e10, -1e10); s2 = 0; for (rn = 0; rn < P.BinFileLen; rn++) { @@ -129,30 +131,30 @@ void SetupModel(char* DensityFile, char* NetworkFile, char* SchoolFile, char* Re s2 += t; // Adjust the bounds of the spatial bounding box so that they include the location // for this block of population. - if (x < P.SpatialBoundingBox[0]) P.SpatialBoundingBox[0] = x; - if (x >= P.SpatialBoundingBox[2]) P.SpatialBoundingBox[2] = x + 1e-6; - if (y < P.SpatialBoundingBox[1]) P.SpatialBoundingBox[1] = y; - if (y >= P.SpatialBoundingBox[3]) P.SpatialBoundingBox[3] = y + 1e-6; + if (x < P.SpatialBoundingBox.start.x) P.SpatialBoundingBox.start.x = x; + if (x >= P.SpatialBoundingBox.end.x) P.SpatialBoundingBox.end.x = x + 1e-6; + if (y < P.SpatialBoundingBox.start.y) P.SpatialBoundingBox.start.y = y; + if (y >= P.SpatialBoundingBox.end.y) P.SpatialBoundingBox.end.y = y + 1e-6; } } if (!P.DoSpecifyPop) P.PopSize = (int)s2; } P.in_cells_.height = P.in_cells_.width; - P.SpatialBoundingBox[0] = floor(P.SpatialBoundingBox[0] / P.in_cells_.width) * P.in_cells_.width; - P.SpatialBoundingBox[1] = floor(P.SpatialBoundingBox[1] / P.in_cells_.height) * P.in_cells_.height; - P.SpatialBoundingBox[2] = ceil(P.SpatialBoundingBox[2] / P.in_cells_.width) * P.in_cells_.width; - P.SpatialBoundingBox[3] = ceil(P.SpatialBoundingBox[3] / P.in_cells_.height) * P.in_cells_.height; - P.in_degrees_.width = P.SpatialBoundingBox[2] - P.SpatialBoundingBox[0]; - P.in_degrees_.height = P.SpatialBoundingBox[3] - P.SpatialBoundingBox[1]; + P.SpatialBoundingBox.start.x = floor(P.SpatialBoundingBox.start.x / P.in_cells_.width) * P.in_cells_.width; + P.SpatialBoundingBox.start.y = floor(P.SpatialBoundingBox.start.y / P.in_cells_.height) * P.in_cells_.height; + P.SpatialBoundingBox.end.x = ceil(P.SpatialBoundingBox.end.x / P.in_cells_.width) * P.in_cells_.width; + P.SpatialBoundingBox.end.y = ceil(P.SpatialBoundingBox.end.y / P.in_cells_.height) * P.in_cells_.height; + P.in_degrees_.width = P.SpatialBoundingBox.end.x - P.SpatialBoundingBox.start.x; + P.in_degrees_.height = P.SpatialBoundingBox.end.y - P.SpatialBoundingBox.start.y; P.ncw = 4 * ((int)ceil(P.in_degrees_.width / P.in_cells_.width / 4)); P.nch = 4 * ((int)ceil(P.in_degrees_.height / P.in_cells_.height / 4)); P.in_degrees_.width = ((double)P.ncw) * P.in_cells_.width; P.in_degrees_.height = ((double)P.nch) * P.in_cells_.height; - P.SpatialBoundingBox[2] = P.SpatialBoundingBox[0] + P.in_degrees_.width; - P.SpatialBoundingBox[3] = P.SpatialBoundingBox[1] + P.in_degrees_.height; + P.SpatialBoundingBox.end.x = P.SpatialBoundingBox.start.x + P.in_degrees_.width; + P.SpatialBoundingBox.end.y = P.SpatialBoundingBox.start.y + P.in_degrees_.height; P.NC = P.ncw * P.nch; - fprintf(stderr, "Adjusted bounding box = (%lg, %lg)- (%lg, %lg)\n", P.SpatialBoundingBox[0], P.SpatialBoundingBox[1], P.SpatialBoundingBox[2], P.SpatialBoundingBox[3]); + fprintf(stderr, "Adjusted bounding box = (%lg, %lg)- (%lg, %lg)\n", P.SpatialBoundingBox.start.x, P.SpatialBoundingBox.start.y, P.SpatialBoundingBox.end.x, P.SpatialBoundingBox.end.y); fprintf(stderr, "Number of cells = %i (%i x %i)\n", P.NC, P.ncw, P.nch); fprintf(stderr, "Population size = %i \n", P.PopSize); if (P.in_degrees_.width > 180) { @@ -170,8 +172,8 @@ void SetupModel(char* DensityFile, char* NetworkFile, char* SchoolFile, char* Re P.NC = P.ncw * P.nch; fprintf(stderr, "Number of cells adjusted to be %i (%i^2)\n", P.NC, P.ncw); s = floor(sqrt((double)P.PopSize)); - P.SpatialBoundingBox[0] = P.SpatialBoundingBox[1] = 0; - P.SpatialBoundingBox[2] = P.SpatialBoundingBox[3] = s; + P.SpatialBoundingBox.start = Vector2(0, 0); + P.SpatialBoundingBox.end = Vector2(s, s); P.PopSize = (int)(s * s); fprintf(stderr, "Population size adjusted to be %i (%lg^2)\n", P.PopSize, s); P.in_degrees_.width = P.in_degrees_.height = s; @@ -195,8 +197,8 @@ void SetupModel(char* DensityFile, char* NetworkFile, char* SchoolFile, char* Re P.in_microcells_.height = P.in_cells_.height / ((double)P.NMCL); for (int i = 0; i < P.NumSeedLocations; i++) { - P.LocationInitialInfection[i][0] -= P.SpatialBoundingBox[0]; - P.LocationInitialInfection[i][1] -= P.SpatialBoundingBox[1]; + P.LocationInitialInfection[i].x -= P.SpatialBoundingBox.start.x; + P.LocationInitialInfection[i].y -= P.SpatialBoundingBox.start.y; } // Find longest distance - may not be diagonally across the bounding box. t = dist2_raw(0, 0, P.in_degrees_.width, P.in_degrees_.height); @@ -208,7 +210,7 @@ void SetupModel(char* DensityFile, char* NetworkFile, char* SchoolFile, char* Re if (!(nKernel = (double*)calloc(P.NKR + 1, sizeof(double))) || !(nKernelHR = (double*)calloc(P.NKR + 1, sizeof(double)))) ERR_CRITICAL("Unable to allocate kernel storage\n"); P.KernelDelta = t / P.NKR; - // fprintf(stderr,"** %i %lg %lg %lg %lg | %lg %lg %lg %lg \n",P.DoUTM_coords,P.SpatialBoundingBox[0],P.SpatialBoundingBox[1],P.SpatialBoundingBox[2],P.SpatialBoundingBox[3],P.width,P.height,t,P.KernelDelta); + // fprintf(stderr,"** %i %lg %lg %lg %lg | %lg %lg %lg %lg \n",P.DoUTM_coords,P.SpatialBoundingBox.start.x,P.SpatialBoundingBox.start.y,P.SpatialBoundingBox.end.x,P.SpatialBoundingBox.end.y,P.width,P.height,t,P.KernelDelta); fprintf(stderr, "Coords xmcell=%lg m ymcell = %lg m\n", sqrt(dist2_raw(P.in_degrees_.width / 2, P.in_degrees_.height / 2, P.in_degrees_.width / 2 + P.in_microcells_.width, P.in_degrees_.height / 2)), sqrt(dist2_raw(P.in_degrees_.width / 2, P.in_degrees_.height / 2, P.in_degrees_.width / 2, P.in_degrees_.height / 2 + P.in_microcells_.height))); @@ -779,10 +781,10 @@ void SetupPopulation(char* SchoolFile, char* RegDemogFile) { k = 1; } - if ((k) && (x >= P.SpatialBoundingBox[0]) && (y >= P.SpatialBoundingBox[1]) && (x < P.SpatialBoundingBox[2]) && (y < P.SpatialBoundingBox[3])) + if ((k) && (x >= P.SpatialBoundingBox.start.x) && (y >= P.SpatialBoundingBox.start.y) && (x < P.SpatialBoundingBox.end.x) && (y < P.SpatialBoundingBox.end.y)) { - j = (int)floor((x - P.SpatialBoundingBox[0]) / P.in_microcells_.width + 0.1); - k = (int)floor((y - P.SpatialBoundingBox[1]) / P.in_microcells_.height + 0.1); + j = (int)floor((x - P.SpatialBoundingBox.start.x) / P.in_microcells_.width + 0.1); + k = (int)floor((y - P.SpatialBoundingBox.start.y) / P.in_microcells_.height + 0.1); l = j * P.get_number_of_micro_cells_high() + k; if (l < P.NMC) { @@ -826,8 +828,8 @@ void SetupPopulation(char* SchoolFile, char* RegDemogFile) for (l = 0; l < P.NMC; l++) if (mcell_adunits[l] >= 0) { - BF[rn].x = (double)(P.in_microcells_.width * (((double)(l / P.get_number_of_micro_cells_high())) + 0.5)) + P.SpatialBoundingBox[0]; //x - BF[rn].y = (double)(P.in_microcells_.height * (((double)(l % P.get_number_of_micro_cells_high())) + 0.5)) + P.SpatialBoundingBox[1]; //y + BF[rn].x = (double)(P.in_microcells_.width * (((double)(l / P.get_number_of_micro_cells_high())) + 0.5)) + P.SpatialBoundingBox.start.x; //x + BF[rn].y = (double)(P.in_microcells_.height * (((double)(l % P.get_number_of_micro_cells_high())) + 0.5)) + P.SpatialBoundingBox.start.y; //y BF[rn].ad = (P.DoAdUnits) ? (AdUnits[mcell_adunits[l]].id) : 0; BF[rn].pop = mcell_dens[l]; BF[rn].cnt = mcell_country[l]; @@ -1252,8 +1254,8 @@ void SetupPopulation(char* SchoolFile, char* RegDemogFile) if (!P.DoRandomInitialInfectionLoc) { - int k = (int)(P.LocationInitialInfection[0][0] / P.in_microcells_.width); - l = (int)(P.LocationInitialInfection[0][1] / P.in_microcells_.height); + int k = (int)(P.LocationInitialInfection[0].x / P.in_microcells_.width); + l = (int)(P.LocationInitialInfection[0].y / P.in_microcells_.height); j = k * P.get_number_of_micro_cells_high() + l; double rand_r = 0.0; //added these variables so that if initial infection location is empty we can search the 10km neighbourhood to find a suitable cell @@ -1265,15 +1267,15 @@ void SetupPopulation(char* SchoolFile, char* RegDemogFile) { rand_r = ranf(); rand_theta = ranf(); rand_r = 0.083 * sqrt(rand_r); rand_theta = 2 * PI * rand_theta; //rand_r is multiplied by 0.083 as this is roughly equal to 10km in decimal degrees - k = (int)((P.LocationInitialInfection[0][0] + rand_r * cos(rand_theta)) / P.in_microcells_.width); - l = (int)((P.LocationInitialInfection[0][1] + rand_r * sin(rand_theta)) / P.in_microcells_.height); + k = (int)((P.LocationInitialInfection[0].x + rand_r * cos(rand_theta)) / P.in_microcells_.width); + l = (int)((P.LocationInitialInfection[0].y + rand_r * sin(rand_theta)) / P.in_microcells_.height); j = k * P.get_number_of_micro_cells_high() + l; counter++; } if (counter < 100) { - P.LocationInitialInfection[0][0] = P.LocationInitialInfection[0][0] + rand_r * cos(rand_theta); //set LocationInitialInfection to actual one used - P.LocationInitialInfection[0][1] = P.LocationInitialInfection[0][1] + rand_r * sin(rand_theta); + P.LocationInitialInfection[0].x = P.LocationInitialInfection[0].x + rand_r * cos(rand_theta); //set LocationInitialInfection to actual one used + P.LocationInitialInfection[0].y = P.LocationInitialInfection[0].y + rand_r * sin(rand_theta); } } if (Mcells[j].n < P.NumInitialInfections[0]) @@ -1337,9 +1339,9 @@ void SetupPopulation(char* SchoolFile, char* RegDemogFile) { fscanf(dat, "%lg %lg %i %i", &x, &y, &j, &m); for (int i = 0; i < P.PlaceTypeMaxAgeRead[j]; i++) fscanf(dat, "%hu", &(Places[j][P.Nplace[j]].AvailByAge[i])); - Places[j][P.Nplace[j]].loc.x = (float)(x - P.SpatialBoundingBox[0]); - Places[j][P.Nplace[j]].loc.y = (float)(y - P.SpatialBoundingBox[1]); - if ((x >= P.SpatialBoundingBox[0]) && (x < P.SpatialBoundingBox[2]) && (y >= P.SpatialBoundingBox[1]) && (y < P.SpatialBoundingBox[3])) + Places[j][P.Nplace[j]].loc.x = (float)(x - P.SpatialBoundingBox.start.x); + Places[j][P.Nplace[j]].loc.y = (float)(y - P.SpatialBoundingBox.start.y); + if ((x >= P.SpatialBoundingBox.start.x) && (x < P.SpatialBoundingBox.end.x) && (y >= P.SpatialBoundingBox.start.y) && (y < P.SpatialBoundingBox.end.y)) { int i = P.nch * ((int)(Places[j][P.Nplace[j]].loc.x / P.in_cells_.width)) + ((int)(Places[j][P.Nplace[j]].loc.y / P.in_cells_.height)); if (Cells[i].n == 0) mr++; diff --git a/src/Update.cpp b/src/Update.cpp index e23a7f748..2b1c17fd2 100644 --- a/src/Update.cpp +++ b/src/Update.cpp @@ -96,8 +96,8 @@ void DoInfect(int ai, double t, int tn, int run) // Change person from susceptib StateT[tn].cumItype[a->infect_type % INFECT_TYPE_MASK]++; StateT[tn].cumIa[HOST_AGE_GROUP(ai)]++; //// calculate radius squared, and increment sum of radii squared. - x = (Households[a->hh].loc.x - P.LocationInitialInfection[0][0]); - y = (Households[a->hh].loc.y - P.LocationInitialInfection[0][1]); + x = (Households[a->hh].loc.x - P.LocationInitialInfection[0].x); + y = (Households[a->hh].loc.y - P.LocationInitialInfection[0].y); q = x * x + y * y; StateT[tn].sumRad2 += q; @@ -200,8 +200,8 @@ void RecordEvent(double t, int ai, int run, int type, int tn) //added int as arg InfEventLog[nEvents].t = t; InfEventLog[nEvents].infectee_ind = ai; InfEventLog[nEvents].infectee_adunit = Mcells[Hosts[ai].mcell].adunit; - InfEventLog[nEvents].infectee_x = Households[Hosts[ai].hh].loc.x + P.SpatialBoundingBox[0]; - InfEventLog[nEvents].infectee_y = Households[Hosts[ai].hh].loc.y + P.SpatialBoundingBox[1]; + InfEventLog[nEvents].infectee_x = Households[Hosts[ai].hh].loc.x + P.SpatialBoundingBox.start.x; + InfEventLog[nEvents].infectee_y = Households[Hosts[ai].hh].loc.y + P.SpatialBoundingBox.start.y; InfEventLog[nEvents].listpos = Hosts[ai].listpos; InfEventLog[nEvents].infectee_cell = Hosts[ai].pcell; InfEventLog[nEvents].thread = tn; From 36970506dd010fbb3c6b269ac7ee41cb52ca2cd3 Mon Sep 17 00:00:00 2001 From: Nicholas Rodine Date: Mon, 22 Jun 2020 15:20:54 -0500 Subject: [PATCH 3/4] Changed P.BoundingBox to be a Geometry::BoundingBox, and updated usages. --- src/CovidSim.cpp | 6 +++--- src/Param.h | 6 +++++- src/SetupModel.cpp | 8 ++++---- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/CovidSim.cpp b/src/CovidSim.cpp index e83e56188..9e8245977 100644 --- a/src/CovidSim.cpp +++ b/src/CovidSim.cpp @@ -1217,10 +1217,10 @@ void ReadParams(char* ParamFile, char* PreParamFile) P.CFR_ILI_ByAge[i] = 0.00; } - if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Bounding box for bitmap", "%lf", (void*) & (P.BoundingBox[0]), 4, 1, 0)) + if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Bounding box for bitmap", "%lf", (void*) & (P.BoundingBox.start.x), 4, 1, 0)) { - P.BoundingBox[0] = P.BoundingBox[1] = 0.0; - P.BoundingBox[2] = P.BoundingBox[3] = 1.0; + P.BoundingBox.start = Vector2(0, 0); + P.BoundingBox.end = Vector2(1, 1); } if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Spatial domain for simulation", "%lf", (void*) & (P.SpatialBoundingBox.start.x), 4, 1, 0)) { diff --git a/src/Param.h b/src/Param.h index 847979182..56fafe948 100644 --- a/src/Param.h +++ b/src/Param.h @@ -157,7 +157,11 @@ struct Param double PlaceCloseCasePropThresh, PlaceCloseAdunitPropThresh, PlaceCloseFracIncTrig; int DoHolidays, NumHolidays; double HolidayEffect[NUM_PLACE_TYPES], HolidayStartTime[DAYS_PER_YEAR], HolidayDuration[DAYS_PER_YEAR]; - double ColourPeriod, BoundingBox[4], BitmapScale; + double ColourPeriod; + + Geometry::BoundingBox BoundingBox; + + double BitmapScale; double TreatSuscDrop, TreatInfDrop, TreatDeathDrop, TreatSympDrop, TreatDelayMean, TreatTimeStart, TreatPlaceGeogDuration; double TreatProphCourseLength, TreatCaseCourseLength, TreatPropRadial, TreatRadius, TreatRadius2, TreatCellIncThresh; double CaseIsolation_CellIncThresh, HHQuar_CellIncThresh, DigitalContactTracing_CellIncThresh; diff --git a/src/SetupModel.cpp b/src/SetupModel.cpp index d347a22f7..26e66be07 100644 --- a/src/SetupModel.cpp +++ b/src/SetupModel.cpp @@ -184,15 +184,15 @@ void SetupModel(char* DensityFile, char* NetworkFile, char* SchoolFile, char* Re fprintf(stderr, "Number of microcells = %i\n", P.NMC); P.scale.x = P.BitmapScale; P.scale.y = P.BitmapAspectScale * P.BitmapScale; - P.b.width = (int)(P.in_degrees_.width * (P.BoundingBox[2] - P.BoundingBox[0]) * P.scale.x); + P.b.width = (int)(P.in_degrees_.width * (P.BoundingBox.width()) * P.scale.x); P.b.width = (P.b.width + 3) / 4; P.b.width *= 4; - P.b.height = (int)(P.in_degrees_.height * (P.BoundingBox[3] - P.BoundingBox[1]) * P.scale.y); + P.b.height = (int)(P.in_degrees_.height * (P.BoundingBox.height()) * P.scale.y); P.b.height += (4 - P.b.height % 4) % 4; P.bheight2 = P.b.height + 20; // space for colour legend fprintf(stderr, "Bitmap width = %i\nBitmap height = %i\n", P.b.width, P.b.height); - P.bmin.x = (int)(P.in_degrees_.width * P.BoundingBox[0] * P.scale.x); - P.bmin.y = (int)(P.in_degrees_.height * P.BoundingBox[1] * P.scale.y); + P.bmin.x = (int)(P.in_degrees_.width * P.BoundingBox.start.x * P.scale.x); + P.bmin.y = (int)(P.in_degrees_.height * P.BoundingBox.start.y * P.scale.y); P.in_microcells_.width = P.in_cells_.width / ((double)P.NMCL); P.in_microcells_.height = P.in_cells_.height / ((double)P.NMCL); for (int i = 0; i < P.NumSeedLocations; i++) From e27c374a579ec0d791ec42fb1cfd1c2be2f8cbfd Mon Sep 17 00:00:00 2001 From: Nicholas Rodine Date: Mon, 22 Jun 2020 15:28:15 -0500 Subject: [PATCH 4/4] Replaced infectee_x/y with infectee_position. Fixed usages. Added overload for adding Vector2 and Vector2. --- src/CovidSim.cpp | 5 +++-- src/Geometry/Vector2.cpp | 6 ++++++ src/Geometry/Vector2.h | 2 ++ src/Model.h | 4 +++- src/Update.cpp | 3 +-- 5 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/CovidSim.cpp b/src/CovidSim.cpp index 9e8245977..aa5684846 100644 --- a/src/CovidSim.cpp +++ b/src/CovidSim.cpp @@ -2780,7 +2780,8 @@ void InitModel(int run) // passing run number so we can save run number in the i nEvents = 0; for (int i = 0; i < P.MaxInfEvents; i++) { - InfEventLog[i].t = InfEventLog[i].infectee_x = InfEventLog[i].infectee_y = InfEventLog[i].t_infector = 0.0; + InfEventLog[i].infectee_position = Vector2(0, 0); + InfEventLog[i].t = InfEventLog[i].t_infector = 0.0; InfEventLog[i].infectee_ind = InfEventLog[i].infector_ind = 0; InfEventLog[i].infectee_adunit = InfEventLog[i].listpos = InfEventLog[i].infectee_cell = InfEventLog[i].infector_cell = InfEventLog[i].thread = 0; } @@ -4260,7 +4261,7 @@ void SaveEvents(void) for (i = 0; i < nEvents; i++) { fprintf(dat, "%i\t%.10f\t%i\t%i\t%i\t%i\t%i\t%.10f\t%.10f\t%.10f\t%i\t%i\n", - InfEventLog[i].type, InfEventLog[i].t, InfEventLog[i].thread, InfEventLog[i].infectee_ind, InfEventLog[i].infectee_cell, InfEventLog[i].listpos, InfEventLog[i].infectee_adunit, InfEventLog[i].infectee_x, InfEventLog[i].infectee_y, InfEventLog[i].t_infector, InfEventLog[i].infector_ind, InfEventLog[i].infector_cell); + InfEventLog[i].type, InfEventLog[i].t, InfEventLog[i].thread, InfEventLog[i].infectee_ind, InfEventLog[i].infectee_cell, InfEventLog[i].listpos, InfEventLog[i].infectee_adunit, InfEventLog[i].infectee_position.x, InfEventLog[i].infectee_position.y, InfEventLog[i].t_infector, InfEventLog[i].infector_ind, InfEventLog[i].infector_cell); } fclose(dat); } diff --git a/src/Geometry/Vector2.cpp b/src/Geometry/Vector2.cpp index 57930ed20..4779bd2c4 100644 --- a/src/Geometry/Vector2.cpp +++ b/src/Geometry/Vector2.cpp @@ -2,6 +2,12 @@ using namespace Geometry; +Vector2 Geometry::operator+(const Vector2 &left, const Vector2 &right){ + return left + Vector2(right); +} +Vector2 Geometry::operator+(const Vector2 &left, const Vector2 &right){ + return Vector2(left) + right; +} Vector2 Geometry::operator*(const Vector2 &left, const Vector2 &right){ return left * Vector2(right); } diff --git a/src/Geometry/Vector2.h b/src/Geometry/Vector2.h index 5fb4a54d0..320967470 100644 --- a/src/Geometry/Vector2.h +++ b/src/Geometry/Vector2.h @@ -149,6 +149,8 @@ namespace Geometry { return Vector2((U)this->x, (U)this->y); } + Vector2 operator+(const Vector2 &left, const Vector2 &right); + Vector2 operator+(const Vector2 &left, const Vector2 &right); Vector2 operator*(const Vector2 &left, const Vector2 &right); Vector2 operator*(const Vector2 &left, const Vector2 &right); diff --git a/src/Model.h b/src/Model.h index 5f321c237..16feb2677 100644 --- a/src/Model.h +++ b/src/Model.h @@ -185,7 +185,9 @@ const std::size_t ResultsDoubleOffsetStart = offsetof(Results, S) / sizeof(doubl */ struct Events { - double infectee_x, infectee_y, t, t_infector; + Geometry::Vector2 infectee_position; + + double t, t_infector; int run, infectee_ind, infector_ind, type, infectee_adunit, listpos, infectee_cell, infector_cell, thread; }; diff --git a/src/Update.cpp b/src/Update.cpp index 2b1c17fd2..203fb2ccb 100644 --- a/src/Update.cpp +++ b/src/Update.cpp @@ -200,8 +200,7 @@ void RecordEvent(double t, int ai, int run, int type, int tn) //added int as arg InfEventLog[nEvents].t = t; InfEventLog[nEvents].infectee_ind = ai; InfEventLog[nEvents].infectee_adunit = Mcells[Hosts[ai].mcell].adunit; - InfEventLog[nEvents].infectee_x = Households[Hosts[ai].hh].loc.x + P.SpatialBoundingBox.start.x; - InfEventLog[nEvents].infectee_y = Households[Hosts[ai].hh].loc.y + P.SpatialBoundingBox.start.y; + InfEventLog[nEvents].infectee_position = Households[Hosts[ai].hh].loc + P.SpatialBoundingBox.start; InfEventLog[nEvents].listpos = Hosts[ai].listpos; InfEventLog[nEvents].infectee_cell = Hosts[ai].pcell; InfEventLog[nEvents].thread = tn;