toil_ims_aux.F90       coverage:  88.89 %func     88.98 %block


     1) module TOilIms_Aux_module
     2) 
     3)   use PFLOTRAN_Constants_module
     4) 
     5)   implicit none
     6)   
     7)   private 
     8) 
     9) #include "petsc/finclude/petscsys.h"
    10) 
    11)   !BEGINNING-Paramters to move into toil_ims_paramters 
    12)   PetscReal, public :: toil_ims_window_epsilon = 1.d-4
    13)   PetscReal, public :: toil_ims_fmw_comp(2) = & ! initialised after EOSread
    14)                         [UNINITIALIZED_DOUBLE,UNINITIALIZED_DOUBLE]
    15)   PetscReal, public :: toil_ims_max_pressure_change = 5.d4
    16)   PetscInt, public :: toil_ims_max_it_before_damping = UNINITIALIZED_INTEGER
    17)   PetscReal, public :: toil_ims_damping_factor = 0.6d0
    18)   PetscReal, public :: toil_ims_itol_rel_update = UNINITIALIZED_DOUBLE
    19)   PetscReal, public :: toil_ims_itol_scaled_res = 1.d-5
    20)   PetscReal, public :: toil_ims_tgh2_itol_scld_res_e1(3) = 1.d-5
    21)   PetscReal, public :: toil_ims_tgh2_itol_scld_res_e2 = 1.d0
    22)   PetscBool, public :: toil_ims_tough2_conv_criteria = PETSC_FALSE
    23)   PetscInt, public :: toil_ims_debug_cell_id = UNINITIALIZED_INTEGER
    24)   !END-Paramters to move into toil_ims_paramters
    25) 
    26)   ! if needed must be specifi to toil_ims (e.g. TOIL_IMS_PREV_TS)
    27)   !PetscInt, parameter, public :: TOIL_IMS_PREV_TS = 1
    28)   !PetscInt, parameter, public :: TOIL_IMS_PREV_IT = 2
    29) 
    30)   ! Primary DOF indices 
    31)   PetscInt, parameter, public :: TOIL_IMS_PRESSURE_DOF = 1
    32)   PetscInt, parameter, public :: TOIL_IMS_SATURATION_DOF = 2
    33)   PetscInt, parameter, public :: TOIL_IMS_ENERGY_DOF = 3
    34) 
    35)   ! Equation indices   
    36)   PetscInt, parameter, public :: TOIL_IMS_LIQUID_EQUATION_INDEX = 1
    37)   PetscInt, parameter, public :: TOIL_IMS_OIL_EQUATION_INDEX = 2
    38)   PetscInt, parameter, public :: TOIL_IMS_ENERGY_EQUATION_INDEX = 3
    39) 
    40)   ! Indices used to map aux_real for condition values 
    41)   PetscInt, parameter, public :: TOIL_IMS_PRESSURE_INDEX = 1
    42)   PetscInt, parameter, public :: TOIL_IMS_OIL_SATURATION_INDEX = 2
    43)   PetscInt, parameter, public :: TOIL_IMS_TEMPERATURE_INDEX = 3
    44)   PetscInt, parameter, public :: TOIL_IMS_LIQUID_FLUX_INDEX = 4
    45)   PetscInt, parameter, public :: TOIL_IMS_OIL_FLUX_INDEX = 5
    46)   PetscInt, parameter, public :: TOIL_IMS_ENERGY_FLUX_INDEX = 6
    47)   PetscInt, parameter, public :: TOIL_IMS_LIQ_CONDUCTANCE_INDEX = 7
    48)   PetscInt, parameter, public :: TOIL_IMS_OIL_CONDUCTANCE_INDEX = 8
    49)   PetscInt, parameter, public :: TOIL_IMS_MAX_INDEX = 9
    50) 
    51)   PetscInt, parameter, public :: TOIL_IMS_UPDATE_FOR_DERIVATIVE = -1
    52)   PetscInt, parameter, public :: TOIL_IMS_UPDATE_FOR_FIXED_ACCUM = 0
    53)   PetscInt, parameter, public :: TOIL_IMS_UPDATE_FOR_ACCUM = 1
    54)   PetscInt, parameter, public :: TOIL_IMS_UPDATE_FOR_BOUNDARY = 2
    55) 
    56)   PetscReal, parameter, public :: toil_ims_pressure_scale = 1.d0
    57)   
    58)   ! these variables, which are global to general, can be modified
    59)   PetscInt, public :: toil_ims_dof_to_primary_vars(3) ! only one 2ph state 
    60)   PetscBool, public :: toil_ims_isothermal = PETSC_FALSE
    61) 
    62)   !phase mapping:
    63)   !While LIQUID_PHASE = 1 alway, OIL_PHASE can be:
    64)   ! 2 for brine/oil
    65)   ! 3 for brine/gas/oil (can be 2 again, but then GAS_PHASE requires
    66)   !                      a different index). Need mapping in any case
    67)   PetscInt, parameter, public :: TOIL_IMS_OIL_PHASE = 2
    68) 
    69)   type, public :: toil_ims_auxvar_type
    70)     !PetscInt :: istate_store(2) ! 1 = previous timestep; 2 = previous iteration
    71)     PetscReal, pointer :: pres(:)   ! (iphase)
    72)     PetscReal, pointer :: sat(:)    ! (iphase)
    73)     PetscReal, pointer :: den(:)    ! (iphase) kmol/m^3 phase
    74)     PetscReal, pointer :: den_kg(:) ! (iphase) kg/m^3 phase
    75)     PetscReal :: temp
    76)     PetscReal, pointer :: H(:) ! MJ/kmol
    77)     PetscReal, pointer :: U(:) ! MJ/kmol
    78) !    PetscReal, pointer :: dsat_dp(:,:)
    79) !    PetscReal, pointer :: dden_dp(:,:)
    80) !    PetscReal, pointer :: dsat_dt(:)
    81) !    PetscReal, pointer :: dden_dt(:)
    82)     PetscReal, pointer :: mobility(:) ! relative perm / kinematic viscosity
    83)     PetscReal :: effective_porosity ! factors in compressibility
    84)     PetscReal :: pert
    85) !    PetscReal, pointer :: dmobility_dp(:)
    86)   end type toil_ims_auxvar_type
    87) 
    88)   ! it might be required for thermal diffusion terms and tough conv criteria
    89)   ! consider to pput here all 
    90)   type, public :: toil_ims_parameter_type
    91)   !  PetscReal, public :: window_epsilon 
    92)   !  PetscReal, pointer :: diffusion_coefficient(:) ! (iphase)
    93)   !  PetscReal :: newton_inf_scaled_res_tol
    94)   !  PetscBool :: check_post_converged
    95)   end type toil_ims_parameter_type
    96) 
    97)   type, public :: toil_ims_type
    98)     PetscInt :: n_inactive_rows
    99)     PetscInt, pointer :: inactive_rows_local(:), inactive_rows_local_ghosted(:)
   100)     PetscInt, pointer :: row_zeroing_array(:)
   101) 
   102)     PetscBool :: auxvars_up_to_date
   103)     PetscBool :: inactive_cells_exist
   104)     PetscInt :: num_aux, num_aux_bc, num_aux_ss
   105)     type(toil_ims_parameter_type), pointer :: parameter
   106)     type(toil_ims_auxvar_type), pointer :: auxvars(:,:)
   107)     type(toil_ims_auxvar_type), pointer :: auxvars_bc(:)
   108)     type(toil_ims_auxvar_type), pointer :: auxvars_ss(:)
   109)   end type toil_ims_type
   110) 
   111)   interface TOilImsAuxVarDestroy
   112)     module procedure TOilImsAuxVarSingleDestroy
   113)     module procedure TOilImsAuxVarArray1Destroy
   114)     module procedure TOilImsAuxVarArray2Destroy
   115)   end interface TOilImsAuxVarDestroy
   116)   
   117) !  interface TOilImsOutputAuxVars
   118) !    module procedure TOilImsOutputAuxVars1
   119) !    module procedure TOilImsOutputAuxVars2
   120) !  end interface TOilImsOutputAuxVars
   121)   public :: TOilImsAuxCreate, &
   122)             TOilImsAuxDestroy, &
   123)             TOilImsAuxVarInit, &
   124)             TOilImsAuxVarCompute, &
   125)             TOilImsAuxVarPerturb, &
   126)             TOilImsAuxVarDestroy, &
   127)             TOilImsAuxVarStrip
   128)             
   129) 
   130) contains
   131) 
   132) 
   133) ! ************************************************************************** !
   134) 
   135) function TOilImsAuxCreate(option)
   136)   ! 
   137)   ! Allocate and initialize auxiliary object
   138)   ! 
   139)   ! Author: Paolo Orsini (OGS)
   140)   ! Date: 10/20/25
   141)   ! 
   142) 
   143)   use Option_module
   144)   use EOS_Oil_module
   145) 
   146)   implicit none
   147) 
   148)   type(option_type) :: option
   149)     
   150)   type(toil_ims_type), pointer :: TOilImsAuxCreate
   151)   
   152)   type(toil_ims_type), pointer :: aux
   153) 
   154)   ! there is no variable switch, but this map can be used 
   155)   ! to change the primary variable set 
   156)   toil_ims_dof_to_primary_vars(1:3) = &
   157)        [TOIL_IMS_PRESSURE_INDEX, TOIL_IMS_OIL_SATURATION_INDEX, &
   158)         TOIL_IMS_TEMPERATURE_INDEX]
   159) 
   160)   toil_ims_fmw_comp(LIQUID_PHASE) = FMWH2O
   161)   !toil_ims_fmw_comp(TOIL_IMS_OIL_PHASE) = fmw_oil ! this defines the dead oil
   162)   toil_ims_fmw_comp(TOIL_IMS_OIL_PHASE) = EOSOilGetFMW() !defines the dead oil
   163)   
   164)   allocate(aux) 
   165)   aux%auxvars_up_to_date = PETSC_FALSE
   166)   aux%inactive_cells_exist = PETSC_FALSE
   167)   aux%num_aux = 0
   168)   aux%num_aux_bc = 0
   169)   aux%num_aux_ss = 0
   170)   nullify(aux%auxvars)
   171)   nullify(aux%auxvars_bc)
   172)   nullify(aux%auxvars_ss)
   173)   aux%n_inactive_rows = 0
   174)   nullify(aux%inactive_rows_local)
   175)   nullify(aux%inactive_rows_local_ghosted)
   176)   nullify(aux%row_zeroing_array)
   177) 
   178)   allocate(aux%parameter)
   179)   !aux%parameter%window_epsilon = 1.d-4 
   180) 
   181)   ! fluid diffusion not needed 
   182)   !allocate(aux%general_parameter)
   183)   !allocate(aux%general_parameter%diffusion_coefficient(option%nphase))
   184)   !geh: there is no point in setting default lquid diffusion coeffcient values 
   185)   !     here as they will be overwritten by the fluid property defaults.
   186)   !aux%general_parameter%diffusion_coefficient(LIQUID_PHASE) = &
   187)   !                                                         UNINITIALIZED_DOUBLE
   188)   !aux%general_parameter%diffusion_coefficient(GAS_PHASE) = 2.13d-5
   189)   !aux%general_parameter%newton_inf_scaled_res_tol = 1.d-50
   190)   !aux%general_parameter%check_post_converged = PETSC_FALSE
   191) 
   192)   TOilImsAuxCreate => aux
   193)   
   194) end function TOilImsAuxCreate
   195) 
   196) ! ************************************************************************** !
   197) 
   198) subroutine TOilImsAuxVarInit(auxvar,option)
   199)   ! 
   200)   ! Initialize auxiliary object
   201)   ! 
   202)   ! Author: PAolo Orsini
   203)   ! Date: 10/20/15
   204)   ! 
   205) 
   206)   use Option_module
   207) 
   208)   implicit none
   209)   
   210)   type(toil_ims_auxvar_type) :: auxvar
   211)   type(option_type) :: option
   212) 
   213)   !auxvar%istate_store = NULL_STATE
   214)   auxvar%temp = 0.d0
   215)   auxvar%effective_porosity = 0.d0
   216)   auxvar%pert = 0.d0
   217)   
   218)   ! pressure for the two phases (water,oil) and capillary pressure
   219)   allocate(auxvar%pres(option%nphase+ONE_INTEGER))
   220)   auxvar%pres = 0.d0
   221)   allocate(auxvar%sat(option%nphase))
   222)   auxvar%sat = 0.d0
   223)   allocate(auxvar%den(option%nphase))
   224)   auxvar%den = 0.d0
   225)   allocate(auxvar%den_kg(option%nphase))
   226)   auxvar%den_kg = 0.d0
   227)   allocate(auxvar%H(option%nphase))
   228)   auxvar%H = 0.d0
   229)   allocate(auxvar%U(option%nphase))
   230)   auxvar%U = 0.d0
   231)   allocate(auxvar%mobility(option%nphase))
   232)   auxvar%mobility = 0.d0
   233)   
   234) end subroutine TOilImsAuxVarInit
   235) 
   236) ! ************************************************************************** !
   237) 
   238) subroutine TOilImsAuxVarCompute(x,toil_auxvar,global_auxvar,material_auxvar, &
   239)                                 characteristic_curves,natural_id,option)
   240)   ! 
   241)   ! Computes auxiliary variables for each grid cell
   242)   ! 
   243)   ! Author: Paolo Orsini
   244)   ! Date: 10/21/15
   245)   ! 
   246) 
   247)   use Option_module
   248)   use Global_Aux_module
   249)   use EOS_Water_module
   250)   use EOS_Oil_module
   251)   use Characteristic_Curves_module
   252)   use Material_Aux_class
   253)   
   254)   implicit none
   255) 
   256)   type(option_type) :: option
   257)   class(characteristic_curves_type) :: characteristic_curves
   258)   PetscReal :: x(option%nflowdof)
   259)   type(toil_ims_auxvar_type) :: toil_auxvar
   260)   type(global_auxvar_type) :: global_auxvar ! passing this for salt conc.
   261)                                             ! not currenty used  
   262)   class(material_auxvar_type) :: material_auxvar
   263)   PetscInt :: natural_id !only for debugging/print out - currently not used 
   264) 
   265)   PetscInt :: lid, oid, cpid
   266)   PetscReal :: cell_pressure, wat_sat_pres
   267)   PetscReal :: krl, visl, dkrl_Se
   268)   PetscReal :: kro, viso, dkro_Se
   269)   PetscReal :: dummy
   270)   PetscReal :: Uoil_J_kg, Hoil_J_kg
   271)   PetscErrorCode :: ierr
   272) 
   273)   ! from SubsurfaceSetFlowMode
   274) !    class is (pm_toil_ims_type)
   275) !      option%iflowmode = TOIL_IMS_MODE
   276) !      option%nphase = 2
   277) !      option%liquid_phase = 1           ! liquid_pressure
   278) !      option%oil_phase = 2              ! oil_pressure
   279) !      option%capillary_pressure_id = 3  ! capillary pressure
   280) !
   281)  
   282)   lid = option%liquid_phase
   283)   oid = option%oil_phase
   284)   cpid = option%capillary_pressure_id
   285) 
   286)   ! do we need this initializations? All values are overwritten below 
   287)   toil_auxvar%H = 0.d0
   288)   toil_auxvar%U = 0.d0
   289)   toil_auxvar%pres = 0.d0
   290)   toil_auxvar%sat = 0.d0
   291)   toil_auxvar%den = 0.d0
   292)   toil_auxvar%den_kg = 0.d0
   293)   toil_auxvar%effective_porosity = 0.d0
   294) 
   295)   toil_auxvar%mobility = 0.d0
   296) 
   297)   !assing auxvars given by the solution variables
   298)   toil_auxvar%pres(oid) = x(TOIL_IMS_PRESSURE_DOF)
   299)   toil_auxvar%sat(oid) = x(TOIL_IMS_SATURATION_DOF)
   300)   toil_auxvar%temp = x(TOIL_IMS_ENERGY_DOF)
   301) 
   302)   toil_auxvar%sat(lid) = 1.d0 - toil_auxvar%sat(oid)
   303)       
   304)   call characteristic_curves%saturation_function% &
   305)              CapillaryPressure(toil_auxvar%sat(lid),toil_auxvar%pres(cpid), &
   306)                                option)                             
   307) 
   308)   ! Testing zero capillary pressure
   309)   !toil_auxvar%pres(cpid) = 0.d0
   310) 
   311)   toil_auxvar%pres(lid) = toil_auxvar%pres(oid) - &
   312)                           toil_auxvar%pres(cpid)
   313) 
   314)   cell_pressure = max(toil_auxvar%pres(lid),toil_auxvar%pres(oid))
   315) 
   316) 
   317)   ! calculate effective porosity as a function of pressure
   318)   if (option%iflag /= TOIL_IMS_UPDATE_FOR_BOUNDARY) then
   319)     toil_auxvar%effective_porosity = material_auxvar%porosity_base
   320) 
   321)     if (soil_compressibility_index > 0) then
   322)       call MaterialCompressSoil(material_auxvar,cell_pressure, &
   323)                                 toil_auxvar%effective_porosity,dummy)
   324)     endif
   325)     if (option%iflag /= TOIL_IMS_UPDATE_FOR_DERIVATIVE) then
   326)       material_auxvar%porosity = toil_auxvar%effective_porosity
   327)     endif
   328)   endif
   329) 
   330)   ! UPDATE THERMODYNAMIC PROPERTIES FOR BOTH PHASES!!!
   331) 
   332)   ! Liquid phase thermodynamic properties
   333)   ! must use cell_pressure as the pressure, not %pres(lid)
   334)   call EOSWaterDensity(toil_auxvar%temp,cell_pressure, &
   335)                        toil_auxvar%den_kg(lid),toil_auxvar%den(lid),ierr)
   336)   call EOSWaterEnthalpy(toil_auxvar%temp,cell_pressure,toil_auxvar%H(lid),ierr)
   337)   toil_auxvar%H(lid) = toil_auxvar%H(lid) * 1.d-6 ! J/kmol -> MJ/kmol
   338)   ! MJ/kmol comp
   339)   toil_auxvar%U(lid) = toil_auxvar%H(lid) - &
   340)                        ! Pa / kmol/m^3 * 1.e-6 = MJ/kmol
   341)                        (cell_pressure / toil_auxvar%den(lid) * &
   342)                         1.d-6)
   343) 
   344)   ! ADD HERE BRINE dependency. Two options (see mphase)
   345)   ! - salinity constant in space and time (passed in option%option%m_nacl)
   346)   ! - salt can be trasnported by RT (sequential coupling) and passed 
   347)   !   and passed with global_auxvar%m_nacl 
   348)   !  ! Assign salinity 
   349)   !  m_na=option%m_nacl; m_cl=m_na; m_nacl=m_na 
   350)   !  if (option%ntrandof > 0) then
   351)   !    m_na = global_auxvar%m_nacl(1)
   352)   !    m_cl = global_auxvar%m_nacl(2)
   353)   !    m_nacl = m_na
   354)   !    if (m_cl > m_na) m_nacl = m_cl
   355)   !  endif    
   356)   !
   357)   !  ! calculate density for pure water
   358)   !  call EOSWaterDensityEnthalpy(t,pw,dw_kg,dw_mol,hw,ierr)
   359)   !  !..................
   360)   !  xm_nacl = m_nacl*FMWNACL
   361)   !  xm_nacl = xm_nacl/(1.D3 + xm_nacl)
   362)   !  ! corrects water densit previously calculated as pure water
   363)   !  call EOSWaterDensityNaCl(t,p,xm_nacl,dw_kg)  
   364)   !  ! water viscosity dependence on salt concetration, but no derivatives
   365)   !  !  call EOSWaterViscosityNaCl(t,p,xm_nacl,visl)
   366)   !  call EOSWaterViscosity(t,pw,sat_pressure,0.d0,visl,dvdt,dvdp,dvdps,ierr)
   367) 
   368)   call EOSOilDensityEnergy(toil_auxvar%temp,toil_auxvar%pres(oid),&
   369)                            toil_auxvar%den(oid),toil_auxvar%H(oid), &
   370)                            toil_auxvar%U(oid),ierr)
   371) 
   372)   !toil_auxvar%den_kg(oid) = toil_auxvar%den(oid) * fmw_oil 
   373)   toil_auxvar%den_kg(oid) = toil_auxvar%den(oid) * EOSOilGetFMW()
   374) 
   375)   toil_auxvar%H(oid) = toil_auxvar%H(oid) * 1.d-6 ! J/kmol -> MJ/kmol
   376)   toil_auxvar%U(oid) = toil_auxvar%U(oid) * 1.d-6 ! J/kmol -> MJ/kmol
   377) 
   378)   ! compute water mobility (rel. perm / viscostiy)
   379)   call characteristic_curves%liq_rel_perm_function% &
   380)          RelativePermeability(toil_auxvar%sat(lid),krl,dkrl_Se,option)
   381)                             
   382)   call EOSWaterSaturationPressure(toil_auxvar%temp, wat_sat_pres,ierr)                   
   383) 
   384)   ! use cell_pressure; cell_pressure - psat calculated internally
   385)   call EOSWaterViscosity(toil_auxvar%temp,cell_pressure,wat_sat_pres,visl,ierr)
   386) 
   387)   toil_auxvar%mobility(lid) = krl/visl
   388) 
   389) 
   390)   ! compute oil mobility (rel. perm / viscostiy)
   391)   call characteristic_curves%oil_rel_perm_function% &
   392)          RelativePermeability(toil_auxvar%sat(lid),kro,dkro_Se,option)
   393) 
   394)   call EOSOilViscosity(toil_auxvar%temp,toil_auxvar%pres(oid), &
   395)                        toil_auxvar%den(oid), viso, ierr)
   396) 
   397)   toil_auxvar%mobility(oid) = kro/viso
   398) 
   399) 
   400) end subroutine TOilImsAuxVarCompute
   401) 
   402) ! ************************************************************************** !
   403) 
   404) subroutine TOilImsAuxVarPerturb(toil_auxvar,global_auxvar, &
   405)                                 material_auxvar, &
   406)                                 characteristic_curves,natural_id, &
   407)                                 option)
   408)   ! 
   409)   ! Calculates auxiliary variables for perturbed system
   410)   ! 
   411)   ! Author: Paolo Orsini
   412)   ! Date: 11/05/15
   413)   ! 
   414) 
   415)   use Option_module
   416)   use Characteristic_Curves_module
   417)   use Global_Aux_module
   418)   use Material_Aux_class
   419) 
   420)   implicit none
   421) 
   422)   type(option_type) :: option
   423)   PetscInt :: natural_id !only for debugging/print out - currently not used 
   424)   type(toil_ims_auxvar_type) :: toil_auxvar(0:)
   425)   type(global_auxvar_type) :: global_auxvar
   426)   class(material_auxvar_type) :: material_auxvar
   427)   class(characteristic_curves_type) :: characteristic_curves
   428)      
   429)   PetscReal :: x(option%nflowdof), x_pert(option%nflowdof), &
   430)                pert(option%nflowdof), x_pert_save(option%nflowdof)
   431) 
   432)   PetscReal :: res(option%nflowdof), res_pert(option%nflowdof)
   433)   PetscReal :: tempreal
   434) 
   435)   ! IMS uses 1.d-8 for Press and 1.d-5 for Sat ad Temp
   436)   ! MPHASE uses 1.d-8 for Press, Sat and Temp  
   437)   ! GENERAL uses 1.d-8 for Press, Sat and Temp
   438)   PetscReal, parameter :: perturbation_tolerance = 1.d-8
   439)   !PetscReal, parameter :: perturbation_tolerance = 1.d-5
   440) 
   441)   !PetscReal, parameter :: min_mole_fraction_pert = 1.d-12
   442)   ! From General (min perturb = 1.d-10)
   443)   PetscReal, parameter :: min_perturbation = 1.d-10
   444)   !PetscReal, parameter :: min_perturbation = 1.d-7
   445)   PetscInt :: idof
   446) 
   447)   x(TOIL_IMS_PRESSURE_DOF) = &
   448)      toil_auxvar(ZERO_INTEGER)%pres(option%oil_phase)
   449)   x(TOIL_IMS_SATURATION_DOF) = &
   450)      toil_auxvar(ZERO_INTEGER)%sat(option%oil_phase)
   451) 
   452)   x(TOIL_IMS_ENERGY_DOF) = toil_auxvar(ZERO_INTEGER)%temp
   453) 
   454)   pert(TOIL_IMS_ENERGY_DOF) = &
   455)            perturbation_tolerance*x(TOIL_IMS_ENERGY_DOF)+min_perturbation
   456) 
   457)   ! below how the water pressure is perturbed in general
   458)   ! pert(GENERAL_LIQUID_PRESSURE_DOF) = &
   459)   !      perturbation_tolerance*x(GENERAL_LIQUID_PRESSURE_DOF) + &
   460)   !      min_perturbation
   461)   pert(TOIL_IMS_PRESSURE_DOF) = &
   462)          perturbation_tolerance*x(TOIL_IMS_PRESSURE_DOF)+min_perturbation
   463) 
   464)   ! always perturb toward 0.5 (0.9 is used in ims and mphase
   465)   if (x(TOIL_IMS_SATURATION_DOF) > 0.5d0) then 
   466)       pert(TOIL_IMS_SATURATION_DOF) = -1.d0 * perturbation_tolerance
   467)   else
   468)      pert(TOIL_IMS_SATURATION_DOF) = perturbation_tolerance
   469)   endif
   470) 
   471) ! below constrains from ims and mphase - might not be needed is post-solve checks
   472) !  if (pert(TOIL_IMS_SATURATION_DOF) < 1D-12 .and. pert(TOIL_IMS_SATURATION_DOF) >= 0.D0) &
   473) !     pert(TOIL_IMS_SATURATION_DOF) = 1D-12
   474) !  if (pert(TOIL_IMS_SATURATION_DOF) > -1D-12 .and. pert(TOIL_IMS_SATURATION_DOF) < 0.D0) &
   475) !     pert(TOIL_IMS_SATURATION_DOF) = -1D-12
   476) !       
   477) !  if ( ( pert(TOIL_IMS_SATURATION_DOF)+ x(TOIL_IMS_SATURATION_DOF) )>1.D0) then
   478) !    pert(TOIL_IMS_SATURATION_DOF) = (1.D0-pert(TOIL_IMS_SATURATION_DOF))*1D-6
   479) !  endif
   480) !  if (( pert(TOIL_IMS_SATURATION_DOF)+x(TOIL_IMS_SATURATION_DOF) ) < 0.D0)then
   481) !    pert(TOIL_IMS_SATURATION_DOF) = x(TOIL_IMS_SATURATION_DOF)*1D-6
   482) !  endif
   483) 
   484) 
   485)   ! TOIL_IMS_UPDATE_FOR_DERIVATIVE indicates call from perturbation
   486)   option%iflag = TOIL_IMS_UPDATE_FOR_DERIVATIVE
   487)   do idof = 1, option%nflowdof
   488)     toil_auxvar(idof)%pert = pert(idof)
   489)     x_pert = x
   490)     x_pert(idof) = x(idof) + pert(idof)
   491)     x_pert_save = x_pert
   492)     call TOilImsAuxVarCompute(x_pert,toil_auxvar(idof),global_auxvar, &
   493)                               material_auxvar, &
   494)                               characteristic_curves,natural_id,option)
   495) 
   496) !#ifdef DEBUG_GENERAL
   497) !    call GlobalAuxVarCopy(global_auxvar,global_auxvar_debug,option)
   498) !    call GeneralAuxVarCopy(gen_auxvar(idof),general_auxvar_debug,option)
   499) !    call GeneralAuxVarUpdateState(x_pert,general_auxvar_debug, &
   500) !                                  global_auxvar_debug, &
   501) !                                  material_auxvar, &
   502) !                                  characteristic_curves, &
   503) !                                  natural_id,option)
   504) !    if (global_auxvar%istate /= global_auxvar_debug%istate) then
   505) !      write(option%io_buffer, &
   506) !            &'(''Change in state due to perturbation: '',i3,'' -> '',i3, &
   507) !            &'' at cell '',i3,'' for dof '',i3)') &
   508) !        global_auxvar%istate, global_auxvar_debug%istate, natural_id, idof
   509) !      call printMsg(option)
   510) !      write(option%io_buffer,'(''orig: '',6es17.8)') x(1:3)
   511) !      call printMsg(option)
   512) !      write(option%io_buffer,'(''pert: '',6es17.8)') x_pert_save(1:3)
   513) !      call printMsg(option)
   514) !    endif
   515) !#endif
   516) 
   517)   enddo
   518) 
   519)   toil_auxvar(TOIL_IMS_PRESSURE_DOF)%pert = &
   520)      toil_auxvar(TOIL_IMS_PRESSURE_DOF)%pert / toil_ims_pressure_scale
   521) 
   522)   
   523) !#ifdef DEBUG_GENERAL
   524) !  call GlobalAuxVarStrip(global_auxvar_debug)
   525) !  call GeneralAuxVarStrip(general_auxvar_debug)
   526) !#endif
   527)  
   528) end subroutine TOilImsAuxVarPerturb
   529) 
   530) ! ************************************************************************** !
   531) 
   532) subroutine TOilImsAuxVarSingleDestroy(auxvar)
   533)   ! 
   534)   ! Deallocates a mode auxiliary object
   535)   ! this could be generalised for different modes 
   536)   ! using class(*) (unlimited polymorphic)
   537)   ! 
   538)   ! Author: Paolo Orsini
   539)   ! Date: 10/20/15
   540)   ! 
   541) 
   542)   implicit none
   543) 
   544)   type(toil_ims_auxvar_type), pointer :: auxvar
   545)   
   546)   if (associated(auxvar)) then
   547)     call TOilImsAuxVarStrip(auxvar)
   548)     deallocate(auxvar)
   549)   endif
   550)   nullify(auxvar)  
   551) 
   552) end subroutine TOilImsAuxVarSingleDestroy
   553) 
   554) ! ************************************************************************** !
   555) 
   556) subroutine TOilImsAuxVarArray1Destroy(auxvars)
   557)   ! 
   558)   ! Deallocates a mode auxiliary object
   559)   ! this could be generalised for different modes 
   560)   ! using class(*) (unlimited polymorphic)
   561)   ! 
   562)   ! Author: Paolo Orsini
   563)   ! Date: 10/20/15
   564)   ! 
   565) 
   566)   implicit none
   567) 
   568)   type(toil_ims_auxvar_type), pointer :: auxvars(:)
   569)   
   570)   PetscInt :: iaux
   571)   
   572)   if (associated(auxvars)) then
   573)     do iaux = 1, size(auxvars)
   574)       call TOilImsAuxVarStrip(auxvars(iaux))
   575)     enddo  
   576)     deallocate(auxvars)
   577)   endif
   578)   nullify(auxvars)  
   579) 
   580) end subroutine TOilImsAuxVarArray1Destroy
   581) 
   582) ! ************************************************************************** !
   583) 
   584) subroutine TOilImsAuxVarArray2Destroy(auxvars)
   585)   ! 
   586)   ! Deallocates a mode auxiliary object
   587)   ! this could be generalised for different modes 
   588)   ! using class(*) (unlimited polymorphic)
   589)   ! 
   590)   ! Author: Paolo Orsini
   591)   ! Date: 10/20/15
   592)   ! 
   593) 
   594)   implicit none
   595) 
   596)   type(toil_ims_auxvar_type), pointer :: auxvars(:,:)
   597)   
   598)   PetscInt :: iaux, idof
   599)   
   600)   if (associated(auxvars)) then
   601)     do iaux = 1, size(auxvars,2)
   602)       do idof = 1, size(auxvars,1)
   603)         call TOilImsAuxVarStrip(auxvars(idof-1,iaux))
   604)       enddo
   605)     enddo  
   606)     deallocate(auxvars)
   607)   endif
   608)   nullify(auxvars)  
   609) 
   610) end subroutine TOilImsAuxVarArray2Destroy
   611) 
   612) ! ************************************************************************** !
   613) 
   614) subroutine TOilImsAuxVarStrip(auxvar)
   615)   ! 
   616)   ! TOilImsAuxVarDestroy: Deallocates a general auxiliary object
   617)   ! 
   618)   ! Author: Paolo Orsini
   619)   ! Date: 10/20/15
   620)   ! 
   621)   use Utility_module, only : DeallocateArray
   622) 
   623)   implicit none
   624) 
   625)   type(toil_ims_auxvar_type) :: auxvar
   626)   
   627)   call DeallocateArray(auxvar%pres)  
   628)   call DeallocateArray(auxvar%sat)  
   629)   call DeallocateArray(auxvar%den)  
   630)   call DeallocateArray(auxvar%den_kg)  
   631)   call DeallocateArray(auxvar%H)  
   632)   call DeallocateArray(auxvar%U)  
   633)   call DeallocateArray(auxvar%mobility)  
   634)   
   635) end subroutine TOilImsAuxVarStrip
   636) 
   637) ! ************************************************************************** !
   638) 
   639) subroutine TOilImsAuxDestroy(aux)
   640)   ! 
   641)   ! Deallocates a general auxiliary object
   642)   ! 
   643)   ! Author: Glenn Hammond
   644)   ! Date: 03/07/11
   645)   ! 
   646)   use Utility_module, only : DeallocateArray
   647) 
   648)   implicit none
   649) 
   650)   type(TOil_ims_type), pointer :: aux
   651)   PetscInt :: iaux, idof
   652)   
   653)   if (.not.associated(aux)) return
   654)   
   655)   call TOilImsAuxVarDestroy(aux%auxvars)
   656)   call TOilImsAuxVarDestroy(aux%auxvars_bc)
   657)   call TOilImsAuxVarDestroy(aux%auxvars_ss)
   658) 
   659)   call DeallocateArray(aux%inactive_rows_local)
   660)   call DeallocateArray(aux%inactive_rows_local_ghosted)
   661)   call DeallocateArray(aux%row_zeroing_array)
   662) 
   663)   if (associated(aux%parameter)) then
   664)     deallocate(aux%parameter) 
   665)   end if
   666)   nullify(aux%parameter)
   667)   !if (associated(aux%general_parameter)) then
   668)   !  call DeallocateArray(aux%general_parameter%diffusion_coefficient)
   669)   !  deallocate(aux%general_parameter)
   670)   !endif
   671)   !nullify(aux%general_parameter)
   672)   
   673)   deallocate(aux)
   674)   nullify(aux)
   675)   
   676) end subroutine TOilImsAuxDestroy
   677) 
   678) ! ************************************************************************** !
   679) 
   680) end module TOilIms_Aux_module
   681) 

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