Skip to content

Commit 8203968

Browse files
authored
refactor(oc): introduce module/type for time step selection (#1923)
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.
1 parent 67d6a1e commit 8203968

File tree

20 files changed

+663
-683
lines changed

20 files changed

+663
-683
lines changed

autotest/TestTimeStepSelect.f90

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
module TestTimeStepSelect
2+
use testdrive, only: error_type, unittest_type, new_unittest, check
3+
use TimeStepSelectModule, only: TimeStepSelectType
4+
use ConstantsModule, only: LINELENGTH
5+
6+
implicit none
7+
private
8+
public :: collect_timestepselect
9+
10+
contains
11+
12+
subroutine collect_timestepselect(testsuite)
13+
type(unittest_type), allocatable, intent(out) :: testsuite(:)
14+
testsuite = [ &
15+
new_unittest("first", test_first), &
16+
new_unittest("last", test_last), &
17+
new_unittest("all", test_all), &
18+
new_unittest("freq", test_freq), &
19+
new_unittest("step", test_step) &
20+
]
21+
end subroutine collect_timestepselect
22+
23+
subroutine test_first(error)
24+
type(error_type), allocatable, intent(out) :: error
25+
type(TimeStepSelectType) :: steps
26+
character(len=LINELENGTH) :: line
27+
28+
line = "FIRST"
29+
30+
call steps%init()
31+
call steps%read(line)
32+
33+
call check(error, steps%is_selected(1, .false.))
34+
if (allocated(error)) return
35+
36+
call check(error, steps%is_selected(1, .true.))
37+
if (allocated(error)) return
38+
39+
call check(error,.not. steps%is_selected(2, .false.))
40+
if (allocated(error)) return
41+
42+
end subroutine test_first
43+
44+
subroutine test_last(error)
45+
type(error_type), allocatable, intent(out) :: error
46+
type(TimeStepSelectType) :: steps
47+
character(len=LINELENGTH) :: line
48+
49+
line = "LAST"
50+
51+
call steps%init()
52+
call steps%read(line)
53+
54+
call check(error,.not. steps%is_selected(1, .false.))
55+
if (allocated(error)) return
56+
57+
call check(error, steps%is_selected(1, .true.))
58+
if (allocated(error)) return
59+
60+
end subroutine test_last
61+
62+
subroutine test_all(error)
63+
type(error_type), allocatable, intent(out) :: error
64+
type(TimeStepSelectType) :: steps
65+
character(len=LINELENGTH) :: line
66+
67+
line = "ALL"
68+
69+
call steps%init()
70+
call steps%read(line)
71+
72+
call check(error, steps%is_selected(1, .true.))
73+
if (allocated(error)) return
74+
75+
call check(error, steps%is_selected(1, .false.))
76+
if (allocated(error)) return
77+
78+
end subroutine test_all
79+
80+
subroutine test_freq(error)
81+
type(error_type), allocatable, intent(out) :: error
82+
type(TimeStepSelectType) :: steps
83+
character(len=LINELENGTH) :: line
84+
85+
line = "FREQUENCY 2"
86+
87+
call steps%init()
88+
call steps%read(line)
89+
90+
call check(error,.not. steps%is_selected(1, .false.))
91+
if (allocated(error)) return
92+
93+
call check(error, steps%is_selected(2, .false.))
94+
if (allocated(error)) return
95+
96+
call check(error,.not. steps%is_selected(3, .false.))
97+
if (allocated(error)) return
98+
99+
call check(error, steps%is_selected(4, .false.))
100+
if (allocated(error)) return
101+
102+
end subroutine test_freq
103+
104+
subroutine test_step(error)
105+
type(error_type), allocatable, intent(out) :: error
106+
type(TimeStepSelectType) :: steps
107+
character(len=LINELENGTH) :: line
108+
109+
line = "STEPS 1"
110+
111+
call steps%init()
112+
call steps%read(line)
113+
114+
call check(error, steps%is_selected(1, .false.))
115+
if (allocated(error)) return
116+
117+
call check(error,.not. steps%is_selected(2, .false.))
118+
if (allocated(error)) return
119+
120+
end subroutine test_step
121+
122+
end module TestTimeStepSelect

autotest/meson.build

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ if test_drive.found() and not fc_id.contains('intel')
1616
'PtrHashTable',
1717
'Sim',
1818
'SwfUtils',
19-
'TimeSelect'
19+
'TimeSelect',
20+
'TimeStepSelect'
2021
]
2122

2223
test_srcs = files(

autotest/tester.f90

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ program tester
1818
use TestSim, only: collect_sim
1919
use TestSwfUtils, only: collect_swfutils
2020
use TestTimeSelect, only: collect_timeselect
21+
use TestTimeStepSelect, only: collect_timestepselect
2122
implicit none
2223
integer :: stat, is
2324
character(len=:), allocatable :: suite_name, test_name
@@ -42,7 +43,8 @@ program tester
4243
new_testsuite("PtrHashTable", collect_ptrhashtable), &
4344
new_testsuite("Sim", collect_sim), &
4445
new_testsuite("SwfUtils", collect_swfutils), &
45-
new_testsuite("TimeSelect", collect_timeselect) &
46+
new_testsuite("TimeSelect", collect_timeselect), &
47+
new_testsuite("TimeStepSelect", collect_timestepselect) &
4648
]
4749

4850
call get_argument(1, suite_name)

make/makedefaults

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# makedefaults created by pymake (version 1.2.10) for the 'mf6' executable.
1+
# makedefaults created by pymake (version 1.2.11.dev0) for the 'mf6' executable.
22

33
# determine OS
44
ifeq ($(OS), Windows_NT)

make/makefile

Lines changed: 39 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,48 @@
1-
# makefile created by pymake (version 1.2.10) for the 'mf6' executable.
1+
# makefile created by pymake (version 1.2.11.dev0) for the 'mf6' executable.
22

33

44
include ./makedefaults
55

66
# Define the source file directories
77
SOURCEDIR1=../src
8-
SOURCEDIR2=../src/Exchange
9-
SOURCEDIR3=../src/Idm
10-
SOURCEDIR4=../src/Idm/selector
11-
SOURCEDIR5=../src/Timing
12-
SOURCEDIR6=../src/Model
13-
SOURCEDIR7=../src/Model/Connection
14-
SOURCEDIR8=../src/Model/Discretization
15-
SOURCEDIR9=../src/Model/ModelUtilities
16-
SOURCEDIR10=../src/Model/GroundWaterFlow
17-
SOURCEDIR11=../src/Model/GroundWaterFlow/submodules
18-
SOURCEDIR12=../src/Model/Geometry
19-
SOURCEDIR13=../src/Model/TransportModel
20-
SOURCEDIR14=../src/Model/GroundWaterTransport
21-
SOURCEDIR15=../src/Model/SurfaceWaterFlow
22-
SOURCEDIR16=../src/Model/ParticleTracking
23-
SOURCEDIR17=../src/Model/GroundWaterEnergy
24-
SOURCEDIR18=../src/Solution
25-
SOURCEDIR19=../src/Solution/ParticleTracker
26-
SOURCEDIR20=../src/Solution/LinearMethods
27-
SOURCEDIR21=../src/Solution/PETSc
28-
SOURCEDIR22=../src/Distributed
29-
SOURCEDIR23=../src/Utilities
8+
SOURCEDIR2=../src/Idm
9+
SOURCEDIR3=../src/Idm/selector
10+
SOURCEDIR4=../src/Exchange
11+
SOURCEDIR5=../src/Distributed
12+
SOURCEDIR6=../src/Solution
13+
SOURCEDIR7=../src/Solution/LinearMethods
14+
SOURCEDIR8=../src/Solution/ParticleTracker
15+
SOURCEDIR9=../src/Solution/PETSc
16+
SOURCEDIR10=../src/Timing
17+
SOURCEDIR11=../src/Utilities
18+
SOURCEDIR12=../src/Utilities/Idm
19+
SOURCEDIR13=../src/Utilities/Idm/mf6blockfile
20+
SOURCEDIR14=../src/Utilities/TimeSeries
21+
SOURCEDIR15=../src/Utilities/Memory
22+
SOURCEDIR16=../src/Utilities/OutputControl
23+
SOURCEDIR17=../src/Utilities/ArrayRead
24+
SOURCEDIR18=../src/Utilities/Libraries
25+
SOURCEDIR19=../src/Utilities/Libraries/rcm
26+
SOURCEDIR20=../src/Utilities/Libraries/blas
27+
SOURCEDIR21=../src/Utilities/Libraries/sparskit2
28+
SOURCEDIR22=../src/Utilities/Libraries/daglib
29+
SOURCEDIR23=../src/Utilities/Libraries/sparsekit
3030
SOURCEDIR24=../src/Utilities/Export
31-
SOURCEDIR25=../src/Utilities/TimeSeries
32-
SOURCEDIR26=../src/Utilities/Idm
33-
SOURCEDIR27=../src/Utilities/Idm/mf6blockfile
34-
SOURCEDIR28=../src/Utilities/ArrayRead
35-
SOURCEDIR29=../src/Utilities/Memory
36-
SOURCEDIR30=../src/Utilities/Matrix
37-
SOURCEDIR31=../src/Utilities/Vector
38-
SOURCEDIR32=../src/Utilities/Observation
39-
SOURCEDIR33=../src/Utilities/OutputControl
40-
SOURCEDIR34=../src/Utilities/Libraries
41-
SOURCEDIR35=../src/Utilities/Libraries/rcm
42-
SOURCEDIR36=../src/Utilities/Libraries/sparskit2
43-
SOURCEDIR37=../src/Utilities/Libraries/sparsekit
44-
SOURCEDIR38=../src/Utilities/Libraries/blas
45-
SOURCEDIR39=../src/Utilities/Libraries/daglib
31+
SOURCEDIR25=../src/Utilities/Vector
32+
SOURCEDIR26=../src/Utilities/Matrix
33+
SOURCEDIR27=../src/Utilities/Observation
34+
SOURCEDIR28=../src/Model
35+
SOURCEDIR29=../src/Model/Connection
36+
SOURCEDIR30=../src/Model/ParticleTracking
37+
SOURCEDIR31=../src/Model/SurfaceWaterFlow
38+
SOURCEDIR32=../src/Model/GroundWaterTransport
39+
SOURCEDIR33=../src/Model/ModelUtilities
40+
SOURCEDIR34=../src/Model/GroundWaterFlow
41+
SOURCEDIR35=../src/Model/GroundWaterFlow/submodules
42+
SOURCEDIR36=../src/Model/Discretization
43+
SOURCEDIR37=../src/Model/TransportModel
44+
SOURCEDIR38=../src/Model/Geometry
45+
SOURCEDIR39=../src/Model/GroundWaterEnergy
4646

4747
VPATH = \
4848
${SOURCEDIR1} \
@@ -235,6 +235,7 @@ $(OBJDIR)/Subcell.o \
235235
$(OBJDIR)/TrackData.o \
236236
$(OBJDIR)/TimeSelect.o \
237237
$(OBJDIR)/prt-fmi.o \
238+
$(OBJDIR)/TimeStepSelect.o \
238239
$(OBJDIR)/sort.o \
239240
$(OBJDIR)/SfrCrossSectionUtils.o \
240241
$(OBJDIR)/TernarySolveTrack.o \

msvs/mf6core.vfproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@
288288
<File RelativePath="..\src\Model\ModelUtilities\SfrCrossSectionUtils.f90"/>
289289
<File RelativePath="..\src\Model\ModelUtilities\SwfCxsUtils.f90"/>
290290
<File RelativePath="..\src\Model\ModelUtilities\TimeSelect.f90"/>
291+
<File RelativePath="..\src\Model\ModelUtilities\TimeStepSelect.f90"/>
291292
<File RelativePath="..\src\Model\ModelUtilities\TrackData.f90"/>
292293
<File RelativePath="..\src\Model\ModelUtilities\TspAdvOptions.f90"/>
293294
<File RelativePath="..\src\Model\ModelUtilities\UzfCellGroup.f90"/>

src/Model/GroundWaterFlow/gwf-oc.f90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ subroutine oc_ar(this, head, dis, dnodata)
7171
! -- Initialize variables
7272
inodata = 0
7373
nocdobj = 2
74-
allocate (this%ocdobj(nocdobj))
74+
allocate (this%ocds(nocdobj))
7575
do i = 1, nocdobj
7676
call ocd_cr(ocdobjptr)
7777
select case (i)
@@ -84,7 +84,7 @@ subroutine oc_ar(this, head, dis, dnodata)
8484
'COLUMNS 10 WIDTH 11 DIGITS 4 GENERAL ', &
8585
this%iout, dnodata)
8686
end select
87-
this%ocdobj(i) = ocdobjptr
87+
this%ocds(i) = ocdobjptr
8888
deallocate (ocdobjptr)
8989
end do
9090
!

src/Model/GroundWaterTransport/gwt-ist.f90

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -49,32 +49,31 @@ module GwtIstModule
4949
!<
5050
type, extends(BndType) :: GwtIstType
5151

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

5557
integer(I4B), pointer :: icimout => null() !< unit number for binary cim output
5658
integer(I4B), pointer :: ibudgetout => null() !< binary budget output file
5759
integer(I4B), pointer :: ibudcsv => null() !< unit number for csv budget output file
5860
integer(I4B), pointer :: idcy => null() !< order of decay rate (0:none, 1:first, 2:zero)
5961
integer(I4B), pointer :: isrb => null() !< sorption active flag (0:off, 1:on); only linear is supported in ist
6062
integer(I4B), pointer :: kiter => null() !< picard iteration counter
61-
real(DP), dimension(:), pointer, contiguous :: cim => null() !< concentration for immobile domain
62-
real(DP), dimension(:), pointer, contiguous :: cimnew => null() !< immobile concentration at end of current time step
63-
real(DP), dimension(:), pointer, contiguous :: cimold => null() !< immobile concentration at end of last time step
64-
real(DP), dimension(:), pointer, contiguous :: zetaim => null() !< mass transfer rate to immobile domain
65-
real(DP), dimension(:), pointer, contiguous :: porosity => null() !< immobile domain porosity defined as volume of immobile voids per volume of immobile domain
66-
real(DP), dimension(:), pointer, contiguous :: volfrac => null() !< volume fraction of the immobile domain defined as volume of immobile domain per aquifer volume
67-
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
68-
real(DP), dimension(:), pointer, contiguous :: distcoef => null() !< distribution coefficient
69-
real(DP), dimension(:), pointer, contiguous :: decay => null() !< first or zero order rate constant for liquid
70-
real(DP), dimension(:), pointer, contiguous :: decaylast => null() !< decay rate used for last iteration (needed for zero order decay)
71-
real(DP), dimension(:), pointer, contiguous :: decayslast => null() !< sorbed decay rate used for last iteration (needed for zero order decay)
72-
real(DP), dimension(:), pointer, contiguous :: decay_sorbed => null() !< first or zero order rate constant for sorbed mass
73-
real(DP), dimension(:), pointer, contiguous :: strg => null() !< mass transfer rate
74-
real(DP), dimension(2, NBDITEMS) :: budterm !< immmobile domain mass summaries
75-
76-
type(BudgetType), pointer :: budget => null() !< budget object
77-
type(OutputControlDataType), pointer :: ocd => null() !< output control object for cim
63+
real(DP), pointer, contiguous :: cim(:) => null() !< concentration for immobile domain
64+
real(DP), pointer, contiguous :: cimnew(:) => null() !< immobile concentration at end of current time step
65+
real(DP), pointer, contiguous :: cimold(:) => null() !< immobile concentration at end of last time step
66+
real(DP), pointer, contiguous :: zetaim(:) => null() !< mass transfer rate to immobile domain
67+
real(DP), pointer, contiguous :: porosity(:) => null() !< immobile domain porosity defined as volume of immobile voids per volume of immobile domain
68+
real(DP), pointer, contiguous :: volfrac(:) => null() !< volume fraction of the immobile domain defined as volume of immobile domain per aquifer volume
69+
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
70+
real(DP), pointer, contiguous :: distcoef(:) => null() !< distribution coefficient
71+
real(DP), pointer, contiguous :: decay(:) => null() !< first or zero order rate constant for liquid
72+
real(DP), pointer, contiguous :: decaylast(:) => null() !< decay rate used for last iteration (needed for zero order decay)
73+
real(DP), pointer, contiguous :: decayslast(:) => null() !< sorbed decay rate used for last iteration (needed for zero order decay)
74+
real(DP), pointer, contiguous :: decay_sorbed(:) => null() !< first or zero order rate constant for sorbed mass
75+
real(DP), pointer, contiguous :: strg(:) => null() !< mass transfer rate
76+
real(DP) :: budterm(2, NBDITEMS) !< immmobile domain mass summaries
7877

7978
contains
8079

0 commit comments

Comments
 (0)