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

Feature/move max iter grnd canopy #771

Merged
merged 13 commits into from
Jan 31, 2018
Merged
20 changes: 20 additions & 0 deletions docs/Development/ReleaseNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,26 @@ To check which release of VIC you are running:

The VIC image driver can be optionally compiled with ROUT_RVIC to enable routing in image mode (ROUT_STUB is the default extension which means no routing). With ROUT_RVIC enabled, the output variable ``OUT_DISCHARGE`` is available, and there will also be an extra state variable ``STATE_ROUT_RING`` stored in the state file.

9. Moved MAX_ITER_GRND_CANOPY, which controls the maximum number of ground-canopy iterations in CLOSE_ENERGY mode for vegetation types with an overstory, to the parameters struct ([GH#771](https://github.com/UW-Hydro/VIC/pull/771))

Previously this was set in the surface_fluxes.c numerics routine for ground-canopy iterations, which meant that that routine had to be altered to change the maximum number of iterations. It has now been moved to the parameters struct so that it can be overriden in the constants file.

10. Miscellaneous clean-up:

[GH#723](https://github.com/UW-Hydro/VIC/pull/723)

1. Added support for veg_hist forcings (non-climatological) in image mode
2. Fixed erroneous allocation of extra veg tile in image mode
3. Simplified looping over veg tiles and bands in vic_run() and prepare_full_energy()
4. Replaced lengthy data structures with local pointers in vic_run()
5. Simplified out_prec, out_rain, and Melt arrays
6. Updated names of variables and options for LAI and FCANOPY in documentation to match their new names in the code
7. Removed constants MAX_VEG and MAX_BANDS from code; all arrays that were declared with those lengths were replaced with dynamic allocations. This allowed for specification of veg libraries containing more classes without recompiling the code, and more efficient memory usage.

[GH#766](https://github.com/UW-Hydro/VIC/pull/766)

1. Improved logic in computing soil evaporation (esoil), primarily in func_surf_energy_bal(), by creating explicit terms for transpiration (transp) and esoil in the layer data structure.

#### Bug Fixes:

1. Renamed "fcov" to "fcan" in image driver to better match variable code name ([GH#673](https://github.com/UW-Hydro/VIC/pull/673))
Expand Down
1 change: 1 addition & 0 deletions docs/Documentation/Constants.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ The table below lists the constants available for manipulation via the `CONSTANT
| TOL_GRND | |
| TOL_OVER | |
| FROZEN_MAXITER | |
| MAX_ITER_GRND_CANOPY | |
| NEWT_RAPH_MAXTRIAL | |
| NEWT_RAPH_TOLX | |
| NEWT_RAPH_TOLF | |
Expand Down
6 changes: 3 additions & 3 deletions vic/drivers/cesm/bld/vic.constants.txt
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@
# Frozen Soil Parameters
# FROZEN_MAXITER 1000

# Canopy Iterations
# MAX_ITER_GRND_CANOPY 10

# Newton-Raphson solver parameters
# NEWT_RAPH_MAXTRIAL 150
# NEWT_RAPH_TOLX 1.0e-4
Expand All @@ -188,6 +191,3 @@
# ROOT_BRENT_MAXITER 1000
# ROOT_BRENT_TSTEP 10
# ROOT_BRENT_T 1.0e-7

# Frozen Soil Parameters
# FROZEN_MAXITER 1000
9 changes: 9 additions & 0 deletions vic/drivers/shared_all/src/get_parameters.c
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,10 @@ get_parameters(FILE *paramfile)
else if (strcasecmp("FROZEN_MAXITER", optstr) == 0) {
sscanf(cmdstr, "%*s %d", &param.FROZEN_MAXITER);
}
// Canopy Iterations
else if (strcasecmp("MAX_ITER_GRND_CANOPY", optstr) == 0) {
sscanf(cmdstr, "%*s %d", &param.MAX_ITER_GRND_CANOPY);
}
// Newton-Raphson Solver Parameters
else if (strcasecmp("NEWT_RAPH_MAXTRIAL", optstr) == 0) {
sscanf(cmdstr, "%*s %d", &param.NEWT_RAPH_MAXTRIAL);
Expand Down Expand Up @@ -880,6 +884,11 @@ validate_parameters()
log_err(
"FROZEN_MAXITER must be defined on the interval [0, inf) (iterations");
}
// Canopy Iterations
if (!(param.MAX_ITER_GRND_CANOPY >= 0)) {
log_err(
"MAX_ITER_GRND_CANOPY must be defined on the interval [0, inf) (iterations");
}
// Newton-Raphson Solver Parameters
if (!(param.NEWT_RAPH_MAXTRIAL >= 0)) {
log_err(
Expand Down
10 changes: 10 additions & 0 deletions vic/drivers/shared_all/src/initialize_parameters.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ void
initialize_parameters()
{
extern parameters_struct param;
extern option_struct options;
// Initialize temporary parameters

// Lapse Rate
Expand Down Expand Up @@ -211,6 +212,15 @@ initialize_parameters()
// Frozen Soil Parameters
param.FROZEN_MAXITER = 1000;

// Canopy Iterations
if (options.CLOSE_ENERGY) {
// iterate to close energy balance
param.MAX_ITER_GRND_CANOPY = 10;
}
else {
param.MAX_ITER_GRND_CANOPY = 0;
}

// Newton-Raphson solver parameters
param.NEWT_RAPH_MAXTRIAL = 150;
param.NEWT_RAPH_TOLX = 1.0e-4;
Expand Down
2 changes: 2 additions & 0 deletions vic/drivers/shared_all/src/print_library_shared.c
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,8 @@ print_parameters(parameters_struct *param)
fprintf(LOG_DEST, "\tTOL_GRND: %.4f\n", param->TOL_GRND);
fprintf(LOG_DEST, "\tTOL_OVER: %.4f\n", param->TOL_OVER);
fprintf(LOG_DEST, "\tFROZEN_MAXITER: %d\n", param->FROZEN_MAXITER);
fprintf(LOG_DEST, "\tMAX_ITER_GRND_CANOPY: %d\n",
param->MAX_ITER_GRND_CANOPY);
fprintf(LOG_DEST, "\tNEWT_RAPH_MAXTRIAL: %d\n", param->NEWT_RAPH_MAXTRIAL);
fprintf(LOG_DEST, "\tNEWT_RAPH_TOLX: %.4f\n", param->NEWT_RAPH_TOLX);
fprintf(LOG_DEST, "\tNEWT_RAPH_TOLF: %.4f\n", param->NEWT_RAPH_TOLF);
Expand Down
6 changes: 5 additions & 1 deletion vic/drivers/shared_image/src/vic_mpi_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,7 @@ create_MPI_param_struct_type(MPI_Datatype *mpi_type)
MPI_Datatype *mpi_types;

// nitems has to equal the number of elements in parameters_struct
nitems = 153;
nitems = 154;
blocklengths = malloc(nitems * sizeof(*blocklengths));
check_alloc_status(blocklengths, "Memory allocation error.");

Expand Down Expand Up @@ -1333,6 +1333,10 @@ create_MPI_param_struct_type(MPI_Datatype *mpi_type)
offsets[i] = offsetof(parameters_struct, FROZEN_MAXITER);
mpi_types[i++] = MPI_INT;

// int MAX_ITER_GRND_CANOPY
offsets[i] = offsetof(parameters_struct, MAX_ITER_GRND_CANOPY);
mpi_types[i++] = MPI_INT;

// int NEWT_RAPH_MAXTRIAL
offsets[i] = offsetof(parameters_struct, NEWT_RAPH_MAXTRIAL);
mpi_types[i++] = MPI_INT;
Expand Down
3 changes: 3 additions & 0 deletions vic/vic_run/include/vic_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,9 @@ typedef struct {
// Frozen Soil Parameters
int FROZEN_MAXITER;

// Canopy Iterations
int MAX_ITER_GRND_CANOPY;

// Newton-Raphson Solver Parameters
int NEWT_RAPH_MAXTRIAL;
double NEWT_RAPH_TOLX;
Expand Down
13 changes: 3 additions & 10 deletions vic/vic_run/src/surface_fluxes.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ surface_fluxes(bool overstory,
extern option_struct options;
extern parameters_struct param;

int MAX_ITER_GRND_CANOPY;
int ErrorFlag;
int INCLUDE_SNOW = false;
int UNSTABLE_CNT;
Expand Down Expand Up @@ -225,13 +224,6 @@ surface_fluxes(bool overstory,
double store_Raut;
double store_NPP;

if (options.CLOSE_ENERGY) {
MAX_ITER_GRND_CANOPY = 10;
}
else {
MAX_ITER_GRND_CANOPY = 0;
}

if (options.CARBON) {
store_gsLayer = calloc(options.Ncanopy, sizeof(*store_gsLayer));
check_alloc_status(store_gsLayer, "Memory allocation error.");
Expand Down Expand Up @@ -722,11 +714,12 @@ surface_fluxes(bool overstory,
}
}
while ((fabs(tol_under - last_tol_under) > param.TOL_GRND) &&
(tol_under != 0) && (under_iter < MAX_ITER_GRND_CANOPY));
(tol_under != 0) &&
(under_iter < param.MAX_ITER_GRND_CANOPY));
}
while ((fabs(tol_over - last_tol_over) > param.TOL_OVER &&
overstory) && (tol_over != 0) &&
(over_iter < MAX_ITER_GRND_CANOPY));
(over_iter < param.MAX_ITER_GRND_CANOPY));

/**************************************
Compute GPP, Raut, and NPP
Expand Down