YAC 3.14.0
Yet Another Coupler
Loading...
Searching...
No Matches
dummy_io.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
8PROGRAM dummy_io
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 = 8
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) :: field_name(no_of_fields)
30 CHARACTER(LEN=max_char_length) :: yaml_filename
31 CHARACTER(LEN=max_char_length) :: grid_name
32 CHARACTER(LEN=max_char_length) :: comp_name
33
34 INTEGER :: i, igrid, ierror
35
36 INTEGER :: comp_id
37 INTEGER :: cell_point_ids(2)
38 INTEGER :: grid_ids(2)
39
40 INTEGER :: glb_index(nbr_cells)
41 INTEGER :: cell_core_mask(nbr_cells)
42 INTEGER :: nbr_vertices_per_cell
43
44 REAL(wp), ALLOCATABLE :: buffer_lon(:)
45 REAL(wp), ALLOCATABLE :: buffer_lat(:)
46 INTEGER, ALLOCATABLE :: cell_to_vertex(:,:)
47
48 INTEGER, ALLOCATABLE :: cell_mask(:)
49 INTEGER, ALLOCATABLE :: field_id(:)
50
51 INTEGER :: local_comm, npes, rank
52
53 CALL mpi_init (ierror)
54
55 ! Initialise the coupler
56 CALL yac_finit ( )
57 yaml_filename = "toy_dummy.yaml" ! default configuration file name
58 CALL parse_arguments(yaml_filename)
59 CALL yac_fread_config_yaml(yaml_filename)
60
61 ! Inform the coupler about what we are
62 comp_name = "dummy_io"
63 CALL yac_fdef_comp ( comp_name, comp_id )
64
65 CALL yac_fget_comp_comm ( comp_id, local_comm )
66
67 CALL mpi_comm_rank ( local_comm, rank, ierror )
68 CALL mpi_comm_size ( local_comm, npes, ierror )
69
70 WRITE ( 6 , * ) trim(comp_name), " rank ", rank, ": local size is ", npes
71
72 ! Here we define two grids (although numerically identical) to mimick
73 ! two different Output server groups
74
75 DO igrid = 1, 2
76
77 IF ( igrid == 1 ) THEN
78 grid_name = "ocean_grid"
79 ELSE
80 grid_name = "atmos_grid"
81 ENDIF
82
83 ALLOCATE(buffer_lon(nbr_vertices))
84 ALLOCATE(buffer_lat(nbr_vertices))
85 ALLOCATE(cell_to_vertex(3,nbr_cells))
86
87 nbr_vertices_per_cell = 3
88
89 ! Define vertices
90
91 ! 1
92 ! / \
93 ! / o \
94 ! / \
95 ! 2-------3 Eq.
96 ! \ /
97 ! \ o /
98 ! \ /
99 ! 4
100
101 buffer_lon(1) = 0.0 * yac_rad
102 buffer_lon(2) = -1.0 * yac_rad
103 buffer_lon(3) = 1.0 * yac_rad
104 buffer_lon(4) = 0.0 * yac_rad
105 buffer_lat(1) = 1.0 * yac_rad
106 buffer_lat(2) = 0.0 * yac_rad
107 buffer_lat(3) = 0.0 * yac_rad
108 buffer_lat(4) = -1.0 * yac_rad
109
110 ! Connectivity
111 cell_to_vertex(1,1) = 1
112 cell_to_vertex(2,1) = 2
113 cell_to_vertex(3,1) = 3 ! cell 1
114 cell_to_vertex(1,2) = 2
115 cell_to_vertex(2,2) = 4
116 cell_to_vertex(3,2) = 3 ! cell 2
117
118 ! Definition of an unstructured grid
119 CALL yac_fdef_grid ( &
120 & grid_name, &
121 & nbr_vertices, &
122 & nbr_cells, &
123 & nbr_vertices_per_cell, &
124 & buffer_lon, &
125 & buffer_lat, &
126 & cell_to_vertex, &
127 & grid_ids(igrid) )
128
129 ! Decomposition information
130
131 DO i = 1, nbr_cells
132 glb_index(i) = i
133 cell_core_mask(i) = 1
134 ENDDO
135
136 CALL yac_fset_global_index ( &
137 & glb_index, &
139 & grid_ids(igrid) )
140 CALL yac_fset_core_mask ( &
141 & cell_core_mask, &
143 & grid_ids(igrid) )
144
145 ! Center points in cells (needed e.g. for nearest neighbour)
146
147 buffer_lon(1) = 0.0 * yac_rad
148 buffer_lon(2) = 0.0 * yac_rad
149 buffer_lat(1) = 0.5 * yac_rad
150 buffer_lat(2) = -0.5 * yac_rad
151
152 CALL yac_fdef_points ( &
153 & grid_ids(igrid), &
154 & nbr_cells, &
156 & buffer_lon, &
157 & buffer_lat, &
158 & cell_point_ids(igrid) )
159
160 DEALLOCATE (buffer_lon, buffer_lat, cell_to_vertex)
161
162 ! Mask generation
163 ALLOCATE(cell_mask(nbr_cells))
164 DO i = 1, nbr_cells
165 cell_mask(i) = 1
166 ENDDO
167
168 CALL yac_fset_mask ( &
169 & cell_mask, &
170 & cell_point_ids(igrid) )
171
172 DEALLOCATE (cell_mask)
173
174 ENDDO
175
176 field_name(1) = "atmos_out1" ! output field
177 field_name(2) = "atmos_out2" ! output field
178 field_name(3) = "atmos_out3" ! output field
179 field_name(4) = "atmos_out4" ! output field
180
181 field_name(5) = "ocean_out1" ! output field
182 field_name(6) = "ocean_out2" ! output field
183 field_name(7) = "ocean_out3" ! output field
184 field_name(8) = "ocean_out4" ! output field
185
186 ALLOCATE(field_id(no_of_fields))
187
188 ! atmosphere output
189
190 DO i = 1, no_of_fields-4
191 CALL yac_fdef_field ( &
192 & field_name(i), &
193 & comp_id, &
194 & cell_point_ids(2), &
195 & 1, &
196 & 1, &
197 & "1", &
199 & field_id(i) )
200 ENDDO
201
202 ! ocean output
203
204 DO i = no_of_fields-3, no_of_fields
205 CALL yac_fdef_field ( &
206 & field_name(i), &
207 & comp_id, &
208 & cell_point_ids(1), &
209 & 1, &
210 & 1, &
211 & "1", &
213 & field_id(i) )
214 ENDDO
215
216 CALL yac_fenddef ( )
217
218 CALL yac_ffinalize
219
220 CALL mpi_finalize (ierror)
221
222CONTAINS
223
224 SUBROUTINE parse_arguments(configFilename)
225
226 CHARACTER(LEN=max_char_length) :: configFilename
227
228 CHARACTER(LEN=max_char_length) :: arg
229 INTEGER :: i
230 LOGICAL :: skip_arg = .false.
231
232 DO i = 1, command_argument_count()
233
234 IF (.NOT. skip_arg) THEN
235
236 CALL get_command_argument(i, arg)
237
238 SELECT CASE (arg)
239
240 CASE ('-c')
241 IF (i == command_argument_count()) THEN
242 print '(2a, /)', 'missing parameter for command-line option: ', arg
243 print '(a, /)', 'command-line options:'
244 print '(a)', ' -c configFilename'
245 stop
246 ELSE
247 CALL get_command_argument(i+1, configfilename)
248 skip_arg = .true.
249 END IF
250
251 CASE default
252 print '(2a, /)', 'unrecognised command-line option: ', arg
253 print '(a, /)', 'command-line options:'
254 print '(a)', ' -c configFilename'
255 stop
256 END SELECT
257 ELSE
258 skip_arg = .false.
259 END IF
260 END DO
261
262 END SUBROUTINE parse_arguments
263
264END PROGRAM dummy_io
program dummy_io
Definition dummy_io.f90:8
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 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