Skip to content

Commit 3a2d9a0

Browse files
authored
refactor(ExplicitModel): add shared members (MODFLOW-ORG#1506)
* add ibound and filename to ExplicitModelType (broad relevance) * add set_idsoln() routine (consistent with numerical model) * fix docstrings in explicit model and explicit solution * remove unneeded returns
1 parent 4e7bb44 commit 3a2d9a0

File tree

2 files changed

+97
-129
lines changed

2 files changed

+97
-129
lines changed

src/Model/ExplicitModel.f90

Lines changed: 58 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
1-
!> @brief Explicit Model Module
2-
!!
3-
!! This module contains the Explicit Model, which is a parent
4-
!! class for models that solve themselves. Explicit models are
5-
!! added to an Explicit Solution, which is simply a container
6-
!! that scrolls through a list of explicit models and calls
7-
!! methods in a prescribed sequence.
8-
!!
9-
!<
1+
!> @brief Models that solve themselves
102
module ExplicitModelModule
113

12-
use KindModule, only: I4B
4+
use KindModule, only: I4B, DP
5+
use ConstantsModule, only: LINELENGTH
136
use ListModule, only: ListType
147
use BaseModelModule, only: BaseModelType
158
use BaseDisModule, only: DisBaseType
9+
use MemoryManagerModule, only: mem_allocate, mem_deallocate
1610

1711
implicit none
1812
private
@@ -21,17 +15,27 @@ module ExplicitModelModule
2115
AddExplicitModelToList, &
2216
GetExplicitModelFromList
2317

24-
!> @brief Base type for explicit models.
18+
!> @brief Base type for models that solve themselves.
19+
!!
20+
!! An explicit solution simply scrolls through a list of explicit
21+
!! models and calls solution procedures in a prescribed sequence.
22+
!<
2523
type, extends(BaseModelType) :: ExplicitModelType
26-
type(ListType), pointer :: bndlist => null() !< array of boundary packages for this model
24+
character(len=LINELENGTH), pointer :: filename => null() !< input file name
25+
integer(I4B), dimension(:), pointer, contiguous :: ibound => null() !< ibound array
26+
type(ListType), pointer :: bndlist => null() !< array of boundary packages
2727
class(DisBaseType), pointer :: dis => null() !< discretization object
2828
contains
29+
! -- Overridden methods
2930
procedure :: model_ad
3031
procedure :: model_solve
3132
procedure :: model_cq
3233
procedure :: model_bd
3334
procedure :: model_da
35+
! -- Utility methods
3436
procedure :: allocate_scalars
37+
procedure :: allocate_arrays
38+
procedure :: set_idsoln
3539
end type ExplicitModelType
3640

3741
contains
@@ -67,41 +71,59 @@ end subroutine model_bd
6771
!> @ brief Deallocate the model
6872
!<
6973
subroutine model_da(this)
70-
! -- modules
71-
use MemoryManagerModule, only: mem_deallocate
7274
class(ExplicitModelType) :: this
73-
!
74-
! -- derived types
75+
76+
! -- deallocate scalars
77+
deallocate (this%filename)
78+
79+
! -- deallocate arrays
80+
call mem_deallocate(this%ibound)
81+
82+
! -- nullify pointers
83+
if (associated(this%ibound)) &
84+
call mem_deallocate(this%ibound, 'IBOUND', this%memoryPath)
85+
86+
! -- member derived types
7587
call this%bndlist%Clear()
7688
deallocate (this%bndlist)
77-
!
78-
! -- BaseModelType
89+
90+
! -- deallocate base tpye
7991
call this%BaseModelType%model_da()
8092
end subroutine model_da
8193

82-
!> @ brief Allocate model scalar variables
94+
!> @ brief Allocate scalar variables
8395
!<
8496
subroutine allocate_scalars(this, modelname)
85-
use MemoryManagerModule, only: mem_allocate
8697
class(ExplicitModelType) :: this
8798
character(len=*), intent(in) :: modelname
88-
!
89-
! -- allocate basetype members
99+
90100
call this%BaseModelType%allocate_scalars(modelname)
91-
!
92-
! -- allocate members from this type
93101
allocate (this%bndlist)
102+
allocate (this%filename)
103+
this%filename = ''
94104
end subroutine allocate_scalars
95105

106+
!> @brief Allocate array variables
107+
!<
108+
subroutine allocate_arrays(this)
109+
class(ExplicitModelType) :: this
110+
integer(I4B) :: i
111+
112+
call mem_allocate(this%ibound, this%dis%nodes, 'IBOUND', this%memoryPath)
113+
do i = 1, this%dis%nodes
114+
this%ibound(i) = 1 ! active by default
115+
end do
116+
end subroutine allocate_arrays
117+
96118
!> @ brief Cast a generic object into an explicit model
97119
!<
98120
function CastAsExplicitModelClass(obj) result(res)
99121
class(*), pointer, intent(inout) :: obj
100122
class(ExplicitModelType), pointer :: res
101-
!
123+
102124
res => null()
103125
if (.not. associated(obj)) return
104-
!
126+
105127
select type (obj)
106128
class is (ExplicitModelType)
107129
res => obj
@@ -116,7 +138,7 @@ subroutine AddExplicitModelToList(list, model)
116138
class(ExplicitModelType), pointer, intent(inout) :: model
117139
! -- local
118140
class(*), pointer :: obj
119-
!
141+
120142
obj => model
121143
call list%Add(obj)
122144
end subroutine AddExplicitModelToList
@@ -130,9 +152,17 @@ function GetExplicitModelFromList(list, idx) result(res)
130152
class(ExplicitModelType), pointer :: res
131153
! -- local
132154
class(*), pointer :: obj
133-
!
155+
134156
obj => list%GetItem(idx)
135157
res => CastAsExplicitModelClass(obj)
136158
end function GetExplicitModelFromList
137159

160+
!> @brief Set the solution ID
161+
!<
162+
subroutine set_idsoln(this, id)
163+
class(ExplicitModelType) :: this
164+
integer(I4B), intent(in) :: id
165+
this%idsoln = id
166+
end subroutine set_idsoln
167+
138168
end module ExplicitModelModule

0 commit comments

Comments
 (0)