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

Last change on this file since 2912 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
Line 
1!
2MODULE surf_land_orchidee_mod
3#ifndef ORCHIDEE_NOOPENMP
4#ifndef ORCHIDEE_NOZ0H
5!
6! This module controles the interface towards the model ORCHIDEE.
7!
8! Compatibility with ORCHIDIEE :
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.
11!
12! Subroutines in this module : surf_land_orchidee
13!                              Init_orchidee_index
14!                              Get_orchidee_communicator
15!                              Init_neighbours
16
17  USE dimphy
18#ifdef CPP_VEGET
19  USE intersurf     ! module d'ORCHIDEE
20#endif
21  USE cpl_mod,      ONLY : cpl_send_land_fields
22  USE surface_data, ONLY : type_ocean
23  USE geometry_mod, ONLY : dx, dy
24  USE mod_grid_phy_lmdz
25  USE mod_phys_lmdz_para, mpi_root_rank=>mpi_master
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, &
37       knindex, rlon, rlat, yrmu0, pctsrf, &
38       debut, lafin, &
39       plev,  u1_lay, v1_lay, gustiness, temp_air, spechum, epot_air, ccanopy, &
40       tq_cdrag, petAcoef, peqAcoef, petBcoef, peqBcoef, &
41       precip_rain, precip_snow, lwdown, swnet, swdown, &
42       ps, q2m, t2m, &
43       evap, fluxsens, fluxlat, &             
44       tsol_rad, tsurf_new, alb1_new, alb2_new, &
45       emis_new, z0m_new, z0h_new, qsurf)
46
47    USE mod_surf_para
48    USE mod_synchro_omp
49    USE carbon_cycle_mod, ONLY : carbon_cycle_cpl
50    USE indice_sol_mod
51    USE print_control_mod, ONLY: lunout
52    USE mod_grid_phy_lmdz, ONLY: nbp_lon, nbp_lat
53#ifdef CPP_VEGET
54    USE time_phylmdz_mod, ONLY: itau_phy
55#endif
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
80!   ccanopy      concentration CO2 canopee, correspond au co2_send de
81!                carbon_cycle_mod ou valeur constant co2_ppm
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
102!   alb1_new     albedo in visible SW interval
103!   alb2_new     albedo in near IR interval
104!   emis_new     emissivite
105!   z0m_new      surface roughness for momentum
106!   z0h_new      surface roughness for heat
107!   qsurf        air moisture at surface
108!
109    INCLUDE "YOMCST.h"
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
122    REAL, DIMENSION(klon), INTENT(IN)         :: yrmu0 ! cosine of solar zenith angle
123    REAL, DIMENSION(klon), INTENT(IN)         :: plev
124    REAL, DIMENSION(klon), INTENT(IN)         :: u1_lay, v1_lay, gustiness
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
132    REAL, DIMENSION(klon), INTENT(IN)         :: q2m, t2m
133
134! Parametres de sortie
135!****************************************************************************************
136    REAL, DIMENSION(klon), INTENT(OUT)        :: evap, fluxsens, fluxlat, qsurf
137    REAL, DIMENSION(klon), INTENT(OUT)        :: tsol_rad, tsurf_new
138    REAL, DIMENSION(klon), INTENT(OUT)        :: alb1_new, alb2_new
139    REAL, DIMENSION(klon), INTENT(OUT)        :: emis_new, z0m_new, z0h_new
140
141! Local
142!****************************************************************************************
143    INTEGER                                   :: ij, jj, igrid, ireal, index
144    INTEGER                                   :: error
145    REAL, DIMENSION(klon)                     :: swdown_vrai
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)
204   
205    INTEGER :: orch_omp_rank
206    INTEGER :: orch_omp_size
207!
208! Fin definition
209!****************************************************************************************
210
211    IF (check) WRITE(lunout,*)'Entree ', modname
212 
213! Initialisation
214 
215    IF (debut) THEN
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.'
219       CALL abort_physic(modname,abort_message,1)
220#endif
221
222       CALL Init_surf_para(knon)
223       ALLOCATE(ktindex(knon))
224       IF ( .NOT. ALLOCATED(albedo_keep)) THEN
225!ym          ALLOCATE(albedo_keep(klon))
226!ym bizarre que non alloué en knon precedement
227          ALLOCATE(albedo_keep(knon))
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
239          IF ( indi > nbp_lon) THEN
240             indi = 1
241             indj = indj + 1
242          ENDIF
243          ig(igrid) = indi
244          jg(igrid) = indj
245       ENDDO
246       ig(klon) = 1
247       jg(klon) = nbp_lat
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'
253             CALL abort_physic(modname,abort_message,1)
254          ENDIF
255       ENDIF
256       IF ((.NOT. ALLOCATED(lon_scat))) THEN
257          ALLOCATE(lon_scat(nbp_lon,nbp_lat), stat = error)
258          IF (error /= 0) THEN
259             abort_message='Pb allocation lon_scat'
260             CALL abort_physic(modname,abort_message,1)
261          ENDIF
262       ENDIF
263       IF ((.NOT. ALLOCATED(lat_scat))) THEN
264          ALLOCATE(lat_scat(nbp_lon,nbp_lat), stat = error)
265          IF (error /= 0) THEN
266             abort_message='Pb allocation lat_scat'
267             CALL abort_physic(modname,abort_message,1)
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
285          DO jj = 2, nbp_lat-1
286             DO ij = 1, nbp_lon
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)
294          lon_scat(:,nbp_lat) = lon_scat(:,2)
295          lat_scat(:,nbp_lat) = rlat_g(klon_glo)
296       ENDIF
297   
298       CALL bcast(lon_scat)
299       CALL bcast(lat_scat)
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'
307             CALL abort_physic(modname,abort_message,1)
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'
315             CALL abort_physic(modname,abort_message,1)
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'
333             CALL abort_physic(modname,abort_message,1)
334          ENDIF
335       ENDIF
336       DO igrid = 1, knon
337          ij = knindex(igrid)
338          resolution(igrid,1) = dx(ij)
339          resolution(igrid,2) = dy(ij)
340       ENDDO
341     
342       ALLOCATE(coastalflow(klon), stat = error)
343       IF (error /= 0) THEN
344          abort_message='Pb allocation coastalflow'
345          CALL abort_physic(modname,abort_message,1)
346       ENDIF
347       
348       ALLOCATE(riverflow(klon), stat = error)
349       IF (error /= 0) THEN
350          abort_message='Pb allocation riverflow'
351          CALL abort_physic(modname,abort_message,1)
352       ENDIF
353!
354! carbon_cycle_cpl not possible with this interface and version of ORHCHIDEE
355!
356       IF (carbon_cycle_cpl) THEN
357          abort_message='carbon_cycle_cpl not yet possible with this interface of ORCHIDEE'
358          CALL abort_physic(modname,abort_message,1)
359       END IF
360       
361    ENDIF                          ! (fin debut)
362 
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
369     
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)
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)
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
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       
395       IF (knon > 0) THEN
396#ifdef CPP_VEGET
397         CALL Init_intersurf(nbp_lon,nbp_lat,knon,ktindex,offset,orch_omp_size,orch_omp_rank,orch_comm)
398#endif
399       ENDIF
400
401       
402       IF (knon > 0) THEN
403
404#ifdef CPP_VEGET
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, &
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, &
411               tsol_rad, tsurf_new, qsurf, albedo_out, emis_new, z0m_new, &
412               lon_scat, lat_scat, q2m, t2m, z0h_new)
413#endif         
414       ENDIF
415
416       CALL Synchro_omp
417
418       albedo_keep(1:knon) = (albedo_out(1:knon,1)+albedo_out(1:knon,2))/2.
419
420    ENDIF
421
422   
423!  swdown_vrai(1:knon) = swnet(1:knon)/(1. - albedo_keep(1:knon))
424    swdown_vrai(1:knon) = swdown(1:knon)
425
426    IF (knon > 0) THEN
427#ifdef CPP_VEGET   
428       CALL intersurf_main_gathered (itime+itau_phy, nbp_lon, nbp_lat, knon, ktindex, dtime,  &
429            lrestart_read, lrestart_write, lalo, &
430            contfrac, neighbours, resolution, date0, &
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), &
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))
437#endif       
438    ENDIF
439
440    CALL Synchro_omp
441   
442    albedo_keep(1:knon) = (albedo_out(1:knon,1)+albedo_out(1:knon,2))/2.
443
444!* Send to coupler
445!
446    IF (type_ocean=='couple') THEN
447       CALL cpl_send_land_fields(itime, knon, knindex, &
448            riverflow, coastalflow)
449    ENDIF
450
451    alb1_new(1:knon) = albedo_out(1:knon,1)
452    alb2_new(1:knon) = albedo_out(1:knon,2)
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   
462    IF (debut) CALL Finalize_surf_para
463
464   
465  END SUBROUTINE surf_land_orchidee
466!
467!****************************************************************************************
468!
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)
477   
478    INTEGER               :: ktindex_glo(knon_glo)
479    INTEGER               :: offset_para(0:omp_size*mpi_size-1)
480    INTEGER               :: LastPoint
481    INTEGER               :: task
482   
483    ktindex(1:knon)=knindex(1:knon)+(klon_mpi_begin-1)+(klon_omp_begin-1)+nbp_lon-1
484   
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
495    ENDIF
496   
497    CALL bcast(offset_para)
498   
499    offset=offset_para(omp_size*mpi_rank+omp_rank)
500   
501    ktindex(1:knon)=ktindex(1:knon)-offset
502
503  END SUBROUTINE Init_orchidee_index
504
505!
506!************************* ***************************************************************
507!
508
509  SUBROUTINE Get_orchidee_communicator(orch_comm,orch_omp_size,orch_omp_rank)
510  USE  mod_surf_para
511     
512#ifdef CPP_MPI
513    INCLUDE 'mpif.h'
514#endif   
515
516    INTEGER,INTENT(OUT) :: orch_comm
517    INTEGER,INTENT(OUT) :: orch_omp_size
518    INTEGER,INTENT(OUT) :: orch_omp_rank
519    INTEGER             :: color
520    INTEGER             :: i,ierr
521!
522! End definition
523!****************************************************************************************
524   
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   
534#ifdef CPP_MPI   
535      CALL MPI_COMM_SPLIT(COMM_LMDZ_PHY,color,mpi_rank,orch_comm,ierr)
536#endif
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
550   
551   
552  END SUBROUTINE Get_orchidee_communicator
553!
554!****************************************************************************************
555
556
557  SUBROUTINE Init_neighbours(knon,neighbours,knindex,pctsrf)
558    USE mod_grid_phy_lmdz
559    USE mod_surf_para   
560    USE indice_sol_mod
561
562#ifdef CPP_MPI
563    INCLUDE 'mpif.h'
564#endif   
565
566! Input arguments
567!****************************************************************************************
568    INTEGER, INTENT(IN)                     :: knon
569    INTEGER, DIMENSION(klon), INTENT(IN)    :: knindex
570    REAL, DIMENSION(klon), INTENT(IN)       :: pctsrf
571   
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 
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)
587!
588! End definition
589!****************************************************************************************
590
591    ktindex(1:knon)=knindex(1:knon)+(klon_mpi_begin-1)+(klon_omp_begin-1)+nbp_lon-1
592   
593    CALL gather_surf(ktindex(1:knon),ktindex_glo)
594    CALL gather(pctsrf,pctsrf_glo)
595   
596    IF (is_mpi_root .AND. is_omp_root) THEN
597      neighbours_glo(:,:)=-1
598!  Initialisation des offset   
599!
600! offset bord ouest
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
604! offset point normal
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
608! offset bord   est
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
612!
613!
614! Attention aux poles
615!
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
620          correspond(ij,jj) = igrid
621       ENDDO
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
630       
631       DO igrid = 1, knon_glo
632          iglob = ktindex_glo(igrid)
633         
634          IF (MOD(iglob, nbp_lon) == 1) THEN
635             offset = off_ini(:,1)
636          ELSE IF(MOD(iglob, nbp_lon) == 0) THEN
637             offset = off_ini(:,3)
638          ELSE
639             offset = off_ini(:,2)
640          ENDIF
641         
642          DO i = 1, 8
643             index = iglob + offset(i)
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)
649             ENDIF
650          ENDDO
651       ENDDO
652       ENDIF !fin knon_glo == 1
653
654    ENDIF
655   
656    DO i = 1, 8
657      CALL scatter_surf(neighbours_glo(:,i),neighbours(1:knon,i))
658    ENDDO
659  END SUBROUTINE Init_neighbours
660
661!
662!****************************************************************************************
663!
664#endif
665#endif
666END MODULE surf_land_orchidee_mod
Note: See TracBrowser for help on using the repository browser.