11 Subroutine solversetup
17 Use f90moduleinterfaces
22 #include <finclude/petscsys.h> 23 #include <finclude/petscvec.h> 24 #include <finclude/petscvec.h90> 25 #include <finclude/petscdmda.h> 26 #include <finclude/petscdm.h> 27 #include <finclude/petscdmda.h90> 28 #include <finclude/petscis.h> 29 #include <finclude/petscmat.h> 30 #include <finclude/petscsnes.h> 31 #include <finclude/petscsnes.h90> 35 petscerrorcode :: ierr
43 character(80) :: filename=
'' 46 external forminitialguess
49 external jac_matrix_empty
53 call mpi_comm_rank(petsc_comm_world,user%rank,ierr)
54 call mpi_comm_size(petsc_comm_world,user%num_procs,ierr)
58 call snescreate(petsc_comm_world,snes,ierr)
61 call dmdacreate1d(petsc_comm_world, &
62 & dmda_boundary_ghosted, &
66 & petsc_null_integer, &
71 call dmcreateglobalvector(da,x,ierr)
72 call vecduplicate(x,r,ierr)
75 call dmdagetcorners(da, &
77 & petsc_null_integer, &
78 & petsc_null_integer, &
80 & petsc_null_integer, &
81 & petsc_null_integer, &
84 call dmdagetghostcorners(da, &
86 & petsc_null_integer, &
87 & petsc_null_integer, &
89 & petsc_null_integer, &
90 & petsc_null_integer, &
97 user%xe = user%xs+user%xm-1
98 user%gxe = user%gxs+user%gxm-1
102 call snessetdm(snes,da,ierr)
114 call petscoptionsgetint(petsc_null_character,
'-jac',jac_id,flg,ierr)
119 write(*,*)
'Option -jac not set in makefile, using matrix-free with numerical approximations.' 130 call petscoptionsgetreal(petsc_null_character,
'-erel',erel,flg,ierr)
131 If(user%rank == 0)
write(*,*)
'Using matrix-free Jacobian with numerical approximations. erel:',erel
132 call matcreatesnesmf(snes,j,ierr)
133 call matmffdsetfunctionerror(j,erel,ierr)
134 call snessetjacobian(snes,j,j,matmffdcomputejacobian,petsc_null_object,ierr)
137 If(user%rank == 0)
write(*,*)
'Using matrix-free AD Jacobian.' 139 jaclocal = int(ngrid / user%num_procs)
140 If(mod(ngrid,user%num_procs) /= 0 )
Then 141 write(*,*)
'Surface Tension Code: Dimensions and number of cores dont match! mod(ngrid,n_cores) must equal 0' 146 If(jaclocal /= user%xm)
Then 147 write(*,*)
'Surface Tension Code: Shell-Jacobi-Matrix and DMDA have to be parallelized accordingly.' 152 call matcreateshell(petsc_comm_world,ncomp*jaclocal,ncomp*jaclocal,ncomp*ngrid,ncomp*ngrid,petsc_null_object,j,ierr)
153 call matshellsetoperation( j, matop_mult, jac_shell_ad, ierr )
154 call snessetjacobian( snes, j, j, jac_matrix_empty, petsc_null_object, ierr)
157 If(user%rank == 0)
write(*,*)
'Using finite-difference Jacobian.' 167 If(user%rank == 0)
write(*,*)
'Surface Tension Code: Using AD-generated Jacobian.' 168 write(*,*)
'Not working yet!' 180 write(*,*)
'No valid option set for -jac in makefile, using full Jacobi via finite-differences.' 181 call snessetjacobian(snes,j,j,snescomputejacobiandefault,petsc_null_object,ierr)
186 call snesmonitorset(snes,monitortimer,petsc_null_object,petsc_null_function,ierr)
189 call snessetfromoptions(snes,ierr)
192 call forminitialguess(snes,x,ierr)
198 timer_old = mpi_wtime()
201 call snessolve(snes,petsc_null_object,x,ierr)
211 End Subroutine solversetup
219 subroutine monitortimer(snes,its,norm,dummy,ierr)
221 Use global_x, Only: timer,timer_old,total_time,r
222 Use mod_dft
, Only: free
225 Use vle_var
, Only: rhob,tc
237 #include <finclude/petscsys.h> 238 #include <finclude/petscvec.h> 248 vec :: current_solution
249 DOUBLE PRECISION :: delta_time
251 REAL :: m_average,surftens,st_macro
252 character(80) :: filename=
'' 259 call mpi_reduce(free,free,1,mpi_double_precision,mpi_sum,0,petsc_comm_world,ierr)
262 call mpi_comm_rank(petsc_comm_world,rank,ierr)
266 surftens = kbol * t *1.e20*1000.0 *free
267 m_average = sum( rhob(1,1:ncomp)*parame(1:ncomp,1) ) / rhob(1,0)
269 st_macro = surftens / ( 1.0 + 3.0/8.0/pi *t/tc &
270 * (1.0/2.55)**2 / (0.0674*m_average+0.0045) )
272 write(*,*)
'ST',st_macro
276 scale_factor = 0.8 - 2.4828*wif_surfactant
281 If(surfactant)
write(*,*)
'ST including surfactant', st_macro*scale_factor
286 CALL file_open(filename,99)
287 WRITE (99,*) st_macro*scale_factor
295 delta_time = timer - timer_old
297 total_time = total_time + delta_time
300 call vecnorm(r,2,f2norm,ierr)
304 filename =
'ItsTimeNorm.dat' 305 open(unit = 44, file = filename)
306 write(44,*) its,total_time,f2norm
309 end subroutine monitortimer
WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW This module contains constant...
This module contains variables associated with the PETSc solver.
subroutine formfunction(snes, X, F, user, ierr)
The subroutine FormFunction is a wrapper function which takes care of handling the global PETSc data ...
In this module, the application context is defined.
WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW This module contains paramete...