tracer_icosa.F90 4.86 KB
Newer Older
1
MODULE tracer_icosa_mod
ymipsl's avatar
ymipsl committed
2

3
#ifndef NO_TRACER_PARSER
4
  USE trac_types_mod_ico
5
#endif
6 7


ymipsl's avatar
ymipsl committed
8 9
  INTEGER, PARAMETER   :: advect_none    = 0
  INTEGER, PARAMETER   :: advect_vanleer = 1
MEURDESOIF Yann's avatar
MEURDESOIF Yann committed
10 11
  
  TYPE t_tracer
12
    CHARACTER(LEN=256) :: name=""
MEURDESOIF Yann's avatar
MEURDESOIF Yann committed
13 14 15
    INTEGER            :: advection_scheme
    CHARACTER(LEN=256) :: advection_scheme_name=""
    REAL               :: default_init_value=0
ymeur's avatar
ymeur committed
16 17
    LOGICAL            :: has_default_init_value=.FALSE.
    LOGICAL            :: already_initialized=.FALSE.
MEURDESOIF Yann's avatar
MEURDESOIF Yann committed
18 19 20
  END TYPE t_tracer
  
  TYPE(t_tracer),ALLOCATABLE,SAVE :: tracers(:)
ymipsl's avatar
ymipsl committed
21 22 23 24 25
 
  INTERFACE set_advection_scheme
    MODULE PROCEDURE set_advection_scheme_1, set_advection_scheme_full
  END INTERFACE

26
#ifdef NO_TRACER_PARSER
27 28
  TYPE trac_type
  END type trac_type
29 30
#endif

31 32
  TYPE(trac_type), ALLOCATABLE, SAVE :: tracs(:)

ymipsl's avatar
ymipsl committed
33 34 35
CONTAINS

  SUBROUTINE init_tracer
36 37
    USE grid_param
#ifndef NO_TRACER_PARSER
38
    USE readTracFiles_mod_ico
39
    USE strings_mod_ico
40
#endif
41 42 43

    USE getin_mod,      ONLY : getin

44
    IMPLICIT NONE
45

MEURDESOIF Yann's avatar
MEURDESOIF Yann committed
46 47 48 49
    INTEGER                :: ftype
    INTEGER                :: iq     
    LOGICAL                :: ret
    CHARACTER(LEN=256)     :: scheme
50 51 52
    REAL                   :: default_init_value
    CHARACTER(LEN=10)      :: str_iq
    INTEGER                :: unknown_tracer
53
    LOGICAL                :: is_exist
54 55 56 57 58 59 60 61
    INTEGER                :: nb_tracs, nt
    CHARACTER(LEN=256),   SAVE :: type_trac                   !--- Keyword for tracers type(s)
!$OMP THREADPRIVATE(type_trac)
    CHARACTER(LEN=256),   SAVE, ALLOCATABLE :: types_trac(:)  !--- Keyword for tracers type(s), parsed version
!$OMP THREADPRIVATE(types_trac)
    


62
    
63 64
!$OMP BARRIER
!$OMP MASTER
MEURDESOIF Yann's avatar
MEURDESOIF Yann committed
65 66
    ALLOCATE(tracers(nqtot))
    
67 68 69 70
    nb_tracs=0

#ifndef NO_TRACER_PARSER

71 72 73 74
    type_trac="dynamico"
    CALL getin("type_trac",type_trac) 
    IF(strParse(type_trac, '|', types_trac, n=nt)) STOP 'problem to check type_trac'

75 76 77
    INQUIRE(file="tracer.def", exist=is_exist)
    
    IF (is_exist) THEN
78
      ret=readTracersFiles(type_trac, ftype, tracs)
79 80 81 82
      CALL getKey_init(tracs)
      nb_tracs=SIZE(tracs)
    ENDIF
    
83
    unknown_tracer=1    
MEURDESOIF Yann's avatar
MEURDESOIF Yann committed
84 85
    DO iq=1,nqtot

86
      IF (iq<=nb_tracs) THEN
87 88 89 90 91 92 93 94 95 96 97 98
        tracers(iq)%name=tracs(iq)%name
        IF(getKey("scheme",scheme,tracs(iq)%name)) scheme="vanleer"
        tracers(iq)%advection_scheme_name=scheme
        SELECT CASE (TRIM(scheme))
          CASE ("vanleer")
            tracers(iq)%advection_scheme=advect_vanleer
          CASE ("none")
            tracers(iq)%advection_scheme=advect_none
          CASE DEFAULT
           PRINT*,"unknow tracer advection scheme : ", TRIM(scheme), "=> ABORT"
           STOP
        END SELECT
ymeur's avatar
ymeur committed
99 100 101 102 103 104 105
        IF(getKey("default_init_value",default_init_value,tracs(iq)%name)) THEN
          tracers(iq)%has_default_init_value=.FALSE.
        ELSE
          tracers(iq)%default_init_value=default_init_value
          tracers(iq)%has_default_init_value=.TRUE.
        ENDIF
           
106 107 108 109 110 111
      ELSE
        WRITE( str_iq, '(I3.3)' )  unknown_tracer
        tracers(iq)%name="tracer"//TRIM(str_iq)
        tracers(iq)%advection_scheme=advect_vanleer
        tracers(iq)%advection_scheme_name="vanleer"
        tracers(iq)%default_init_value = 0
ymeur's avatar
ymeur committed
112
        tracers(iq)%already_initialized = .FALSE.
113 114
        unknown_tracer = unknown_tracer + 1
      ENDIF
MEURDESOIF Yann's avatar
MEURDESOIF Yann committed
115 116
    ENDDO

117 118
#endif

MEURDESOIF Yann's avatar
MEURDESOIF Yann committed
119
    CALL dump_tracers  
120 121
!$OMP END MASTER
!$OMP BARRIER
122 123 124


!$OMP MASTER
ymeur's avatar
ymeur committed
125
    CALL insert_tracer_output
126 127
!$OMP END MASTER

ymipsl's avatar
ymipsl committed
128 129
  END SUBROUTINE init_tracer

ymeur's avatar
ymeur committed
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
  SUBROUTINE insert_tracer_output
  USE xios_mod
   USE grid_param
  IMPLICIT NONE
    TYPE(xios_fieldgroup) :: fieldgroup_hdl
    TYPE(xios_field) :: field_hdl
    INTEGER :: iq
  
    CALL xios_get_handle("standard_output_tracers",fieldgroup_hdl)
    DO iq=1,nqtot
      CALL xios_add_child(fieldgroup_hdl, field_hdl, "tracer_"//TRIM(tracers(iq)%name))
      CALL xios_set_attr(field_hdl, name=TRIM(tracers(iq)%name))
    ENDDO

    CALL xios_get_handle("standard_output_tracers_init",fieldgroup_hdl)
    DO iq=1,nqtot
      CALL xios_add_child(fieldgroup_hdl, field_hdl, "tracer_"//TRIM(tracers(iq)%name)//"_init")
      CALL xios_set_attr(field_hdl, name=TRIM(tracers(iq)%name)//"_init")
    ENDDO
MEURDESOIF Yann's avatar
MEURDESOIF Yann committed
149

ymeur's avatar
ymeur committed
150
  END SUBROUTINE insert_tracer_output
MEURDESOIF Yann's avatar
MEURDESOIF Yann committed
151 152 153 154 155 156 157 158 159 160 161 162 163

  SUBROUTINE dump_tracers
  USE grid_param
    IMPLICIT NONE
    INTEGER ::iq
    
      DO iq=1,nqtot
        PRINT*, iq, " name=",tracers(iq)%name," advection_scheme=",TRIM(tracers(iq)%advection_scheme_name), " default_init_value=", tracers(iq)%default_init_value
      ENDDO
   END SUBROUTINE dump_tracers

    

ymipsl's avatar
ymipsl committed
164 165 166 167 168
  SUBROUTINE set_advection_scheme_1(nq,scheme)
  IMPLICIT NONE
    INTEGER, INTENT(IN) :: nq
    INTEGER, INTENT(IN) :: scheme
    
MEURDESOIF Yann's avatar
MEURDESOIF Yann committed
169
    tracers(nq)%advection_scheme=scheme
ymipsl's avatar
ymipsl committed
170 171 172 173 174 175 176 177
  
  END SUBROUTINE set_advection_scheme_1

  SUBROUTINE set_advection_scheme_full(schemes)
  USE grid_param
  IMPLICIT NONE
    INTEGER, INTENT(IN) :: schemes(nqtot)
  
MEURDESOIF Yann's avatar
MEURDESOIF Yann committed
178
    tracers(:)%advection_scheme=schemes(:)
ymipsl's avatar
ymipsl committed
179 180 181
  
  END SUBROUTINE set_advection_scheme_full

182
END MODULE tracer_icosa_mod