Skip to content

Commit

Permalink
Refactored VerifyGeography
Browse files Browse the repository at this point in the history
  • Loading branch information
RoryBarnes committed Sep 15, 2024
1 parent e83cad5 commit 97954f7
Show file tree
Hide file tree
Showing 2 changed files with 158 additions and 76 deletions.
182 changes: 132 additions & 50 deletions src/poise.c
Original file line number Diff line number Diff line change
Expand Up @@ -607,15 +607,15 @@ void ReadGeography(BODY *body, CONTROL *control, FILES *files, OPTIONS *options,
//CheckDuplication(files,options,files->Infile[iFile].cIn,lTmp,\
control->Io.iVerbose);
if (!memcmp(sLower(cTmp), "u", 1)) {
body[iFile - 1].iGeography = LANDWATERUNIFORM;
body[iFile - 1].iGeography = GEOGRAPHYUNIFORM;
} else if (!memcmp(sLower(cTmp), "m", 1)) {
body[iFile - 1].iGeography = LANDWATERMODERN;
body[iFile - 1].iGeography = GEOGRAPHYMODERN;
} else if (!memcmp(sLower(cTmp), "r", 1)) {
body[iFile - 1].iGeography = LANDWATERRANDOM;
body[iFile - 1].iGeography = GEOGRAPHYRANDOM;
} else if (!memcmp(sLower(cTmp), "p", 1)) {
body[iFile - 1].iGeography = LANDWATERPOLAR;
body[iFile - 1].iGeography = GEOGRAPHYPOLAR;
} else if (!memcmp(sLower(cTmp), "e", 1)) {
body[iFile - 1].iGeography = LANDWATEREQUATORIAL;
body[iFile - 1].iGeography = GEOGRAPHYEQUATORIAL;
} else {
if (control->Io.iVerbose >= VERBERR) {
fprintf(stderr,
Expand Down Expand Up @@ -1606,7 +1606,7 @@ void InitializeOptionsPoise(OPTIONS *options, fnReadOption fnRead[]) {
fvFormattedString(&options[OPT_GEOGRAPHY].cDescr,
"Type of land distribution");
fvFormattedString(&options[OPT_GEOGRAPHY].cDefault, "uniform");
options[OPT_GEOGRAPHY].dDefault = LANDWATERUNIFORM;
options[OPT_GEOGRAPHY].dDefault = GEOGRAPHYUNIFORM;
options[OPT_GEOGRAPHY].iType = 3;
options[OPT_GEOGRAPHY].bMultiFile = 1;
fnRead[OPT_GEOGRAPHY] = &ReadGeography;
Expand Down Expand Up @@ -2205,15 +2205,15 @@ void InitializeLandWater(BODY *body, int iBody) {
body[iBody].daLandFrac = malloc(body[iBody].iNumLats * sizeof(double));
body[iBody].daWaterFrac = malloc(body[iBody].iNumLats * sizeof(double));

if (body[iBody].iGeography == LANDWATERUNIFORM) {
if (body[iBody].iGeography == GEOGRAPHYUNIFORM) {
fvInitializeLandWaterUniform(body, iBody);
} else if (body[iBody].iGeography == LANDWATERMODERN) {
} else if (body[iBody].iGeography == GEOGRAPHYMODERN) {
fvInitializeLandWaterModern(body, iBody);
} else if (body[iBody].iGeography == LANDWATERRANDOM) {
} else if (body[iBody].iGeography == GEOGRAPHYRANDOM) {
fvInitializeLandWaterRandom(body, iBody);
} else if (body[iBody].iGeography == LANDWATERPOLAR) {
} else if (body[iBody].iGeography == GEOGRAPHYPOLAR) {
fvInitializeLandWaterPolar(body, iBody);
} else if (body[iBody].iGeography == LANDWATEREQUATORIAL) {
} else if (body[iBody].iGeography == GEOGRAPHYEQUATORIAL) {
fvInitializeLandWaterEquatorial(body, iBody);
}

Expand Down Expand Up @@ -2898,58 +2898,140 @@ void NullPoiseDerivatives(BODY *body, EVOLVE *evolve, UPDATE *update,
// Nothing here, because entire climate simulation is ran in ForceBehavior
}

void VerifyGeography(BODY *body, CONTROL *control, OPTIONS *options,
SYSTEM *system, int iBody) {
void fvGeographyExitLandWaterLatitude(CONTROL *control, OPTIONS *options,
int iBody) {
if (control->Io.iVerbose > VERBINPUT) {
fprintf(stderr,
"ERROR: Cannot set %s with \"uniform\", \"modern\", or "
"\"random\" geography. "
"Note that \"uniform\" is the default.\n",
options[OPT_LANDWATERLATITUDE].cName);
}
DoubleLineExit(options[OPT_LANDWATERLATITUDE].cFile[iBody + 1],
options[OPT_GEOGRAPHY].cFile[iBody + 1],
options[OPT_LANDWATERLATITUDE].iLine[iBody + 1],
options[OPT_GEOGRAPHY].iLine[iBody + 1]);
}

if (body[iBody].iGeography == LANDWATERUNIFORM ||
body[iBody].iGeography == LANDWATERMODERN ||
body[iBody].iGeography == LANDWATERRANDOM) {
if (options[OPT_LANDWATERLATITUDE].iLine[iBody + 1] != -1) {
if (control->Io.iVerbose > VERBINPUT) {
fprintf(stderr,
"ERROR: Cannot set %s with \"uniform\", \"modern\", or "
"\"random\" geography. "
"Note that \"uniform\" is the default.\n",
options[OPT_LANDWATERLATITUDE].cName);
}
DoubleLineExit(options[OPT_LANDWATERLATITUDE].cFile[iBody + 1],
options[OPT_GEOGRAPHY].cFile[iBody + 1],
options[OPT_LANDWATERLATITUDE].iLine[iBody + 1],
options[OPT_GEOGRAPHY].iLine[iBody + 1]);
}
void fvGeographyExitLandFracMean(CONTROL *control, OPTIONS *options,
int iBody) {
if (control->Io.iVerbose > VERBINPUT) {
fprintf(stderr,
"ERROR: Cannot set %s with \"uniform\", \"modern\", \"polar\" or "
"\"equatorial\" geography. "
"Note that \"uniform\" is the default.\n",
options[OPT_LANDWATERLATITUDE].cName);
}
DoubleLineExit(options[OPT_LANDFRACMEAN].cFile[iBody + 1],
options[OPT_GEOGRAPHY].cFile[iBody + 1],
options[OPT_LANDFRACMEAN].iLine[iBody + 1],
options[OPT_GEOGRAPHY].iLine[iBody + 1]);
}

if (body[iBody].iGeography == LANDWATERMODERN ||
body[iBody].iGeography == LANDWATERRANDOM ||
body[iBody].iGeography == LANDWATERPOLAR ||
body[iBody].iGeography == LANDWATEREQUATORIAL) {
if (options[OPT_LANDFRAC].iLine[iBody + 1] != -1) {
if (control->Io.iVerbose > VERBINPUT) {
fprintf(stderr,
"ERROR: %s can only be set when %s is set to \"uniform\". Note "
"that \"uniform\" is the default.\n",
options[OPT_LANDFRAC].cName, options[OPT_GEOGRAPHY].cName);
}
}
void fvGeographyExitLandFracAmp(CONTROL *control, OPTIONS *options, int iBody) {
if (control->Io.iVerbose > VERBINPUT) {
fprintf(stderr,
"ERROR: Cannot set %s with \"uniform\", \"modern\", \"polar\" or "
"\"equatorial\" geography. "
"Note that \"uniform\" is the default.\n",
options[OPT_LANDWATERLATITUDE].cName);
}
DoubleLineExit(options[OPT_LANDFRACAMP].cFile[iBody + 1],
options[OPT_GEOGRAPHY].cFile[iBody + 1],
options[OPT_LANDFRACAMP].iLine[iBody + 1],
options[OPT_GEOGRAPHY].iLine[iBody + 1]);
}

void fvGeographyExitLandFrac(CONTROL *control, OPTIONS *options, int iBody) {
if (control->Io.iVerbose > VERBINPUT) {
fprintf(stderr,
"ERROR: %s can only be set when %s is set to \"uniform\". Note "
"that \"uniform\" is the default.\n",
options[OPT_LANDFRAC].cName, options[OPT_GEOGRAPHY].cName);
}
DoubleLineExit(options[OPT_LANDFRAC].cFile[iBody + 1],
options[OPT_GEOGRAPHY].cFile[iBody + 1],
options[OPT_LANDFRAC].iLine[iBody + 1],
options[OPT_GEOGRAPHY].iLine[iBody + 1]);
}

if (body[iBody].iGeography == LANDWATERRANDOM &&
options[OPT_RANDSEED].iLine[iBody + 1] == -1) {
void fvVerifyLatitudeMeanAndAmpNotSet(CONTROL *control, OPTIONS *options,
int iBody) {
if (options[OPT_LANDWATERLATITUDE].iLine[iBody + 1] != -1) {
fvGeographyExitLandWaterLatitude(control, options, iBody);
}
if (options[OPT_LANDFRACMEAN].iLine[iBody + 1] != -1) {
fvGeographyExitLandFracMean(control, options, iBody);
}
if (options[OPT_LANDFRACAMP].iLine[iBody + 1] != -1) {
fvGeographyExitLandFracAmp(control, options, iBody);
}
}

void fvVerifyGeographyUniform(CONTROL *control, OPTIONS *options, int iBody) {
fvVerifyLatitudeMeanAndAmpNotSet(control, options, iBody);
}

void fvVerifyGeographyModern(CONTROL *control, OPTIONS *options, int iBody) {
fvVerifyLatitudeMeanAndAmpNotSet(control, options, iBody);
if (options[OPT_LANDFRAC].iLine[iBody + 1] != -1) {
fvGeographyExitLandFrac(control, options, iBody);
}
}

void fvVerifyGeographyRandom(CONTROL *control, OPTIONS *options, SYSTEM *system,
int iBody) {
fvVerifyLatitudeMeanAndAmpNotSet(control, options, iBody);
if (options[OPT_RANDSEED].iLine[iBody + 1] == -1) {
if (control->Io.iVerbose > VERBINPUT) {
fprintf(stderr,
"\nWARNING: %s is set to \"radnom\", but %s is not set.\n\n",
"\nWARNING: %s is set to \"random\", but %s is not set.\n\n",
options[OPT_GEOGRAPHY].cName, options[OPT_RANDSEED].cName);
}
}
srand(system->iSeed);
}

if (body[iBody].iGeography == LANDWATERRANDOM) {
srand(system->iSeed);
void fvVerifyGeographyPolarEquatorial(BODY *body, CONTROL *control,
OPTIONS *options, int iBody) {
if (options[OPT_LANDFRACMEAN].iLine[iBody + 1] != -1) {
fvGeographyExitLandFracMean(control, options, iBody);
}
if (options[OPT_LANDFRACAMP].iLine[iBody + 1] != -1) {
fvGeographyExitLandFracAmp(control, options, iBody);
}
if (options[OPT_LANDFRAC].iLine[iBody + 1] != -1) {
fvGeographyExitLandFrac(control, options, iBody);
}
if (options[OPT_LANDWATERLATITUDE].iLine[iBody + 1] != -1) {
if (control->Io.iVerbose > VERBINPUT) {
fprintf(stderr, "\nWARNING: %s set to \"", options[OPT_GEOGRAPHY].cName);
if (body[iBody].iGeography == GEOGRAPHYPOLAR) {
fprintf(stderr, "polar");
} else if (body[iBody].iGeography == GEOGRAPHYEQUATORIAL) {
fprintf(stderr, "equatorial");
}
fprintf(stderr, "\" but %s is not set.\n",
options[OPT_LANDWATERLATITUDE].cName);
}
}

body[iBody].iLatLandWater =
(int)(body[iBody].dLatLandWater * body[iBody].iNumLats / PI);
}

void VerifyGeography(BODY *body, CONTROL *control, OPTIONS *options,
SYSTEM *system, int iBody) {

if (body[iBody].iGeography == LANDWATERPOLAR ||
body[iBody].iGeography == LANDWATEREQUATORIAL) {
body[iBody].iLatLandWater =
(int)(body[iBody].dLatLandWater * body[iBody].iNumLats / PI);
if (body[iBody].iGeography == GEOGRAPHYUNIFORM) {
fvVerifyGeographyUniform(control, options, iBody);
} else if (body[iBody].iGeography == GEOGRAPHYMODERN) {
fvVerifyGeographyModern(control, options, iBody);
} else if (body[iBody].iGeography == GEOGRAPHYRANDOM) {
fvVerifyGeographyRandom(control, options, system, iBody);
} else if (body[iBody].iGeography == GEOGRAPHYPOLAR ||
body[iBody].iGeography == GEOGRAPHYEQUATORIAL) {
fvVerifyGeographyPolarEquatorial(body, control, options, iBody);
}
}

Expand Down
52 changes: 26 additions & 26 deletions src/poise.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
#define ALBTAYLOR 1

/* Land Geography */
#define LANDWATERUNIFORM 0
#define LANDWATERMODERN 1
#define LANDWATERRANDOM 2
#define LANDWATERPOLAR 3
#define LANDWATEREQUATORIAL 4
#define GEOGRAPHYUNIFORM 0
#define GEOGRAPHYMODERN 1
#define GEOGRAPHYRANDOM 2
#define GEOGRAPHYPOLAR 3
#define GEOGRAPHYEQUATORIAL 4

// Constants for the ice model
#define LFICE 3.34e5 // ???
Expand Down Expand Up @@ -83,16 +83,16 @@
#define OPT_SKIPSEASENABLED 1921
#define OPT_DIFFROT 1922
#define OPT_SPINUPTOL 1923
#define OPT_READORBITOBLDATA 1924
#define OPT_FILEORBITOBLDATA 1925
#define OPT_READORBITOBLDATA 1924
#define OPT_FILEORBITOBLDATA 1925

#define OPT_LANDFRAC 1940
#define OPT_LANDFRACMEAN 1941
#define OPT_LANDFRACAMP 1942
#define OPT_HEATCAPLAND 1943
#define OPT_HEATCAPWATER 1944
#define OPT_FRZTSEAICE 1945
//#define OPT_LATENTHEAT 1945
// #define OPT_LATENTHEAT 1945
#define OPT_ICECONDUCT 1946
#define OPT_MIXINGDEPTH 1947
#define OPT_NULANDWATER 1948
Expand Down Expand Up @@ -198,7 +198,7 @@ void HelpOptionsPoise(OPTIONS *);
void InitializeOptionsPoise(OPTIONS *, fnReadOption[]);
void ReadOptionsPoise(BODY *, CONTROL *, FILES *, OPTIONS *, SYSTEM *,
fnReadOption[], int);
void ReadOrbitOblData(BODY*,CONTROL*,FILES*,OPTIONS*,SYSTEM*,int);
void ReadOrbitOblData(BODY *, CONTROL *, FILES *, OPTIONS *, SYSTEM *, int);

/* Verify Functions */
void VerifyPoise(BODY *, CONTROL *, FILES *, OPTIONS *, OUTPUT *, SYSTEM *,
Expand All @@ -217,39 +217,39 @@ void FinalizeUpdateIceMassPoise(BODY *, UPDATE *, int *, int, int, int);

void HelpOutputPoise(OUTPUT *);
void WriteTGlobal(BODY *, CONTROL *, OUTPUT *, SYSTEM *, UNITS *, UPDATE *, int,
double *, char**);
double *, char **);
void WriteAlbedoGlobal(BODY *, CONTROL *, OUTPUT *, SYSTEM *, UNITS *, UPDATE *,
int, double *, char**);
int, double *, char **);
void WriteTempLat(BODY *, CONTROL *, OUTPUT *, SYSTEM *, UNITS *, UPDATE *, int,
double *, char**);
double *, char **);
void WriteTempMinLW(BODY *, CONTROL *, OUTPUT *, SYSTEM *, UNITS *, UPDATE *,
int, double *, char**);
int, double *, char **);
void WriteTempMaxLW(BODY *, CONTROL *, OUTPUT *, SYSTEM *, UNITS *, UPDATE *,
int, double *, char**);
int, double *, char **);
void WriteAlbedoLat(BODY *, CONTROL *, OUTPUT *, SYSTEM *, UNITS *, UPDATE *,
int, double *, char**);
int, double *, char **);
void WriteAnnualInsol(BODY *, CONTROL *, OUTPUT *, SYSTEM *, UNITS *, UPDATE *,
int, double *, char**);
int, double *, char **);
void WriteDailyInsol(BODY *, CONTROL *, OUTPUT *, SYSTEM *, UNITS *, UPDATE *,
int, double *, char**);
int, double *, char **);
void WritePlanckB(BODY *, CONTROL *, OUTPUT *, SYSTEM *, UNITS *, UPDATE *, int,
double *, char**);
double *, char **);
void WritePlanckBAvg(BODY *, CONTROL *, OUTPUT *, SYSTEM *, UNITS *, UPDATE *,
int, double *, char**);
int, double *, char **);
void WriteSeasonalTemp(BODY *, CONTROL *, OUTPUT *, SYSTEM *, UNITS *, UPDATE *,
int, double *, char**);
int, double *, char **);
void WriteSeasonalFluxes(BODY *, CONTROL *, OUTPUT *, SYSTEM *, UNITS *,
UPDATE *, int, double *, char**);
UPDATE *, int, double *, char **);
void WriteSeasonalIceBalance(BODY *, CONTROL *, OUTPUT *, SYSTEM *, UNITS *,
UPDATE *, int, double *, char**);
UPDATE *, int, double *, char **);
void WriteFluxMerid(BODY *, CONTROL *, OUTPUT *, SYSTEM *, UNITS *, UPDATE *,
int, double *, char**);
int, double *, char **);
void WriteFluxIn(BODY *, CONTROL *, OUTPUT *, SYSTEM *, UNITS *, UPDATE *, int,
double *, char**);
double *, char **);
void WriteFluxOut(BODY *, CONTROL *, OUTPUT *, SYSTEM *, UNITS *, UPDATE *, int,
double *, char**);
double *, char **);
void WriteDivFlux(BODY *, CONTROL *, OUTPUT *, SYSTEM *, UNITS *, UPDATE *, int,
double *, char**);
double *, char **);
void InitializeOutputPoise(OUTPUT *, fnWriteOutput[]);

/* Logging Functions */
Expand Down

0 comments on commit 97954f7

Please sign in to comment.