[880] | 1 | MODULE set_bounds_mod |
---|
| 2 | USE geometry, ONLY : swap_geometry, lon_e, lat_e |
---|
| 3 | USE dimensions, ONLY : swap_dimensions, u_pos |
---|
| 4 | USE math_const, ONLY : Pi |
---|
| 5 | USE domain_mod, ONLY : t_domain, t_cellset, domloc_glo_ind |
---|
| 6 | USE spherical_geom_mod, ONLY : xyz2lonlat |
---|
| 7 | |
---|
| 8 | IMPLICIT NONE |
---|
| 9 | PRIVATE |
---|
| 10 | SAVE |
---|
| 11 | |
---|
| 12 | PUBLIC :: set_bounds |
---|
| 13 | |
---|
| 14 | CONTAINS |
---|
| 15 | |
---|
| 16 | SUBROUTINE set_bounds_primal(d, cells, all, own) |
---|
| 17 | TYPE(t_domain) :: d |
---|
| 18 | TYPE(t_cellset) :: cells |
---|
| 19 | LOGICAL :: all, own(:,:) ! if all is .TRUE., include halo cells |
---|
| 20 | REAL :: lon,lat |
---|
| 21 | INTEGER :: i,j,k, n, halo_size |
---|
| 22 | |
---|
| 23 | halo_size = MERGE(1,0,all) |
---|
| 24 | |
---|
| 25 | ! count primal cells |
---|
| 26 | n=0 |
---|
| 27 | DO j=d%jj_begin-halo_size, d%jj_end+halo_size |
---|
| 28 | DO i=d%ii_begin-halo_size, d%ii_end+halo_size |
---|
| 29 | IF (own(i,j) .OR. all ) n=n+1 |
---|
| 30 | ENDDO |
---|
| 31 | ENDDO |
---|
| 32 | cells%ncell = n |
---|
| 33 | |
---|
| 34 | ! now set bounds |
---|
| 35 | ALLOCATE(cells%ij(n), cells%lon(n), cells%lat(n), cells%ind_glo(n)) |
---|
| 36 | ALLOCATE(cells%bnds_lon(0:5,n), cells%bnds_lat(0:5,n)) |
---|
| 37 | |
---|
| 38 | n=0 |
---|
| 39 | DO j=d%jj_begin-halo_size, d%jj_end+halo_size |
---|
| 40 | DO i=d%ii_begin-halo_size, d%ii_end+halo_size |
---|
| 41 | IF (own(i,j) .OR. all) THEN |
---|
| 42 | n=n+1 |
---|
| 43 | CALL xyz2lonlat(d%xyz(:,i,j), lon, lat) |
---|
| 44 | cells%lon(n)=lon*180./Pi |
---|
| 45 | cells%lat(n)=lat*180./Pi |
---|
| 46 | DO k=0,5 |
---|
| 47 | CALL xyz2lonlat(d%vertex(:,k,i,j), lon, lat) |
---|
| 48 | cells%bnds_lon(k,n)=lon*180./Pi |
---|
| 49 | cells%bnds_lat(k,n)=lat*180./Pi |
---|
| 50 | END DO |
---|
| 51 | cells%ij(n)=d%iim*(j-1)+i |
---|
| 52 | cells%ind_glo(n) = d%assign_cell_glo(i,j)-1 |
---|
| 53 | END IF |
---|
| 54 | END DO |
---|
| 55 | END DO |
---|
| 56 | |
---|
| 57 | ! PRINT *, 'set_bounds_primal', all, halo_size, cells%ncell |
---|
| 58 | END SUBROUTINE set_bounds_primal |
---|
| 59 | |
---|
| 60 | SUBROUTINE set_bounds_dual(d, cells) |
---|
| 61 | USE metric, ONLY : vup, vdown |
---|
| 62 | TYPE(t_domain) :: d |
---|
| 63 | TYPE(t_cellset) :: cells |
---|
| 64 | REAL :: lonc, latc, lon(0:2), lat(0:2) |
---|
| 65 | INTEGER :: i,j,k,n |
---|
| 66 | |
---|
| 67 | ! count dual cells |
---|
| 68 | n=0 |
---|
| 69 | DO j=d%jj_begin+1,d%jj_end |
---|
| 70 | DO i=d%ii_begin,d%ii_end-1 |
---|
| 71 | n=n+2 |
---|
| 72 | ENDDO |
---|
| 73 | ENDDO |
---|
| 74 | cells%ncell = n |
---|
| 75 | |
---|
| 76 | ! now set bounds |
---|
| 77 | ALLOCATE(cells%ind_glo(n)) ! not set but must be allocated |
---|
| 78 | ALLOCATE(cells%ij(n), cells%lon(n), cells%lat(n)) |
---|
| 79 | ALLOCATE(cells%bnds_lon(0:2,n), cells%bnds_lat(0:2,n)) |
---|
| 80 | |
---|
| 81 | n=0 |
---|
| 82 | DO j=d%jj_begin+1,d%jj_end |
---|
| 83 | DO i=d%ii_begin,d%ii_end-1 |
---|
| 84 | n=n+1 |
---|
| 85 | CALL xyz2lonlat(d%vertex(:,vdown,i,j), lonc, latc) |
---|
| 86 | CALL xyz2lonlat(d%xyz(:,i,j), lon(0), lat(0)) |
---|
| 87 | CALL xyz2lonlat(d%xyz(:,i,j-1), lon(1), lat(1)) |
---|
| 88 | CALL xyz2lonlat(d%xyz(:,i+1,j-1), lon(2), lat(2)) |
---|
| 89 | cells%lon(n)=lonc*180./Pi |
---|
| 90 | cells%lat(n)=latc*180/Pi |
---|
| 91 | DO k=0,2 |
---|
| 92 | cells%bnds_lat(k,n)=lat(k)*180./Pi |
---|
| 93 | cells%bnds_lon(k,n)=lon(k)*180./Pi |
---|
| 94 | END DO |
---|
| 95 | cells%ij(n) = d%z_down + d%iim*(j-1)+i |
---|
| 96 | ENDDO |
---|
| 97 | ENDDO |
---|
| 98 | |
---|
| 99 | DO j=d%jj_begin,d%jj_end-1 |
---|
| 100 | DO i=d%ii_begin+1,d%ii_end |
---|
| 101 | n=n+1 |
---|
| 102 | CALL xyz2lonlat(d%vertex(:,vup,i,j), lonc, latc) |
---|
| 103 | CALL xyz2lonlat(d%xyz(:,i,j), lon(0), lat(0)) |
---|
| 104 | CALL xyz2lonlat(d%xyz(:,i,j+1), lon(1), lat(1)) |
---|
| 105 | CALL xyz2lonlat(d%xyz(:,i-1,j+1), lon(2), lat(2)) |
---|
| 106 | cells%lon(n)=lonc*180./Pi |
---|
| 107 | cells%lat(n)=latc*180/Pi |
---|
| 108 | DO k=0,2 |
---|
| 109 | cells%bnds_lat(k,n)=lat(k)*180./Pi |
---|
| 110 | cells%bnds_lon(k,n)=lon(k)*180./Pi |
---|
| 111 | END DO |
---|
| 112 | cells%ij(n) = d%z_up + d%iim*(j-1)+i |
---|
| 113 | ENDDO |
---|
| 114 | ENDDO |
---|
| 115 | |
---|
| 116 | END SUBROUTINE set_bounds_dual |
---|
| 117 | |
---|
| 118 | SUBROUTINE set_bounds_edge(ind, d, cells) |
---|
| 119 | USE metric, ONLY : cell_glo |
---|
| 120 | INTEGER, INTENT(IN) :: ind |
---|
| 121 | TYPE(t_domain) :: d |
---|
| 122 | TYPE(t_cellset) :: cells |
---|
| 123 | REAL :: lon(2), lat(2) |
---|
| 124 | INTEGER :: i,j,ij,k,kk,n |
---|
| 125 | |
---|
| 126 | ! count edges |
---|
| 127 | n=0 |
---|
| 128 | DO j=d%jj_begin,d%jj_end |
---|
| 129 | DO i=d%ii_begin,d%ii_end |
---|
| 130 | DO k=0,5 |
---|
| 131 | IF (d%edge_assign_domain(k,i,j)==domloc_glo_ind(ind) & |
---|
| 132 | .AND. d%edge_assign_i(k,i,j)==i & |
---|
| 133 | .AND. d%edge_assign_j(k,i,j)==j & |
---|
| 134 | .AND. d%edge_assign_pos(k,i,j)==k) n=n+1 |
---|
| 135 | END DO |
---|
| 136 | END DO |
---|
| 137 | END DO |
---|
| 138 | cells%ncell = n |
---|
| 139 | |
---|
| 140 | ! now set bounds |
---|
| 141 | ALLOCATE(cells%ij(n), cells%lon(n), cells%lat(n), cells%ind_glo(n)) |
---|
| 142 | ALLOCATE(cells%sgn(n)) ! flip sign when reading/writing |
---|
| 143 | ALLOCATE(cells%bnds_lon(2,n), cells%bnds_lat(2,n)) |
---|
| 144 | |
---|
| 145 | CALL swap_dimensions(ind) |
---|
| 146 | CALL swap_geometry(ind) |
---|
| 147 | |
---|
| 148 | n=0 |
---|
| 149 | DO j=d%jj_begin,d%jj_end |
---|
| 150 | DO i=d%ii_begin,d%ii_end |
---|
| 151 | DO k=0,5 |
---|
| 152 | IF (d%edge_assign_domain(k,i,j)==domloc_glo_ind(ind) & |
---|
| 153 | .AND. d%edge_assign_i(k,i,j)==i & |
---|
| 154 | .AND. d%edge_assign_j(k,i,j)==j & |
---|
| 155 | .AND. d%edge_assign_pos(k,i,j)==k) THEN |
---|
| 156 | n=n+1 |
---|
| 157 | ij=(j-1)*d%iim+i+u_pos(k+1) |
---|
| 158 | kk = MOD(k+d%delta(i,j)+6,6) |
---|
| 159 | cells%ij(n) = ij |
---|
| 160 | cells%sgn(n) = d%edge_assign_sign(k,i,j) |
---|
| 161 | cells%ind_glo(n)= cell_glo(d%assign_cell_glo(i,j))%edge(kk)-1 |
---|
| 162 | cells%lon(n) = lon_e(ij)*180./Pi |
---|
| 163 | cells%lat(n) = lat_e(ij)*180./Pi |
---|
| 164 | |
---|
| 165 | kk = MOD(k-1+6,6) |
---|
| 166 | CALL xyz2lonlat(d%vertex(:,kk,i,j), lon(1),lat(1)) |
---|
| 167 | CALL xyz2lonlat(d%vertex(:,k, i,j), lon(2),lat(2)) |
---|
| 168 | cells%bnds_lon(:,n)=lon(:)*180./Pi |
---|
| 169 | cells%bnds_lat(:,n)=lat(:)*180/Pi |
---|
| 170 | END IF |
---|
| 171 | END DO |
---|
| 172 | END DO |
---|
| 173 | END DO |
---|
| 174 | |
---|
| 175 | END SUBROUTINE set_bounds_edge |
---|
| 176 | |
---|
| 177 | SUBROUTINE set_bounds(domain_type, glo) |
---|
| 178 | TYPE(t_domain), POINTER :: domain_type(:), d |
---|
| 179 | LOGICAL :: glo |
---|
| 180 | INTEGER :: ind |
---|
| 181 | !$OMP BARRIER |
---|
| 182 | !$OMP MASTER |
---|
| 183 | ! IF glo is .TRUE. we are dealing with the global mesh, otherwise with the local mesh |
---|
| 184 | ! write_field uses the global mesh and may want halo cells |
---|
| 185 | ! output_field (XIOS) uses the local mesh and uses only own cells |
---|
| 186 | ! output_field uses edges while write_field uses only primal and dual cells |
---|
| 187 | DO ind=1, SIZE(domain_type) |
---|
| 188 | d=>domain_type(ind) |
---|
| 189 | IF(glo) THEN ! global mesh / write_field |
---|
| 190 | ! primal cell i,j is owned if d%assign_domain(i,j)==ind |
---|
| 191 | CALL set_bounds_primal(d, d%primal_own, .FALSE., d%assign_domain==ind) |
---|
| 192 | CALL set_bounds_primal(d, d%primal_all, .TRUE., d%assign_domain==ind) |
---|
| 193 | CALL set_bounds_dual(d, d%dual_own) |
---|
| 194 | CALL set_bounds_dual(d, d%dual_all) |
---|
| 195 | ELSE ! local mesh / XIOS |
---|
| 196 | ! primal cell i,j is owned if d%own(i,j)==.TRUE. |
---|
| 197 | CALL set_bounds_primal(d, d%primal_own, .FALSE., d%own) |
---|
| 198 | CALL set_bounds_dual(d, d%dual_own) |
---|
| 199 | CALL set_bounds_edge(ind, d, d%edge_own) |
---|
| 200 | END IF |
---|
| 201 | END DO |
---|
| 202 | !$OMP END MASTER |
---|
| 203 | !$OMP BARRIER |
---|
| 204 | END SUBROUTINE set_bounds |
---|
| 205 | |
---|
| 206 | END MODULE set_bounds_mod |
---|