MoDeNa  1.0
Software framework facilitating sequential multi-scale modelling
integration.f90
Go to the documentation of this file.
1 
7 module integration
8  use globals
9  implicit none
10  private
11  public preprocess,integrate
12  !time integration variables for lsode
13  real(dp), dimension(:), allocatable :: rwork,y
14  integer, dimension(:), allocatable :: iwork
15  real(dp) :: jac,tout,rtol,atol,t
16  integer :: iopt, istate, itask, itol, liw, lrw, nnz, lenrat, mf, neq
17  !needed for selection of model subroutine
18  abstract interface
19  subroutine sub (neq, t, y, ydot)
20  use constants
21  integer, intent(in) :: neq
22  real(dp), intent(in) :: t
23  real(dp), intent(in) :: y(neq)
24  real(dp), intent(out) :: ydot(neq)
25  end subroutine sub
26  end interface
28  procedure(sub), pointer :: odesystem_ptr => null()
29  real(dp) :: vt0,told
30  real(dp), dimension(:), allocatable :: yold
31 contains
32 !********************************BEGINNING*************************************
34 subroutine preprocess
35  use in_out, only: read_inputs
36  use phys_prop, only: volume_balance
37  use model, only: odesystem,set_initial_conditions,update_domain_size
38  real(dp) :: vt,fs
39  write(*,*) 'wellcome to wall drainage.'
40  call read_inputs
41  neq=meshpoints
42  allocate(y(neq),yold(neq))
43  call set_initial_conditions(y)
44  t=initialtime
45  call update_domain_size(t,y)
46  call volume_balance(y,vt,fs)
47  vt0=vt
48  odesystem_ptr=>odesystem
49  mf=int_method
50  atol=int_abstol
51  rtol=int_reltol
52  nnz=neq**2 !i really don't know, smaller numbers can make problems
53  lenrat=2 !depends on dp
54  allocate(rwork(int(20+(2+1._dp/lenrat)*nnz+(11+9._dp/lenrat)*neq)),&
55  iwork(30))
56  itask = 1
57  istate = 1
58  iopt = 1
59  rwork(5:10)=0
60  iwork(5:10)=0
61  lrw = size(rwork)
62  liw = size(iwork)
63  iwork(6)=maxts
64  tout =t+timestep
65  itol = 1 !don't change, or you must declare atol as atol(neq)
66 end subroutine preprocess
67 !***********************************END****************************************
68 
69 
70 !********************************BEGINNING*************************************
72 subroutine integrate
73  use model, only: q
74  use solve_nonlin, only: hbrd
75  use in_out, only: save_int_header,save_int_step,save_int_close
76  integer :: i,fi,fi2
77  integer, parameter :: n=1
78  integer :: info
79  real (dp), dimension(n) :: x,fvec,diag
80  call save_int_header
81  call save_int_step(y,t)
82  do i=1,its
83  told=t
84  yold=y
85  x(1)=q
86  ! at each time step find the flux, which will preserve total volume
87  ! of the system (film + strut)
88  call hbrd(drain_residual,n,x,fvec,epsilon(ae_tol),ae_tol,info,diag)
89  if (info /= 1) then
90  print*, 'Flux not found.'
91  print*, 'Hbrd returned info = ',info
92  stop
93  endif
94  call save_int_step(y,t)
95  if (mu>1.0e3_dp) then
96  print*, 'gel point reached'
97  exit
98  endif
99  tout = tout+timestep
100  enddo
101  call save_int_close
102  deallocate(y,yold,rwork,iwork)
103  write(*,*) 'program exited normally.'
104 end subroutine integrate
105 !***********************************END****************************************
106 
107 
108 !********************************BEGINNING*************************************
110 subroutine drain_residual(n,x,fvec,iflag)
111  use model, only: q,update_domain_size
112  use phys_prop, only: volume_balance,rb
113  integer, intent(in) :: n
114  integer, intent(inout) :: iflag
115  real(dp), dimension(n), intent(in) :: x
116  real(dp), dimension(n), intent(out) :: fvec
117  real(dp) :: vt,fs
118  q=x(1)
119  t=told
120  y=yold
121  istate=1
122  call dlsodes (odesystem_ptr, neq, y, t, tout, itol, rtol, atol, itask, &
123  istate, iopt, rwork, lrw, iwork, liw, jac, mf)
124  call update_domain_size(t,y)
125  call volume_balance(y,vt,fs)
126  fvec(1)=sqrt((vt-vt0)**2)
127  ! print*, x(1),fvec(1)
128 end subroutine drain_residual
129 !***********************************END****************************************
130 end module integration
integer meshpoints
number of discretization points in space
Definition: globals.f90:13
real(dp), dimension(:), allocatable y
state variables
Definition: globals.f90:106
real(dp) int_reltol
relative tolerance of integrator
Definition: globals.f90:18
integer int_method
type of integration method (see MF in ODEPACK)
Definition: globals.f90:13
real(dp) ae_tol
tolerance of algebraic equation solver
Definition: globals.f90:18
real(dp) timestep
timestep
Definition: globals.f90:49
integer its
number of outer integration outer time steps
Definition: globals.f90:29
real(dp) int_abstol
absolute tolerance of integrator
Definition: globals.f90:18
namespace with global variables
Definition: globals.f90:8
real(dp) initialtime
starting time
Definition: globals.f90:18
integer maxts
maximum inner time steps between t and t+h
Definition: globals.f90:29