Skip to content

Commit d1872e7

Browse files
Diana GergelJoe Hamman
Diana Gergel
authored and
Joe Hamman
committed
Feature/debug cesm driver (#642)
* update command line usage docs * update release notes * Fixed image driver history file name (#635) * Fixed image driver history file name timetamp - now is timstep-beginning * Added release notes about PR #635 (fixing image driver history filename timestamp) * Committing a fix to vic_restore.c Added an if statement so that when VIC is run on multiple nodes, only the master node will validate state file dimensions and coordinate variables. * Use multiple processors for image restart tests * dummy forcings are now created while initializing the model prior to communicating with the coupler * removed decimal point for missing value for unsigned ints * initial fix for getting state file date/time info * updated fix for getting statefile time info from dmy_current (period-ending) * Fixed a bug when calculating steps of forcing to skip (#639) * Fixed a bug when calculating steps of forcing to skip - should round to integer first before converting to int type to prevent possible 1-timestep wrong offset * Added bug fix release notes to PR#639 * fixed bug that passed fillvalue as double when it was supposed to be an int in gather_put_nc_field_int fctn * Added release notes about PR #638. (#640) (Fixing a problem with image restarts when using multiple processors). * use appropriate fillvalue datatypes in gather_put_nc_field fctns * add caseid to statefile name by passing case metadata in to vic_cesm_run function * Revert "add caseid to statefile name by passing case metadata in to vic_cesm_run function because adding this logic to vic_cesm_init instead" This reverts commit 7e28f13. * assign caseid to statefile name in vic_cesm_init * fix warnings for SNOW_BAND and AGGFREQ * fixed typo in comment * Added check to ensure mask variable in the input domain file is integer type (#645) * Added check to ensure mask varible in domain file is integer type * Cleaned up some printing lines * Added get_nc_var_type.c * Minor update of comments and ReleaseNotes * Added domain file description in docs * Small fix of table in docs * Added ncdump -h results for domain file in docs * Minor docs update * fix typo in primary reference (#646) * Fix bug make lastday (#647) * Added check to ensure mask varible in domain file is integer type * Cleaned up some printing lines * Added get_nc_var_type.c * Minor update of comments and ReleaseNotes * Added domain file description in docs * Small fix of table in docs * Added ncdump -h results for domain file in docs * Minor docs update * The input arguments to function `make_lastday` are sometimes in a wrong order - fixed the bug * Added ReleaseNotes regarding PR#647 * Revert "Merge branch 'hotfix/5.0.1' of github.com:UW-Hydro/VIC into hotfix/5.0.1" This reverts commit a9a202b, reversing changes made to bbf7d9a. * pressure was being converted to kPa, should be in Pa * Revert "pressure was being converted to kPa, should be in Pa" This reverts commit 72a56a5. * pressure was being converted to kPa, should be in Pa * convert pressure to kPa when reading it in rather than Pa since this was updated in VIC 5 * Revert "convert pressure to kPa when reading it in rather than Pa since this was updated in VIC 5" This reverts commit e7192c5. * fixed bug with using the correct local domain grid cells and units issues * address PR review comments * add change log entry
1 parent 05e1dbc commit d1872e7

File tree

10 files changed

+70
-22
lines changed

10 files changed

+70
-22
lines changed

docs/Development/ReleaseNotes.md

+10
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,16 @@ This is a major update from VIC 4. The VIC 5.0.0 release aims to have nearly ide
197197

198198
Fixed a bug where volumetric heat capacity of water should be used in `func_canopy_energy_bal` (previously specific heat capacity was used).
199199

200+
6. Fixes for the CESM driver ([GH#642](https://github.com/UW-Hydro/VIC/pull/642))
201+
202+
1. Using correct fill value datatypes in MPI Gather steps
203+
2. Updated state file name time step to be period-ending rather than period-beginning
204+
3. Set the state file name to the RASM case ID
205+
4. Removed decimal point for missing values for unsigned integers
206+
5. Create dummy forcings when initializing the model (so that there is forcing data for the first time step)
207+
6. Changed pressure units from kPa to Pa
208+
7. Fixed bug that prevented using the correct local domain grid cells in `cesm_put_data.c`
209+
8. Changed reference temperature units from Celsius to Kelvin in `cesm_put_data.c`
200210
------------------------------
201211

202212
## VIC 4.2.d [![DOI](https://zenodo.org/badge/doi/10.5281/zenodo.56058.svg)](http://dx.doi.org/10.5281/zenodo.56058)

vic/drivers/cesm/src/cesm_interface_c.c

+4
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ vic_cesm_init(vic_clock *vclock,
9696
// populate model state, either using a cold start or from a restart file
9797
vic_populate_model_state(trim(cmeta->starttype));
9898

99+
// initialize forcings
100+
vic_force();
101+
99102
// initialize output structures
100103
vic_init_output(&dmy_current);
101104

@@ -137,6 +140,7 @@ vic_cesm_run(vic_clock *vclock)
137140

138141
// if save:
139142
if (vclock->state_flag) {
143+
// write state file
140144
vic_store(&dmy_current, state_filename);
141145
write_rpointer_file(state_filename);
142146
}

vic/drivers/cesm/src/cesm_put_data.c

+8-8
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,12 @@ vic_cesm_put_data()
140140

141141
// 2m reference temperature
142142
// CESM units: K
143-
l2x_vic[i].l2x_Sl_tref += AreaFactor * force->air_temp[NR];
143+
l2x_vic[i].l2x_Sl_tref += AreaFactor * (force[i].air_temp[NR] + CONST_TKFRZ);
144144

145145
// 2m reference specific humidity
146146
// CESM units: g/g
147147
l2x_vic[i].l2x_Sl_qref += AreaFactor * CONST_EPS *
148-
force->vp[NR] / force->pressure[NR];
148+
force[i].vp[NR] / force[i].pressure[NR];
149149

150150
// Albedo Note: VIC does not partition its albedo, all returned
151151
// values will be the same
@@ -156,10 +156,10 @@ vic_cesm_put_data()
156156
// force->NetShortAtmos net shortwave flux (+ down)
157157
// SWup = force->shortwave[NR] - energy.NetShortAtmos
158158
// Set the albedo to zero for the case where there is no shortwave down
159-
if (force->shortwave[NR] > 0.) {
159+
if (force[i].shortwave[NR] > 0.) {
160160
albedo = AreaFactor *
161-
(force->shortwave[NR] - energy.NetShortAtmos) /
162-
force->shortwave[NR];
161+
(force[i].shortwave[NR] - energy.NetShortAtmos) /
162+
force[i].shortwave[NR];
163163
}
164164
else {
165165
albedo = 0.;
@@ -184,7 +184,7 @@ vic_cesm_put_data()
184184

185185
// 10m wind
186186
// CESM units: m/s
187-
l2x_vic[i].l2x_Sl_u10 += AreaFactor * force->wind[NR];
187+
l2x_vic[i].l2x_Sl_u10 += AreaFactor * force[i].wind[NR];
188188

189189
// dry deposition velocities (optional)
190190
// CESM units: ?
@@ -259,7 +259,7 @@ vic_cesm_put_data()
259259
// upward longwave heat flux
260260
// CESM units: W m-2
261261
l2x_vic[i].l2x_Fall_lwup += AreaFactor *
262-
(force->longwave[NR] -
262+
(force[i].longwave[NR] -
263263
energy.NetLongAtmos);
264264

265265
// evaporation water flux
@@ -278,7 +278,7 @@ vic_cesm_put_data()
278278

279279
// heat flux shortwave net
280280
l2x_vic[i].l2x_Fall_swnet += AreaFactor *
281-
(force->shortwave[NR] -
281+
(force[i].shortwave[NR] -
282282
energy.NetShortAtmos);
283283

284284
// co2 flux **For testing set to 0

vic/drivers/cesm/src/get_global_param.c

+9
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,12 @@ get_global_param(FILE *gp)
385385
"control file.");
386386
}
387387
}
388+
else if (strcasecmp("SNOW_BAND", optstr) == 0) {
389+
sscanf(cmdstr, "%*s %s", flgstr);
390+
if (str_to_bool(flgstr)) {
391+
options.SNOW_BAND = SNOW_BAND_TRUE_BUT_UNSET;
392+
}
393+
}
388394
else if (strcasecmp("LAKES", optstr) == 0) {
389395
sscanf(cmdstr, "%*s %s", flgstr);
390396
if (strcasecmp("FALSE", flgstr) == 0) {
@@ -415,6 +421,9 @@ get_global_param(FILE *gp)
415421
else if (strcasecmp("OUTVAR", optstr) == 0) {
416422
; // do nothing
417423
}
424+
else if (strcasecmp("AGGFREQ", optstr) == 0) {
425+
; // do nothing
426+
}
418427
else if (strcasecmp("OUTPUT_STEPS_PER_DAY", optstr) == 0) {
419428
; // do nothing
420429
}

vic/drivers/cesm/src/vic_cesm_start.c

+5
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ vic_cesm_start(vic_clock *vclock,
4646
// Driver specific settings
4747
if (mpi_rank == VIC_MPI_ROOT) {
4848
strcpy(filenames.global, GLOBALPARAM);
49+
50+
// assign case name to state file name
51+
strncpy(filenames.statefile, trim(cmeta->caseid),
52+
sizeof(filenames.statefile));
53+
4954
// read global settings
5055
filep.globalparam = open_file(filenames.global, "r");
5156
get_global_param(filep.globalparam);

vic/drivers/cesm/src/vic_force.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ vic_force(void)
127127
for (j = 0; j < NF; j++) {
128128
for (i = 0; i < local_domain.ncells_active; i++) {
129129
// CESM units: Pa
130-
// VIC units: kPa
131-
force[i].pressure[j] = x2l_vic[i].x2l_Sa_pbot / PA_PER_KPA;
130+
// VIC units: Pa
131+
force[i].pressure[j] = x2l_vic[i].x2l_Sa_pbot;
132132
}
133133
}
134134

vic/drivers/shared_image/src/vic_init_output.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,8 @@ initialize_history_file(nc_file_struct *nc,
224224
double *dvar;
225225

226226

227-
// This could be further refined but for now, I've choosen a file naming
228-
// Convention that goes like this:
227+
// This could be further refined but for now, I've chosen a file naming
228+
// convention that goes like this:
229229
switch (stream->agg_alarm.freq) {
230230
// If FREQ_NDAYS -- filename = result_dir/prefix.YYYY-MM-DD.nc
231231
case FREQ_NDAYS:

vic/drivers/shared_image/src/vic_store.c

+28-8
Original file line numberDiff line numberDiff line change
@@ -48,25 +48,45 @@ vic_store(dmy_struct *dmy_current,
4848
size_t k;
4949
size_t m;
5050
size_t p;
51+
double offset;
52+
double time_num;
53+
double end_time_num;
5154
int *ivar = NULL;
5255
double *dvar = NULL;
5356
size_t d2start[2];
5457
size_t d3start[3];
5558
size_t d4start[4];
5659
size_t d5start[5];
5760
size_t d6start[6];
61+
dmy_struct end_time_date;
5862
nc_file_struct nc_state_file;
5963
nc_var_struct *nc_var;
6064

6165
set_nc_state_file_info(&nc_state_file);
6266

6367
// only open and initialize the netcdf file on the first thread
6468
if (mpi_rank == VIC_MPI_ROOT) {
69+
70+
// advance dmy_current by one timestep since dmy_current is the
71+
// timestep-beginning timestamp, and state file date should be
72+
// the end of the current time step
73+
dt_seconds_to_time_units(global_param.time_units, global_param.dt,
74+
&offset);
75+
time_num = date2num(global_param.time_origin_num, dmy_current, 0,
76+
global_param.calendar, global_param.time_units);
77+
end_time_num = time_num + offset;
78+
79+
// allocate dmy struct for end of current time step
80+
num2date(global_param.time_origin_num, end_time_num, 0.,
81+
global_param.calendar, global_param.time_units,
82+
&end_time_date);
83+
84+
6585
// create netcdf file for storing model state
6686
sprintf(filename, "%s.%04i%02i%02i_%05u.nc",
67-
filenames.statefile, global_param.stateyear,
68-
global_param.statemonth, global_param.stateday,
69-
global_param.statesec);
87+
filenames.statefile, end_time_date.year,
88+
end_time_date.month, end_time_date.day,
89+
end_time_date.dayseconds);
7090

7191
initialize_state_file(filename, &nc_state_file, dmy_current);
7292

@@ -350,7 +370,7 @@ vic_store(dmy_struct *dmy_current,
350370
}
351371
gather_put_nc_field_int(nc_state_file.nc_id,
352372
nc_var->nc_varid,
353-
nc_state_file.d_fillvalue,
373+
nc_state_file.i_fillvalue,
354374
d4start, nc_var->nc_counts, ivar);
355375
for (i = 0; i < local_domain.ncells_active; i++) {
356376
ivar[i] = nc_state_file.i_fillvalue;
@@ -376,7 +396,7 @@ vic_store(dmy_struct *dmy_current,
376396
}
377397
gather_put_nc_field_int(nc_state_file.nc_id,
378398
nc_var->nc_varid,
379-
nc_state_file.d_fillvalue,
399+
nc_state_file.i_fillvalue,
380400
d4start, nc_var->nc_counts, ivar);
381401
for (i = 0; i < local_domain.ncells_active; i++) {
382402
ivar[i] = nc_state_file.i_fillvalue;
@@ -813,7 +833,7 @@ vic_store(dmy_struct *dmy_current,
813833
}
814834
gather_put_nc_field_int(nc_state_file.nc_id,
815835
nc_var->nc_varid,
816-
nc_state_file.d_fillvalue,
836+
nc_state_file.i_fillvalue,
817837
d2start, nc_var->nc_counts, ivar);
818838
for (i = 0; i < local_domain.ncells_active; i++) {
819839
ivar[i] = nc_state_file.i_fillvalue;
@@ -826,7 +846,7 @@ vic_store(dmy_struct *dmy_current,
826846
}
827847
gather_put_nc_field_int(nc_state_file.nc_id,
828848
nc_var->nc_varid,
829-
nc_state_file.d_fillvalue,
849+
nc_state_file.i_fillvalue,
830850
d2start, nc_var->nc_counts, ivar);
831851
for (i = 0; i < local_domain.ncells_active; i++) {
832852
ivar[i] = nc_state_file.i_fillvalue;
@@ -972,7 +992,7 @@ vic_store(dmy_struct *dmy_current,
972992
}
973993
gather_put_nc_field_int(nc_state_file.nc_id,
974994
nc_var->nc_varid,
975-
nc_state_file.d_fillvalue,
995+
nc_state_file.i_fillvalue,
976996
d2start, nc_var->nc_counts, ivar);
977997
for (i = 0; i < local_domain.ncells_active; i++) {
978998
ivar[i] = nc_state_file.i_fillvalue;

vic/drivers/shared_image/src/vic_write.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ vic_write(stream_struct *stream,
194194
}
195195
gather_put_nc_field_schar(nc_hist_file->nc_id,
196196
nc_hist_file->nc_vars[k].nc_varid,
197-
nc_hist_file->d_fillvalue,
197+
nc_hist_file->c_fillvalue,
198198
dstart, dcount, cvar);
199199
}
200200
else {

vic/vic_run/include/vic_def.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
/***** Model Constants *****/
5353
#define MAXSTRING 2048
5454
#define MISSING -99999. /**< missing value */
55-
#define MISSING_USI 99999. /**< missing value for unsigned ints */
55+
#define MISSING_USI 99999 /**< missing value for unsigned ints */
5656
#define MISSING_S "MISSING" /**< missing value for strings */
5757
#define NODATA_VH -1 /**< missing value for veg_hist inputs */
5858
#define NODATA_VEG -1 /**< flag for veg types not in grid cell */

0 commit comments

Comments
 (0)