source: LMDZ6/trunk/libf/phylmd/surf_land_orchidee_nofrein_mod.F90 @ 3628

Last change on this file since 3628 was 3102, checked in by oboucher, 6 years ago

Removing x permission from these files

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