Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style(connections): apply fprettify formatting #960

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 16 additions & 15 deletions src/Model/Connection/CellWithNbrs.f90
Original file line number Diff line number Diff line change
Expand Up @@ -7,59 +7,60 @@ module CellWithNbrsModule
integer(I4B), parameter :: defaultCapacity = 6

!> Data structure to hold a global cell identifier,
!! using a pointer to the model and its local cell
!! using a pointer to the model and its local cell
!< index
type, public :: GlobalCellType
integer(I4B) :: index !< the index on the model grid
class(NumericalModelType), pointer :: model => null() !< the model
end type

! a global cell with neighbors
type, public :: CellWithNbrsType
type(GlobalCellType) :: cell
integer(I4B) :: nrOfNbrs = 0
type(CellWithNbrsType), dimension(:), pointer, contiguous :: neighbors => null()
type(CellWithNbrsType), dimension(:), pointer, &
contiguous :: neighbors => null()
contains
procedure :: addNbrCell
end type

contains
contains

subroutine addNbrCell(this, index, modelToAdd)
class(CellWithNbrsType) :: this
integer(I4B) :: index
class(NumericalModelType), pointer :: modelToAdd
! local
integer(I4B) :: nbrCnt, currentSize, i
type(CellWithNbrsType), dimension(:), pointer, contiguous :: newNeighbors
type(CellWithNbrsType), dimension(:), pointer, contiguous :: oldNeighbors
type(CellWithNbrsType), dimension(:), pointer, contiguous :: newNeighbors
type(CellWithNbrsType), dimension(:), pointer, contiguous :: oldNeighbors

if (.not. associated(this%neighbors)) then
allocate(this%neighbors(defaultCapacity))
allocate (this%neighbors(defaultCapacity))
this%nrOfNbrs = 0
end if

nbrCnt = this%nrOfNbrs
currentSize = size(this%neighbors)
if (nbrCnt + 1 > currentSize) then

! inflate
oldNeighbors => this%neighbors
allocate(newNeighbors(currentSize + defaultCapacity))
do i=1, currentSize
allocate (newNeighbors(currentSize + defaultCapacity))
do i = 1, currentSize
newNeighbors(i) = oldNeighbors(i)
end do
this%neighbors => newNeighbors

! clean up
deallocate(oldNeighbors)
nullify(oldNeighbors)
deallocate (oldNeighbors)
nullify (oldNeighbors)
end if

this%neighbors(nbrCnt + 1)%cell%index = index
this%neighbors(nbrCnt + 1)%cell%model => modelToAdd
this%nrOfNbrs = nbrCnt + 1

end subroutine addNbrCell

end module
end module
106 changes: 53 additions & 53 deletions src/Model/Connection/ConnectionBuilder.f90
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,31 @@ module ConnectionBuilderModule
use BaseSolutionModule, only: BaseSolutionType
use NumericalSolutionModule, only: NumericalSolutionType
use BaseExchangeModule, only: BaseExchangeType, GetBaseExchangeFromList
use DisConnExchangeModule, only: DisConnExchangeType, &
GetDisConnExchangeFromList
use DisConnExchangeModule, only: DisConnExchangeType, &
GetDisConnExchangeFromList
use NumericalModelModule, only: NumericalModelType
use SpatialModelConnectionModule, only: SpatialModelConnectionType, &
CastAsSpatialModelConnectionClass, &
GetSpatialModelConnectionFromList, &
AddSpatialModelConnectionToList
implicit none
CastAsSpatialModelConnectionClass, &
GetSpatialModelConnectionFromList, &
AddSpatialModelConnectionToList

implicit none
private

type, public :: ConnectionBuilderType
contains
procedure, pass(this) :: processSolution
procedure, private, pass(this) :: processExchanges
procedure, private, pass(this) :: setConnectionsToSolution
procedure, private, pass(this) :: assignExchangesToConnections
end type ConnectionBuilderType
contains
end type ConnectionBuilderType

contains

!> @brief Process the exchanges in the solution into model connections
!!
!! This routine processes all exchanges in a solution and,
!! when required, creates model connections of the proper
!! when required, creates model connections of the proper
!! type (GWF-GWF, GWT-GWT, ...) for a subset. It removes this
!! subset of exchanges from the solution and replaces them with the
!! created connections.
Expand All @@ -54,10 +54,10 @@ subroutine processSolution(this, solution)
call this%processExchanges(numSol%exchangelist, newConnections)
if (newConnections%Count() == 0) then
return
end if
end if

write(iout,'(1x,a,i0,a,a)') 'Created ', newConnections%Count(), &
' model connections for solution ', trim(solution%name)
write (iout, '(1x,a,i0,a,a)') 'Created ', newConnections%Count(), &
' model connections for solution ', trim(solution%name)

! set the global exchanges from this solution to
! the model connections
Expand All @@ -73,7 +73,7 @@ end subroutine processSolution

!> @brief Create connections from exchanges
!!
!! If the configuration demands it, this will create connections,
!! If the configuration demands it, this will create connections,
!! for the exchanges (one connection per exchange) add them to
!! the global list, and return them as @param newConnections
!<
Expand All @@ -96,10 +96,11 @@ subroutine processExchanges(this, exchanges, newConnections)
! Force use of the interface model
dev_always_ifmod = .false.
if (IDEVELOPMODE == 1) then
call get_environment_variable('DEV_ALWAYS_USE_IFMOD', value=envvar, status=status)
call get_environment_variable('DEV_ALWAYS_USE_IFMOD', &
value=envvar, status=status)
if (status == 0 .and. envvar == '1') then
dev_always_ifmod = .true.
write(*,'(a,/)') "### Experimental: forcing interface model ###"
write (*, '(a,/)') "### Experimental: forcing interface model ###"
end if
end if

Expand All @@ -109,17 +110,17 @@ subroutine processExchanges(this, exchanges, newConnections)
! if it is not DisConnExchangeType, we can skip it
continue
end if

! for now, if we have XT3D on the interface, we use a connection,
! (this will be more generic in the future)
if (conEx%use_interface_model() .or. conEx%dev_ifmod_on &
! (this will be more generic in the future)
if (conEx%use_interface_model() .or. conEx%dev_ifmod_on &
.or. dev_always_ifmod) then

! we should not get period connections here
isPeriodic = associated(conEx%model1, conEx%model2)
if (isPeriodic) then
write(*,*) 'Error (which should never happen): interface model '// &
'does not support periodic boundary condition'
write (*, *) 'Error (which should never happen): interface model '// &
'does not support periodic boundary condition'
call ustop()
end if

Expand All @@ -128,7 +129,7 @@ subroutine processExchanges(this, exchanges, newConnections)
call AddSpatialModelConnectionToList(baseconnectionlist, modelConnection)
call AddSpatialModelConnectionToList(newConnections, modelConnection)

! and for model 2, unless periodic
! and for model 2, unless periodic
modelConnection => createModelConnection(conEx%model2, conEx)
call AddSpatialModelConnectionToList(baseconnectionlist, modelConnection)
call AddSpatialModelConnectionToList(newConnections, modelConnection)
Expand All @@ -142,7 +143,7 @@ subroutine processExchanges(this, exchanges, newConnections)
exit
end if
end do

end if
end do

Expand All @@ -158,40 +159,40 @@ function createModelConnection(model, exchange) result(connection)
use GwfGwfConnectionModule, only: GwfGwfConnectionType
use GwtGwtConnectionModule, only: GwtGwtConnectionType
use GwfModule, only: GwfModelType
class(NumericalModelType), pointer , intent(in) :: model !< the model for which the connection will be created

class(NumericalModelType), pointer, intent(in) :: model !< the model for which the connection will be created
class(DisConnExchangeType), pointer, intent(in) :: exchange !< the type of connection
class(SpatialModelConnectionType), pointer :: connection !< the created connection

! different concrete connection types:
class(GwfGwfConnectionType), pointer :: flowConnection => null()
class(GwtGwtConnectionType), pointer :: transportConnection => null()

connection => null()

! select on type of connection to create
select case(exchange%typename)
case('GWF-GWF')
allocate(GwfGwfConnectionType :: flowConnection)
call flowConnection%construct(model, exchange)
connection => flowConnection
flowConnection => null()
case('GWT-GWT')
allocate(GwtGwtConnectionType :: transportConnection)
call transportConnection%construct(model, exchange)
connection => transportConnection
transportConnection => null()
case default
write(*,*) 'Error (which should never happen): undefined exchangetype found'
call ustop()
end select

select case (exchange%typename)
case ('GWF-GWF')
allocate (GwfGwfConnectionType :: flowConnection)
call flowConnection%construct(model, exchange)
connection => flowConnection
flowConnection => null()
case ('GWT-GWT')
allocate (GwtGwtConnectionType :: transportConnection)
call transportConnection%construct(model, exchange)
connection => transportConnection
transportConnection => null()
case default
write (*, *) 'Error (which should never happen): '// &
'undefined exchangetype found'
call ustop()
end select

end function createModelConnection



!> @brief Set connections to the solution
!!
!! This adds the connections to the solution and removes
!! This adds the connections to the solution and removes
!! those exchanges which are replaced by a connection
!<
subroutine setConnectionsToSolution(this, connections, solution)
Expand All @@ -211,7 +212,7 @@ subroutine setConnectionsToSolution(this, connections, solution)
! will this exchange be replaced by a connection?
keepExchange = .true.
do iconn = 1, connections%Count()
conn => GetSpatialModelConnectionFromList(connections,iconn)
conn => GetSpatialModelConnectionFromList(connections, iconn)
exPtr2 => conn%primaryExchange
if (associated(exPtr2, exPtr)) then
! if so, don't add it to the list
Expand Down Expand Up @@ -284,8 +285,7 @@ subroutine assignExchangesToConnections(this, exchanges, connections)

! clean
call keepList%Clear(destroy=.false.)

end subroutine assignExchangesToConnections



end module ConnectionBuilderModule
16 changes: 8 additions & 8 deletions src/Model/Connection/CsrUtils.f90
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ module CsrUtilsModule

implicit none
private

public :: getCSRIndex

contains

!> @brief Return index for element i,j in CSR storage,
!< returns -1 when not there
function getCSRIndex(i, j, ia, ja) result(csrIndex)
Expand All @@ -18,15 +18,15 @@ function getCSRIndex(i, j, ia, ja) result(csrIndex)
integer(I4B) :: csrIndex !< the CSR ndex of element i,j
! local
integer(I4B) :: idx

csrIndex = -1
do idx = ia(i), ia(i+1)-1
do idx = ia(i), ia(i + 1) - 1
if (ja(idx) == j) then
csrIndex = idx
return
end if
end do

end function

end module
end function

end module
Loading