Skip to content

Commit

Permalink
refactor(GeomUtil): move get_ijk, get_jk, get_node from InputOutput (M…
Browse files Browse the repository at this point in the history
  • Loading branch information
wpbonelli authored Dec 7, 2023
1 parent ae9e0e1 commit 5b12e3d
Show file tree
Hide file tree
Showing 25 changed files with 179 additions and 186 deletions.
49 changes: 48 additions & 1 deletion autotest/TestGeomUtil.f90
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module TestGeomUtil
use KindModule, only: I4B, DP
use testdrive, only: check, error_type, new_unittest, test_failed, &
to_string, unittest_type
use GeomUtilModule, only: point_in_polygon
use GeomUtilModule, only: get_node, get_ijk, get_jk, point_in_polygon
use ConstantsModule, only: LINELENGTH
implicit none
private
Expand All @@ -14,6 +14,8 @@ module TestGeomUtil
subroutine collect_geomutil(testsuite)
type(unittest_type), allocatable, intent(out) :: testsuite(:)
testsuite = [ &
new_unittest("get_node_get_ijk", &
test_get_node_get_ijk), &
new_unittest("point_in_polygon_sq", &
test_point_in_polygon_sq), &
new_unittest("point_in_polygon_tri", &
Expand All @@ -25,6 +27,51 @@ end subroutine collect_geomutil

! 2D arrays for polygons and check points use column-major indexing

subroutine test_get_node_get_ijk(error)
type(error_type), allocatable, intent(out) :: error
integer :: ilay
integer :: irow
integer :: icol
integer :: nlay
integer :: nrow
integer :: ncol
integer :: nnum
integer :: ncls
integer :: k, i, j

! trivial grid with 1 cell
nnum = get_node(1, 1, 1, 1, 1, 1)
call get_ijk(nnum, 1, 1, 1, ilay, irow, icol)
call check(error, nnum == 1)
call check(error, ilay == 1)
call check(error, irow == 1)
call check(error, icol == 1)
if (allocated(error)) return

! small grid, 3x4x5
nlay = 3
nrow = 4
ncol = 5
ncls = nlay * nrow * ncol
do k = 1, nlay
do i = 1, nrow
do j = 1, ncol
! node number from ijk
nnum = get_node(k, i, j, nlay, nrow, ncol)
call check(error, nnum == (k - 1) * nrow * ncol + (i - 1) * ncol + j)
if (allocated(error)) return

! ijk from node number
call get_ijk(nnum, nrow, ncol, nlay, irow, icol, ilay)
call check(error, ilay == k)
call check(error, irow == i)
call check(error, icol == j)
if (allocated(error)) return
end do
end do
end do
end subroutine test_get_node_get_ijk

subroutine test_point_in_polygon(error, shape, &
poly, in_pts, out_pts, vert_pts, face_pts)
type(error_type), allocatable, intent(inout) :: error
Expand Down
51 changes: 2 additions & 49 deletions autotest/TestInputOutput.f90
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module TestInputOutput
use testdrive, only: error_type, unittest_type, new_unittest, check
use ConstantsModule, only: LINELENGTH
use InputOutputModule, only: get_node, get_ijk
! use InputOutputModule, only: ???
implicit none
private
public :: collect_inputoutput
Expand All @@ -10,54 +10,7 @@ module TestInputOutput

subroutine collect_inputoutput(testsuite)
type(unittest_type), allocatable, intent(out) :: testsuite(:)
testsuite = [ &
new_unittest("get_node_get_ijk", test_get_node_get_ijk) &
]
allocate (testsuite(0))
end subroutine collect_inputoutput

subroutine test_get_node_get_ijk(error)
type(error_type), allocatable, intent(out) :: error
integer :: ilay
integer :: irow
integer :: icol
integer :: nlay
integer :: nrow
integer :: ncol
integer :: nnum
integer :: ncls
integer :: k, i, j

! trivial grid with 1 cell
nnum = get_node(1, 1, 1, 1, 1, 1)
call get_ijk(nnum, 1, 1, 1, ilay, irow, icol)
call check(error, nnum == 1)
call check(error, ilay == 1)
call check(error, irow == 1)
call check(error, icol == 1)
if (allocated(error)) return

! small grid, 3x4x5
nlay = 3
nrow = 4
ncol = 5
ncls = nlay * nrow * ncol
do k = 1, nlay
do i = 1, nrow
do j = 1, ncol
! node number from ijk
nnum = get_node(k, i, j, nlay, nrow, ncol)
call check(error, nnum == (k - 1) * nrow * ncol + (i - 1) * ncol + j)
if (allocated(error)) return

! ijk from node number
call get_ijk(nnum, nrow, ncol, nlay, irow, icol, ilay)
call check(error, ilay == k)
call check(error, irow == i)
call check(error, icol == j)
if (allocated(error)) return
end do
end do
end do
end subroutine test_get_node_get_ijk

end module TestInputOutput
58 changes: 30 additions & 28 deletions make/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,33 @@ SOURCEDIR2=../src/Exchange
SOURCEDIR3=../src/Distributed
SOURCEDIR4=../src/Solution
SOURCEDIR5=../src/Solution/LinearMethods
SOURCEDIR6=../src/Solution/PETSc
SOURCEDIR7=../src/Timing
SOURCEDIR8=../src/Utilities
SOURCEDIR9=../src/Utilities/Idm
SOURCEDIR10=../src/Utilities/Idm/selector
SOURCEDIR11=../src/Utilities/Idm/mf6blockfile
SOURCEDIR12=../src/Utilities/TimeSeries
SOURCEDIR13=../src/Utilities/Memory
SOURCEDIR14=../src/Utilities/OutputControl
SOURCEDIR15=../src/Utilities/ArrayRead
SOURCEDIR16=../src/Utilities/Libraries
SOURCEDIR17=../src/Utilities/Libraries/rcm
SOURCEDIR18=../src/Utilities/Libraries/blas
SOURCEDIR19=../src/Utilities/Libraries/sparskit2
SOURCEDIR20=../src/Utilities/Libraries/daglib
SOURCEDIR21=../src/Utilities/Libraries/sparsekit
SOURCEDIR22=../src/Utilities/Vector
SOURCEDIR23=../src/Utilities/Matrix
SOURCEDIR24=../src/Utilities/Observation
SOURCEDIR25=../src/Model
SOURCEDIR26=../src/Model/Connection
SOURCEDIR27=../src/Model/GroundWaterTransport
SOURCEDIR28=../src/Model/ModelUtilities
SOURCEDIR29=../src/Model/GroundWaterFlow
SOURCEDIR30=../src/Model/TransportModel
SOURCEDIR31=../src/Model/Geometry
SOURCEDIR6=../src/Solution/ParticleTracker
SOURCEDIR7=../src/Solution/PETSc
SOURCEDIR8=../src/Timing
SOURCEDIR9=../src/Utilities
SOURCEDIR10=../src/Utilities/Idm
SOURCEDIR11=../src/Utilities/Idm/selector
SOURCEDIR12=../src/Utilities/Idm/mf6blockfile
SOURCEDIR13=../src/Utilities/TimeSeries
SOURCEDIR14=../src/Utilities/Memory
SOURCEDIR15=../src/Utilities/OutputControl
SOURCEDIR16=../src/Utilities/ArrayRead
SOURCEDIR17=../src/Utilities/Libraries
SOURCEDIR18=../src/Utilities/Libraries/rcm
SOURCEDIR19=../src/Utilities/Libraries/blas
SOURCEDIR20=../src/Utilities/Libraries/sparskit2
SOURCEDIR21=../src/Utilities/Libraries/daglib
SOURCEDIR22=../src/Utilities/Libraries/sparsekit
SOURCEDIR23=../src/Utilities/Vector
SOURCEDIR24=../src/Utilities/Matrix
SOURCEDIR25=../src/Utilities/Observation
SOURCEDIR26=../src/Model
SOURCEDIR27=../src/Model/Connection
SOURCEDIR28=../src/Model/GroundWaterTransport
SOURCEDIR29=../src/Model/ModelUtilities
SOURCEDIR30=../src/Model/GroundWaterFlow
SOURCEDIR31=../src/Model/TransportModel
SOURCEDIR32=../src/Model/Geometry

VPATH = \
${SOURCEDIR1} \
Expand Down Expand Up @@ -67,7 +68,8 @@ ${SOURCEDIR27} \
${SOURCEDIR28} \
${SOURCEDIR29} \
${SOURCEDIR30} \
${SOURCEDIR31}
${SOURCEDIR31} \
${SOURCEDIR32}

.SUFFIXES: .f90 .F90 .o

Expand Down Expand Up @@ -99,6 +101,7 @@ $(OBJDIR)/BlockParser.o \
$(OBJDIR)/MemoryManager.o \
$(OBJDIR)/TimeSeries.o \
$(OBJDIR)/ats.o \
$(OBJDIR)/GeomUtil.o \
$(OBJDIR)/TimeSeriesLink.o \
$(OBJDIR)/TimeSeriesFileList.o \
$(OBJDIR)/tdis.o \
Expand Down Expand Up @@ -326,7 +329,6 @@ $(OBJDIR)/sparsekit.o \
$(OBJDIR)/rcm.o \
$(OBJDIR)/blas1_d.o \
$(OBJDIR)/Iunit.o \
$(OBJDIR)/GeomUtil.o \
$(OBJDIR)/RectangularGeometry.o \
$(OBJDIR)/CircularGeometry.o

Expand Down
3 changes: 2 additions & 1 deletion src/Model/GroundWaterFlow/gwf3csub8.f90
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ module GwfCsubModule
use BlockParserModule, only: BlockParserType
use TimeSeriesLinkModule, only: TimeSeriesLinkType, &
GetTimeSeriesLinkFromList
use InputOutputModule, only: get_node, extract_idnum_or_bndname
use GeomUtilModule, only: get_node
use InputOutputModule, only: extract_idnum_or_bndname
use BaseDisModule, only: DisBaseType
use SimModule, only: count_errors, store_error, store_error_unit, &
store_warning
Expand Down
3 changes: 2 additions & 1 deletion src/Model/GroundWaterFlow/gwf3dis8.f90
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ module GwfDisModule
use ConstantsModule, only: LINELENGTH, DHALF, DONE, DZERO, &
LENMEMPATH, LENVARNAME
use BaseDisModule, only: DisBaseType
use InputOutputModule, only: get_node, get_ijk, URWORD, ulasav, ulaprufw, &
use GeomUtilModule, only: get_node, get_ijk
use InputOutputModule, only: URWORD, ulasav, ulaprufw, &
ubdsv1, ubdsv06, urword, getunit, openfile
use SimModule, only: count_errors, store_error, store_error_unit, &
store_error_filename
Expand Down
3 changes: 2 additions & 1 deletion src/Model/GroundWaterFlow/gwf3disv8.f90
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ module GwfDisvModule
use ConstantsModule, only: LINELENGTH, LENMEMPATH, LENVARNAME, &
DZERO, DONE, DHALF
use BaseDisModule, only: DisBaseType
use InputOutputModule, only: get_node, get_ijk, get_jk, URWORD, ulasav, &
use GeomUtilModule, only: get_node, get_ijk, get_jk
use InputOutputModule, only: URWORD, ulasav, &
ulaprufw, ubdsv1, ubdsv06, getunit, openfile
use SimModule, only: count_errors, store_error, store_error_unit, &
store_error_filename
Expand Down
2 changes: 1 addition & 1 deletion src/Model/GroundWaterFlow/gwf3evt8.f90
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module EvtModule
use BlockParserModule, only: BlockParserType
use CharacterStringModule, only: CharacterStringType
use MatrixBaseModule
use GeomUtilModule, only: get_node
!
implicit none
!
Expand Down Expand Up @@ -794,7 +795,6 @@ end subroutine evt_define_listlabel
!<
subroutine default_nodelist(this)
! -- modules
use InputOutputModule, only: get_node
use SimModule, only: store_error
use ConstantsModule, only: LINELENGTH
! -- dummy
Expand Down
3 changes: 2 additions & 1 deletion src/Model/GroundWaterFlow/gwf3lak8.f90
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ module LakModule
use TableModule, only: TableType, table_cr
use ObserveModule, only: ObserveType
use ObsModule, only: ObsType
use InputOutputModule, only: get_node, URWORD, extract_idnum_or_bndname
use GeomUtilModule, only: get_node
use InputOutputModule, only: URWORD, extract_idnum_or_bndname
use BaseDisModule, only: DisBaseType
use SimModule, only: count_errors, store_error, store_error_unit, &
deprecation_warning
Expand Down
3 changes: 2 additions & 1 deletion src/Model/GroundWaterFlow/gwf3maw8.f90
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ module MawModule
use TableModule, only: TableType, table_cr
use ObserveModule, only: ObserveType
use ObsModule, only: ObsType
use InputOutputModule, only: get_node, URWORD, extract_idnum_or_bndname, &
use GeomUtilModule, only: get_node
use InputOutputModule, only: URWORD, extract_idnum_or_bndname, &
GetUnit, openfile
use BaseDisModule, only: DisBaseType
use SimModule, only: count_errors, store_error, store_error_unit, &
Expand Down
3 changes: 1 addition & 2 deletions src/Model/GroundWaterFlow/gwf3rch8.f90
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module RchModule
use BlockParserModule, only: BlockParserType
use CharacterStringModule, only: CharacterStringType
use MatrixBaseModule
use GeomUtilModule, only: get_node
!
implicit none
!
Expand Down Expand Up @@ -472,8 +473,6 @@ end subroutine rch_define_listlabel
!! Equivalent to reading IRCH as CONSTANT 1
!<
subroutine default_nodelist(this)
! -- modules
use InputOutputModule, only: get_node
! -- dummy
class(RchType) :: this
! -- local
Expand Down
5 changes: 2 additions & 3 deletions src/Model/ModelUtilities/BoundaryPackageExt.f90
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module BndExtModule
use SimVariablesModule, only: errmsg
use SimModule, only: store_error, count_errors, store_error_filename
use BndModule, only: BndType
use GeomUtilModule, only: get_node, get_ijk

implicit none

Expand Down Expand Up @@ -466,7 +467,6 @@ end subroutine source_dimensions
subroutine nodelist_update(this)
! -- modules
use SimVariablesModule, only: errmsg
use InputOutputModule, only: get_node
! -- dummy
class(BndExtType) :: this !< BndExtType object
! -- local
Expand Down Expand Up @@ -530,7 +530,6 @@ end subroutine nodelist_update
subroutine check_cellid(this, ii, cellid, mshape, ndim)
! -- modules
use SimVariablesModule, only: errmsg
use InputOutputModule, only: get_node
! -- dummy
class(BndExtType) :: this !< BndExtType object
! -- local
Expand Down Expand Up @@ -596,7 +595,7 @@ subroutine write_list(this)
! -- modules
use ConstantsModule, only: LINELENGTH, LENBOUNDNAME, &
TABLEFT, TABCENTER, DZERO
use InputOutputModule, only: ulstlb, get_ijk
use InputOutputModule, only: ulstlb
use TableModule, only: TableType, table_cr
! -- dummy
class(BndExtType) :: this !< BndExtType object
Expand Down
4 changes: 1 addition & 3 deletions src/Model/ModelUtilities/Connections.f90
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module ConnectionsModule
use GenericUtilitiesModule, only: sim_message
use SimVariablesModule, only: errmsg
use BlockParserModule, only: BlockParserType
use GeomUtilModule, only: get_node

implicit none
private
Expand Down Expand Up @@ -513,7 +514,6 @@ subroutine disconnections(this, name_model, nodes, ncol, nrow, nlay, &
! -- modules
use ConstantsModule, only: DHALF, DZERO, DTHREE, DTWO, DPI
use SparseModule, only: sparsematrix
use InputOutputModule, only: get_node
! -- dummy
class(ConnectionsType) :: this
character(len=*), intent(in) :: name_model
Expand Down Expand Up @@ -762,7 +762,6 @@ subroutine disvconnections(this, name_model, nodes, ncpl, nlay, nrsize, &
! -- modules
use ConstantsModule, only: DHALF, DZERO, DTHREE, DTWO, DPI
use SparseModule, only: sparsematrix
use InputOutputModule, only: get_node
use DisvGeom, only: DisvGeomType
use MemoryManagerModule, only: mem_reallocate
! -- dummy
Expand Down Expand Up @@ -1196,7 +1195,6 @@ subroutine vertexconnect(nodes, nrsize, maxnnz, nlay, ncpl, sparse, &
! ------------------------------------------------------------------------------
! -- modules
use SparseModule, only: sparsematrix
use InputOutputModule, only: get_node
use DisvGeom, only: DisvGeomType
! -- dummy
integer(I4B), intent(in) :: nodes
Expand Down
2 changes: 1 addition & 1 deletion src/Model/ModelUtilities/DisvGeom.f90
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module DisvGeom

use KindModule, only: DP, I4B
use InputOutputModule, only: get_node, get_jk
use GeomUtilModule, only: get_node, get_jk
implicit none
private
public :: DisvGeomType
Expand Down
Loading

0 comments on commit 5b12e3d

Please sign in to comment.