source: LMDZ5/branches/LMDZ_tree_FC/libf/phylmd/surf_land_orchidee_nofrein_mod.F90 @ 2939

Last change on this file since 2939 was 2939, checked in by jghattas, 7 years ago

Correction.

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