diff --git a/ccpp/config/ccpp_prebuild_config.py b/ccpp/config/ccpp_prebuild_config.py index 99313c01b..aa18cbbaa 100755 --- a/ccpp/config/ccpp_prebuild_config.py +++ b/ccpp/config/ccpp_prebuild_config.py @@ -23,7 +23,7 @@ TYPEDEFS_NEW_METADATA = { 'ccpp_types' : { 'ccpp_types' : '', - 'ccpp_t' : 'cdata(i)', + 'ccpp_t' : 'cdata', }, 'machine' : { 'machine' : '', @@ -35,17 +35,17 @@ 'module_radlw_parameters' : '', }, 'GFS_typedefs' : { - 'GFS_diag_type' : 'physics%Diag(cdata(i)%blk_no)', - 'GFS_control_type' : 'physics%Model(cdata(i)%blk_no)', - 'GFS_cldprop_type' : 'physics%Cldprop(cdata(i)%blk_no)', - 'GFS_tbd_type' : 'physics%Tbd(cdata(i)%blk_no)', - 'GFS_sfcprop_type' : 'physics%Sfcprop(cdata(i)%blk_no)', - 'GFS_coupling_type' : 'physics%Coupling(cdata(i)%blk_no)', - 'GFS_interstitial_type' : 'physics%Interstitial(cdata(i)%blk_no)', - 'GFS_statein_type' : 'physics%Statein(cdata(i)%blk_no)', - 'GFS_radtend_type' : 'physics%Radtend(cdata(i)%blk_no)', - 'GFS_grid_type' : 'physics%Grid(cdata(i)%blk_no)', - 'GFS_stateout_type' : 'physics%Stateout(cdata(i)%blk_no)', + 'GFS_diag_type' : 'physics%Diag(cdata%blk_no)', + 'GFS_control_type' : 'physics%Model(cdata%blk_no)', + 'GFS_cldprop_type' : 'physics%Cldprop(cdata%blk_no)', + 'GFS_tbd_type' : 'physics%Tbd(cdata%blk_no)', + 'GFS_sfcprop_type' : 'physics%Sfcprop(cdata%blk_no)', + 'GFS_coupling_type' : 'physics%Coupling(cdata%blk_no)', + 'GFS_interstitial_type' : 'physics%Interstitial(cdata%blk_no)', + 'GFS_statein_type' : 'physics%Statein(cdata%blk_no)', + 'GFS_radtend_type' : 'physics%Radtend(cdata%blk_no)', + 'GFS_grid_type' : 'physics%Grid(cdata%blk_no)', + 'GFS_stateout_type' : 'physics%Stateout(cdata%blk_no)', 'GFS_typedefs' : '', }, 'gmtb_scm_physical_constants' : { @@ -139,7 +139,10 @@ 'ccpp/physics/physics/namelist_soilveg_ruc.F90', 'ccpp/physics/physics/set_soilveg_ruc.F90', 'ccpp/physics/physics/module_soil_pre.F90', - 'scm/src/GFS_typedefs.F90' + # derived data type definitions + 'scm/src/GFS_typedefs.F90', + 'scm/src/gmtb_scm_kinds.f90', + 'scm/src/gmtb_scm_type_defs.f90', ] # Add all physics scheme files relative to basedir @@ -229,6 +232,7 @@ # Auto-generated makefile/cmakefile snippets that contain all schemes SCHEMES_MAKEFILE = 'ccpp/physics/CCPP_SCHEMES.mk' SCHEMES_CMAKEFILE = 'ccpp/physics/CCPP_SCHEMES.cmake' +SCHEMES_SOURCEFILE = 'ccpp/physics/CCPP_SCHEMES.sh' # CCPP host cap in which to insert the ccpp_field_add statements; # determines the directory to place ccpp_{modules,fields}.inc @@ -239,6 +243,7 @@ # Auto-generated makefile/cmakefile snippets that contain all caps CAPS_MAKEFILE = 'ccpp/physics/CCPP_CAPS.mk' CAPS_CMAKEFILE = 'ccpp/physics/CCPP_CAPS.cmake' +CAPS_SOURCEFILE = 'ccpp/physics/CCPP_CAPS.sh' # Directory where to put all auto-generated physics caps CAPS_DIR = 'ccpp/physics/physics' @@ -318,6 +323,7 @@ # Directory where to write static API to STATIC_API_DIR = 'scm/src/' +STATIC_API_SRCFILE = 'scm/src/CCPP_STATIC_API.sh' # Directory for writing HTML pages generated from metadata files METADATA_HTML_OUTPUT_DIR = 'ccpp/physics/physics/docs' @@ -335,4 +341,4 @@ # Name of the CCPP data structure in the host model cap; # in the case of SCM, this is a vector with loop index i -CCPP_DATA_STRUCTURE = 'cdata(i)' +CCPP_DATA_STRUCTURE = 'cdata' diff --git a/ccpp/framework b/ccpp/framework index 5b472cd7c..f3cad9e2b 160000 --- a/ccpp/framework +++ b/ccpp/framework @@ -1 +1 @@ -Subproject commit 5b472cd7ce5db19e3c514d0c487429655124bb7c +Subproject commit f3cad9e2b6b69ab4c07826a1de50b7f6c6d08cd1 diff --git a/ccpp/physics b/ccpp/physics index d808b16ec..291153ca3 160000 --- a/ccpp/physics +++ b/ccpp/physics @@ -1 +1 @@ -Subproject commit d808b16ec1bda4cdc0c99e88877cd7a19f2b9329 +Subproject commit 291153ca39ec315c263390cbe7adf72eb686e4c5 diff --git a/scm/src/CMakeLists.txt b/scm/src/CMakeLists.txt index f234f2e47..042801a6d 100644 --- a/scm/src/CMakeLists.txt +++ b/scm/src/CMakeLists.txt @@ -25,7 +25,9 @@ set(BACIO_LIB4 ${NCEPLIBS_DIR}/lib/libbacio_4.a) set(SP_LIBd ${NCEPLIBS_DIR}/lib/libsp_v2.0.2_d.a) set(W3NCO_LIBd ${NCEPLIBS_DIR}/lib/libw3nco_d.a) -set(STATIC false) +if(STATIC) + ADD_DEFINITIONS(-DSTATIC) +endif(STATIC) SET(CCPP_SRC ${CMAKE_SOURCE_DIR}/../../ccpp/framework) SET(GFSPHYSICS_SRC ${CMAKE_SOURCE_DIR}/../../ccpp/physics) @@ -218,6 +220,8 @@ endif() # Configure sources ADD_SUBDIRECTORY(${CCPP_SRC} ${CMAKE_BINARY_DIR}/ccpp/framework) ADD_SUBDIRECTORY(${GFSPHYSICS_SRC} ${CMAKE_BINARY_DIR}/ccpp/physics) +ADD_DEPENDENCIES(ccppphys ccpp) + SET(scm_source_files gmtb_scm.F90 gmtb_scm_input.f90 gmtb_scm_utils.f90 @@ -231,8 +235,14 @@ SET(scm_source_files gmtb_scm.F90 gmtb_scm_type_defs.f90 ) -ADD_EXECUTABLE(gmtb_scm ${scm_source_files}) -TARGET_LINK_LIBRARIES(gmtb_scm ccppphys ccpp) +if(STATIC) + ADD_EXECUTABLE(gmtb_scm ${scm_source_files} ccpp_static_api.F90) + TARGET_LINK_LIBRARIES(gmtb_scm ccppphys ccpp ${BACIO_LIB4} ${SP_LIBd} ${W3NCO_LIBd}) +else(STATIC) + ADD_EXECUTABLE(gmtb_scm ${scm_source_files}) + TARGET_LINK_LIBRARIES(gmtb_scm ccppphys ccpp) +endif(STATIC) + set_target_properties(gmtb_scm PROPERTIES COMPILE_FLAGS "${CMAKE_Fortran_FLAGS}" LINK_FLAGS "${CMAKE_Fortran_FLAGS}") diff --git a/scm/src/gmtb_scm.F90 b/scm/src/gmtb_scm.F90 index e3bacae39..0b9ac864e 100644 --- a/scm/src/gmtb_scm.F90 +++ b/scm/src/gmtb_scm.F90 @@ -14,10 +14,19 @@ subroutine gmtb_scm_main_sub() use gmtb_scm_forcing use gmtb_scm_time_integration use gmtb_scm_output + use gmtb_scm_type_defs +#ifdef STATIC use :: ccpp_api, & - only: ccpp_t, & - ccpp_init, & + only: ccpp_init, & + ccpp_finalize + use :: ccpp_static_api, & + only: ccpp_physics_init, & + ccpp_physics_run, & + ccpp_physics_finalize +#else + use :: ccpp_api, & + only: ccpp_init, & ccpp_finalize, & ccpp_physics_init, & ccpp_physics_run, & @@ -25,23 +34,21 @@ subroutine gmtb_scm_main_sub() ccpp_field_add, & ccpp_initialized, & ccpp_error - use :: iso_c_binding, only: c_loc #include "ccpp_modules.inc" +#endif implicit none type(scm_state_type), target :: scm_state type(scm_input_type), target :: scm_input type(scm_reference_type), target :: scm_reference - type(physics_type), target :: physics integer :: i, j, grid_error real(kind=8) :: rinc(5) !(DAYS, HOURS, MINUTES, SECONDS, MILLISECONDS) integer :: jdat(1:8) - type(ccpp_t), allocatable, target :: cdata(:) integer :: cdata_time_index integer :: ierr character(len=16) :: logfile_name @@ -72,7 +79,7 @@ subroutine gmtb_scm_main_sub() stop end select - allocate(cdata(scm_state%n_cols)) + allocate(cdata_cols(scm_state%n_cols)) call set_state(scm_input, scm_reference, scm_state) @@ -105,7 +112,7 @@ subroutine gmtb_scm_main_sub() do i = 1, scm_state%n_cols !set up each column's physics suite (which may be different) - call ccpp_init(trim(adjustl(scm_state%physics_suite_name(i))), cdata(i), ierr) + call ccpp_init(trim(adjustl(scm_state%physics_suite_name(i))), cdata_cols(i), ierr) if (ierr/=0) then write(*,'(a,i0,a)') 'An error occurred in ccpp_init for column ', i, '. Exiting...' stop @@ -117,8 +124,8 @@ subroutine gmtb_scm_main_sub() open(unit=physics%Init_parm(i)%logunit, file=trim(scm_state%output_dir)//'/'//logfile_name, action='write', status='replace') end if - cdata(i)%blk_no = i - cdata(i)%thrd_no = 1 + cdata_cols(i)%blk_no = i + cdata_cols(i)%thrd_no = 1 physics%Init_parm(i)%levs = scm_state%n_levels physics%Init_parm(i)%bdat(1) = scm_state%init_year @@ -148,16 +155,26 @@ subroutine gmtb_scm_main_sub() physics%Init_parm(i)) call physics%associate(scm_state, i) - + +#ifndef STATIC ! use ccpp_fields.inc to call ccpp_field_add for all variables to add ! (this is auto-generated from ccpp/scripts/ccpp_prebuild.py, ! the script parses tables in gmtb_scm_type_defs.f90) + associate_column: associate (cdata => cdata_cols(i)) #include "ccpp_fields.inc" - + end associate associate_column +#endif + !initialize each column's physics - call ccpp_physics_init(cdata(i), ierr=ierr) +#ifdef STATIC + write(0,'(a,i0,a)') "Calling ccpp_physics_init for column ", i, " with suite '" // trim(trim(adjustl(scm_state%physics_suite_name(i)))) // "'" + call ccpp_physics_init(cdata_cols(i), suite_name=trim(trim(adjustl(scm_state%physics_suite_name(i)))), ierr=ierr) + write(0,'(a,i0,a,i0)') "Called ccpp_physics_init for column ", i, " with suite '" // trim(trim(adjustl(scm_state%physics_suite_name(i)))) // "', ierr=", ierr +#else + call ccpp_physics_init(cdata_cols(i), ierr=ierr) +#endif if (ierr/=0) then - write(*,'(a,i0,a)') 'An error occurred in ccpp_physics_init for column ', i, '. Exiting...' + write(*,'(a,i0,a)') 'An error occurred in ccpp_physics_init for column ', i, ': ' // trim(cdata_cols(i)%errmsg) // '. Exiting...' stop end if @@ -177,7 +194,7 @@ subroutine gmtb_scm_main_sub() if (.not. scm_state%model_ics) call calc_pres_exner_geopotential(1, scm_state) !pass in state variables to be modified by forcing and physics - call do_time_step(scm_state, cdata) + call do_time_step(scm_state, cdata_cols) else if (scm_state%time_scheme == 2) then ! !if using the leapfrog scheme, we initialize by taking one half forward time step and one half (unfiltered) leapfrog time step to get to the end of the first time step @@ -203,9 +220,13 @@ subroutine gmtb_scm_main_sub() scm_state%state_v(:,:,:,2) = scm_state%state_v(:,:,:,1) do i=1, scm_state%n_cols - call ccpp_physics_run(cdata(i), ierr=ierr) +#ifdef STATIC + call ccpp_physics_run(cdata_cols(i), suite_name=trim(trim(adjustl(scm_state%physics_suite_name(i)))), ierr=ierr) +#else + call ccpp_physics_run(cdata_cols(i), ierr=ierr) +#endif if (ierr/=0) then - write(*,'(a,i0,a)') 'An error occurred in ccpp_physics_run for column ', i, '. Exiting...' + write(*,'(a,i0,a)') 'An error occurred in ccpp_physics_run for column ', i, ': ' // trim(cdata_cols(i)%errmsg) // '. Exiting...' stop end if end do @@ -229,7 +250,7 @@ subroutine gmtb_scm_main_sub() scm_state%state_tracer(:,:,:,:,1) = scm_state%temp_tracer(:,:,:,:,1) !go forward one leapfrog time step - call do_time_step(scm_state, cdata) + call do_time_step(scm_state, cdata_cols) !for filtered-leapfrog scheme, call the filtering routine to calculate values of the state variables to save in slot 1 using slot 2 vars (updated, unfiltered) output from the physics call filter(scm_state) @@ -284,7 +305,7 @@ subroutine gmtb_scm_main_sub() end do !pass in state variables to be modified by forcing and physics - call do_time_step(scm_state, cdata) + call do_time_step(scm_state, cdata_cols) if (scm_state%time_scheme == 2) then !for filtered-leapfrog scheme, call the filtering routine to calculate values of the state variables to save in slot 1 using slot 2 vars (updated, unfiltered) output from the physics @@ -307,15 +328,19 @@ subroutine gmtb_scm_main_sub() end do do i=1, scm_state%n_cols - call ccpp_physics_finalize(cdata(i), ierr=ierr) +#ifdef STATIC + call ccpp_physics_finalize(cdata_cols(i), suite_name=trim(trim(adjustl(scm_state%physics_suite_name(i)))), ierr=ierr) +#else + call ccpp_physics_finalize(cdata_cols(i), ierr=ierr) +#endif if (ierr/=0) then - write(*,'(a,i0,a)') 'An error occurred in ccpp_physics_finalize for column ', i, '. Exiting...' + write(*,'(a,i0,a)') 'An error occurred in ccpp_physics_finalize for column ', i, ': ' // trim(cdata_cols(i)%errmsg) // '. Exiting...' stop end if end do do i=1, scm_state%n_cols - call ccpp_finalize(cdata(i), ierr) + call ccpp_finalize(cdata_cols(i), ierr) if (ierr/=0) then write(*,'(a,i0,a)') 'An error occurred in ccpp_finalize for column ', i, '. Exiting...' stop diff --git a/scm/src/gmtb_scm_time_integration.f90 b/scm/src/gmtb_scm_time_integration.f90 index fbb16391a..6aa224f69 100644 --- a/scm/src/gmtb_scm_time_integration.f90 +++ b/scm/src/gmtb_scm_time_integration.f90 @@ -6,7 +6,13 @@ module gmtb_scm_time_integration use gmtb_scm_kinds, only: sp, dp, qp use gmtb_scm_forcing -use ccpp_api, only: ccpp_t, ccpp_physics_run +#ifdef STATIC +use ccpp_api, only: ccpp_t +use ccpp_static_api, only: ccpp_physics_run +#else +use ccpp_api, only: ccpp_t, & + ccpp_physics_run +#endif implicit none @@ -48,11 +54,11 @@ subroutine filter(scm_state) !! The subroutine nuopc_rad_update calculates the time-dependent parameters required to run radiation, and nuopc_rad_run calculates the radiative heating rate (but does not apply it). The !! subroutine apply_forcing_leapfrog advances the state variables forward using the leapfrog method and nuopc_phys_run further changes the state variables using the forward method. By the end of !! this subroutine, the unfiltered state variables will have been stepped forward in time. -subroutine do_time_step(scm_state, cdata) +subroutine do_time_step(scm_state, cdata_cols) use gmtb_scm_type_defs, only: scm_state_type type(scm_state_type), intent(inout) :: scm_state - type(ccpp_t), intent(inout) :: cdata(:) + type(ccpp_t), intent(inout) :: cdata_cols(:) integer :: i, ierr @@ -78,9 +84,13 @@ subroutine do_time_step(scm_state, cdata) end if do i=1, scm_state%n_cols - call ccpp_physics_run(cdata(i), ierr=ierr) +#ifdef STATIC + call ccpp_physics_run(cdata_cols(i), suite_name=trim(adjustl(scm_state%physics_suite_name(i))), ierr=ierr) +#else + call ccpp_physics_run(cdata_cols(i), ierr=ierr) +#endif if (ierr/=0) then - write(*,'(a,i0,a)') 'An error occurred in ccpp_physics_run for column ', i, '. Exiting...' + write(*,'(a,i0,a)') 'An error occurred in ccpp_physics_run for column ', i, ': ' // trim(cdata_cols(i)%errmsg) // '. Exiting...' stop end if end do diff --git a/scm/src/gmtb_scm_type_defs.f90 b/scm/src/gmtb_scm_type_defs.f90 index 62a9fa40a..db8e7ef77 100644 --- a/scm/src/gmtb_scm_type_defs.f90 +++ b/scm/src/gmtb_scm_type_defs.f90 @@ -7,11 +7,21 @@ module gmtb_scm_type_defs !! \htmlinclude gmtb_scm_type_defs.html !! - use gmtb_scm_kinds, only : sp, dp, qp - use GFS_typedefs, only: GFS_control_type, GFS_statein_type, GFS_stateout_type, GFS_sfcprop_type, GFS_coupling_type, & - GFS_grid_type, GFS_tbd_type, GFS_cldprop_type, GFS_radtend_type, GFS_diag_type, GFS_interstitial_type, & - GFS_init_type - use machine, only: kind_phys + use gmtb_scm_kinds, only: sp, dp, qp + use GFS_typedefs, only: GFS_control_type, & + GFS_statein_type, & + GFS_stateout_type, & + GFS_sfcprop_type, & + GFS_coupling_type, & + GFS_grid_type, & + GFS_tbd_type, & + GFS_cldprop_type, & + GFS_radtend_type, & + GFS_diag_type, & + GFS_interstitial_type, & + GFS_init_type + use machine, only: kind_phys + use ccpp_api, only: ccpp_t implicit none @@ -335,6 +345,10 @@ module gmtb_scm_type_defs procedure :: associate => physics_associate end type physics_type + type(physics_type), target :: physics + + type(ccpp_t), allocatable, target :: cdata_cols(:) + contains subroutine scm_state_create(scm_state, n_columns, n_levels, n_soil, n_snow, n_time_levels) diff --git a/scm/src/gmtb_scm_type_defs.meta b/scm/src/gmtb_scm_type_defs.meta index 3acbcf783..7a620d23c 100644 --- a/scm/src/gmtb_scm_type_defs.meta +++ b/scm/src/gmtb_scm_type_defs.meta @@ -114,3 +114,15 @@ units = DDT dimensions = () type = physics_type +[physics] + standard_name = physics_type_instance + long_name = instance of derived data type physics_type + units = DDT + dimensions = () + type = physics_type +[cdata] + standard_name = ccpp_t_instance + long_name = instance of derived data type ccpp_t + units = DDT + dimensions = () + type = ccpp_t