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

Last change on this file since 2562 was 2410, checked in by jghattas, 9 years ago

Added the variable yrmu0(cosine of the solar zenith angle) into ORCHIDEE:

Current version of LMDZ can now be used with ORCHIDEE trunk revisions from rev 2961 and newer. For revision 1078-2960 on ORCHIDEE trunk, a small modification (change coszang into sinang) in surf_land_orchidee_mod.f90 is needed. For older versions than ORCHIDEE trunk revision 1078, the interface in surf_land_orchidee_noopenmp_mod.f90 should be used (add cpp key ORCHIDEE_NOOPENMP).

For details see ticket https://forge.ipsl.jussieu.fr/orchidee/ticket/217

  • 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
[781]4!
[2410]5! This module controles the interface towards the model ORCHIDEE.
[781]6!
[2410]7! Compatibility with ORCHIDIEE :
8! The current version can be used with ORCHIDEE/trunk from revision 2961.
9! This interface can also be used with ORCHIDEE/trunk revision 1078-2960 if changing
10! coszang=yrmu0 into sinang=yrmu0 at 2 places later below in this module.
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
[987]32  LOGICAL, ALLOCATABLE, SAVE :: flag_omp(:)
[781]33CONTAINS
34!
35!****************************************************************************************
36
37  SUBROUTINE surf_land_orchidee(itime, dtime, date0, knon, &
[2410]38       knindex, rlon, rlat, yrmu0, pctsrf, &
[781]39       debut, lafin, &
[2240]40       plev,  u1_lay, v1_lay, gustiness, temp_air, spechum, epot_air, ccanopy, &
[781]41       tq_cdrag, petAcoef, peqAcoef, petBcoef, peqBcoef, &
42       precip_rain, precip_snow, lwdown, swnet, swdown, &
[1146]43       ps, q2m, t2m, &
[781]44       evap, fluxsens, fluxlat, &             
[888]45       tsol_rad, tsurf_new, alb1_new, alb2_new, &
[781]46       emis_new, z0_new, qsurf)
[1279]47
48    USE mod_surf_para
49    USE mod_synchro_omp
[1454]50    USE carbon_cycle_mod, ONLY : carbon_cycle_cpl
[1785]51    USE indice_sol_mod
[2311]52    USE print_control_mod, ONLY: lunout
[2344]53    USE mod_grid_phy_lmdz, ONLY: nbp_lon, nbp_lat
[2348]54#ifdef CPP_VEGET
55    USE time_phylmdz_mod, ONLY: itau_phy
56#endif
[781]57!   
58! Cette routine sert d'interface entre le modele atmospherique et le
59! modele de sol continental. Appel a sechiba
60!
61! L. Fairhead 02/2000
62!
63! input:
64!   itime        numero du pas de temps
65!   dtime        pas de temps de la physique (en s)
66!   nisurf       index de la surface a traiter (1 = sol continental)
67!   knon         nombre de points de la surface a traiter
68!   knindex      index des points de la surface a traiter
69!   rlon         longitudes de la grille entiere
70!   rlat         latitudes de la grille entiere
71!   pctsrf       tableau des fractions de surface de chaque maille
72!   debut        logical: 1er appel a la physique (lire les restart)
73!   lafin        logical: dernier appel a la physique (ecrire les restart)
74!                     (si false calcul simplifie des fluxs sur les continents)
75!   plev         hauteur de la premiere couche (Pa)     
76!   u1_lay       vitesse u 1ere couche
77!   v1_lay       vitesse v 1ere couche
78!   temp_air     temperature de l'air 1ere couche
79!   spechum      humidite specifique 1ere couche
80!   epot_air     temp pot de l'air
[1279]81!   ccanopy      concentration CO2 canopee, correspond au co2_send de
82!                carbon_cycle_mod ou valeur constant co2_ppm
[781]83!   tq_cdrag     cdrag
84!   petAcoef     coeff. A de la resolution de la CL pour t
85!   peqAcoef     coeff. A de la resolution de la CL pour q
86!   petBcoef     coeff. B de la resolution de la CL pour t
87!   peqBcoef     coeff. B de la resolution de la CL pour q
88!   precip_rain  precipitation liquide
89!   precip_snow  precipitation solide
90!   lwdown       flux IR descendant a la surface
91!   swnet        flux solaire net
92!   swdown       flux solaire entrant a la surface
93!   ps           pression au sol
94!   radsol       rayonnement net aus sol (LW + SW)
95!   
96!
97! output:
98!   evap         evaporation totale
99!   fluxsens     flux de chaleur sensible
100!   fluxlat      flux de chaleur latente
101!   tsol_rad     
102!   tsurf_new    temperature au sol
[888]103!   alb1_new     albedo in visible SW interval
104!   alb2_new     albedo in near IR interval
[781]105!   emis_new     emissivite
106!   z0_new       surface roughness
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
[781]139    REAL, DIMENSION(klon), INTENT(OUT)        :: emis_new, z0_new
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
[2344]405          CALL intersurf_main (itime+itau_phy-1, nbp_lon, nbp_lat, knon, ktindex, dtime, &
[802]406               lrestart_read, lrestart_write, lalo, &
407               contfrac, neighbours, resolution, date0, &
408               zlev,  u1_lay, v1_lay, spechum, temp_air, epot_air, ccanopy, &
409               cdrag, petA_orc, peqA_orc, petB_orc, peqB_orc, &
410               precip_rain, precip_snow, lwdown, swnet, swdown, ps, &
411               evap, fluxsens, fluxlat, coastalflow, riverflow, &
412               tsol_rad, tsurf_new, qsurf, albedo_out, emis_new, z0_new, &
[2410]413               lon_scat, lat_scat, q2m, t2m, coszang=yrmu0)
[1067]414#endif         
[781]415       ENDIF
416
[987]417       CALL Synchro_omp
418
[781]419       albedo_keep(1:knon) = (albedo_out(1:knon,1)+albedo_out(1:knon,2))/2.
420
421    ENDIF
422
[987]423   
[781]424!  swdown_vrai(1:knon) = swnet(1:knon)/(1. - albedo_keep(1:knon))
425    swdown_vrai(1:knon) = swdown(1:knon)
426
[987]427    IF (knon > 0) THEN
[1067]428#ifdef CPP_VEGET   
[2344]429       CALL intersurf_main (itime+itau_phy, nbp_lon, nbp_lat, knon, ktindex, dtime,  &
[802]430            lrestart_read, lrestart_write, lalo, &
431            contfrac, neighbours, resolution, date0, &
[781]432            zlev,  u1_lay(1:knon), v1_lay(1:knon), spechum(1:knon), temp_air(1:knon), epot_air(1:knon), ccanopy(1:knon), &
433            cdrag(1:knon), petA_orc(1:knon), peqA_orc(1:knon), petB_orc(1:knon), peqB_orc(1:knon), &
434            precip_rain(1:knon), precip_snow(1:knon), lwdown(1:knon), swnet(1:knon), swdown_vrai(1:knon), ps(1:knon), &
435            evap(1:knon), fluxsens(1:knon), fluxlat(1:knon), coastalflow(1:knon), riverflow(1:knon), &
436            tsol_rad(1:knon), tsurf_new(1:knon), qsurf(1:knon), albedo_out(1:knon,:), emis_new(1:knon), z0_new(1:knon), &
[2410]437            lon_scat, lat_scat, q2m, t2m, coszang=yrmu0(1:knon))
[1067]438#endif       
[781]439    ENDIF
440
[987]441    CALL Synchro_omp
442   
[781]443    albedo_keep(1:knon) = (albedo_out(1:knon,1)+albedo_out(1:knon,2))/2.
444
445!* Send to coupler
446!
[996]447    IF (type_ocean=='couple') THEN
[781]448       CALL cpl_send_land_fields(itime, knon, knindex, &
449            riverflow, coastalflow)
450    ENDIF
451
[888]452    alb1_new(1:knon) = albedo_out(1:knon,1)
453    alb2_new(1:knon) = albedo_out(1:knon,2)
[781]454
455! Convention orchidee: positif vers le haut
456    fluxsens(1:knon) = -1. * fluxsens(1:knon)
457    fluxlat(1:knon)  = -1. * fluxlat(1:knon)
458   
459!  evap     = -1. * evap
460
461    IF (debut) lrestart_read = .FALSE.
462   
[987]463    IF (debut) CALL Finalize_surf_para
[1279]464
[987]465   
[781]466  END SUBROUTINE surf_land_orchidee
467!
468!****************************************************************************************
469!
[987]470  SUBROUTINE Init_orchidee_index(knon,knindex,offset,ktindex)
471  USE mod_surf_para
472  USE mod_grid_phy_lmdz
473 
474    INTEGER,INTENT(IN)    :: knon
475    INTEGER,INTENT(IN)    :: knindex(klon)   
476    INTEGER,INTENT(OUT)   :: offset
477    INTEGER,INTENT(OUT)   :: ktindex(klon)
[781]478   
[987]479    INTEGER               :: ktindex_glo(knon_glo)
480    INTEGER               :: offset_para(0:omp_size*mpi_size-1)
481    INTEGER               :: LastPoint
482    INTEGER               :: task
[781]483   
[987]484    ktindex(1:knon)=knindex(1:knon)+(klon_mpi_begin-1)+(klon_omp_begin-1)+nbp_lon-1
[781]485   
[987]486    CALL gather_surf(ktindex(1:knon),ktindex_glo)
487   
488    IF (is_mpi_root .AND. is_omp_root) THEN
489      LastPoint=0
490      DO Task=0,mpi_size*omp_size-1
491        IF (knon_glo_para(Task)>0) THEN
492           offset_para(task)= LastPoint-MOD(LastPoint,nbp_lon)
493           LastPoint=ktindex_glo(knon_glo_end_para(task))
494        ENDIF
495      ENDDO
[781]496    ENDIF
497   
[987]498    CALL bcast(offset_para)
[781]499   
[987]500    offset=offset_para(omp_size*mpi_rank+omp_rank)
501   
502    ktindex(1:knon)=ktindex(1:knon)-offset
[781]503
[987]504  END SUBROUTINE Init_orchidee_index
505
[781]506!
[987]507!************************* ***************************************************************
[781]508!
[987]509
510  SUBROUTINE Get_orchidee_communicator(orch_comm,orch_omp_size,orch_omp_rank)
511  USE  mod_surf_para
512     
[1001]513#ifdef CPP_MPI
[781]514    INCLUDE 'mpif.h'
515#endif   
516
517    INTEGER,INTENT(OUT) :: orch_comm
[987]518    INTEGER,INTENT(OUT) :: orch_omp_size
519    INTEGER,INTENT(OUT) :: orch_omp_rank
[781]520    INTEGER             :: color
[987]521    INTEGER             :: i,ierr
[802]522!
523! End definition
524!****************************************************************************************
[781]525   
[987]526   
527    IF (is_omp_root) THEN         
528     
529      IF (knon_mpi==0) THEN
530         color = 0
531      ELSE
532         color = 1
533      ENDIF
534   
[1001]535#ifdef CPP_MPI   
[987]536      CALL MPI_COMM_SPLIT(COMM_LMDZ_PHY,color,mpi_rank,orch_comm,ierr)
[781]537#endif
[1023]538   
539    ENDIF
540    CALL bcast_omp(orch_comm)
541   
542    IF (knon_mpi /= 0) THEN
543      orch_omp_size=0
544      DO i=0,omp_size-1
545        IF (knon_omp_para(i) /=0) THEN
546          orch_omp_size=orch_omp_size+1
547          IF (i==omp_rank) orch_omp_rank=orch_omp_size-1
548        ENDIF
549      ENDDO
550    ENDIF
[987]551   
[781]552   
553  END SUBROUTINE Get_orchidee_communicator
554!
555!****************************************************************************************
556
[987]557
558  SUBROUTINE Init_neighbours(knon,neighbours,knindex,pctsrf)
559    USE mod_grid_phy_lmdz
560    USE mod_surf_para   
[1785]561    USE indice_sol_mod
[987]562
[1001]563#ifdef CPP_MPI
[781]564    INCLUDE 'mpif.h'
565#endif   
566
[802]567! Input arguments
568!****************************************************************************************
[781]569    INTEGER, INTENT(IN)                     :: knon
[987]570    INTEGER, DIMENSION(klon), INTENT(IN)    :: knindex
[781]571    REAL, DIMENSION(klon), INTENT(IN)       :: pctsrf
572   
[802]573! Output arguments
574!****************************************************************************************
575    INTEGER, DIMENSION(knon,8), INTENT(OUT) :: neighbours
576
577! Local variables
578!****************************************************************************************
579    INTEGER                              :: i, igrid, jj, ij, iglob
580    INTEGER                              :: ierr, ireal, index
581    INTEGER, DIMENSION(8,3)              :: off_ini
582    INTEGER, DIMENSION(8)                :: offset 
[987]583    INTEGER, DIMENSION(nbp_lon,nbp_lat)  :: correspond
584    INTEGER, DIMENSION(knon_glo)         :: ktindex_glo
585    INTEGER, DIMENSION(knon_glo,8)       :: neighbours_glo
586    REAL, DIMENSION(klon_glo)            :: pctsrf_glo
587    INTEGER                              :: ktindex(klon)
[802]588!
589! End definition
590!****************************************************************************************
591
[987]592    ktindex(1:knon)=knindex(1:knon)+(klon_mpi_begin-1)+(klon_omp_begin-1)+nbp_lon-1
[781]593   
[987]594    CALL gather_surf(ktindex(1:knon),ktindex_glo)
595    CALL gather(pctsrf,pctsrf_glo)
[781]596   
[987]597    IF (is_mpi_root .AND. is_omp_root) THEN
598      neighbours_glo(:,:)=-1
[781]599!  Initialisation des offset   
600!
601! offset bord ouest
[987]602       off_ini(1,1) = - nbp_lon   ; off_ini(2,1) = - nbp_lon + 1     ; off_ini(3,1) = 1
603       off_ini(4,1) = nbp_lon + 1 ; off_ini(5,1) = nbp_lon           ; off_ini(6,1) = 2 * nbp_lon - 1
604       off_ini(7,1) = nbp_lon -1  ; off_ini(8,1) = - 1
[781]605! offset point normal
[987]606       off_ini(1,2) = - nbp_lon   ; off_ini(2,2) = - nbp_lon + 1     ; off_ini(3,2) = 1
607       off_ini(4,2) = nbp_lon + 1 ; off_ini(5,2) = nbp_lon           ; off_ini(6,2) = nbp_lon - 1
608       off_ini(7,2) = -1          ; off_ini(8,2) = - nbp_lon - 1
[781]609! offset bord   est
[987]610       off_ini(1,3) = - nbp_lon   ; off_ini(2,3) = - 2 * nbp_lon + 1 ; off_ini(3,3) = - nbp_lon + 1
611       off_ini(4,3) =  1          ; off_ini(5,3) = nbp_lon           ; off_ini(6,3) = nbp_lon - 1
612       off_ini(7,3) = -1          ; off_ini(8,3) = - nbp_lon - 1
[781]613!
614!
615! Attention aux poles
616!
[987]617       DO igrid = 1, knon_glo
618          index = ktindex_glo(igrid)
619          jj = INT((index - 1)/nbp_lon) + 1
620          ij = index - (jj - 1) * nbp_lon
[781]621          correspond(ij,jj) = igrid
622       ENDDO
[2126]623!sonia : Les mailles des voisines doivent etre toutes egales (pour couplage orchidee)
624       IF (knon_glo == 1) THEN
625         igrid = 1
626         DO i = 1,8
627           neighbours_glo(igrid, i) = igrid
628         ENDDO
629       ELSE
630       print*,'sonia : knon_glo,ij,jj', knon_glo, ij,jj
[781]631       
[987]632       DO igrid = 1, knon_glo
633          iglob = ktindex_glo(igrid)
634         
635          IF (MOD(iglob, nbp_lon) == 1) THEN
[781]636             offset = off_ini(:,1)
[987]637          ELSE IF(MOD(iglob, nbp_lon) == 0) THEN
[781]638             offset = off_ini(:,3)
639          ELSE
640             offset = off_ini(:,2)
641          ENDIF
[987]642         
[781]643          DO i = 1, 8
644             index = iglob + offset(i)
[987]645             ireal = (MIN(MAX(1, index - nbp_lon + 1), klon_glo))
646             IF (pctsrf_glo(ireal) > EPSFRA) THEN
647                jj = INT((index - 1)/nbp_lon) + 1
648                ij = index - (jj - 1) * nbp_lon
649                neighbours_glo(igrid, i) = correspond(ij, jj)
[781]650             ENDIF
651          ENDDO
652       ENDDO
[2126]653       ENDIF !fin knon_glo == 1
[781]654
655    ENDIF
656   
[987]657    DO i = 1, 8
658      CALL scatter_surf(neighbours_glo(:,i),neighbours(1:knon,i))
[781]659    ENDDO
660  END SUBROUTINE Init_neighbours
[987]661
[781]662!
663!****************************************************************************************
664!
[1146]665#endif
[781]666END MODULE surf_land_orchidee_mod
Note: See TracBrowser for help on using the repository browser.