diff --git a/build/CMakeLists.txt b/build/CMakeLists.txt index 14f94527c7d1e4fe439346b71d411893b86df25e..154187abc541445aeac93a4e55423acb58ff557e 100644 --- a/build/CMakeLists.txt +++ b/build/CMakeLists.txt @@ -189,6 +189,9 @@ set(SOLVER ${ENGINE_DIR}/vegSWavRad.f90) set(DRIVER + ${DRIVER_DIR}/summa_type.f90 + ${DRIVER_DIR}/summa_setup.f90 + ${DRIVER_DIR}/summa_restart.f90 ${DRIVER_DIR}/summa_alarms.f90 ${DRIVER_DIR}/summa_globalData.f90) @@ -203,10 +206,10 @@ set(INTERFACE set(SYS_INIT_INTERFACE ${SYS_INIT_DIR}/batch_distributer_actor.f90) set(FILE_ACCESS_INTERFACE + ${FILE_ACCESS_DIR}/summa_init_struc.f90 ${FILE_ACCESS_DIR}/forcing_file_info.f90 ${FILE_ACCESS_DIR}/file_access_actor.f90 ${FILE_ACCESS_DIR}/output_structure.f90 - # ${FILE_ACCESS_DIR}/read_force.f90 ${FILE_ACCESS_DIR}/fileAccess_writeOutput.f90) set(JOB_INTERFACE ${JOB_ACTOR_DIR}/job_actor.f90) @@ -236,10 +239,10 @@ set(SYS_INIT ${SYS_INIT_DIR}/summa_client.cpp ${SYS_INIT_DIR}/summa_server.cpp) set(FILE_ACCESS_ACTOR - # ${ACTORS_DIR}/file_access_actor/file_access_utils.cpp - ${ACTORS_DIR}/file_access_actor/file_access_actor.cpp - ${ACTORS_DIR}/file_access_actor/forcing_file_info.cpp - ${ACTORS_DIR}/file_access_actor/output_container.cpp) + ${FILE_ACCESS_DIR}/summa_init_struc.cpp + ${FILE_ACCESS_DIR}/file_access_actor.cpp + ${FILE_ACCESS_DIR}/forcing_file_info.cpp + ${FILE_ACCESS_DIR}/output_container.cpp) set(JOB_ACTOR ${ACTORS_DIR}/job_actor/GRU.cpp ${ACTORS_DIR}/job_actor/job_actor.cpp diff --git a/build/includes/file_access_actor/file_access_actor.hpp b/build/includes/file_access_actor/file_access_actor.hpp index e9337d022b23bac1709b9984bcdc467eacb5ba38..17847a641c537b778c7fed3c6eb49a562958c076 100644 --- a/build/includes/file_access_actor/file_access_actor.hpp +++ b/build/includes/file_access_actor/file_access_actor.hpp @@ -9,6 +9,7 @@ #include "message_atoms.hpp" #include "forcing_file_info.hpp" #include "json.hpp" +#include "summa_init_struc.hpp" using namespace caf; @@ -35,6 +36,7 @@ extern "C" { * File Access Actor state variables *********************************************/ struct file_access_state { + TimingInfo file_access_timing; caf::actor parent; int start_gru; int num_gru; @@ -42,20 +44,16 @@ struct file_access_state { NumGRUInfo num_gru_info; void *handle_ncid = new_handle_var_i(); // output file ids - int num_vectors_in_output_manager; int num_steps; - int stepsInCurrentFile; - int numFiles; - int filesLoaded; int num_output_steps; Output_Container* output_container; File_Access_Actor_Settings file_access_actor_settings; + std::unique_ptr<SummaInitStruc> summa_init_struc; std::unique_ptr<forcingFileContainer> forcing_files; - TimingInfo file_access_timing; bool write_params_flag = true; }; diff --git a/build/includes/file_access_actor/summa_init_struc.hpp b/build/includes/file_access_actor/summa_init_struc.hpp new file mode 100644 index 0000000000000000000000000000000000000000..b92d1d9d00528a392591504e5ed17e5174ae8c50 --- /dev/null +++ b/build/includes/file_access_actor/summa_init_struc.hpp @@ -0,0 +1,22 @@ +#define SUMMA_INIT_STRUC +#ifdef SUMMA_INIT_STRUC + +extern "C" { + void initialize_init_struc(int& num_gru, int& err, void* message); + void paramSetup_fortran(int& err, void* message); + void readRestart_fortran(int& err, void* message); + void deallocate_init_struc(); +} + +class SummaInitStruc { + public: + SummaInitStruc(); + ~SummaInitStruc(); + + int allocate(int num_gru); // allocate space in Fortran + int summa_paramSetup(); // call summa_paramSetup + int summa_readRestart(); // call summa_readRestart +}; + + +#endif diff --git a/build/source/file_access_actor/file_access_actor.cpp b/build/source/file_access_actor/file_access_actor.cpp index f1c96d10b1c9668352fae690e2a33593fa248aeb..c528cdfdf97b1fb1ba18a4ff0948a53300896802 100644 --- a/build/source/file_access_actor/file_access_actor.cpp +++ b/build/source/file_access_actor/file_access_actor.cpp @@ -39,22 +39,34 @@ behavior file_access_actor(stateful_actor<file_access_state>* self, int num_hru = self->state.num_gru; int err = 0; - // Call ffile_info + + self->state.summa_init_struc = std::make_unique<SummaInitStruc>(); + err = self->state.summa_init_struc->allocate(self->state.num_gru); + if (err != 0) aout(self) << "ERROR: SummaInitStruc allocation failed\n"; + err = self->state.summa_init_struc->summa_paramSetup(); + if (err != 0) aout(self) << "ERROR: SummaInitStruc paramSetup failed\n"; + err = self->state.summa_init_struc->summa_readRestart(); + if (err != 0) aout(self) << "ERROR: SummaInitStruc readRestart failed\n"; + + // Get the information about the forcing files self->state.forcing_files = std::make_unique<forcingFileContainer>(); err = self->state.forcing_files->initForcingFiles(self->state.num_gru); if (err != 0) return -1; std::unique_ptr<char[]> message(new char[256]); fileAccessActor_init_fortran(&self->state.num_steps, - &fa_settings.num_timesteps_in_output_buffer, self->state.handle_ncid, - &self->state.start_gru, &self->state.num_gru, &num_hru, &err, - &message); + &fa_settings.num_timesteps_in_output_buffer, + self->state.handle_ncid, + &self->state.start_gru, + &self->state.num_gru, &num_hru, &err, + &message); if (err != 0) { aout(self) << "\n\nERROR: fileAccessActor_init_fortran() - " << message.get() << "\n\n"; return -1; } + // return -1; // Ensure output buffer size is less than the number of simulation timesteps if (self->state.num_steps < fa_settings.num_timesteps_in_output_buffer) { self->state.num_output_steps = self->state.num_steps; @@ -95,10 +107,10 @@ behavior file_access_actor(stateful_actor<file_access_state>* self, self->state.forcing_files->getNumSteps(iFile), iFile); return; } - auto err = self->state.forcing_files->loadForcingFile(iFile, - self->state.start_gru, self->state.num_gru); + auto err = self->state.forcing_files-> + loadForcingFile(iFile, self->state.start_gru, self->state.num_gru); if (err != 0) { - aout(self) << "ERROR: Reading Forcing" << std::endl; + aout(self) << "ERROR: Reading Forcing\n"; self->quit(); return; } @@ -118,7 +130,7 @@ behavior file_access_actor(stateful_actor<file_access_state>* self, auto err = self->state.forcing_files->loadForcingFile(iFile, self->state.start_gru, self->state.num_gru); if (err != 0) { - aout(self) << "ERROR: Reading Forcing" << std::endl; + aout(self) << "ERROR: Reading Forcing Internal\n"; self->quit(); return; } diff --git a/build/source/file_access_actor/file_access_actor.f90 b/build/source/file_access_actor/file_access_actor.f90 index dc977d3e3efec16fc22b1e2459ab62fb7c4826f1..d9cdfce071bc53a1b1e92adb8166c5196594b468 100644 --- a/build/source/file_access_actor/file_access_actor.f90 +++ b/build/source/file_access_actor/file_access_actor.f90 @@ -86,9 +86,14 @@ subroutine fileAccessActor_init_fortran(& ! Variables for forcing ! Moudles that pertian to Version 4 (Sundials addition) #ifdef V4_ACTIVE - USE mDecisions_module,only:enthalpyFD,enthalpyFDlu ! look-up values for the choice of heat capacity computation - USE enthalpyTemp_module,only:T2H_lookup_snow ! module to calculate a look-up table for the snow temperature-enthalpy conversion + USE mDecisions_module,only:enthalpyForm, & ! use enthalpy with soil temperature-enthalpy analytical solution + enthalpyFormLU, & ! use enthalpy with soil temperature-enthalpy lookup tables + closedForm ! use temperature with closed form heat capacity + + USE enthalpyTemp_module,only:T2H_lookup_snWat ! module to calculate a look-up table for the snow temperature-enthalpy conversion USE enthalpyTemp_module,only:T2L_lookup_soil ! module to calculate a look-up table for the soil temperature-enthalpy conversion +#else + USE ConvE2Temp_module,only:E2T_lookup #endif implicit none @@ -111,8 +116,10 @@ subroutine fileAccessActor_init_fortran(& ! Variables for forcing integer(i4b) :: ivar ! counter for variables character(len=256) :: attrFile ! attributes file name character(LEN=256) :: restartFile ! restart file name - logical :: needLookup ! logical to decide if computing enthalpy lookup tables - + logical(lgt) :: needLookup_soil ! logical to decide if computing enthalpy lookup tables + logical(lgt) :: checkEnthalpy ! flag if checking enthalpy for consistency + logical(lgt) :: use_lookup ! flag to use the lookup table for soil enthalpy, otherwise use analytical solution + integer(i4b) :: indxGRU=1 character(len=256) :: message ! error message for downwind routine @@ -126,69 +133,71 @@ subroutine fileAccessActor_init_fortran(& ! Variables for forcing ! *** read model decisions ! ***************************************************************************** ! NOTE: Must be after ffile_info because mDecisions uses the data_step - call mDecisions(err,message) - if(err/=0)then; call f_c_string_ptr(message, message_r); return; endif + ! call mDecisions(err,message) + ! if(err/=0)then; call f_c_string_ptr(message, message_r); return; endif ! TODO: This can be moved to a simple getter the file_access_actor calls num_timesteps = numtim ! Returns to the file_access_actor -#ifdef V4_ACTIVE - ! decide if computing enthalpy lookup tables, if need enthalpy and not using hypergeometric function - needLookup = .false. - if(model_decisions(iLookDECISIONS%nrgConserv)%iDecision == enthalpyFDlu) needLookup = .true. -#endif +! #ifdef V4_ACTIVE +! ! decide if computing enthalpy lookup tables, if need enthalpy and not using hypergeometric function +! needLookup_soil = .false. +! ! if need enthalpy for either energy backward Euler residual or IDA state variable and not using soil enthalpy hypergeometric function +! if(model_decisions(iLookDECISIONS%nrgConserv)%iDecision == enthalpyFormLU) needLookup_soil = .true. +! ! if using IDA and enthalpy as a state variable, need temperature-enthalpy lookup tables for soil and vegetation +! #endif - ! get the maximum number of snow layers - select case(model_decisions(iLookDECISIONS%snowLayers)%iDecision) - case(sameRulesAllLayers); err=100; message=trim(message)//'sameRulesAllLayers not implemented';call f_c_string_ptr(trim(message), message_r);return - case(rulesDependLayerIndex); maxSnowLayers = 5 - case default; err=20; message=trim(message)//'unable to identify option to combine/sub-divide snow layers'; call f_c_string_ptr(trim(message), message_r); return - end select ! (option to combine/sub-divide snow layers) + ! ! get the maximum number of snow layers + ! select case(model_decisions(iLookDECISIONS%snowLayers)%iDecision) + ! case(sameRulesAllLayers); err=100; message=trim(message)//'sameRulesAllLayers not implemented';call f_c_string_ptr(trim(message), message_r);return + ! case(rulesDependLayerIndex); maxSnowLayers = 5 + ! case default; err=20; message=trim(message)//'unable to identify option to combine/sub-divide snow layers'; call f_c_string_ptr(trim(message), message_r); return + ! end select ! (option to combine/sub-divide snow layers) - maxLayers = gru_struc(1)%hruInfo(1)%nSoil + maxSnowLayers + ! maxLayers = gru_struc(1)%hruInfo(1)%nSoil + maxSnowLayers ! ***************************************************************************** ! *** read default model parameters ! ***************************************************************************** - ! read default values and constraints for model parameters (local column) - call read_pinit(LOCALPARAM_INFO,.TRUE., mpar_meta,localParFallback,err,message) - if(err/=0)then; call f_c_string_ptr(trim(message), message_r); return; endif + ! ! read default values and constraints for model parameters (local column) + ! call read_pinit(LOCALPARAM_INFO,.TRUE., mpar_meta,localParFallback,err,message) + ! if(err/=0)then; call f_c_string_ptr(trim(message), message_r); return; endif - ! read default values and constraints for model parameters (basin-average) - call read_pinit(BASINPARAM_INFO,.FALSE.,bpar_meta,basinParFallback,err,message) - if(err/=0)then; call f_c_string_ptr(trim(message), message_r); return; endif + ! ! read default values and constraints for model parameters (basin-average) + ! call read_pinit(BASINPARAM_INFO,.FALSE.,bpar_meta,basinParFallback,err,message) + ! if(err/=0)then; call f_c_string_ptr(trim(message), message_r); return; endif ! ***************************************************************************** ! *** read Noah vegetation and soil tables ! ***************************************************************************** - greenVegFrac_monthly = (/0.01_dp, 0.02_dp, 0.03_dp, 0.07_dp, 0.50_dp, 0.90_dp,& - 0.95_dp, 0.96_dp, 0.65_dp, 0.24_dp, 0.11_dp, 0.02_dp/) + ! greenVegFrac_monthly = (/0.01_dp, 0.02_dp, 0.03_dp, 0.07_dp, 0.50_dp, 0.90_dp,& + ! 0.95_dp, 0.96_dp, 0.65_dp, 0.24_dp, 0.11_dp, 0.02_dp/) ! read Noah soil and vegetation tables - call soil_veg_gen_parm(trim(SETTINGS_PATH)//trim(VEGPARM), & ! filename for vegetation table - trim(SETTINGS_PATH)//trim(SOILPARM), & ! filename for soils table - trim(SETTINGS_PATH)//trim(GENPARM), & ! filename for general table - trim(model_decisions(iLookDECISIONS%vegeParTbl)%cDecision), & ! classification system used for vegetation - trim(model_decisions(iLookDECISIONS%soilCatTbl)%cDecision)) ! classification system used for soils - if(err/=0)then; call f_c_string_ptr(trim(message), message_r); return; endif + ! call soil_veg_gen_parm(trim(SETTINGS_PATH)//trim(VEGPARM), & ! filename for vegetation table + ! trim(SETTINGS_PATH)//trim(SOILPARM), & ! filename for soils table + ! trim(SETTINGS_PATH)//trim(GENPARM), & ! filename for general table + ! trim(model_decisions(iLookDECISIONS%vegeParTbl)%cDecision), & ! classification system used for vegetation + ! trim(model_decisions(iLookDECISIONS%soilCatTbl)%cDecision)) ! classification system used for soils + ! if(err/=0)then; call f_c_string_ptr(trim(message), message_r); return; endif ! read Noah-MP vegetation tables - call read_mp_veg_parameters(trim(SETTINGS_PATH)//trim(MPTABLE), & ! filename for Noah-MP table - trim(model_decisions(iLookDECISIONS%vegeParTbl)%cDecision)) ! classification system used for vegetation - if(err/=0)then; call f_c_string_ptr(trim(message), message_r); return; endif + ! call read_mp_veg_parameters(trim(SETTINGS_PATH)//trim(MPTABLE), & ! filename for Noah-MP table + ! trim(model_decisions(iLookDECISIONS%vegeParTbl)%cDecision)) ! classification system used for vegetation + ! if(err/=0)then; call f_c_string_ptr(trim(message), message_r); return; endif ! define urban vegetation category - select case(trim(model_decisions(iLookDECISIONS%vegeParTbl)%cDecision)) - case('USGS'); urbanVegCategory = 1 - case('MODIFIED_IGBP_MODIS_NOAH'); urbanVegCategory = 13 - case('plumberCABLE'); urbanVegCategory = -999 - case('plumberCHTESSEL'); urbanVegCategory = -999 - case('plumberSUMMA'); urbanVegCategory = -999 - case default; message=trim(message)//'unable to identify vegetation category';call f_c_string_ptr(trim(message), message_r);return - end select + ! select case(trim(model_decisions(iLookDECISIONS%vegeParTbl)%cDecision)) + ! case('USGS'); urbanVegCategory = 1 + ! case('MODIFIED_IGBP_MODIS_NOAH'); urbanVegCategory = 13 + ! case('plumberCABLE'); urbanVegCategory = -999 + ! case('plumberCHTESSEL'); urbanVegCategory = -999 + ! case('plumberSUMMA'); urbanVegCategory = -999 + ! case default; message=trim(message)//'unable to identify vegetation category';call f_c_string_ptr(trim(message), message_r);return + ! end select ! ***************************************************************************** ! *** Initialize output structure @@ -207,164 +216,144 @@ subroutine fileAccessActor_init_fortran(& ! Variables for forcing ! *** Read Attributes ! ***************************************************************************** - attrFile = trim(SETTINGS_PATH)//trim(LOCAL_ATTRIBUTES) - call read_attrb(trim(attrFile),num_gru,outputStructure(1)%attrStruct,& - outputStructure(1)%typeStruct,outputStructure(1)%idStruct,err,message) - if(err/=0)then; call f_c_string_ptr(trim(message), message_r); return; endif + ! attrFile = trim(SETTINGS_PATH)//trim(LOCAL_ATTRIBUTES) + ! call read_attrb(trim(attrFile),num_gru,outputStructure(1)%attrStruct,& + ! outputStructure(1)%typeStruct,outputStructure(1)%idStruct,err,message) + ! if(err/=0)then; call f_c_string_ptr(trim(message), message_r); return; endif - ! set default model parameters - do iGRU=1, num_gru - do iHRU=1, gru_struc(iGRU)%hruCount - ! set parmameters to their default value - outputStructure(1)%dparStruct%gru(iGRU)%hru(iHRU)%var(:) = localParFallback(:)%default_val ! x%hru(:)%var(:) + ! ! set default model parameters + ! do iGRU=1, num_gru + ! do iHRU=1, gru_struc(iGRU)%hruCount + ! ! set parmameters to their default value + ! outputStructure(1)%dparStruct%gru(iGRU)%hru(iHRU)%var(:) = localParFallback(:)%default_val ! x%hru(:)%var(:) - ! overwrite default model parameters with information from the Noah-MP tables - call pOverwrite(outputStructure(1)%typeStruct%gru(iGRU)%hru(iHRU)%var(iLookTYPE%vegTypeIndex), & ! vegetation category - outputStructure(1)%typeStruct%gru(iGRU)%hru(iHRU)%var(iLookTYPE%soilTypeIndex), & ! soil category - outputStructure(1)%dparStruct%gru(iGRU)%hru(iHRU)%var, & ! default model parameters - err,message) ! error control - if(err/=0)then; call f_c_string_ptr(trim(message), message_r); return; endif + ! ! overwrite default model parameters with information from the Noah-MP tables + ! call pOverwrite(outputStructure(1)%typeStruct%gru(iGRU)%hru(iHRU)%var(iLookTYPE%vegTypeIndex), & ! vegetation category + ! outputStructure(1)%typeStruct%gru(iGRU)%hru(iHRU)%var(iLookTYPE%soilTypeIndex), & ! soil category + ! outputStructure(1)%dparStruct%gru(iGRU)%hru(iHRU)%var, & ! default model parameters + ! err,message) ! error control + ! if(err/=0)then; call f_c_string_ptr(trim(message), message_r); return; endif - ! copy over to the parameter structure - ! NOTE: constant for the dat(:) dimension (normally depth) - do ivar=1,size(localParFallback) - outputStructure(1)%mparStruct%gru(iGRU)%hru(iHRU)%var(ivar)%dat(:) = outputStructure(1)%dparStruct%gru(iGRU)%hru(iHRU)%var(ivar) - end do ! looping through variables + ! ! copy over to the parameter structure + ! ! NOTE: constant for the dat(:) dimension (normally depth) + ! do ivar=1,size(localParFallback) + ! outputStructure(1)%mparStruct%gru(iGRU)%hru(iHRU)%var(ivar)%dat(:) = outputStructure(1)%dparStruct%gru(iGRU)%hru(iHRU)%var(ivar) + ! end do ! looping through variables - end do ! looping through HRUs + ! end do ! looping through HRUs - ! set default for basin-average parameters - outputStructure(1)%bparStruct%gru(iGRU)%var(:) = basinParFallback(:)%default_val + ! ! set default for basin-average parameters + ! outputStructure(1)%bparStruct%gru(iGRU)%var(:) = basinParFallback(:)%default_val - end do ! looping through GRUs + ! end do ! looping through GRUs ! ***************************************************************************** ! *** Read Parameters ! ***************************************************************************** - checkHRU = integerMissing - call read_param(iRunMode,checkHRU,start_gru,num_hru,num_gru,outputStructure(1)%idStruct,& - outputStructure(1)%mparStruct,outputStructure(1)%bparStruct,err,message) - if(err/=0)then; call f_c_string_ptr(trim(message), message_r); return; endif + ! checkHRU = integerMissing + ! call read_param(iRunMode,checkHRU,start_gru,num_hru,num_gru,outputStructure(1)%idStruct,& + ! outputStructure(1)%mparStruct,outputStructure(1)%bparStruct,err,message) + ! if(err/=0)then; call f_c_string_ptr(trim(message), message_r); return; endif ! ***************************************************************************** ! *** compute derived model variables that are pretty much constant for the basin as a whole ! ***************************************************************************** ! ! loop through GRUs - do iGRU=1,num_gru - ! calculate the fraction of runoff in future time steps - call fracFuture(outputStructure(1)%bparStruct%gru(iGRU)%var, & ! vector of basin-average model parameters - outputStructure(1)%bvarStruct_init%gru(iGRU), & ! data structure of basin-average variables - err,message) ! error control - if(err/=0)then; call f_c_string_ptr(trim(message), message_r); return; endif + ! do iGRU=1,num_gru + ! ! calculate the fraction of runoff in future time steps + ! call fracFuture(outputStructure(1)%bparStruct%gru(iGRU)%var, & ! vector of basin-average model parameters + ! outputStructure(1)%bvarStruct_init%gru(iGRU), & ! data structure of basin-average variables + ! err,message) ! error control + ! if(err/=0)then; call f_c_string_ptr(trim(message), message_r); return; endif - ! loop through local HRUs - do iHRU=1,gru_struc(iGRU)%hruCount + ! ! loop through local HRUs + ! do iHRU=1,gru_struc(iGRU)%hruCount - kHRU=0 - ! check the network topology (only expect there to be one downslope HRU) - do jHRU=1,gru_struc(iGRU)%hruCount - if(outputStructure(1)%typeStruct%gru(iGRU)%hru(iHRU)%var(iLookTYPE%downHRUindex) == outputStructure(1)%idStruct%gru(iGRU)%hru(jHRU)%var(iLookID%hruId))then - if(kHRU==0)then ! check there is a unique match - kHRU=jHRU - else - message=trim(message)//'only expect there to be one downslope HRU'; call f_c_string_ptr(trim(message), message_r); return - end if ! (check there is a unique match) - end if ! (if identified a downslope HRU) - end do - - - ! check that the parameters are consistent - call paramCheck(outputStructure(1)%mparStruct%gru(iGRU)%hru(iHRU),err,message) - if(err/=0)then; call f_c_string_ptr(trim(message), message_r); return; endif + ! kHRU=0 + ! ! check the network topology (only expect there to be one downslope HRU) + ! do jHRU=1,gru_struc(iGRU)%hruCount + ! if(outputStructure(1)%typeStruct%gru(iGRU)%hru(iHRU)%var(iLookTYPE%downHRUindex) == outputStructure(1)%idStruct%gru(iGRU)%hru(jHRU)%var(iLookID%hruId))then + ! if(kHRU==0)then ! check there is a unique match + ! kHRU=jHRU + ! else + ! message=trim(message)//'only expect there to be one downslope HRU'; call f_c_string_ptr(trim(message), message_r); return + ! end if ! (check there is a unique match) + ! end if ! (if identified a downslope HRU) + ! end do + + + ! ! check that the parameters are consistent + ! call paramCheck(outputStructure(1)%mparStruct%gru(iGRU)%hru(iHRU),err,message) + ! if(err/=0)then; call f_c_string_ptr(trim(message), message_r); return; endif #ifdef V4_ACTIVE ! calculate a look-up table for the temperature-enthalpy conversion of snow for future snow layer merging + ! NOTE1: might be able to make this more efficient by only doing this for the HRUs that have snow ! NOTE2: H is the mixture enthalpy of snow liquid and ice - call T2H_lookup_snow(outputStructure(1)%mparStruct%gru(iGRU)%hru(iHRU),err,message) - if(err/=0)then; call f_c_string_ptr(trim(message), message_r); return; endif - - ! calculate a lookup table for the temperature-enthalpy conversion of soil - ! NOTE: L is the integral of soil Clapeyron equation liquid water matric potential from temperature - ! multiply by Cp_liq*iden_water to get temperature component of enthalpy - if(needLookup)then - call T2L_lookup_soil(gru_struc(iGRU)%hruInfo(iHRU)%nSoil, & ! intent(in): number of soil layers - outputStructure(1)%mparStruct%gru(iGRU)%hru(iHRU), & ! intent(in): parameter data structure - outputStructure(1)%lookupStruct%gru(iGRU)%hru(iHRU), & ! intent(inout): lookup table data structure - err,message) ! intent(out): error control - if(err/=0)then; call f_c_string_ptr(trim(message), message_r); return; endif - endif -else - ! calculate a look-up table for the temperature-enthalpy conversion - call E2T_lookup(outputStructure(1)%mparStruct%gru(iGRU)%hru(iHRU),err,message) - if(err/=0)then; message=trim(message); call f_c_string_ptr(trim(message), message_r); return; endif + ! call T2H_lookup_snWat(outputStructure(1)%mparStruct%gru(iGRU)%hru(iHRU),err,message) + ! if(err/=0)then; call f_c_string_ptr(trim(message), message_r); return; endif + + ! ! calculate a lookup table for the temperature-enthalpy conversion of soil + ! ! NOTE: L is the integral of soil Clapeyron equation liquid water matric potential from temperature + ! ! multiply by Cp_liq*iden_water to get temperature component of enthalpy + ! if(needLookup_soil)then + ! call T2L_lookup_soil(gru_struc(iGRU)%hruInfo(iHRU)%nSoil, & ! intent(in): number of soil layers + ! outputStructure(1)%mparStruct%gru(iGRU)%hru(iHRU), & ! intent(in): parameter data structure + ! outputStructure(1)%lookupStruct%gru(iGRU)%hru(iHRU), & ! intent(inout): lookup table data structure + ! err,message) ! intent(out): error control + ! if(err/=0)then; call f_c_string_ptr(trim(message), message_r); return; endif + ! endif +#else + ! ! calculate a look-up table for the temperature-enthalpy conversion + ! call E2T_lookup(outputStructure(1)%mparStruct%gru(iGRU)%hru(iHRU),err,message) + ! if(err/=0)then; message=trim(message); call f_c_string_ptr(trim(message), message_r); return; endif #endif - ! overwrite the vegetation height - HVT(outputStructure(1)%typeStruct%gru(iGRU)%hru(iHRU)%var(iLookTYPE%vegTypeIndex)) = outputStructure(1)%mparStruct%gru(iGRU)%hru(iHRU)%var(iLookPARAM%heightCanopyTop)%dat(1) - HVB(outputStructure(1)%typeStruct%gru(iGRU)%hru(iHRU)%var(iLookTYPE%vegTypeIndex)) = outputStructure(1)%mparStruct%gru(iGRU)%hru(iHRU)%var(iLookPARAM%heightCanopyBottom)%dat(1) - - ! overwrite the tables for LAI and SAI - if(model_decisions(iLookDECISIONS%LAI_method)%iDecision == specified)then - SAIM(outputStructure(1)%typeStruct%gru(iGRU)%hru(iHRU)%var(iLookTYPE%vegTypeIndex),:) = outputStructure(1)%mparStruct%gru(iGRU)%hru(iHRU)%var(iLookPARAM%winterSAI)%dat(1) - LAIM(outputStructure(1)%typeStruct%gru(iGRU)%hru(iHRU)%var(iLookTYPE%vegTypeIndex),:) = outputStructure(1)%mparStruct%gru(iGRU)%hru(iHRU)%var(iLookPARAM%summerLAI)%dat(1)*greenVegFrac_monthly - endif - - end do ! HRU - - ! compute total area of the upstream HRUS that flow into each HRU - do iHRU=1,gru_struc(iGRU)%hruCount - outputStructure(1)%upArea%gru(iGRU)%hru(iHRU) = 0._rkind - do jHRU=1,gru_struc(iGRU)%hruCount - ! check if jHRU flows into iHRU; assume no exchange between GRUs - if(outputStructure(1)%typeStruct%gru(iGRU)%hru(jHRU)%var(iLookTYPE%downHRUindex)==outputStructure(1)%typeStruct%gru(iGRU)%hru(iHRU)%var(iLookID%hruId))then - outputStructure(1)%upArea%gru(iGRU)%hru(iHRU) = outputStructure(1)%upArea%gru(iGRU)%hru(iHRU) + outputStructure(1)%attrStruct%gru(iGRU)%hru(jHRU)%var(iLookATTR%HRUarea) - endif ! (if jHRU is an upstream HRU) - end do ! jHRU - end do ! iHRU - - ! identify the total basin area for a GRU (m2) - outputStructure(1)%bvarStruct_init%gru(iGRU)%var(iLookBVAR%basin__totalArea)%dat(1) = 0._rkind - do iHRU=1,gru_struc(iGRU)%hruCount - outputStructure(1)%bvarStruct_init%gru(iGRU)%var(iLookBVAR%basin__totalArea)%dat(1) = & - outputStructure(1)%bvarStruct_init%gru(iGRU)%var(iLookBVAR%basin__totalArea)%dat(1) + outputStructure(1)%attrStruct%gru(iGRU)%hru(iHRU)%var(iLookATTR%HRUarea) - end do - - end do ! GRU - - - - - - - ! ***************************************************************************** - ! Restart File + ! ! overwrite the vegetation height ! HVT(outputStructure(1)%typeStruct%gru(iGRU)%hru(iHRU)%var(iLookTYPE%vegTypeIndex)) = outputStructure(1)%mparStruct%gru(iGRU)%hru(iHRU)%var(iLookPARAM%heightCanopyTop)%dat(1) ! HVB(outputStructure(1)%typeStruct%gru(iGRU)%hru(iHRU)%var(iLookTYPE%vegTypeIndex)) = outputStructure(1)%mparStruct%gru(iGRU)%hru(iHRU)%var(iLookPARAM%heightCanopyBottom)%dat(1) ! ! overwrite the tables for LAI and SAI ! if(model_decisions(iLookDECISIONS%LAI_method)%iDecision == specified)then ! SAIM(outputStructure(1)%typeStruct%gru(iGRU)%hru(iHRU)%var(iLookTYPE%vegTypeIndex),:) = outputStructure(1)%mparStruct%gru(iGRU)%hru(iHRU)%var(iLookPARAM%winterSAI)%dat(1) ! LAIM(outputStructure(1)%typeStruct%gru(iGRU)%hru(iHRU)%var(iLookTYPE%vegTypeIndex),:) = outputStructure(1)%mparStruct%gru(iGRU)%hru(iHRU)%var(iLookPARAM%summerLAI)%dat(1)*greenVegFrac_monthly ! endif ! end do ! HRU ! ! compute total area of the upstream HRUS that flow into each HRU ! do iHRU=1,gru_struc(iGRU)%hruCount ! outputStructure(1)%upArea%gru(iGRU)%hru(iHRU) = 0._rkind ! do jHRU=1,gru_struc(iGRU)%hruCount ! ! check if jHRU flows into iHRU; assume no exchange between GRUs ! if(outputStructure(1)%typeStruct%gru(iGRU)%hru(jHRU)%var(iLookTYPE%downHRUindex)==outputStructure(1)%typeStruct%gru(iGRU)%hru(iHRU)%var(iLookID%hruId))then ! outputStructure(1)%upArea%gru(iGRU)%hru(iHRU) = outputStructure(1)%upArea%gru(iGRU)%hru(iHRU) + outputStructure(1)%attrStruct%gru(iGRU)%hru(jHRU)%var(iLookATTR%HRUarea) ! endif ! (if jHRU is an upstream HRU) ! end do ! jHRU ! end do ! iHRU ! ! identify the total basin area for a GRU (m2) ! outputStructure(1)%bvarStruct_init%gru(iGRU)%var(iLookBVAR%basin__totalArea)%dat(1) = 0._rkind ! do iHRU=1,gru_struc(iGRU)%hruCount ! outputStructure(1)%bvarStruct_init%gru(iGRU)%var(iLookBVAR%basin__totalArea)%dat(1) = & ! outputStructure(1)%bvarStruct_init%gru(iGRU)%var(iLookBVAR%basin__totalArea)%dat(1) + outputStructure(1)%attrStruct%gru(iGRU)%hru(iHRU)%var(iLookATTR%HRUarea) ! end do ! end do ! GRU ! ***************************************************************************** ! Restart File ! ***************************************************************************** ! define restart file path/name - if(STATE_PATH == '') then - restartFile = trim(SETTINGS_PATH)//trim(MODEL_INITCOND) - else - restartFile = trim(STATE_PATH)//trim(MODEL_INITCOND) - endif - - ! read initial conditions - call read_icond(restartFile, & ! intent(in): name of initial conditions file - num_gru, & ! intent(in): number of response units - outputStructure(1)%mparStruct, & ! intent(in): model parameters - outputStructure(1)%progStruct_init, & ! intent(inout): model prognostic variables - outputStructure(1)%bvarStruct_init, & ! intent(inout): model basin (GRU) variables - outputStructure(1)%indxStruct_init, & ! intent(inout): model indices - err,message) ! intent(out): error control - if(err/=0)then; call f_c_string_ptr(trim(message), message_r); return; endif - - call check_icond(num_gru, & - outputStructure(1)%progStruct_init, & ! intent(inout): model prognostic variables - outputStructure(1)%mparStruct, & ! intent(in): model parameters - outputStructure(1)%indxStruct_init, & ! intent(inout): model indices - err,message) ! intent(out): error control +! if(STATE_PATH == '') then +! restartFile = trim(SETTINGS_PATH)//trim(MODEL_INITCOND) +! else +! restartFile = trim(STATE_PATH)//trim(MODEL_INITCOND) +! endif + +! ! read initial conditions +! call read_icond(restartFile, & ! intent(in): name of initial conditions file +! num_gru, & ! intent(in): number of response units +! outputStructure(1)%mparStruct, & ! intent(in): model parameters +! outputStructure(1)%progStruct_init, & ! intent(inout): model prognostic variables +! outputStructure(1)%bvarStruct_init, & ! intent(inout): model basin (GRU) variables +! outputStructure(1)%indxStruct_init, & ! intent(inout): model indices +! err,message) ! intent(out): error control +! if(err/=0)then; call f_c_string_ptr(trim(message), message_r); return; endif + +! #ifdef V4_ACTIVE +! checkEnthalpy = .false. +! use_lookup = .false. +! if(model_decisions(iLookDECISIONS%nrgConserv)%iDecision .ne. closedForm) checkEnthalpy = .true. ! check enthalpy either for mixed form energy equation or enthalpy state variable +! if(model_decisions(iLookDECISIONS%nrgConserv)%iDecision==enthalpyFormLU) use_lookup = .true. ! use lookup tables for soil temperature-enthalpy instead of analytical solution +! call check_icond(num_gru, & ! intent(in): number of response units +! outputStructure(1)%progStruct_init, & ! intent(inout): model prognostic variables +! outputStructure(1)%diagStruct, & ! intent(inout): model diagnostic variables +! outputStructure(1)%mparStruct, & ! intent(in): model parameters +! outputStructure(1)%indxStruct_init, & ! intent(in): layer indexes +! outputStructure(1)%lookupStruct, & ! intent(in): lookup tables +! checkEnthalpy, & ! intent(in): flag if need to start with consistent enthalpy +! use_lookup, & ! intent(in): flag to use the lookup table for soil enthalpy +! err,message) + +! #else +! call check_icond(num_gru, & +! outputStructure(1)%progStruct_init, & ! intent(inout): model prognostic variables +! outputStructure(1)%mparStruct, & ! intent(in): model parameters +! outputStructure(1)%indxStruct_init, & ! intent(inout): model indices +! err,message) ! intent(out): error control +! #endif if(err/=0)then; call f_c_string_ptr(trim(message), message_r); return; endif end subroutine fileAccessActor_init_fortran @@ -465,15 +454,6 @@ subroutine FileAccessActor_DeallocateStructures(handle_ncid) bind(C,name="FileAc call c_f_pointer(handle_ncid, ncid) - - ! close the open output Files - ! do iFreq=1,maxvarFreq - ! if (ncid%var(iFreq)/=integerMissing) then - ! call nc_file_close(ncid%var(iFreq),err,cmessage) - ! if(err/=0)then; message=trim(message)//trim(cmessage); return; end if - ! endif - ! end do - deallocate(ncid) deallocate(outputTimeStep) deallocate(outputStructure) diff --git a/build/source/file_access_actor/forcing_file_info.cpp b/build/source/file_access_actor/forcing_file_info.cpp index 0430823fe95940154211fc49fdc56224a941071d..6ca84bde21578ac1ae62e22d7251f28b35ada528 100644 --- a/build/source/file_access_actor/forcing_file_info.cpp +++ b/build/source/file_access_actor/forcing_file_info.cpp @@ -25,7 +25,8 @@ forcingFileContainer::~forcingFileContainer() { int forcingFileContainer::initForcingFiles(int num_gru) { file_access_timing_.updateStartPoint("init_duration"); - int num_files, err; + int num_files = 0; + int err = 0; std::unique_ptr<char[]> message(new char[256]); // initalize the fortran side @@ -55,10 +56,12 @@ int forcingFileContainer::initForcingFiles(int num_gru) { } getFileInfoCopy_fortran(i, &file_name, forcing_files_[i-1].nVars, - forcing_files_[i-1].nTimeSteps, varName_size, var_ix_size, - data_id_size, var_name_arr.data(), forcing_files_[i-1].var_ix.data(), - forcing_files_[i-1].data_id.data(), forcing_files_[i-1].firstJulDay, - forcing_files_[i-1].convTime2Days); + forcing_files_[i-1].nTimeSteps, varName_size, + var_ix_size, data_id_size, var_name_arr.data(), + forcing_files_[i-1].var_ix.data(), + forcing_files_[i-1].data_id.data(), + forcing_files_[i-1].firstJulDay, + forcing_files_[i-1].convTime2Days); forcing_files_[i-1].filenmData = std::string(file_name.get()); forcing_files_[i-1].nVars = varName_size; diff --git a/build/source/file_access_actor/forcing_file_info.f90 b/build/source/file_access_actor/forcing_file_info.f90 index ab80eb74ddcda81c84e875fe956d5d253748df82..eb553fc295cbba732e489958cbc6a20e787c1bd8 100644 --- a/build/source/file_access_actor/forcing_file_info.f90 +++ b/build/source/file_access_actor/forcing_file_info.f90 @@ -36,8 +36,8 @@ subroutine ffile_info_fortran(num_gru, num_forcing_files, err, message_r) & ! ***************************************************************************** ! *** read description of model forcing datafile used in each HRU ! ***************************************************************************** - call ffile_info(num_gru, err, message) - if(err/=0)then; call f_c_string_ptr(trim(message), message_r); return; endif + ! call ffile_info(num_gru, err, message) + ! if(err/=0)then; call f_c_string_ptr(trim(message), message_r); return; endif num_forcing_files = size(forcFileInfo) end subroutine ffile_info_fortran @@ -259,9 +259,9 @@ subroutine openForcingFile(forc_file,iFile,infile,ncId,err,message) ! define the reference time for the model simulation call extractTime(refTimeString, & ! input = units string for time data - iyyy,im,id,ih,imin,dsec, & ! output = year, month, day, hour, minute, second - ih_tz, imin_tz, dsec_tz, & ! output = time zone information (hour, minute, second) - err,cmessage) ! output = error code and error message + iyyy,im,id,ih,imin,dsec, & ! output = year, month, day, hour, minute, second + ih_tz, imin_tz, dsec_tz, & ! output = time zone information (hour, minute, second) + err,cmessage) ! output = error code and error message if(err/=0)then; message=trim(message)//trim(cmessage); return; end if select case(trim(NC_TIME_ZONE)) diff --git a/build/source/file_access_actor/summa_init_struc.cpp b/build/source/file_access_actor/summa_init_struc.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b34b06f78b2286f1a1d230424c6b1b830908c5ad --- /dev/null +++ b/build/source/file_access_actor/summa_init_struc.cpp @@ -0,0 +1,30 @@ +#include "summa_init_struc.hpp" +#include <memory> + +SummaInitStruc::SummaInitStruc() {} + +SummaInitStruc::~SummaInitStruc() { + deallocate_init_struc(); +} + +int SummaInitStruc::allocate(int num_gru) { + int err = 0; + std::unique_ptr<char[]> message(new char[256]); + initialize_init_struc(num_gru, err, &message); + return err; +} + +int SummaInitStruc::summa_paramSetup() { + int err = 0; + std::unique_ptr<char[]> message(new char[256]); + paramSetup_fortran(err, &message); + return err; +} + +int SummaInitStruc::summa_readRestart() { + int err = 0; + std::unique_ptr<char[]> message(new char[256]); + readRestart_fortran(err, &message); + return err; +} + diff --git a/build/source/file_access_actor/summa_init_struc.f90 b/build/source/file_access_actor/summa_init_struc.f90 new file mode 100644 index 0000000000000000000000000000000000000000..6b4e719ce8736d5b64bca48e4113b161d90a7152 --- /dev/null +++ b/build/source/file_access_actor/summa_init_struc.f90 @@ -0,0 +1,194 @@ +module summa_init_struc + USE iso_c_binding + USE nrtype + USE summa_type, only:summa1_type_dec ! master summa data type + implicit none + public :: initialize_init_struc + public :: paramSetup_fortran + public :: deallocate_init_struc + ! Used to get all the inital conditions for the model -- allows calling summa_setup.f90 + type(summa1_type_dec),allocatable,save,public :: init_struc + + contains +subroutine initialize_init_struc(num_gru, err, message_r) bind(C, name="initialize_init_struc") + USE globalData,only:structInfo ! information on the data structures + USE globalData,only:gru_struc ! gru-hru mapping structures + USE globalData,only:time_meta, & + forc_meta, & + attr_meta, & + type_meta, & + prog_meta, & + diag_meta, & + flux_meta, & + id_meta, & + mpar_meta, & + indx_meta, & + bpar_meta, & + bvar_meta + ! statistics metadata structures + USE globalData,only:statForc_meta, & ! child metadata for stats + statProg_meta, & ! child metadata for stats + statDiag_meta, & ! child metadata for stats + statFlux_meta, & ! child metadata for stats + statIndx_meta, & ! child metadata for stats + statBvar_meta ! child metadata for stats + USE allocspace_module,only:allocGlobal ! module to allocate space for global data structures + USE C_interface_module,only:f_c_string_ptr ! convert fortran string to c string + implicit none + ! dummy variables + integer(c_int), intent(in) :: num_gru + integer(c_int), intent(out) :: err + type(c_ptr), intent(out) :: message_r + ! local variables + integer(i4b) :: iStruct,iGRU ! looping variables + character(len=256) :: message ! error message + character(len=256) :: cmessage ! error message + + ! Start of subroutine + message = '' + call f_c_string_ptr(message, message_r) + allocate(init_struc) + summaVars: associate(& + ! statistics structures + forcStat => init_struc%forcStat , & ! x%gru(:)%hru(:)%var(:)%dat -- model forcing data + progStat => init_struc%progStat , & ! x%gru(:)%hru(:)%var(:)%dat -- model prognostic (state) variables + diagStat => init_struc%diagStat , & ! x%gru(:)%hru(:)%var(:)%dat -- model diagnostic variables + fluxStat => init_struc%fluxStat , & ! x%gru(:)%hru(:)%var(:)%dat -- model fluxes + indxStat => init_struc%indxStat , & ! x%gru(:)%hru(:)%var(:)%dat -- model indices + bvarStat => init_struc%bvarStat , & ! x%gru(:)%var(:)%dat -- basin-average variables + + ! primary data structures (scalars) + timeStruct => init_struc%timeStruct , & ! x%var(:) -- model time data + forcStruct => init_struc%forcStruct , & ! x%gru(:)%hru(:)%var(:) -- model forcing data + attrStruct => init_struc%attrStruct , & ! x%gru(:)%hru(:)%var(:) -- local attributes for each HRU + typeStruct => init_struc%typeStruct , & ! x%gru(:)%hru(:)%var(:) -- local classification of soil veg etc. for each HRU + idStruct => init_struc%idStruct , & ! x%gru(:)%hru(:)%var(:) -- + + ! primary data structures (variable length vectors) + indxStruct => init_struc%indxStruct , & ! x%gru(:)%hru(:)%var(:)%dat -- model indices + mparStruct => init_struc%mparStruct , & ! x%gru(:)%hru(:)%var(:)%dat -- model parameters + progStruct => init_struc%progStruct , & ! x%gru(:)%hru(:)%var(:)%dat -- model prognostic (state) variables + diagStruct => init_struc%diagStruct , & ! x%gru(:)%hru(:)%var(:)%dat -- model diagnostic variables + fluxStruct => init_struc%fluxStruct , & ! x%gru(:)%hru(:)%var(:)%dat -- model fluxes + + ! basin-average structures + bparStruct => init_struc%bparStruct , & ! x%gru(:)%var(:) -- basin-average parameters + bvarStruct => init_struc%bvarStruct , & ! x%gru(:)%var(:)%dat -- basin-average variables + + ! ancillary data structures + dparStruct => init_struc%dparStruct , & ! x%gru(:)%hru(:)%var(:) -- default model parameters + + ! run time variables + computeVegFlux => init_struc%computeVegFlux , & ! flag to indicate if we are computing fluxes over vegetation (.false. means veg is buried with snow) + dt_init => init_struc%dt_init , & ! used to initialize the length of the sub-step for each HRU + upArea => init_struc%upArea , & ! area upslope of each HRU + + ! miscellaneous variables + nGRU => init_struc%nGRU , & ! number of grouped response units + nHRU => init_struc%nHRU , & ! number of global hydrologic response units + hruCount => init_struc%hruCount & ! number of local hydrologic response units + ) + + ! allocate other data structures + do iStruct=1,size(structInfo) + ! allocate space + select case(trim(structInfo(iStruct)%structName)) + case('time'); call allocGlobal(time_meta, timeStruct, err, cmessage) ! model forcing data + case('forc'); call allocGlobal(forc_meta, forcStruct, err, cmessage) ! model forcing data + case('attr'); call allocGlobal(attr_meta, attrStruct, err, cmessage) ! local attributes for each HRU + case('type'); call allocGlobal(type_meta, typeStruct, err, cmessage) ! local classification of soil veg etc. for each HRU + case('id' ); call allocGlobal(id_meta, idStruct, err, message) ! local values of hru and gru IDs + case('mpar'); call allocGlobal(mpar_meta, mparStruct, err, cmessage) ! model parameters + case('indx'); call allocGlobal(indx_meta, indxStruct, err, cmessage) ! model variables + case('prog'); call allocGlobal(prog_meta, progStruct, err, cmessage) ! model prognostic (state) variables + case('diag'); call allocGlobal(diag_meta, diagStruct, err, cmessage) ! model diagnostic variables + case('flux'); call allocGlobal(flux_meta, fluxStruct, err, cmessage) ! model fluxes + case('bpar'); call allocGlobal(bpar_meta, bparStruct, err, cmessage) ! basin-average parameters + case('bvar'); call allocGlobal(bvar_meta, bvarStruct, err, cmessage) ! basin-average variables + case('deriv'); cycle + case default; err=20; message='unable to find structure name: '//trim(structInfo(iStruct)%structName) + end select + ! check errors + if(err/=0)then + message=trim(message)//trim(cmessage)//'[structure = '//trim(structInfo(iStruct)%structName)//']' + call f_c_string_ptr(message, message_r) + return + endif + end do ! looping through data structures + + ! allocate space for default model parameters + ! NOTE: This is done here, rather than in the loop above, because dpar is not one of the "standard" data structures + call allocGlobal(mpar_meta,dparStruct,err,cmessage) ! default model parameters + if(err/=0)then + message=trim(message)//trim(cmessage)//' [problem allocating dparStruct]' + call f_c_string_ptr(message, message_r) + return + endif + + ! allocate space for the time step and computeVegFlux flags (recycled for each GRU for subsequent model calls) + allocate(dt_init%gru(num_gru),upArea%gru(num_gru),computeVegFlux%gru(num_gru),stat=err) + if(err/=0)then + message=trim(message)//'problem allocating space for dt_init, upArea, or computeVegFlux [GRU]' + call f_c_string_ptr(message, message_r) + return + endif + + ! allocate space for the HRUs + do iGRU=1,num_gru + hruCount = gru_struc(iGRU)%hruCount ! gru_struc populated in "read_dimension" + allocate(dt_init%gru(iGRU)%hru(hruCount),upArea%gru(iGRU)%hru(hruCount),& + computeVegFlux%gru(iGRU)%hru(hruCount),stat=err) + if(err/=0)then + message='problem allocating space for dt_init, upArea, or computeVegFlux [HRU]' + call f_c_string_ptr(message, message_r) + return + endif + end do + + nGRU = num_gru + nHRU = sum(gru_struc%hruCount) + + + end associate summaVars +end subroutine initialize_init_struc + +subroutine paramSetup_fortran(err, message_r) bind(C, name="paramSetup_fortran") + USE C_interface_module,only:f_c_string_ptr ! convert fortran string to c string + USE summa_setup,only:summa_paramSetup + implicit none + ! dummy variables + integer(c_int), intent(out) :: err + type(c_ptr), intent(out) :: message_r + ! local variables + character(len=256) :: message ! error message + + message = '' + call f_c_string_ptr(message, message_r) + + call summa_paramSetup(init_struc, err, message) + call f_c_string_ptr(message, message_r) + +end subroutine paramSetup_fortran + +subroutine readRestart_fortran(err, message_r) bind(C, name="readRestart_fortran") + USE C_interface_module,only:f_c_string_ptr ! convert fortran string to c string + USE summa_restart,only:summa_readRestart + implicit none + ! dummy variables + integer(c_int), intent(out) :: err + type(c_ptr), intent(out) :: message_r + ! local variables + character(len=256) :: message ! error message + + message = '' + call f_c_string_ptr(message, message_r) + call summa_readRestart(init_struc, err, message) + call f_c_string_ptr(message, message_r) + +end subroutine readRestart_fortran + +subroutine deallocate_init_struc() bind(C, name="deallocate_init_struc") + implicit none + deallocate(init_struc) +end subroutine deallocate_init_struc +end module summa_init_struc \ No newline at end of file diff --git a/build/source/hru_actor/hru_actor.cpp b/build/source/hru_actor/hru_actor.cpp index 6bfacb104124b23225b0f9c4c3b151a0fd3af657..dc754f017c2f63b0a54875e1cbb0577e77751842 100644 --- a/build/source/hru_actor/hru_actor.cpp +++ b/build/source/hru_actor/hru_actor.cpp @@ -1,6 +1,6 @@ #include "hru_actor.hpp" -bool hru_extra_logging = false; +bool hru_extra_logging = true; namespace caf { @@ -58,10 +58,6 @@ behavior hru_actor(stateful_actor<hru_state>* self, int refGRU, int indxGRU, break; } - if (hru_extra_logging) - aout(self) << "HRU:" << self->state.indxGRU << " - Timestep: " - << self->state.timestep << "\n"; - self->state.num_steps_until_write--; err = Run_HRU(self); // Simulate a Timestep if (err != 0) { diff --git a/build/source/hru_actor/hru_init.f90 b/build/source/hru_actor/hru_init.f90 index 2adc3280eb04a967414c55b55a0224ae48769205..3e15273ff5c4baf528861adf1579fc0cdbe773ad 100755 --- a/build/source/hru_actor/hru_init.f90 +++ b/build/source/hru_actor/hru_init.f90 @@ -249,7 +249,7 @@ subroutine setupHRUParam(indxGRU, & ! ID of hru ! * desired modules ! --------------------------------------------------------------------------------------- USE nrtype ! variable types, etc. - USE output_structure_module,only:outputStructure + USE summa_init_struc,only:init_struc ! subroutines and functions use time_utils_module,only:elapsedSec ! calculate the elapsed time USE mDecisions_module,only:mDecisions ! module to read model decisions @@ -302,41 +302,29 @@ subroutine setupHRUParam(indxGRU, & ! ID of hru ! ffile_info and mDecisions moved to their own seperate subroutine call hru_data%oldTime_hru%var(:) = hru_data%startTime_hru%var(:) - - ! Copy the attrStruct - hru_data%attrStruct%var(:) = outputStructure(1)%attrStruct%gru(indxGRU)%hru(indxHRU)%var(:) - ! Copy the typeStruct - hru_data%typeStruct%var(:) = outputStructure(1)%typeStruct%gru(indxGRU)%hru(indxHRU)%var(:) - ! Copy the idStruct - hru_data%idStruct%var(:) = outputStructure(1)%idStruct%gru(indxGRU)%hru(indxHRU)%var(:) - - ! Copy the mparStruct - hru_data%mparStruct%var(:) = outputStructure(1)%mparStruct%gru(indxGRU)%hru(indxHRU)%var(:) - ! Copy the bparStruct - hru_data%bparStruct%var(:) = outputStructure(1)%bparStruct%gru(indxGRU)%var(:) - ! Copy the dparStruct - hru_data%dparStruct%var(:) = outputStructure(1)%dparStruct%gru(indxGRU)%hru(indxHRU)%var(:) - ! Copy the bvarStruct - do ivar=1, size(outputStructure(1)%bvarStruct_init%gru(indxGRU)%var(:)) - hru_data%bvarStruct%var(ivar)%dat(:) = outputStructure(1)%bvarStruct_init%gru(indxGRU)%var(ivar)%dat(:) + hru_data%attrStruct%var(:) = init_struc%attrStruct%gru(indxGRU)%hru(indxHRU)%var(:) + hru_data%typeStruct%var(:) = init_struc%typeStruct%gru(indxGRU)%hru(indxHRU)%var(:) + hru_data%idStruct%var(:) = init_struc%idStruct%gru(indxGRU)%hru(indxHRU)%var(:) + hru_data%mparStruct%var(:) = init_struc%mparStruct%gru(indxGRU)%hru(indxHRU)%var(:) + hru_data%bparStruct%var(:) = init_struc%bparStruct%gru(indxGRU)%var(:) + hru_data%dparStruct%var(:) = init_struc%dparStruct%gru(indxGRU)%hru(indxHRU)%var(:) + do ivar=1, size(init_struc%bvarStruct%gru(indxGRU)%var(:)) + hru_data%bvarStruct%var(ivar)%dat(:) = init_struc%bvarStruct%gru(indxGRU)%var(ivar)%dat(:) enddo - ! Copy the lookup Struct if its allocated #ifdef V4_ACTIVE - if (allocated(outputStructure(1)%lookupStruct%gru(indxGRU)%hru(indxHRU)%z)) then - do i_z=1, size(outputStructure(1)%lookupStruct%gru(indxGRU)%hru(indxHRU)%z(:)) - do iVar=1, size(outputStructure(1)%lookupStruct%gru(indxGRU)%hru(indxHRU)%z(i_z)%var(:)) - hru_data%lookupStruct%z(i_z)%var(ivar)%lookup(:) = outputStructure(1)%lookupStruct%gru(indxGRU)%hru(indxHRU)%z(i_z)%var(iVar)%lookup(:) + if (allocated(init_struc%lookupStruct%gru(indxGRU)%hru(indxHRU)%z)) then + do i_z=1, size(init_struc%lookupStruct%gru(indxGRU)%hru(indxHRU)%z(:)) + do iVar=1, size(init_struc%lookupStruct%gru(indxGRU)%hru(indxHRU)%z(i_z)%var(:)) + hru_data%lookupStruct%z(i_z)%var(ivar)%lookup(:) = init_struc%lookupStruct%gru(indxGRU)%hru(indxHRU)%z(i_z)%var(iVar)%lookup(:) end do end do endif #endif - ! Copy the progStruct_init - do ivar=1, size(outputStructure(1)%progStruct_init%gru(indxGRU)%hru(indxHRU)%var(:)) - hru_data%progStruct%var(ivar)%dat(:) = outputStructure(1)%progStruct_init%gru(indxGRU)%hru(indxHRU)%var(ivar)%dat(:) + do ivar=1, size(init_struc%progStruct%gru(indxGRU)%hru(indxHRU)%var(:)) + hru_data%progStruct%var(ivar)%dat(:) = init_struc%progStruct%gru(indxGRU)%hru(indxHRU)%var(ivar)%dat(:) enddo - ! copy the indexStruct_init - do ivar=1, size(outputStructure(1)%indxStruct_init%gru(indxGRU)%hru(indxHRU)%var(:)) - hru_data%indxStruct%var(ivar)%dat(:) = outputStructure(1)%indxStruct_init%gru(indxGRU)%hru(indxHRU)%var(ivar)%dat(:) + do ivar=1, size(init_struc%indxStruct%gru(indxGRU)%hru(indxHRU)%var(:)) + hru_data%indxStruct%var(ivar)%dat(:) = init_struc%indxStruct%gru(indxGRU)%hru(indxHRU)%var(ivar)%dat(:) enddo end subroutine setupHRUParam diff --git a/build/source/job_actor/job_actor.f90 b/build/source/job_actor/job_actor.f90 index 598f1ee235772ef63b49ba7ebcf3b86c2f7d8a5e..321971c312c83b9748235b885eff598dd609e0e5 100644 --- a/build/source/job_actor/job_actor.f90 +++ b/build/source/job_actor/job_actor.f90 @@ -72,14 +72,6 @@ subroutine job_init_fortran(file_manager, start_gru, num_gru,& startGRU=start_gru iRunMode=iRunModeGRU checkHRU=integerMissing - - ! TODO: MOVED TO SUMMA_ACTOR (Batch_Distributer_Actor) - ! call summa_SetTimesDirsAndFiles(summaFileManagerIn,err,message) - ! if(err/=0)then; print*, trim(message); return; endif - - ! TODO: MOVED TO fortran_global_state_actor - ! call summa_defineGlobalData(err, message) - ! if(err/=0)then; print*, trim(message); return; endif ! ***************************************************************************** ! *** read the number of GRUs and HRUs