MoDeNa  1.0
Software framework facilitating sequential multi-scale modelling
DFT-nMF-units.f90
1 !WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW
2 ! SUBROUTINE DFT_nMFT2
3 !
4 ! This subroutine performs a DFT calculation of the PCP-SAFT model using
5 ! the fundamental measure theory (FMT) for the hard-sphere fluid, the
6 ! TPT1-theory for chain formation and a first (or second) order perturba-
7 ! tion theory for the dispersive interactions.
8 !
9 ! Background to the code:
10 ! The functional derivative of d(F)/d(rho) is done in two parts, as
11 ! 'myrho(i) + mu_att(i)' , where 'mu_att' comprises the perturbation
12 ! theory (dispersive attraction) as well as the non-local part of the hard-
13 ! sphere term and chain term. For the hard-sphere term mu_att contains
14 ! contributions of the form mu_FMT = d(F^hs)/d(rho*) - (dF^hs/drho*)_LDA,
15 ! where the index 'hs' is for hard-sphere (analogous for the chain term)
16 ! and 'LDA' is for 'local density approximation', i.e. the values for the
17 ! local density.
18 !
19 ! The term 'myrho' contains the hard-sphere term and the chain term in
20 ! the LDA. Because the PC-SAFT dispersion term is not identical to the
21 ! Barker-Henderson (BH) perturtation theory (first or second order) for
22 ! LJ fluids, the term 'myrho' also contains the difference of the PC-SAFT
23 ! dispersion contribution and the BH perturbation theory used here the
24 ! LDA. This difference is obtained by using the flag {subtract1 = '1PT'}
25 ! the effect of the flag is that the BH-perturbation theory is subtracted
26 ! from the PC-SAFT model for calculating 'myrho'.
27 !
28 ! Caution: the indication for using the second order term in the pertur-
29 ! bation expansion is currently soley given by the flag {subtract1 = '2PT'}
30 ! The second order case needs to be re-tested before usage !
31 !WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW
32 
33 SUBROUTINE dft_nmft_units
34 
35  USE parameters, ONLY: pi, rgas, kbol
36  USE basic_variables
37  USE eos_variables, ONLY: fres, eta, rho, x, z3t
38  USE dft_module
39  use utilities
40  use eos_polar, only: f_polar, phi_polar
42 
43  IMPLICIT NONE
44 
45  !-----------------------------------------------------------------------------
46  INTEGER :: i, j, kk, converg
47  INTEGER :: discret, fa, outpt, irc, maxiter, ih
48  LOGICAL :: diagram
49  REAL, DIMENSION(-NDFT:NDFT) :: zp, rhop, rhop_o
50  REAL, DIMENSION(-NDFT:NDFT) :: df_drho_tot, f_tot
51  REAL, DIMENSION(-NDFT:NDFT) :: df_drho_att, f_att
52  REAL, DIMENSION(2) :: rhob
53  REAL :: f_disp_1pt, f_disp_pcsaft
54  REAL :: mu_disp_1pt, mu_disp_pcsaft
55  REAL :: zges(np), pbulk
56  REAL :: msegm, delta_st, tanhfac
57  REAL :: end_x, steps, my0
58  REAL :: f_int_z, mu_int_z
59  REAL :: f_int_r, mu_int_r
60  REAL :: f_int2_z, mu_int2_z, mu_int3_z
61  REAL :: f_int2_r, mu_int2_r, mu_int3_r
62  REAL :: zz1
63  REAL :: dz_local
64  REAL :: dev, maxdev
65  REAL :: delta_f, free
66  REAL :: surftens(0:200), st_macro(200)
67  REAL :: f01, f02, f03, f04, f05
68  REAL :: c1_con, c2_con
69  REAL :: zms, z3
70  REAL :: tsav, psav, tc, pc, rhoc
71  REAL :: density(np), w(np,nc), lnphi(np,nc)
72  REAL :: damppic
73  REAL :: box_l_no_unit
74  REAL, DIMENSION(-NDFT:NDFT) :: lambda, rhobar, phi_dn0, phi_dn1
75  REAL, DIMENSION(-NDFT:NDFT) :: phi_dn2, phi_dn3, phi_dn4, phi_dn5
76  REAL, DIMENSION(0:5,-NDFT:NDFT) :: ni
77  REAL :: zs
78  REAL :: f_ch, df_drho_ch
79  REAL :: f_fmt, df_drho_fmt
80  REAL :: mu_assoc, f_assoc
81  REAL :: fres_polar, fdd, fqq, fdq
82  REAL :: mu_polar, fdd_rk, fqq_rk, fdq_rk, z3_rk
83  !-----------------------------------------------------------------------------
84  ! note: variable ensemble_flag = 'tp' is set for calculating: mu_res=mu_res(T,p)
85  ! note: variable ensemble_flag = 'tv' is set for calculating: mu_res=mu_res(T,rho)
86  ! note: variable subtract1 = 'no' is set for regular calculations
87  ! note: variable subtract1 = '1PT' is set for calculating properties subtracting a
88  ! first order perturbation term (dispersion)
89 
90  num = 1
91  CALL set_default_eos_numerical
92 
93 
94  wca = .false.
95  shift = .false.
96  diagram = .true.
97 
98  CALL read_input
99  msegm = parame(1,1)
100 
101 
102  d_hs = parame(1,2) * ( 1.0 - 0.12*exp( -3.0*parame(1,3)/t ) )
103  dhs_st = d_hs/parame(1,2)
104  z3t_st = pi/6.0* parame(1,1) * d_hs**3
105 
106  IF ( ncomp /= 1 ) THEN
107  write (*,*)'SPECIFY ONLY ONE COMPONENT IN THE INPUT-FILE:'
108  write (*,*)' ./input_file/INPUT.INP'
109  stop
110  END IF
111  OPEN (68,file = './output_file/DFT_profiles.xlo')
112  OPEN (69,file = './output_file/DFT_sigma.xlo')
113  OPEN (71,file = './output_file/DFT_iteration.xlo')
114  OPEN (72,file = './output_file/DFT_h.xlo')
115 
116 
117  !-----------------------------------------------------------------------------
118  ! The cut-off distance rc is the max. distance for integrating inter-
119  ! actions. Beyond rc, tail-corrections are added.
120  !-----------------------------------------------------------------------------
121  rc = 9.0 ! dimensionless cut-off distance rc = r_c/sigma
122 
123 
124  !-----------------------------------------------------------------------------
125  ! basic definitions for calculating density profile,
126  !-----------------------------------------------------------------------------
127  ! grid-size dzp = zp(1)-zp(0)
128 
129  box_l_no_unit = 160.0 ! lenth of simulation box (Angstrom)
130  discret= 1000 ! number of spacial discretizations for profile
131  dzp = box_l_no_unit / REAL(discret) ! grid-distance (Angstrom)
132  fa = nint( parame(1,2) / dzp + 1 ) ! number of steps per sigma (currently of component 1)
133  outpt = 100 ! number output-points = discret/outpt
134 
135 
136  !-----------------------------------------------------------------------------
137  ! definitions for the numerical algorithm
138  !-----------------------------------------------------------------------------
139 
140  maxiter = 100 ! maximum number of iterations per temp.step
141  maxdev = 2.e-7 ! maximum deviation
142  damppic = 0.005 ! damping of Picard-iteration
143 
144 
145  !-----------------------------------------------------------------------------
146  ! get a matrix of values for the pair correlation function g(r,rho)
147  !-----------------------------------------------------------------------------
148 
149  rg = 4.0
150  den_step = 40
151  !dzr = dzp / 2.0 ! dimensionless grid-distance for integrating
152  ! ! the Barker-Henderson attraction term
153  dzr = 0.025 ! dimensionless grid-distance for integrating
154  ! the Barker-Henderson attraction term
155  CALL rdf_matrix_units (msegm)
156 
157 
158  !-----------------------------------------------------------------------------
159  ! prepare for phase equilibrium calculation for given T
160  !-----------------------------------------------------------------------------
161 
162  diagram_for_various_t_loop: DO
163 
164  nphas = 2
165  n_unkw = ncomp ! number of quantities to be iterated
166  it(1) = 'p' ! iteration of pressure
167 
168  val_init(1) = 0.45 ! starting value for liquid density
169  val_init(2) = 1.e-5 ! starting value for vapor density
170  val_init(3) = t ! value of temperature
171  val_init(4) = 10.0 ! default starting value for p in (Pa)
172  IF ( eos >= 4 ) val_init(4) = 1.e-3 ! default starting value for LJ-model
173  val_init(5) = 0.0 ! logar. mole fraction: lnx=0, x=1, phase 1
174  val_init(6) = 0.0 ! logar. mole fraction: lnx=0, x=1, phase 2
175 
176  running = 't' ! T is running variable in PHASE_EQUILIB - here T=const.
177  end_x = t ! end temperature - here T=const.
178  steps = 1.0 ! number of steps of running var. - here 1, since T=const.
179 
180  outp = 0 ! output to terminal
181 
182 
183  !--------------------------------------------------------------------------
184  ! calculate phase equilibrium for given T
185  !--------------------------------------------------------------------------
186 
187  converg = 0
188  DO WHILE ( converg == 0 )
189  ensemble_flag = 'tp' ! this flag is for: 'regular calculation'
190  CALL phase_equilib( end_x, steps, converg )
191  IF ( converg /= 1 ) THEN
192  val_conv(2) = 0.0
193  val_init(3) = t - 10.0 ! value of temperature
194  IF ( val_conv(4) /= 0.0 ) val_init(4) = val_conv(4) / 4.0
195  ! caution: the intermediate points calculated here are not correct, because
196  ! the temperature-dependent props like d_BH, g(r), or z3t are not evaluated
197  ! for every temp-step. The final converged result, however, is correct.
198  steps = 2.0 ! number of steps of running var.
199  WRITE (*,*) 'no VLE found'
200  IF ( val_init(3) <= 10.0 ) RETURN
201  END IF
202  END DO
203 
204  ! rhob: molecular density times sigma**3 (rho_molec*sigma**3)
205  rhob(1) = dense(1)/z3t_st ! coexisting bulk density L
206  rhob(2) = dense(2)/z3t_st ! coexisting bulk density V
207  WRITE (*,*) 'temperature ',t,p/1.e5
208  WRITE (*,*) 'densities ',rhob(1), rhob(2)
209  WRITE (*,*) 'dense ',dense(1),dense(2)
210 
211 
212  ! --- get density in SI-units (kg/m**3) -----------------------------------
213  CALL si_dens ( density, w )
214 
215 
216  ! --- (re-)calculate residual chemical potential of both phases -----------
217  ensemble_flag = 'tv' ! this flag is for: mu_res=mu_res(T,rho)
218  densta(1) = dense(1) ! Index 1 is for liquid density (here: packing fraction eta)
219  densta(2) = dense(2) ! Index 2 is for vapour density (here: packing fraction eta)
220  CALL fugacity (lnphi)
221  my0 = lnphi(1,1) + log( rhob(1) ) ! my0 = mu_res(T,rho_bulk_L) + ln(rho_bulk_l)
222  zges(1) = p / ( rgas*t*density(1) ) * mm(1)/1000.0
223  zges(2) = p / ( rgas*t*density(2) ) * mm(1)/1000.0
224 
225  pbulk = zges(1) * rhob(1) ! pressure p/kT (= Z*rho)
226  WRITE (*,*) 'chem. potentials', lnphi(1,1) + log( rhob(1) ), &
227  lnphi(2,1) + log( rhob(2) )
228  WRITE (*,*) ' '
229  tc = t
230  IF (num == 2) WRITE (*,*) 'enter an estimate for crit. temp.'
231  IF (num == 2) READ (*,*) tc
232  ensemble_flag = 'tp' ! this flag is for: 'regular calculation'
233  tsav = t
234  psav = p
235  IF ( eos < 4 ) CALL critical (tc,pc,rhoc)
236  !IF ( eos >= 4 .AND. eos /= 7 ) CALL lj_critical (tc,pc,rhoc)
237  t = tsav
238  p = psav
239  WRITE (*,'(a,3(f16.4))') 'critical point',tc, pc/1.e5, rhoc
240  WRITE (*,*) ' '
241 
242  !--------------------------------------------------------------------------
243  ! update z3t, the T-dependent quantity that relates eta and rho, as eta = z3t*rho
244  !--------------------------------------------------------------------------
245  CALL perturbation_parameter
246 
247 
248  !--------------------------------------------------------------------------
249  ! define initial density profile rhop(i)
250  ! and dimensionless space coordinates zp(i)
251  !
252  ! discret : number of grid-points within "the box"
253  ! irc : number of grid-points extending the the box to left and right
254  ! the box is extended in order to allow for numerical integration
255  ! 'irc' is determined by the cut-off distance 'rc'
256  !--------------------------------------------------------------------------
257 
258  irc = nint(rc*parame(1,2)/dzp) + 1
259  tanhfac = -2.3625*t/tc + 2.4728
260  ! tanhfac = 2.7*(1.0 - t/tc) ! this parameterization was published (Gross, JCP, 2009)
261  DO i = -irc, (discret+irc)
262  zp(i) = REAL(i) * dzp
263  END DO
264  DO i = -irc, (discret+irc)
265  rhop(i) = tanh(-(zp(i)-zp(int(discret/2))) / parame(1,2) *tanhfac) * (rhob(1)-rhob(2))/2.0 &
266  + (rhob(1)+rhob(2))/2.0
267  ! rhop(i) = rhob(1)
268  END DO
269 
270 
271  !--------------------------------------------------------------------------
272  ! Initialize the DENS_INV subroutine
273  !--------------------------------------------------------------------------
274 
275  nphas = 1
276 
277  ensemble_flag = 'tv' ! this flag is for: mu_res=mu_res(T,rho)
278 
279 
280 
281  !==========================================================================
282  ! Start iterating the density profile
283  !==========================================================================
284 
285  kk = 1
286  ih = 85
287 
288  dft_convergence_loop: DO
289 
290  !-----------------------------------------------------------------------
291  ! Getting auxilliary quantities along the profile
292  !-----------------------------------------------------------------------
293 
294  CALL aux_chain ( discret, fa, dzp, d_hs, zp, rhop, rhobar, lambda )
295 
296  CALL fmt_dens ( discret, fa, dzp, d_hs, zp, rhop, ni, &
297  phi_dn0, phi_dn1, phi_dn2, phi_dn3, phi_dn4, phi_dn5 )
298 
299 
300  !-----------------------------------------------------------------------
301  ! Start loop for density profile
302  !-----------------------------------------------------------------------
303 
304  DO i = 0, discret
305 
306  !--------------------------------------------------------------------
307  ! hard sphere contribution
308  ! f_fmt is the Helmholtz energy density F_FMT/(VkT) = F_FMT/(NkT)*rho
309  ! dF_drho_fmt is the functional derivative of F_FMT/(kT) to rho
310  !--------------------------------------------------------------------
311  zs = 1.0 - ni(3,i)
312  f_fmt = - ni(0,i)*log(zs) + ni(1,i)*ni(2,i)/zs - ni(4,i)*ni(5,i)/zs &
313  + (ni(2,i)**3 -3.0*ni(2,i)*ni(5,i)*ni(5,i)) *(ni(3,i)+zs*zs*log(zs)) &
314  /36.0/pi/zs/zs/ni(3,i)**2
315 
316  CALL df_fmt_dr ( i, fa, dzp, d_hs, zp, phi_dn0, &
317  phi_dn1, phi_dn2, phi_dn3, phi_dn4, phi_dn5, df_drho_fmt )
318 
319 
320  !--------------------------------------------------------------------
321  ! chain term
322  !--------------------------------------------------------------------
323  CALL df_chain_dr ( i, fa, dzp, d_hs, zp, rhop, lambda, &
324  rhobar, z3t_st, f_ch, df_drho_ch )
325 
326 
327  !--------------------------------------------------------------------
328  ! dispersive attraction
329  !--------------------------------------------------------------------
330  f_int_z = 0.0
331  f_int2_z = 0.0
332  mu_int_z = 0.0
333  mu_int2_z = 0.0
334  mu_int3_z = 0.0
335  f01 = 0.0
336  f02 = 0.0
337  f03 = 0.0
338  f04 = 0.0
339  f05 = 0.0
340  DO j = (i-irc), (i+irc) ! integration in z-coordinate
341  zz1 = abs( zp(j) - zp(i) ) ! distance z12 between 1 and 2
342  dz_local = dzp
343  IF ( zz1 < rc*parame(1,2) ) THEN
344  IF ( zz1 >= rc*parame(1,2) - dzp ) dz_local = rc*parame(1,2) - zz1
345  CALL dft_rad_int_units ( i, j, ih, zz1, rhop, f_int_r, mu_int_r, &
346  f_int2_r, mu_int2_r, mu_int3_r )
347  ELSE
348  f_int_r = 0.0
349  f_int2_r = 0.0
350  mu_int_r = 0.0
351  mu_int2_r= 0.0
352  mu_int3_r= 0.0
353  END IF
354 
355  f_int_z = f_int_z + dz_local * (rhop(j)* f_int_r + f01)/2.0
356  mu_int_z = mu_int_z + dz_local * (rhop(j)*mu_int_r + f02)/2.0
357  f_int2_z = f_int2_z + dz_local * ( f_int2_r + f03)/2.0
358  mu_int2_z= mu_int2_z+ dz_local * (mu_int2_r + f04)/2.0
359  mu_int3_z= mu_int3_z+ dz_local * (mu_int3_r + f05)/2.0
360  f01 = rhop(j)* f_int_r
361  f02 = rhop(j)* mu_int_r
362  f03 = f_int2_r
363  f04 = mu_int2_r
364  f05 = mu_int3_r
365  END DO
366 
367 
368  !--------------------------------------------------------------------
369  ! cut-off corrections
370  !--------------------------------------------------------------------
371 
372  CALL cutoff_corrections_units ( i, irc, rhop, rhob, f_int_z, mu_int_z, f_int2_z, mu_int2_z )
373 
374 
375  !--------------------------------------------------------------------
376  ! for second order dispersive attraction ( usually not used !!! )
377  !--------------------------------------------------------------------
378 
379  z3 = rhop(i) * z3t_st
380  zms = 1.0 - z3
381  c1_con= 1.0/ ( 1.0 + parame(1,1)*(8.0*z3-2.0*z3**2 )/zms**4 &
382  + (1.0 - parame(1,1))*(20.0*z3-27.0*z3**2 &
383  + 12.0*z3**3 -2.0*z3**4 ) /(zms*(2.0-z3))**2 )
384  c2_con= - c1_con*c1_con &
385  * ( parame(1,1)*(-4.0*z3**2 +20.0*z3+8.0)/zms**5 &
386  + (1.0 - parame(1,1)) *(2.0*z3**3 +12.0*z3**2 -48.0*z3+40.0) &
387  / (zms*(2.0-z3))**3 )
388  mu_int2_z = mu_int2_z /4.0 * ( 2.0*rhop(i)*c1_con + rhop(i)*z3*c2_con )
389  mu_int3_z = mu_int3_z /4.0 *rhop(i)*rhop(i)*c1_con
390  f_int2_z = f_int2_z /4.0 *rhop(i)*rhop(i)*c1_con
391 
392  !--------------------------------------------------------------------
393  ! The integration of the DFT-integral can be done with cubic splines
394  !--------------------------------------------------------------------
395  ! stepno = discret + irc*2
396  ! CALL SPLINE_PARA (dzp, intgrid, utri, stepno)
397  ! CALL SPLINE_INT (f_int_z, dzp, intgrid, utri, stepno)
398  ! f_int_z = f_int_z + rhob(1)*( 4.0/90.0*rc**-9 -1.0/3.0*rc**-3 )
399  ! f_int_z = f_int_z + rhob(2)*( 4.0/90.0*rc**-9 -1.0/3.0*rc**-3 )
400 
401 
402  !--------------------------------------------------------------------
403  ! Calculation of 'dF_drho_att', which denotes non-local contributions
404  ! of d(F)/d(rho*). Apart from the dispersive attraction, it contains
405  ! non-local contributions of the hard-sphere term, and the chain term.
406  ! 'dF_drho_att' is defined as: dF_drho_att = d(F)/d(rho*) - (dF/drho*)_LDA
407  ! where LDA is for 'local density approximation', i.e. the values for
408  ! the local density.
409  !
410  ! F is the intrinsic Helmholtz energy
411  ! rho* = rhop(i) denotes the dimensionless density.
412  ! parame(1,3) is epsilon/k (LJ-energy parameter)
413  ! parame(1,2) is sigma (LJ-size parameter)
414  !
415  ! For a non-local second order term uncomment lines starting with '!2'
416  !--------------------------------------------------------------------
417  ! remember: factor 2*PI because of the cylindrical coordinates
418 
419  df_drho_att(i) = 2.0*pi*parame(1,1)**2 * parame(1,3)/t * mu_int_z
420  f_att(i) = pi*parame(1,1)**2 *parame(1,3)/t*rhop(i)*f_int_z
421 
422 
423  ! --- if a second order perturbation theory is considered -----------
424  IF (subtract1 =='2PT') THEN
425  df_drho_att(i)= df_drho_att(i) -2.0*pi*parame(1,1)**3 *(parame(1,3)/t)**2 *(mu_int2_z+mu_int3_z)
426  f_att(i) = f_att(i) -2.0*pi*parame(1,1)**3 *(parame(1,3)/t)**2 *f_int2_z
427  END IF
428 
429  !--------------------------------------------------------------------
430  ! make the dispersive attraction term consistent with PC-SAFT, by
431  ! adding the difference ( PC-SAFT - 1PT )_dispersion locally (LDA)
432  !--------------------------------------------------------------------
433 
434  !*****************************************************************************
435  ! under construction
436  !*****************************************************************************
437  dense(1) = rhop(i) * z3t_st
438  densta(1) = dense(1)
439 
440  ensemble_flag = 'tv'
441 
442  call only_one_term_eos_numerical ( 'disp_term', 'PT1 ' )
443  call fugacity ( lnphi )
444  call restore_previous_eos_numerical
445  f_disp_1pt = fres*rhop(i)
446  mu_disp_1pt = lnphi(1,1)
447 
448  call only_one_term_eos_numerical ( 'disp_term', 'PC-SAFT ' )
449  call fugacity ( lnphi )
450  call restore_previous_eos_numerical
451  f_disp_pcsaft = fres*rhop(i)
452  mu_disp_pcsaft = lnphi(1,1)
453 
454  eta = densta(1)
455  rho = eta/z3t
456  z3_rk = z3t ! only for pure substances
457  x(1) = 1.0
458  call f_polar ( fdd, fqq, fdq )
459  call phi_polar ( 1, z3_rk, fdd_rk, fqq_rk, fdq_rk )
460  fres_polar = ( fdd + fqq + fdq ) * rhop(i)
461  mu_polar = fdd_rk + fqq_rk + fdq_rk
462 
463  f_assoc = 0.0
464  mu_assoc = 0.0
465  IF ( sum( nint(parame(1:ncomp,12)) ) > 0) THEN
466  call only_one_term_eos_numerical ( 'hb_term ', 'TPT1_Chap' )
467  call fugacity ( lnphi )
468  call restore_previous_eos_numerical
469  f_assoc = fres*rhop(i)
470  mu_assoc = lnphi(1,1)
471  END IF
472 
473  ensemble_flag = 'tp'
474 
475  df_drho_att(i)= df_drho_att(i) + ( mu_disp_pcsaft - mu_disp_1pt ) + mu_assoc + mu_polar
476  f_att(i) = f_att(i) + ( f_disp_pcsaft - f_disp_1pt ) + f_assoc + fres_polar
477  !*****************************************************************************
478  !*****************************************************************************
479 
480 
481  !--------------------------------------------------------------------
482  ! collect the total Helmholtz energy density 'f_tot' and the
483  ! functional derivative to rhop(z) 'dF_drho_tot' (including ideal gas)
484  ! For f_tot, it is numerically advantageous to add the ideal gas term
485  ! after updating rhop(i)
486  !--------------------------------------------------------------------
487 
488  df_drho_tot(i) = log( rhop(i) ) + df_drho_fmt + df_drho_ch + df_drho_att(i)
489  f_tot(i) = f_fmt + f_ch + f_att(i)
490 
491 
492  ! --- on-the-fly report on local errors in the profile --------------
493  IF ( mod(i, outpt) == 0 )write(*,'(i7,2(G15.6))') i,rhop(i), my0 - df_drho_tot(i)
494 
495  END DO ! end of loop (i = 0, discret) along the profile
496 
497 
498  !-----------------------------------------------------------------------
499  ! update the density profile using either a Picard-iteration scheme
500  ! (i.e. a direct substitution scheme, or a LDA - Inversion Procedure
501  ! similar to R.Evans (Bristol), which is done in function DENS_INVERS2.
502  !-----------------------------------------------------------------------
503  dev = 0.0
504  DO i = 0, discret
505  rhop_o(i) = rhop(i)
506  rhop(i) = rhop(i) * exp( my0 - df_drho_tot(i) )
507  rhop(i) = rhop_o(i) + (rhop(i)-rhop_o(i))*damppic
508  dev = dev + ( (rhop(i)-rhop_o(i))*parame(1,2)**3 )**2
509  END DO
510 
511 
512  !-----------------------------------------------------------------------
513  ! calculate surface tension
514  !-----------------------------------------------------------------------
515  free = 0.0
516  DO i = 1, discret
517  f_tot(i) = f_tot(i) + rhop(i)*( log(rhop(i))-1.0 ) ! now add the ideal gas term
518  delta_f = f_tot(i) - (rhop(i)*my0 - pbulk) ! all quantities .../(kT)
519  free = free + delta_f*dzp
520  END DO
521  surftens(kk) = kbol * t *1.e20*1000.0 *free
522 
523 
524  !-----------------------------------------------------------------------
525  ! add an approximate capillary wave contribution to the surface tension
526  !-----------------------------------------------------------------------
527  st_macro(kk) = surftens(kk) / ( 1.0 + 3.0/8.0/pi *t/tc &
528  * (1.0/2.55)**2 / (0.0674*parame(1,1)+0.0045) )
529 
530 
531  delta_st = 1.0
532  IF ( kk > 1 ) delta_st = abs( surftens(kk)-surftens(kk-1) ) / surftens(kk)
533 
534  WRITE (*,*) '-----------------------------------------------------------'
535  WRITE (*,*) ' # error-sum intrinsic ST total ST'
536  WRITE (*,'(i3,3(F16.8))') kk, dev, surftens(kk), st_macro(kk)
537  WRITE (*,*) '-----------------------------------------------------------'
538  WRITE (71,'(i3,4(E18.8))') kk, dev, surftens(kk), st_macro(kk)
539  kk = kk + 1
540 
541  !-----------------------------------------------------------------------
542  ! add an approximate capillary wave contribution to the surface tension
543  !-----------------------------------------------------------------------
544  ! write (*,*) 'error measure',dev, delta_st
545  IF ( dev < maxdev .OR. delta_st < 1.e-8 ) THEN
546  EXIT dft_convergence_loop
547  ELSE
548  IF ( kk > maxiter ) THEN
549  WRITE(*,*)' no convergence in ',maxiter,' steps'
550  EXIT dft_convergence_loop
551  ENDIF
552  ENDIF
553 
554  ENDDO dft_convergence_loop
555 
556  !--------------------------------------------------------------------------
557  ! write resulting density profile
558  !--------------------------------------------------------------------------
559  WRITE(68,'(i3,6(f18.8))') 0, zp(0)-zp(int(discret/2)), rhop(0), t, &
560  val_conv(4)/1.e5, density(1), density(2)
561  DO i = 0, discret
562  IF ( mod(i, outpt) == 0 ) WRITE (68,'(i6,3(f18.12))') i,zp(i)-zp(int(discret/2)), &
563  rhop(i), -( df_drho_tot(i)-my0 )
564  ! IF ( MOD(i, outpt) == 0 ) WRITE(*,'(i6,3(f18.12))') i,zp(i)-zp(INT(discret/2)),rhop(i)
565  ! write (69,*) zp(i)*parame(1,2), pN_pT(i)/parame(1,2)**3 /1E-30*parame(1,3)*KBOL/1.E6 ! in MPa
566  END DO
567  WRITE (68,*) ' '
568 
569 
570  !--------------------------------------------------------------------------
571  ! summarize results
572  !--------------------------------------------------------------------------
573  WRITE (*,*) ' '
574  WRITE (*,*) 'SUMMARY FOR A SINGLE TEMPERATURE'
575  WRITE (*,*) ' '
576  WRITE (*,*) 'Temp. [K], Pressure [bar] ',t,val_conv(4)/1.e5
577  WRITE (*,*) 'Critical point Temp., Press. ',tc,pc/1.e5
578  WRITE (*,*) 'Density [kg/m**3] ',density(1),density(2)
579  WRITE (*,*) 'Dimensionless Density (rho*) ',rhob(1),rhob(2)
580  WRITE (*,*) 'Excess Grand Potential ',free
581  WRITE (*,*) 'Intrinsic Interf. Tension [mN/m] ',surftens(kk-1)
582  WRITE (*,*) 'Macroscop.Interf. Tension [mN/m] ',st_macro(kk-1)
583  WRITE (*,*) '============================================================'
584  WRITE (*,*) ' '
585  WRITE (69,'(9(f18.10))') t, val_conv(4)/1.e5, &
586  rhob(1),rhob(2),surftens(kk-1),st_macro(kk-1),free,dev
587 
588  !--------------------------------------------------------------------------
589  ! when calc. a phase diagram & diagram of surface tens., loop for higher T
590  !--------------------------------------------------------------------------
591  ensemble_flag = 'tp' ! this flag is for 'regular calculations'
592  subtract1 = 'no' ! this flag is for 'regular calculations'
593  IF ( diagram ) THEN
594  IF ( (t+8.0) <= tc ) THEN
595  t = t + 5.0
596  IF ( (t+15.0) <= tc ) t = t + 5.0
597  IF ( (t+25.0) <= tc ) t = t + 10.0
598  IF ( (t+45.0) <= tc ) t = t + 20.0
599  nphas = 2
600  n_unkw = ncomp ! number of quantities to be iterated
601  it(1) = 'p' ! iteration of pressure
602  val_init(3) = t ! value of temperature
603  running = 't' ! T is running variable in PHASE_EQUILIB - here T=const.
604  end_x = t ! end temperature - here T=const.
605  steps = 1.0 ! number of steps of running var. - here 1, since T=const.
606  d_hs = parame(1,2) * ( 1.0 - 0.12*exp( -3.0*parame(1,3)/t ) )
607  z3t_st = pi/6.0* parame(1,1) * d_hs**3
608  dhs_st = d_hs/parame(1,2)
609  CALL rdf_matrix_units (msegm)
610  ELSE
611  EXIT diagram_for_various_t_loop
612  END IF
613  ELSE
614  EXIT diagram_for_various_t_loop
615  END IF
616 
617  ENDDO diagram_for_various_t_loop
618  WRITE (69,'(7(f18.10))') tc, pc/1.e5, rhoc, rhoc, 0., 0., 0.
619 
620 END SUBROUTINE dft_nmft_units
621 
622 
623 
624 
625 
626 !WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW
627 !
628 !WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW
629 
630 SUBROUTINE cutoff_corrections_units ( i, irc, rhop, rhob, f_int_z, mu_int_z, f_int2_z, mu_int2_z )
631 
632  USE dft_module, ONLY: ndft, rc
633  USE eos_variables, ONLY: parame
634  IMPLICIT NONE
635 
636  !-----------------------------------------------------------------------------
637  INTEGER, INTENT(IN) :: i
638  INTEGER, INTENT(IN) :: irc
639  REAL, DIMENSION(-NDFT:NDFT), INTENT(IN) :: rhop
640  REAL, DIMENSION(2), INTENT(IN) :: rhob
641  REAL, INTENT(IN OUT) :: f_int_z, f_int2_z
642  REAL, INTENT(IN OUT) :: mu_int_z, mu_int2_z
643 
644  !-----------------------------------------------------------------------------
645  REAL :: cutoffz, cutoffz2, rhotemp
646  !-----------------------------------------------------------------------------
647 
648  cutoffz = ( 4.0/90.0 * rc**-9 - 1.0/3.0 * rc**-3 ) * parame(1,2)**3
649  cutoffz2 = ( 16.0/22.0/21.0 * rc**-21 - 2.0/15.0 * rc**-15 + 16.0/90.0 * rc**-9 ) * parame(1,2)**3
650  IF ( abs( rhop(i+irc)-rhob(2) ) > 1.e-5 ) THEN
651  rhotemp = rhop(i+irc) ! this is a crude approximation !
652  ! rhotemp = rhob(2)
653  f_int_z = f_int_z + rhotemp*cutoffz
654  mu_int_z = mu_int_z + rhotemp*cutoffz
655  f_int2_z = f_int2_z + cutoffz2
656  mu_int2_z= mu_int2_z+ cutoffz2
657  ELSE
658  f_int_z = f_int_z + rhob(2)*cutoffz
659  mu_int_z = mu_int_z + rhob(2)*cutoffz
660  f_int2_z = f_int2_z + cutoffz2
661  mu_int2_z= mu_int2_z+ cutoffz2
662  END IF
663  IF ( abs( rhop(i-irc)-rhob(1) ) > 1.e-3 ) THEN
664  rhotemp = rhop(i-irc)
665  ! rhotemp=rhob(1)
666  f_int_z = f_int_z + rhotemp*cutoffz
667  mu_int_z = mu_int_z + rhotemp*cutoffz
668  f_int2_z = f_int2_z + cutoffz2
669  mu_int2_z= mu_int2_z+ cutoffz2
670  ELSE
671  f_int_z = f_int_z + rhob(1)*cutoffz
672  mu_int_z = mu_int_z + rhob(1)*cutoffz
673  f_int2_z = f_int2_z + cutoffz2
674  mu_int2_z= mu_int2_z+ cutoffz2
675  END IF
676 
677 END SUBROUTINE cutoff_corrections_units
678 
679 
680 
681 
682 
683 !WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW
684 ! SUBROUTINE DFT_RAD_INT
685 !
686 ! This subroutine integrates the kernel of the perturbation theory in
687 ! radial direction (more precisely in distance coordinate r^ hat). A
688 ! non-mean field approach is taken, using a radial distribution function
689 ! (currently at a Percus-Yevick level).
690 !
691 ! The first and second order contributions to the perturbation theory
692 ! are calculated - although the second order contribution is rarely used.
693 !
694 ! ToDo: comment the subroutine and remove the GOTO constructs
695 !WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW
696 
697 SUBROUTINE dft_rad_int_units (i,j,ih,zz_1,rhop,f_int_r,my_int_r, &
698  f_int2_r,my_int2_r,my_int3_r)
699 
700  USE dft_module
701  USE eos_variables, ONLY: parame
702  IMPLICIT NONE
703 
704  !-----------------------------------------------------------------------------
705  INTEGER, INTENT(IN) :: i
706  INTEGER, INTENT(IN) :: j
707  INTEGER, INTENT(IN OUT) :: ih
708  REAL, INTENT(IN) :: zz_1
709  REAL, INTENT(IN) :: rhop(-ndft:ndft)
710  REAL, INTENT(OUT) :: f_int_r
711  REAL, INTENT(OUT) :: my_int_r
712  REAL, INTENT(OUT) :: f_int2_r
713  REAL, INTENT(OUT) :: my_int2_r
714  REAL, INTENT(OUT) :: my_int3_r
715 
716  !-----------------------------------------------------------------------------
717  INTEGER :: k
718 
719  REAL :: zz1
720  REAL :: sig_ij
721  REAL :: dzr_local
722  REAL :: fint0, fint0_2, fint1, fint1_2
723  REAL :: myint0, myint0_2, myint0_3, myint1
724  REAL :: myint1_2, myint1_3
725  REAL :: dg_drho, dg_dr
726  REAL :: rad, xg, rdf, rho_bar, ua, rs
727  REAL :: analytic1, analytic2, tau_rs
728  LOGICAL :: shortcut
729  !-----------------------------------------------------------------------------
730 
731  shortcut = .true.
732  fint0 = rc * tau_cut ! first order term
733  fint0_2 = rc * tau_cut*tau_cut ! 2nd order
734  myint0 = rc * tau_cut ! first order term
735  myint0_2 = rc * tau_cut*tau_cut ! 2nd order
736  myint0_3 = 0.0 ! 2nd order
737 
738  f_int_r = 0.0
739  f_int2_r = 0.0
740  my_int_r = 0.0
741  my_int2_r= 0.0
742  my_int3_r= 0.0
743 
744  !-----------------------------------------------------------------------------
745  ! for mixtures it is advantageous to write all distances in dimensionless
746  ! form, e.g. r^hat = r^hat / sigma.
747  ! For mixtures, sig_ij = ( sig_i + sig_j ) / 2.
748  !-----------------------------------------------------------------------------
749  sig_ij = parame(1,2) ! for pure substances
750  zz1 = zz_1 / sig_ij
751 
752  ! --- this block only speeds up the integration -------------------------------
753  IF ( shortcut ) THEN
754  rs = max( rg, zz1 ) ! +dzr
755  IF ( rs > rc ) WRITE (*,*) 'error !!!!'
756  analytic1 = 0.4*rs**-10 - 0.4*rc**-10 - rs**-4 + rc**-4
757  analytic2 = 16.0/22.0 * (rs**-22 - rc**-22 ) - 2.0*rs**-16 +2.0*rc**-16 +1.6*rs**-10 - 1.6*rc**-10
758  f_int_r = f_int_r + analytic1
759  f_int2_r = f_int2_r + analytic2
760  my_int_r = my_int_r + analytic1
761  my_int2_r= my_int2_r+ analytic2
762  IF ( rs == zz1 ) GO TO 10
763  tau_rs = 4.0 * ( rs**-12 - rs**-6 )
764  fint0 = rs * tau_rs
765  fint0_2 = rs * tau_rs*tau_rs
766  myint0 = rs * tau_rs
767  myint0_2= rs * tau_rs*tau_rs
768  rad = rs ! the simple integration scheme: set to rc
769  k = 0 + nint( (rc-rs)/dzr ) ! in simple scheme: set to 0
770  ELSE
771  rad = rc
772  k = 0
773  END IF
774  !-------------
775  !rad = rc
776  !k = 0
777 
778 
779  DO WHILE ( rad /= max( 1.0, zz1 ) )
780 
781  dzr_local = dzr ! dzr is set in f_dft (dimensionless)
782 
783  IF ( rad - dzr_local <= max( 1.0, zz1 ) ) THEN
784  dzr_local = rad - max( 1.0, zz1 )
785  rad = max( 1.0, zz1 )
786  ELSE
787  rad = rad - dzr_local
788  END IF
789 
790  k = k + 1
791  ua = 4.0 * ( rad**-12 -rad**-6 )
792  xg = rad / dhs_st
793  rho_bar = ( rhop(i) + rhop(j) )/2.0 * sig_ij**3
794  rdf = 1.0
795  dg_drho = 0.0
796  IF ( rad <= rg ) THEN
797  CALL bi_cub_spline (rho_bar,xg,ya,x1a,x2a,y1a,y2a,y12a, &
798  c_bicub,rdf,dg_drho,dg_dr,den_step,ih,k)
799  dg_drho = dg_drho * parame(1,2)**3 ! caution: introduced with length dimensions in Angstrom
800  END IF
801 
802  fint1 = rdf * rad * ua
803  fint1_2 = rdf * rad * ua * ua
804  myint1 = rad * (rdf + 0.5*rhop(i)*dg_drho) * ua
805  myint1_2 = rdf * rad * ua * ua
806  myint1_3 = dg_drho * rad * ua * ua
807  ! intf(k) = fint1
808  f_int_r = f_int_r + dzr_local * (fint1 + fint0)/2.0
809  f_int2_r = f_int2_r + dzr_local * (fint1_2 + fint0_2)/2.0
810  my_int_r = my_int_r + dzr_local * (myint1 + myint0)/2.0
811  my_int2_r= my_int2_r+ dzr_local * (myint1_2 + myint0_2)/2.0
812  my_int3_r= my_int3_r+ dzr_local * (myint1_3 + myint0_3)/2.0
813 
814  fint0 = fint1
815  fint0_2 = fint1_2
816  myint0 = myint1
817  myint0_2= myint1_2
818  myint0_3= myint1_3
819 
820  !IF ( zz1 >= 1.0 .AND. rad-dzr_local+1.E-8 >= zz1 ) integration_cycle = .true. ! integration down to ABS(zz1)
821  !IF ( zz1 < 1.0 .AND. rad-dzr_local+1.E-8 >= 1.0 ) integration_cycle = .true. ! integration down to ABS(zz1) but for r^hat<1, g(r)=0 (so stop at r^hat=1)
822  !integration_cycle = .false.
823 
824  ENDDO
825 
826  ! IF (k.GT.30) THEN
827  ! stepno = k
828  ! CALL SPLINE_PARA (dzr,intf,utri,stepno)
829  ! CALL SPLINE_INT (f_int_r,dzr,intf,utri,stepno)
830  ! ENDIF
831 
832 10 CONTINUE
833 
834  analytic1 = 4.0/10.0*rc**-10 - rc**-4
835  analytic2 = 16.0/22.0*rc**-22 - 2.0*rc**-16 + 1.6*rc**-10
836  f_int_r = f_int_r + analytic1
837  f_int2_r = f_int2_r + analytic2
838  my_int_r = my_int_r + analytic1
839  my_int2_r= my_int2_r+ analytic2
840 
841  f_int_r = f_int_r * sig_ij*sig_ij
842  f_int2_r = f_int2_r * sig_ij*sig_ij
843  my_int_r = my_int_r * sig_ij*sig_ij
844  my_int2_r= my_int2_r* sig_ij*sig_ij
845 
846 END SUBROUTINE dft_rad_int_units
847 
848 
849 !WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW
850 !
851 !WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW
852 
853 SUBROUTINE rdf_matrix_units (msegm)
854 
855  USE parameters, ONLY: pi
856  USE dft_module
857  IMPLICIT NONE
858 
859  !-----------------------------------------------------------------------------
860  REAL, INTENT(IN) :: msegm
861 
862  !-----------------------------------------------------------------------------
863  INTEGER :: i, k = 0
864  REAL :: rdf, rad, xg, rho_rdf, z3
865  !-----------------------------------------------------------------------------
866 
867 
868  do i = 1, den_step
869 
870  ! rho_rdf= rhob(1) + (rhob(2)-rhob(1))*REAL(i)/den_step
871  rho_rdf = 1.e-5 + (1.0) * REAL(i-1) / REAL(den_step-1) ! segment density, rho_s*sigma**3
872  rho_rdf = rho_rdf / msegm ! molar density, rho_m*sigma**3
873  rad = rc
874  k = 0
875  !write (*,*) 'eta=',rho_rdf*msegm * PI/6.0 * dhs_st**3
876 
877  do while ( rad - 1.e-8 > 0.95 )
878 
879  rad = rad - dzr
880  k = k + 1
881  xg = rad / dhs_st
882  z3 = rho_rdf * msegm * pi/6.0 * dhs_st**3 ! dhs_st is dim.less effective diam. d*(T)=d(T)/sigma
883  ya(i,k) = 1.0
884  IF ( xg <= rg .AND. z3 > 0.0 ) CALL rdf_int ( z3, msegm, xg, rdf )
885  IF ( xg <= rg .AND. z3 > 0.0 ) ya(i,k) = rdf
886  ! ya(i,k) = y(x1a(i), x2a(k)) with x1a: density-vector, x2a: r-vector
887  x1a(i) = rho_rdf
888  x2a(k) = xg
889 
890  end do
891 
892  end do
893 
894  if ( xg > 1.0 ) stop 'rdf_matrix_units: 0.95*sigma is too high for lower bound'
895 
896  WRITE (*,*) ' done with calculating g(r)',dhs_st
897 
898  kmax = k
899  CALL bicub_derivative ( ya, x1a, x2a, y1a, y2a, y12a, den_step, kmax )
900  CALL bicub_c ( ya, x1a, x2a, y1a, y2a, y12a, c_bicub, den_step, kmax )
901 
902 END SUBROUTINE rdf_matrix_units
WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW This module contains constant...
Definition: modules.f90:6
double lambda
Latent heat of blowing agent, J/kg.
WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW Module DFT_MODULE This module...
Definition: modules.f90:272
WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW This module contains paramete...
Definition: modules.f90:120
WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW This module contains paramete...
Definition: modules.f90:29
WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW This module contains paramete...
Definition: modules.f90:220