mphase_aux.F90       coverage:  100.00 %func     78.11 %block


     1) module Mphase_Aux_module
     2)   
     3)   use Mphase_pckr_module
     4) 
     5)   use PFLOTRAN_Constants_module
     6) 
     7)   implicit none
     8)   
     9)   private
    10) 
    11) !#define GARCIA 1
    12) #define DUANDEN 1
    13) 
    14) #include "petsc/finclude/petscsys.h"
    15) 
    16)   type, public :: mphase_auxvar_elem_type
    17)     PetscReal :: pres
    18)     PetscReal :: temp
    19)     PetscReal , pointer :: sat(:)
    20)     PetscReal , pointer :: den(:)
    21)     PetscReal , pointer :: avgmw(:)
    22)     PetscReal , pointer :: vis(:)
    23)     PetscReal , pointer :: h(:)
    24)     PetscReal , pointer :: u(:)
    25)     PetscReal , pointer :: pc(:)
    26)     PetscReal , pointer :: kvr(:)
    27)     PetscReal , pointer :: xmol(:)
    28)     PetscReal , pointer :: diff(:)
    29)     PetscReal , pointer :: hysdat(:)
    30)     PetscReal :: zco2
    31) !    PetscReal :: dvis_dp
    32) !    PetscReal :: kr
    33) !    PetscReal :: dkr_dp
    34)   end type mphase_auxvar_elem_type
    35) 
    36)   type, public :: mphase_auxvar_type
    37)     
    38)     type(mphase_auxvar_elem_type), pointer :: auxvar_elem(:) 
    39) #if 0
    40)     PetscReal , pointer :: davgmw_dx(:)
    41)     PetscReal , pointer :: dden_dp(:)
    42)     PetscReal , pointer :: dden_dt(:)
    43)     PetscReal , pointer :: dden_dx(:)
    44)     PetscReal , pointer :: dkvr_dp(:)
    45)     PetscReal , pointer :: dkvr_dt(:)
    46)     PetscReal , pointer :: dkvr_ds(:)
    47)     PetscReal , pointer :: dkvr_dx(:)
    48)     PetscReal , pointer :: dh_dp(:)
    49)     PetscReal , pointer :: dh_dt(:)
    50)     PetscReal , pointer :: dh_dx(:)
    51)     PetscReal , pointer :: du_dp(:)
    52)     PetscReal , pointer :: du_dt(:)
    53)     PetscReal , pointer :: du_dx(:)
    54) #endif
    55)   end type mphase_auxvar_type
    56)   
    57)   type, public :: mphase_parameter_type
    58)     PetscReal, pointer :: dencpr(:)
    59)     PetscReal, pointer :: ckwet(:)
    60)     PetscReal, pointer :: sir(:,:)
    61)   end type mphase_parameter_type
    62)   
    63)   type, public :: mphase_type
    64)     PetscInt :: n_zero_rows
    65)     PetscInt, pointer :: zero_rows_local(:), zero_rows_local_ghosted(:)
    66) 
    67)     PetscBool :: auxvars_up_to_date
    68)     PetscBool :: inactive_cells_exist
    69)     PetscInt :: num_aux, num_aux_bc, num_aux_ss
    70) 
    71)     PetscReal, pointer :: res_old_AR(:,:)
    72)     PetscReal, pointer :: res_old_FL(:,:)
    73)     PetscReal, pointer :: delx(:,:)
    74)   
    75)     type(mphase_parameter_type), pointer :: mphase_parameter
    76)     type(mphase_auxvar_type), pointer :: auxvars(:)
    77)     type(mphase_auxvar_type), pointer :: auxvars_bc(:)
    78)     type(mphase_auxvar_type), pointer :: auxvars_ss(:)
    79)   end type mphase_type
    80) 
    81) 
    82)   public :: MphaseAuxCreate, MphaseAuxDestroy, &
    83)             MphaseAuxVarCompute_NINC, MphaseAuxVarCompute_WINC, &
    84)             MphaseAuxVarInit, MphaseAuxVarCopy
    85) 
    86) contains
    87) 
    88) ! ************************************************************************** !
    89) 
    90) function MphaseAuxCreate()
    91)   ! 
    92)   ! MphaseAuxVarCreate: Allocate and initialize auxiliary object
    93)   ! Author: Chuan Lu
    94)   ! 
    95) 
    96)   use Option_module
    97) 
    98)   implicit none
    99)   
   100)   type(mphase_type), pointer :: MphaseAuxCreate
   101)   
   102)   type(mphase_type), pointer :: aux
   103) 
   104)   allocate(aux) 
   105)   aux%auxvars_up_to_date = PETSC_FALSE
   106)   aux%inactive_cells_exist = PETSC_FALSE
   107)   aux%num_aux = 0
   108)   aux%num_aux_bc = 0
   109)   aux%num_aux_ss = 0
   110)   nullify(aux%auxvars)
   111)   nullify(aux%auxvars_bc)
   112)   nullify(aux%auxvars_ss)
   113)   aux%n_zero_rows = 0
   114)   allocate(aux%mphase_parameter)
   115)   nullify(aux%mphase_parameter%sir)
   116)   nullify(aux%mphase_parameter%ckwet)
   117)   nullify(aux%mphase_parameter%dencpr)
   118)   nullify(aux%zero_rows_local)
   119)   nullify(aux%zero_rows_local_ghosted)
   120)   nullify(aux%res_old_AR)
   121)   nullify(aux%res_old_FL)
   122)   nullify(aux%delx)
   123)   
   124)   MphaseAuxCreate => aux
   125)   
   126) end function MphaseAuxCreate
   127) 
   128) ! ************************************************************************** !
   129) 
   130) subroutine MphaseAuxVarInit(auxvar,option)
   131)   ! 
   132)   ! Initialize auxiliary object
   133)   ! Author: Chuan Lu
   134)   ! 
   135) 
   136)   use Option_module
   137) 
   138)   implicit none
   139)   
   140)   type(mphase_auxvar_type) :: auxvar
   141)   type(option_type) :: option
   142) 
   143)   PetscInt :: var_elem_size, var_node_size
   144)   PetscInt :: nvar 
   145) 
   146)   allocate(auxvar%auxvar_elem(0 : option%nflowdof))
   147)   allocate(auxvar%auxvar_elem(0)%hysdat(4))
   148)  
   149)   do nvar = 0, option%nflowdof
   150)      allocate ( auxvar%auxvar_elem(nvar)%sat(option%nphase))
   151)      allocate ( auxvar%auxvar_elem(nvar)%den(option%nphase))
   152)      allocate ( auxvar%auxvar_elem(nvar)%avgmw(option%nphase))
   153)      allocate ( auxvar%auxvar_elem(nvar)%h(option%nphase))
   154)      allocate ( auxvar%auxvar_elem(nvar)%u(option%nphase))
   155)      allocate ( auxvar%auxvar_elem(nvar)%pc(option%nphase))
   156)      allocate ( auxvar%auxvar_elem(nvar)%kvr(option%nphase))
   157)      allocate ( auxvar%auxvar_elem(nvar)%vis(option%nphase))
   158)      allocate ( auxvar%auxvar_elem(nvar)%xmol(option%nphase*option%nflowspec))
   159)      allocate ( auxvar%auxvar_elem(nvar)%diff(option%nphase*option%nflowspec))
   160)      if (nvar>0) &
   161)        auxvar%auxvar_elem(nvar)%hysdat => auxvar%auxvar_elem(0)%hysdat
   162) 
   163)      auxvar%auxvar_elem(nvar)%pres = 0.d0
   164)      auxvar%auxvar_elem(nvar)%temp = 0.d0
   165)      auxvar%auxvar_elem(nvar)%sat = 0.d0
   166)      auxvar%auxvar_elem(nvar)%den = 0.d0
   167)      auxvar%auxvar_elem(nvar)%avgmw = 0.d0
   168)      auxvar%auxvar_elem(nvar)%h = 0.d0
   169)      auxvar%auxvar_elem(nvar)%u = 0.d0
   170)      auxvar%auxvar_elem(nvar)%pc = 0.d0
   171)      auxvar%auxvar_elem(nvar)%kvr = 0.d0
   172)      auxvar%auxvar_elem(nvar)%xmol = 0.d0
   173)      auxvar%auxvar_elem(nvar)%diff = 0.d0
   174)      auxvar%auxvar_elem(nvar)%vis = 0.d0
   175) #if 0
   176)      auxvar%auxvar_elem(nvar)%dsat_dp = 0.d0
   177)      auxvar%auxvar_elem(nvar)%dden_dp = 0.d0
   178)      auxvar%auxvar_elem(nvar)%dkvr_dp = 0.d0
   179) #endif
   180)   enddo
   181) 
   182) end subroutine MphaseAuxVarInit
   183) 
   184) ! ************************************************************************** !
   185) 
   186) subroutine MphaseAuxVarCopy(auxvar,auxvar2,option)
   187)   ! 
   188)   ! Copies an auxiliary variable
   189)   ! 
   190)   use Option_module
   191) 
   192)   implicit none
   193)   
   194)   type(mphase_auxvar_elem_type) :: auxvar, auxvar2
   195)   type(option_type) :: option
   196) 
   197)   auxvar2%pres = auxvar%pres
   198)   auxvar2%temp = auxvar%temp
   199)   auxvar2%sat = auxvar%sat
   200)   auxvar2%den = auxvar%den
   201)   auxvar2%avgmw = auxvar%avgmw
   202)   auxvar2%h = auxvar%h
   203)   auxvar2%u = auxvar%u
   204)   auxvar2%pc = auxvar%pc
   205) !  auxvar2%kr = auxvar%kr
   206) !  auxvar2%dkr_dp = auxvar%dkr_dp
   207)   auxvar2%vis = auxvar%vis
   208) !  auxvar2%dvis_dp = auxvar%dvis_dp
   209)   auxvar2%kvr = auxvar%kvr
   210) #if 0
   211)   auxvar2%dsat_dp = auxvar%dsat_dp
   212)   auxvar2%dden_dp = auxvar%dden_dp
   213)   auxvar2%dden_dt = auxvar%dden_dt
   214)   auxvar2%dkvr_dp = auxvar%dkvr_dp
   215)   auxvar2%dkvr_dt = auxvar%dkvr_dt
   216)   auxvar2%dh_dp = auxvar%dh_dp
   217)   auxvar2%dh_dt = auxvar%dh_dt
   218)   auxvar2%du_dp = auxvar%du_dp
   219)   auxvar2%du_dt = auxvar%du_dt  
   220) #endif
   221)   auxvar2%xmol = auxvar%xmol
   222)   auxvar2%diff = auxvar%diff
   223) 
   224) end subroutine MphaseAuxVarCopy
   225) 
   226) ! ************************************************************************** !
   227) 
   228) subroutine MphaseAuxVarCompute_NINC(x,auxvar,global_auxvar,iphase,saturation_function, &
   229)                                    fluid_properties,option,xphico2)
   230)   ! 
   231)   ! MphaseAuxVarCompute_NI: Computes auxiliary variables for each grid cell
   232)   ! No increments
   233)   ! Author: Chuan Lu
   234)   ! 
   235) 
   236)   use Option_module
   237)   use Global_Aux_module
   238)   use EOS_Water_module
   239)   use Gas_EOS_module
   240)   use co2eos_module
   241)   use co2_span_wagner_module
   242)   use co2_span_wagner_spline_module, only: sw_prop
   243)   use co2_sw_module, only: co2_sw_interp
   244)   use Saturation_Function_module
   245)   use Fluid_module
   246)   use Mphase_pckr_module
   247)   
   248)   implicit none
   249) 
   250)   type(option_type) :: option
   251)   type(fluid_property_type) :: fluid_properties
   252)   type(saturation_function_type) :: saturation_function
   253)   PetscReal :: x(option%nflowdof)
   254)   type(mphase_auxvar_elem_type) :: auxvar
   255)   type(global_auxvar_type) :: global_auxvar
   256)   PetscInt :: iphase
   257)   PetscReal, optional :: xphico2
   258) 
   259)   PetscErrorCode :: ierr
   260)   PetscReal :: pw, dw_kg, dw_mol, hw, sat_pressure, visl
   261)   PetscReal :: p, t, temp, p2, err
   262)   PetscReal :: henry, lngamco2
   263)   PetscReal :: dg, dddp, dddt, m_na, m_cl, m_nacl
   264)   PetscReal :: fg, dfgdp, dfgdt, xphi
   265)   PetscReal :: eng, hg, dhdp, dhdt
   266)   PetscReal :: visg, dvdp, dvdt
   267)   PetscReal :: h(option%nphase), u(option%nphase), kr(option%nphase)
   268)   PetscReal :: xm_nacl, y_nacl, vphi             
   269)   PetscReal :: tk, xco2, pw_kg, x1, vphi_a1, vphi_a2 
   270)   PetscReal :: Qkco2, mco2, xco2eq
   271)   PetscReal :: aux(1)
   272)   PetscInt :: iflag
   273)   
   274)   auxvar%den = 0.d0
   275)   auxvar%sat = 0.d0
   276)   
   277)   auxvar%h = 0.d0
   278)   auxvar%u = 0.d0
   279)   auxvar%avgmw = 0.d0
   280)   auxvar%xmol = 0.d0
   281)   auxvar%pc = 0.d0
   282)   auxvar%kvr = 0.d0
   283)   auxvar%diff = 0.d0
   284)   kr = 0.d0
   285)  
   286)   auxvar%pres = x(1)  
   287)   auxvar%temp = x(2)
   288) 
   289)   p = auxvar%pres
   290)   t = auxvar%temp
   291)   
   292)   select case(iphase)
   293)     case(1)
   294) !******* aqueous phase exists ***********
   295)       auxvar%xmol(2) = x(3)
   296) !      if (auxvar%xmol(2) < 0.D0) print *,'tran:',iphase, x(1:3)
   297) !      if (auxvar%xmol(2) > 1.D0) print *,'tran:',iphase, x(1:3)
   298) !pcl  if (x(3) < 0.d0) then
   299) !pcl    option%io_buffer = 'CO2 mole fraction below zero.  It is likely ' // &
   300) !pcl      'that CO2 aqueous concentrations in transport are inconsistent with flow.'
   301) !pcl    call printErrMsgByRank(option)
   302) !pcl  endif
   303)       auxvar%xmol(1) = 1.D0 - auxvar%xmol(2)
   304)       auxvar%pc(:) = 0.D0
   305)       auxvar%sat(1) = 1.D0
   306)       auxvar%sat(2) = 0.D0
   307)       kr(1)= 1.D0
   308)       kr(2)= 0.D0
   309)     case(2)
   310) !******* gas phase exists ***********
   311)       auxvar%xmol(4) = x(3)
   312) !      if (auxvar%xmol(4) < 0.D0) print *,'tran:',iphase, x(1:3)
   313) !      if (auxvar%xmol(4) > 1.D0) print *,'tran:',iphase, x(1:3)
   314)       auxvar%xmol(3) = 1.D0 - auxvar%xmol(4)
   315)       auxvar%pc(:) = 0.D0
   316)       auxvar%sat(1) = 0.D0
   317)       auxvar%sat(2) = 1.D0
   318)       kr(1)= 0.D0
   319)       kr(2)= 1.D0
   320)     case(3)    
   321) !******* 2-phase phase exists ***********
   322)       auxvar%sat(2) = x(3)
   323)       if (auxvar%sat(2) < 0.D0)then
   324) !        print *,'tran:',iphase, x(1:3)
   325)         auxvar%sat(2) = 0.D0
   326)       endif
   327) !      if (auxvar%sat(2)> 1.D0) print *,'tran:',iphase, x(1:3)
   328)       auxvar%sat(1) = 1.D0 - auxvar%sat(2)
   329)       auxvar%pc(:) = 0.D0
   330)       temp = 1.D-2
   331)       auxvar%xmol(1)=1.D0; auxvar%xmol(2)=0.D0
   332)       auxvar%xmol(3)=temp; auxvar%xmol(4)=1.D0-auxvar%xmol(3)
   333)    end select
   334) ! ********************* Gas phase properties ***********************
   335)     call EOSWaterSaturationPressure(t, sat_pressure, ierr)
   336)     err = 1.D0
   337)     p2 = p
   338) 
   339)     if (p2 >= 5.d4) then
   340)        
   341)       if (option%co2eos == EOS_SPAN_WAGNER) then
   342) ! ************ Span-Wagner EOS ********************             
   343)         select case(option%itable)  
   344)           case(0,1,2,4,5)
   345)             if (option%itable >= 4) then
   346)                 ! print *,' interp', itable
   347)               call co2_sw_interp(p2*1.D-6,t,dg,dddt,dddp,fg, &
   348)                      dfgdp,dfgdt,eng,hg,dhdt,dhdp,visg,dvdt,dvdp,option%itable)
   349)             else
   350)               iflag = 1
   351)               call co2_span_wagner(p2*1.D-6,t+273.15D0,dg,dddt,dddp,fg, &
   352)                      dfgdp,dfgdt,eng,hg,dhdt,dhdp,visg,dvdt,dvdp,iflag, &
   353)                      option%itable)
   354)             endif
   355) 
   356)             dg = dg/FMWCO2
   357)             fg = fg*1.D6 
   358)             hg = hg*FMWCO2
   359)             xphi = fg/p2
   360)             
   361) ! ************* Span-Wagner EOS with Bi-Cubic Spline interpolation ********
   362)           case(3) 
   363)             call sw_prop(t,p2*1.D-6,dg,hg,eng,fg)
   364)             call visco2(t,dg,visg)
   365)             dg = dg/FMWCO2
   366)             fg = fg*1.D6 
   367)             hg = hg*FMWCO2
   368)             xphi = fg/p2
   369)           end select
   370)           
   371)        elseif (option%co2eos == EOS_MRK) then
   372)        
   373) ! MRK eos [modified version from  Kerrick and Jacobs (1981) and Weir et al. (1996).]     
   374)           call CO2(t,p2,dg,fg,xphi,hg)
   375)           call visco2(t,dg,visg)
   376)           dg = dg/FMWCO2
   377)           hg = hg*FMWCO2*option%scale
   378)           !      print *, 'translator', p2,t,dg,hg,visg
   379)        else
   380)          call printErrMsg(option,'pflow mphase ERROR: Need specify CO2 EOS')
   381)       endif
   382)     else      
   383)       call ideal_gaseos_noderiv(p2,t,dg,hg,eng)
   384)       ! J/kmol -> whatever
   385)       hg = hg * option%scale
   386)       eng = eng * option%scale      
   387)       call visco2(t,dg*FMWCO2,visg)
   388)       fg = p2
   389)       xphi = 1.D0
   390)     endif
   391) 
   392)     m_na=option%m_nacl; m_cl=m_na; m_nacl=m_na 
   393)     if (option%ntrandof > 0) then
   394)       m_na = global_auxvar%m_nacl(1)
   395)       m_cl = global_auxvar%m_nacl(2)
   396)       m_nacl = m_na
   397)       if (m_cl > m_na) m_nacl = m_cl
   398)     endif  
   399) 
   400) 
   401)     call Henry_duan_sun(t,p2*1.D-5,henry,lngamco2,m_na,m_cl)
   402)     Qkco2 = henry*xphi  ! convert from bar to Pa
   403)     henry = 1.D0/(FMWH2O*1.D-3)/(henry*1.D-5)/xphi 
   404)     if (present(xphico2)) xphico2 = xphi
   405)    
   406)     mco2 = (p - sat_pressure)*1.D-5*Qkco2
   407)     xco2eq = mco2/(1.D3/fmwh2o + mco2 + m_nacl)
   408) 
   409) !   print *,'mphase_duan_den: ',xco2eq,mco2,m_nacl,qkco2,p,p2,sat_pressure,t
   410) 
   411) !   question here: m_nacl or m_na+m_cl ?
   412)    
   413)     select case(iphase)     
   414)     case(1)
   415)       auxvar%xmol(4) = auxvar%xmol(2)*henry/p   
   416)       auxvar%xmol(3) = 1.D0-auxvar%xmol(4)
   417)       if (auxvar%xmol(3) < 0.D0) auxvar%xmol(3) = 0.D0
   418) !     if (xmol(3) < 0.D0) xmol(3) = 0.D0
   419)     case(2)   
   420)       auxvar%xmol(2) = p*auxvar%xmol(4)/henry
   421)       auxvar%xmol(1) = 1.D0 - auxvar%xmol(2)
   422)     case(3)
   423)       temp= sat_pressure/p
   424)       auxvar%xmol(2) = xco2eq
   425)       auxvar%xmol(1) = 1.D0 - xco2eq
   426)       auxvar%xmol(3) = temp
   427)       auxvar%xmol(4) = 1.D0 - temp            
   428)     end select
   429)     auxvar%avgmw(2) = auxvar%xmol(3)*FMWH2O + auxvar%xmol(4)*FMWCO2
   430)     pw = p
   431)     call EOSWaterDensity(t,pw,dw_kg,dw_mol,ierr) 
   432)     call EOSWaterEnthalpy(t,pw,hw,ierr) 
   433)     hw = hw * option%scale ! J/kmol -> whatever units
   434)     auxvar%den(2) = 1.D0/(auxvar%xmol(4)/dg + auxvar%xmol(3)/dw_mol)
   435)     auxvar%h(2) = hg  
   436)     auxvar%u(2) = hg - p/dg*option%scale
   437)     auxvar%pc(2) = 0.D0
   438) 
   439) !   auxvar%diff(option%nflowspec+1:option%nflowspec*2) = 2.13D-5
   440)     auxvar%diff(option%nflowspec+1:option%nflowspec*2) = &
   441)       fluid_properties%gas_diffusion_coefficient &
   442)       * 101325.d0/p * ((t+273.15d0)/273.15d0)**1.8d0
   443) !       fluid_properties%diff_base(2)
   444) 
   445) !   print *,'gas diff: ',fluid_properties%gas_diffusion_coefficient,p,t
   446)        
   447) !  z factor    
   448)     auxvar%zco2=auxvar%den(2)/(p/IDEAL_GAS_CONSTANT/(t+273.15D0)*1.D-3)
   449) 
   450) !***************  Liquid phase properties **************************
   451)  
   452) !    avgmw(1)= xmol(1)* FMWH2O + xmol(2) * FMWCO2 
   453)     auxvar%h(1) = hw
   454)     auxvar%u(1) = hw - pw/dw_mol*option%scale
   455) 
   456)     auxvar%diff(1:option%nflowspec) = fluid_properties%diffusion_coefficient
   457)   ! fluid_properties%diff_base(1)
   458) 
   459)   
   460)     xm_nacl = m_nacl*FMWNACL
   461)     xm_nacl = xm_nacl/(1.D3 + xm_nacl)
   462)     aux(1) = xm_nacl
   463)     call EOSWaterDensityExt(t,p,aux,dw_kg,dw_mol,ierr)
   464) !   call EOSWaterViscosityNaCl(t,p,xm_nacl,visl)
   465)     call EOSWaterViscosity(t,pw,sat_pressure,0.d0,visl,dvdt,dvdp,ierr)
   466) 
   467) !FEHM mixing ****************************
   468) !  den(1) = xmol(2)*dg + xmol(1)*dw_mol
   469) !  ideal mixing    
   470) !  den(1) = 1.D0/(xmol(2)/dg + xmol(1)/dw_mol) !*c+(1-c)* 
   471) 
   472) !  m_nacl=option%m_nacl
   473) !  if (reaction%species_idx%na_ion_id /= 0 .and. &
   474) !     reaction%species_idx%cl_ion_id /= 0) then
   475) !    m_na = rt_auxvar%pri_molal(reaction%species_idx%na_ion_id)
   476) !    m_cl = rt_auxvar%pri_molal(reaction%species_idx%cl_ion_id)
   477) !    m_nacl = m_na
   478) !    if (m_cl > m_nacl) m_nacl=m_cl
   479) !  endif  
   480) 
   481)     y_nacl = m_nacl/(m_nacl + 1.D3/FMWH2O)
   482) ! **  xmol(1) = xh2o + xnacl
   483)     auxvar%avgmw(1) = auxvar%xmol(1)*((1.D0 - y_nacl)*FMWH2O &
   484)        + y_nacl*FMWNACL) + auxvar%xmol(2)*FMWCO2
   485) 
   486) !duan mixing **************************
   487) #ifdef DUANDEN
   488) !                 units: t [C], p [MPa], dw_kg [kg/m^3]
   489)   call EOSWaterDuanMixture (t,p,auxvar%xmol(2),y_nacl,auxvar%avgmw(1),dw_kg,auxvar%den(1))
   490) 
   491) #else
   492)   auxvar%den(1) = dw_mol
   493) #endif 
   494) !print *,'mixture den: ',t,p,auxvar%xmol(2),y_nacl,auxvar%avgmw(1),dw_kg,auxvar%den(1),dw_mol
   495) 
   496) ! Garcia mixing **************************
   497) #ifdef GARCIA
   498)   vphi = 1D-6*(37.51D0 + t &
   499)        *(-9.585D-2 + t*(8.74D-4 - t*5.044D-7)))
   500)   auxvar%den(1) = dw_kg/(1D0-(FMWCO2*1.D-3-dw_kg*vphi) &
   501)        *auxvar%xmol(2)/(auxvar%avgmw(1)*1.D-3))
   502)   auxvar%den(1) = auxvar%den(1)/auxvar%avgmw(1)
   503) #endif  
   504)        
   505)  ! Hebach, J. Chem.Eng.Data 2004 (49),p950 ***********
   506)  !   den(1) = 949.7109D0 + p*(0.559684D-6 - 0.00097D-12*p) &  
   507)  !      + (t+273.15)*(0.883148 - 0.00228*(t+273.15))  
   508)  !  den(1) = dw_kg + (den(1)-dw_kg)*xmol(2)/p*henry
   509)  !  den(1) = den(1)/avgmw(1)
   510) 
   511) !****************************** 2 phase S-Pc-kr relation ************************
   512)     if (option%nphase >= 2) then
   513)       if (saturation_function%hysteresis_id <= 0.1D0) then 
   514)         call pckrNH_noderiv(auxvar%sat,auxvar%pc,kr, &
   515)                                    saturation_function, &
   516)                                    option)
   517)         pw=p !-pc(1)
   518)      
   519)       else
   520)         call pckrHY_noderiv(auxvar%sat,auxvar%hysdat,auxvar%pc,kr, &
   521)                                    saturation_function, &
   522)                                    option)
   523)       end if
   524)     endif
   525) 
   526) !    call SaturationFunctionCompute(auxvar%pres,auxvar%sat,kr, &
   527) !                                   ds_dp,dkr_dp, &
   528) !                                   saturation_function, &
   529) !                                   por,perm, &
   530) !                                   option)
   531)     auxvar%kvr(2) = kr(2)/visg     
   532)     auxvar%kvr(1) = kr(1)/visl
   533)     auxvar%vis(2) = visg     
   534)     auxvar%vis(1) = visl
   535)     select case(iphase)
   536)       case(1)
   537)         auxvar%pc =0.D0
   538)       case(2)
   539)         auxvar%pc =0.D0
   540)     end select          
   541) 
   542) end subroutine MphaseAuxVarCompute_NINC
   543) 
   544) ! ************************************************************************** !
   545) 
   546) subroutine MphaseAuxVarCompute_WINC(x,delx,auxvar,global_auxvar,iphase,saturation_function, &
   547)                                     fluid_properties,option)
   548) 
   549)   use Option_module
   550)   use Global_Aux_module
   551)   
   552)   use Saturation_Function_module
   553)   use Fluid_module
   554)   
   555)   implicit none
   556) 
   557)   type(option_type) :: option
   558)   type(fluid_property_type) :: fluid_properties
   559)   type(saturation_function_type) :: saturation_function
   560)   PetscReal :: x(option%nflowdof), xx(option%nflowdof), delx(option%nflowdof)
   561)   type(mphase_auxvar_elem_type) :: auxvar(1:option%nflowdof)
   562)   type(global_auxvar_type) :: global_auxvar
   563) 
   564)   PetscInt :: iphase
   565) 
   566)   PetscInt :: n 
   567)   
   568)   do n=1, option%nflowdof
   569)      xx=x;  xx(n)=x(n)+ delx(n)
   570) ! ***   note: var_node here starts from 1 to option%flowdof ***
   571)     call  MphaseAuxVarCompute_NINC(xx,auxvar(n),global_auxvar,iphase, &
   572)                                    saturation_function, &
   573)                                    fluid_properties, option)
   574)   enddo
   575) 
   576) end subroutine MphaseAuxVarCompute_WINC
   577) 
   578) ! ************************************************************************** !
   579) 
   580) subroutine MphaseAuxVarElemDestroy(auxvar_elem)
   581)   ! 
   582)   ! Deallocates a mphase auxiliary elment object
   583)   ! 
   584)   implicit none
   585) 
   586)   type(mphase_auxvar_elem_type) :: auxvar_elem
   587) 
   588)   if (associated(auxvar_elem%xmol)) deallocate(auxvar_elem%xmol)
   589)   nullify(auxvar_elem%xmol)
   590)   if (associated(auxvar_elem%diff))deallocate(auxvar_elem%diff)
   591)   nullify(auxvar_elem%diff)
   592)   if (associated(auxvar_elem%pc))deallocate(auxvar_elem%pc)
   593)   nullify(auxvar_elem%pc)
   594)   if (associated(auxvar_elem%sat))deallocate(auxvar_elem%sat)
   595)   nullify(auxvar_elem%sat)
   596)   if (associated(auxvar_elem%u))deallocate(auxvar_elem%u)
   597)   nullify(auxvar_elem%u)
   598)   if (associated(auxvar_elem%h))deallocate(auxvar_elem%h)
   599)   nullify(auxvar_elem%h)
   600)   if (associated(auxvar_elem%den))deallocate(auxvar_elem%den)
   601)   nullify(auxvar_elem%den)
   602)   if (associated(auxvar_elem%vis))deallocate(auxvar_elem%vis)
   603)    nullify(auxvar_elem%vis)
   604)    if (associated(auxvar_elem%avgmw))deallocate(auxvar_elem%avgmw)
   605)    nullify(auxvar_elem%avgmw)
   606)   if (associated(auxvar_elem%kvr))deallocate(auxvar_elem%kvr)
   607)   nullify(auxvar_elem%kvr)
   608)   if (associated(auxvar_elem%vis))deallocate(auxvar_elem%vis)
   609)   nullify(auxvar_elem%vis)
   610) 
   611) end subroutine MphaseAuxVarElemDestroy
   612) 
   613) ! ************************************************************************** !
   614) 
   615) subroutine MphaseAuxVarDestroy(auxvar)
   616)   ! 
   617)   ! Deallocates a mphase auxiliary object
   618)   ! 
   619)   implicit none
   620) 
   621)   type(mphase_auxvar_type) :: auxvar
   622) 
   623)   PetscInt :: ielem
   624) 
   625)   deallocate(auxvar%auxvar_elem(0)%hysdat)
   626)   nullify(auxvar%auxvar_elem(0)%hysdat)
   627) 
   628)   ! subtract 1 since indexing from 0
   629)   if (associated(auxvar%auxvar_elem)) then
   630)     do ielem = 0, size(auxvar%auxvar_elem) - 1 
   631)       call MphaseAuxVarElemDestroy(auxvar%auxvar_elem(ielem))
   632)     enddo
   633)     deallocate(auxvar%auxvar_elem)
   634)     nullify(auxvar%auxvar_elem)
   635)   endif
   636) 
   637) end subroutine MphaseAuxVarDestroy
   638) 
   639) ! ************************************************************************** !
   640) 
   641) subroutine MphaseAuxDestroy(aux)
   642)   ! 
   643)   ! Deallocates a mphase auxiliary object
   644)   ! 
   645)   implicit none
   646) 
   647)   type(mphase_type), pointer :: aux
   648) 
   649)   PetscInt :: iaux
   650)   
   651)   if (.not.associated(aux)) return
   652) 
   653)   if (associated(aux%auxvars)) then
   654)     do iaux = 1, aux%num_aux
   655)       call MphaseAuxVarDestroy(aux%auxvars(iaux))
   656)     enddo
   657)     deallocate(aux%auxvars)
   658)     nullify(aux%auxvars)
   659)   endif
   660)   
   661)   if (associated(aux%auxvars_bc)) then
   662)     do iaux = 1, aux%num_aux_bc
   663)       call MphaseAuxVarDestroy(aux%auxvars_bc(iaux))
   664)     enddo
   665)     deallocate(aux%auxvars_bc)
   666)     nullify(aux%auxvars_bc)
   667)   endif
   668)   
   669)   if (associated(aux%auxvars_ss)) then
   670)     do iaux = 1, aux%num_aux_ss
   671)       call MphaseAuxVarDestroy(aux%auxvars_ss(iaux))
   672)     enddo
   673)     deallocate(aux%auxvars_ss)
   674)     nullify(aux%auxvars_ss)
   675)   endif
   676)   
   677)   if (associated(aux%zero_rows_local)) deallocate(aux%zero_rows_local)
   678)   nullify(aux%zero_rows_local)
   679)   if (associated(aux%zero_rows_local_ghosted)) deallocate(aux%zero_rows_local_ghosted)
   680)   nullify(aux%zero_rows_local_ghosted)
   681)   if (associated(aux%mphase_parameter)) then
   682)     if (associated(aux%mphase_parameter%dencpr)) deallocate(aux%mphase_parameter%dencpr)
   683)     nullify(aux%mphase_parameter%dencpr)
   684)     if (associated(aux%mphase_parameter%ckwet)) deallocate(aux%mphase_parameter%ckwet)
   685)     nullify(aux%mphase_parameter%ckwet)
   686)     if (associated(aux%mphase_parameter%sir)) deallocate(aux%mphase_parameter%sir)
   687)     nullify(aux%mphase_parameter%sir)
   688)     deallocate(aux%mphase_parameter)
   689)   endif
   690)   nullify(aux%mphase_parameter)
   691)   if (associated(aux%res_old_AR)) deallocate(aux%res_old_AR)
   692)   if (associated(aux%res_old_FL)) deallocate(aux%res_old_FL)
   693)   if (associated(aux%delx)) deallocate(aux%delx)
   694)   
   695)   deallocate(aux)
   696)   nullify(aux)
   697)   
   698) end subroutine MphaseAuxDestroy
   699) 
   700) end module Mphase_Aux_module
   701) 
   702) 

generated by
Intel(R) C++/Fortran Compiler code-coverage tool
Web-Page Owner: Nobody