MoDeNa  1.0
Software framework facilitating sequential multi-scale modelling
integration.f90
Go to the documentation of this file.
1 
8 module integration
9  implicit none
10  private
11  public integrate
12 contains
13 !********************************BEGINNING*************************************
18 subroutine integrate
19  use constants
20  use globals
21  use physicalproperties
22  use conductivity, only: equcond
23  use ioutils, only: newunit
24  use model, only: modelpu,ngas,nfv,dz,dif,sol,bc,mor
25  use inout, only: input,output,print_header
26  integer :: i, j, k, l, counter, fi
27  integer :: multiplicator
28  integer :: itol, itask, istate, iopt
29  integer :: MF, ML, MU, LRW, LIW, LENRAT, NNZ, LWM, NEQ
30  integer, allocatable :: IWORK(:)
31 
32  real(dp) :: tin, tout, keq
33  real(dp) :: rtol, atol, jdem
34 
35  real(dp), allocatable :: ystate(:), yprime(:) ! vector of state
36  real(dp), allocatable :: RWORK(:)
37  real(dp), allocatable :: yinit(:)
38  real(dp), allocatable :: pp(:) ! partial pressure
39 
40  ! model should be general, but physical properties and conductivity are
41  ! hardcoded for ngas=4
42  ngas=4
43  gasname(1)="O2"
44  gasname(2)="N2"
45  gasname(3)="CO2"
46  gasname(4)="CyP"
47  allocate(solmodel(ngas),diffmodel(ngas))
48  allocate(pp(ngas),sg(ngas),dg(ngas),xg(ngas),sheetsg(ngas),sheetdg(ngas))
49  allocate(pbg(ngas),kfoamxg(ngas),kgasxg(ngas))
50  allocate(sgmodena(ngas),sginputs(ngas),sgoutputs(ngas))
51  allocate(sgtemppos(ngas),sgxl1pos(ngas),sgxl2pos(ngas))
52  allocate(dgmodena(ngas),dginputs(ngas),dgoutputs(ngas),dgtemppos(ngas))
53  allocate(kgmodena(ngas),kginputs(ngas),kgoutputs(ngas),kgtemppos(ngas))
54 ! -----------------------------------
55 ! load inputs
56 ! -----------------------------------
57  call input
58 ! -----------------------------------
59 ! find out physical properties
60 ! -----------------------------------
61  dgas= gasdiffusivity(temp)
62  call createmodels(ngas)
63  eps=1-rhof/rhop
64  do i=1,ngas
65  if (solmodel(i)==1) then
66  sg(i)=solubility(temp,i)
67  endif
68  if (diffmodel(i)==1) then
69  dg(i)=diffusivity(temp,i)
70  endif
71  enddo
72  call print_header
73  sg=sg*rg*temp*1100._dp/(1e5*mg)
74  sheetsg=sheetsg*rg*temp*1100._dp/(1e5*mg)
75 ! -----------------------------------
76 ! Allocate memory for working arrays
77 ! -----------------------------------
78  if (sheet) then
79  ncell=nint((dfoam-dsheet)/(dcell+dwall))
80  else
81  ncell = nint(dfoam/(dcell+dwall))
82  print*, ncell
83  divsheet=0
84  endif
86  neq = ngas*nfv
87  allocate(ystate(1:neq))
88  allocate(yprime(1:neq))
89  allocate(dz(nfv))
90  allocate(mor(nfv))
91  allocate(dif(neq))
92  allocate(sol(neq))
93  allocate(bc(ngas))
94  allocate(yinit(ngas))
95 ! ----------------------------------
96 ! mesh and initial conditions
97 ! ----------------------------------
98  k=1
99  do i=1,divsheet
100  dz(k)=dsheet/divsheet
101  mor(k)=3
102  do l=1,ngas
103  dif(ngas*(k-1)+l)=sheetdg(l)
104  sol(ngas*(k-1)+l)=sheetsg(l)
105  ystate(ngas*(k-1)+l)=xg(l)*pressure/rg/temp
106  enddo
107  k=k+1
108  enddo
109  do i = 1, ncell
110  do j=1,divcell
111  dz(k)=dcell/divcell
112  mor(k)=1
113  do l=1,ngas
114  dif(ngas*(k-1)+l)=dgas
115  sol(ngas*(k-1)+l)=1
116  ystate(ngas*(k-1)+l)=xg(l)*pressure/rg/temp
117  enddo
118  k=k+1
119  enddo
120  do j=1,divwall
121  dz(k)=dwall/divwall
122  mor(k)=2
123  do l=1,ngas
124  dif(ngas*(k-1)+l)=dg(l)
125  sol(ngas*(k-1)+l)=sg(l)
126  ystate(ngas*(k-1)+l)=xg(l)*pressure/rg/temp
127  enddo
128  k=k+1
129  enddo
130  end do
131 ! ----------------------------------
132 ! boundary conditions
133 ! ----------------------------------
134  bc=pbg/rg/temp
135 ! ----------------------------------
136 ! initialize integration
137 ! ----------------------------------
138  lenrat = 2 ! usually for real(dp)
139  nnz = neq**2 ! nonzero elements - MV CHECK
140  lwm = 2*nnz + 2*neq + (nnz+10*neq)/lenrat ! MITER = 2
141  liw = 31 + neq + nnz +100
142  lrw = 20 + (2 + 1._dp/lenrat)*nnz + (11 + 9._dp/lenrat)*neq
143  mf = 222 ! 222 stiff, internally generated jacobi matrix
144  ! 10 'normal' - chage the allocation to smaller fields
145  ! 210 structure obtained NEQ+1 calls, implicit Adams,
146  allocate(rwork(1:lrw))
147  allocate(iwork(1:liw))
148  open(10,file='dcmp_progress.out', status='unknown')
149  counter = 1
150  itol = 1
151  rtol = 1.0e-10_dp
152  atol = 1.0e-6_dp
153  itask = 1
154  istate = 1
155  iopt = 0
156  multiplicator = 100
157 ! ----------------------------------
158 ! Integration loop
159 ! ----------------------------------
160  open (newunit(fi),file='keq_time.out')
161  write(fi,'(10A23)') '#time', 'eq_conductivity', 'total_pressure', 'p_O2', &
162  'p_N2', 'p_CO2', 'p_CP'
163  call output(0, 0.0_dp, ystate, neq, pp)
164  call equcond(keq,ystate,ngas,nfv,mor,eps,dcell,fstrut,temp_cond)
165  write(fi,'(10es23.15)') tbeg/(3600*24),keq*1.0e3_dp,sum(pp),pp
166  do i = 1, nroutputs*multiplicator ! stabilizing multiplicator
167  tin = dble(i-1)*(tend-tbeg)/dble(nroutputs*multiplicator)+tbeg
168  tout = dble(i )*(tend-tbeg)/dble(nroutputs*multiplicator)+tbeg
169 100 continue ! try to make another run for the initial step simulation
170  call dlsodes(modelpu, neq, ystate, tin, tout, itol, rtol, atol, itask,&
171  istate, iopt, rwork, lrw, iwork, liw, jdem, mf)
172  ! evaluating the integration
173  if (istate.lt.0) then
174  write(*,*) 'Something is wrong, look for ISTATE =', istate
175  if (istate.eq.-1) then ! not enough steps to reach tout
176  istate = 3
177  iopt = 1 ! start to change something
178  rwork(5:8)=0.0e0_dp
179  iwork(5) = 0
180  iwork(6) = counter*1000
181  iwork(7) = 0
182  counter = counter + 2
183  write(*,*) 'MAXSTEP', iwork(6)
184  write(10,*) 'MAXSTEP', iwork(6)
185  goto 100
186  endif
187  ! stop
188  elseif (counter>3) then
189  counter=counter-1
190  iwork(6) = counter*1000
191  write(*,*) 'MAXSTEP', iwork(6)
192  write(10,*) 'MAXSTEP', iwork(6)
193  endif
194  ! some output
195  if (mod(i,multiplicator).eq.0) then
196  write(*,'(2x,A,1x,f6.1,1x,A)') 'time:', tout/(3600*24),'days'
197  write(10,'(2x,A,1x,es9.3,1x,A)') 'time:', tout/(3600*24),'days'
198  call output(i/multiplicator, tout, ystate, neq, pp)
199  call equcond(keq,ystate,ngas,nfv,mor,eps,dcell,fstrut,temp_cond)
200  write(fi,'(10es23.15)') tout/(3600*24),keq*1e3,sum(pp),pp
201  endif
202  enddo
203  close(10)
204  close(fi)
205  call destroymodels(ngas)
206 end subroutine integrate
207 !***********************************END****************************************
208 end module integration
real(dp) dcell
cell size
Definition: globals.f90:20
integer divwall
number of grid points in wall
Definition: globals.f90:12
integer, dimension(:), allocatable solmodel
solubility model
Definition: globals.f90:16
real(dp), dimension(:), allocatable xg
molar fractions of gases
Definition: globals.f90:36
integer ngas
number of dissolved gases
Definition: globals.f90:29
real(dp), dimension(:), allocatable sheetsg
gas solubility in sheet
Definition: globals.f90:34
integer divcell
number of grid points in cell
Definition: globals.f90:13
real(dp) rhop
polymer density
Definition: globals.f90:49
real(dp) temp
temperature (K)
Definition: globals.f90:49
real(dp) tbeg
time at the end
Definition: globals.f90:19
real(dp) eps
foam porosity
Definition: globals.f90:30
integer, dimension(:), allocatable diffmodel
diffusivity model
Definition: globals.f90:17
real(dp), dimension(:), allocatable pbg
boundary conditions
Definition: globals.f90:37
real(dp), dimension(:), allocatable dz
spatial discretization
Definition: globals.f90:106
real(dp), dimension(:), allocatable pressure
partial pressure(Pa)
Definition: globals.f90:106
real(dp), dimension(:), allocatable dg
gas diffusiviy in polymer
Definition: globals.f90:33
real(dp) dfoam
foam thickness
Definition: globals.f90:22
real(dp) rhof
foam density
Definition: globals.f90:28
integer nroutputs
number of outer endme steps
Definition: globals.f90:11
real(dp) fstrut
strut content
Definition: globals.f90:27
real(dp), dimension(:), allocatable sheetdg
gas diffusivity in sheet
Definition: globals.f90:35
integer divsheet
number of grid points in sheet
Definition: globals.f90:14
real(dp), dimension(:), allocatable sg
gas solubility in polymer
Definition: globals.f90:32
integer ncell
number of cells
Definition: globals.f90:15
real(dp) dsheet
sheet thickness
Definition: globals.f90:23
real(dp) temp_cond
temperature of conductivity measurements
Definition: globals.f90:25
namespace with global variables
Definition: globals.f90:8
logical sheet
determines if sheet is used on the outside of the foam
Definition: globals.f90:10
real(dp) dgas
gas diffusivity in gasphase
Definition: globals.f90:31
real(dp) dwall
wall thickness
Definition: globals.f90:21
double tend
end time, s