source: LMDZ5/trunk/libf/phylmd/surf_land_orchidee_mod.F90 @ 2916

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