Ignore:
Timestamp:
Jun 24, 2020, 2:13:23 PM (4 years ago)
Author:
dubos
Message:

simple_physics : cleanup

Location:
dynamico_lmdz/simple_physics
Files:
3 added
6 edited
1 moved

Legend:

Unmodified
Added
Removed
  • dynamico_lmdz/simple_physics/config/DYNAMICO/TEST/run.def

    r4245 r4246  
    4141diurnal=.TRUE.
    4242
     43planet_rad=6.37122e6
     44mugaz=28.97
     45
    4346#---------------- Run ---------------
    4447run_length=8640000
  • dynamico_lmdz/simple_physics/phyparam/Makefile

    r4236 r4246  
    1919        bash/extract_cython.sh
    2020        cd python ; rm -rf build *.c ; python setup.py build_ext --inplace
    21         cd python ; python -c 'import phyparam as phys ; phys.setup(100.); phys.alloc(30,100) ; phys.coldstart(30, 100.)'
    2221obj :
    2322        @rm -rf obj include lib xml tmp *~ */*~
  • dynamico_lmdz/simple_physics/phyparam/physics/iniphyparam_mod.F90

    r4245 r4246  
    1010CONTAINS
    1111
    12   SUBROUTINE read_params(ptimestep) BIND(C, name='phyparam_setup')
    13     !$cython header void phyparam_setup(double);
    14     !$cython wrapper def setup(timestep) : phy.phyparam_setup(timestep)
     12  SUBROUTINE read_params() BIND(C, name='phyparam_setup')
     13    !$cython header void phyparam_setup();
     14    !$cython wrapper def setup() : phy.phyparam_setup()
    1515    USE read_param_mod
    1616    USE phys_const, ONLY : planet_rad,g,r,cpp,rcp,dtphys,unjours,mugaz
     
    1818    USE planet, ONLY : coefir, coefvis
    1919    USE turbulence, ONLY : lmixmin, emin_turb
    20     USE surface
     20    USE soil_mod
    2121    USE callkeys
    22     REAL, INTENT(IN), VALUE :: ptimestep
    2322
    2423    CALL read_param('planet_rad',6.4e6 ,planet_rad,'planet_rad')
     
    5958    CALL read_param('period_sort', 1., period_sort, 'period sorties en jour')
    6059
     60  END SUBROUTINE read_params
     61
     62  SUBROUTINE iniphyparam(ptimestep, punjours, prad, pg, pr, pcpp)
     63    USE comgeomfi, ONLY : nsoilmx
     64    USE soil_mod, ONLY : init_soil
     65    USE phys_const, ONLY : planet_rad,g,r,cpp,rcp,dtphys,unjours
     66    USE callkeys
     67    REAL, INTENT(IN)  :: ptimestep, punjours, prad, pg, pr, pcpp
     68
     69    CALL read_params
    6170    !   choice of the frequency of the computation of radiations
    6271    IF(diurnal) THEN
     
    6675    ENDIF
    6776    iradia=1
     77    dtphys=ptimestep
    6878
    69     dtphys=ptimestep
    70   END SUBROUTINE read_params
    71 
    72   SUBROUTINE iniphyparam(ptimestep, punjours, prad, pg, pr, pcpp)
    73     USE comgeomfi, ONLY : nsoilmx
    74     USE surface, ONLY : init_soil
    75     USE phys_const, ONLY : planet_rad,g,r,cpp,rcp,dtphys,unjours
    76     USE callkeys
    77     REAL, INTENT(IN)  :: ptimestep, punjours, prad, pg, pr, pcpp
    78 
    79     CALL read_params(ptimestep)
    80     CALL check_mismatch('unjours', punjours, unjours)
    81     CALL check_mismatch('rad', prad, planet_rad)
    82     CALL check_mismatch('g', pg, g)
    83     CALL check_mismatch('R', pr, r)
    84     CALL check_mismatch('cpp', pcpp, cpp)
     79    CALL check_mismatch('day lenght (s)', punjours, unjours)
     80    CALL check_mismatch('planetary radius (km)', prad/1000., planet_rad/1000.)
     81    CALL check_mismatch('gravity', pg, g)
     82    CALL check_mismatch('specific R', pr, r)
     83    CALL check_mismatch('specific heat capacity', pcpp, cpp)
    8584    LOG_WARN('iniphyparam')
    8685
  • dynamico_lmdz/simple_physics/phyparam/physics/phyparam_mod.F90

    r4245 r4246  
    2424       &            pdu,pdv,pdt,pdpsrf) BIND(C, name='phyparam_phyparam')
    2525    USE phys_const, ONLY : g, rcp, r, unjours
    26     USE surface, ONLY : soil_forward, soil_backward
    27     USE surface, ONLY : z0, inertie, emissiv, albedo  ! precomputed
    28     USE surface, ONLY : tsurf, tsoil ! state variables
    29 !    USE surface, ONLY : capcal, fluxgrd, zc, zd ! should be temporaries
     26    USE soil_mod, ONLY : soil_forward, soil_backward
     27    USE soil_mod, ONLY : z0, inertie, emissiv, albedo  ! precomputed
     28    USE soil_mod, ONLY : tsurf, tsoil ! state variables
    3029    USE turbulence, ONLY : vdif
    3130    USE convection, ONLY : convadj
     
    7776         &  zd(ngrid, nsoilmx),    &
    7877         &  fluxgrd(ngrid),        & ! heat flux from deep soil
    79          &  capcal(ngrid)          & ! effective heat capacity of soil
     78         &  capcal(ngrid),         & ! effective heat capacity of soil
    8079         &  zdufr(ngrid,nlayer),   & ! partial tendencies for zonal velocity,
    8180         &  zdvfr(ngrid,nlayer),   & !   meridional velocity,
     
    8483         &  zdtsrf(ngrid),         & ! total tendency of surface temperature
    8584         &  zflubid(ngrid),        & ! radiative + deep soil fluxes
    86          &  zpmer(ngrid),          & ! sea-level pressure
     85         &  zpmer(ngrid)            ! sea-level pressure
    8786    REAL zdum1(ngrid,nlayer)
    8887    REAL zdum2(ngrid,nlayer)
     
    118117       CALL alloc(ngrid, nlayer)
    119118       CALL precompute
    120        CALL coldstart(ngrid, ptimestep)
     119       CALL coldstart(ngrid)
    121120    ENDIF
    122121
     
    178177    IF (callsoil) THEN
    179178       CALL soil_forward(ngrid,nsoilmx, ptimestep, inertie, tsurf, tsoil, &
    180          &            zc, zd, capcal, fluxgrd)
    181 
    182 !       CALL soil_new(ngrid,nsoilmx,ptimestep,inertie, &
    183 !            tsurf, tsoil, capcal,fluxgrd)
    184 !       CALL soil(ngrid,nsoilmx,.false.,inertie, &
    185 !            &          ptimestep,tsurf,tsoil,capcal,fluxgrd)
     179            &            zc, zd, capcal, fluxgrd)
     180
     181       !       CALL soil_new(ngrid,nsoilmx,ptimestep,inertie, &
     182       !            tsurf, tsoil, capcal,fluxgrd)
     183       !       CALL soil(ngrid,nsoilmx,.false.,inertie, &
     184       !            &          ptimestep,tsurf,tsoil,capcal,fluxgrd)
    186185    ELSE
    187186       capcal(:)  = capcal_nosoil
    188187       fluxgrd(:) = 0.
    189     ENDIF
     188    END IF
    190189
    191190    IF(lverbose) THEN
     
    193192       WRITELOG(*,*) capcal(igout), fluxgrd(igout), tsurf(igout)
    194193       LOG_DBG('phyparam')
    195     ENDIF
     194    END IF
    196195
    197196    !-----------------------------------------------------------------------
     
    345344    !$cython wrapper def alloc(ngrid, nlayer) : phy.phyparam_alloc(ngrid, nlayer)
    346345    USE astronomy, ONLY : iniorbit
    347     USE surface
     346    USE soil_mod
    348347    INTEGER, INTENT(IN), VALUE :: ngrid, nlayer
    349348    ! allocate precomputed arrays
     
    353352    ALLOCATE(tsurf(ngrid))
    354353    ALLOCATE(tsoil(ngrid,nsoilmx))
    355     IF(.FALSE.) THEN ! arrays below are now local temporaries in phyparam
    356        ALLOCATE(capcal(ngrid),fluxgrd(ngrid))
    357        ALLOCATE(zc(ngrid,nsoilmx),zd(ngrid,nsoilmx))
    358     END IF
    359354    CALL iniorbit
    360355  END SUBROUTINE alloc
     
    364359    !$cython wrapper def precompute() : phy.phyparam_precompute()
    365360    ! precompute time-independent arrays
    366     USE surface
     361    USE soil_mod
    367362    rnatur(:)  = 1.
    368363    inertie(:) = (1.-rnatur(:))*I_mer+rnatur(:)*I_ter
     
    372367  END SUBROUTINE precompute
    373368
    374   SUBROUTINE coldstart(ngrid, ptimestep) BIND(C, name='phyparam_coldstart')
    375     !$cython header void phyparam_coldstart(int, double);
    376     !$cython wrapper def coldstart (ngrid, timestep): phy.phyparam_coldstart(ngrid, timestep)
     369  SUBROUTINE coldstart(ngrid) BIND(C, name='phyparam_coldstart')
     370    !$cython header void phyparam_coldstart(int);
     371    !$cython wrapper def coldstart (ngrid): phy.phyparam_coldstart(ngrid)
    377372    ! create internal state to start a run without a restart file
    378     USE surface
     373    USE soil_mod, ONLY : tsurf, tsoil
    379374    INTEGER, INTENT(IN), VALUE :: ngrid
    380     REAL, INTENT(IN),    VALUE :: ptimestep
    381375    tsurf(:)   = tsoil_init
    382376    tsoil(:,:) = tsoil_init
    383377    icount=0
    384     IF(callsoil) THEN
    385        IF(.FALSE.) THEN
    386           ! init_soil is now called by iniphyparam
    387           ! initializes zc, zd, capcal, fluxgrd
    388           CALL soil(ngrid,nsoilmx,.TRUE.,inertie, &
    389                &          ptimestep,tsurf,tsoil,capcal,fluxgrd)
    390        END IF
    391        IF(.FALSE.) THEN ! soil_forward is now called by phyparam
    392           CALL soil_forward(ngrid, nsoilmx, ptimestep, inertie, tsurf, tsoil, &
    393                &            zc, zd, capcal, fluxgrd)
    394        END IF
    395     ELSE
     378    IF(.NOT. callsoil) THEN
    396379       WRITELOG(*,*) 'WARNING!!! Thermal conduction in the soil turned off'
    397380       LOG_WARN('coldstart')
    398        capcal(:)  = capcal_nosoil
    399        fluxgrd(:) = 0.
    400381    ENDIF
    401382  END SUBROUTINE coldstart
  • dynamico_lmdz/simple_physics/phyparam/physics/radiative_mod.F90

    r4244 r4246  
    2121    USE astronomy,    ONLY : orbite, solarlong
    2222    USE solar,        ONLY : solang, zenang, mucorr
    23     USE surface,      ONLY : albedo, emissiv, tsurf
     23    USE soil_mod,     ONLY : albedo, emissiv, tsurf
    2424    USE radiative_sw, ONLY : sw
    2525    USE radiative_lw, ONLY : lw
  • dynamico_lmdz/simple_physics/phyparam/physics/soil_mod.F90

    r4245 r4246  
    1 MODULE surface
     1MODULE soil_mod
    22
    33#include "use_logging.h"
     
    2323  REAL, ALLOCATABLE :: tsurf(:), tsoil(:,:)
    2424  !$OMP THREADPRIVATE(tsurf, tsoil)
    25   ! variables below should be temporary arrays, not persistent
    26   REAL, ALLOCATABLE :: zc(:,:),zd(:,:), capcal(:), fluxgrd(:)
    27   !$OMP THREADPRIVATE(zc,zd, capcal, fluxgrd)
    2825
    29   PUBLIC :: init_soil, &
    30        soil, soil_new, soil_forward, soil_backward, &
    31        zc, zd, &
     26  PUBLIC :: init_soil, soil_forward, soil_backward, &
    3227       rnatur, albedo, emissiv, z0, inertie, &
    33        tsurf, tsoil, capcal, fluxgrd
     28       tsurf, tsoil
    3429
    3530CONTAINS
     
    8681  END SUBROUTINE init_soil
    8782
     83  !=======================================================================
     84  !
     85  !   Auteur:  Frederic Hourdin     30/01/92
     86  !   -------
     87  !
     88  !   objet:  computation of : the soil temperature evolution
     89  !   ------                   the surfacic heat capacity "Capcal"
     90  !                            the surface conduction flux pcapcal
     91  !
     92  !
     93  !   Method: implicit time integration
     94  !   -------
     95  !   Consecutive ground temperatures are related by:
     96  !           T(k+1) = C(k) + D(k)*T(k)  (1)
     97  !   the coefficients C and D are computed at the t-dt time-step.
     98  !   Routine structure:
     99  !   1)new temperatures are computed  using (1)
     100  !   2)C and D coefficients are computed from the new temperature
     101  !     profile for the t+dt time-step
     102  !   3)the coefficients A and B are computed where the diffusive
     103  !     fluxes at the t+dt time-step is given by
     104  !            Fdiff = A + B Ts(t+dt)
     105  !     or     Fdiff = F0 + Capcal (Ts(t+dt)-Ts(t))/dt
     106  !            with F0 = A + B (Ts(t))
     107  !                 Capcal = B*dt
     108  !
     109
    88110  PURE SUBROUTINE soil_backward(ngrid,nsoil, zc,zd, ptsrf,ptsoil)
    89111    INTEGER, INTENT(IN) :: ngrid, nsoil         ! number of columns, of soil layers
     
    97119    !  coefficient computed during the forward sweep
    98120    !  -----------------------------------------------
    99    
     121
    100122    !  surface temperature => temperature in first soil layer
    101123    DO ig=1,ngrid
     
    103125            &      (lambda*(1.-zd(ig,1))+1.)
    104126    ENDDO
    105    
     127
    106128    !   other temperatures
    107129    DO jk=1,nsoil-1
     
    129151    !   Computation of the Cgrd and Dgrd coefficients the backward sweep :
    130152    !   ---------------------------------------------------------------
    131    
     153
    132154    DO jk=1,nsoil
    133155       zdz2(jk)=dz2(jk)/ptimestep
    134156    ENDDO
    135    
     157
    136158    DO ig=1,ngrid
    137159       z1=zdz2(nsoil)+dz1(nsoil-1)
     
    139161       zd(ig,nsoil-1)=dz1(nsoil-1)/z1
    140162    ENDDO
    141    
     163
    142164    DO jk=nsoil-1,2,-1
    143165       DO ig=1,ngrid
     
    148170       ENDDO
    149171    ENDDO
    150    
     172
    151173    !-----------------------------------------------------------------------
    152174    !   computation of the surface diffusive flux from ground and
    153175    !   calorific capacity of the ground:
    154176    !   ---------------------------------
    155    
     177
    156178    DO ig=1,ngrid
    157179       pfluxgrd(ig)=ptherm_i(ig)*dz1(1)*                              &
     
    166188  END SUBROUTINE soil_forward
    167189
    168   SUBROUTINE soil_new(ngrid,nsoil,ptimestep,ptherm_i, ptsrf,ptsoil, pcapcal,pfluxgrd)
    169     INTEGER, INTENT(IN) :: ngrid, nsoil         ! number of columns, of soil layers
    170     REAL, INTENT(IN)    :: ptimestep,         & ! time step
    171          &                 ptherm_i(ngrid)      ! thermal inertia ??
    172     REAL, INTENT(INOUT) :: ptsrf(ngrid),      & ! surface temperature
    173          &                 ptsoil(ngrid,nsoil)  ! soil temperature
    174     REAL, INTENT(OUT)   :: pcapcal(ngrid),    & ! effective calorific capacity
    175          &                 pfluxgrd(ngrid)      ! conductive heat flux at the ground
    176     CALL soil_backward(ngrid,nsoil, zc,zd, ptsrf,ptsoil)
    177     CALL soil_forward(ngrid, nsoil, ptimestep, ptherm_i, ptsrf, ptsoil, &
    178             &            zc, zd, pcapcal, pfluxgrd)
    179   END SUBROUTINE soil_new
    180 
    181   SUBROUTINE soil(ngrid,nsoil,firstcall,ptherm_i,          &
    182        &          ptimestep,ptsrf,ptsoil,                  &
    183        &          pcapcal,pfluxgrd)
    184 
    185     !=======================================================================
    186     !
    187     !   Auteur:  Frederic Hourdin     30/01/92
    188     !   -------
    189     !
    190     !   objet:  computation of : the soil temperature evolution
    191     !   ------                   the surfacic heat capacity "Capcal"
    192     !                            the surface conduction flux pcapcal
    193     !
    194     !
    195     !   Method: implicit time integration
    196     !   -------
    197     !   Consecutive ground temperatures are related by:
    198     !           T(k+1) = C(k) + D(k)*T(k)  (1)
    199     !   the coefficients C and D are computed at the t-dt time-step.
    200     !   Routine structure:
    201     !   1)new temperatures are computed  using (1)
    202     !   2)C and D coefficients are computed from the new temperature
    203     !     profile for the t+dt time-step
    204     !   3)the coefficients A and B are computed where the diffusive
    205     !     fluxes at the t+dt time-step is given by
    206     !            Fdiff = A + B Ts(t+dt)
    207     !     or     Fdiff = F0 + Capcal (Ts(t+dt)-Ts(t))/dt
    208     !            with F0 = A + B (Ts(t))
    209     !                 Capcal = B*dt
    210     !
    211     !   Interface:
    212     !   ----------
    213     !
    214     !   Arguments:
    215     !   ----------
    216     !   ngrid               number of grid-points
    217     !   ptimestep              physical timestep (s)
    218     !   pto(ngrid,nsoil)     temperature at time-step t (K)
    219     !   ptn(ngrid,nsoil)     temperature at time step t+dt (K)
    220     !   pcapcal(ngrid)      specific heat (W*m-2*s*K-1)
    221     !   pfluxgrd(ngrid)      surface diffusive flux from ground (Wm-2)
    222     !
    223     !=======================================================================
    224     !   declarations:
    225     !   -------------
    226 
    227 
    228     !-----------------------------------------------------------------------
    229     !  arguments
    230     !  ---------
    231 
    232     INTEGER ngrid,nsoil
    233     REAL ptimestep
    234     REAL ptsrf(ngrid),ptsoil(ngrid,nsoil),ptherm_i(ngrid)
    235     REAL pcapcal(ngrid),pfluxgrd(ngrid)
    236     LOGICAL firstcall
    237 
    238 
    239     !-----------------------------------------------------------------------
    240     !  local arrays
    241     !  ------------
    242 
    243     INTEGER ig,jk
    244     REAL zdz2(nsoil),z1(ngrid)
    245 
    246     IF (firstcall) THEN
    247        ! init_soil is now called by iniphyparam
    248        ! CALL init_soil(ngrid, nsoil)
    249     ELSE
    250        IF(.FALSE.) THEN
    251           !-----------------------------------------------------------------------
    252           !   Computation of the soil temperatures using the Cgrd and Dgrd
    253           !  coefficient computed at the previous time-step:
    254           !  -----------------------------------------------
    255          
    256           !    surface temperature
    257           DO ig=1,ngrid
    258              ptsoil(ig,1)=(lambda*zc(ig,1)+ptsrf(ig))/                   &
    259                   &      (lambda*(1.-zd(ig,1))+1.)
    260           ENDDO
    261          
    262           !   other temperatures
    263           DO jk=1,nsoil-1
    264              DO ig=1,ngrid
    265                 ptsoil(ig,jk+1)=zc(ig,jk)+zd(ig,jk)*ptsoil(ig,jk)
    266              ENDDO
    267           ENDDO
    268        ELSE
    269           CALL soil_backward(ngrid,nsoil, zc,zd, ptsrf,ptsoil)
    270        END IF
    271        
    272     ENDIF
    273 
    274     IF(.FALSE.) THEN
    275        !-----------------------------------------------------------------------
    276        !   Computation of the Cgrd and Dgrd coefficient for the next step:
    277        !   ---------------------------------------------------------------
    278        
    279        DO jk=1,nsoil
    280           zdz2(jk)=dz2(jk)/ptimestep
    281        ENDDO
    282        
    283        DO ig=1,ngrid
    284           z1(ig)=zdz2(nsoil)+dz1(nsoil-1)
    285           zc(ig,nsoil-1)=zdz2(nsoil)*ptsoil(ig,nsoil)/z1(ig)
    286           zd(ig,nsoil-1)=dz1(nsoil-1)/z1(ig)
    287        ENDDO
    288        
    289        DO jk=nsoil-1,2,-1
    290           DO ig=1,ngrid
    291              z1(ig)=1./(zdz2(jk)+dz1(jk-1)+dz1(jk)*(1.-zd(ig,jk)))
    292              zc(ig,jk-1)=                                                &
    293                   &      (ptsoil(ig,jk)*zdz2(jk)+dz1(jk)*zc(ig,jk))*z1(ig)
    294              zd(ig,jk-1)=dz1(jk-1)*z1(ig)
    295           ENDDO
    296        ENDDO
    297        
    298        !-----------------------------------------------------------------------
    299        !   computation of the surface diffusive flux from ground and
    300        !   calorific capacity of the ground:
    301        !   ---------------------------------
    302        
    303        DO ig=1,ngrid
    304           pfluxgrd(ig)=ptherm_i(ig)*dz1(1)*                              &
    305                &   (zc(ig,1)+(zd(ig,1)-1.)*ptsoil(ig,1))
    306           z1(ig)=lambda*(1.-zd(ig,1))+1.
    307           pcapcal(ig)=ptherm_i(ig)*                                      &
    308                &   ptimestep*(zdz2(1)+(1.-zd(ig,1))*dz1(1))/z1(ig)
    309           pfluxgrd(ig)=pfluxgrd(ig)                                      &
    310                &   +pcapcal(ig)*(ptsoil(ig,1)*z1(ig)-lambda*zc(ig,1)-ptsrf(ig))   &
    311                &   /ptimestep
    312        ENDDO
    313     ELSE
    314        CALL soil_forward(ngrid, nsoil, ptimestep, ptherm_i, ptsrf, ptsoil, &
    315             &            zc, zd, pcapcal, pfluxgrd)
    316     END IF
    317   END SUBROUTINE soil
    318      
    319    END MODULE surface
    320    
     190END MODULE soil_mod
  • dynamico_lmdz/simple_physics/phyparam/python/setup.py

    r4236 r4246  
    66       ext_modules = cythonize([ Extension("phyparam",["phyparam.pyx"],
    77                                           libraries=['phyparam'],
    8                                            library_dirs=['.'])] )
     8                                           library_dirs=['./lib'])] )
    99       )
Note: See TracChangeset for help on using the changeset viewer.