From a29c12d44ded99c51da8491f8989cc8557028b2f Mon Sep 17 00:00:00 2001 From: Diana Gergel Date: Mon, 15 Jan 2018 16:59:21 -0800 Subject: [PATCH 1/8] initial commit to move MAX_ITER_GRND_CANOPY to param struct in order to modify it more easily --- docs/Documentation/Constants.md | 1 + vic/drivers/cesm/bld/vic.constants.txt | 6 +++--- vic/drivers/shared_all/src/get_parameters.c | 9 +++++++++ vic/drivers/shared_all/src/initialize_parameters.c | 3 +++ vic/drivers/shared_all/src/print_library_shared.c | 1 + vic/drivers/shared_image/src/vic_mpi_support.c | 4 ++++ vic/vic_run/include/vic_def.h | 3 +++ vic/vic_run/src/surface_fluxes.c | 13 +++++-------- 8 files changed, 29 insertions(+), 11 deletions(-) diff --git a/docs/Documentation/Constants.md b/docs/Documentation/Constants.md index 27fffda65..a8a3d9b4a 100644 --- a/docs/Documentation/Constants.md +++ b/docs/Documentation/Constants.md @@ -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 | | diff --git a/vic/drivers/cesm/bld/vic.constants.txt b/vic/drivers/cesm/bld/vic.constants.txt index c9350bafc..c0bbf9086 100644 --- a/vic/drivers/cesm/bld/vic.constants.txt +++ b/vic/drivers/cesm/bld/vic.constants.txt @@ -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 @@ -188,6 +191,3 @@ # ROOT_BRENT_MAXITER 1000 # ROOT_BRENT_TSTEP 10 # ROOT_BRENT_T 1.0e-7 - -# Frozen Soil Parameters -# FROZEN_MAXITER 1000 diff --git a/vic/drivers/shared_all/src/get_parameters.c b/vic/drivers/shared_all/src/get_parameters.c index 45b8aa6f4..26024d5e8 100644 --- a/vic/drivers/shared_all/src/get_parameters.c +++ b/vic/drivers/shared_all/src/get_parameters.c @@ -481,6 +481,10 @@ get_parameters(FILE *paramfile) else if (strcasecmp("FROZEN_MAXITER", optstr) == 0) { sscanf(cmdstr, "%*s %d", ¶m.FROZEN_MAXITER); } + // Canopy Iterations + else if (strcasecmp("MAX_ITER_GRND_CANOPY", optstr) == 0) { + sscanf(cmdstr, "%*s %d", ¶m.MAX_ITER_GRND_CANOPY); + } // Newton-Raphson Solver Parameters else if (strcasecmp("NEWT_RAPH_MAXTRIAL", optstr) == 0) { sscanf(cmdstr, "%*s %d", ¶m.NEWT_RAPH_MAXTRIAL); @@ -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( diff --git a/vic/drivers/shared_all/src/initialize_parameters.c b/vic/drivers/shared_all/src/initialize_parameters.c index 1add5498d..b677f9f69 100644 --- a/vic/drivers/shared_all/src/initialize_parameters.c +++ b/vic/drivers/shared_all/src/initialize_parameters.c @@ -211,6 +211,9 @@ initialize_parameters() // Frozen Soil Parameters param.FROZEN_MAXITER = 1000; + // Canopy Iterations + param.MAX_ITER_GRND_CANOPY = 10; + // Newton-Raphson solver parameters param.NEWT_RAPH_MAXTRIAL = 150; param.NEWT_RAPH_TOLX = 1.0e-4; diff --git a/vic/drivers/shared_all/src/print_library_shared.c b/vic/drivers/shared_all/src/print_library_shared.c index ef9efdeaa..ccbd9b223 100644 --- a/vic/drivers/shared_all/src/print_library_shared.c +++ b/vic/drivers/shared_all/src/print_library_shared.c @@ -797,6 +797,7 @@ 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); diff --git a/vic/drivers/shared_image/src/vic_mpi_support.c b/vic/drivers/shared_image/src/vic_mpi_support.c index ed92f10fc..3be4745e6 100644 --- a/vic/drivers/shared_image/src/vic_mpi_support.c +++ b/vic/drivers/shared_image/src/vic_mpi_support.c @@ -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; diff --git a/vic/vic_run/include/vic_def.h b/vic/vic_run/include/vic_def.h index 184ede176..0ad47f2c5 100644 --- a/vic/vic_run/include/vic_def.h +++ b/vic/vic_run/include/vic_def.h @@ -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; diff --git a/vic/vic_run/src/surface_fluxes.c b/vic/vic_run/src/surface_fluxes.c index 8354ba743..d32749b60 100644 --- a/vic/vic_run/src/surface_fluxes.c +++ b/vic/vic_run/src/surface_fluxes.c @@ -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; @@ -225,11 +224,9 @@ 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.CLOSE_ENERGY) { + // if not closing energy balance, don't iterate + param.MAX_ITER_CANOPY_GRND = 0; } if (options.CARBON) { @@ -722,11 +719,11 @@ 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_CANOPY_GRND)); } 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_CANOPY_GRND)); /************************************** Compute GPP, Raut, and NPP From 503b3bbe9222b14611749226f13aaeecdfcbf246 Mon Sep 17 00:00:00 2001 From: Diana Gergel Date: Mon, 15 Jan 2018 20:07:22 -0500 Subject: [PATCH 2/8] fix typos --- vic/vic_run/src/surface_fluxes.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/vic/vic_run/src/surface_fluxes.c b/vic/vic_run/src/surface_fluxes.c index d32749b60..12f4a9140 100644 --- a/vic/vic_run/src/surface_fluxes.c +++ b/vic/vic_run/src/surface_fluxes.c @@ -226,7 +226,7 @@ surface_fluxes(bool overstory, if (!options.CLOSE_ENERGY) { // if not closing energy balance, don't iterate - param.MAX_ITER_CANOPY_GRND = 0; + param.MAX_ITER_GRND_CANOPY = 0; } if (options.CARBON) { @@ -719,11 +719,11 @@ surface_fluxes(bool overstory, } } while ((fabs(tol_under - last_tol_under) > param.TOL_GRND) && - (tol_under != 0) && (under_iter < param.MAX_ITER_CANOPY_GRND)); + (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 < param.MAX_ITER_CANOPY_GRND)); + (over_iter < param.MAX_ITER_GRND_CANOPY)); /************************************** Compute GPP, Raut, and NPP From 468287ce43c71933cb273cb13679258f4f60b7c8 Mon Sep 17 00:00:00 2001 From: Diana Gergel Date: Mon, 15 Jan 2018 20:36:58 -0500 Subject: [PATCH 3/8] fix mpi bug --- vic/drivers/shared_image/src/vic_mpi_support.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vic/drivers/shared_image/src/vic_mpi_support.c b/vic/drivers/shared_image/src/vic_mpi_support.c index 3be4745e6..371c92bec 100644 --- a/vic/drivers/shared_image/src/vic_mpi_support.c +++ b/vic/drivers/shared_image/src/vic_mpi_support.c @@ -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."); From c33a0b3be8b4b5d6b775262812a6fb436cc442f0 Mon Sep 17 00:00:00 2001 From: Diana Gergel Date: Mon, 15 Jan 2018 17:49:38 -0800 Subject: [PATCH 4/8] add release notes entry --- docs/Development/ReleaseNotes.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/Development/ReleaseNotes.md b/docs/Development/ReleaseNotes.md index 1824d489d..c84076d54 100644 --- a/docs/Development/ReleaseNotes.md +++ b/docs/Development/ReleaseNotes.md @@ -111,6 +111,10 @@ 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 + + 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. + #### 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)) From 7ba492af0e68d54bda0f7dfa15f3452bbe314fc6 Mon Sep 17 00:00:00 2001 From: Diana Gergel Date: Mon, 15 Jan 2018 21:46:57 -0800 Subject: [PATCH 5/8] ran uncrustify --- vic/drivers/shared_all/src/get_parameters.c | 2 +- vic/drivers/shared_all/src/print_library_shared.c | 3 ++- vic/vic_run/src/surface_fluxes.c | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/vic/drivers/shared_all/src/get_parameters.c b/vic/drivers/shared_all/src/get_parameters.c index 26024d5e8..634351bef 100644 --- a/vic/drivers/shared_all/src/get_parameters.c +++ b/vic/drivers/shared_all/src/get_parameters.c @@ -884,7 +884,7 @@ validate_parameters() log_err( "FROZEN_MAXITER must be defined on the interval [0, inf) (iterations"); } - // Canopy 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"); diff --git a/vic/drivers/shared_all/src/print_library_shared.c b/vic/drivers/shared_all/src/print_library_shared.c index c6965efd8..ed5667f8a 100644 --- a/vic/drivers/shared_all/src/print_library_shared.c +++ b/vic/drivers/shared_all/src/print_library_shared.c @@ -798,7 +798,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, "\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); diff --git a/vic/vic_run/src/surface_fluxes.c b/vic/vic_run/src/surface_fluxes.c index 12f4a9140..4c31d5ba9 100644 --- a/vic/vic_run/src/surface_fluxes.c +++ b/vic/vic_run/src/surface_fluxes.c @@ -719,7 +719,8 @@ surface_fluxes(bool overstory, } } while ((fabs(tol_under - last_tol_under) > param.TOL_GRND) && - (tol_under != 0) && (under_iter < param.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) && From 50b137cacb38917ccd8c165a2606a08656e10c9e Mon Sep 17 00:00:00 2001 From: Diana Gergel Date: Mon, 15 Jan 2018 21:49:53 -0800 Subject: [PATCH 6/8] update release notes entry w/ PR # --- docs/Development/ReleaseNotes.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/Development/ReleaseNotes.md b/docs/Development/ReleaseNotes.md index 579b4fe59..04079e0e5 100644 --- a/docs/Development/ReleaseNotes.md +++ b/docs/Development/ReleaseNotes.md @@ -111,7 +111,7 @@ 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 +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. From 524ee952927ac0c61c2c6d76a195cf4e87400718 Mon Sep 17 00:00:00 2001 From: Diana Gergel Date: Thu, 18 Jan 2018 14:50:14 -0500 Subject: [PATCH 7/8] move MAX_ITER_GRND_CANOPY parameter update to initialize_parameters.c in shared_all from surface_fluxes.c in vic_run --- vic/drivers/shared_all/src/initialize_parameters.c | 9 ++++++++- vic/vic_run/src/surface_fluxes.c | 5 ----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/vic/drivers/shared_all/src/initialize_parameters.c b/vic/drivers/shared_all/src/initialize_parameters.c index b677f9f69..cb00aec7f 100644 --- a/vic/drivers/shared_all/src/initialize_parameters.c +++ b/vic/drivers/shared_all/src/initialize_parameters.c @@ -33,6 +33,7 @@ void initialize_parameters() { extern parameters_struct param; + extern option_struct options; // Initialize temporary parameters // Lapse Rate @@ -212,7 +213,13 @@ initialize_parameters() param.FROZEN_MAXITER = 1000; // Canopy Iterations - param.MAX_ITER_GRND_CANOPY = 10; + 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; diff --git a/vic/vic_run/src/surface_fluxes.c b/vic/vic_run/src/surface_fluxes.c index 12f4a9140..274f73dd3 100644 --- a/vic/vic_run/src/surface_fluxes.c +++ b/vic/vic_run/src/surface_fluxes.c @@ -224,11 +224,6 @@ surface_fluxes(bool overstory, double store_Raut; double store_NPP; - if (!options.CLOSE_ENERGY) { - // if not closing energy balance, don't iterate - param.MAX_ITER_GRND_CANOPY = 0; - } - if (options.CARBON) { store_gsLayer = calloc(options.Ncanopy, sizeof(*store_gsLayer)); check_alloc_status(store_gsLayer, "Memory allocation error."); From 07e4601b89d32e22edcbc5171ebbbd44cd586b6e Mon Sep 17 00:00:00 2001 From: Diana Gergel Date: Thu, 18 Jan 2018 14:41:13 -0800 Subject: [PATCH 8/8] ran uncrustify --- vic/drivers/shared_all/src/initialize_parameters.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vic/drivers/shared_all/src/initialize_parameters.c b/vic/drivers/shared_all/src/initialize_parameters.c index cb00aec7f..0a3b3c4ff 100644 --- a/vic/drivers/shared_all/src/initialize_parameters.c +++ b/vic/drivers/shared_all/src/initialize_parameters.c @@ -33,7 +33,7 @@ void initialize_parameters() { extern parameters_struct param; - extern option_struct options; + extern option_struct options; // Initialize temporary parameters // Lapse Rate @@ -218,7 +218,7 @@ initialize_parameters() param.MAX_ITER_GRND_CANOPY = 10; } else { - param.MAX_ITER_GRND_CANOPY = 0; + param.MAX_ITER_GRND_CANOPY = 0; } // Newton-Raphson solver parameters