ROMS
Loading...
Searching...
No Matches
mct_driver.h
Go to the documentation of this file.
1 PROGRAM mct_driver
2!
3!git $Id$
4!=======================================================================
5! Copyright (c) 2002-2025 The ROMS Group !
6! Licensed under a MIT/X style license !
7! See License_ROMS.md Hernan G. Arango !
8!==================================================== John C. Warner ===
9! !
10! Master program to couple ROMS to other models using the Model !
11! Coupling Toolkit (MCT) library. !
12! !
13! The following models are coupled to ROMS: !
14! !
15#ifdef WRF_COUPLING
16! WRF, Weather Research and Forecasting model: !
17! http://www.wrf-model.org !
18! !
19#endif
20#ifdef SWAN_COUPLING
21! SWAN, Simulating WAves Nearshore model: !
22! http://vlm089.citg.tudelft.nl/swan/index.htm !
23! !
24#endif
25!=======================================================================
26!
27 USE mod_param
28 USE mod_parallel
29 USE mod_coupler
30 USE mod_iounits
31 USE mod_scalars
32!
33 USE m_mctworld, ONLY : mctworld_clean => clean
34
35#ifdef WRF_COUPLING
36 USE mct_coupler_mod, ONLY : finalize_ocn2atm_coupling
37#endif
38#if defined SWAN_COUPLING || defined REFDIF_COUPLING
39 USE mct_coupler_mod, ONLY : finalize_ocn2wav_coupling
40#endif
42 USE roms_kernel_mod, ONLY : roms_run
44#if defined PIO_LIB && defined DISTRIBUTE
45 USE set_pio_mod, ONLY : finalize_pio
46#endif
47!
48 implicit none
49!
50! Local variable declarations.
51!
52 logical, save :: first
53
54 integer :: mycolor, mycomm, myerror, mykey, nnodes
55 integer :: ng, provided, required
56
57 real(r4) :: couplingtime ! single precision
58!
59!-----------------------------------------------------------------------
60! Initialize distributed-memory (MPI) configuration
61!-----------------------------------------------------------------------
62!
63! Initialize MPI execution environment.
64!
65#ifdef MULTI_THREAD
66 required=mpi_thread_multiple
67 CALL mpi_init_thread (required, provided, myerror)
68 IF (myerror.ne.0) THEN
69 print '(/,a)',' ROMS: Unable to initialize multi-threaded MPI'
70 exit_flag=6
71 END IF
72#else
73 CALL mpi_init (myerror)
74 IF (myerror.ne.0) THEN
75 print '(/,a)',' ROMS: Unable to initialize MPI'
76 exit_flag=6
77 END IF
78#endif
79!
80! Get rank of the local process in the group associated with the
81! comminicator.
82!
83 CALL mpi_comm_size (mpi_comm_world, nnodes, myerror)
84 CALL mpi_comm_rank (mpi_comm_world, myrank, myerror)
85!
86! Set temporarily the ocean communicator to current handle before
87! splitting so the input coupling script name can be broadcasted to
88! all the nodes.
89!
90 ocn_comm_world=mpi_comm_world
91!
92! Read in coupled model parameters from standard input.
93!
94 CALL read_couplepar (inlm)
95!
96! Allocate several coupling variables.
97!
98 CALL allocate_coupler (nnodes)
99!
100! Split the communicator into coupled models sub-groups based
101! on color and key.
102!
103 mykey=0
104 IF ((pets(iocean)%val(1).le.myrank).and. &
105 & (myrank.le.pets(iocean)%val(nthreads(iocean)))) THEN
106 mycolor=ocnid
107 END IF
108#ifdef ATM_COUPLING
109 IF ((pets(iatmos)%val(1).le.myrank).and. &
110 & (myrank.le.pets(iatmos)%val(nthreads(iatmos)))) THEN
111 mycolor=atmid
112 END IF
113#endif
114#ifdef WAV_COUPLING
115 IF ((pets(iwaves)%val(1).le.myrank).and. &
116 & (myrank.le.pets(iwaves)%val(nthreads(iwaves)))) THEN
117 mycolor=wavid
118 END IF
119#endif
120 CALL mpi_comm_split (mpi_comm_world, mycolor, mykey, mycomm, &
121 & myerror)
122!
123!-----------------------------------------------------------------------
124! Run coupled models according to the processor rank.
125!-----------------------------------------------------------------------
126!
127#if defined SWAN_COUPLING
128 IF (mycolor.eq.wavid) THEN
129 couplingtime=real(timeinterval(iocean,iwaves))
130 CALL swan_initialize (mycomm, inpname(iwaves))
131 CALL swan_run (couplingtime)
132 CALL swan_finalize
133 END IF
134#elif defined REFDIF_COUPLING
135 IF (mycolor.eq.wavid) THEN
136 couplingtime=real(timeinterval(iocean,iwaves))
137 CALL refdif_initialize (mycomm)
138 CALL refdif_run (couplingtime, inpname(iwaves))
139 CALL refdif_finalize
140 END IF
141#endif
142#ifdef WRF_COUPLING
143 IF (mycolor.eq.atmid) THEN
144 couplingtime=real(timeinterval(iocean,iatmos))
145!! CALL module_wrf_top_mp_wrf_init (MyCOMM)
146!! CALL module_wrf_top_mp_wrf_run (TimeInterval(Iocean,Iwaves))
147!! CALL module_wrf_top_mp_wrf_finalize
148 CALL module_wrf_top_wrf_init (mycomm)
149 CALL module_wrf_top_wrf_run (couplingtime)
150 CALL module_wrf_top_wrf_finalize
151 END IF
152#endif
153 IF (mycolor.eq.ocnid) THEN
154 first=.true.
155 IF (exit_flag.eq.noerror) THEN
156 CALL roms_initialize (first, mpicomm=mycomm)
157 run_time=0.0_r8
158 DO ng=1,ngrids
159 run_time=max(run_time, dt(ng)*ntimes(ng))
160 END DO
161 END IF
162 IF (exit_flag.eq.noerror) THEN
163 CALL roms_run (run_time)
164 END IF
165 CALL roms_finalize
166#if defined PIO_LIB && defined DISTRIBUTE
167 CALL finalize_pio
168#endif
169#if defined SWAN_COUPLING || defined REFDIF_COUPLING
170 CALL finalize_ocn2wav_coupling
171#endif
172#ifdef WRF_COUPLING
173 CALL finalize_ocn2atm_coupling
174#endif
175 END IF
176!
177!-----------------------------------------------------------------------
178! Terminates all the mpi-processing and coupling.
179!-----------------------------------------------------------------------
180!
181 CALL mpi_barrier (mpi_comm_world, myerror)
182 CALL mctworld_clean ()
183 CALL mpi_finalize (myerror)
184
185 stop
186
187 END PROGRAM mct_driver
program mct_driver
Definition mct_driver.h:1
integer iocean
integer wavid
Definition mod_coupler.F:89
integer iatmos
integer atmid
Definition mod_coupler.F:88
type(t_integer), dimension(:), allocatable pets
integer, dimension(:), allocatable nthreads
integer ocnid
Definition mod_coupler.F:90
character(len=256), dimension(:), allocatable inpname
subroutine allocate_coupler(nnodes)
integer iwaves
real(r8), dimension(:,:), allocatable timeinterval
integer ocn_comm_world
integer, parameter inlm
Definition mod_param.F:662
integer ngrids
Definition mod_param.F:113
integer, dimension(:), allocatable ntimes
real(dp), dimension(:), allocatable dt
integer exit_flag
real(dp) run_time
integer noerror
subroutine, public roms_finalize
Definition ad_roms.h:283
subroutine, public roms_run(runinterval)
Definition ad_roms.h:239
subroutine, public roms_initialize(first, mpicomm)
Definition ad_roms.h:52
subroutine, public finalize_pio
Definition set_pio.F:323
subroutine read_couplepar(model)