MoDeNa  1.0
Software framework facilitating sequential multi-scale modelling
in_out.f90
Go to the documentation of this file.
1 
7 module in_out
8  use foaming_globals_m
9  use constants
10  use globals
11  use ioutils, only:newunit,str
12  implicit none
13  private
14  public set_paths,read_inputs,save_integration_header,&
15  save_integration_step,save_integration_close,load_old_results
16 contains
17 !********************************BEGINNING*************************************
21 subroutine set_paths
22  fileplacein='../inputs/'
23  fileplaceout='./'
24  inputs='unifiedInput.json'
25  outputs_1d='outputs_1d.out'
26  outputs_gr='outputs_GR.out'
27  outputs_c='outputs_c.out'
28  outputs_kin='kinetics.out'
29  outputs_drain='bblgr_2_drain.out'
30  outputs_af='after_foaming.txt'
31  inputs=trim(adjustl(fileplacein))//trim(adjustl(inputs))
32  outputs_1d=trim(adjustl(fileplaceout))//trim(adjustl(outputs_1d))
33  outputs_gr=trim(adjustl(fileplaceout))//trim(adjustl(outputs_gr))
34  outputs_c=trim(adjustl(fileplaceout))//trim(adjustl(outputs_c))
35  outputs_kin=trim(adjustl(fileplaceout))//trim(adjustl(outputs_kin))
36  outputs_drain=trim(adjustl(fileplaceout))//trim(adjustl(outputs_drain))
37  outputs_af=trim(adjustl(fileplaceout))//trim(adjustl(outputs_af))
38 end subroutine set_paths
39 !***********************************END****************************************
43 subroutine read_inputs
44  use fson
45  use fson_value_m, only: fson_value_get
46  character(len=1024) :: strval
47  type(fson_value), pointer :: json_data
48  write(*,*) 'loading input file ',trim(inputs)
49  json_data => fson_parse(inputs)
50  ngas=2
51  co2_pos=2
52  call fson_get(json_data, "bubbleGrowth.geometry", geometry)
53  call fson_get(json_data, "bubbleGrowth.integrator", strval)
54  if (strval=="dlsode") then
55  integrator=1
56  elseif (strval=="dlsodes") then
57  integrator=2
58  elseif (strval=="cvode") then
59  integrator=3
60  else
61  stop 'unknown integrator'
62  endif
63  call fson_get(json_data, "bubbleGrowth.method", strval)
64  if (strval=="nonstiff") then
65  if (integrator==1 .or. integrator==2) then
66  int_meth=10
67  elseif (integrator==3) then
68  int_meth=1
69  endif
70  elseif (strval=="stiff") then
71  if (integrator==1 .or. integrator==2) then
72  if (integrator==1) then
73  int_meth=22
74  elseif (integrator==2) then
75  int_meth=222
76  endif
77  elseif (integrator==3) then
78  int_meth=2
79  endif
80  else
81  stop 'method can be either stiff or nonstiff'
82  endif
83  call fson_get(json_data, "bubbleGrowth.inertialTerm", inertial_term)
84  call fson_get(json_data, "bubbleGrowth.solubilityCorrection", solcorr)
85  call fson_get(json_data, "bubbleGrowth.meshCoarseningParameter", mshco)
86  call fson_get(json_data, "bubbleGrowth.internalNodes", p)
87  call fson_get(json_data, "bubbleGrowth.initialTime", tstart)
88  if (firstrun .and. .not. shooting) then
89  call fson_get(json_data, "bubbleGrowth.finalTime", tend)
90  endif
91  call fson_get(json_data, "bubbleGrowth.outerTimeSteps", its)
92  call fson_get(json_data, "bubbleGrowth.maxInnerTimeSteps", maxts)
93  call fson_get(json_data, "bubbleGrowth.relativeTolerance", rel_tol)
94  call fson_get(json_data, "bubbleGrowth.absoluteTolerance", abs_tol)
95  allocate(d(ngas),cbl(ngas),xgas(ngas+1),kh(ngas),mbl(ngas),&
98  wblpol(ngas),d0(ngas))
99  call fson_get(json_data, "physicalProperties.pressure", pamb)
100  call fson_get(&
101  json_data, "physicalProperties.blowingAgents.PBL.molarMass", mbl(1))
102  call fson_get(&
103  json_data, "physicalProperties.blowingAgents.CO2.molarMass", mbl(2))
104  call fson_get(json_data, "physicalProperties.polymer.heatCapacity", cppol)
105  call fson_get(&
106  json_data, &
107  "physicalProperties.blowingAgents.PBL.heatCapacityInLiquidPhase", &
108  cpbll(1))
109  call fson_get(&
110  json_data, &
111  "physicalProperties.blowingAgents.CO2.heatCapacityInLiquidPhase", &
112  cpbll(2))
113  call fson_get(&
114  json_data, &
115  "physicalProperties.blowingAgents.PBL.heatCapacityInGaseousPhase", &
116  cpblg(1))
117  call fson_get(&
118  json_data, &
119  "physicalProperties.blowingAgents.CO2.heatCapacityInGaseousPhase", &
120  cpblg(2))
121  call fson_get(&
122  json_data, &
123  "physicalProperties.blowingAgents.PBL.evaporationHeat", dhv(1))
124  call fson_get(&
125  json_data, &
126  "physicalProperties.blowingAgents.CO2.evaporationHeat", dhv(2))
127  call fson_get(&
128  json_data, "physicalProperties.blowingAgents.PBL.density", rhobl)
129  call fson_get(json_data, "initialConditions.temperature", temp0)
130  if (.not. shooting) then
131  call fson_get(json_data, "initialConditions.bubbleRadius", r0)
132  endif
133  call fson_get(json_data, "initialConditions.numberBubbleDensity", nb0)
134  call fson_get(json_data, "kinetics.kineticModel", strval)
135  if (strval=='Baser') then
136  kin_model=1
137  elseif (strval=='BaserRx') then
138  kin_model=3
139  elseif (strval=='RF-1') then
140  kin_model=4
141  else
142  stop 'unknown kinetic model'
143  endif
144  call fson_get(json_data, "initialConditions.concentrations.water", w0)
145  call fson_get(json_data, "kinetics.gelPoint", gelpointconv)
146  if (kin_model==1 .or. kin_model==3) then
147  call fson_get(json_data, "kinetics.useDilution", dilution)
148  call fson_get(&
149  json_data, "initialConditions.concentrations.polyol", oh0)
150  call fson_get(&
151  json_data, "initialConditions.concentrations.isocyanate", nco0)
152  call fson_get(&
153  json_data, "kinetics.gellingReaction.frequentialFactor", aoh)
154  call fson_get(&
155  json_data, "kinetics.gellingReaction.activationEnergy", eoh)
156  call fson_get(&
157  json_data, "kinetics.blowingReaction.frequentialFactor", aw)
158  call fson_get(&
159  json_data, "kinetics.blowingReaction.activationEnergy", ew)
160  elseif (kin_model==4) then
161  call fson_get(&
162  json_data, "initialConditions.concentrations.catalyst", catalyst)
163  call fson_get(&
164  json_data, "initialConditions.concentrations.polyol1", polyol1_ini)
165  call fson_get(&
166  json_data, "initialConditions.concentrations.polyol2", polyol2_ini)
167  call fson_get(&
168  json_data, "initialConditions.concentrations.amine", amine_ini)
169  call fson_get(&
170  json_data, "initialConditions.concentrations.isocyanate1", &
172  call fson_get(&
173  json_data, "initialConditions.concentrations.isocyanate2", &
175  call fson_get(&
176  json_data, "initialConditions.concentrations.isocyanate3", &
179  endif
180  call fson_get(&
181  json_data, &
182  "initialConditions.concentrations.blowingAgents.PBL", cbl(1))
183  call fson_get(&
184  json_data, &
185  "initialConditions.concentrations.blowingAgents.CO2", cbl(2))
186  if (kin_model==1 .or. kin_model==3 .or. kin_model==4) then
187  call fson_get(&
188  json_data, "kinetics.gellingReaction.reactionEnthalpy", dhoh)
189  call fson_get(&
190  json_data, "kinetics.blowingReaction.reactionEnthalpy", dhw)
191  endif
192  call fson_get(&
193  json_data, "physicalProperties.polymer.polymerDensityModel", strval)
194  if (strval=="constant") then
195  rhop_model=1
196  call fson_get(json_data, "physicalProperties.polymer.density", rhop)
197  elseif (strval=="nanotools") then
198  rhop_model=2
199  elseif (strval=="pcsaft") then
200  rhop_model=3
201  else
202  stop 'unknown polymer density model'
203  endif
204  call fson_get(json_data, "physicalProperties.surfaceTensionModel", strval)
205  if (strval=="constant") then
206  itens_model=1
207  call fson_get(json_data, "physicalProperties.surfaceTension", sigma)
208  elseif (strval=="pcsaft") then
209  itens_model=2
210  call fson_get(&
211  json_data, "physicalProperties.surfactant", surfactantpresent)
212  else
213  stop 'unknown interfacial tension model'
214  endif
215  call fson_get(&
216  json_data, &
217  "physicalProperties.blowingAgents.PBL.diffusivityModel", strval)
218  if (strval=="constant") then
219  diff_model(1)=1
220  call fson_get(&
221  json_data, &
222  "physicalProperties.blowingAgents.PBL.diffusivity", d(1))
223  elseif (strval=="nanotools") then
224  diff_model(1)=2
225  else
226  stop 'unknown diffusivity model'
227  endif
228  call fson_get(&
229  json_data, &
230  "physicalProperties.blowingAgents.CO2.diffusivityModel", strval)
231  if (strval=="constant") then
232  diff_model(2)=1
233  call fson_get(&
234  json_data, &
235  "physicalProperties.blowingAgents.CO2.diffusivity", d(2))
236  elseif (strval=="nanotools") then
237  diff_model(2)=2
238  else
239  stop 'unknown diffusivity model'
240  endif
241  call fson_get(&
242  json_data, &
243  "physicalProperties.blowingAgents.PBL.solubilityModel", strval)
244  if (strval=="constant") then
245  sol_model(1)=1
246  call fson_get(&
247  json_data, &
248  "physicalProperties.blowingAgents.PBL.solubility", kh(1))
249  elseif (strval=="pcsaft") then
250  sol_model(1)=2
251  elseif (strval=="Gupta") then
252  sol_model(1)=3
253  elseif (strval=="Winkler") then
254  sol_model(1)=4
255  elseif (strval=="Baser") then
256  sol_model(1)=6
257  elseif (strval=="hardcodedWinkler") then
258  sol_model(1)=7
259  else
260  stop 'unknown solubility model'
261  endif
262  call fson_get(&
263  json_data, &
264  "physicalProperties.blowingAgents.CO2.solubilityModel", strval)
265  if (strval=="constant") then
266  sol_model(2)=1
267  elseif (strval=="pcsaft") then
268  sol_model(2)=2
269  elseif (strval=="hardcodedconstant") then
270  sol_model(2)=8
271  call fson_get(&
272  json_data, &
273  "physicalProperties.blowingAgents.CO2.solubility", kh(2))
274  else
275  stop 'unknown solubility model'
276  endif
277  call fson_get(&
278  json_data, "physicalProperties.polymer.viscosityModel", strval)
279  if (strval=="constant") then
280  visc_model=1
281  call fson_get(json_data, "physicalProperties.polymer.viscosity", eta)
282  elseif (strval=="hardcodedCastroMacosko") then
283  visc_model=2
284  elseif (strval=="CastroMacosko") then
285  visc_model=3
286  else
287  stop 'unknown viscosity model'
288  endif
289  call fson_destroy(json_data)
290  write(*,*) 'done: inputs loaded'
291  write(*,*)
292 end subroutine read_inputs
293 !***********************************END****************************************
294 
295 
296 !********************************BEGINNING*************************************
301 subroutine save_integration_header
302  open (unit=newunit(fi1), file = outputs_1d)
303  write(fi1,'(1000A24)') '#time', 'radius','pressure1', 'pressure2',&
304  'conversion_of_polyol',&
305  'conversion_of_water', 'eq_concentration', 'first_concentration', &
306  'viscosity', 'moles_in_polymer', 'moles_in_bubble', 'total_moles', &
307  'shell_thickness', 'temperature', 'foam_density', 'weight_fraction1', &
308  'weight_fraction2','porosity'
309  open (unit=newunit(fi2), file = outputs_gr)
310  write(fi2,'(1000A23)') '#GrowthRate1', 'GrowthRate2', 'temperature', &
311  'bubbleRadius','c1','c2','p1','p2'
312  if (kin_model==4) then
313  open (unit=newunit(fi3), file = outputs_kin)
314  write(fi3,'(1000A23)') "time","Catalyst_1","CE_A0","CE_A1","CE_B",&
315  "CE_B2","CE_I0","CE_I1","CE_I2","CE_PBA","CE_Breac","CE_Areac0",&
316  "CE_Areac1","CE_Ireac0","CE_Ireac1","CE_Ireac2","Bulk","R_1",&
317  "R_1_mass","R_1_temp","R_1_vol"
318  endif
319  open (unit=newunit(fi4), file = outputs_c)
320  open (unit=newunit(fi5), file = outputs_drain)
321  write(fi5,'(1000A24)') '#time','radius','porosity','viscosity'
322 end subroutine save_integration_header
323 !***********************************END****************************************
324 
325 
326 !********************************BEGINNING*************************************
330 subroutine save_integration_step(iout)
331  integer, intent(in) :: iout
332  integer :: i
333  write(fi1,"(1000es24.15e3)") time,radius,pressure,y(xoheq),y(xweq),&
334  eqconc,y(fceq),eta,mb(1),mb2(1),mb3(1),st,temp,rhofoam,&
336  write(fi2,"(1000es23.15)") grrate, temp, radius, avconc, pressure
337  if (kin_model==4) then
338  write(fi3,"(1000es23.15)") time,y(kineq(1)),y(kineq(2)),y(kineq(3)),&
339  y(kineq(4)),y(kineq(5)),y(kineq(6)),y(kineq(7)),y(kineq(8)),&
340  y(kineq(9)),y(kineq(10)),y(kineq(11)),y(kineq(12)),y(kineq(13)),&
341  y(kineq(14)),y(kineq(15)),y(kineq(16)),y(kineq(17)),y(kineq(18)),&
342  y(kineq(19)),y(kineq(20))
343  endif
344  write(fi4,"(1000es23.15)") (y(fceq+i+1),i=0,ngas*p,ngas)
345  write(fi5,"(1000es24.15e3)") time,radius,porosity,eta
346  ! save arrays, which are preserved for future use
347  etat(iout,1)=time
348  etat(iout,2)=eta
349  port(iout,1)=time
350  port(iout,2)=porosity
351  init_bub_rad(iout,1)=time
352  init_bub_rad(iout,2)=radius
353 end subroutine save_integration_step
354 !***********************************END****************************************
355 
356 
357 !********************************BEGINNING*************************************
361 subroutine save_integration_close(iout)
362  integer, intent(in) :: iout
363  real(dp), dimension(:,:), allocatable :: matr
364  close(fi1)
365  close(fi2)
366  if (kin_model==4) then
367  close(fi3)
368  endif
369  close(fi4)
370  close(fi5)
371  open(unit=newunit(fi1),file=outputs_af)
372  write(fi1,'(1000A24)') '#foam_density', 'bubble_diameter','pressure1',&
373  'pressure2'
374  write(fi1,"(1000es24.15e3)") rhofoam,2*radius,pressure
375  close(fi1)
376  ! reallocate matrices for eta_rm and bub_vf functions
377  ! interpolation doesn't work otherwise
378  if (iout /= its) then
379  allocate(matr(0:its,2))
380  matr=etat
381  deallocate(etat)
382  allocate(etat(0:iout,2))
383  etat=matr(0:iout,:)
384  matr=port
385  deallocate(port)
386  allocate(port(0:iout,2))
387  port=matr(0:iout,:)
388  matr=init_bub_rad
389  deallocate(init_bub_rad)
390  allocate(init_bub_rad(0:iout,2))
391  init_bub_rad=matr(0:iout,:)
392  endif
393 end subroutine save_integration_close
394 !***********************************END****************************************
395 
396 
397 !********************************BEGINNING*************************************
401 subroutine load_old_results
402  integer :: i,j,ios,fi
403  real(dp), dimension(:,:), allocatable :: matrix
404  j=0
405  open(newunit(fi),file=outputs_1d)
406  do !find number of points
407  read(fi,*,iostat=ios)
408  if (ios/=0) exit
409  j=j+1
410  enddo
411  allocate(matrix(j,18))
412  rewind(fi)
413  read(fi,*)
414  do i=2,j
415  read(fi,*) matrix(i,:)
416  enddo
417  close(fi)
418  allocate(bub_rad(j-1,2))
419  bub_rad(:,1)=matrix(2:j,1)
420  bub_rad(:,2)=matrix(2:j,2)
421  deallocate(matrix)
422 end subroutine load_old_results
423 !***********************************END****************************************
424 end module in_out
character(len=99) inputs
input file
Definition: globals.f90:11
logical surfactantpresent
surfactant is present - pcsaft caluclation (t/f)
Definition: globals.f90:22
character(len=99) outputs_drain
output file for the wall drainage
Definition: globals.f90:11
real(dp) porosity
foam porosity
Definition: globals.f90:49
logical solcorr
use solubility correction on bubble radius (t/f)
Definition: globals.f90:22
real(dp) polyol1_ini
initial concentration of polyol 1
Definition: globals.f90:49
real(dp), dimension(:), allocatable dhv
evaporation heat of blowing agent (for each gas)
Definition: globals.f90:106
real(dp) st
shell thickness
Definition: globals.f90:49
integer ngas
number of dissolved gases
Definition: globals.f90:29
integer, dimension(:), allocatable sol_model
solubility model 1=constant,2=modena
Definition: globals.f90:102
integer rhop_model
polymer density model. 1=constant,2=modena
Definition: globals.f90:29
real(dp) rhop
polymer density
Definition: globals.f90:49
character(len=99) outputs_kin
output file with variables of detailed kinetic model
Definition: globals.f90:11
real(dp) temp
temperature (K)
Definition: globals.f90:49
real(dp), dimension(:), allocatable y
state variables
Definition: globals.f90:106
real(dp) amine_ini
initial concentration of amine
Definition: globals.f90:49
real(dp) aw
frequential factor of blowing reaction
Definition: globals.f90:49
real(dp) nb0
initial bubble number density
Definition: globals.f90:49
real(dp) radius
bubble radius (m)
Definition: globals.f90:49
real(dp), dimension(:), allocatable kh
Henry constants (for each dissolved gas)
Definition: globals.f90:106
real(dp) aoh
frequential factor of gelling reaction
Definition: globals.f90:49
real(dp) gelpointconv
conversion of polyol at gel point
Definition: globals.f90:49
real(dp), dimension(:), allocatable mb2
moles in bubble
Definition: globals.f90:106
real(dp) rel_tol
relative tolerance
Definition: globals.f90:49
real(dp) w0
initial concentration of water (can be zero)
Definition: globals.f90:49
logical dilution
use dilution effect for kinetics (t/f)
Definition: globals.f90:22
real(dp) isocyanate2_ini
initial concentration of isocyanate 2
Definition: globals.f90:49
real(dp), dimension(:), allocatable pressure
partial pressure(Pa)
Definition: globals.f90:106
logical inertial_term
include inertial term in equations (t/f)
Definition: globals.f90:22
real(dp) sigma
interfacial tension
Definition: globals.f90:49
integer, dimension(:), allocatable diff_model
diffusivity model 1=constant,2=modena
Definition: globals.f90:102
real(dp) rhobl
density of liquid physical blowing agent
Definition: globals.f90:49
real(dp) isocyanate3_ini
initial concentration of isocyanate 3
Definition: globals.f90:49
real(dp), dimension(:), allocatable mbl
blowing agent molar mass (for each dissolved gas)
Definition: globals.f90:106
real(dp) eoh
activation energy of gelling reaction
Definition: globals.f90:49
real(dp) eqconc
equivalent concentration for first gas
Definition: globals.f90:49
character(len=99) fileplacein
location of input files
Definition: globals.f90:11
real(dp) time
time (s)
Definition: globals.f90:49
character(len=99) geometry
geometry 3D=spherical, 2D=cylindrical
Definition: globals.f90:11
integer, dimension(:), allocatable kineq
kinetics state variable equations (indexes)
Definition: globals.f90:102
real(dp) abs_tol
absolute tolerance
Definition: globals.f90:49
real(dp), dimension(:), allocatable cpbll
heat capacity of blowing agent in liquid phase (for each gas)
Definition: globals.f90:106
real(dp) nco0
initial concentration of isocyanate
Definition: globals.f90:49
logical shooting
am I using shooting method (t/f)
Definition: globals.f90:22
real(dp), dimension(:), allocatable d0
initial diffusion coefficients used in non-dimensional routines
Definition: globals.f90:106
real(dp) mshco
mesh coarsening parameter
Definition: globals.f90:49
real(dp), dimension(:), allocatable mb3
total moles
Definition: globals.f90:106
real(dp), dimension(:), allocatable xgas
initial molar fraction of gases in the bubble
Definition: globals.f90:106
real(dp), dimension(:), allocatable cbl
concentration profile in reaction mixture
Definition: globals.f90:106
integer itens_model
interfacial tension model. 1=constant,2=modena
Definition: globals.f90:29
integer integrator
integrator. 1=dlsode,2=dlsodes
Definition: globals.f90:29
real(dp) rhofoam
foam density
Definition: globals.f90:49
real(dp) temp0
initial temperature
Definition: globals.f90:49
integer co2_pos
carbon dioxide position
Definition: globals.f90:29
real(dp), dimension(:), allocatable d
diffusion coefficients (for each dissolved gas)
Definition: globals.f90:106
character(len=99) outputs_gr
output file for the surrogate model fitting
Definition: globals.f90:11
real(dp), dimension(:), allocatable avconc
average concentration in reaction mixture
Definition: globals.f90:106
character(len=99) outputs_af
final foam properties for foam cond. and foam aging
Definition: globals.f90:11
real(dp), dimension(:), allocatable mb
moles in polymer
Definition: globals.f90:106
real(dp) pamb
ambient pressure (in the liquid)
Definition: globals.f90:49
real(dp) polyol2_ini
initial concentration of polyol 2
Definition: globals.f90:49
integer kin_model
reaction kinetics model.
Definition: globals.f90:29
real(dp) eta
viscosity
Definition: globals.f90:49
real(dp), dimension(:), allocatable wblpol
weight fraction of blowing agents in reaction mixture
Definition: globals.f90:106
integer its
number of outer integration outer time steps
Definition: globals.f90:29
integer fceq
first concentration equation (index)
Definition: globals.f90:29
integer fi5
file indices
Definition: globals.f90:29
integer xoheq
polyol conversion equation (index)
Definition: globals.f90:29
real(dp) cppol
heat capacity of polymer
Definition: globals.f90:49
real(dp), dimension(2) grrate
growth rate
Definition: globals.f90:49
real(dp) isocyanate1_ini
initial concentration of isocyanate 1
Definition: globals.f90:49
character(len=99) outputs_c
output file with concentration profiles
Definition: globals.f90:11
character(len=99) fileplaceout
location of output files
Definition: globals.f90:11
real(dp) r0
initial radius
Definition: globals.f90:49
real(dp) dhw
blowing reaction enthalpy
Definition: globals.f90:49
namespace with global variables
Definition: globals.f90:8
integer p
number of internal nodes
Definition: globals.f90:29
character(len=99) outputs_1d
output file with scalar variables
Definition: globals.f90:11
real(dp) dhoh
gelling reaction enthalpy
Definition: globals.f90:49
integer maxts
maximum inner time steps between t and t+h
Definition: globals.f90:29
real(dp), dimension(:), allocatable cpblg
heat capacity of blowing agent in gas phase (for each gas)
Definition: globals.f90:106
real(dp) catalyst
concentration of catalyst
Definition: globals.f90:49
real(dp) oh0
initial concentration of polyol (don't set to zero)
Definition: globals.f90:49
real(dp) ew
activation energy of blowing reaction
Definition: globals.f90:49
integer visc_model
viscosity model. 1=constant,2=Castro and Macosko,3=modena
Definition: globals.f90:29
integer xweq
water conversion equation (index)
Definition: globals.f90:29
integer int_meth
stiff or no? See MF for ODEPACK
Definition: globals.f90:29