MoDeNa  1.0
Software framework facilitating sequential multi-scale modelling
Main.F90
1 
4 
5 !!WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW
62 !WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW
63 !
64 
65 
66 Program dft
67 
68 Use parameters, Only: np,nc,kbol
69 Use basic_variables, Only: ncomp,t,p,ensemble_flag,num,parame,eos,pol,xif,compna,mm, &
70  surfactant, wif_surfactant
71 Use eos_variables, Only: dhs,mseg,eta,dd_term,dq_term,qq_term
72 Use eos_constants, Only: ap,bp,dnm
73 Use mod_dft, Only: box,dzp,fa,zp,fa_disp,ab_disp,pbulk
74 Use vle_var, ONLY: tc,pc,rhob,density
75 USE dft_fcn_module, ONLY: chempot_total
76 
77 !PETSc modules
79 Use f90moduleinterfaces
80 Use global_x !(snes,ngrid,ngp,x,r,timer)
81 
82 
83 Implicit None
84 
85 #include <finclude/petscsys.h>
86 
90 
91 petscerrorcode :: ierr
92 type(userctx) :: user
93 petscbool :: flg
94 INTEGER :: i
95 character(80) :: filename=''
96 REAL :: zges(np)
97 REAL :: dhs_save(nc)
98 REAL :: cif(nc)
99 REAL :: psi_factor
100 REAL :: x_surfactant
101 INTEGER :: position_surfactant
102 
103 !external subroutines associated with Solver
104 external forminitialguess
105 external formfunction
106 
107 
111  call petscinitialize(petsc_null_character,ierr)
112  call mpi_comm_rank(petsc_comm_world,user%rank,ierr)
113  call mpi_comm_size(petsc_comm_world,user%num_procs,ierr)
114 
118 
119  filename='./in.txt'
120  CALL file_open(filename,77) ! open input file
121  READ (77,*) t ! read temperature
122  READ (77,*) ncomp ! read number of components in the system
123  Do i = 1,ncomp ! read component names
124  READ (77,*) compna(i)
125  End Do
126  Do i = 1,ncomp ! read component overall molar concentrations
127  READ (77,*) xif(i)
128  End Do
129 
130  !check whether surfactant present in system
131  surfactant = .false.
132  If(ncomp > 1) Then
133  Do i = 1,ncomp
134  If(trim(compna(i)) == 'surfactant') Then
135  surfactant = .true.
136  !reduce number of components
137  ncomp = ncomp - 1
138  x_surfactant = xif(i)
139  position_surfactant = i
140  End If
141  End Do
142  End If
143 
144  If(surfactant) Then
145  !calculate new molar concentrations without surfactant
146  If(position_surfactant == 1) Then
147  Do i = 2,ncomp+1
148  xif(i-1) = xif(i)
149  compna(i-1) = compna(i)
150  End Do
151  xif(1:ncomp) = xif(1:ncomp) / sum(xif(1:ncomp))
152  Else If(position_surfactant == ncomp + 1) Then
153  xif(1:ncomp) = xif(1:ncomp) / sum(xif(1:ncomp))
154  Else
155  Do i = 1,ncomp+1
156  If(i>position_surfactant) Then
157  xif(i-1) = xif(i)
158  compna(i-1) = compna(i)
159  End If
160  End Do
161  xif(1:ncomp) = xif(1:ncomp) / sum(xif(1:ncomp))
162  End If
163 
164  End If
165 
166  !In cases where only 0.0 are passed for xif, xif(1:ncomp) = xif(1:ncomp) / sum(xif(1:ncomp)) leads to NAN results
167  If(xif(1) /= xif(1)) Then
168  If(ncomp == 2) xif(1:ncomp) = 0.
169  If(ncomp > 2) xif(1:ncomp) = 1./Real(ncomp)
170  End If
171 
172 
173 ! !calculate molar fractions from molar concentrations
174 ! xif(1:ncomp) =cif(1:ncomp) / sum(cif(1:ncomp))
175 
176 
177 ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
178 ! GENERAL SIMULATION SET UP
179 ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
180 
181  num = 0 ! (num=0: using analytical derivatives of EOS)
182  ! (num=1: using numerical derivatives of EOS)
183  ! (num=2: White's renormalization group theory)
184  IF ( num /= 0 ) CALL set_default_eos_numerical
185 
186  eos = 1
187  pol = 1
188 
189  p = 1.000e05
190 
191  CALL para_input ! retriev pure comp. parameters
192 
193  ensemble_flag = 'tp' ! this specifies, whether the eos-subroutines
194  ! are executed for constant 'tp' or for constant 'tv'
195 
196 
197 
198 !calculate feed mass fraction of surfactant
199 If(surfactant) wif_surfactant = 0.01!x_surfactant*2655.24078 / (sum( xif(1:ncomp)*mm(1:ncomp) ) + x_surfactant*2655.24078 )
200 
204 
205  CALL eos_const (ap, bp, dnm)
206 
207  dd_term = 'GV' ! dipole-dipole term of Gross & Vrabec (2006)
208  qq_term = 'JG' ! quadrupole-quadrupole term of Gross (2005)
209  dq_term = 'VG' ! dipole-quadrupole term of Vrabec & Gross (2008)
210 
211  CALL vle_mix(rhob,density,chempot_total,user) !user is passed so user%rank is known and only node 0 prints out the reslts of the VLE calculation
212 
213  !determine critical point
214  num = 0
215  dhs_save = dhs !needed because subroutine CRIT_POINT_MIX changes the value
216  CALL crit_point_mix(tc,user) !of the global variable dhs! In cases where Tc doesnt converge
217  dhs = dhs_save !dhs can be NAN after CRIT_POINT_MIX!!
218  !chance to overwite NAN results
219 ! IF(user%rank == 0) THEN
220 ! WRITE (*,*) 'Give final value of Tc:'
221 ! READ (*,*) tc
222 ! END IF
223 ! CALL MPI_Bcast(tc,1,MPI_DOUBLE_PRECISION,0,PETSC_COMM_WORLD,ierr)
224 
225 
226 
227 
231 
232  num = 1
233  CALL set_default_eos_numerical
234 
235  !set default values (overwritten from makefile)
236  box = 45.0 !box length [A]
237  ngrid = 614 !grid points
238 
239  !overwrite box size and ngrid if options are set in makefile
240  call petscoptionsgetreal(petsc_null_character,'-box',box,flg,ierr)
241  call petscoptionsgetint(petsc_null_character,'-nx',ngrid,flg,ierr)
242 
243 
244  dzp = box / REAL(ngrid) !grid spacing [A]
245  Allocate(fa(ncomp))
246  fa(1:ncomp) = nint( parame(1:ncomp,2) / dzp ) !grid points per sigma [-]
247 
248  !FOR DISP
249  ALLOCATE(fa_disp(ncomp),ab_disp(ncomp))
250  psi_factor = 1.5
251  fa_disp(1:ncomp) = nint( psi_factor * REAL(fa(1:ncomp)) )
252  Do i=1,ncomp
253  if( mod(fa_disp(i),2) /= 0 ) fa_disp(i) = fa_disp(i) + 1
254  End Do
255 
256 
257  ab_disp(1:ncomp) = psi_factor * dhs(1:ncomp)
258 
259 
260  ngp = 2 * maxval(fa_disp(1:ncomp)) + 5 !number of ghost points (+5 kann eig weg)
261 
262  Allocate(zp(-ngp:ngrid+ngp))
263 
264  Do i=-ngp,ngrid+ngp
265  zp(i) = REAL(i) * dzp !z-distance from origin of grid points [A]
266  End Do
267 
268  pbulk = ( p * 1.e-30 ) / ( kbol*t* rhob(1,0) ) * rhob(1,0) !p/kT
269 
270 
271  !update z3t, the T-dependent quantity that relates eta and rho, as eta = z3t*rho
272  CALL perturbation_parameter
273 
277  call solversetup
278 
279 
280 
281 
282 End Program dft
WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW This module contains constant...
Definition: modules.f90:6
WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW This module contains paramete...
Definition: modules.f90:200
WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW This module contains paramete...
Definition: modules.f90:120
This module contains variables associated with the PETSc solver.
Definition: mod_PETSc.F90:24
WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW This module contains the vari...
Definition: modules.f90:327
subroutine vle_mix(rhob, density, chemPot_total, user)
Definition: VLE_main.F90:7
subroutine formfunction(snes, X, F, user, ierr)
The subroutine FormFunction is a wrapper function which takes care of handling the global PETSc data ...
Definition: Function.F90:14
program dft
Main program.
Definition: Main.F90:66
In this module, the application context is defined.
Definition: mod_PETSc.F90:7
WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW This module contains paramete...
Definition: modules.f90:29