YAC 3.14.0
Yet Another Coupler
Loading...
Searching...
No Matches
dummy_atmosphere.f90
Go to the documentation of this file.
1! Copyright (c) 2024 The YAC Authors
2!
3! SPDX-License-Identifier: BSD-3-Clause
4
7
9
10 USE mpi
11 USE yac
12
13 IMPLICIT NONE
14
15 INTEGER, PARAMETER :: pd = 12
16 INTEGER, PARAMETER :: rd = 307
17
18 INTEGER, PARAMETER :: dp = selected_real_kind(pd,rd)
19 INTEGER, PARAMETER :: wp = dp
20
21 INTEGER, PARAMETER :: no_of_fields = 14
22 INTEGER, PARAMETER :: max_char_length = 132
23
24 INTEGER, PARAMETER :: nbr_cells = 2
25 INTEGER, PARAMETER :: nbr_vertices = 4
26
27 REAL(wp), PARAMETER :: yac_rad = 0.017453292519943295769_wp ! M_PI / 180
28
29 CHARACTER(LEN=max_char_length) :: dummy_name
30 CHARACTER(LEN=max_char_length) :: field_name(no_of_fields)
31 INTEGER :: field_collection_size(no_of_fields)
32 CHARACTER(LEN=max_char_length) :: yaml_filename
33 CHARACTER(LEN=max_char_length) :: grid_name
34 CHARACTER(LEN=max_char_length) :: comp_name
35 CHARACTER(LEN=max_char_length) :: timestep_string
36
37 INTEGER :: role
38 INTEGER :: i, info, ierror
39 INTEGER :: comp_id
40 INTEGER :: cell_point_ids(1)
41 INTEGER :: grid_id
42
43 INTEGER :: glb_index(nbr_cells)
44 INTEGER :: cell_core_mask(nbr_cells)
45 INTEGER :: nbr_vertices_per_cell
46
47 REAL(wp), ALLOCATABLE :: buffer(:,:)
48 REAL(wp), ALLOCATABLE :: buffer_lon(:)
49 REAL(wp), ALLOCATABLE :: buffer_lat(:)
50 INTEGER, ALLOCATABLE :: cell_to_vertex(:,:)
51
52 INTEGER, ALLOCATABLE :: cell_mask(:)
53 INTEGER, ALLOCATABLE :: field_id(:)
54
55 INTEGER :: local_comm, npes, rank
56
57 CALL mpi_init (ierror)
58
59 ! Initialise the coupler
60 CALL yac_finit ( )
61 yaml_filename = "toy_dummy.yaml" ! default configuration file name
62 CALL parse_arguments(yaml_filename)
63 CALL yac_fread_config_yaml(yaml_filename)
64
65 ! Inform the coupler about what we are
66 comp_name = "dummy_atmosphere"
67 grid_name = "dummy_atmosphere_grid"
68 CALL yac_fdef_comp ( comp_name, comp_id )
69
70 print *, "YAC Version: ", trim(yac_fget_version())
71
72 CALL yac_fget_comp_comm ( comp_id, local_comm )
73 print *, 'Local Comm', local_comm
74
75 CALL mpi_comm_rank ( local_comm, rank, ierror )
76 CALL mpi_comm_size ( local_comm, npes, ierror )
77
78 WRITE ( 6 , * ) trim(comp_name), " rank ", rank, ": local size is ", npes
79
80 ALLOCATE(buffer_lon(nbr_vertices))
81 ALLOCATE(buffer_lat(nbr_vertices))
82 ALLOCATE(cell_to_vertex(3,nbr_cells))
83
84 nbr_vertices_per_cell = 3
85
86 ! Define vertices
87
88 ! 1
89 ! / \
90 ! / o \
91 ! / \
92 ! 2-------3 Eq.
93 ! \ /
94 ! \ o /
95 ! \ /
96 ! 4
97
98 buffer_lon(1) = 0.0 * yac_rad
99 buffer_lon(2) = -1.0 * yac_rad
100 buffer_lon(3) = 1.0 * yac_rad
101 buffer_lon(4) = 0.0 * yac_rad
102 buffer_lat(1) = 1.0 * yac_rad
103 buffer_lat(2) = 0.0 * yac_rad
104 buffer_lat(3) = 0.0 * yac_rad
105 buffer_lat(4) = -1.0 * yac_rad
106
107 ! Connectivity
108 cell_to_vertex(1,1) = 1
109 cell_to_vertex(2,1) = 2
110 cell_to_vertex(3,1) = 3 ! cell 1
111 cell_to_vertex(1,2) = 2
112 cell_to_vertex(2,2) = 4
113 cell_to_vertex(3,2) = 3 ! cell 2
114
115 ! Definition of an unstructured grid
116 CALL yac_fdef_grid ( &
117 & grid_name, &
118 & nbr_vertices, &
119 & nbr_cells, &
120 & nbr_vertices_per_cell, &
121 & buffer_lon, &
122 & buffer_lat, &
123 & cell_to_vertex, &
124 & grid_id )
125
126 ! Decomposition information
127
128 DO i = 1, nbr_cells
129 glb_index(i) = i
130 cell_core_mask(i) = 1
131 ENDDO
132
133 CALL yac_fset_global_index ( &
134 & glb_index, &
136 & grid_id )
137 CALL yac_fset_core_mask ( &
138 & cell_core_mask, &
140 & grid_id )
141
142 ! Center points in cells (needed e.g. for nearest neighbour)
143
144 buffer_lon(1) = 0.0 * yac_rad
145 buffer_lon(2) = 0.0 * yac_rad
146 buffer_lat(1) = 0.5 * yac_rad
147 buffer_lat(2) = -0.5 * yac_rad
148
149 CALL yac_fdef_points ( &
150 & grid_id, &
151 & nbr_cells, &
153 & buffer_lon, &
154 & buffer_lat, &
155 & cell_point_ids(1) )
156
157 DEALLOCATE (buffer_lon, buffer_lat, cell_to_vertex)
158
159 ! Mask generation
160 ALLOCATE(cell_mask(nbr_cells))
161 DO i = 1, nbr_cells
162 cell_mask(i) = 1
163 ENDDO
164
165 CALL yac_fset_mask ( &
166 & cell_mask, &
167 & cell_point_ids(1) )
168
169 DEALLOCATE (cell_mask)
170
171 field_name(1) = "surface_downward_eastward_stress" ! bundled field containing two components
172 field_name(2) = "surface_downward_northward_stress" ! bundled field containing two components
173 field_name(3) = "surface_fresh_water_flux" ! bundled field containing three components
174 field_name(4) = "surface_temperature"
175 field_name(5) = "total_heat_flux" ! bundled field containing four components
176 field_name(6) = "atmosphere_sea_ice_bundle" ! bundled field containing four components
177 field_name(7) = "sea_surface_temperature"
178 field_name(8) = "eastward_sea_water_velocity"
179 field_name(9) = "northward_sea_water_velocity"
180 field_name(10) = "ocean_sea_ice_bundle" ! bundled field containing four components
181 field_name(11) = "atmos_out1" ! output field
182 field_name(12) = "atmos_out2" ! output field
183 field_name(13) = "atmos_out3" ! output field
184 field_name(14) = "atmos_out4" ! output field
185
186 field_collection_size(1) = 2
187 field_collection_size(2) = 2
188 field_collection_size(3) = 3
189 field_collection_size(4) = 1
190 field_collection_size(5) = 4
191 field_collection_size(6) = 4
192 field_collection_size(7) = 1
193 field_collection_size(8) = 1
194 field_collection_size(9) = 1
195 field_collection_size(10) = 5
196 field_collection_size(11) = 1
197 field_collection_size(12) = 1
198 field_collection_size(13) = 1
199 field_collection_size(14) = 1
200
201 ALLOCATE(field_id(no_of_fields))
202
203 ! fields for coupling
204
205 DO i = 1, no_of_fields-4
206 CALL yac_fdef_field ( &
207 & field_name(i), &
208 & comp_id, &
209 & cell_point_ids, &
210 & 1, &
211 & field_collection_size(i), &
212 & "1", &
214 & field_id(i) )
215 ENDDO
216
217 ! fields for output server
218
219 DO i = no_of_fields-3, no_of_fields
220 CALL yac_fdef_field ( &
221 & field_name(i), &
222 & comp_id, &
223 & cell_point_ids, &
224 & 1, &
225 & field_collection_size(i), &
226 & "1", &
228 & field_id(i) )
229 ENDDO
230
231 CALL yac_fenddef ( )
232
233 ! Data exchange
234
235 ALLOCATE(buffer(nbr_cells,5))
236 buffer(:,:) = 0.0_wp
237
238 ! field_id(1) represents "TAUX" wind stress component
239 ! field_id(2) represents "TAUY" wind stress component
240 ! field_id(3) represents "SFWFLX" surface fresh water flux
241 ! field_id(4) represents "SFTEMP" surface temperature
242 ! field_id(5) represents "THFLX" total heat flux
243 ! field_id(6) represents "ICEATM" ice temperatures and melt potential
244 !
245 ! field_id(7) represents "SST" sea surface temperature
246 ! field_id(8) represents "OCEANU" u component of ocean surface current
247 ! field_id(9) represents "OCEANV" v component of ocean surface current
248 ! field_id(10)represents "ICEOCE" ice thickness, concentration and temperatures
249 !
250 ! field_id(11) - field_id(14) represent output fields
251 !
252 ! Get some info back from the coupling configuration
253 !
254
255 DO i = 1, no_of_fields
256 timestep_string = yac_fget_field_timestep( field_id(i) )
257 WRITE ( 6 , * ) "Field ID ", field_id(i), trim(timestep_string)
258 ENDDO
259
260 DO i = 1, no_of_fields
261 role = yac_fget_field_role( field_id(i) )
262 dummy_name = yac_fget_field_name( field_id(i) )
263 WRITE ( 6 , * ) "Requested role for ", trim(dummy_name) , " is ", role
264 ENDDO
265
266 !
267 ! Send fields from atmosphere to ocean
268 ! ------------------------------------
269
270 ! meridional wind stress
271 buffer(:,1) = 10.1_wp
272 buffer(:,2) = 10.2_wp
273
274 CALL yac_fput ( field_id(1), nbr_cells, 2, buffer(1:nbr_cells,1:2), info, ierror )
275 IF ( info > 0 ) &
276 WRITE ( 6 , * ) "atmosphere CPL TAUX 1", minval(buffer(1:nbr_cells,1:1)), maxval(buffer(1:nbr_cells,1:1))
277 IF ( info > 0 ) WRITE ( 6 , * ) "atmosphere CPL TAUX 2", minval(buffer(1:nbr_cells,2:2)), maxval(buffer(1:nbr_cells,2:2))
278
279 ! zonal wind stress
280 buffer(:,1) = 20.1_wp
281 buffer(:,2) = 20.2_wp
282
283 CALL yac_fput ( field_id(2), nbr_cells, 2, buffer(1:nbr_cells,1:2), info, ierror )
284 IF ( info > 0 ) &
285 WRITE ( 6 , * ) "atmosphere CPL TAUY 1", minval(buffer(1:nbr_cells,1:1)), maxval(buffer(1:nbr_cells,1:1))
286 IF ( info > 0 ) &
287 WRITE ( 6 , * ) "atmosphere CPL TAUY 2", minval(buffer(1:nbr_cells,2:2)), maxval(buffer(1:nbr_cells,2:2))
288
289 ! surface fresh water flux
290 buffer(:,1) = 30.1_wp
291 buffer(:,2) = 30.2_wp
292 buffer(:,3) = 30.3_wp
293
294 CALL yac_fput ( field_id(3), nbr_cells, 3, buffer(1:nbr_cells,1:3), info, ierror )
295
296 ! surface temperature
297 buffer(:,1) = 40.1_wp
298 CALL yac_fput ( field_id(4), nbr_cells, 1, buffer(1:nbr_cells,1:1), info, ierror )
299
300 ! total heat flux
301 buffer(:,1) = 50.1_wp
302 buffer(:,2) = 50.2_wp
303 buffer(:,3) = 50.3_wp
304 buffer(:,4) = 50.4_wp
305
306 CALL yac_fput ( field_id(5), nbr_cells, 4, buffer(1:nbr_cells,1:4), info, ierror )
307
308 ! ice temperatures and melt potential
309 buffer(:,1) = 60.1_wp
310 buffer(:,2) = 60.2_wp
311 buffer(:,3) = 60.3_wp
312 buffer(:,4) = 60.4_wp
313
314 CALL yac_fput ( field_id(6), nbr_cells, 4, buffer(1:nbr_cells,1:4), info, ierror )
315
316 !
317 ! Receive fields from ocean
318 ! -------------------------
319
320 ! SST
321 CALL yac_fget ( field_id(7), nbr_cells, 1, buffer(1:nbr_cells,1:1), info, ierror )
322 IF ( info > 0 ) &
323 WRITE ( 6 , * ) "atmosphere CPL SST", minval(buffer(1:nbr_cells,1:1)), maxval(buffer(1:nbr_cells,1:1))
324
325 ! zonal velocity
326 CALL yac_fget ( field_id(8), nbr_cells, 1, buffer(1:nbr_cells,1:1), info, ierror )
327 IF ( info > 0 ) &
328 WRITE ( 6 , * ) "atmosphere CPL OCEANU", minval(buffer(1:nbr_cells,1:1)), maxval(buffer(1:nbr_cells,1:1))
329
330 ! meridional velocity
331 CALL yac_fget ( field_id(9), nbr_cells, 1, buffer(1:nbr_cells,1:1), info, ierror )
332 IF ( info > 0 ) &
333 WRITE ( 6 , * ) "atmosphere CPL OCEANV", minval(buffer(1:nbr_cells,1:1)), maxval(buffer(1:nbr_cells,1:1))
334
335 ! Ice thickness, concentration, T1 and T2
336
337 CALL yac_fget ( field_id(10), nbr_cells, 5, buffer(1:nbr_cells,1:5), info, ierror )
338 IF ( info > 0 ) THEN
339 WRITE ( 6 , * ) "atmosphere CPL ice 1", minval(buffer(1:nbr_cells,1:1)), maxval(buffer(1:nbr_cells,1:1))
340 WRITE ( 6 , * ) "atmosphere CPL ice 2", minval(buffer(1:nbr_cells,2:2)), maxval(buffer(1:nbr_cells,2:2))
341 WRITE ( 6 , * ) "atmosphere CPL ice 3", minval(buffer(1:nbr_cells,3:3)), maxval(buffer(1:nbr_cells,3:3))
342 WRITE ( 6 , * ) "atmosphere CPL ice 4", minval(buffer(1:nbr_cells,4:4)), maxval(buffer(1:nbr_cells,4:4))
343 WRITE ( 6 , * ) "atmosphere CPL ice 5", minval(buffer(1:nbr_cells,5:5)), maxval(buffer(1:nbr_cells,5:5))
344 ENDIF
345
346 DEALLOCATE(buffer)
347 DEALLOCATE(field_id)
348
349 CALL yac_ffinalize
350
351 CALL mpi_finalize (ierror)
352
353CONTAINS
354
355 SUBROUTINE parse_arguments(configFilename)
356
357 CHARACTER(LEN=max_char_length) :: configFilename
358
359 CHARACTER(LEN=max_char_length) :: arg
360 INTEGER :: i
361 LOGICAL :: skip_arg = .false.
362
363 DO i = 1, command_argument_count()
364
365 IF (.NOT. skip_arg) THEN
366
367 CALL get_command_argument(i, arg)
368
369 SELECT CASE (arg)
370
371 CASE ('-c')
372 IF (i == command_argument_count()) THEN
373 print '(2a, /)', 'missing parameter for command-line option: ', arg
374 print '(a, /)', 'command-line options:'
375 print '(a)', ' -c configFilename'
376 stop
377 ELSE
378 CALL get_command_argument(i+1, configfilename)
379 skip_arg = .true.
380 END IF
381
382 CASE default
383 print '(2a, /)', 'unrecognised command-line option: ', arg
384 print '(a, /)', 'command-line options:'
385 print '(a)', ' -c configFilename'
386 stop
387 END SELECT
388 ELSE
389 skip_arg = .false.
390 END IF
391 END DO
392
393 END SUBROUTINE parse_arguments
394
395END PROGRAM dummy_atmosphere
program dummy_atmosphere
Fortran interface for the definition of coupling fields using default masks.
Fortran interface for the definition of grids.
Fortran interface for the definition of points.
Fortran interface for invoking the end of the definition phase.
Fortran interface for the coupler termination.
Fortran interface for getting back a local MPI communicator.
Fortran interface for getting the YAC version.
Fortran interface for receiving coupling fields.
Fortran interface for sending coupling fields.
Fortran interface for the reading of configuration files.
Fortran interface for the setting of a grid core masks.
Fortran interface for the setting of grid global ids.
Fortran interface for the setting of default pointset masks.
@ yac_location_cell
@ yac_time_unit_second
static void parse_arguments(int argc, char **argv, enum experiment_type *experiment)
Definition toy_scrip.c:490