FV3-JEDI
fv3jedi_lineargetvalues_mod.f90
Go to the documentation of this file.
1 ! (C) Copyright 2020 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 
7 
8 ! fckit
9 use fckit_mpi_module, only: fckit_mpi_comm
10 
11 ! oops
12 use datetime_mod, only: datetime
13 use unstructured_interpolation_mod, only: unstrc_interp
14 
15 ! ufo
16 use ufo_locs_mod, only: ufo_locs, ufo_locs_time_mask
17 use ufo_geovals_mod, only: ufo_geovals
18 
19 ! fv3jedi uses
26 
27 implicit none
28 
29 private
31 
33  contains
34  procedure, public :: fill_geovals_ad
36 
37 ! --------------------------------------------------------------------------------------------------
38 
39 contains
40 
41 ! --------------------------------------------------------------------------------------------------
42 
43 subroutine fill_geovals_ad(self, geom, fields, t1, t2, locs, geovals)
44 
45 class(fv3jedi_lineargetvalues), intent(inout) :: self
46 type(fv3jedi_geom), intent(in) :: geom
47 type(fv3jedi_field), intent(inout) :: fields(:)
48 type(datetime), intent(in) :: t1
49 type(datetime), intent(in) :: t2
50 type(ufo_locs), intent(in) :: locs
51 type(ufo_geovals), intent(in) :: geovals
52 
53 integer :: gv, n, ji, jj, jlev
54 type(fv3jedi_field), pointer :: field
55 character(len=field_clen) :: fv3jedi_name
56 logical, allocatable :: time_mask(:)
57 real(kind=kind_real), allocatable :: field_us(:)
58 real(kind=kind_real), allocatable :: geovals_all(:,:), geovals_tmp(:)
59 
60 ! Get mask for locations in this time window
61 ! ------------------------------------------
62 call ufo_locs_time_mask(locs, t1, t2, time_mask)
63 
64 
65 ! Allocate intermediate variables
66 ! -------------------------------
67 allocate(field_us(self%ngrid))
68 allocate(geovals_all(locs%nlocs, self%npz+1))
69 allocate(geovals_tmp(locs%nlocs))
70 field_us = 0.0_kind_real
71 geovals_all = 0.0_kind_real
72 geovals_tmp = 0.0_kind_real
73 
74 
75 ! Loop over GeoVaLs
76 ! -----------------
77 do gv = 1, geovals%nvar
78 
79  ! Get GeoVaLs field
80  ! -----------------
81  call long_name_to_fv3jedi_name(fields, trim(geovals%variables(gv)), fv3jedi_name)
82  call get_field(fields, fv3jedi_name, field)
83 
84  ! Adjoint of fill GeoVaLs relevant to this window
85  ! -----------------------------------------------
86  do n = 1,locs%nlocs
87  if (time_mask(n)) geovals_all(n, 1:field%npz) = geovals%geovals(gv)%vals(1:field%npz, n)
88  enddo
89 
90  ! Adjoint of interpolation
91  ! ------------------------
92  if ( trim(self%interp_method) == 'bump' .and. &
93  .not.field%integerfield .and. trim(field%space)=='magnitude' ) then
94 
95  call self%bump%apply_ad(field%npz, field%array, locs%nlocs, geovals_all(:,1:field%npz))
96 
97  else ! Otherwise use unstructured interpolation
98 
99  do jlev = 1, field%npz
100 
101  geovals_tmp(1:locs%nlocs) = geovals_all(1:locs%nlocs, jlev)
102 
103  ! Conditions for integer and directional fields
104  ! ---------------------------------------------
105  if (.not. field%integerfield .and. trim(field%space)=='magnitude') then
106  call self%unsinterp%apply_ad(field_us, geovals_tmp)
107  else
108  call abor1_ftn("fv3jedi_getvalues_mod.fill_geovals: interpolation for this kind of "// &
109  "field is not supported. FieldName: "// trim(field%fv3jedi_name))
110  endif
111 
112  n = 0
113  do jj = field%jsc, field%jec
114  do ji = field%isc, field%iec
115  n = n + 1
116  field%array(ji, jj, jlev) = field_us(n)
117  enddo
118  enddo
119 
120  enddo
121 
122  endif
123 
124 enddo
125 
126 deallocate(time_mask)
127 deallocate(field_us)
128 deallocate(geovals_all)
129 deallocate(geovals_tmp)
130 
131 end subroutine fill_geovals_ad
132 
133 ! ------------------------------------------------------------------------------
134 
fv3jedi_field_mod
Definition: fv3jedi_field_mod.f90:6
fv3jedi_getvalues_mod
Definition: fv3jedi_getvalues_mod.f90:6
fv3jedi_geom_mod
Fortran module handling geometry for the FV3 model.
Definition: fv3jedi_geom_mod.f90:8
fv3jedi_lineargetvalues_mod
Definition: fv3jedi_lineargetvalues_mod.f90:6
fv3jedi_increment_mod
Definition: fv3jedi_increment_mod.F90:6
fv3jedi_field_mod::get_field
Definition: fv3jedi_field_mod.f90:25
fv3jedi_geom_mod::fv3jedi_geom
Fortran derived type to hold geometry data for the FV3JEDI model.
Definition: fv3jedi_geom_mod.f90:46
fv3jedi_lineargetvalues_mod::fill_geovals_ad
subroutine fill_geovals_ad(self, geom, fields, t1, t2, locs, geovals)
Definition: fv3jedi_lineargetvalues_mod.f90:44
fv3jedi_field_mod::long_name_to_fv3jedi_name
subroutine, public long_name_to_fv3jedi_name(fields, long_name, fv3jedi_name)
Definition: fv3jedi_field_mod.f90:268
fv3jedi_getvalues_mod::fv3jedi_getvalues_base
Definition: fv3jedi_getvalues_mod.f90:35
fv3jedi_kinds_mod::kind_real
integer, parameter, public kind_real
Definition: fv3jedi_kinds_mod.f90:14
fv3jedi_field_mod::fv3jedi_field
Definition: fv3jedi_field_mod.f90:36
fv3jedi_kinds_mod
Definition: fv3jedi_kinds_mod.f90:6
fv3jedi_lineargetvalues_mod::fv3jedi_lineargetvalues
Definition: fv3jedi_lineargetvalues_mod.f90:32
fv3jedi_increment_mod::fv3jedi_increment
Definition: fv3jedi_increment_mod.F90:34
fv3jedi_field_mod::field_clen
integer, parameter, public field_clen
Definition: fv3jedi_field_mod.f90:31