-
Notifications
You must be signed in to change notification settings - Fork 392
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
Timestep and Calendar Modifications #188
Timestep and Calendar Modifications #188
Conversation
- Timestep units changed from hours to seconds, - Ported netcdftime.py to vic_time.c supporting all netCDF calendars. Not stable. Timestep/Calendar commit num. 1.
Note: the Travis build failed only for |
@jhamman put parentheses around every mathematical operation that is done in a For example, #define MIN_PER_DAY MIN_PER_HOUR * HOURS_PER_DAY should read #define MIN_PER_DAY (MIN_PER_HOUR * HOURS_PER_DAY) Similarly: #define MIN_PER_DAY (MIN_PER_HOUR * HOURS_PER_DAY) /**< hours per day */
#define SEC_PER_HOUR (SEC_PER_MIN * MIN_PER_HOUR) /**< seconds per hour */
#define SEC_PER_DAY (SEC_PER_HOUR * HOURS_PER_DAY) /**< hours per day */
#define CONST_OMEGA (2.0 * CONST_PI / CONST_SDAY)
#define CONST_RGAS (CONST_AVOGAD * CONST_BOLTZ) /**< Universal gas constant ~ J/K/kmole */
#define CONST_RDAIR (CONST_RGAS / CONST_MWDAIR) /**< Dry air gas constant ~ J/K/kg */
#define CONST_RWV (CONST_RGAS / CONST_MWWV) /**< Water vapor gas constant ~ J/K/kg */
#define CONST_EPS (CONST_MWWV / CONST_MWAIR) /**< Ratio of molecular weights */
#define CONST_TSTD (CONST_TKFRZ + 15.0) /**< (K) standard temp at 0.0 m elevation */
#define CONST_RHODAIR (CONST_PSTD / (CONST_RDAIR * CONST_TKFRZ)) /**< density of dry air at STP ~ kg/m^3 */ We should similarly check the other header files. Keep in mind that the precompiler does textual substitution for day = (double)date->day + (double)date->dayseconds / (double)SEC_PER_DAY; becomes day = (double)date->day + (double)date->dayseconds / (double) SEC_PER_HOUR * HOURS_PER_DAY; which becomes day = (double)date->day + (double)date->dayseconds / (double) SEC_PER_MIN * MIN_PER_HOUR * HOURS_PER_DAY; which becomes day = (double)date->day + (double)date->dayseconds / (double) 60 * 60 * 24; which becomes day = (double)date->day + (double)date->dayseconds * 24; which is a big number for any Note that if you put the parentheses around the statements, you will have day = (double)date->day + (double)date->dayseconds / (double) ((SEC_PER_MIN * MIN_PER_HOUR) * HOURS_PER_DAY); which will give you the right answer. |
int i; | ||
size_t stepsperday; | ||
|
||
stepsperday = SEC_PER_DAY / stepsize; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this require extra checking to make sure that stepsize
evenly divides SEC_PER_DAY
. If stepsperday
is a quantity that is regularly used, it may make sense to add it to the time structure for VIC.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good point. I'm going to pass a stepsperday
variable into the function and then calculate the stepsize
inside the function.
In the global_param_struct, I store these values:
double dt; /**< Time step in seconds */
double snow_dt; /**< Snow model time step in seconds */
double runoff_dt; /**< Runoff time step in seconds */
double out_dt; /**< Output time step in seconds */
size_t model_steps_per_day; /**< Number of model timesteps per day */
size_t snow_steps_per_day; /**< Number of snow timesteps per day */
size_t runoff_steps_per_day; /**< Number of runoff timesteps per day */
but those do not necessarily correspond to the stepsize of this function.
I see. I see. That is much clearer now and I will implement that change shortly. |
31, /* DECEMBER */ | ||
}; | ||
unsigned tmpstartdate; | ||
unsigned tmpenddate; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Be explicit about the size of unsigned
. I know it defaults to unsigned int
, but since the rest of VIC is explicit about that, stick with it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done. will extend to other locations as well.
There are a lot of whitespace-only changes in the commit that should not be included. Are you using the same uncrustify configuration file as we used before? You should rollback most of the whitespace only changes, cause they just clutter the commit and since uncrustify was already run on the original branch we should not include whitespace only changes. |
short local_starthour; | ||
unsigned short day_in_year, year, month, days_in_month; | ||
int sec_offset_int; | ||
unsigned tmp_endsec; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unsigned int
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will be done via #194
The history file is opened (and time dimension defined) in: For the state file in (note this does not currently have a time dimension): For the reads, the time dimension is currently not treated explicitly (just read one slice at a time from the beginning of the file, which obviously needs work). I just assume that the time slice that is being read in vic_force() in https://github.com/bartnijssen/VIC/blob/develop/drivers/image/src/vic_force.c increments by 1 every time (dstart[0] increases, the rest is constant). Proper treatment of the calendar would mean that dstart[0] is calculated in a better way (I just start at 0 and increment).
|
…rly_timestep Conflicts: drivers/image/src/get_global_param.c drivers/shared/include/vic_driver_shared.h
Thanks @bartnijssen. In order to to keep this PR to a manageable size, I'm going to leave the updating of the image driver I/O time handling to another issue (#197) and PR . |
I've completed my modifications for this branch. I've tested on a few grid cells with the classic driver only but it is running stably for all calendars. Remaining issues for the image driver have been opened so I think this can be merged then closed. |
Does that mean all the mtclim operations work correctly in all the different calendars (skipping leap days, etc) or simply that the model does not crash if we specify different calendars? The main concern with the different calendars is that this creates a lot of new options (and hence test pathways). If this has not been fully tested with mtclim (e.g. would that handle all the different calendars correctly - which is not the same as not crashing), then we need to disallow the calendars that have not been tested or only allow the calendars when all the forcings are fully specified. |
That is a good point. The model does not crash with the different calendars. Maybe @tbohn has some ideas on the applicability of other calendars to I'm fine with restricting the use of other calendars to cases when |
Even a single leap day difference can add up to a month in a 100 year simulation, which is why this can come back to haunt us. We'll want to include at the very least a warning with non-standard calendars that they have not been tested. I'd rather not rely on someone thinking it'd probably be OK, but prefer to do real testing. In the absence of that (I do not suggest making this a major push right now), keep the code, but warn the user and open a new issue for more thorough testing of this feature. Bart
|
Yes, I think the standard, no_leap and all_leap calendars would be fine I think we could even find a way to make the 360-day calendar work, if we Ted On Tue, Jan 20, 2015 at 10:46 AM, Joe Hamman notifications@github.com
|
A cumulative leap day offset should not be a problem since /* begin loop through yeardays */
for (i = 0; i < DAYS_PER_YEAR; i++) {
...
/* solar constant as a function of yearday (W/m^2) */
sc = param.MTCLIM_SOLAR_CONSTANT + 45.5 *
sin((2.0 * CONST_PI * (double)i / CONST_DDAYS_PER_YEAR) + 1.7);
....
} In previous versions of |
@jhamman : If you add the small changes to the MTCLIM code that we discussed (pass both day of year and the number of days in the year), then I'll go ahead and merge |
@jhamman : BTW - also note that the pull request cannot be merged automatically, because I merged another pull request first. If you can resolve the conflict on your end that would be great. |
No problem, I'll bring this branch up to date before committing these last changes. |
…s a parameter "days_per_year" to determine if leap days should be included.
…rly_timestep Conflicts: drivers/shared/include/vic_driver_shared.h
Ok, with this last set of commits I
The build passed and I verified in a few test cases that this is doing what we want. |
…it in vic_time and mtclim_wrapper.
Timestep and Calendar Modifications
Initial mods for subhourly timestep and alternative calendar support
Addresses #42 and #70 and contributes to #179.
To do (in upcoming commits):
image driver
Test wide range of variable combinations in initialize_atmos.c