MoDeNa  1.0
Software framework facilitating sequential multi-scale modelling
DFT-MF.f90
1 !WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW
2 !
3 !WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW
4 
5 SUBROUTINE dft
6 
7  USE parameters, ONLY: rgas, pi
9  USE eos_variables, ONLY: z3t
10  USE dft_module
11  use utilities
12  USE eos_numerical_derivatives, ONLY: subtract1
13  IMPLICIT NONE
14 
15  LOGICAL diagram
16  INTEGER :: i, j, kk, converg, discret, fa, outpt, irc
17  INTEGER :: ithick, idel, iab1, iab2 ! ,stepno
18  REAL, DIMENSION(-NDFT:NDFT) :: zp
19  REAL, DIMENSION(-NDFT:NDFT) :: rhop, rhop_o
20  REAL, DIMENSION(-NDFT:NDFT) :: mf_att
21  REAL ,DIMENSION(2) :: rhob
22  REAL :: end_x, steps, my0
23  REAL :: zz1
24  REAL :: integrand, dev
25  REAL :: omega, free, phs1, om1, pbulk, surftens
26  REAL :: zges(np), inte2, f01, rm
27  REAL :: tc, pc, rhoc, tsav ! ,attan ,myrho(-5000:5000)
28  REAL :: density(np), w(np,nc), lnphi(np,nc)
29  REAL :: cploc, dens_inv, dummy, cpcp
30  REAL :: intgrid(0:5000) ! ,utri(5000),intf(0:5000)
31  !-----------------------------------------------------------------------------
32 
33  num = 1
34  CALL set_default_eos_numerical
35 
36  wca = .false.
37  diagram =.true.
38 
39  CALL read_input
40 
41  ! T_st=t/parame(1,3)
42  ! IF (WCA) CALL Barker(T_st,d_hs)
43  ! IF (.NOT.WCA) CALL Barker_org(T_st,d_hs)
44  z3t = pi/6.0* parame(1,1) * ( 1.0 & ! divided by parame(i,2)**3
45  *(1.0-0.12*exp(-3.0*parame(1,3)/t)) )**3
46 
47  IF (ncomp /= 1) THEN
48  write(*,*)'SPECIFY ONLY ONE COMPONENT IN THE INPUT-FILE:'
49  write(*,*)' ./input_file/INPUT.INP'
50  stop
51  ENDIF
52 
53  !-----------------------------------------------------------------------------
54  ! The truncated and shifted LJ-potential is considered
55  ! The attractive part of this potential is defined by:
56  ! u(r) = - epsilon - TAU for 0 < r < rm
57  ! u(r) = 4*epsilon*(r**-12 - r**-6) - TAU for rm< r < rc
58  ! u(r) = 0. for r > rc
59  ! rm=2**(1/6) corresponds to the minimum of full LJ-potential
60  ! rc=7.5 is the cut-off distance (both values dimensionless)
61  ! (-TAU) is the value by which the potetial is shifted upwards,
62  ! with TAU=4*epsilon*(rc**-12 - rc**-6)
63  !-----------------------------------------------------------------------------
64  rc = 4.0
65  rm = 2.0**(1.0/6.0)
66  tau_cut = 4.0*(rc**(-12)-rc**(-6))
67 
68  !-----------------------------------------------------------------------------
69  ! basic definitions for calculating density profile,
70  !-----------------------------------------------------------------------------
71  discret= 1200 ! number of spacial discretizations for profile
72  fa = 40 ! size of the box is discret/fa * sigma
73  ! (with sigma: LJ diameter)
74  ! fa is here dimensionless, however
75  dzp = 1.0/REAL(fa) ! dimensionless grid-distance dzp*=dzp/sigma
76  ! grid-size dzp = zp(1)-zp(0)
77  outpt = 10 ! number output-points = discret/outpt
78 
79  !-----------------------------------------------------------------------------
80  ! prepare for phase equilibrium calculation for given T
81  !-----------------------------------------------------------------------------
82  diagram_condition: DO
83  nphas = 2
84  n_unkw = ncomp ! number of quantities to be iterated
85  it(1)='p' ! iteration of pressure
86 
87  val_init(1) = 0.45 ! starting value for liquid density
88  val_init(2) = 1.e-6 ! starting value for vapor density
89  val_init(3) = t ! value of temperature
90  val_init(4) = 1.0 ! default starting value for P
91  IF (eos >= 4) val_init(4) = 1.e-3 ! default starting value for LJ-model
92  val_init(5) = 0.0 ! logar. mole fraction: lnx=0, x=1, phase 1
93  val_init(6) = 0.0 ! logar. mole fraction: lnx=0, x=1, phase 2
94 
95  running = 't' ! T is running variable in PHASE_EQUILIB - here T=const.
96  end_x = t ! end temperature - here T=const.
97  steps = 1.0 ! number of steps of running var. - here 1, since T=const.
98 
99  outp = 0 ! output to terminal
100  !--------------------------------------------------------------------------
101  ! calculate phase equilibrium for given T
102  !--------------------------------------------------------------------------
103  find_equil: DO
104  ensemble_flag = 'tp' ! this flag is for: 'regular calculation'
105  CALL phase_equilib(end_x,steps,converg)
106  IF (converg == 1) THEN
107  EXIT find_equil
108  ELSE
109  val_init(3) = t - 10.0 ! value of temperature
110  steps = 2.0 ! number of steps of running var. - here 1, since T=const.
111  write (*,*) 'no VLE found'
112  ENDIF
113  END DO find_equil
114  CALL si_dens (density,w)
115  rhob(1) = dense(1)/z3t ! coexisting bulk density L
116  rhob(2) = dense(2)/z3t ! coexisting bulk density V
117  write (*,*) 'densities ',rhob(1),rhob(2)
118 
119  ! (re-)calculate residual chemical potential of both phases
120  ensemble_flag = 'tv' ! this flag is for: my_res=my_res(T,rho)
121  CALL fugacity (lnphi)
122  my0 = lnphi(1,1)
123  zges(1) = p / (rgas *t *density(1)) * mm(1)/1000.0
124  zges(2) = p / (rgas *t *density(2)) * mm(1)/1000.0
125 
126  pbulk = zges(1)*rhob(1) ! pressure p/kT (= Z*rho)
127  write (*,*) 'chem. potentials',lnphi(1,1),lnphi(2,1)
128  ! write (*,*) 'pressures p/kT ',zges(1)*rhob(1),zges(2)*rhob(2)
129  ! write (*,*) 'pressures p ',p
130  write (*,*) ' '
131 
132  !--------------------------------------------------------------------------
133  ! define initial density profile rhop(i)
134  ! and dimensionless space coordinates zp(i)
135  !
136  ! discret : number of grid-points within "the box"
137  ! irc : number of grid-points extending the the box to left and right
138  ! the box is extended in order to allow for numerical integration
139  ! 'irc' is determined by the cut-off distance 'rc'
140  ! IAB1,IAB2: help-integers allowing a linear initial density profile in
141  ! vicinity of the box-center
142  !--------------------------------------------------------------------------
143  irc = nint(rc/dzp) + 1
144  ithick = discret / 2
145  idel = discret / 10
146  ithick = ithick + 1
147  iab2 = ithick + idel/2
148  iab1 = ithick - idel/2
149  do i = -irc, iab1
150  zp(i) = REAL(i) * dzp
151  rhop(i) = rhob(1)
152  END do
153  do i = iab1+1, iab2
154  zp(i) = REAL(i) * dzp
155  rhop(i) = rhob(1) - (rhob(1) - rhob(2)) *REAL(I-IAB1) / REAL(iab2-iab1)
156  end do
157  do i = iab2, discret+irc
158  zp(i) = REAL(i) * dzp
159  rhop(i) =rhob(2)
160  end do
161 
162  !--------------------------------------------------------------------------
163  ! Initialize the DENS_INV subroutine
164  !--------------------------------------------------------------------------
165  nphas = 1
166 
167  cpcp = 1.e7
168  ensemble_flag = 'tv' ! this flag is for: my_res=my_res(T,rho)
169  subtract1 = '1PT' ! this flag is for: 'minus 1st order pert. theory' for chem. pot.
170 
171  dummy = dens_inv(cpcp)
172 
173 
174  !--------------------------------------------------------------------------
175  ! Start iterating the density profile
176  !--------------------------------------------------------------------------
177  kk=1
178  converge_profile: DO
179 
180  DO i=0,discret
181  ! dense(1) = rhop(i)*z3t
182  ! densta(1) = rhop(i)*z3t
183 
184  ! -------------------------------------------------------------------
185  ! the residual chemical pot. that is treated with a LDA is here calculated.
186  ! this part together with 'my_att' gives the functional derivative of Fres to rho(z)
187  ! -------------------------------------------------------------------
188  ! CALL FUGACITY (lnphi)
189  ! myrho(i) = lnphi(1,1)
190 
191  ! inte = 0.0
192  inte2 = 0.0
193  f01 = 0.0
194  DO j=-irc,discret+irc
195  zz1 = abs(zp(j)-zp(i))
196  IF (wca) THEN
197  IF (zz1 > rm .AND. zz1 <= rc)THEN
198  integrand= 0.4*(zz1**(-10)-rc**(-10)) &
199  -(zz1**(-4 )-rc**(-4 )) &
200  +tau_cut/2.0*(zz1**2 -rc**2 )
201  ELSEIF (zz1 <= rm) THEN
202  integrand= 0.40*(rm**(-10)- rc**(-10)) &
203  - (rm**(-4) - rc**(-4)) &
204  +0.5*(zz1**2- rm**2 ) &
205  +tau_cut/2.0*(zz1**2 -rc**2 )
206  ELSE
207  integrand= 0.0
208  ENDIF
209  ELSE
210  IF (zz1 > 1.0 .AND. zz1 <= rc) THEN
211  integrand= 0.4*(zz1**(-10)-rc**(-10)) &
212  -(zz1**(-4 )-rc**(-4 )) &
213  +tau_cut/2.0*(zz1**2-rc**2)
214  ELSEIF (zz1 <= 1.0) THEN
215  integrand= 0.4*(1.0- rc**(-10)) &
216  - (1.0 - rc**(-4)) &
217  +tau_cut/2.0*(1.0-rc**2)
218  ELSE
219  integrand= 0.0
220  ENDIF
221  ENDIF
222  intgrid(j+irc) = rhop(j)* integrand
223  inte2=inte2+dzp*(intgrid(j+irc)+f01)/2.0
224  f01 = intgrid(j+irc)
225  ENDDO
226 
227  !--------------------------------------------------------------------
228  ! The integration of the DFT-integral is done with cubic splines
229  !--------------------------------------------------------------------
230  ! stepno = discret+irc*2
231  ! CALL SPLINE_PARA (dzp,intgrid,utri,stepno)
232  ! CALL SPLINE_INT (inte,dzp,intgrid,utri,stepno)
233 
234 
235  !--------------------------------------------------------------------
236  ! the attractive part of the chemical potential
237  ! mf_att(i) = d(F_att)/d(rho*)
238  ! where F_att is attractive part of the intrinsic Helmholtz energy
239  ! and where rho*=rhop(i) denotes the dimensionless density.
240  ! parame(1,3) is epsilon/k (LJ-energy parameter)
241  ! parame(1,2) is sigma (LJ-size parameter)
242  !--------------------------------------------------------------------
243  mf_att(i) = -2.0*pi*parame(1,3)/t*parame(1,1)**2 *inte2
244  ! if (REAL(i)/REAL(outpt) == REAL(INT(i/outpt))) &
245  ! write(*,*) i,rhop(i), -( myrho(i)-mf_att(i)-my0 ),inte/rhop(i)
246  ENDDO
247 
248 
249  dev = 0.0
250  DO i=0,discret
251  rhop_o(i) = rhop(i)
252  !--------------------------------------------------------------------
253  ! LDA - Inversion Procedure according to R.Evans, Bristol
254  !--------------------------------------------------------------------
255  cploc = my0 + mf_att(i)
256  rhop(i) = dens_inv(cploc)
257  ! write (*,*) i,rhop_o(i),rhop(i)
258  ! read (*,*)
259  ! attan = 0.5
260  ! rhop(i) = rhop_o(i)*(1.0-attan)+rhop(i)*attan
261  dev = dev + (rhop(i)-rhop_o(i))**2
262  ENDDO
263 
264 
265  kk=kk+1
266  write (*,*) kk,dev
267 
268  IF (dev >= 4.e-8 .AND. kk <= 50) cycle converge_profile
269  IF (kk > 50) write (*,*) ' no convergence in 50 steps'
270  EXIT converge_profile
271  END DO converge_profile
272 
273  !--------------------------------------------------------------------------
274  ! write resulting density profile
275  !--------------------------------------------------------------------------
276  write (68,'(i3,66(f18.8))') 0,zp(0)-zp(int(discret/2)),rhop(0),t, &
277  val_conv(4)/1.e5,density(1),density(2)
278  DO i=0,discret
279  IF (REAL(i)/REAL(outpt) == real(int(i/outpt))) &
280  write (68,'(i6,3(f18.10))') i,zp(i)-zp(int(discret/2)),rhop(i)
281  ! IF (REAL(i)/REAL(outpt) == REAL(INT(i/outpt))) &
282  ! write (*,'(i6,3(f18.12))') i,zp(i)-zp(INT(discret/2)),rhop(i)
283  ENDDO
284  write (68,*) ' '
285 
286  !--------------------------------------------------------------------------
287  ! calculate surface tension
288  !--------------------------------------------------------------------------
289  free =0.0
290  DO i=1,discret
291  dense(1) = rhop(i)*z3t
292  densta(1) = rhop(i)*z3t
293  ! call CPHS(ro1,fmh,zmh,hsmy)
294  CALL fugacity (lnphi)
295  phs1 = dense(1)/z3t*z_ges ! phs must be p/kT
296  om1 = lnphi(1,1) - my0 - mf_att(i)/2.0
297  omega = pbulk - phs1 + dense(1)/z3t*om1 ! Pbulk must be p/kT
298  free = free + omega*dzp
299  END DO
300  surftens = 1.380662* t *free /parame(1,2)**2
301  write (*,*) ' '
302  write (*,*) 'Temp. [K], Pressure [bar] ',t,val_conv(4)/1.e5
303  write (*,*) 'Density [kg/m**3] ',density(1),density(2)
304  write (*,*) 'Dimensionless Density (rho*) ',rhob(1),rhob(2)
305  write (*,*) 'Excess Grand Potential ',free
306  write (*,*) 'Interfacial Tension [mN/m] = ',surftens
307  write (*,*) ' '
308  write (69,'(7(f18.10))') t,val_conv(4)/1.e5, &
309  density(1),density(2),surftens,free,dev
310 
311  !--------------------------------------------------------------------------
312  ! calculate phase diagram and diagram of surface tension
313  !--------------------------------------------------------------------------
314  IF (diagram) THEN
315  tc=t
316  ensemble_flag = 'tp'
317  subtract1 = 'no'
318  tsav=t
319  IF (eos < 4 .AND. val_conv(4) > 1.e6) CALL critical (tc,pc,rhoc)
320  ! IF (eos >= 4 .AND. eos /= 7) CALL LJ_CRITICAL (tc,pc,rhoc)
321  t=tsav
322  IF (val_conv(4) > 1.e6) THEN
323  write (*,'(a,3(f16.4))') 'critical point',tc,pc/1.e5,rhoc
324  write (*,*) ' '
325  ENDIF
326  IF (val_conv(4) < 1.e6) tc=1000.0
327  IF ((t+2.5) <= tc) THEN
328  t=t+2.0
329  IF ((t+8.0) <= tc) t=t+3.0
330  IF ((t+25.0) <= tc) t=t+15.0
331  val_init(3) = t ! value of temperature
332  end_x = t ! end temperature - here T=const.
333  steps = 1.0 ! number of steps of running var. - here 1, since T=const.
334  nphas = 2
335  z3t = pi/6.0* parame(1,1) * ( 1.0 & ! divided by parame(i,2)**3
336  *(1.0-0.12*exp(-3.0*parame(1,3)/t)) )**3
337  cycle diagram_condition
338  ENDIF
339  IF(tc /= 1.e3)write(69,'(6(f18.10))')tc,pc/1.e5,rhoc,rhoc,0.,0.
340  ENDIF
341  EXIT diagram_condition
342  END DO diagram_condition
343 
344 END SUBROUTINE dft
345 
346 
347 !WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW
348 !
349 !WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW
350 
351 SUBROUTINE tridiag (a,b,c,r,u,n)
352 
353  USE utilities
354  IMPLICIT NONE
355 
356  !-----------------------------------------------------------------------------
357  INTEGER :: n
358  REAL :: a(n),b(n),c(n),r(n),u(n)
359 
360  !-----------------------------------------------------------------------------
361  INTEGER, PARAMETER :: nmax = 5000
362  INTEGER :: j
363  REAL :: bet, gam(nmax)
364  !-----------------------------------------------------------------------------
365 
366  bet = b(1)
367  u(1) = r(1)/bet
368  DO j = 2,n
369  gam(j) = c(j-1)/bet
370  bet = b(j)-a(j)*gam(j)
371  IF (bet == 0.0) call paus ('TRIDIAG failed')
372  u(j) = (r(j)-a(j)*u(j-1))/bet
373  END DO
374  DO j = n-1,1,-1
375  u(j) = u(j) - gam(j+1)*u(j+1)
376  END DO
377 
378 END SUBROUTINE tridiag
379 
380 
381 !WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW
382 ! SUBROUTINE SPLINE_PARA
383 !
384 ! Considered are cubic splines of the form
385 ! P(i) = alpha(i)
386 ! + beta(i) *(x-x0(i))
387 ! + gamma(i)*(x-x0(i))**2
388 ! + delta(i)*(x-x0(i))**3 for i= (0 , stepno-1 )
389 !
390 ! parameters of the tridiagonal matrix ( M * utri = rtri )
391 ! with matrix-elements: m(j+1,j) = ctri(j) fuer alle j
392 ! m(j,j) = btri(j) fuer alle j
393 ! m(j-1,j) = atri(j) fuer j >= 2
394 ! where u(i) = gamma(i) (defined for i=(1,stepno-2)) and gamma(0)=0
395 !WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW
396 
397 SUBROUTINE spline_para (dzp,intgrid,utri,stepno)
398 
399  IMPLICIT NONE
400 
401  !-----------------------------------------------------------------------------
402  INTEGER :: stepno,j
403  REAL :: dzp
404  REAL, DIMENSION(5000) :: atri, btri, ctri, rtri, utri
405  REAL, DIMENSION(0:5000) :: intgrid
406  !-----------------------------------------------------------------------------
407 
408 
409  ! intgrid(index) is the function-value of the spline-grid at the
410  ! grid-point 'index'
411  ! dzp is the distance of the grid-points
412  DO j = 1, (stepno-1)
413  atri(j) = dzp
414  btri(j) = 4.0*dzp
415  ctri(j) = dzp
416  rtri(j) = 3.0/dzp*(intgrid(j+1)-2.0*intgrid(j)+intgrid(j-1))
417  ENDDO
418 
419  CALL tridiag (atri,btri,ctri,rtri,utri,(stepno-1))
420 
421 END SUBROUTINE spline_para
422 
423 
424 !WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW
425 !
426 !WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW
427 
428 SUBROUTINE spline_coeff(beta,gamma,delta,dzp,intgrid,utri,stepno)
429 
430  IMPLICIT NONE
431 
432  !-----------------------------------------------------------------------------
433  INTEGER :: stepno, j
434  REAL :: dzp, utri(5000)
435  REAL, DIMENSION(0:5000) :: intgrid, beta, gamma, delta
436  !-----------------------------------------------------------------------------
437 
438  beta(0) = (intgrid(1)-intgrid(0))/dzp - dzp/3.0*utri(1)
439  gamma(0) = 0.0
440  delta(0) = (utri(1)-0.0)/(3.0*dzp)
441  DO j = 1, (stepno-2)
442  gamma(j)= utri(j)
443  beta(j) = (intgrid(j+1)-intgrid(j))/dzp - dzp/3.0*(utri(j+1)+2.0*utri(j))
444  delta(j)= (utri(j+1)-utri(j))/(3.0*dzp)
445  END DO
446  gamma(stepno-1)= utri(stepno-1)
447  beta(stepno-1) = (intgrid(stepno)-intgrid(stepno-1))/dzp - dzp/3.0*(0.0+2.0*utri(stepno-1))
448  delta(stepno-1)= (0.0-utri(stepno-1))/(3.0*dzp)
449 
450  ! Integration over splines
451  ! I1=0.0
452  ! DO j= 0,(stepno-1)
453  ! I1 = I1 + intgrid(j)*dzp +0.5*beta(j)*dzp**2 +1.0/3.0*gamma(j)*dzp**3 +0.25*delta(j)*dzp**4
454  ! ENDDO
455 
456 END SUBROUTINE spline_coeff
457 
458 
459 !WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW
460 !
461 !WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW
462 
463 SUBROUTINE spline_int(INTEGRAL,dzp,intgrid,utri,stepno)
464 
465  IMPLICIT NONE
466 
467  !-----------------------------------------------------------------------------
468  INTEGER stepno,j
469  REAL :: dzp, integral, utri(5000)
470  REAL, DIMENSION(0:5000) :: intgrid, beta, gamma, delta
471  !-----------------------------------------------------------------------------
472 
473  beta(0) = (intgrid(1)-intgrid(0))/dzp - dzp/3.0*utri(1)
474  gamma(0) = 0.0
475  delta(0) = (utri(1)-0.0)/(3.0*dzp)
476  DO j = 1, (stepno-2)
477  gamma(j)= utri(j)
478  beta(j) = (intgrid(j+1)-intgrid(j))/dzp - dzp/3.0*(utri(j+1)+2.0*utri(j))
479  delta(j)= (utri(j+1)-utri(j))/(3.0*dzp)
480  END DO
481  gamma(stepno-1)= utri(stepno-1)
482  beta(stepno-1) = (intgrid(stepno)-intgrid(stepno-1))/dzp &
483  - dzp/3.0*(0.0+2.0*utri(stepno-1))
484  delta(stepno-1)= (0.0-utri(stepno-1))/(3.0*dzp)
485 
486  ! Integration over splines
487  integral = 0.0
488  DO j= 0,(stepno-1)
489  integral = integral + intgrid(j)*dzp +0.5*beta(j)*dzp**2 &
490  +1.0/3.0*gamma(j)*dzp**3 +0.25*delta(j)*dzp**4
491  ENDDO
492 
493 END SUBROUTINE spline_int
494 
495 
496 !WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW
497 ! FUNCTION DENS_INV
498 !
499 ! INVERSION OF HARD SPHERE CHEMICAL POTENTIAL
500 ! routine: R. Evans, Bristol
501 !WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW
502 
503 REAL FUNCTION dens_inv(CPCP)
504 
505  USE basic_variables
506  USE eos_variables, ONLY: z3t
507  IMPLICIT None
508 
509  !-----------------------------------------------------------------------------
510  INTEGER :: l, n, i, ii, j, k, kk
511  INTEGER :: nn(3)
512  REAL :: dl(3), dm(3), dmm(3)
513  REAL :: b(10), c(10), d(10)
514  REAL :: a(10,3)
515  REAL :: cpcp, cp, df, di, s, hsmy, lnphi(np,nc)
516 
517  common/help/ a,b,c,d,dmm
518  DATA dm / 0.0, 0.0, 10.0 /
519  DATA dl / 0.1, 0.6, 0.95 /
520  DATA nn / 8, 10, 8 /
521  !-----------------------------------------------------------------------------
522 
523  dl(1) = 0.1 /parame(1,1)
524  dl(2) = 0.6 /parame(1,1)
525  dl(3) = 0.95 /parame(1,1)
526 
527  ! EXTERNAL CPHS
528  cp = cpcp
529  IF (cpcp >= 1.e6) THEN
530  t=1.e-6 /parame(1,1)
531  DO l=1,3
532  n=nn(l)
533  di=df
534  df=dl(l)
535  !-----------
536  dense(1) = di*z3t
537  densta(1) = di*z3t
538  CALL fugacity (lnphi)
539  hsmy=lnphi(1,1)
540  !-----------
541  ! call cphs(DI,fhs,zhs,hsmy)
542  dmm(l)=hsmy
543  DO i=1,n
544  d(i)=di+(df-di)/(REAL(n)-1.0)*(REAL(i)-1.0)
545  !-----------
546  dense(1) = d(i)*z3t
547  densta(1) = d(i)*z3t
548  CALL fugacity (lnphi)
549  hsmy=lnphi(1,1)
550  !-----------
551  ! call cphs(d(i),fhs,zhs,hsmy)
552  c(i)=hsmy-dm(l)
553  IF (l == 1) c(i)=exp(c(i))
554  a(i,l)=0.0
555  END DO
556  DO i=1,n
557  s=1.0
558  b(2:n)=0.0
559  b(1)=1.0
560  DO j=1,n
561  IF (j == i) EXIT
562  s=s/(c(i)-c(j))
563  DO kk=2,n
564  k=n-kk+2
565  b(k)=b(k-1)-c(j)*b(k)
566  END DO
567  b(1)=-c(j)*b(1)
568  END DO
569  DO k=1,n
570  a(k,l)=a(k,l)+d(i)*s*b(k)
571  END DO
572  END DO
573  END DO
574  dens_inv=0.0
575  ELSE
576  dens_inv=0.0
577  IF (cp >= dmm(1)) THEN
578  l=1
579  IF (cp > dmm(2)) l=2
580  IF (cp > dmm(3)) l=3
581  IF (l == 1) cp=exp(cp)
582  cp=cp-dm(l)
583  n=nn(l)
584  dens_inv=a(n,l)
585  DO i=2,n
586  ii=n-i+1
587  dens_inv=dens_inv*cp+a(ii,l)
588  END DO
589  END IF
590  END IF
591 
592 END FUNCTION dens_inv
593 
594 !WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW
595 ! SUBROUTINE Barker_org(T_st,d_hs)
596 !
597 ! calculation of BARKER-HENDERSON effecive diameter dbh
598 ! using the direct numerical integration
599 !WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW
600 
601 SUBROUTINE barker_org(T_st,d_hs)
602 
603  IMPLICIT NONE
604 
605  !-----------------------------------------------------------------------------
606  INTEGER :: kint, j
607  REAL :: gint, summ, xsig, eux, add, xinv
608  REAL :: x6, u0, u0r, d_hs, epst, t_st, rm
609  !-----------------------------------------------------------------------------
610 
611  epst = 1.0 / t_st
612  rm = 1.0
613  kint = 200
614  gint = REAL(kint)
615  summ = 1.0 / (2.0 * gint)
616  DO j = 1, kint
617  xsig = REAL(j) /gint * rm
618  IF ( xsig < 0.5 ) then
619  eux = 0.0
620  ELSE
621  xinv = 1.0 / xsig
622  x6 = xinv**6
623  u0 = 4.0 * x6 * (x6-1.0)
624  u0r = u0 * epst
625  IF ( u0r > 20.0 ) THEN
626  eux =0.0
627  ELSE
628  eux =exp( -u0r )
629  END IF
630  END IF
631  add = (1.0-eux) / gint
632  summ = summ + add
633  END DO
634  summ = summ - add/2.0
635  d_hs = rm*summ
636  ! dbh = gam*sig
637 
638 END SUBROUTINE barker_org
639 
640 
WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW This module contains constant...
Definition: modules.f90:6
WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW Module DFT_MODULE This module...
Definition: modules.f90:272
WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW This module contains paramete...
Definition: modules.f90:120
program dft
Main program.
Definition: Main.F90:66
WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW This module contains paramete...
Definition: modules.f90:29
WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW This module contains paramete...
Definition: modules.f90:220