source: LMDZ6/trunk/libf/phylmd/surf_land_orchidee_mod.F90 @ 3397

Last change on this file since 3397 was 3391, checked in by oboucher, 6 years ago

Fields can now be passed to ORCHIDEE through surf_land_orchidee.
Fields are compressed in pbl_surface_mod and uncompressed in surf_land_orchidee.
Cosmetic changes, including in surf_land_mod.

  • Property copyright set to
    Name of program: LMDZ
    Creation date: 1984
    Version: LMDZ5
    License: CeCILL version 2
    Holder: Laboratoire de m\'et\'eorologie dynamique, CNRS, UMR 8539
    See the license file in the root directory
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 24.0 KB
RevLine 
[781]1!
2MODULE surf_land_orchidee_mod
[1146]3#ifndef ORCHIDEE_NOOPENMP
[2571]4#ifndef ORCHIDEE_NOZ0H
[2952]5#ifndef ORCHIDEE_NOFREIN
[781]6!
[2410]7! This module controles the interface towards the model ORCHIDEE.
[781]8!
[2410]9! Compatibility with ORCHIDIEE :
[2952]10! The current version can be used with ORCHIDEE/trunk from revision 4465.
11! This interface is used if none of the cpp keys ORCHIDEE_NOOPENMP,
12! ORCHIDEE_NOZ0H or ORCHIDEE_NOFREIN is set.
[2410]13!
[781]14! Subroutines in this module : surf_land_orchidee
15!                              Init_orchidee_index
16!                              Get_orchidee_communicator
17!                              Init_neighbours
18
19  USE dimphy
[1067]20#ifdef CPP_VEGET
[781]21  USE intersurf     ! module d'ORCHIDEE
[1067]22#endif
[781]23  USE cpl_mod,      ONLY : cpl_send_land_fields
[996]24  USE surface_data, ONLY : type_ocean
[2351]25  USE geometry_mod, ONLY : dx, dy
[781]26  USE mod_grid_phy_lmdz
[2351]27  USE mod_phys_lmdz_para, mpi_root_rank=>mpi_master
[3391]28  USE carbon_cycle_mod, ONLY : nbcf_in_orc, nbcf_out, fields_in, yfields_in, yfields_out, cfname_in, cfname_out
[781]29
30  IMPLICIT NONE
31
32  PRIVATE
33  PUBLIC  :: surf_land_orchidee
34
35CONTAINS
36!
37!****************************************************************************************
38
39  SUBROUTINE surf_land_orchidee(itime, dtime, date0, knon, &
[2410]40       knindex, rlon, rlat, yrmu0, pctsrf, &
[781]41       debut, lafin, &
[2240]42       plev,  u1_lay, v1_lay, gustiness, temp_air, spechum, epot_air, ccanopy, &
[781]43       tq_cdrag, petAcoef, peqAcoef, petBcoef, peqBcoef, &
44       precip_rain, precip_snow, lwdown, swnet, swdown, &
[1146]45       ps, q2m, t2m, &
[781]46       evap, fluxsens, fluxlat, &             
[888]47       tsol_rad, tsurf_new, alb1_new, alb2_new, &
[2952]48       emis_new, z0m_new, z0h_new, qsurf, &
49       veget, lai, height )
[1279]50
51    USE mod_surf_para
52    USE mod_synchro_omp
[3391]53    USE carbon_cycle_mod
[1785]54    USE indice_sol_mod
[2311]55    USE print_control_mod, ONLY: lunout
[2344]56    USE mod_grid_phy_lmdz, ONLY: nbp_lon, nbp_lat
[2348]57#ifdef CPP_VEGET
58    USE time_phylmdz_mod, ONLY: itau_phy
59#endif
[781]60!   
61! Cette routine sert d'interface entre le modele atmospherique et le
62! modele de sol continental. Appel a sechiba
63!
64! L. Fairhead 02/2000
65!
66! input:
67!   itime        numero du pas de temps
68!   dtime        pas de temps de la physique (en s)
69!   nisurf       index de la surface a traiter (1 = sol continental)
70!   knon         nombre de points de la surface a traiter
71!   knindex      index des points de la surface a traiter
72!   rlon         longitudes de la grille entiere
73!   rlat         latitudes de la grille entiere
74!   pctsrf       tableau des fractions de surface de chaque maille
75!   debut        logical: 1er appel a la physique (lire les restart)
76!   lafin        logical: dernier appel a la physique (ecrire les restart)
77!                     (si false calcul simplifie des fluxs sur les continents)
78!   plev         hauteur de la premiere couche (Pa)     
79!   u1_lay       vitesse u 1ere couche
80!   v1_lay       vitesse v 1ere couche
81!   temp_air     temperature de l'air 1ere couche
82!   spechum      humidite specifique 1ere couche
83!   epot_air     temp pot de l'air
[1279]84!   ccanopy      concentration CO2 canopee, correspond au co2_send de
85!                carbon_cycle_mod ou valeur constant co2_ppm
[781]86!   tq_cdrag     cdrag
87!   petAcoef     coeff. A de la resolution de la CL pour t
88!   peqAcoef     coeff. A de la resolution de la CL pour q
89!   petBcoef     coeff. B de la resolution de la CL pour t
90!   peqBcoef     coeff. B de la resolution de la CL pour q
91!   precip_rain  precipitation liquide
92!   precip_snow  precipitation solide
93!   lwdown       flux IR descendant a la surface
94!   swnet        flux solaire net
95!   swdown       flux solaire entrant a la surface
96!   ps           pression au sol
97!   radsol       rayonnement net aus sol (LW + SW)
98!
99! output:
100!   evap         evaporation totale
101!   fluxsens     flux de chaleur sensible
102!   fluxlat      flux de chaleur latente
103!   tsol_rad     
104!   tsurf_new    temperature au sol
[888]105!   alb1_new     albedo in visible SW interval
106!   alb2_new     albedo in near IR interval
[781]107!   emis_new     emissivite
[2571]108!   z0m_new      surface roughness for momentum
109!   z0h_new      surface roughness for heat
[781]110!   qsurf        air moisture at surface
111!
[793]112    INCLUDE "YOMCST.h"
[2952]113    INCLUDE "dimpft.h"
[781]114!
115! Parametres d'entree
116!****************************************************************************************
117    INTEGER, INTENT(IN)                       :: itime
118    REAL, INTENT(IN)                          :: dtime
119    REAL, INTENT(IN)                          :: date0
120    INTEGER, INTENT(IN)                       :: knon
121    INTEGER, DIMENSION(klon), INTENT(IN)      :: knindex
122    LOGICAL, INTENT(IN)                       :: debut, lafin
123    REAL, DIMENSION(klon,nbsrf), INTENT(IN)   :: pctsrf
124    REAL, DIMENSION(klon), INTENT(IN)         :: rlon, rlat
[2410]125    REAL, DIMENSION(klon), INTENT(IN)         :: yrmu0 ! cosine of solar zenith angle
[781]126    REAL, DIMENSION(klon), INTENT(IN)         :: plev
[2240]127    REAL, DIMENSION(klon), INTENT(IN)         :: u1_lay, v1_lay, gustiness
[781]128    REAL, DIMENSION(klon), INTENT(IN)         :: temp_air, spechum
129    REAL, DIMENSION(klon), INTENT(IN)         :: epot_air, ccanopy
130    REAL, DIMENSION(klon), INTENT(IN)         :: tq_cdrag
131    REAL, DIMENSION(klon), INTENT(IN)         :: petAcoef, peqAcoef
132    REAL, DIMENSION(klon), INTENT(IN)         :: petBcoef, peqBcoef
133    REAL, DIMENSION(klon), INTENT(IN)         :: precip_rain, precip_snow
134    REAL, DIMENSION(klon), INTENT(IN)         :: lwdown, swnet, swdown, ps
[1146]135    REAL, DIMENSION(klon), INTENT(IN)         :: q2m, t2m
[781]136
137! Parametres de sortie
138!****************************************************************************************
139    REAL, DIMENSION(klon), INTENT(OUT)        :: evap, fluxsens, fluxlat, qsurf
[888]140    REAL, DIMENSION(klon), INTENT(OUT)        :: tsol_rad, tsurf_new
141    REAL, DIMENSION(klon), INTENT(OUT)        :: alb1_new, alb2_new
[2571]142    REAL, DIMENSION(klon), INTENT(OUT)        :: emis_new, z0m_new, z0h_new
[2952]143    REAL, DIMENSION(klon,nvm_lmdz), INTENT(OUT) :: veget
144    REAL, DIMENSION(klon,nvm_lmdz), INTENT(OUT) :: lai
145    REAL, DIMENSION(klon,nvm_lmdz), INTENT(OUT) :: height
[781]146
147! Local
148!****************************************************************************************
[3391]149    INTEGER                                   :: ij, jj, igrid, ireal, index, nb
[781]150    INTEGER                                   :: error
[1146]151    REAL, DIMENSION(klon)                     :: swdown_vrai
[781]152    CHARACTER (len = 20)                      :: modname = 'surf_land_orchidee'
153    CHARACTER (len = 80)                      :: abort_message
154    LOGICAL,SAVE                              :: check = .FALSE.
155    !$OMP THREADPRIVATE(check)
156
157! type de couplage dans sechiba
158!  character (len=10)   :: coupling = 'implicit'
159! drapeaux controlant les appels dans SECHIBA
160!  type(control_type), save   :: control_in
161! Preserved albedo
162    REAL, ALLOCATABLE, DIMENSION(:), SAVE     :: albedo_keep, zlev
163    !$OMP THREADPRIVATE(albedo_keep,zlev)
164! coordonnees geographiques
165    REAL, ALLOCATABLE, DIMENSION(:,:), SAVE   :: lalo
166    !$OMP THREADPRIVATE(lalo)
167! pts voisins
168    INTEGER,ALLOCATABLE, DIMENSION(:,:), SAVE :: neighbours
169    !$OMP THREADPRIVATE(neighbours)
170! fractions continents
171    REAL,ALLOCATABLE, DIMENSION(:), SAVE      :: contfrac
172    !$OMP THREADPRIVATE(contfrac)
173! resolution de la grille
174    REAL, ALLOCATABLE, DIMENSION (:,:), SAVE  :: resolution
175    !$OMP THREADPRIVATE(resolution)
176
177    REAL, ALLOCATABLE, DIMENSION (:,:), SAVE  :: lon_scat, lat_scat 
178    !$OMP THREADPRIVATE(lon_scat,lat_scat)
179
180    LOGICAL, SAVE                             :: lrestart_read = .TRUE.
181    !$OMP THREADPRIVATE(lrestart_read)
182    LOGICAL, SAVE                             :: lrestart_write = .FALSE.
183    !$OMP THREADPRIVATE(lrestart_write)
184
185    REAL, DIMENSION(knon,2)                   :: albedo_out
186
187! Pb de nomenclature
188    REAL, DIMENSION(klon)                     :: petA_orc, peqA_orc
189    REAL, DIMENSION(klon)                     :: petB_orc, peqB_orc
190! Pb de correspondances de grilles
191    INTEGER, DIMENSION(:), SAVE, ALLOCATABLE  :: ig, jg
192    !$OMP THREADPRIVATE(ig,jg)
193    INTEGER :: indi, indj
194    INTEGER, SAVE, ALLOCATABLE,DIMENSION(:)   :: ktindex
195    !$OMP THREADPRIVATE(ktindex)
196
197! Essai cdrag
198    REAL, DIMENSION(klon)                     :: cdrag
199    INTEGER,SAVE                              :: offset
200    !$OMP THREADPRIVATE(offset)
201
202    REAL, DIMENSION(klon_glo)                 :: rlon_g,rlat_g
203    INTEGER, SAVE                             :: orch_comm
204    !$OMP THREADPRIVATE(orch_comm)
205
206    REAL, ALLOCATABLE, DIMENSION(:), SAVE     :: coastalflow
207    !$OMP THREADPRIVATE(coastalflow)
208    REAL, ALLOCATABLE, DIMENSION(:), SAVE     :: riverflow
209    !$OMP THREADPRIVATE(riverflow)
[987]210   
211    INTEGER :: orch_omp_rank
212    INTEGER :: orch_omp_size
[781]213!
214! Fin definition
215!****************************************************************************************
216
217    IF (check) WRITE(lunout,*)'Entree ', modname
218 
219! Initialisation
220 
221    IF (debut) THEN
[1067]222! Test of coherence between variable ok_veget and cpp key CPP_VEGET
223#ifndef CPP_VEGET
224       abort_message='Pb de coherence: ok_veget = .true. mais CPP_VEGET = .false.'
[2311]225       CALL abort_physic(modname,abort_message,1)
[1067]226#endif
227
[987]228       CALL Init_surf_para(knon)
[781]229       ALLOCATE(ktindex(knon))
230       IF ( .NOT. ALLOCATED(albedo_keep)) THEN
[987]231!ym          ALLOCATE(albedo_keep(klon))
232!ym bizarre que non alloué en knon precedement
233          ALLOCATE(albedo_keep(knon))
[781]234          ALLOCATE(zlev(knon))
235       ENDIF
236! Pb de correspondances de grilles
237       ALLOCATE(ig(klon))
238       ALLOCATE(jg(klon))
239       ig(1) = 1
240       jg(1) = 1
241       indi = 0
242       indj = 2
243       DO igrid = 2, klon - 1
244          indi = indi + 1
[2344]245          IF ( indi > nbp_lon) THEN
[781]246             indi = 1
247             indj = indj + 1
248          ENDIF
249          ig(igrid) = indi
250          jg(igrid) = indj
251       ENDDO
252       ig(klon) = 1
[2344]253       jg(klon) = nbp_lat
[781]254
255       IF ((.NOT. ALLOCATED(lalo))) THEN
256          ALLOCATE(lalo(knon,2), stat = error)
257          IF (error /= 0) THEN
258             abort_message='Pb allocation lalo'
[2311]259             CALL abort_physic(modname,abort_message,1)
[781]260          ENDIF
261       ENDIF
262       IF ((.NOT. ALLOCATED(lon_scat))) THEN
[2344]263          ALLOCATE(lon_scat(nbp_lon,nbp_lat), stat = error)
[781]264          IF (error /= 0) THEN
265             abort_message='Pb allocation lon_scat'
[2311]266             CALL abort_physic(modname,abort_message,1)
[781]267          ENDIF
268       ENDIF
269       IF ((.NOT. ALLOCATED(lat_scat))) THEN
[2344]270          ALLOCATE(lat_scat(nbp_lon,nbp_lat), stat = error)
[781]271          IF (error /= 0) THEN
272             abort_message='Pb allocation lat_scat'
[2311]273             CALL abort_physic(modname,abort_message,1)
[781]274          ENDIF
275       ENDIF
276       lon_scat = 0.
277       lat_scat = 0.
278       DO igrid = 1, knon
279          index = knindex(igrid)
280          lalo(igrid,2) = rlon(index)
281          lalo(igrid,1) = rlat(index)
282       ENDDO
283
284       
285       
286       CALL Gather(rlon,rlon_g)
287       CALL Gather(rlat,rlat_g)
288
289       IF (is_mpi_root) THEN
290          index = 1
[2344]291          DO jj = 2, nbp_lat-1
292             DO ij = 1, nbp_lon
[781]293                index = index + 1
294                lon_scat(ij,jj) = rlon_g(index)
295                lat_scat(ij,jj) = rlat_g(index)
296             ENDDO
297          ENDDO
298          lon_scat(:,1) = lon_scat(:,2)
299          lat_scat(:,1) = rlat_g(1)
[2344]300          lon_scat(:,nbp_lat) = lon_scat(:,2)
301          lat_scat(:,nbp_lat) = rlat_g(klon_glo)
[781]302       ENDIF
303   
[1023]304       CALL bcast(lon_scat)
305       CALL bcast(lat_scat)
[781]306!
307! Allouer et initialiser le tableau des voisins et des fraction de continents
308!
309       IF ( (.NOT.ALLOCATED(neighbours))) THEN
310          ALLOCATE(neighbours(knon,8), stat = error)
311          IF (error /= 0) THEN
312             abort_message='Pb allocation neighbours'
[2311]313             CALL abort_physic(modname,abort_message,1)
[781]314          ENDIF
315       ENDIF
316       neighbours = -1.
317       IF (( .NOT. ALLOCATED(contfrac))) THEN
318          ALLOCATE(contfrac(knon), stat = error)
319          IF (error /= 0) THEN
320             abort_message='Pb allocation contfrac'
[2311]321             CALL abort_physic(modname,abort_message,1)
[781]322          ENDIF
323       ENDIF
324
325       DO igrid = 1, knon
326          ireal = knindex(igrid)
327          contfrac(igrid) = pctsrf(ireal,is_ter)
328       ENDDO
329
330
331       CALL Init_neighbours(knon,neighbours,knindex,pctsrf(:,is_ter))
332
333!
334!  Allocation et calcul resolutions
335       IF ( (.NOT.ALLOCATED(resolution))) THEN
336          ALLOCATE(resolution(knon,2), stat = error)
337          IF (error /= 0) THEN
338             abort_message='Pb allocation resolution'
[2311]339             CALL abort_physic(modname,abort_message,1)
[781]340          ENDIF
341       ENDIF
342       DO igrid = 1, knon
343          ij = knindex(igrid)
[2351]344          resolution(igrid,1) = dx(ij)
345          resolution(igrid,2) = dy(ij)
[781]346       ENDDO
347     
348       ALLOCATE(coastalflow(klon), stat = error)
349       IF (error /= 0) THEN
350          abort_message='Pb allocation coastalflow'
[2311]351          CALL abort_physic(modname,abort_message,1)
[781]352       ENDIF
353       
354       ALLOCATE(riverflow(klon), stat = error)
355       IF (error /= 0) THEN
356          abort_message='Pb allocation riverflow'
[2311]357          CALL abort_physic(modname,abort_message,1)
[781]358       ENDIF
[1279]359!
[1454]360! carbon_cycle_cpl not possible with this interface and version of ORHCHIDEE
[1279]361!
[3391]362! >> PC
363!       IF (carbon_cycle_cpl) THEN
364!          abort_message='carbon_cycle_cpl not yet possible with this interface of ORCHIDEE'
365!          CALL abort_physic(modname,abort_message,1)
366!       END IF
367! << PC
[1279]368       
[781]369    ENDIF                          ! (fin debut)
[1279]370 
[781]371!
372! Appel a la routine sols continentaux
373!
374    IF (lafin) lrestart_write = .TRUE.
375    IF (check) WRITE(lunout,*)'lafin ',lafin,lrestart_write
[987]376     
[781]377    petA_orc(1:knon) = petBcoef(1:knon) * dtime
378    petB_orc(1:knon) = petAcoef(1:knon)
379    peqA_orc(1:knon) = peqBcoef(1:knon) * dtime
380    peqB_orc(1:knon) = peqAcoef(1:knon)
381
382    cdrag = 0.
383    cdrag(1:knon) = tq_cdrag(1:knon)
384
385! zlev(1:knon) = (100.*plev(1:knon))/((ps(1:knon)/287.05*temp_air(1:knon))*9.80665)
[2011]386!    zlev(1:knon) = (100.*plev(1:knon))/((ps(1:knon)/RD*temp_air(1:knon))*RG)
387     zlev(1:knon) = plev(1:knon)*RD*temp_air(1:knon)/((ps(1:knon)*100.0)*RG)
[781]388
389
390! PF et PASB
391!   where(cdrag > 0.01)
392!     cdrag = 0.01
393!   endwhere
394!  write(*,*)'Cdrag = ',minval(cdrag),maxval(cdrag)
395
396 
397    IF (debut) THEN
[987]398       CALL Init_orchidee_index(knon,knindex,offset,ktindex)
399       CALL Get_orchidee_communicator(orch_comm,orch_omp_size,orch_omp_rank)
400       CALL Init_synchro_omp
401       
[1023]402       IF (knon > 0) THEN
[1067]403#ifdef CPP_VEGET
[987]404         CALL Init_intersurf(nbp_lon,nbp_lat,knon,ktindex,offset,orch_omp_size,orch_omp_rank,orch_comm)
[1067]405#endif
[987]406       ENDIF
[802]407
[987]408       
409       IF (knon > 0) THEN
410
[3391]411         print *,'OB before intersurf=', SIZE(cfname_in), SIZE(cfname_out)
[1067]412#ifdef CPP_VEGET
[2571]413         CALL intersurf_initialize_gathered (itime+itau_phy-1, nbp_lon, nbp_lat, knon, ktindex, dtime, &
414               lrestart_read, lrestart_write, lalo, contfrac, neighbours, resolution, date0, &
415               zlev,  u1_lay, v1_lay, spechum, temp_air, epot_air, &
[802]416               cdrag, petA_orc, peqA_orc, petB_orc, peqB_orc, &
417               precip_rain, precip_snow, lwdown, swnet, swdown, ps, &
418               evap, fluxsens, fluxlat, coastalflow, riverflow, &
[2952]419               tsol_rad, tsurf_new, qsurf, albedo_out, emis_new, z0m_new, &   
[3391]420! >> PC
421               !lon_scat, lat_scat, q2m, t2m, z0h_new, nvm_orch)
422               lon_scat, lat_scat, q2m, t2m, z0h_new, nvm_orch, &
423               field_out_names=cfname_out, field_in_names=cfname_in(1:nbcf_in_orc))
424! << PC
[1067]425#endif         
[781]426       ENDIF
427
[987]428       CALL Synchro_omp
429
[781]430       albedo_keep(1:knon) = (albedo_out(1:knon,1)+albedo_out(1:knon,2))/2.
431
432    ENDIF
[987]433   
[781]434!  swdown_vrai(1:knon) = swnet(1:knon)/(1. - albedo_keep(1:knon))
435    swdown_vrai(1:knon) = swdown(1:knon)
436
[987]437    IF (knon > 0) THEN
[1067]438#ifdef CPP_VEGET   
[2952]439       IF (nvm_orch .NE. nvm_lmdz ) THEN
440          abort_message='Pb de dimensiosn PFT: nvm_orch et nvm_lmdz differents.'
441          CALL abort_physic(modname,abort_message,1)
442       ENDIF
443
[2571]444       CALL intersurf_main_gathered (itime+itau_phy, nbp_lon, nbp_lat, knon, ktindex, dtime,  &
[802]445            lrestart_read, lrestart_write, lalo, &
446            contfrac, neighbours, resolution, date0, &
[781]447            zlev,  u1_lay(1:knon), v1_lay(1:knon), spechum(1:knon), temp_air(1:knon), epot_air(1:knon), ccanopy(1:knon), &
448            cdrag(1:knon), petA_orc(1:knon), peqA_orc(1:knon), petB_orc(1:knon), peqB_orc(1:knon), &
449            precip_rain(1:knon), precip_snow(1:knon), lwdown(1:knon), swnet(1:knon), swdown_vrai(1:knon), ps(1:knon), &
450            evap(1:knon), fluxsens(1:knon), fluxlat(1:knon), coastalflow(1:knon), riverflow(1:knon), &
[2571]451            tsol_rad(1:knon), tsurf_new(1:knon), qsurf(1:knon), albedo_out(1:knon,:), emis_new(1:knon), z0m_new(1:knon), &
[2952]452            lon_scat, lat_scat, q2m, t2m, z0h_new(1:knon),&
453            veget(1:knon,:),lai(1:knon,:),height(1:knon,:),&
[3391]454            fields_out=yfields_out(1:knon,1:nbcf_out),  &
455            fields_in=yfields_in(1:knon,1:nbcf_in_orc), &
[2952]456            coszang=yrmu0(1:knon))
[1067]457#endif       
[781]458    ENDIF
459
[987]460    CALL Synchro_omp
461   
[781]462    albedo_keep(1:knon) = (albedo_out(1:knon,1)+albedo_out(1:knon,2))/2.
463
464!* Send to coupler
465!
[996]466    IF (type_ocean=='couple') THEN
[781]467       CALL cpl_send_land_fields(itime, knon, knindex, &
468            riverflow, coastalflow)
469    ENDIF
470
[888]471    alb1_new(1:knon) = albedo_out(1:knon,1)
472    alb2_new(1:knon) = albedo_out(1:knon,2)
[781]473
474! Convention orchidee: positif vers le haut
475    fluxsens(1:knon) = -1. * fluxsens(1:knon)
476    fluxlat(1:knon)  = -1. * fluxlat(1:knon)
477   
478!  evap     = -1. * evap
479
480    IF (debut) lrestart_read = .FALSE.
481   
[987]482    IF (debut) CALL Finalize_surf_para
[1279]483
[3391]484! >> PC
485! Decompressing variables into LMDz for the module carbon_cycle_mod
486! nbcf_in can be zero, in which case the loop does not operate
487! fields_in can then used elsewhere in the model
488     
489     fields_in(:,:)=0.0
490
491     DO nb=1, nbcf_in_orc
492       DO igrid = 1, knon
493        ireal = knindex(igrid)
494        fields_in(ireal,nb)=yfields_in(igrid,nb)
495       ENDDO
496       WRITE(*,*) 'surf_land_orchidee_mod --- yfields_in :',cfname_in(nb)
497     ENDDO
498! >> PC
[987]499   
[781]500  END SUBROUTINE surf_land_orchidee
501!
502!****************************************************************************************
503!
[987]504  SUBROUTINE Init_orchidee_index(knon,knindex,offset,ktindex)
505  USE mod_surf_para
506  USE mod_grid_phy_lmdz
507 
508    INTEGER,INTENT(IN)    :: knon
509    INTEGER,INTENT(IN)    :: knindex(klon)   
510    INTEGER,INTENT(OUT)   :: offset
511    INTEGER,INTENT(OUT)   :: ktindex(klon)
[781]512   
[987]513    INTEGER               :: ktindex_glo(knon_glo)
514    INTEGER               :: offset_para(0:omp_size*mpi_size-1)
515    INTEGER               :: LastPoint
516    INTEGER               :: task
[781]517   
[987]518    ktindex(1:knon)=knindex(1:knon)+(klon_mpi_begin-1)+(klon_omp_begin-1)+nbp_lon-1
[781]519   
[987]520    CALL gather_surf(ktindex(1:knon),ktindex_glo)
521   
522    IF (is_mpi_root .AND. is_omp_root) THEN
523      LastPoint=0
524      DO Task=0,mpi_size*omp_size-1
525        IF (knon_glo_para(Task)>0) THEN
526           offset_para(task)= LastPoint-MOD(LastPoint,nbp_lon)
527           LastPoint=ktindex_glo(knon_glo_end_para(task))
528        ENDIF
529      ENDDO
[781]530    ENDIF
531   
[987]532    CALL bcast(offset_para)
[781]533   
[987]534    offset=offset_para(omp_size*mpi_rank+omp_rank)
535   
536    ktindex(1:knon)=ktindex(1:knon)-offset
[781]537
[987]538  END SUBROUTINE Init_orchidee_index
539
[781]540!
[987]541!************************* ***************************************************************
[781]542!
[987]543
544  SUBROUTINE Get_orchidee_communicator(orch_comm,orch_omp_size,orch_omp_rank)
545  USE  mod_surf_para
546     
[1001]547#ifdef CPP_MPI
[781]548    INCLUDE 'mpif.h'
549#endif   
550
551    INTEGER,INTENT(OUT) :: orch_comm
[987]552    INTEGER,INTENT(OUT) :: orch_omp_size
553    INTEGER,INTENT(OUT) :: orch_omp_rank
[781]554    INTEGER             :: color
[987]555    INTEGER             :: i,ierr
[802]556!
557! End definition
558!****************************************************************************************
[781]559   
[987]560    IF (is_omp_root) THEN         
561     
562      IF (knon_mpi==0) THEN
563         color = 0
564      ELSE
565         color = 1
566      ENDIF
567   
[1001]568#ifdef CPP_MPI   
[987]569      CALL MPI_COMM_SPLIT(COMM_LMDZ_PHY,color,mpi_rank,orch_comm,ierr)
[781]570#endif
[1023]571   
572    ENDIF
573    CALL bcast_omp(orch_comm)
574   
575    IF (knon_mpi /= 0) THEN
576      orch_omp_size=0
577      DO i=0,omp_size-1
578        IF (knon_omp_para(i) /=0) THEN
579          orch_omp_size=orch_omp_size+1
580          IF (i==omp_rank) orch_omp_rank=orch_omp_size-1
581        ENDIF
582      ENDDO
583    ENDIF
[781]584   
585  END SUBROUTINE Get_orchidee_communicator
586!
587!****************************************************************************************
588
[987]589
590  SUBROUTINE Init_neighbours(knon,neighbours,knindex,pctsrf)
591    USE mod_grid_phy_lmdz
592    USE mod_surf_para   
[1785]593    USE indice_sol_mod
[987]594
[1001]595#ifdef CPP_MPI
[781]596    INCLUDE 'mpif.h'
597#endif   
598
[802]599! Input arguments
600!****************************************************************************************
[781]601    INTEGER, INTENT(IN)                     :: knon
[987]602    INTEGER, DIMENSION(klon), INTENT(IN)    :: knindex
[781]603    REAL, DIMENSION(klon), INTENT(IN)       :: pctsrf
604   
[802]605! Output arguments
606!****************************************************************************************
607    INTEGER, DIMENSION(knon,8), INTENT(OUT) :: neighbours
608
609! Local variables
610!****************************************************************************************
611    INTEGER                              :: i, igrid, jj, ij, iglob
612    INTEGER                              :: ierr, ireal, index
613    INTEGER, DIMENSION(8,3)              :: off_ini
614    INTEGER, DIMENSION(8)                :: offset 
[987]615    INTEGER, DIMENSION(nbp_lon,nbp_lat)  :: correspond
616    INTEGER, DIMENSION(knon_glo)         :: ktindex_glo
617    INTEGER, DIMENSION(knon_glo,8)       :: neighbours_glo
618    REAL, DIMENSION(klon_glo)            :: pctsrf_glo
619    INTEGER                              :: ktindex(klon)
[802]620!
621! End definition
622!****************************************************************************************
623
[987]624    ktindex(1:knon)=knindex(1:knon)+(klon_mpi_begin-1)+(klon_omp_begin-1)+nbp_lon-1
[781]625   
[987]626    CALL gather_surf(ktindex(1:knon),ktindex_glo)
627    CALL gather(pctsrf,pctsrf_glo)
[781]628   
[987]629    IF (is_mpi_root .AND. is_omp_root) THEN
630      neighbours_glo(:,:)=-1
[781]631!  Initialisation des offset   
632!
633! offset bord ouest
[987]634       off_ini(1,1) = - nbp_lon   ; off_ini(2,1) = - nbp_lon + 1     ; off_ini(3,1) = 1
635       off_ini(4,1) = nbp_lon + 1 ; off_ini(5,1) = nbp_lon           ; off_ini(6,1) = 2 * nbp_lon - 1
636       off_ini(7,1) = nbp_lon -1  ; off_ini(8,1) = - 1
[781]637! offset point normal
[987]638       off_ini(1,2) = - nbp_lon   ; off_ini(2,2) = - nbp_lon + 1     ; off_ini(3,2) = 1
639       off_ini(4,2) = nbp_lon + 1 ; off_ini(5,2) = nbp_lon           ; off_ini(6,2) = nbp_lon - 1
640       off_ini(7,2) = -1          ; off_ini(8,2) = - nbp_lon - 1
[781]641! offset bord   est
[987]642       off_ini(1,3) = - nbp_lon   ; off_ini(2,3) = - 2 * nbp_lon + 1 ; off_ini(3,3) = - nbp_lon + 1
643       off_ini(4,3) =  1          ; off_ini(5,3) = nbp_lon           ; off_ini(6,3) = nbp_lon - 1
644       off_ini(7,3) = -1          ; off_ini(8,3) = - nbp_lon - 1
[781]645!
646! Attention aux poles
647!
[987]648       DO igrid = 1, knon_glo
649          index = ktindex_glo(igrid)
650          jj = INT((index - 1)/nbp_lon) + 1
651          ij = index - (jj - 1) * nbp_lon
[781]652          correspond(ij,jj) = igrid
653       ENDDO
[2126]654!sonia : Les mailles des voisines doivent etre toutes egales (pour couplage orchidee)
655       IF (knon_glo == 1) THEN
656         igrid = 1
657         DO i = 1,8
658           neighbours_glo(igrid, i) = igrid
659         ENDDO
660       ELSE
[781]661       
[987]662       DO igrid = 1, knon_glo
663          iglob = ktindex_glo(igrid)
664         
665          IF (MOD(iglob, nbp_lon) == 1) THEN
[781]666             offset = off_ini(:,1)
[987]667          ELSE IF(MOD(iglob, nbp_lon) == 0) THEN
[781]668             offset = off_ini(:,3)
669          ELSE
670             offset = off_ini(:,2)
671          ENDIF
[987]672         
[781]673          DO i = 1, 8
674             index = iglob + offset(i)
[987]675             ireal = (MIN(MAX(1, index - nbp_lon + 1), klon_glo))
676             IF (pctsrf_glo(ireal) > EPSFRA) THEN
677                jj = INT((index - 1)/nbp_lon) + 1
678                ij = index - (jj - 1) * nbp_lon
679                neighbours_glo(igrid, i) = correspond(ij, jj)
[781]680             ENDIF
681          ENDDO
682       ENDDO
[2126]683       ENDIF !fin knon_glo == 1
[781]684
685    ENDIF
686   
[987]687    DO i = 1, 8
688      CALL scatter_surf(neighbours_glo(:,i),neighbours(1:knon,i))
[781]689    ENDDO
690  END SUBROUTINE Init_neighbours
[987]691
[781]692!
693!****************************************************************************************
694!
[1146]695#endif
[2571]696#endif
[2952]697#endif
[781]698END MODULE surf_land_orchidee_mod
Note: See TracBrowser for help on using the repository browser.