Skip to content

Commit 697bd7c

Browse files
committed
Adds column-to-column connections when using MOAB
1 parent 53c63ee commit 697bd7c

File tree

2 files changed

+141
-0
lines changed

2 files changed

+141
-0
lines changed
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
module ColumnConnectionSetType
2+
3+
4+
use shr_kind_mod , only : r8 => shr_kind_r8
5+
use shr_infnan_mod , only : isnan => shr_infnan_isnan, nan => shr_infnan_nan, assignment(=)
6+
use decompMod , only : bounds_type
7+
use abortutils , only : endrun
8+
use ColumnType , only : col_pp
9+
implicit none
10+
save
11+
public
12+
13+
type, public :: col_connection_set_type
14+
Integer :: nconn ! number of connections
15+
Integer, pointer :: col_id_up(:) => null() ! list of ids of upwind cells
16+
Integer, pointer :: col_id_dn(:) => null() ! list of ids of downwind cells
17+
Integer, pointer :: grid_id_up(:) => null() ! list of ids of upwind cells
18+
Integer, pointer :: grid_id_dn(:) => null() ! list of ids of downwind cells
19+
integer, pointer :: grid_id_up_norder(:) => null() ! list of ids of upwind cells in natural order
20+
integer, pointer :: grid_id_dn_norder(:) => null() ! list of ids of downwind cells in natural order
21+
integer, pointer :: col_up_forder(:) => null() ! the order in which the lateral flux should be added for upwind cells
22+
integer, pointer :: col_dn_forder(:) => null() ! the order in which the lateral flux should be added for downwind cells
23+
Real(r8), pointer :: dist(:) => null() ! list of distance vectors
24+
Real(r8), pointer :: face_length(:) => null() ! list of edge of faces normal to distance vectors
25+
Real(r8), pointer :: uparea(:) => null() ! list of up cell areas of horizaontal faces
26+
Real(r8), pointer :: downarea(:) => null() ! list of down cell areas of horizaontal faces
27+
Real(r8), pointer :: dzg(:) => null() ! list of areas of dz between downwind and upwind cells
28+
Real(r8), pointer :: facecos(:) => null() ! dot product of the cell face normal vector and cell centroid vector
29+
Real(r8), pointer :: vertcos(:) => null() ! dot product of the cell face normal vector and cell centroid vector for vertical flux, the rank for vertcos
30+
! is from 1 to column size which is different from rank of lateral faces
31+
contains
32+
#ifdef HAVE_MOAB
33+
procedure, public :: Init => InitViaMOAB
34+
#endif
35+
end type col_connection_set_type
36+
37+
type (col_connection_set_type), public, target :: c2c_connections ! connection type
38+
39+
contains
40+
41+
#ifdef HAVE_MOAB
42+
!------------------------------------------------------------------------
43+
subroutine InitViaMOAB(this, bounds_proc)
44+
!
45+
use MOABGridType, only : moab_edge_internal, moab_gcell
46+
use decompMod , only : bounds_type
47+
!
48+
implicit none
49+
!
50+
class (col_connection_set_type) :: this
51+
type(bounds_type), intent(in) :: bounds_proc ! bound information at processor level
52+
!
53+
integer :: g, g_up_moab, g_dn_moab, g_up_elm, g_dn_elm
54+
integer :: c, c_up, c_dn
55+
integer :: iconn, nconn
56+
integer, parameter :: nat_veg_col_itype = 1
57+
integer, pointer :: nat_col_id(:)
58+
59+
60+
! allocate memory and initialize
61+
allocate(nat_col_id(bounds_proc%begg_all:bounds_proc%endg_all))
62+
nat_col_id(:) = -1
63+
64+
! loop over columns to determine the naturally-vegetated column for each grid cell.
65+
do c = bounds_proc%begc_all, bounds_proc%endc_all
66+
if (col_pp%itype(c) == nat_veg_col_itype) then
67+
g = col_pp%gridcell(c)
68+
69+
if (nat_col_id(g) /= -1) then
70+
call endrun('ERROR: More than one naturally vegetated column found.')
71+
end if
72+
73+
nat_col_id(g) = c
74+
end if
75+
end do
76+
77+
! loop over grid level connections and determine number of column level connections
78+
nconn = 0
79+
do iconn = 1, moab_edge_internal%num
80+
g_up_moab = moab_edge_internal%cell_ids(iconn, 1)
81+
g_dn_moab = moab_edge_internal%cell_ids(iconn, 2)
82+
83+
g_up_elm = moab_gcell%moab2elm(g_up_moab)
84+
g_dn_elm = moab_gcell%moab2elm(g_dn_moab)
85+
86+
if (nat_col_id(g_up_elm) /= -1 .and. nat_col_id(g_dn_elm) /= -1) then
87+
nconn = nconn + 1
88+
end if
89+
end do
90+
91+
! allocate and initialize data structure
92+
this%nconn = nconn
93+
allocate(this%col_id_up(nconn)) ; this%col_id_up(:) = 0
94+
allocate(this%col_id_dn(nconn)) ; this%col_id_dn(:) = 0
95+
allocate(this%grid_id_up(nconn)) ; this%grid_id_up(:) = 0
96+
allocate(this%grid_id_dn(nconn)) ; this%grid_id_dn(:) = 0
97+
allocate(this%grid_id_up_norder(nconn)) ; this%grid_id_up_norder(:) = 0
98+
allocate(this%grid_id_dn_norder(nconn)) ; this%grid_id_dn_norder(:) = 0
99+
allocate(this%col_up_forder(nconn)) ; this%col_up_forder(:) = 0
100+
allocate(this%col_dn_forder(nconn)) ; this%col_dn_forder(:) = 0
101+
allocate(this%face_length(nconn)) ; this%face_length(:) = 0
102+
allocate(this%uparea(nconn)) ; this%uparea(:) = 0
103+
allocate(this%downarea(nconn)) ; this%downarea(:) = 0
104+
allocate(this%dist(nconn)) ; this%dist(:) = 0
105+
allocate(this%dzg(nconn)) ; this%dzg(:) = 0
106+
allocate(this%facecos(nconn)) ; this%facecos(:) = 0
107+
108+
nconn = 0
109+
do iconn = 1, moab_edge_internal%num
110+
g_up_moab = moab_edge_internal%cell_ids(iconn, 1)
111+
g_dn_moab = moab_edge_internal%cell_ids(iconn, 2)
112+
113+
g_up_elm = moab_gcell%moab2elm(g_up_moab)
114+
g_dn_elm = moab_gcell%moab2elm(g_dn_moab)
115+
116+
if (nat_col_id(g_up_elm) /= -1 .and. nat_col_id(g_dn_elm) /= -1) then
117+
nconn = nconn + 1
118+
119+
this%col_id_up(nconn) = nat_col_id(g_up_elm)
120+
this%col_id_dn(nconn) = nat_col_id(g_dn_elm)
121+
122+
this%grid_id_up(nconn) = g_up_elm
123+
this%grid_id_dn(nconn) = g_dn_elm
124+
125+
this%grid_id_up_norder(nconn) = moab_gcell%natural_id(g_up_moab)
126+
this%grid_id_dn_norder(nconn) = moab_gcell%natural_id(g_dn_moab)
127+
end if
128+
end do
129+
130+
! free up memory
131+
deallocate(nat_col_id)
132+
133+
end subroutine InitViaMOAB
134+
#endif
135+
136+
end module ColumnConnectionSetType
137+

components/elm/src/main/elm_initializeMod.F90

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ module elm_initializeMod
2424
use ELMFatesParamInterfaceMod, only: FatesReadPFTs
2525
use BeTRSimulationELM, only : create_betr_simulation_elm
2626
use SoilLittVertTranspMod, only : CreateLitterTransportList
27+
use ColumnConnectionSetType, only : c2c_connections
2728
use iso_c_binding
2829
!
2930
!-----------------------------------------
@@ -426,6 +427,9 @@ subroutine initialize1( )
426427

427428
call initGridCells()
428429
call initGhostGridCells()
430+
#ifdef HAVE_MOAB
431+
call c2c_connections%Init(bounds_proc)
432+
#endif
429433

430434
! Set global seg maps for gridcells, topounits, landlunits, columns and patches
431435
!if(max_topounits > 1) then

0 commit comments

Comments
 (0)