Changeset 685 for codes


Ignore:
Timestamp:
03/07/18 18:43:51 (6 years ago)
Author:
dubos
Message:

devel/unstructured : towards vertical remapping

Location:
codes/icosagcm/devel/Python/src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • codes/icosagcm/devel/Python/src/hexagonal/macros.jin

    r615 r685  
    4141#define FORALL_TRISK {% call(itrisk,edge_trisk) forall_trisk() %} 
    4242#define END_BLOCK {% endcall %} 
    43 #define SEQUENCE {% call(ext) sequence() %} 
    44 #define SEQUENCE_EXT {% call(ext) sequence_ext() %} 
    45 #define PROLOGUE(level) {% call at_level(level,ext) %} 
    46 #define BODY(range){% call body(range,ext) %} 
    47 #define EPILOGUE(level){% call at_level(level,ext) %} 
     43#define SEQUENCE_C0 {% call(body,at_level,ext) sequence() %} 
     44#define SEQUENCE_C1 {% call(body,at_level,ext) sequence_ext() %} 
     45#define SEQUENCE_E0 {% call(body,at_level,ext) sequence_edge() %} 
     46#define PROLOGUE(level) {% call(edge,neighbour) at_level(level,ext) %} 
     47#define BODY(range){% call(edge,neighbour) body(range,ext) %} 
     48#define EPILOGUE(level){% call(edge,neighbour) at_level(level,ext) %} 
    4849 
    4950#define CST_IF(condition, action) {{ cst_if(#condition, #action) }} 
     
    5859 
    5960{% macro sequence() -%} 
    60 {{ caller('') }} 
     61{{ caller(body_primal,at_level_primal,'') }} 
    6162{%- endmacro %} 
    6263 
    6364{% macro sequence_ext() -%} 
    64 {{ caller('_ext') }} 
    65 {%- endmacro %} 
    66  
    67 {% macro at_level(lev,ext) -%} 
     65{{ caller(body_primal,at_level_primal,'_ext') }} 
     66{%- endmacro %} 
     67 
     68{% macro at_level_primal(lev,ext) -%} 
    6869{{ define('LL', lev) }} 
    6970DO ij=ij_omp_begin{{ext}},ij_omp_end{{ext}} 
     
    7273{%- endmacro %} 
    7374 
    74 {% macro body(range,ext) -%} 
     75{% macro body_primal(range,ext) -%} 
    7576{{ define('LL', 'l') }} 
    7677DO l = {{ range }} 
    7778  DO ij=ij_omp_begin{{ext}},ij_omp_end{{ext}} 
    7879    {{ caller() }} 
     80  END DO 
     81END DO 
     82{%- endmacro %} 
     83 
     84{% macro sequence_edge() -%} 
     85{{ caller(body_edge,at_level_edge,'') }} 
     86{%- endmacro %} 
     87 
     88{% macro at_level_edge(lev,ext) -%} 
     89{{ define('LL', lev) }} 
     90DO ij=ij_omp_begin{{ext}},ij_omp_end{{ext}} 
     91      {{ caller('u_right','t_right') }} 
     92      {{ caller('u_lup','t_lup') }} 
     93      {{ caller('u_ldown','t_ldown') }} 
     94END DO 
     95{%- endmacro %} 
     96 
     97{% macro body_edge(range,ext) -%} 
     98{{ define('LL', 'l') }} 
     99DO l = {{ range }} 
     100   DO ij=ij_omp_begin{{ext}},ij_omp_end{{ext}} 
     101      {{ caller('u_right','t_right') }} 
     102      {{ caller('u_lup','t_lup') }} 
     103      {{ caller('u_ldown','t_ldown') }} 
    79104  END DO 
    80105END DO 
     
    272297#define HIDX(ij,l) ij 
    273298#define VIDX(ij,l) l 
    274 #endif 
     299#define AT_LEVEL(ij,l,lev) ij,lev 
     300#endif 
  • codes/icosagcm/devel/Python/src/kernels_caldyn_NH.jin

    r659 r685  
    11{% macro compute_p_and_Aik() %} 
    22{% set p_and_c2_from_theta=caller %} 
    3     SEQUENCE_EXT 
     3    SEQUENCE_C1 
    44      BODY('1,llm') 
    55          rho_ij = (g*m_ik(CELL))/(Phi_il(UP(CELL))-Phi_il(CELL)) 
     
    2020 
    2121  ! compute Phi_star 
    22   SEQUENCE_EXT 
     22  SEQUENCE_C1 
    2323    BODY('1,llm+1') 
    2424      Phi_star_il(CELL) = Phi_il(CELL) + tau*g2*(W_il(CELL)/m_il(CELL)-tau) 
     
    5050    ! Solve -A(l-1)x(l-1) + B(l)x(l) - A(l)x(l+1) = R(l) using Thomas algorithm 
    5151 
    52     SEQUENCE_EXT 
     52    SEQUENCE_C1 
    5353      ! Compute residual R_il and B_il 
    5454      PROLOGUE(1) 
  • codes/icosagcm/devel/Python/src/kernels_caldyn_hevi.jin

    r625 r685  
    11KERNEL(caldyn_wflux) 
    2   SEQUENCE 
     2  SEQUENCE_C0 
    33    BODY('llm-1,1,-1') 
    44      ! cumulate mass flux convergence from top to bottom 
     
    101101    ! so that the DOFs are the same whatever caldyn_eta 
    102102    ! in DYNAMICO mass_col is prognosed rather than rhodz 
    103     SEQUENCE_EXT 
     103    SEQUENCE_C1 
    104104      PROLOGUE(0) 
    105105        mass_col(HIDX(CELL))=0. 
  • codes/icosagcm/devel/Python/src/kernels_caldyn_hydro.jin

    r615 r685  
    77#define BALANCE(formula) {% call(thecell) balance() %} formula {% endcall %} 
    88{% macro balance() %} {% set formula=caller %} 
    9 SEQUENCE_EXT 
     9SEQUENCE_C1 
    1010  PROLOGUE(llm) 
    1111    pk(CELL) = ptop + .5*g*{{ formula('CELL') }} 
     
    2929#define GEOPOT(var) {% call geopot(var) %} 
    3030{% macro geopot(var) %} {% set formula=caller %} 
    31   SEQUENCE_EXT 
     31  SEQUENCE_C1 
    3232    BODY('1,llm') 
    3333      p_ik = pk(CELL) 
     
    4848    ! now pk contains the Lagrange multiplier (pressure) 
    4949    ! specific volume 1 = dphi/g/rhodz 
    50     SEQUENCE_EXT 
     50    SEQUENCE_C1 
    5151      BODY('1,llm') 
    5252        geopot(UP(CELL)) = geopot(CELL) + g*rhodz(CELL) 
  • codes/icosagcm/devel/Python/src/kernels_transport.jin

    r615 r685  
    158158  ! First diagnose geopotential and temperature, column-wise 
    159159  BARRIER 
    160   SEQUENCE_EXT 
     160  SEQUENCE_C1 
    161161    PROLOGUE(llm) 
    162162      pk(CELL) = ptop + .5*g*rhodz(CELL) 
     
    225225 
    226226END_BLOCK 
     227 
     228KERNEL(remap_eta) 
     229! IN  : rhodz, mass_dak, mass_dbk 
     230! TMP : mass_col, cur_lev, new_rhodz_cum 
     231! OUT : rhodz, old_rhodz, eta 
     232    SEQUENCE_C1 
     233      PROLOGUE('1') 
     234        rhodz_cum(CELL)=0. 
     235        cur_lev(HIDX(CELL))=1 
     236        eta(CELL)=0. 
     237        new_rhodz_cum(HIDX(CELL))=0. 
     238      END_BLOCK 
     239      BODY('1,llm') 
     240        rhodz_cum(UP(CELL)) = rhodz_cum(CELL) + rhodz(CELL) 
     241      END_BLOCK 
     242      EPILOGUE('llm+1') 
     243        mass_col(HIDX(CELL)) = rhodz_cum(CELL) 
     244      END_BLOCK 
     245 
     246      BODY('1,llm') 
     247        old_rhodz(CELL) = rhodz(CELL) 
     248        rhodz(CELL) = mass_dak(CELL) + mass_col(HIDX(CELL))*mass_dbk(CELL) 
     249        rhodz_cum_target = new_rhodz_cum(HIDX(CELL)) + rhodz(CELL) 
     250        DO level = cur_lev(HIDX(CELL)), llm 
     251           rhodz_cum_levp1 = rhodz_cum(AT_LEVEL(CELL,level+1)) 
     252           IF(rhodz_cum_target<=rhodz_cum_levp1) EXIT 
     253        END DO 
     254        rhodz_cum_lev = rhodz_cum(AT_LEVEL(CELL,level)) 
     255        ! now rhodz_cum_lev <= rhodz_cum_target <= rhodz_cum_levp1   
     256        cur_lev(HIDX(CELL)) = level 
     257        new_rhodz_cum(HIDX(CELL)) = rhodz_cum_target 
     258        eta(UP(CELL)) = level + (rhodz_cum_target-rhodz_cum_lev)/(rhodz_cum_levp1-rhodz_cum_lev) 
     259      END_BLOCK 
     260    END_BLOCK 
     261END_BLOCK 
     262 
     263KERNEL(remap_theta) 
     264! IN  : thetarhodz, eta 
     265! TMP : thetarhodz_cum, new_thetarhodz_cum 
     266! OUT : thetarhodz 
     267    SEQUENCE_C1 
     268      PROLOGUE('1') 
     269        thetarhodz_cum(CELL)=0. 
     270      END_BLOCK 
     271      BODY('1,llm') 
     272        thetarhodz_cum(UP(CELL)) = thetarhodz_cum(CELL) + thetarhodz(CELL) 
     273      END_BLOCK 
     274         
     275      BODY('1,llm+1') 
     276        X = eta(CELL) 
     277        level = FLOOR(X) 
     278        X = X-level 
     279        new_thetarhodz_cum(CELL) = thetarhodz_cum(AT_LEVEL(CELL,level))+X*thetarhodz(AT_LEVEL(CELL,level)) 
     280      END_BLOCK 
     281      BODY('1,llm') 
     282        thetarhodz(CELL)) = new_thetarhodz_cum(UP(CELL)) - new_thetarhodz_cum(CELL) 
     283      END_BLOCK 
     284    END_BLOCK 
     285END_BLOCK 
     286 
     287KERNEL(remap_u) 
     288! IN  : u, old_rhodz, rhodz, eta 
     289! TMP : urhodz_cum, new_urhodz_cum 
     290! OUT : u 
     291    SEQUENCE_E0 
     292      PROLOGUE('1') 
     293        urhodz_cum(EDGE)=0. 
     294      END_BLOCK 
     295      BODY('1,llm') 
     296        urhodz(EDGE) = u(EDGE)*(old_rhodz(CELL1)+old_rhodz(CELL2)) 
     297        urhodz_cum(UP(EDGE)) = urhodz_cum(EDGE) + urhodz(EDGE) 
     298      END_BLOCK 
     299         
     300      BODY('1,llm+1') 
     301        X = .5*(eta(CELL1)+eta(CELL2)) 
     302        level = FLOOR(X) 
     303        X = X-level 
     304        new_urhodz_cum(EDGE) = urhodz_cum(AT_LEVEL(EDGE,level))+X*urhodz(AT_LEVEL(EDGE,level)) 
     305      END_BLOCK 
     306      BODY('1,llm') 
     307        u(EDGE) = (new_urhodz_cum(UP(EDGE)) - new_urhodz_cum(EDGE)) / (rhodz(CELL1)+rhodz(CELL2)) 
     308      END_BLOCK 
     309    END_BLOCK 
     310END_BLOCK 
  • codes/icosagcm/devel/Python/src/unstructured/macros.jin

    r653 r685  
    2121#define FORALL_TRISK {% call forall_trisk(degree) %} 
    2222#define END_BLOCK {% endcall %} 
    23 #define SEQUENCE {% call sequence() %}  
    24 #define SEQUENCE_EXT {% call sequence() %}  
     23#define SEQUENCE_C0 {% call(body,at_level) sequence_primal() %}  
     24#define SEQUENCE_C1 {% call(body,at_level) sequence_primal() %}  
     25#define SEQUENCE_E0 {% call(body,at_level) sequence_edge() %}  
    2526#define PROLOGUE(level) {% call at_level(level) %} 
    2627#define EPILOGUE(level) {% call at_level(level) %} 
    27 #define BODY(range) {% call(cell_up,cell_down) body(range) %} 
     28#define BODY(range) {% call body(range) %} 
    2829 
    2930#define CST_IF(condition, action) {{ cst_if(#condition, #action) }} 
     
    5960{# ----------------------- SEQUENCE, FORALL ----------------------- #} 
    6061 
    61 {% macro sequence() -%} 
    62    
     62{% macro sequence_primal() -%} 
    6363!$OMP DO SCHEDULE(STATIC)                                                                             
    6464  DO ij=1,primal_num 
    65     {{ caller() }} 
     65    {{ caller(body_primal, at_level_primal) }} 
    6666  END DO 
    6767!$OMP END DO 
    68  
    69 {%- endmacro %} 
    70  
    71 {% macro body(range) -%} 
     68{%- endmacro %} 
     69 
     70{% macro sequence_edge() -%} 
     71{% set thecode = caller(body_edge, at_level_edge) %} 
     72!$OMP DO SCHEDULE(STATIC)                                                                             
     73  DO edge=1,edge_num 
     74{{ 'ij_left = left(edge)'   if 'CELL1'    in thecode }} 
     75{{ 'ij_right = right(edge)' if 'CELL2'   in thecode }} 
     76{{ 'ij_up = up(edge)'       if 'VERTEX1' in thecode }} 
     77{{ 'ij_down = down(edge)'   if 'VERTEX2' in thecode }} 
     78    {{ thecode }} 
     79  END DO 
     80!$OMP END DO 
     81{%- endmacro %} 
     82 
     83{% macro body_primal(range) -%} 
    7284  {{ define('CELL','l,ij') }} 
    7385    DO l = {{ range }} 
     
    7789{%- endmacro %} 
    7890 
    79 {% macro at_level(lev) -%} 
    80   {{ define('CELL','l,ij') }} 
    81   l={{ lev }} 
     91{% macro body_edge(range) -%} 
     92{% set thecode = caller() %} 
     93{{ define('EDGE', 'l,edge') }} 
     94{{ cdef(thecode, 'LE_DE', 'le_de(edge)') }} 
     95{{ cdef(thecode, 'SIGN', '1.') }} 
     96{{ cdef(thecode, 'CELL1', 'l,ij_left') }} 
     97{{ cdef(thecode, 'CELL2',  'l,ij_right') }} 
     98{{ cdef(thecode, 'VERTEX1', 'l,ij_down') }} 
     99{{ cdef(thecode, 'VERTEX2', 'l,ij_up') }} 
     100    DO l = {{ range }} 
     101      {{ thecode }} 
     102    END DO 
     103{{ cundef(thecode, ('EDGE','LE_DE','SIGN','CELL1','CELL2','VERTEX1','VERTEX2') ) }} 
     104{%- endmacro %} 
     105 
     106{% macro at_level_primal(lev) -%} 
     107  {{ define('CELL','%s,ij'%lev) }} 
    82108  {{ caller() }} 
    83109  {{ undef('CELL') }} 
     110{%- endmacro %} 
     111 
     112{% macro at_level_edge(lev) -%} 
     113  {{ define('EDGE','%s,edge'%lev) }} 
     114  {{ caller() }} 
     115  {{ undef('EDGE') }} 
    84116{%- endmacro %} 
    85117 
     
    365397 
    366398#ifdef PASS_POST2 
     399#define AT_LEVEL(l,ij,lev) lev,ij 
    367400#define KUP(l,ij) kup,ij 
    368401#define KDOWN(l,ij) kdown,ij 
Note: See TracChangeset for help on using the changeset viewer.