source: LMDZ6/trunk/libf/phylmd/surf_land_orchidee_nounstruct_mod.F90 @ 5274

Last change on this file since 5274 was 5274, checked in by abarral, 9 hours ago

Replace yomcst.h by existing module

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