ICON Community Interface 0.4.0
Loading...
Searching...
No Matches
comin_descrdata.F90
Go to the documentation of this file.
1
3!
4! @authors 10/2021 :: ICON Community Interface <comin@icon-model.org>
5!
6! SPDX-License-Identifier: BSD-3-Clause
7!
8! See LICENSES for license information.
9! Where software is supplied by third parties, it is indicated in the
10! headers of the routines.
11!
13
14 use, INTRINSIC :: iso_c_binding, only: c_int, c_ptr, c_loc, c_bool
15 USE comin_setup_constants, ONLY: wp
16 USE comin_state, ONLY: state
24
25 IMPLICIT NONE
26
27 PRIVATE
28
40
41#include "comin_global.inc"
42
43CONTAINS
44
47 SUBROUTINE comin_descrdata_set_global(comin_global_info)
48 TYPE(t_comin_descrdata_global), INTENT(IN) :: comin_global_info
49 state%comin_descrdata_global = comin_global_info
50 END SUBROUTINE comin_descrdata_set_global
51
54 SUBROUTINE comin_descrdata_set_domain(comin_domain_info)
55 TYPE(t_comin_descrdata_domain), INTENT(IN) :: comin_domain_info(:)
56 ALLOCATE(state%comin_descrdata_domain, source=comin_domain_info)
57 END SUBROUTINE comin_descrdata_set_domain
58
61 SUBROUTINE comin_descrdata_set_simulation_interval(comin_time_info)
62 TYPE(t_comin_descrdata_simulation_interval), INTENT(IN) :: comin_time_info
63 state%comin_descrdata_simulation_interval = comin_time_info
65
68 SUBROUTINE comin_current_get_datetime(sim_time_current)
69 CHARACTER(LEN=:), ALLOCATABLE, INTENT(OUT) :: sim_time_current
70 sim_time_current = state%current_datetime
71 END SUBROUTINE comin_current_get_datetime
72
74 SUBROUTINE comin_current_get_datetime_c(val, len) &
75 & BIND(C, NAME="comin_current_get_datetime")
76 TYPE(c_ptr), INTENT(OUT) :: val
77 INTEGER(kind=c_int), INTENT(OUT) :: len
78
79 val = c_loc(state%current_datetime)
80 len = len_trim(state%current_datetime)
81 END SUBROUTINE comin_current_get_datetime_c
82
85 SUBROUTINE comin_current_set_datetime(sim_time_current)
86 CHARACTER(LEN=*), INTENT(IN) :: sim_time_current
87 state%current_datetime = sim_time_current
88 END SUBROUTINE comin_current_set_datetime
89
94 ! local
95
97 comin_descrdata_get_global => state%comin_descrdata_global
98 IF(.NOT. ASSOCIATED(comin_descrdata_get_global)) THEN
99 CALL comin_plugin_finish("comin_descrdata_get_global", " ERROR: Pointer not associated.")
100 END IF
101 END FUNCTION comin_descrdata_get_global
102
106 INTEGER, INTENT(IN) :: jg
107 ! local
109
111 comin_descrdata_get_domain => state%comin_descrdata_domain(jg)
112 IF(.NOT. ASSOCIATED(comin_descrdata_get_domain)) THEN
113 CALL comin_plugin_finish("comin_descrdata_get_domain", " ERROR: Pointer not associated.")
114 END IF
115
116 END FUNCTION comin_descrdata_get_domain
117
122
123 comin_descrdata_get_simulation_interval => state%comin_descrdata_simulation_interval
124 IF(.NOT. ASSOCIATED(comin_descrdata_get_simulation_interval)) THEN
125 CALL comin_plugin_finish("comin_descrdata_get_simulation_interval", " ERROR: Pointer not associated.")
126 END IF
128
130 SUBROUTINE comin_descrdata_get_simulation_interval_exp_start(val, len) &
131 & BIND(C, NAME="comin_descrdata_get_simulation_interval_exp_start")
132 TYPE(c_ptr), INTENT(OUT) :: val
133 INTEGER(kind=c_int), INTENT(OUT) :: len
134
135 val = c_loc(state%comin_descrdata_simulation_interval%exp_start)
136 len = len_trim(state%comin_descrdata_simulation_interval%exp_start)
137 END SUBROUTINE comin_descrdata_get_simulation_interval_exp_start
138
140 SUBROUTINE comin_descrdata_get_simulation_interval_exp_stop(val, len) &
141 & BIND(C, NAME="comin_descrdata_get_simulation_interval_exp_stop")
142 TYPE(c_ptr), INTENT(OUT) :: val
143 INTEGER(kind=c_int), INTENT(OUT) :: len
144
145 val = c_loc(state%comin_descrdata_simulation_interval%exp_stop)
146 len = len_trim(state%comin_descrdata_simulation_interval%exp_stop)
147 END SUBROUTINE comin_descrdata_get_simulation_interval_exp_stop
148
150 SUBROUTINE comin_descrdata_get_simulation_interval_run_start(val, len) &
151 & BIND(C, NAME="comin_descrdata_get_simulation_interval_run_start")
152 TYPE(c_ptr), INTENT(OUT) :: val
153 INTEGER(kind=c_int), INTENT(OUT) :: len
154
155 val = c_loc(state%comin_descrdata_simulation_interval%run_start)
156 len = len_trim(state%comin_descrdata_simulation_interval%run_start)
157 END SUBROUTINE comin_descrdata_get_simulation_interval_run_start
158
160 SUBROUTINE comin_descrdata_get_simulation_interval_run_stop(val, len) &
161 & BIND(C, NAME="comin_descrdata_get_simulation_interval_run_stop")
162 TYPE(c_ptr), INTENT(OUT) :: val
163 INTEGER(kind=c_int), INTENT(OUT) :: len
164
165 val = c_loc(state%comin_descrdata_simulation_interval%run_stop)
166 len = len_trim(state%comin_descrdata_simulation_interval%run_stop)
167 END SUBROUTINE comin_descrdata_get_simulation_interval_run_stop
168
173 INTEGER(c_int), INTENT(IN), VALUE :: jg
174
175 comin_descrdata_get_timesteplength = state%comin_descrdata_timesteplength(jg)
177
180 SUBROUTINE comin_descrdata_set_timesteplength(jg, dt_current)
181 INTEGER, INTENT(IN) :: jg
182 REAL(wp), INTENT(IN) :: dt_current
183
184 IF (.NOT. ALLOCATED(state%comin_descrdata_timesteplength)) THEN
185 ALLOCATE(state%comin_descrdata_timesteplength(state%comin_descrdata_global%n_dom+4))
186 END IF
187 state%comin_descrdata_timesteplength(jg) = dt_current
189
194
195 END SUBROUTINE comin_descrdata_finalize
196
197 !!
200
203 !-------------------------------------------------------------------------
204 ! The following two functions are for conversion of 1D to 2D indices and vice versa
205 !
206 ! Treatment of 0 (important for empty domains) and negative numbers:
207 !
208 ! Converting 1D => 2D:
209 !
210 ! 0 always is mapped to blk_no = 1, idx_no = 0
211 ! negative numbers: Convert usings ABS(j) and negate idx_no
212 !
213 ! Thus: blk_no >= 1 always!
214 ! idx_no > 0 for j > 0
215 ! idx_no = 0 for j = 0
216 ! idx_no < 0 for j < 0
217 !
218 ! This mimics mostly the behaviour of reshape_idx in mo_model_domimp_patches
219 ! with a difference for nproma=1 and j=0 (where reshape_idx returns blk_no=0, idx_no=1)
220 !
221 ! The consistent treatment of 0 in the above way is very important for empty domains
222 ! where start_index=1, end_index=0
223 !
224 ! Converting 2D => 1D:
225 ! Trying to invert the above and catching cases with blk_no < 1
226 !-------------------------------------------------------------------------
227
230 INTEGER(c_int) FUNCTION comin_descrdata_get_block(idx1D) BIND(C, name="comin_descrdata_get_block")
231 INTEGER(c_int), INTENT(IN), VALUE :: idx1d
232 comin_descrdata_get_block = max((abs(idx1d)-1)/state%comin_descrdata_global%nproma + 1, 1) ! i.e. also 1 for idx1D=0, nproma=1
233 END FUNCTION comin_descrdata_get_block
234
237 INTEGER(c_int) FUNCTION comin_descrdata_get_index(idx1D) BIND(C, name="comin_descrdata_get_index")
238 INTEGER(c_int), INTENT(IN), VALUE :: idx1d
239 IF(idx1d==0) THEN
241 ELSE
242 comin_descrdata_get_index = sign(mod(abs(idx1d)-1,state%comin_descrdata_global%nproma)+1, idx1d)
243 ENDIF
244 END FUNCTION comin_descrdata_get_index
245
251 SUBROUTINE comin_descrdata_get_cell_indices(jg, i_blk, i_startblk, i_endblk, i_startidx, &
252 i_endidx, irl_start, irl_end) &
253 & BIND(C, NAME="comin_descrdata_get_cell_indices")
254
255 INTEGER(c_int), INTENT(IN), VALUE :: jg ! Patch index for comin_domain
256 INTEGER(c_int), INTENT(IN), VALUE :: i_blk ! Current block (variable jb in do loops)
257 INTEGER(c_int), INTENT(IN), VALUE :: i_startblk ! Start block of do loop
258 INTEGER(c_int), INTENT(IN), VALUE :: i_endblk ! End block of do loop
259 INTEGER(c_int), INTENT(IN), VALUE :: irl_start ! refin_ctrl level where do loop starts
260 INTEGER(c_int), INTENT(IN), VALUE :: irl_end ! refin_ctrl level where do loop ends
261
262 INTEGER(c_int), INTENT(OUT) :: i_startidx, i_endidx ! Start and end indices (jc loop)
263
264 IF (i_blk == i_startblk) THEN
265 i_startidx = max(1,state%comin_descrdata_domain(jg)%cells%start_index(irl_start))
266 i_endidx = state%comin_descrdata_global%nproma
267 IF (i_blk == i_endblk) i_endidx = state%comin_descrdata_domain(jg)%cells%end_index(irl_end)
268 ELSE IF (i_blk == i_endblk) THEN
269 i_startidx = 1
270 i_endidx = state%comin_descrdata_domain(jg)%cells%end_index(irl_end)
271 ELSE
272 i_startidx = 1
273 i_endidx = state%comin_descrdata_global%nproma
274 ENDIF
275
277
283 SUBROUTINE comin_descrdata_get_edge_indices(jg, i_blk, i_startblk, i_endblk, i_startidx, &
284 i_endidx, irl_start, irl_end) &
285 & BIND(C, NAME="comin_descrdata_get_edge_indices")
286
287 INTEGER(c_int), INTENT(IN), VALUE :: jg ! Patch index for comin_domain
288 INTEGER(c_int), INTENT(IN), VALUE :: i_blk ! Current block (variable jb in do loops)
289 INTEGER(c_int), INTENT(IN), VALUE :: i_startblk ! Start block of do loop
290 INTEGER(c_int), INTENT(IN), VALUE :: i_endblk ! End block of do loop
291 INTEGER(c_int), INTENT(IN), VALUE :: irl_start ! refin_ctrl level where do loop starts
292 INTEGER(c_int), INTENT(IN), VALUE :: irl_end ! refin_ctrl level where do loop ends
293
294 INTEGER(c_int), INTENT(OUT) :: i_startidx, i_endidx ! Start and end indices (jc loop)
295
296 i_startidx = merge(1, &
297 max(1, state%comin_descrdata_domain(jg)%edges%start_index(irl_start)), &
298 i_blk /= i_startblk)
299 i_endidx = merge(state%comin_descrdata_global%nproma, &
300 state%comin_descrdata_domain(jg)%edges%end_index(irl_end), &
301 i_blk /= i_endblk)
302
304
310 SUBROUTINE comin_descrdata_get_vert_indices(jg, i_blk, i_startblk, i_endblk, i_startidx, &
311 i_endidx, irl_start, irl_end) &
312 & BIND(C, NAME="comin_descrdata_get_vert_indices")
313
314 INTEGER(c_int), INTENT(IN), VALUE :: jg ! Patch index for comin_domain
315 INTEGER(c_int), INTENT(IN), VALUE :: i_blk ! Current block (variable jb in do loops)
316 INTEGER(c_int), INTENT(IN), VALUE :: i_startblk ! Start block of do loop
317 INTEGER(c_int), INTENT(IN), VALUE :: i_endblk ! End block of do loop
318 INTEGER(c_int), INTENT(IN), VALUE :: irl_start ! refin_ctrl level where do loop starts
319 INTEGER(c_int), INTENT(IN), VALUE :: irl_end ! refin_ctrl level where do loop ends
320
321 INTEGER(c_int), INTENT(OUT) :: i_startidx, i_endidx ! Start and end indices (jc loop)
322
323 IF (i_blk == i_startblk) THEN
324 i_startidx = state%comin_descrdata_domain(jg)%verts%start_index(irl_start)
325 i_endidx = state%comin_descrdata_global%nproma
326 IF (i_blk == i_endblk) i_endidx = state%comin_descrdata_domain(jg)%verts%end_index(irl_end)
327 ELSE IF (i_blk == i_endblk) THEN
328 i_startidx = 1
329 i_endidx = state%comin_descrdata_domain(jg)%verts%end_index(irl_end)
330 ELSE
331 i_startidx = 1
332 i_endidx = state%comin_descrdata_global%nproma
333 ENDIF
334
336
345 INTEGER(c_int) FUNCTION comin_descrdata_get_cell_npromz(jg) BIND(C)
346 INTEGER(c_int), INTENT(IN), VALUE :: jg ! domain index for comin_domain
347
348 comin_descrdata_get_cell_npromz = state%comin_descrdata_domain(jg)%cells%ncells - &
349 & (state%comin_descrdata_domain(jg)%cells%nblks-1)*state%comin_descrdata_global%nproma
351
360 INTEGER(c_int) FUNCTION comin_descrdata_get_edge_npromz(jg) BIND(C)
361 INTEGER(c_int), INTENT(IN), VALUE :: jg ! domain index for comin_domain
362
363 comin_descrdata_get_edge_npromz = state%comin_descrdata_domain(jg)%edges%nedges - &
364 & (state%comin_descrdata_domain(jg)%edges%nblks-1)*state%comin_descrdata_global%nproma
366
375 INTEGER(c_int) FUNCTION comin_descrdata_get_vert_npromz(jg) BIND(C)
376 INTEGER(c_int), INTENT(IN), VALUE :: jg ! domain index for comin_domain
377
378 comin_descrdata_get_vert_npromz = state%comin_descrdata_domain(jg)%verts%nverts - &
379 & (state%comin_descrdata_domain(jg)%verts%nblks-1)*state%comin_descrdata_global%nproma
381
384 INTEGER(C_INT) FUNCTION comin_descrdata_index_lookup_glb2loc_cell(jg, global_idx) &
385 & result(loc) BIND(C)
386 INTEGER(kind=C_INT), INTENT(IN), VALUE :: jg
387 INTEGER(kind=C_INT), INTENT(IN), VALUE :: global_idx
388 loc = state%comin_descrdata_fct_glb2loc_cell(jg, int(global_idx))
390
391 ! Query topo data routines generated by python script (comin_descrdata_get_domain.F90.py) in ../utils. !
392#include "comin_descrdata_query_domain.inc"
393
394 ! Query global data routines generated by python script (comin_descrdata_get_global.F90.py) in ../utils. !
395#include "comin_descrdata_query_global.inc"
396
397END MODULE comin_descrdata
integer, parameter, public wp
working precision
subroutine, public comin_descrdata_finalize()
Clean descriptive data structure in ComIn currently no content but keep for future use.
subroutine, public comin_descrdata_set_simulation_interval(comin_time_info)
Fill time stamp info.
subroutine, public comin_descrdata_set_domain(comin_domain_info)
Set up data type for grid data.
subroutine, public comin_current_set_datetime(sim_time_current)
Update time stamp info, current time information.
subroutine, public comin_descrdata_set_timesteplength(jg, dt_current)
Fill array with timestep.
subroutine, public comin_descrdata_set_global(comin_global_info)
Fill global data.
subroutine, public comin_plugin_finish(routine, text)
Wrapper function for callback to ICON's "finish" routine.
subroutine, public comin_current_get_datetime(sim_time_current)
Retrieve time stamp info, current time information.
type(t_comin_descrdata_simulation_interval) function, pointer, public comin_descrdata_get_simulation_interval()
request a pointer to simulation status
integer(c_int) function, public comin_descrdata_get_block(idx1d)
auxiliary functions taken from ICON, version 2.6.5
type(t_comin_descrdata_global) function, pointer, public comin_descrdata_get_global()
request a pointer to the global data type
subroutine, public comin_descrdata_get_cell_indices(jg, i_blk, i_startblk, i_endblk, i_startidx, i_endidx, irl_start, irl_end)
Computes the start and end indices of do loops for cell-based variables.
real(wp) function, public comin_descrdata_get_timesteplength(jg)
Receive pointer on array storing timestep information for all domains.
subroutine, public comin_descrdata_get_vert_indices(jg, i_blk, i_startblk, i_endblk, i_startidx, i_endidx, irl_start, irl_end)
Computes the start and end indices of do loops for vertex-based variables.
integer(c_int) function, public comin_descrdata_index_lookup_glb2loc_cell(jg, global_idx)
Conversion of global cell index to MPI-process local index.
integer(c_int) function, public comin_descrdata_get_index(idx1d)
Auxiliary function: conversion of 1D to 2D indices.
subroutine, public comin_descrdata_get_edge_indices(jg, i_blk, i_startblk, i_endblk, i_startidx, i_endidx, irl_start, irl_end)
Computes the start and end indices of do loops for edge-based variables.
integer(c_int) function, public comin_descrdata_get_edge_npromz(jg)
Calculate npromz value for the blocking, needed for patch allocation. ... for the edges.
integer(c_int) function, public comin_descrdata_get_cell_npromz(jg)
Calculate npromz value for the blocking, needed for patch allocation. ... for the cells.
type(t_comin_descrdata_domain) function, pointer, public comin_descrdata_get_domain(jg)
request a pointer to the grid data type for a specific computational domain
integer(c_int) function, public comin_descrdata_get_vert_npromz(jg)
Calculate npromz value for the blocking, needed for patch allocation. ... for the vertices.
type(t_comin_state), pointer, public state
Vertex information for grid data structures.
Patch grid data structure, gathering information on grids.
Global data is invariant wrt the computational grid and never changed or updated.
Simulation status information, sim_current contains current time step.