Skip to content

Commit

Permalink
Merge branch 'gbisht/update-connection-set' (MR !51)
Browse files Browse the repository at this point in the history
Number of active connections and IDs of those connections
within a connection set is saved. The source-sink condition
now iterates of num of active connection instead of total
number of connections.
  • Loading branch information
Gautam Bisht committed Jan 17, 2018
2 parents 789cfbe + f4a1be7 commit 38e0b04
Show file tree
Hide file tree
Showing 3 changed files with 145 additions and 40 deletions.
36 changes: 33 additions & 3 deletions src/mpp/dtypes/ConnectionSetType.F90
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,14 @@ module ConnectionSetType

type, public :: connection_set_type

PetscInt :: id ! identifier
PetscInt :: num_connections ! total num. of connections
type(connection_type) , pointer :: conn(:) ! information about all connections
PetscInt :: id ! identifier
PetscInt :: num_connections ! total num. of connections
PetscInt :: num_active_conn ! number of active connections
PetscInt , pointer :: active_conn_ids(:) ! IDs of active connection
type(connection_type) , pointer :: conn(:) ! information about all connections
type(connection_set_type), pointer :: next
contains
procedure, public :: SetActiveConnections => ConnSetSetActiveConnections

end type connection_set_type

Expand Down Expand Up @@ -417,6 +421,9 @@ function ConnectionSetNew(num_connections)

conn_set%id = 0
conn_set%num_connections = num_connections
conn_set%num_active_conn = 0

nullify(conn_set%active_conn_ids)

allocate(conn_set%conn(num_connections));
do iconn = 1, num_connections
Expand Down Expand Up @@ -522,6 +529,29 @@ subroutine ConnectionSetListClean(list)

end subroutine ConnectionSetListClean

!------------------------------------------------------------------------
subroutine ConnSetSetActiveConnections(this, num_active_conn, active_conn_ids)
!
! !DESCRIPTION:
! Release all allocated memory
!
implicit none
!
! !ARGUMENTS
class(connection_set_type) , intent(inout) :: this
PetscInt , intent(in) :: num_active_conn
PetscInt , pointer, intent(in) :: active_conn_ids(:)
!
! !LOCAL VARIABLES:
PetscInt :: iconn

this%num_active_conn = num_active_conn
allocate (this%active_conn_ids(num_active_conn))

this%active_conn_ids(1:num_active_conn) = active_conn_ids(1:num_active_conn)

end subroutine ConnSetSetActiveConnections

#endif

end module ConnectionSetType
64 changes: 63 additions & 1 deletion src/mpp/dtypes/MeshType.F90
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,8 @@ subroutine MeshCreateConnectionSet1(mesh, region_itype, conn_set, ncells_local,
PetscInt :: ncols
PetscInt :: offset
PetscBool :: use_centroid_in_dist_computation
PetscInt :: num_active_conn
PetscInt , pointer :: active_conn_ids(:)

ncols = mesh%ncells_local/mesh%nlev

Expand Down Expand Up @@ -552,6 +554,8 @@ subroutine MeshCreateConnectionSet1(mesh, region_itype, conn_set, ncells_local,

nconn = ncols
conn_set => ConnectionSetNew(nconn)
allocate(active_conn_ids(nconn))
num_active_conn = 0

iconn = 0
do c = 1, ncols
Expand All @@ -565,13 +569,23 @@ subroutine MeshCreateConnectionSet1(mesh, region_itype, conn_set, ncells_local,
id_up = -1
id_dn = mesh%nlev*c + offset

if (mesh%is_active(id_dn)) then
num_active_conn = num_active_conn + 1
active_conn_ids(num_active_conn) = iconn
end if

call conn_set%conn(iconn)%SetDistUnitVec(0.d0, 0.d0, -1.d0)

case (SOIL_BOTTOM_CELLS, SNOW_BOTTOM_CELLS)

id_up = -1
id_dn = mesh%nlev*(c-1) + 1 + offset

if (mesh%is_active(id_dn)) then
num_active_conn = num_active_conn + 1
active_conn_ids(num_active_conn) = iconn
end if

call conn_set%conn(iconn)%SetDistUnitVec(0.d0, 0.d0, 1.d0)
end select

Expand All @@ -581,12 +595,21 @@ subroutine MeshCreateConnectionSet1(mesh, region_itype, conn_set, ncells_local,
id_up = -1
id_dn = mesh%nlev*c + offset

if (mesh%is_active(id_dn)) then
num_active_conn = num_active_conn + 1
active_conn_ids(num_active_conn) = iconn
end if
call conn_set%conn(iconn)%SetDistUnitVec(0.d0, 0.d0, 1.d0)

case (SOIL_TOP_CELLS, SNOW_TOP_CELLS, SSW_TOP_CELLS)
id_up = -1
id_dn = mesh%nlev*(c-1) + 1 + offset

if (mesh%is_active(id_dn)) then
num_active_conn = num_active_conn + 1
active_conn_ids(num_active_conn) = iconn
end if

call conn_set%conn(iconn)%SetDistUnitVec(0.d0, 0.d0, -1.d0)
end select

Expand All @@ -607,10 +630,16 @@ subroutine MeshCreateConnectionSet1(mesh, region_itype, conn_set, ncells_local,
endif
enddo

call conn_set%SetActiveConnections(num_active_conn, active_conn_ids)

deallocate(active_conn_ids)

case (SOIL_CELLS, ALL_CELLS)

nconn = mesh%ncells_local
conn_set => ConnectionSetNew(nconn)
allocate(active_conn_ids(nconn))
num_active_conn = 0

iconn = 0
do c = 1,ncols
Expand All @@ -623,16 +652,25 @@ subroutine MeshCreateConnectionSet1(mesh, region_itype, conn_set, ncells_local,
call conn_set%conn(iconn)%SetIDUp(id_up)
call conn_set%conn(iconn)%SetIDDn(id_dn)

call conn_set%conn(iconn)%SetDistUnitVec(0.d0, 0.d0, 0.d0)
call conn_set%conn(iconn)%SetDistUnitVec(0.d0, 0.d0, 0.d0)

call conn_set%conn(iconn)%SetArea(mesh%area_xy(id_dn))

call conn_set%conn(iconn)%SetDistUp(0.0d0)
call conn_set%conn(iconn)%SetDistDn(0.0d0)

if (mesh%is_active(id_dn)) then
num_active_conn = num_active_conn + 1
active_conn_ids(num_active_conn) = iconn
end if

enddo
enddo

call conn_set%SetActiveConnections(num_active_conn, active_conn_ids)

deallocate(active_conn_ids)

case default

end select
Expand Down Expand Up @@ -674,11 +712,15 @@ subroutine MeshCreateConnectionSet2(this, nconn, id_up, id_dn, &
PetscReal :: dist_z
PetscReal :: dist
PetscBool :: check
PetscInt :: num_active_conn
PetscInt , pointer :: active_conn_ids(:)

check = PETSC_TRUE
if (present(skip_id_check)) check = .not.skip_id_check

conn_set => ConnectionSetNew(nconn)
allocate(active_conn_ids(nconn))
num_active_conn = 0

do iconn = 1, nconn

Expand All @@ -699,6 +741,22 @@ subroutine MeshCreateConnectionSet2(this, nconn, id_up, id_dn, &
call conn_set%conn(iconn)%SetDistUp(dist_up(iconn))
call conn_set%conn(iconn)%SetDistDn(dist_dn(iconn))

if (id_up(iconn) > 0 .and. id_dn(iconn) > 0) then
if (this%is_active(id_up(iconn)) .and. this%is_active(id_dn(iconn))) then
num_active_conn = num_active_conn + 1
active_conn_ids(num_active_conn) = iconn
end if
elseif (id_up(iconn) > 0) then
if (this%is_active(id_up(iconn))) then
num_active_conn = num_active_conn + 1
active_conn_ids(num_active_conn) = iconn
end if
else
if (this%is_active(id_dn(iconn))) then
num_active_conn = num_active_conn + 1
active_conn_ids(num_active_conn) = iconn
end if
end if
if (.not.present(unit_vec)) then
dist_x = this%x(id_dn(iconn)) - this%x(id_up(iconn))
dist_y = this%y(id_dn(iconn)) - this%y(id_up(iconn))
Expand All @@ -713,6 +771,10 @@ subroutine MeshCreateConnectionSet2(this, nconn, id_up, id_dn, &
call conn_set%conn(iconn)%SetType(itype(iconn))
end do

call conn_set%SetActiveConnections(num_active_conn, active_conn_ids)

deallocate(active_conn_ids)

end subroutine MeshCreateConnectionSet2

!------------------------------------------------------------------------
Expand Down
Loading

0 comments on commit 38e0b04

Please sign in to comment.