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

Fix to state file i/o problems and refactoring of initialization #464

Merged
merged 11 commits into from
Apr 14, 2016

Conversation

tbohn
Copy link
Contributor

@tbohn tbohn commented Apr 8, 2016

Fix to state file i/o problems and refactoring of initialization into separate functions for generating a default state and for handling derived state variables. Most of these functions are shared across drivers.

closes #457
closes #424
closes #401

Quick summary of the changes:

  1. Fixes for miscellaneous state file i/o issues: e.g., lat/lon indexing was wrong for the 1d case in both vic_store() and vic_restore(); some other variables were being written incorrectly.
  2. Refactoring of state initialization: I made the classic driver look more like the image and cesm drivers, with functions devoted to generating the default state, and handling derived state variables, shared across all drivers.

New structure:

read_soilparam(classic) or vic_init(image/cesm):

  • reads soil parameters, does computation of derived soil parameters and properties
  • moved the setting of soil thermal node spacing to here
  • (image only) calls initialize_* functions

vic_populate_model_state(all drivers):

  • (classic only) calls initialize_* functions
  • if (options.INIT_STATE): reads initial state file, via read_initial_model_state(classic) or vic_restore(image/cesm); moved the capping of initial soil moisture to max_moist to inside read_initial_model_state() (classic only) - I can add similar code to vic_restore() if desired
  • else:generate_default_state(all) and generate_default_lake_state(all) // initializes soil/lake water storage and soil/lake temperatures to default values
  • compute_derived_state_vars(all) and compute_derived_lake_dimensions(all) // sets soil thermal node properties and ice contents, and computes lake dimensions that depend on lake storage

… separate functions for generating a default state and for handling derived state variables.
@tbohn
Copy link
Contributor Author

tbohn commented Apr 8, 2016

Note: I've tested that both classic and image drivers now successfully save state at the appointed time, and either read the specified state file or start from a default state as requested.

Note: results are a little different between the new classic and 4.2. Not hugely, but still, not the same. Hopefully this can be investigated further in restart tests.

@tbohn
Copy link
Contributor Author

tbohn commented Apr 9, 2016

Another note: strangely, starting from the the default state does not generate root_brent errors anymore after this PR is merged. However, starting from a state file still does. Not sure why.

@@ -692,6 +696,108 @@ read_soilparam(FILE *soilparam,
temp.Ws = temp.Ws / temp.max_moist[layer];
}

// Soil thermal node thicknesses and positions
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This section was originally in the old initialize_model_state() function, but it really should go here, as node spacing is completely determined from soil parameters and global param options. This way, all soil_con values are populated by the time we exit read_soilparam().

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that currently the last section (around the last ~15 lines) in initialize_soil.c also derives some soil_con values. Should that part be moved here to read_soilparam() also?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think you are right. Good catch. I need to move those into both read_soilparam() and vic_init().

}
}

return(0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we've been moving away from returning an exit status unless it will be used later. In this case, we should exit immediately if there are any errors and we can return with void instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

@jhamman
Copy link
Member

jhamman commented Apr 9, 2016

Nice work @tbohn. Looks good. @yixinmao - you're up!

* This routine initializes the model state (energy balance, water balance, and
* snow components).
*
* If a state file is provided to the model than its
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"then" instead of "than"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

@bartnijssen
Copy link
Member

@tbohn : merge conflicts (probably because of Joe's PR that was just merged) - please merge develop into this PR

Conflicts:
	vic/drivers/shared_image/include/vic_driver_shared_image.h
	vic/drivers/shared_image/src/vic_store.c
@jhamman jhamman added this to the 5.0 milestone Apr 11, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants