simulation_subsurface.F90       coverage:  71.43 %func     54.26 %block


     1) module Simulation_Subsurface_class
     2)   
     3)   use Simulation_Base_class
     4)   use Regression_module
     5)   use Option_module
     6)   use PMC_Subsurface_class
     7)   use PMC_Third_Party_class
     8)   use PMC_Base_class
     9)   use Realization_Subsurface_class
    10)   use Waypoint_module
    11)   use PFLOTRAN_Constants_module
    12) 
    13)   implicit none
    14) 
    15) #include "petsc/finclude/petscsys.h"
    16)   
    17)   private
    18) 
    19)   type, public, extends(simulation_base_type) :: simulation_subsurface_type
    20)     ! pointer to flow process model coupler
    21)     class(pmc_subsurface_type), pointer :: flow_process_model_coupler
    22)     ! pointer to reactive transport process model coupler
    23)     class(pmc_subsurface_type), pointer :: rt_process_model_coupler
    24)     ! pointer to realization object shared by flow and reactive transport
    25)     class(realization_subsurface_type), pointer :: realization 
    26)     ! regression object
    27)     type(regression_type), pointer :: regression
    28)     type(waypoint_list_type), pointer :: waypoint_list_subsurface
    29)   contains
    30)     procedure, public :: Init => SubsurfaceSimulationInit
    31)     procedure, public :: JumpStart => SubsurfaceSimulationJumpStart
    32)     procedure, public :: InputRecord => SubsurfaceSimInputRecord
    33) !    procedure, public :: ExecuteRun
    34) !    procedure, public :: RunToTime
    35)     procedure, public :: FinalizeRun => SubsurfaceFinalizeRun
    36)     procedure, public :: Strip => SubsurfaceSimulationStrip
    37)   end type simulation_subsurface_type
    38)   
    39)   public :: SubsurfaceSimulationCreate, &
    40)             SubsurfaceSimulationInit, &
    41)             SubsurfaceFinalizeRun, &
    42)             SubsurfaceSimulationStrip, &
    43)             SubsurfaceSimulationDestroy
    44)   
    45) contains
    46) 
    47) ! ************************************************************************** !
    48) 
    49) function SubsurfaceSimulationCreate(option)
    50)   ! 
    51)   ! Allocates and initializes a new simulation object
    52)   ! 
    53)   ! Author: Glenn Hammond
    54)   ! Date: 10/25/07
    55)   ! 
    56) 
    57)   use Option_module
    58)   
    59)   implicit none
    60)   
    61)   type(option_type), pointer :: option
    62) 
    63)   class(simulation_subsurface_type), pointer :: SubsurfaceSimulationCreate
    64)   
    65) #ifdef DEBUG
    66)   print *, 'SimulationCreate'
    67) #endif
    68)   
    69)   allocate(SubsurfaceSimulationCreate)
    70)   call SubsurfaceSimulationCreate%Init(option)
    71)   
    72) end function SubsurfaceSimulationCreate
    73) 
    74) ! ************************************************************************** !
    75) 
    76) subroutine SubsurfaceSimulationInit(this,option)
    77)   ! 
    78)   ! Initializes simulation values
    79)   ! 
    80)   ! Author: Glenn Hammond
    81)   ! Date: 04/22/13
    82)   ! 
    83)   use Waypoint_module
    84)   use Option_module
    85)   
    86)   implicit none
    87)   
    88)   class(simulation_subsurface_type) :: this
    89)   type(option_type), pointer :: option
    90)   
    91)   call SimulationBaseInit(this,option)
    92)   nullify(this%flow_process_model_coupler)
    93)   nullify(this%rt_process_model_coupler)
    94)   nullify(this%realization)
    95)   nullify(this%regression)
    96)   this%waypoint_list_subsurface => WaypointListCreate()
    97)   
    98) end subroutine SubsurfaceSimulationInit
    99) 
   100) ! ************************************************************************** !
   101) 
   102) subroutine SubsurfaceSimInputRecord(this)
   103)   ! 
   104)   ! Writes ingested information to the input record file.
   105)   ! 
   106)   ! Author: Jenn Frederick, SNL
   107)   ! Date: 03/17/2016
   108)   ! 
   109)   use Option_module
   110)   use Output_module
   111)   use Discretization_module
   112)   use Reaction_Aux_module
   113)   use Region_module
   114)   use Strata_module
   115)   use Material_module
   116)   use Characteristic_Curves_module
   117)   use Patch_module
   118)   use Condition_module
   119)   use EOS_module
   120)   use Waypoint_module
   121)   
   122)   implicit none
   123)   
   124)   class(simulation_subsurface_type) :: this
   125) 
   126)   character(len=MAXWORDLENGTH) :: word
   127)   PetscInt :: id = INPUT_RECORD_UNIT
   128)   
   129)   if (OptionPrintToScreen(this%option)) then
   130)     write (*,*) 'Printing input record file.'
   131)   endif
   132)   
   133)   write(id,'(a)') ' '
   134)   write(id,'(a)') '---------------------------------------------------------&
   135)                   &-----------------------'
   136)   write(id,'(a29)',advance='no') 'simulation type: '
   137)   write(id,'(a)') 'subsurface'
   138)   write(id,'(a29)',advance='no') 'flow mode: '
   139)   select case(this%realization%option%iflowmode)
   140)     case(MPH_MODE)
   141)       write(id,'(a)') 'multi-phase'
   142)     case(RICHARDS_MODE)
   143)       write(id,'(a)') 'richards'
   144)     case(IMS_MODE)
   145)       write(id,'(a)') 'immiscible'
   146)     case(FLASH2_MODE)
   147)       write(id,'(a)') 'flash2'
   148)     case(G_MODE)
   149)       write(id,'(a)') 'general'
   150)     case(MIS_MODE)
   151)       write(id,'(a)') 'miscible'
   152)     case(TH_MODE)
   153)       write(id,'(a)') 'thermo-hydro'
   154)     case(TOIL_IMS_MODE)
   155)       write(id,'(a)') 'thermal-oil-immiscible'
   156)   end select
   157)   
   158)   ! print time information
   159)   call WaypointInputRecord(this%output_option,this%waypoint_list_subsurface)
   160) 
   161)   ! print output file information
   162)   call OutputInputRecord(this%output_option,this%waypoint_list_subsurface)
   163) 
   164)   ! print grid/discretization information
   165)   call DiscretizationInputRecord(this%realization%discretization)
   166) 
   167)   ! print region information
   168)   call RegionInputRecord(this%realization%patch%region_list)
   169)   
   170)   ! print strata information
   171)   call StrataInputRecord(this%realization%patch%strata_list)
   172)   
   173)   ! print material property information
   174)   call MaterialPropInputRecord(this%realization%material_properties)
   175)   
   176)   ! print characteristic curves information
   177)   call CharCurvesInputRecord(this%realization%patch%characteristic_curves)
   178) 
   179)   ! print chemistry and reactive transport information
   180)   call ReactionInputRecord(this%realization%reaction)
   181)   
   182)   ! print coupler information (ICs, BCs, SSs)
   183)   call PatchCouplerInputRecord(this%realization%patch)
   184)   
   185)   ! print flow and trans condition information
   186)   call FlowCondInputRecord(this%realization%flow_conditions, &
   187)                            this%realization%option)
   188)   call TranCondInputRecord(this%realization%transport_conditions, &
   189)                            this%realization%option)
   190)                        
   191)   ! print equation of state (eos) information
   192)   call EOSInputRecord()
   193) 
   194) end subroutine SubsurfaceSimInputRecord
   195) 
   196) ! ************************************************************************** !
   197) 
   198) subroutine SubsurfaceSimulationJumpStart(this)
   199)   ! 
   200)   ! Initializes simulation
   201)   ! 
   202)   ! Author: Glenn Hammond
   203)   ! Date: 08/11/14
   204)   ! 
   205)   use Logging_module
   206)   use Output_module
   207)   use Option_module
   208)   use Output_Aux_module
   209)   use Timestepper_Base_class
   210) 
   211)   implicit none
   212)   
   213)   class(simulation_subsurface_type) :: this
   214) 
   215)   class(timestepper_base_type), pointer :: master_timestepper
   216)   class(timestepper_base_type), pointer :: flow_timestepper
   217)   class(timestepper_base_type), pointer :: tran_timestepper
   218)   type(option_type), pointer :: option
   219)   type(output_option_type), pointer :: output_option
   220)   PetscBool :: snapshot_plot_flag, observation_plot_flag, massbal_plot_flag
   221)   
   222) #ifdef DEBUG
   223)   call printMsg(this%option,'SubsurfaceSimulationJumpStart()')
   224) #endif
   225) 
   226)   nullify(master_timestepper)
   227)   nullify(flow_timestepper)
   228)   nullify(tran_timestepper)
   229)   snapshot_plot_flag = PETSC_FALSE
   230)   observation_plot_flag = PETSC_FALSE
   231)   massbal_plot_flag = PETSC_FALSE
   232) 
   233)   option => this%option
   234)   output_option => this%output_option
   235) 
   236)   ! first time stepper is master
   237)   master_timestepper => this%process_model_coupler_list%timestepper
   238)   if (associated(this%flow_process_model_coupler)) then
   239)     flow_timestepper => this%flow_process_model_coupler%timestepper
   240)   endif
   241)   if (associated(this%rt_process_model_coupler)) then
   242)     tran_timestepper => this%rt_process_model_coupler%timestepper
   243)   endif
   244)   
   245)   !if TIMESTEPPER->MAX_STEPS < 0, print out solution composition only
   246)   if (master_timestepper%max_time_step < 0) then
   247)     call printMsg(option,'')
   248)     write(option%io_buffer,*) master_timestepper%max_time_step
   249)     option%io_buffer = 'The maximum # of time steps (' // &
   250)                        trim(adjustl(option%io_buffer)) // &
   251)                        '), specified by TIMESTEPPER->MAX_STEPS, ' // &
   252)                        'has been met.  Stopping....'  
   253)     call printMsg(option)
   254)     call printMsg(option,'')
   255)     option%status = DONE
   256)     return
   257)   endif
   258) 
   259)   ! print initial condition output if not a restarted sim
   260)   call OutputInit(option,master_timestepper%steps)
   261)   if (output_option%plot_number == 0 .and. &
   262)       master_timestepper%max_time_step >= 0) then
   263)     if (output_option%print_initial_snap) snapshot_plot_flag = PETSC_TRUE
   264)     if (output_option%print_initial_obs) observation_plot_flag = PETSC_TRUE
   265)     if (output_option%print_initial_massbal) massbal_plot_flag = PETSC_FALSE
   266)     call Output(this%realization,snapshot_plot_flag,observation_plot_flag, &
   267)                 massbal_plot_flag)
   268)   endif
   269)   
   270)   !if TIMESTEPPER->MAX_STEPS < 1, print out initial condition only
   271)   if (master_timestepper%max_time_step < 1) then
   272)     call printMsg(option,'')
   273)     write(option%io_buffer,*) master_timestepper%max_time_step
   274)     option%io_buffer = 'The maximum # of time steps (' // &
   275)                        trim(adjustl(option%io_buffer)) // &
   276)                        '), specified by TIMESTEPPER->MAX_STEPS, ' // &
   277)                        'has been met.  Stopping....'  
   278)     call printMsg(option)
   279)     call printMsg(option,'') 
   280)     option%status = DONE
   281)     return
   282)   endif
   283) 
   284)   ! increment plot number so that 000 is always the initial condition, and nothing else
   285)   if (output_option%plot_number == 0) output_option%plot_number = 1
   286) 
   287)   if (associated(flow_timestepper)) then
   288)     if (.not.associated(flow_timestepper%cur_waypoint)) then
   289)       option%io_buffer = &
   290)         'Null flow waypoint list; final time likely equal to start time.'
   291)       call printMsg(option)
   292)       option%status = FAIL
   293)       return
   294)     else
   295)       flow_timestepper%dt_max = flow_timestepper%cur_waypoint%dt_max
   296)     endif
   297)   endif  
   298)   if (associated(tran_timestepper)) then
   299)     if (.not.associated(tran_timestepper%cur_waypoint)) then
   300)       option%io_buffer = &
   301)         'Null transport waypoint list; final time likely equal to start ' // &
   302)         'time or simulation time needs to be extended on a restart.'
   303)       call printMsg(option)
   304)       option%status = FAIL
   305)       return
   306)     else
   307)       tran_timestepper%dt_max = tran_timestepper%cur_waypoint%dt_max
   308)     endif
   309)   endif
   310)            
   311)   if (associated(flow_timestepper)) &
   312)     flow_timestepper%start_time_step = flow_timestepper%steps + 1
   313)   if (associated(tran_timestepper)) &
   314)     tran_timestepper%start_time_step = tran_timestepper%steps + 1
   315)   
   316)   if (this%realization%debug%print_couplers) then
   317)     call OutputPrintCouplers(this%realization,ZERO_INTEGER)
   318)   endif  
   319) 
   320) end subroutine SubsurfaceSimulationJumpStart
   321) 
   322) ! ************************************************************************** !
   323) 
   324) subroutine SubsurfaceFinalizeRun(this)
   325)   ! 
   326)   ! Finalizes simulation
   327)   ! 
   328)   ! Author: Glenn Hammond
   329)   ! Date: 03/18/13
   330)   ! 
   331) 
   332)   use Timestepper_BE_class
   333)   use Reaction_Sandbox_module, only : RSandboxDestroy
   334)   use SrcSink_Sandbox_module, only : SSSandboxDestroyList
   335)   use WIPP_module, only : WIPPDestroy
   336)   use Klinkenberg_module, only : KlinkenbergDestroy
   337)   use CLM_Rxn_module, only : RCLMRxnDestroy
   338) 
   339)   implicit none
   340)   
   341)   class(simulation_subsurface_type) :: this
   342)   
   343)   PetscErrorCode :: ierr
   344)   
   345)   class(timestepper_BE_type), pointer :: flow_timestepper
   346)   class(timestepper_BE_type), pointer :: tran_timestepper
   347) 
   348) #ifdef DEBUG
   349)   call printMsg(this%option,'SubsurfaceFinalizeRun()')
   350) #endif
   351)   
   352)   call SimulationBaseFinalizeRun(this)
   353)   
   354)   nullify(flow_timestepper)
   355)   nullify(tran_timestepper)
   356)   if (associated(this%flow_process_model_coupler)) then
   357)     select type(ts => this%flow_process_model_coupler%timestepper)
   358)       class is(timestepper_BE_type)
   359)         flow_timestepper => ts
   360)     end select
   361)     call SSSandboxDestroyList()
   362)     call WIPPDestroy()
   363)     call KlinkenbergDestroy()
   364)   endif
   365)   if (associated(this%rt_process_model_coupler)) then
   366)     select type(ts => this%rt_process_model_coupler%timestepper)
   367)       class is(timestepper_BE_type)
   368)         tran_timestepper => ts
   369)     end select
   370)     call RSandboxDestroy()
   371)     call RCLMRxnDestroy()
   372)   endif
   373)   
   374)   call RegressionOutput(this%regression,this%realization, &
   375)                         flow_timestepper,tran_timestepper)  
   376)   
   377) end subroutine SubsurfaceFinalizeRun
   378) 
   379) ! ************************************************************************** !
   380) 
   381) subroutine SubsurfaceSimulationStrip(this)
   382)   ! 
   383)   ! Deallocates members of subsurface simulation
   384)   ! 
   385)   ! Author: Glenn Hammond
   386)   ! Date: 06/11/13
   387)   ! 
   388) 
   389)   implicit none
   390)   
   391)   class(simulation_subsurface_type) :: this
   392)   
   393) #ifdef DEBUG
   394)   call printMsg(this%option,'SubsurfaceSimulationStrip()')
   395) #endif
   396)   
   397)   call SimulationBaseStrip(this)
   398)   call RealizationStrip(this%realization)
   399)   deallocate(this%realization)
   400)   nullify(this%realization)
   401)   call RegressionDestroy(this%regression)
   402)   call WaypointListDestroy(this%waypoint_list_subsurface)
   403)   
   404) end subroutine SubsurfaceSimulationStrip
   405) 
   406) ! ************************************************************************** !
   407) 
   408) subroutine SubsurfaceSimulationDestroy(simulation)
   409)   ! 
   410)   ! Deallocates a simulation
   411)   ! 
   412)   ! Author: Glenn Hammond
   413)   ! Date: 11/01/07
   414)   ! 
   415) 
   416)   implicit none
   417)   
   418)   class(simulation_subsurface_type), pointer :: simulation
   419)   
   420) #ifdef DEBUG
   421)   call printMsg(simulation%option,'SimulationDestroy()')
   422) #endif
   423)   
   424)   if (.not.associated(simulation)) return
   425)   
   426)   call simulation%Strip()
   427)   deallocate(simulation)
   428)   nullify(simulation)
   429)   
   430) end subroutine SubsurfaceSimulationDestroy
   431)   
   432) end module Simulation_Subsurface_class

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