MPAS-JEDI
mpas_increment_interface_mod.F90
Go to the documentation of this file.
1 ! (C) Copyright 2017 UCAR
2 !
3 ! This software is licensed under the terms of the Apache Licence Version 2.0
4 ! which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
5 
6 ! ------------------------------------------------------------------------------
7 
9 
10 use atlas_module, only: atlas_fieldset
11 use fckit_configuration_module, only: fckit_configuration
12 use iso_c_binding
13 
14 !oops
15 use datetime_mod
16 use kinds, only: kind_real
17 use oops_variables_mod
18 
19 !mpas-jedi
20 use mpas_geom_mod
23 
24 implicit none
25 private
26 
27 ! ------------------------------------------------------------------------------
28 
29 contains
30 
31 ! ------------------------------------------------------------------------------
32 
33 subroutine mpas_increment_create_c(c_key_self, c_key_geom, c_vars) &
34  bind(c,name='mpas_increment_create_f90')
35 implicit none
36 integer(c_int), intent(inout) :: c_key_self
37 integer(c_int), intent(in) :: c_key_geom !< Geometry
38 type(c_ptr), value, intent(in) :: c_vars !< List of variables
39 
40 type(mpas_fields), pointer :: self
41 type(mpas_geom), pointer :: geom
42 type(oops_variables) :: vars
43 
44 call mpas_geom_registry%get(c_key_geom, geom)
45 call mpas_fields_registry%init()
46 call mpas_fields_registry%add(c_key_self)
47 call mpas_fields_registry%get(c_key_self,self)
48 
49 vars = oops_variables(c_vars)
50 call self%create(geom, vars, vars)
51 
52 end subroutine mpas_increment_create_c
53 
54 ! ------------------------------------------------------------------------------
55 
56 subroutine mpas_increment_delete_c(c_key_self) &
57  bind(c,name='mpas_increment_delete_f90')
58 implicit none
59 integer(c_int), intent(inout) :: c_key_self
60 type(mpas_fields), pointer :: self
61 
62 call mpas_fields_registry%get(c_key_self,self)
63 
64 call self%delete()
65 
66 call mpas_fields_registry%remove(c_key_self)
67 
68 end subroutine mpas_increment_delete_c
69 
70 ! ------------------------------------------------------------------------------
71 
72 subroutine mpas_increment_zero_c(c_key_self) &
73  bind(c,name='mpas_increment_zero_f90')
74 implicit none
75 integer(c_int), intent(in) :: c_key_self
76 type(mpas_fields), pointer :: self
77 
78 call mpas_fields_registry%get(c_key_self,self)
79 call self%zeros()
80 
81 end subroutine mpas_increment_zero_c
82 
83 ! ------------------------------------------------------------------------------
84 
85 subroutine mpas_increment_ones_c(c_key_self) &
86  bind(c,name='mpas_increment_ones_f90')
87 implicit none
88 integer(c_int), intent(in) :: c_key_self
89 type(mpas_fields), pointer :: self
90 
91 call mpas_fields_registry%get(c_key_self,self)
92 call self%ones()
93 
94 end subroutine mpas_increment_ones_c
95 
96 ! ------------------------------------------------------------------------------
97 
98 subroutine mpas_increment_dirac_c(c_key_self,c_conf) &
99  bind(c,name='mpas_increment_dirac_f90')
100 implicit none
101 integer(c_int), intent(in) :: c_key_self
102 type(c_ptr), value, intent(in) :: c_conf !< Configuration
103 
104 type(mpas_fields), pointer :: self
105 type(fckit_configuration) :: f_conf
106 
107 call mpas_fields_registry%get(c_key_self,self)
108 f_conf = fckit_configuration(c_conf)
109 call dirac(self,f_conf)
110 
111 end subroutine mpas_increment_dirac_c
112 
113 ! ------------------------------------------------------------------------------
114 
115 subroutine mpas_increment_random_c(c_key_self) &
116  bind(c,name='mpas_increment_random_f90')
117 implicit none
118 integer(c_int), intent(in) :: c_key_self
119 type(mpas_fields), pointer :: self
120 
121 call mpas_fields_registry%get(c_key_self,self)
122 call self%random()
123 
124 end subroutine mpas_increment_random_c
125 
126 ! ------------------------------------------------------------------------------
127 
128 subroutine mpas_increment_copy_c(c_key_self,c_key_rhs) &
129  bind(c,name='mpas_increment_copy_f90')
130 implicit none
131 integer(c_int), intent(in) :: c_key_self
132 integer(c_int), intent(in) :: c_key_rhs
133 
134 type(mpas_fields), pointer :: self
135 type(mpas_fields), pointer :: rhs
136 call mpas_fields_registry%get(c_key_self,self)
137 call mpas_fields_registry%get(c_key_rhs,rhs)
138 
139 call self%copy(rhs)
140 
141 end subroutine mpas_increment_copy_c
142 
143 ! ------------------------------------------------------------------------------
144 
145 subroutine mpas_increment_self_add_c(c_key_self,c_key_rhs) &
146  bind(c,name='mpas_increment_self_add_f90')
147 implicit none
148 integer(c_int), intent(in) :: c_key_self
149 integer(c_int), intent(in) :: c_key_rhs
150 
151 type(mpas_fields), pointer :: self
152 type(mpas_fields), pointer :: rhs
153 call mpas_fields_registry%get(c_key_self,self)
154 call mpas_fields_registry%get(c_key_rhs,rhs)
155 
156 call self%self_add(rhs)
157 
158 end subroutine mpas_increment_self_add_c
159 
160 ! ------------------------------------------------------------------------------
161 
162 subroutine mpas_increment_self_schur_c(c_key_self,c_key_rhs) &
163  bind(c,name='mpas_increment_self_schur_f90')
164 implicit none
165 integer(c_int), intent(in) :: c_key_self
166 integer(c_int), intent(in) :: c_key_rhs
167 
168 type(mpas_fields), pointer :: self
169 type(mpas_fields), pointer :: rhs
170 call mpas_fields_registry%get(c_key_self,self)
171 call mpas_fields_registry%get(c_key_rhs,rhs)
172 
173 call self%self_schur(rhs)
174 
175 end subroutine mpas_increment_self_schur_c
176 
177 ! ------------------------------------------------------------------------------
178 
179 subroutine mpas_increment_self_sub_c(c_key_self,c_key_rhs) &
180  bind(c,name='mpas_increment_self_sub_f90')
181 implicit none
182 integer(c_int), intent(in) :: c_key_self
183 integer(c_int), intent(in) :: c_key_rhs
184 
185 type(mpas_fields), pointer :: self
186 type(mpas_fields), pointer :: rhs
187 call mpas_fields_registry%get(c_key_self,self)
188 call mpas_fields_registry%get(c_key_rhs,rhs)
189 
190 call self%self_sub(rhs)
191 
192 end subroutine mpas_increment_self_sub_c
193 
194 ! ------------------------------------------------------------------------------
195 
196 subroutine mpas_increment_self_mul_c(c_key_self,c_zz) &
197  bind(c,name='mpas_increment_self_mul_f90')
198 implicit none
199 integer(c_int), intent(in) :: c_key_self
200 real(c_double), intent(in) :: c_zz
201 type(mpas_fields), pointer :: self
202 real(kind=kind_real) :: zz
203 
204 call mpas_fields_registry%get(c_key_self,self)
205 zz = c_zz
206 
207 call self%self_mult(zz)
208 
209 end subroutine mpas_increment_self_mul_c
210 
211 ! ------------------------------------------------------------------------------
212 
213 subroutine mpas_increment_axpy_inc_c(c_key_self,c_zz,c_key_rhs) &
214  bind(c,name='mpas_increment_axpy_inc_f90')
215 implicit none
216 integer(c_int), intent(in) :: c_key_self
217 real(c_double), intent(in) :: c_zz
218 integer(c_int), intent(in) :: c_key_rhs
219 
220 type(mpas_fields), pointer :: self
221 type(mpas_fields), pointer :: rhs
222 real(kind=kind_real) :: zz
223 
224 call mpas_fields_registry%get(c_key_self,self)
225 call mpas_fields_registry%get(c_key_rhs,rhs)
226 zz = c_zz
227 
228 call self%axpy(zz,rhs)
229 
230 end subroutine mpas_increment_axpy_inc_c
231 
232 ! ------------------------------------------------------------------------------
233 
234 subroutine mpas_increment_axpy_state_c(c_key_self,c_zz,c_key_rhs) &
235  bind(c,name='mpas_increment_axpy_state_f90')
236 implicit none
237 integer(c_int), intent(in) :: c_key_self
238 real(c_double), intent(in) :: c_zz
239 integer(c_int), intent(in) :: c_key_rhs
240 
241 type(mpas_fields), pointer :: self
242 type(mpas_fields), pointer :: rhs
243 real(kind=kind_real) :: zz
244 
245 call mpas_fields_registry%get(c_key_self,self)
246 call mpas_fields_registry%get(c_key_rhs,rhs)
247 zz = c_zz
248 
249 call self%axpy(zz,rhs)
250 
251 end subroutine mpas_increment_axpy_state_c
252 
253 ! ------------------------------------------------------------------------------
254 
255 subroutine mpas_increment_dot_prod_c(c_key_inc1,c_key_inc2,c_prod) &
256  bind(c,name='mpas_increment_dot_prod_f90')
257 implicit none
258 integer(c_int), intent(in) :: c_key_inc1, c_key_inc2
259 real(c_double), intent(inout) :: c_prod
260 real(kind=kind_real) :: zz
261 type(mpas_fields), pointer :: inc1, inc2
262 
263 call mpas_fields_registry%get(c_key_inc1,inc1)
264 call mpas_fields_registry%get(c_key_inc2,inc2)
265 
266 call inc1%dot_prod(inc2,zz)
267 
268 c_prod = zz
269 
270 end subroutine mpas_increment_dot_prod_c
271 
272 ! ------------------------------------------------------------------------------
273 
274 subroutine mpas_increment_diff_incr_c(c_key_lhs,c_key_x1,c_key_x2) &
275  bind(c,name='mpas_increment_diff_incr_f90')
276 implicit none
277 integer(c_int), intent(in) :: c_key_lhs
278 integer(c_int), intent(in) :: c_key_x1
279 integer(c_int), intent(in) :: c_key_x2
280 type(mpas_fields), pointer :: lhs
281 type(mpas_fields), pointer :: x1
282 type(mpas_fields), pointer :: x2
283 
284 call mpas_fields_registry%get(c_key_lhs,lhs)
285 call mpas_fields_registry%get(c_key_x1,x1)
286 call mpas_fields_registry%get(c_key_x2,x2)
287 
288 call diff_incr(lhs,x1,x2)
289 
290 end subroutine mpas_increment_diff_incr_c
291 
292 ! ------------------------------------------------------------------------------
293 
294 subroutine mpas_increment_change_resol_c(c_key_inc,c_key_rhs) &
295  bind(c,name='mpas_increment_change_resol_f90')
296 implicit none
297 integer(c_int), intent(in) :: c_key_inc
298 integer(c_int), intent(in) :: c_key_rhs
299 type(mpas_fields), pointer :: inc, rhs
300 
301 call mpas_fields_registry%get(c_key_inc,inc)
302 call mpas_fields_registry%get(c_key_rhs,rhs)
303 
304 call inc%change_resol(rhs)
305 
306 end subroutine mpas_increment_change_resol_c
307 
308 ! ------------------------------------------------------------------------------
309 
310 subroutine mpas_increment_set_atlas_c(c_key_self,c_key_geom,c_vars,c_afieldset) &
311  bind(c,name='mpas_increment_set_atlas_f90')
312 implicit none
313 integer(c_int), intent(in) :: c_key_self
314 integer(c_int), intent(in) :: c_key_geom
315 type(c_ptr), value, intent(in) :: c_vars
316 type(c_ptr), intent(in), value :: c_afieldset
317 type(mpas_fields), pointer :: self
318 type(mpas_geom), pointer :: geom
319 type(oops_variables) :: vars
320 type(atlas_fieldset) :: afieldset
321 
322 call mpas_fields_registry%get(c_key_self,self)
323 call mpas_geom_registry%get(c_key_geom, geom)
324 vars = oops_variables(c_vars)
325 afieldset = atlas_fieldset(c_afieldset)
326 
327 call set_atlas(self, geom, vars, afieldset)
328 
329 end subroutine mpas_increment_set_atlas_c
330 
331 ! ------------------------------------------------------------------------------
332 
333 subroutine mpas_increment_to_atlas_c(c_key_self,c_key_geom,c_vars,c_afieldset) &
334  bind(c,name='mpas_increment_to_atlas_f90')
335 implicit none
336 integer(c_int), intent(in) :: c_key_self
337 integer(c_int), intent(in) :: c_key_geom
338 type(c_ptr), value, intent(in) :: c_vars
339 type(c_ptr), intent(in), value :: c_afieldset
340 type(mpas_fields), pointer :: self
341 type(mpas_geom), pointer :: geom
342 type(oops_variables) :: vars
343 type(atlas_fieldset) :: afieldset
344 
345 call mpas_fields_registry%get(c_key_self,self)
346 call mpas_geom_registry%get(c_key_geom, geom)
347 vars = oops_variables(c_vars)
348 afieldset = atlas_fieldset(c_afieldset)
349 
350 call to_atlas(self, geom, vars, afieldset)
351 
352 end subroutine mpas_increment_to_atlas_c
353 
354 ! ------------------------------------------------------------------------------
355 
356 subroutine mpas_increment_from_atlas_c(c_key_self,c_key_geom,c_vars,c_afieldset) &
357  bind(c,name='mpas_increment_from_atlas_f90')
358 implicit none
359 integer(c_int), intent(in) :: c_key_self
360 integer(c_int), intent(in) :: c_key_geom
361 type(c_ptr), value, intent(in) :: c_vars
362 type(c_ptr), intent(in), value :: c_afieldset
363 type(mpas_fields), pointer :: self
364 type(mpas_geom), pointer :: geom
365 type(oops_variables) :: vars
366 type(atlas_fieldset) :: afieldset
367 
368 call mpas_fields_registry%get(c_key_self, self)
369 call mpas_geom_registry%get(c_key_geom, geom)
370 vars = oops_variables(c_vars)
371 afieldset = atlas_fieldset(c_afieldset)
372 
373 call from_atlas(self, geom, vars, afieldset)
374 
375 end subroutine mpas_increment_from_atlas_c
376 
377 ! ------------------------------------------------------------------------------
378 
379 subroutine mpas_increment_read_file_c(c_key_inc, c_conf, c_dt) &
380  bind(c,name='mpas_increment_read_file_f90')
381 implicit none
382 integer(c_int), intent(in) :: c_key_inc !< Fields
383 type(c_ptr), value, intent(in) :: c_conf !< Configuration
384 type(c_ptr), value, intent(in) :: c_dt !< DateTime
385 
386 type(mpas_fields), pointer :: self
387 type(datetime) :: fdate
388 type(fckit_configuration) :: f_conf
389 
390 call mpas_fields_registry%get(c_key_inc,self)
391 call c_f_datetime(c_dt, fdate)
392 f_conf = fckit_configuration(c_conf)
393 call self%read_file(f_conf, fdate)
394 
395 end subroutine mpas_increment_read_file_c
396 
397 ! ------------------------------------------------------------------------------
398 
399 subroutine mpas_increment_write_file_c(c_key_inc, c_conf, c_dt) &
400  bind(c,name='mpas_increment_write_file_f90')
401 implicit none
402 integer(c_int), intent(in) :: c_key_inc !< Fields
403 type(c_ptr), value, intent(in) :: c_conf !< Configuration
404 type(c_ptr), value, intent(in) :: c_dt !< DateTime
405 
406 type(mpas_fields), pointer :: self
407 type(datetime) :: fdate
408 type(fckit_configuration) :: f_conf
409 
410 call mpas_fields_registry%get(c_key_inc,self)
411 call c_f_datetime(c_dt, fdate)
412 f_conf = fckit_configuration(c_conf)
413 call self%write_file(f_conf, fdate)
414 
415 end subroutine mpas_increment_write_file_c
416 
417 ! ------------------------------------------------------------------------------
418 
419 subroutine mpas_increment_gpnorm_c(c_key_inc, kf, pstat) &
420  bind(c,name='mpas_increment_gpnorm_f90')
421 implicit none
422 integer(c_int), intent(in) :: c_key_inc
423 integer(c_int), intent(in) :: kf
424 real(c_double), intent(inout) :: pstat(3*kf)
425 
426 type(mpas_fields), pointer :: self
427 real(kind=kind_real) :: zstat(3, kf)
428 integer :: jj, js, jf
429 
430 call mpas_fields_registry%get(c_key_inc,self)
431 
432 call self%gpnorm(kf, zstat)
433 jj=0
434 do jf = 1, kf
435  do js = 1, 3
436  jj=jj+1
437  pstat(jj) = zstat(js,jf)
438  enddo
439 enddo
440 
441 end subroutine mpas_increment_gpnorm_c
442 
443 ! ------------------------------------------------------------------------------
444 
445 subroutine mpas_increment_rms_c(c_key_inc, prms) &
446  bind(c,name='mpas_increment_rms_f90')
447 implicit none
448 integer(c_int), intent(in) :: c_key_inc
449 real(c_double), intent(inout) :: prms
450 
451 type(mpas_fields), pointer :: self
452 real(kind=kind_real) :: zz
453 
454 call mpas_fields_registry%get(c_key_inc,self)
455 
456 call self%rms(zz)
457 
458 prms = zz
459 
460 end subroutine mpas_increment_rms_c
461 
462 ! ------------------------------------------------------------------------------
463 
464 subroutine mpas_increment_print_c(c_key_self) &
465  bind(c,name='mpas_increment_print_f90')
466 implicit none
467 integer(c_int), intent(in) :: c_key_self
468 type(mpas_fields), pointer :: self
469 
470 call mpas_fields_registry%get(c_key_self,self)
471 
472 !call increment_print(self)
473 
474 end subroutine mpas_increment_print_c
475 
476 ! ------------------------------------------------------------------------------
477 
478 subroutine mpas_increment_sizes_c(c_key_self,nc,nf) &
479  bind(c,name='mpas_increment_sizes_f90')
480 implicit none
481 integer(c_int), intent(in) :: c_key_self
482 integer(c_int), intent(inout) :: nc,nf
483 type(mpas_fields), pointer :: self
484 
485 call mpas_fields_registry%get(c_key_self,self)
486 
487 nf = self%nf_ci
488 nc = self%geom%nCellsGlobal
489 
490 end subroutine mpas_increment_sizes_c
491 
492 ! --------------------------------------------------------------------------------------------------
493 
494 subroutine mpas_increment_serial_size_c(c_key_self,c_vsize) &
495  bind(c,name='mpas_increment_serial_size_f90')
496 
497 implicit none
498 
499 ! Passed variables
500 integer(c_int),intent(in) :: c_key_self !< Increment
501 integer(c_size_t),intent(out) :: c_vsize !< Size
502 
503 type(mpas_fields),pointer :: self
504 
505 call mpas_fields_registry%get(c_key_self, self)
506 call self%serial_size(c_vsize)
507 
508 end subroutine mpas_increment_serial_size_c
509 
510 ! --------------------------------------------------------------------------------------------------
511 
512 subroutine mpas_increment_serialize_c(c_key_self,c_vsize,c_vect_inc) &
513  bind(c,name='mpas_increment_serialize_f90')
514 
515 implicit none
516 
517 ! Passed variables
518 integer(c_int),intent(in) :: c_key_self !< Increment
519 integer(c_size_t),intent(in) :: c_vsize !< Size
520 real(c_double),intent(out) :: c_vect_inc(c_vsize) !< Vector
521 
522 type(mpas_fields),pointer :: self
523 
524 call mpas_fields_registry%get(c_key_self, self)
525 ! Call Fortran
526 call self%serialize(c_vsize, c_vect_inc)
527 
528 end subroutine mpas_increment_serialize_c
529 
530 ! --------------------------------------------------------------------------------------------------
531 
532 subroutine mpas_increment_deserialize_c(c_key_self,c_vsize,c_vect_inc,c_index) &
533  bind(c,name='mpas_increment_deserialize_f90')
534 
535 implicit none
536 
537 ! Passed variables
538 integer(c_int),intent(in) :: c_key_self !< Increment
539 integer(c_size_t),intent(in) :: c_vsize !< Size
540 real(c_double),intent(in) :: c_vect_inc(c_vsize) !< Vector
541 integer(c_size_t), intent(inout):: c_index !< Index
542 
543 type(mpas_fields),pointer :: self
544 
545 call mpas_fields_registry%get(c_key_self, self)
546 
547 ! Call Fortran
548 call self%deserialize(c_vsize, c_vect_inc, c_index)
549 
550 end subroutine mpas_increment_deserialize_c
551 ! ------------------------------------------------------------------------------
552 
554 
type(registry_t), public mpas_fields_registry
Linked list interface - defines registry_t type.
type(registry_t), public mpas_geom_registry
Linked list interface - defines registry_t type.
subroutine mpas_increment_axpy_state_c(c_key_self, c_zz, c_key_rhs)
subroutine mpas_increment_rms_c(c_key_inc, prms)
subroutine mpas_increment_gpnorm_c(c_key_inc, kf, pstat)
subroutine mpas_increment_serialize_c(c_key_self, c_vsize, c_vect_inc)
subroutine mpas_increment_set_atlas_c(c_key_self, c_key_geom, c_vars, c_afieldset)
subroutine mpas_increment_sizes_c(c_key_self, nc, nf)
subroutine mpas_increment_write_file_c(c_key_inc, c_conf, c_dt)
subroutine mpas_increment_self_sub_c(c_key_self, c_key_rhs)
subroutine mpas_increment_create_c(c_key_self, c_key_geom, c_vars)
subroutine mpas_increment_copy_c(c_key_self, c_key_rhs)
subroutine mpas_increment_diff_incr_c(c_key_lhs, c_key_x1, c_key_x2)
subroutine mpas_increment_from_atlas_c(c_key_self, c_key_geom, c_vars, c_afieldset)
subroutine mpas_increment_deserialize_c(c_key_self, c_vsize, c_vect_inc, c_index)
subroutine mpas_increment_to_atlas_c(c_key_self, c_key_geom, c_vars, c_afieldset)
subroutine mpas_increment_dot_prod_c(c_key_inc1, c_key_inc2, c_prod)
subroutine mpas_increment_dirac_c(c_key_self, c_conf)
subroutine mpas_increment_change_resol_c(c_key_inc, c_key_rhs)
subroutine mpas_increment_axpy_inc_c(c_key_self, c_zz, c_key_rhs)
subroutine mpas_increment_self_schur_c(c_key_self, c_key_rhs)
subroutine mpas_increment_self_add_c(c_key_self, c_key_rhs)
subroutine mpas_increment_read_file_c(c_key_inc, c_conf, c_dt)
subroutine mpas_increment_self_mul_c(c_key_self, c_zz)
subroutine mpas_increment_serial_size_c(c_key_self, c_vsize)
subroutine, public set_atlas(self, geom, vars, afieldset)
subroutine, public to_atlas(self, geom, vars, afieldset)
subroutine, public diff_incr(lhs, x1, x2)
subroutine, public dirac(self, f_conf)
subroutine, public from_atlas(self, geom, vars, afieldset)
Fortran derived type to hold MPAS field.
Fortran derived type to hold geometry definition.