MAMMA  1.0
Conduitsolver
init.f90
Go to the documentation of this file.
1 !*********************************************************************
5 !
9 !*********************************************************************
10 
11 MODULE init
12 
13  USE parameters, ONLY : n_vars , n_cry , n_gas , n_mom
14 
15  USE parameters, ONLY : idx_p1 , idx_p2 , idx_u1 , idx_u2 , idx_t , &
18 
23 
24 
25  IMPLICIT none
26 
27  REAL*8 :: alfa1_in
28  REAL*8 :: p1_in
29  REAL*8 :: p2_in
30  REAL*8 :: delta_p_in
31  REAL*8 :: u1_in
32  REAL*8 :: u2_in
33  REAL*8 :: t_in
34  REAL*8, ALLOCATABLE :: beta_in(:)
35  REAL*8, ALLOCATABLE :: xd_md_in(:)
36  REAL*8 :: frag_eff_in
37 
38  REAL*8 :: p_out
39 
40 CONTAINS
41 
42  !******************************************************************************
44  !
50  !******************************************************************************
51 
52  SUBROUTINE init_steady(u_0,qp)
53 
54  ! external procedures
56  USE constitutive, ONLY : f_alfa3, f_alfa
57 
58  ! external variables
59  USE constitutive, ONLY : p_1 , p_2 , t , x_d_md, x_g, alfa_g_2
61  USE constitutive, ONLY : rho_2 , rho_md, rho_g, rho_1, rho_c
62  USE constitutive, ONLY : bar_p_m, gamma_m, cv_m
63  USE constitutive, ONLY : bar_p_c, gamma_c, cv_c
64 
65  IMPLICIT none
66 
67  REAL*8, INTENT(IN) :: u_0
68  REAL*8, INTENT(OUT) :: qp(n_vars)
69 
70  REAL*8 :: r_rho_g(1:n_gas)
71  REAL*8 :: r_rho_2
72  REAL*8 :: r_rho_1
73  REAL*8 :: r_rho_c(1:n_cry)
74 
75  REAL*8 :: r_rho_md
76 
77  REAL*8 :: r_u_1
78  REAL*8 :: r_u_2
79 
80  REAL*8 :: r_frag_eff
81 
82  REAL*8 :: alfa2_in
83  REAL*8 :: alfa_g_in(1:n_gas)
84 
85  COMPLEX*16 :: x_g_old(1:n_gas)
86 
87  REAL*8 :: xd_md_tot
88 
89  REAL*8 :: xtot_in
90 
91  INTEGER :: i,j,idx,iter,max_iter
92  REAL*8 :: error_iter
93 
95 
96  ! evaluate the initial crystal volume fraction
97 
98  p_1 = dcmplx( p1_in , 0.d0 )
99  p_2 = dcmplx( p2_in , 0.d0 )
100  t = dcmplx( t_in , 0.d0 )
101 
102  ! evaluate the initial dissolved gas mass fraction
103 
104  r_rho_md = REAL( ( p_1 + bar_p_m ) / ( T * cv_m * ( gamma_m - 1.D0) ) )
105  rho_md = dcmplx(r_rho_md,0.0)
106 
107  r_rho_c(1:n_cry) = REAL( ( p_1 + bar_p_c(1:n_cry) ) / ( T * cv_c(1:n_cry) * & ( gamma_c(1:n_cry) - DCMPLX(1.D0,0.D0) ) ) )
108 
109  r_rho_1 = r_rho_md
110 
111  rho_c(1:n_cry) = dcmplx( r_rho_c(1:n_cry) , 0.d0 )
112  rho_1 = dcmplx( r_rho_1 , 0.d0 )
113 
114  DO i=1,n_gas
115  alfa_g_2(i) = dcmplx(1.0 / n_gas,0.0);
116  x_g(i) = dcmplx(1e-2,0.0)
117  END DO
118 
119  iter = 1
120  max_iter =1000
121  error_iter = 1.0
122 
123  DO WHILE( error_iter .GT. 1e-15 .AND. (iter .LT. max_iter) )
124 
125  x_g_old = x_g
126 
127  CALL f_xdis_eq
128 
129  DO i=1,n_gas
130 
131  xd_md_in(i) = min( REAL(x_d_md_eq(i)) , x_ex_dis_in(i) )
132 
133  END DO
134 
135  ! required by eval_densities
136  x_d_md(1:n_gas) = dcmplx( xd_md_in(1:n_gas) , 0.d0 )
137 
138  CALL f_beta_eq
139 
140  beta_in(1:n_cry) = REAL(beta_eq(1:n_cry))
141 
142  r_u_1 = u_0
143  r_u_2 = u_0 + 1.d-10
144 
145  ! evaluate the volume fractions of the two phases
146 
147  beta = dcmplx( beta_in(1:n_cry) , 0.d0 )
148 
149  CALL eval_densities
150 
151  r_rho_1 = REAL( rho_1 )
152  r_rho_2 = REAL( rho_2 )
153  r_rho_g = REAL( rho_g )
154 
155  r_rho_md = REAL( rho_md )
156 
157  xd_md_tot = sum( xd_md_in(1:n_gas) )
158 
159  xtot_in = sum( x_ex_dis_in(1:n_gas) )
160 
161  IF ( n_gas .EQ. 1 ) THEN
162 
163  CALL f_alfa( x_ex_dis_in(1:n_gas) , xd_md_in(1:n_gas) , &
164  beta_in(1:n_cry) , r_rho_md , r_rho_2 , alfa_g_in(1:n_gas) )
165 
166  ELSE
167 
168  CALL f_alfa3( p2_in, x_ex_dis_in(1:n_gas) , beta_in(1:n_cry) , &
169  r_rho_md , r_rho_g(1:n_gas) , alfa_g_in(1:n_gas) )
170 
171  END IF
172 
173 
174  DO i = 1,n_gas
175 
176  alfa_g_in(i) = max( alfa_g_in(i) , 1.d-10 )
177 
178  END DO
179 
180  alfa2_in = sum( alfa_g_in(1:n_gas) )
181  alfa1_in = 1.d0 - alfa2_in
182 
183  x_g = alfa_g_in * r_rho_g / ( alfa1_in * r_rho_1 + alfa2_in * r_rho_2 )
184 
185  alfa_g_2 = alfa_g_in / alfa2_in
186 
187  error_iter = (maxval(abs(x_g - x_g_old)))
188 
189  END DO
190 
191  IF (iter .GE. max_iter) THEN
192 
193  WRITE(*,*) 'No convergence for initial gas dissolve mass fraction'
194  stop
195 
196  END IF
197 
198  ! initialize the fragmentation efficiency to zero
199 
200  r_frag_eff = frag_eff_in
201 
202  ! -------- define the indexes of variables and equations --------------------
203 
204  idx_p1 = 1
205  idx_p2 = 2
206  idx_u1 = 3
207  idx_u2 = 4
208  idx_t = 5
209  idx_xd_first = 5+1
210  idx_xd_last = 5+n_gas
211  idx_alfa_first = 5+n_gas+1
212  idx_alfa_last = 5+2*n_gas
213  idx_beta_first = 5+2*n_gas+1
214  idx_beta_last = 5+2*n_gas+n_cry*n_mom
215 
216  idx_mix_mass_eqn = 1
217  idx_vol1_eqn = 2
218  idx_mix_mom_eqn = 3
219  idx_rel_vel_eqn = 4
220  idx_mix_engy_eqn = 5
222  idx_dis_gas_eqn_last = 5+n_gas
223  idx_ex_gas_eqn_first = 5+n_gas+1
224  idx_ex_gas_eqn_last = 5+2*n_gas
225  idx_cry_eqn_first = 5+2*n_gas+1
226  idx_cry_eqn_last = 5+2*n_gas+n_cry*n_mom
227 
228  ! --------- define the vector of primitive variables ------------------------
229 
230  ! Frist phase pressure
231  qp(idx_p1) = p1_in
232 
233  ! Second phase pressure
234  qp(idx_p2) = p2_in
235 
236  ! Frist phase velocity
237  qp(idx_u1) = r_u_1
238 
239  ! Second phase velocity
240  qp(idx_u2) = r_u_2
241 
242  ! Temperature
243  qp(idx_t) = t_in
244 
245  ! Dissolved gas mass fractions
246  idx = idx_xd_first
247  DO i = 1,n_gas
248 
249  qp(idx) = xd_md_in(i)
250 
251  idx = idx + 1
252 
253  END DO
254 
255  ! Exsolved gas volume fraction
256  idx = idx_alfa_first
257  DO i = 1,n_gas
258 
259  qp(idx) = alfa_g_in(i)
260 
261  idx = idx + 1
262 
263  END DO
264 
265  ! Crystal volume fractions
266  idx = idx_beta_first
267 
268  IF ( n_mom .LE. 1 ) THEN
269 
270  DO i = 1,n_cry
271 
272  qp(idx) = beta_in(i)
273 
274  idx = idx + 1
275 
276  END DO
277 
278  ELSE
279 
280  DO i = 1,n_cry
281 
282  DO j = 0,n_mom-1
283 
284  ! qp(idx) = mom_cry_in(i,j)
285 
286  idx = idx + 1
287 
288  END DO
289 
290  END DO
291 
292  END IF
293 
294  END SUBROUTINE init_steady
295 
296 END MODULE init
297 
real *8, dimension(:), allocatable bar_p_c
crystals cohesion pressure
real *8, dimension(:), allocatable x_ex_dis_in
integer idx_p2
Index of p2 in the qp array.
Definition: parameters.f90:38
Parameters.
Definition: parameters.f90:10
integer idx_cry_eqn_last
Definition: parameters.f90:59
integer idx_ex_gas_eqn_last
Definition: parameters.f90:57
integer idx_mix_mom_eqn
Definition: parameters.f90:51
complex *16, dimension(:), allocatable rho_g
exsolved gas local density
real *8 u2_in
Inlet second phase velocity.
Definition: init.f90:32
real *8 bar_p_m
melt cohesion pressure
complex *16, dimension(:), allocatable rho_c
crystals local density
integer idx_u2
Index of u2 in the qp array.
Definition: parameters.f90:40
integer n_gas
Numbeer of crystal phases.
Definition: parameters.f90:30
real *8 gamma_m
melt adiabatic exponent
integer idx_ex_gas_eqn_first
Definition: parameters.f90:56
subroutine f_alfa3(r_p_2, xtot, r_beta, r_rho_md, r_rho_g, r_alfa_g)
Bottom exsolved gas.
real *8, dimension(:), allocatable gamma_c
crystals adiabatic exponent
real *8 p_out
Outlet pressure.
Definition: init.f90:38
complex *16, dimension(:), allocatable beta_eq
equil. cry. volume fraction in the melt-crystals phase
complex *16 p_2
local pressure of the exsolved gas
complex *16 rho_md
dis_gas+melt local density
complex *16, dimension(:), allocatable x_d_md_eq
equil. dis. gas mass fraction in the melt+dis.gas phase
real *8 delta_p_in
Inlet pressure difference ( p2-p1 )
Definition: init.f90:30
integer idx_alfa_first
First index of alfa in the qp array.
Definition: parameters.f90:44
integer n_cry
Numbeer of crystal phases.
Definition: parameters.f90:29
integer idx_mix_engy_eqn
Definition: parameters.f90:53
complex *16 rho_2
exsolved gas local density
subroutine f_alfa(xtot, xmax, r_beta, r_rho_md, r_rho_2, r_alfa_2)
Bottom exsolved gas.
real *8 alfa1_in
Inlet first phase volume fraction.
Definition: init.f90:27
integer idx_mix_mass_eqn
Definition: parameters.f90:49
integer idx_alfa_last
Last index of alfa in the qp array.
Definition: parameters.f90:45
complex *16, dimension(:), allocatable alfa_g_2
exsolved gas volume fractions in phase 2
integer idx_rel_vel_eqn
Definition: parameters.f90:52
real *8 cv_m
melt specific heat capacity at constant volume
integer idx_beta_first
First index of beta in the qp array.
Definition: parameters.f90:46
real *8 t_in
Inlet temperature.
Definition: init.f90:33
Initial solution.
Definition: init.f90:11
real *8 u1_in
Inlet first phase velocity.
Definition: init.f90:31
integer n_mom
Number of moments for each crystal phase.
Definition: parameters.f90:35
integer idx_dis_gas_eqn_first
Definition: parameters.f90:54
subroutine f_beta_eq
Equilibrium Crystal content.
real *8 frag_eff_in
Inlet fragmentation efficiency.
Definition: init.f90:36
integer idx_xd_first
First index of xd in the qp array.
Definition: parameters.f90:42
integer idx_p1
Index of p1 in the qp array.
Definition: parameters.f90:37
integer idx_u1
Index of u1 in the qp array.
Definition: parameters.f90:39
complex *16, dimension(:), allocatable x_g
exsolved gas mass fraction (with respect to the mixture)
Constitutive equations.
Definition: constitutive.f90:9
integer idx_cry_eqn_first
Definition: parameters.f90:58
integer idx_beta_last
Last index of beta in the qp array.
Definition: parameters.f90:47
real *8, dimension(:), allocatable beta_in
Inlet crystal volume fraction.
Definition: init.f90:34
integer idx_vol1_eqn
Definition: parameters.f90:50
real *8, dimension(:), allocatable cv_c
crystals specific heat capacity at constant volume
real *8 p1_in
Inlet first phase pressure.
Definition: init.f90:28
integer idx_dis_gas_eqn_last
Definition: parameters.f90:55
complex *16 rho_1
dis_gas+melt+crystals phase local density
integer n_vars
Number of conservative variables.
Definition: parameters.f90:32
real *8 p2_in
Inlet second phase pressure.
Definition: init.f90:29
complex *16, dimension(:), allocatable beta
crystal volume fraction in the melt-crystals phase
complex *16 p_1
local pressure of the melt-crystals phase
subroutine eval_densities
Phases densities.
subroutine f_xdis_eq
Equilibrium Dissolved gas.
real *8, dimension(:), allocatable xd_md_in
Inlet dissolved gas mass fraction.
Definition: init.f90:35
complex *16 t
mixture local temperature
complex *16, dimension(:), allocatable x_d_md
dissolved gas mass fraction in the melt+dis.gas phase
integer idx_t
Index of T in the qp array.
Definition: parameters.f90:41
integer idx_xd_last
Last index of xd in the qp array.
Definition: parameters.f90:43
subroutine init_steady(u_0, qp)
Steady problem initialization.
Definition: init.f90:53