init_subsurface_transport.F90 coverage: 100.00 %func 76.32 %block
1) module Init_Subsurface_Tran_module
2)
3) use PFLOTRAN_Constants_module
4)
5) implicit none
6)
7) private
8)
9) #include "petsc/finclude/petscsys.h"
10)
11) public :: InitSubsurfTranSetupRealization, &
12) InitSubsurfTranSetupSolvers
13)
14) contains
15)
16) ! ************************************************************************** !
17)
18) subroutine InitSubsurfTranSetupRealization(realization)
19) !
20) ! Initializes material property data structres and assign them to the domain.
21) !
22) ! Author: Glenn Hammond
23) ! Date: 12/04/14
24) !
25) use Realization_Subsurface_class
26) use Option_module
27)
28) use Reactive_Transport_module
29) use Global_module
30) use Condition_Control_module
31) use Variables_module
32)
33) implicit none
34)
35) class(realization_subsurface_type) :: realization
36)
37) type(option_type), pointer :: option
38)
39) option => realization%option
40)
41) call RTSetup(realization)
42)
43) ! initialize densities and saturations
44) if (option%nflowdof == 0) then
45) call GlobalSetAuxVarScalar(realization,option%reference_pressure, &
46) LIQUID_PRESSURE)
47) call GlobalSetAuxVarScalar(realization,option%reference_temperature, &
48) TEMPERATURE)
49) call GlobalSetAuxVarScalar(realization,option%reference_saturation, &
50) LIQUID_SATURATION)
51) call GlobalSetAuxVarScalar(realization,option%reference_water_density, &
52) LIQUID_DENSITY)
53) else
54) call GlobalUpdateAuxVars(realization,TIME_T,0.d0)
55) call GlobalWeightAuxVars(realization,0.d0)
56) endif
57)
58) ! initial concentrations must be assigned after densities are set !!!
59) call CondControlAssignTranInitCond(realization)
60)
61) end subroutine InitSubsurfTranSetupRealization
62)
63) ! ************************************************************************** !
64)
65) subroutine InitSubsurfTranSetupSolvers(realization,convergence_context,solver)
66) !
67) ! Initializes material property data structres and assign them to the domain.
68) !
69) ! Author: Glenn Hammond
70) ! Date: 12/04/14
71) !
72) use Realization_Subsurface_class
73) use Option_module
74) use Init_Common_module
75)
76) use Reactive_Transport_module
77) use Secondary_Continuum_module
78) use Solver_module
79) use Convergence_module
80) use Discretization_module
81)
82) implicit none
83)
84) #include "petsc/finclude/petscvec.h"
85) #include "petsc/finclude/petscvec.h90"
86) #include "petsc/finclude/petscmat.h"
87) #include "petsc/finclude/petscmat.h90"
88) #include "petsc/finclude/petscsnes.h"
89) #include "petsc/finclude/petscpc.h"
90)
91) class(realization_subsurface_type) :: realization
92) type(convergence_context_type), pointer :: convergence_context
93) type(solver_type), pointer :: solver
94)
95) type(option_type), pointer :: option
96) SNESLineSearch :: linesearch
97) character(len=MAXSTRINGLENGTH) :: string
98) PetscErrorCode :: ierr
99)
100) option => realization%option
101)
102) call printMsg(option," Beginning setup of TRAN SNES ")
103)
104) call SolverCreateSNES(solver,option%mycomm)
105) call SNESSetOptionsPrefix(solver%snes, "tran_",ierr);CHKERRQ(ierr)
106) call SolverCheckCommandLine(solver)
107)
108) if (option%transport%reactive_transport_coupling == GLOBAL_IMPLICIT) then
109) if (solver%Jpre_mat_type == '') then
110) if (solver%J_mat_type /= MATMFFD) then
111) solver%Jpre_mat_type = solver%J_mat_type
112) else
113) solver%Jpre_mat_type = MATBAIJ
114) endif
115) endif
116) call DiscretizationCreateJacobian(realization%discretization,NTRANDOF, &
117) solver%Jpre_mat_type, &
118) solver%Jpre,option)
119) else
120) solver%J_mat_type = MATAIJ
121) solver%Jpre_mat_type = MATAIJ
122)
123) call DiscretizationCreateJacobian(realization%discretization,ONEDOF, &
124) solver%Jpre_mat_type, &
125) solver%Jpre,option)
126) endif
127)
128) if (solver%J_mat_type /= MATMFFD) then
129) solver%J = solver%Jpre
130) endif
131)
132) call MatSetOptionsPrefix(solver%Jpre,"tran_",ierr);CHKERRQ(ierr)
133)
134) if (solver%use_galerkin_mg) then
135) call DiscretizationCreateInterpolation(realization%discretization,NTRANDOF, &
136) solver%interpolation, &
137) solver%galerkin_mg_levels_x, &
138) solver%galerkin_mg_levels_y, &
139) solver%galerkin_mg_levels_z, &
140) option)
141) endif
142)
143) if (option%transport%reactive_transport_coupling == GLOBAL_IMPLICIT) then
144)
145) if (solver%J_mat_type == MATMFFD) then
146) call MatCreateSNESMF(solver%snes,solver%J, &
147) ierr);CHKERRQ(ierr)
148) endif
149)
150) ! this could be changed in the future if there is a way to ensure that
151) ! the linesearch update does not perturb concentrations negative.
152) call SNESGetLineSearch(solver%snes, linesearch, ierr);CHKERRQ(ierr)
153) call SNESLineSearchSetType(linesearch, SNESLINESEARCHBASIC, &
154) ierr);CHKERRQ(ierr)
155)
156) if (option%use_mc) then
157) call SNESLineSearchSetPostCheck(linesearch, &
158) SecondaryRTUpdateIterate, &
159) realization,ierr);CHKERRQ(ierr)
160) endif
161)
162) ! Have PETSc do a SNES_View() at the end of each solve if verbosity > 0.
163) if (option%verbosity >= 2) then
164) string = '-tran_snes_view'
165) call PetscOptionsInsertString(PETSC_NULL_OBJECT, &
166) string, ierr);CHKERRQ(ierr)
167) endif
168)
169) endif
170)
171) ! ensure setting of SNES options since they set KSP and PC options too
172) call SolverSetSNESOptions(solver)
173)
174) option%io_buffer = 'Solver: ' // trim(solver%ksp_type)
175) call printMsg(option)
176) option%io_buffer = 'Preconditioner: ' // trim(solver%pc_type)
177) call printMsg(option)
178)
179) if (option%transport%reactive_transport_coupling == GLOBAL_IMPLICIT) then
180)
181) ! shell for custom convergence test. The default SNES convergence test
182) ! is call within this function.
183) !TODO(geh): free this convergence context somewhere!
184) option%io_buffer = 'DEALLOCATE TRANSPORT CONVERGENCE CONTEXT somewhere!!!'
185) convergence_context => ConvergenceContextCreate(solver,option, &
186) realization%patch%grid)
187) call SNESSetConvergenceTest(solver%snes,ConvergenceTest, &
188) convergence_context, &
189) PETSC_NULL_FUNCTION,ierr);CHKERRQ(ierr)
190) endif
191)
192) call printMsg(option," Finished setting up TRAN SNES ")
193)
194) end subroutine InitSubsurfTranSetupSolvers
195)
196) end module Init_Subsurface_Tran_module