CFMIP / COSPv2.0

COSP - The CFMIP (Cloud Feedbacks Model Intercomparison Project) Observation Simulator Package
41 stars 38 forks source link

hgt_matrix_half is used inconsistently #60

Closed brhillman closed 2 years ago

brhillman commented 3 years ago

The array cospstateIN%hgt_matrix_half appears to be used inconsistently in the interface code and in calls to simulators and cosp_change_vertical_grid. This array is allocated to have size (npoints,nlevels+1), which would imply that it should hold the heights of model level interfaces, but is used like this in calls to cosp_change_vertical_grid:

call cosp_change_vertical_grid(cloudsatIN%Npoints,1,cloudsatIN%Nlevels,  
                                                      cospgridIN%hgt_matrix(:,cloudsatIN%Nlevels:1:-1),            
                                                      cospgridIN%hgt_matrix_half(:,cloudsatIN%Nlevels:1:-1),
                                                      betamol_in, Nlvgrid,
                                                      vgrid_zl(Nlvgrid:1:-1),vgrid_zu(Nlvgrid:1:-1),            
                                                      betamolI(:,1,Nlvgrid:1:-1))

cosp_change_vertical_grid expects zlev_half to have shape (npoints,nlevels), and to hold the heights of the bottom of each level. But, if a model were to populate hgt_matrix_half with the full interface levels (from levels 1 to nlevels+1, from TOA to surface), then the slicing nlevels:1:-1 would be taking the first nlevels heights, which would be the heights of the interface tops, not bottoms. In E3SM, we appear to implement the hacky fix to populate levels (1,nlevels) of cospstateIN%hgt_matrix_half with the heights of the level bottoms, and then populate level nlevels+1 of hgt_matrix_half with a dummy value of 0. Is this expected behavior?

alejandrobodas commented 3 years ago

@brhillman thanks for reporting this, I think this is indeed a bug. I haven't had the time to look into this properly, but I think that level 1 of hgt_matrix_half is actually not needed. If that's the case, then we could dimension hgt_matrix_half with nlevels, dropping the TOA. If that's not the case (level 1 is indeed needed somewhere), then the slice in the calls to cosp_change_vertical_grid needs to be changed.