MODFLOW 6  version 6.5.0.dev2
MODFLOW 6 Code Documentation
SolutionGroup.f90
Go to the documentation of this file.
2  use kindmodule, only: dp, i4b
6  use listmodule, only: listtype
7 
8  implicit none
9  private
12  private :: castassolutiongroupclass
13 
15  integer(I4B), pointer :: id
16  integer(I4B), pointer :: mxiter
17  integer(I4B), pointer :: nsolutions
18  integer(I4B), dimension(:), allocatable :: idsolutions !array of solution ids in basesolutionlist
19  contains
20  procedure :: sgp_ca
21  procedure :: sgp_da
22  procedure, private :: allocate_scalars
23  procedure :: add_solution
24  end type solutiongrouptype
25 
26 contains
27 
28  subroutine solutiongroup_create(sgp, id)
29 ! ******************************************************************************
30 ! solutiongroup_create -- Create a new solution group
31 ! ******************************************************************************
32 !
33 ! SPECIFICATIONS:
34 ! ------------------------------------------------------------------------------
35  type(solutiongrouptype), pointer :: sgp
36  integer(I4B), intent(in) :: id
37 ! ------------------------------------------------------------------------------
38  !
39  allocate (sgp)
40  call sgp%allocate_scalars()
41  sgp%id = id
42  !
43  ! -- return
44  return
45  end subroutine solutiongroup_create
46 
47  subroutine sgp_ca(this)
48 ! ******************************************************************************
49 ! sgp_ca -- Calculate the solution group
50 ! Solve each solution group and each solution. Start with converge
51 ! flag equal true and reset to zero if any non-convergence triggers
52 ! are encountered.
53 ! ******************************************************************************
54 !
55 ! SPECIFICATIONS:
56 ! ------------------------------------------------------------------------------
57  ! -- modules
58  use constantsmodule, only: linelength
60  use tdismodule, only: kstp, kper
61  ! -- dummy
62  class(solutiongrouptype) :: this
63  ! -- local
64  class(basesolutiontype), pointer :: sp
65  integer(I4B) :: kpicard, isgcnvg, isuppress_output
66  integer(I4B) :: is, isoln
67  ! -- formats
68  character(len=*), parameter :: fmtnocnvg = &
69  "(1X,'Solution Group ', i0, ' did not converge for stress period ', i0, &
70  &' and time step ', i0)"
71 ! ------------------------------------------------------------------------------
72  !
73  ! -- Suppress output during picard iterations
74  if (this%mxiter > 1) then
75  isuppress_output = 1
76  else
77  isuppress_output = 0
78  end if
79  !
80  ! -- set failed flag
81  laststepfailed = 0
82  !
83  ! -- Picard loop
84  picardloop: do kpicard = 1, this%mxiter
85  if (this%mxiter > 1) then
86  write (iout, '(/a,i6/)') 'SOLUTION GROUP PICARD ITERATION: ', kpicard
87  end if
88  isgcnvg = 1
89  do is = 1, this%nsolutions
90  isoln = this%idsolutions(is)
92  call sp%sln_ca(isgcnvg, isuppress_output)
93  end do
94  if (isgcnvg == 1) exit picardloop
95  end do picardloop
96  !
97  ! -- if a picard loop was used and the solution group converged
98  ! then rerun the timestep and save the output. Or if there
99  ! is only one picard iteration, then do nothing as models
100  ! are assumed to be explicitly coupled.
101  if (isgcnvg == 1) then
102  if (this%mxiter > 1) then
103  isuppress_output = 0
104  do is = 1, this%nsolutions
105  isoln = this%idsolutions(is)
107  call sp%sln_ca(isgcnvg, isuppress_output)
108  end do
109  end if
110  else
111  isimcnvg = 0
112  laststepfailed = 1
113  write (iout, fmtnocnvg) this%id, kper, kstp
114  end if
115  !
116  ! -- return
117  return
118  end subroutine sgp_ca
119 
120  subroutine sgp_da(this)
121 ! ******************************************************************************
122 ! deallocate
123 ! ******************************************************************************
124 !
125 ! SPECIFICATIONS:
126 ! ------------------------------------------------------------------------------
127  class(solutiongrouptype) :: this
128 ! ------------------------------------------------------------------------------
129  !
130  deallocate (this%id)
131  deallocate (this%mxiter)
132  deallocate (this%nsolutions)
133  deallocate (this%idsolutions)
134  !
135  ! -- return
136  return
137  end subroutine sgp_da
138 
139  subroutine allocate_scalars(this)
140 ! ******************************************************************************
141 ! allocate_scalars
142 ! ******************************************************************************
143 !
144 ! SPECIFICATIONS:
145 ! ------------------------------------------------------------------------------
146  class(solutiongrouptype) :: this
147 ! ------------------------------------------------------------------------------
148  !
149  allocate (this%id)
150  allocate (this%mxiter)
151  allocate (this%nsolutions)
152  this%id = 0
153  this%mxiter = 1
154  this%nsolutions = 0
155  !
156  ! -- return
157  return
158  end subroutine allocate_scalars
159 
160  subroutine add_solution(this, isoln, sp)
161 ! ******************************************************************************
162 ! add_solution
163 ! ******************************************************************************
164 !
165 ! SPECIFICATIONS:
166 ! ------------------------------------------------------------------------------
167  ! -- modules
169  ! -- dummy
170  class(solutiongrouptype) :: this
171  integer(I4B), intent(in) :: isoln
172  class(basesolutiontype), pointer, intent(in) :: sp
173  ! -- local
174  integer(I4B) :: ipos
175 ! ------------------------------------------------------------------------------
176  !
177  call expandarray(this%idsolutions)
178  ipos = size(this%idsolutions)
179  this%idsolutions(ipos) = isoln
180  this%nsolutions = this%nsolutions + 1
181  !
182  ! -- return
183  return
184  end subroutine add_solution
185 
186  function castassolutiongroupclass(obj) result(res)
187  implicit none
188  class(*), pointer, intent(inout) :: obj
189  class(solutiongrouptype), pointer :: res
190  !
191  res => null()
192  if (.not. associated(obj)) return
193  !
194  select type (obj)
195  class is (solutiongrouptype)
196  res => obj
197  end select
198  return
199  end function castassolutiongroupclass
200 
201  subroutine addsolutiongrouptolist(list, solutiongroup)
202  implicit none
203  ! -- dummy
204  type(listtype), intent(inout) :: list
205  type(solutiongrouptype), pointer, intent(inout) :: solutiongroup
206  ! -- local
207  class(*), pointer :: obj
208  !
209  obj => solutiongroup
210  call list%Add(obj)
211  !
212  return
213  end subroutine addsolutiongrouptolist
214 
215  function getsolutiongroupfromlist(list, idx) result(res)
216  implicit none
217  ! -- dummy
218  type(listtype), intent(inout) :: list
219  integer(I4B), intent(in) :: idx
220  class(solutiongrouptype), pointer :: res
221  ! -- local
222  class(*), pointer :: obj
223  !
224  obj => list%GetItem(idx)
225  res => castassolutiongroupclass(obj)
226  !
227  return
228  end function getsolutiongroupfromlist
229 
230 end module solutiongroupmodule
subroutine, public addbasesolutiontolist(list, solution)
class(basesolutiontype) function, pointer, public getbasesolutionfromlist(list, idx)
This module contains simulation constants.
Definition: Constants.f90:9
integer(i4b), parameter linelength
maximum length of a standard line
Definition: Constants.f90:44
This module defines variable data types.
Definition: kind.f90:8
type(listtype), public basesolutionlist
Definition: mf6lists.f90:19
This module contains simulation variables.
Definition: SimVariables.f90:9
integer(i4b) laststepfailed
flag indicating if the last step failed (1) if last step failed; (0) otherwise (set in converge_check...
integer(i4b) iout
file unit number for simulation output
integer(i4b) isimcnvg
simulation convergence flag (1) if all objects have converged, (0) otherwise
class(solutiongrouptype) function, pointer, private castassolutiongroupclass(obj)
subroutine add_solution(this, isoln, sp)
class(solutiongrouptype) function, pointer, public getsolutiongroupfromlist(list, idx)
subroutine, public solutiongroup_create(sgp, id)
subroutine sgp_da(this)
subroutine sgp_ca(this)
subroutine, public addsolutiongrouptolist(list, solutiongroup)
subroutine allocate_scalars(this)
integer(i4b), pointer, public kstp
current time step number
Definition: tdis.f90:24
integer(i4b), pointer, public kper
current stress period number
Definition: tdis.f90:23
A generic heterogeneous doubly-linked list.
Definition: List.f90:10