Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Param vector updates #418

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 22 additions & 22 deletions src/CovidSim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
#include <strings.h>
#endif

using namespace Geometry;

void ReadParams(char*, char*);
void ReadInterventions(char*);
int GetXMLNode(FILE*, const char*, const char*, char*, int);
Expand Down Expand Up @@ -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<double>(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;
Expand Down Expand Up @@ -1215,15 +1217,15 @@ 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<double>(0, 0);
P.BoundingBox.end = Vector2<double>(1, 1);
}
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<double>(0, 0);
P.SpatialBoundingBox.end = Vector2<double>(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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -2778,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<double>(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;
}
Expand Down Expand Up @@ -2827,8 +2830,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++)
Expand All @@ -2841,8 +2844,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<double>(Households[Hosts[l].hh].loc);
}
Hosts[l].infector = -2;
Hosts[l].infect_type = INFECT_TYPE_MASK - 1;
Expand Down Expand Up @@ -2874,8 +2876,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<double>(Households[Hosts[l].hh].loc);
Hosts[l].infector = -2; Hosts[l].infect_type = INFECT_TYPE_MASK - 1;
DoInfect(l, t, 0, run);
m = 0;
Expand Down Expand Up @@ -2910,8 +2911,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<double>(Households[Hosts[l].hh].loc);
Hosts[l].infector = -2; Hosts[l].infect_type = INFECT_TYPE_MASK - 1;
DoInfect(l, t, 0, run);
m = 0;
Expand Down Expand Up @@ -3409,7 +3409,7 @@ void SaveResults(void)
sprintf(outname, "%s.ge" DIRECTORY_SEPARATOR "%s.%i.png", OutFile, OutFile, i + 1);
fprintf(dat, "<Icon>\n<href>%s</href>\n</Icon>\n", outname);
fprintf(dat, "<LatLonBox>\n<north>%.10f</north>\n<south>%.10f</south>\n<east>%.10f</east>\n<west>%.10f</west>\n</LatLonBox>\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, "</GroundOverlay>\n");
}
fprintf(dat, "</Document>\n</kml>\n");
Expand Down Expand Up @@ -4261,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);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Dist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
6 changes: 6 additions & 0 deletions src/Geometry/Vector2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

using namespace Geometry;

Vector2<double> Geometry::operator+(const Vector2<double> &left, const Vector2<float> &right){
return left + Vector2<double>(right);
}
Vector2<double> Geometry::operator+(const Vector2<float> &left, const Vector2<double> &right){
return Vector2<double>(left) + right;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return Vector2<double>(left) + right;
return right + Vector2<double>(left);

Uses associativity of addition here. In that case, if you change something in one of the two, you don't have to change the other one.

}
Vector2<double> Geometry::operator*(const Vector2<double> &left, const Vector2<float> &right){
return left * Vector2<double>(right);
}
Expand Down
2 changes: 2 additions & 0 deletions src/Geometry/Vector2.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ namespace Geometry {
return Vector2<U>((U)this->x, (U)this->y);
}

Vector2<double> operator+(const Vector2<double> &left, const Vector2<float> &right);
Vector2<double> operator+(const Vector2<float> &left, const Vector2<double> &right);
Vector2<double> operator*(const Vector2<double> &left, const Vector2<float> &right);
Vector2<double> operator*(const Vector2<float> &left, const Vector2<double> &right);

Expand Down
4 changes: 3 additions & 1 deletion src/Model.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<double> infectee_position;

double t, t_infector;
int run, infectee_ind, infector_ind, type, infectee_adunit, listpos, infectee_cell, infector_cell, thread;
};

Expand Down
13 changes: 11 additions & 2 deletions src/Param.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "MicroCellPosition.hpp"

#include "Geometry/Size.h"
#include "Geometry/BoundingBox.h"

/** @brief Enumeration of bitmap formats. */
enum struct BitmapFormats
Expand Down Expand Up @@ -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<double> SpatialBoundingBox;
Geometry::Vector2<double> 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];

Expand Down Expand Up @@ -152,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<double> 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;
Expand Down
Loading