@@ -41,6 +41,7 @@ module FV_StateMod
4141#ifdef RUN_GTFV3
4242 use ieee_exceptions, only: ieee_get_halting_mode, ieee_set_halting_mode, ieee_all
4343 use geos_gtfv3_interface_mod, only: geos_gtfv3_interface_f
44+ use geos_gtfv3_interface_mod, only: geos_gtfv3_interface_f_init, geos_gtfv3_interface_f_finalize
4445#endif
4546
4647implicit none
@@ -819,6 +820,11 @@ subroutine FV_InitState (STATE, CLOCK, INTERNAL, IMPORT, GC, RC)
819820 integer :: tile_in
820821 integer :: gid, masterproc
821822
823+ #ifdef RUN_GTFV3
824+ logical :: halting_mode(5 )
825+ integer :: comm
826+ #endif
827+
822828! BEGIN
823829
824830! Retrieve the pointer to the state
@@ -1143,6 +1149,22 @@ subroutine FV_InitState (STATE, CLOCK, INTERNAL, IMPORT, GC, RC)
11431149 call MAPL_MemUtilsWrite(VM, ' FV_StateMod: FV Initialize' , RC= STATUS )
11441150 VERIFY_(STATUS)
11451151
1152+ #ifdef RUN_GTFV3
1153+ if (run_gtfv3 /= 0 ) then
1154+ ! call ESMF_VMGetCurrent(VM, _RC)
1155+ call ESMF_VMGet(VM, mpiCommunicator= comm, _RC)
1156+ ! A workaround to the issue of SIGFPE abort during importing of numpy, is to
1157+ ! disable trapping of FPEs temporarily, call the Python interface and resume trapping
1158+ call ieee_get_halting_mode(ieee_all, halting_mode)
1159+ call ieee_set_halting_mode(ieee_all, .false. )
1160+ call geos_gtfv3_interface_f_init( &
1161+ comm, &
1162+ FV_Atm(1 )% npx, FV_Atm(1 )% npy, FV_Atm(1 )% npz, FV_Atm(1 )% flagstruct% ntiles, &
1163+ IS, IE, JS, JE, ISD, IED, JSD, JED, real (STATE% DT), 7 )
1164+ call ieee_set_halting_mode(ieee_all, halting_mode)
1165+ end if
1166+ #endif
1167+
11461168 RETURN_(ESMF_SUCCESS)
11471169
11481170end subroutine FV_InitState
@@ -1238,15 +1260,13 @@ subroutine FV_Run (STATE, EXPORT, CLOCK, GC, RC)
12381260#ifdef RUN_GTFV3
12391261 type (ESMF_VM) :: vm
12401262 integer :: comm, rank, mpierr
1241- logical :: halting_mode(5 )
12421263 real :: start, finish
12431264#endif
12441265
12451266! Begin
12461267
12471268#ifdef RUN_GTFV3
1248- ! MPI communicator
1249- call ESMF_VMGetCurrent(vm, rc= status)
1269+ call ESMF_VMGetCurrent(vm, rc= status) ! pchakrab: replace with ESMF_GridCompGet(gc, VM=VM, _RC)
12501270 call ESMF_VMGet(vm, mpiCommunicator= comm)
12511271 call MPI_Comm_rank(comm, rank, mpierr)
12521272#endif
@@ -1992,11 +2012,6 @@ subroutine FV_Run (STATE, EXPORT, CLOCK, GC, RC)
19922012 call cpu_time(finish)
19932013 if (rank == 0 ) print * , ' 0: fv_dynamics: time taken = ' , finish - start, ' s'
19942014 else
1995- ! A workaround to the issue of SIGFPE abort during importing of numpy, is to
1996- ! disable trapping of floating point exceptions temporarily, call the interface
1997- ! to the Python function and resume trapping
1998- call ieee_get_halting_mode(ieee_all, halting_mode)
1999- call ieee_set_halting_mode(ieee_all, .false. )
20002015 call cpu_time(start)
20012016 call geos_gtfv3_interface_f( &
20022017 comm, &
@@ -2016,7 +2031,6 @@ subroutine FV_Run (STATE, EXPORT, CLOCK, GC, RC)
20162031 ! input/output
20172032 FV_Atm(1 )% mfx, FV_Atm(1 )% mfy, FV_Atm(1 )% cx, FV_Atm(1 )% cy, FV_Atm(1 )% diss_est)
20182033 call cpu_time(finish)
2019- call ieee_set_halting_mode(ieee_all, halting_mode)
20202034 print * , rank, ' , geos_gtfv3_interface_f: time taken = ' , finish - start, ' s'
20212035 end if
20222036#endif
@@ -2402,32 +2416,21 @@ end subroutine FV_DA_Incs
24022416
24032417 subroutine FV_Finalize (STATE )
24042418
2405- use fv_control_mod, only : fv_end
2406-
2407- type (T_FVDYCORE_STATE),pointer :: STATE
2408-
2409- integer isc, iec, jsc, jec
2410- integer isd, ied, jsd, jed
2411- integer npz, ng
2419+ use fv_control_mod, only : fv_end
24122420
2413- isc = FV_Atm(1 )% bd% isc
2414- iec = FV_Atm(1 )% bd% iec
2415- jsc = FV_Atm(1 )% bd% jsc
2416- jec = FV_Atm(1 )% bd% jec
2417- isd = FV_Atm(1 )% bd% isd
2418- ied = FV_Atm(1 )% bd% ied
2419- jsd = FV_Atm(1 )% bd% jsd
2420- jed = FV_Atm(1 )% bd% jed
2421- npz = FV_Atm(1 )% npz
2422- ng = FV_Atm(1 )% ng
2421+ type (T_FVDYCORE_STATE),pointer :: STATE
24232422
2424- if (DEBUG) call debug_fv_state(' FV_Finalize' ,STATE)
2423+ if (DEBUG) call debug_fv_state(' FV_Finalize' ,STATE)
24252424
2426- call timing_off(' TOTAL' )
2427- call fv_end(FV_Atm, grids_on_this_pe ,.false. )
2425+ call timing_off(' TOTAL' )
2426+ call fv_end(FV_Atm, grids_on_this_pe ,.false. )
24282427
24292428#if defined( MAPL_MODE )
2430- ! call ESMF_GridDestroy (STATE%GRID%GRID)
2429+ ! call ESMF_GridDestroy (STATE%GRID%GRID)
2430+ #endif
2431+
2432+ #ifdef RUN_GTFV3
2433+ if (run_gtfv3 /= 0 ) call geos_gtfv3_interface_f_finalize()
24312434#endif
24322435
24332436 end subroutine FV_Finalize
0 commit comments