Skip to content

Commit

Permalink
refactor(oc): introduce module/type for time step selection (#1923)
Browse files Browse the repository at this point in the history
In the spirit of TimeSelect, factor out a module and type TimeStepSelect for time step selections. This simplifies PrintSaveManager which can compose two of the latter. Add unit tests. Cleanup docstrings, comments, and style in base and concrete OC types.

This can also be used by PRT, to come in a separate PR which cleans up particle release logic.
  • Loading branch information
wpbonelli committed Jul 4, 2024
1 parent 67d6a1e commit 8203968
Show file tree
Hide file tree
Showing 20 changed files with 663 additions and 683 deletions.
122 changes: 122 additions & 0 deletions autotest/TestTimeStepSelect.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
module TestTimeStepSelect
use testdrive, only: error_type, unittest_type, new_unittest, check
use TimeStepSelectModule, only: TimeStepSelectType
use ConstantsModule, only: LINELENGTH

implicit none
private
public :: collect_timestepselect

contains

subroutine collect_timestepselect(testsuite)
type(unittest_type), allocatable, intent(out) :: testsuite(:)
testsuite = [ &
new_unittest("first", test_first), &
new_unittest("last", test_last), &
new_unittest("all", test_all), &
new_unittest("freq", test_freq), &
new_unittest("step", test_step) &
]
end subroutine collect_timestepselect

subroutine test_first(error)
type(error_type), allocatable, intent(out) :: error
type(TimeStepSelectType) :: steps
character(len=LINELENGTH) :: line

line = "FIRST"

call steps%init()
call steps%read(line)

call check(error, steps%is_selected(1, .false.))
if (allocated(error)) return

call check(error, steps%is_selected(1, .true.))
if (allocated(error)) return

call check(error,.not. steps%is_selected(2, .false.))
if (allocated(error)) return

end subroutine test_first

subroutine test_last(error)
type(error_type), allocatable, intent(out) :: error
type(TimeStepSelectType) :: steps
character(len=LINELENGTH) :: line

line = "LAST"

call steps%init()
call steps%read(line)

call check(error,.not. steps%is_selected(1, .false.))
if (allocated(error)) return

call check(error, steps%is_selected(1, .true.))
if (allocated(error)) return

end subroutine test_last

subroutine test_all(error)
type(error_type), allocatable, intent(out) :: error
type(TimeStepSelectType) :: steps
character(len=LINELENGTH) :: line

line = "ALL"

call steps%init()
call steps%read(line)

call check(error, steps%is_selected(1, .true.))
if (allocated(error)) return

call check(error, steps%is_selected(1, .false.))
if (allocated(error)) return

end subroutine test_all

subroutine test_freq(error)
type(error_type), allocatable, intent(out) :: error
type(TimeStepSelectType) :: steps
character(len=LINELENGTH) :: line

line = "FREQUENCY 2"

call steps%init()
call steps%read(line)

call check(error,.not. steps%is_selected(1, .false.))
if (allocated(error)) return

call check(error, steps%is_selected(2, .false.))
if (allocated(error)) return

call check(error,.not. steps%is_selected(3, .false.))
if (allocated(error)) return

call check(error, steps%is_selected(4, .false.))
if (allocated(error)) return

end subroutine test_freq

subroutine test_step(error)
type(error_type), allocatable, intent(out) :: error
type(TimeStepSelectType) :: steps
character(len=LINELENGTH) :: line

line = "STEPS 1"

call steps%init()
call steps%read(line)

call check(error, steps%is_selected(1, .false.))
if (allocated(error)) return

call check(error,.not. steps%is_selected(2, .false.))
if (allocated(error)) return

end subroutine test_step

end module TestTimeStepSelect
3 changes: 2 additions & 1 deletion autotest/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ if test_drive.found() and not fc_id.contains('intel')
'PtrHashTable',
'Sim',
'SwfUtils',
'TimeSelect'
'TimeSelect',
'TimeStepSelect'
]

test_srcs = files(
Expand Down
4 changes: 3 additions & 1 deletion autotest/tester.f90
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ program tester
use TestSim, only: collect_sim
use TestSwfUtils, only: collect_swfutils
use TestTimeSelect, only: collect_timeselect
use TestTimeStepSelect, only: collect_timestepselect
implicit none
integer :: stat, is
character(len=:), allocatable :: suite_name, test_name
Expand All @@ -42,7 +43,8 @@ program tester
new_testsuite("PtrHashTable", collect_ptrhashtable), &
new_testsuite("Sim", collect_sim), &
new_testsuite("SwfUtils", collect_swfutils), &
new_testsuite("TimeSelect", collect_timeselect) &
new_testsuite("TimeSelect", collect_timeselect), &
new_testsuite("TimeStepSelect", collect_timestepselect) &
]

call get_argument(1, suite_name)
Expand Down
2 changes: 1 addition & 1 deletion make/makedefaults
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# makedefaults created by pymake (version 1.2.10) for the 'mf6' executable.
# makedefaults created by pymake (version 1.2.11.dev0) for the 'mf6' executable.

# determine OS
ifeq ($(OS), Windows_NT)
Expand Down
77 changes: 39 additions & 38 deletions make/makefile
Original file line number Diff line number Diff line change
@@ -1,48 +1,48 @@
# makefile created by pymake (version 1.2.10) for the 'mf6' executable.
# makefile created by pymake (version 1.2.11.dev0) for the 'mf6' executable.


include ./makedefaults

# Define the source file directories
SOURCEDIR1=../src
SOURCEDIR2=../src/Exchange
SOURCEDIR3=../src/Idm
SOURCEDIR4=../src/Idm/selector
SOURCEDIR5=../src/Timing
SOURCEDIR6=../src/Model
SOURCEDIR7=../src/Model/Connection
SOURCEDIR8=../src/Model/Discretization
SOURCEDIR9=../src/Model/ModelUtilities
SOURCEDIR10=../src/Model/GroundWaterFlow
SOURCEDIR11=../src/Model/GroundWaterFlow/submodules
SOURCEDIR12=../src/Model/Geometry
SOURCEDIR13=../src/Model/TransportModel
SOURCEDIR14=../src/Model/GroundWaterTransport
SOURCEDIR15=../src/Model/SurfaceWaterFlow
SOURCEDIR16=../src/Model/ParticleTracking
SOURCEDIR17=../src/Model/GroundWaterEnergy
SOURCEDIR18=../src/Solution
SOURCEDIR19=../src/Solution/ParticleTracker
SOURCEDIR20=../src/Solution/LinearMethods
SOURCEDIR21=../src/Solution/PETSc
SOURCEDIR22=../src/Distributed
SOURCEDIR23=../src/Utilities
SOURCEDIR2=../src/Idm
SOURCEDIR3=../src/Idm/selector
SOURCEDIR4=../src/Exchange
SOURCEDIR5=../src/Distributed
SOURCEDIR6=../src/Solution
SOURCEDIR7=../src/Solution/LinearMethods
SOURCEDIR8=../src/Solution/ParticleTracker
SOURCEDIR9=../src/Solution/PETSc
SOURCEDIR10=../src/Timing
SOURCEDIR11=../src/Utilities
SOURCEDIR12=../src/Utilities/Idm
SOURCEDIR13=../src/Utilities/Idm/mf6blockfile
SOURCEDIR14=../src/Utilities/TimeSeries
SOURCEDIR15=../src/Utilities/Memory
SOURCEDIR16=../src/Utilities/OutputControl
SOURCEDIR17=../src/Utilities/ArrayRead
SOURCEDIR18=../src/Utilities/Libraries
SOURCEDIR19=../src/Utilities/Libraries/rcm
SOURCEDIR20=../src/Utilities/Libraries/blas
SOURCEDIR21=../src/Utilities/Libraries/sparskit2
SOURCEDIR22=../src/Utilities/Libraries/daglib
SOURCEDIR23=../src/Utilities/Libraries/sparsekit
SOURCEDIR24=../src/Utilities/Export
SOURCEDIR25=../src/Utilities/TimeSeries
SOURCEDIR26=../src/Utilities/Idm
SOURCEDIR27=../src/Utilities/Idm/mf6blockfile
SOURCEDIR28=../src/Utilities/ArrayRead
SOURCEDIR29=../src/Utilities/Memory
SOURCEDIR30=../src/Utilities/Matrix
SOURCEDIR31=../src/Utilities/Vector
SOURCEDIR32=../src/Utilities/Observation
SOURCEDIR33=../src/Utilities/OutputControl
SOURCEDIR34=../src/Utilities/Libraries
SOURCEDIR35=../src/Utilities/Libraries/rcm
SOURCEDIR36=../src/Utilities/Libraries/sparskit2
SOURCEDIR37=../src/Utilities/Libraries/sparsekit
SOURCEDIR38=../src/Utilities/Libraries/blas
SOURCEDIR39=../src/Utilities/Libraries/daglib
SOURCEDIR25=../src/Utilities/Vector
SOURCEDIR26=../src/Utilities/Matrix
SOURCEDIR27=../src/Utilities/Observation
SOURCEDIR28=../src/Model
SOURCEDIR29=../src/Model/Connection
SOURCEDIR30=../src/Model/ParticleTracking
SOURCEDIR31=../src/Model/SurfaceWaterFlow
SOURCEDIR32=../src/Model/GroundWaterTransport
SOURCEDIR33=../src/Model/ModelUtilities
SOURCEDIR34=../src/Model/GroundWaterFlow
SOURCEDIR35=../src/Model/GroundWaterFlow/submodules
SOURCEDIR36=../src/Model/Discretization
SOURCEDIR37=../src/Model/TransportModel
SOURCEDIR38=../src/Model/Geometry
SOURCEDIR39=../src/Model/GroundWaterEnergy

VPATH = \
${SOURCEDIR1} \
Expand Down Expand Up @@ -235,6 +235,7 @@ $(OBJDIR)/Subcell.o \
$(OBJDIR)/TrackData.o \
$(OBJDIR)/TimeSelect.o \
$(OBJDIR)/prt-fmi.o \
$(OBJDIR)/TimeStepSelect.o \
$(OBJDIR)/sort.o \
$(OBJDIR)/SfrCrossSectionUtils.o \
$(OBJDIR)/TernarySolveTrack.o \
Expand Down
1 change: 1 addition & 0 deletions msvs/mf6core.vfproj
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@
<File RelativePath="..\src\Model\ModelUtilities\SfrCrossSectionUtils.f90"/>
<File RelativePath="..\src\Model\ModelUtilities\SwfCxsUtils.f90"/>
<File RelativePath="..\src\Model\ModelUtilities\TimeSelect.f90"/>
<File RelativePath="..\src\Model\ModelUtilities\TimeStepSelect.f90"/>
<File RelativePath="..\src\Model\ModelUtilities\TrackData.f90"/>
<File RelativePath="..\src\Model\ModelUtilities\TspAdvOptions.f90"/>
<File RelativePath="..\src\Model\ModelUtilities\UzfCellGroup.f90"/>
Expand Down
4 changes: 2 additions & 2 deletions src/Model/GroundWaterFlow/gwf-oc.f90
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ subroutine oc_ar(this, head, dis, dnodata)
! -- Initialize variables
inodata = 0
nocdobj = 2
allocate (this%ocdobj(nocdobj))
allocate (this%ocds(nocdobj))
do i = 1, nocdobj
call ocd_cr(ocdobjptr)
select case (i)
Expand All @@ -84,7 +84,7 @@ subroutine oc_ar(this, head, dis, dnodata)
'COLUMNS 10 WIDTH 11 DIGITS 4 GENERAL ', &
this%iout, dnodata)
end select
this%ocdobj(i) = ocdobjptr
this%ocds(i) = ocdobjptr
deallocate (ocdobjptr)
end do
!
Expand Down
37 changes: 18 additions & 19 deletions src/Model/GroundWaterTransport/gwt-ist.f90
Original file line number Diff line number Diff line change
Expand Up @@ -49,32 +49,31 @@ module GwtIstModule
!<
type, extends(BndType) :: GwtIstType

type(TspFmiType), pointer :: fmi => null() !< pointer to fmi object
type(GwtMstType), pointer :: mst => null() !< pointer to mst object
type(TspFmiType), pointer :: fmi => null() !< flow model interface
type(GwtMstType), pointer :: mst => null() !< mobile storage and transfer
type(BudgetType), pointer :: budget => null() !< budget
type(OutputControlDataType), pointer :: ocd => null() !< output control data

integer(I4B), pointer :: icimout => null() !< unit number for binary cim output
integer(I4B), pointer :: ibudgetout => null() !< binary budget output file
integer(I4B), pointer :: ibudcsv => null() !< unit number for csv budget output file
integer(I4B), pointer :: idcy => null() !< order of decay rate (0:none, 1:first, 2:zero)
integer(I4B), pointer :: isrb => null() !< sorption active flag (0:off, 1:on); only linear is supported in ist
integer(I4B), pointer :: kiter => null() !< picard iteration counter
real(DP), dimension(:), pointer, contiguous :: cim => null() !< concentration for immobile domain
real(DP), dimension(:), pointer, contiguous :: cimnew => null() !< immobile concentration at end of current time step
real(DP), dimension(:), pointer, contiguous :: cimold => null() !< immobile concentration at end of last time step
real(DP), dimension(:), pointer, contiguous :: zetaim => null() !< mass transfer rate to immobile domain
real(DP), dimension(:), pointer, contiguous :: porosity => null() !< immobile domain porosity defined as volume of immobile voids per volume of immobile domain
real(DP), dimension(:), pointer, contiguous :: volfrac => null() !< volume fraction of the immobile domain defined as volume of immobile domain per aquifer volume
real(DP), dimension(:), pointer, contiguous :: bulk_density => null() !< bulk density of immobile domain defined as mass of solids in immobile domain per volume of immobile domain
real(DP), dimension(:), pointer, contiguous :: distcoef => null() !< distribution coefficient
real(DP), dimension(:), pointer, contiguous :: decay => null() !< first or zero order rate constant for liquid
real(DP), dimension(:), pointer, contiguous :: decaylast => null() !< decay rate used for last iteration (needed for zero order decay)
real(DP), dimension(:), pointer, contiguous :: decayslast => null() !< sorbed decay rate used for last iteration (needed for zero order decay)
real(DP), dimension(:), pointer, contiguous :: decay_sorbed => null() !< first or zero order rate constant for sorbed mass
real(DP), dimension(:), pointer, contiguous :: strg => null() !< mass transfer rate
real(DP), dimension(2, NBDITEMS) :: budterm !< immmobile domain mass summaries

type(BudgetType), pointer :: budget => null() !< budget object
type(OutputControlDataType), pointer :: ocd => null() !< output control object for cim
real(DP), pointer, contiguous :: cim(:) => null() !< concentration for immobile domain
real(DP), pointer, contiguous :: cimnew(:) => null() !< immobile concentration at end of current time step
real(DP), pointer, contiguous :: cimold(:) => null() !< immobile concentration at end of last time step
real(DP), pointer, contiguous :: zetaim(:) => null() !< mass transfer rate to immobile domain
real(DP), pointer, contiguous :: porosity(:) => null() !< immobile domain porosity defined as volume of immobile voids per volume of immobile domain
real(DP), pointer, contiguous :: volfrac(:) => null() !< volume fraction of the immobile domain defined as volume of immobile domain per aquifer volume
real(DP), pointer, contiguous :: bulk_density(:) => null() !< bulk density of immobile domain defined as mass of solids in immobile domain per volume of immobile domain
real(DP), pointer, contiguous :: distcoef(:) => null() !< distribution coefficient
real(DP), pointer, contiguous :: decay(:) => null() !< first or zero order rate constant for liquid
real(DP), pointer, contiguous :: decaylast(:) => null() !< decay rate used for last iteration (needed for zero order decay)
real(DP), pointer, contiguous :: decayslast(:) => null() !< sorbed decay rate used for last iteration (needed for zero order decay)
real(DP), pointer, contiguous :: decay_sorbed(:) => null() !< first or zero order rate constant for sorbed mass
real(DP), pointer, contiguous :: strg(:) => null() !< mass transfer rate
real(DP) :: budterm(2, NBDITEMS) !< immmobile domain mass summaries

contains

Expand Down
Loading

0 comments on commit 8203968

Please sign in to comment.