Skip to content

Commit

Permalink
use proc pointers, introduce ModelRegistrar module (minimizes code in…
Browse files Browse the repository at this point in the history
… to-be-templated ModelFactory module), cr -> register renaming (seems appropriate since cr routines create and then add models to global lists)
  • Loading branch information
wpbonelli committed Mar 1, 2024
1 parent eb5f11c commit 73cdb32
Show file tree
Hide file tree
Showing 20 changed files with 202 additions and 301 deletions.
1 change: 1 addition & 0 deletions make/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ $(OBJDIR)/VirtualPrtModel.o \
$(OBJDIR)/VirtualGwtModel.o \
$(OBJDIR)/VirtualGwfModel.o \
$(OBJDIR)/VirtualGweModel.o \
$(OBJDIR)/ModelRegistrar.o \
$(OBJDIR)/VirtualGwtExchange.o \
$(OBJDIR)/VirtualGwfExchange.o \
$(OBJDIR)/VirtualGweExchange.o \
Expand Down
1 change: 1 addition & 0 deletions msvs/mf6core.vfproj
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,7 @@
<File RelativePath="..\src\mf6lists.f90"/>
<File RelativePath="..\src\RunControl.f90"/>
<File RelativePath="..\src\ModelFactory.f90"/>
<File RelativePath="..\src\ModelRegistrar.f90"/>
<File RelativePath="..\src\ExchangeFactory.f90"/>
<File RelativePath="..\src\RunControlFactory.F90">
<FileConfiguration Name="Debug|Win32">
Expand Down
34 changes: 11 additions & 23 deletions src/Distributed/VirtualGweModel.f90
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module VirtualGweModelModule
implicit none
private

public :: add_virtual_gwe_model
public :: register_virtual_gwe

type, extends(VirtualModelType) :: VirtualGweModelType
! CND
Expand All @@ -34,7 +34,6 @@ module VirtualGweModelModule
type(VirtualIntType), pointer :: inest => null()
contains
! public
procedure :: create => vgwe_create
procedure :: prepare_stage => vgwe_prepare_stage
procedure :: destroy => vgwe_destroy
! private
Expand All @@ -45,37 +44,26 @@ module VirtualGweModelModule

contains

subroutine add_virtual_gwe_model(model_id, model_name, model)
subroutine register_virtual_gwe(model_id, model_name, model)
use VirtualDataListsModule, only: virtual_model_list
integer(I4B) :: model_id !< global model id
character(len=*) :: model_name !< model name
class(NumericalModelType), pointer :: model !< the actual model (can be null() when remote)
integer(I4B), intent(in) :: model_id !< global model id
character(len=*), intent(in) :: model_name !< model name
class(NumericalModelType), pointer, intent(inout) :: model !< the actual model (can be null() when remote)
! local
class(VirtualGweModelType), pointer :: virtual_gwe_model
class(*), pointer :: obj

allocate (virtual_gwe_model)
call virtual_gwe_model%create(model_name, model_id, model)
call virtual_gwe_model%VirtualModelType%create(model_name, model_id, model)
virtual_gwe_model%container_type = VDC_GWEMODEL_TYPE

call virtual_gwe_model%allocate_data()
call virtual_gwe_model%init_virtual_data()

obj => virtual_gwe_model
call virtual_model_list%Add(obj)

end subroutine add_virtual_gwe_model

subroutine vgwe_create(this, name, id, model)
class(VirtualGweModelType) :: this
character(len=*) :: name
integer(I4B) :: id
class(NumericalModelType), pointer :: model

! create base
call this%VirtualModelType%create(name, id, model)
this%container_type = VDC_GWEMODEL_TYPE

call this%allocate_data()
call this%init_virtual_data()

end subroutine vgwe_create
end subroutine register_virtual_gwe

subroutine init_virtual_data(this)
class(VirtualGweModelType) :: this
Expand Down
36 changes: 12 additions & 24 deletions src/Distributed/VirtualGwfModel.f90
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module VirtualGwfModelModule
implicit none
private

public :: add_virtual_gwf_model
public :: register_virtual_gwf

type, public, extends(VirtualModelType) :: VirtualGwfModelType
! NPF
Expand All @@ -28,7 +28,6 @@ module VirtualGwfModelModule
type(VirtualDbl1dType), pointer :: buy_dense => null()
contains
! public
procedure :: create => vgwf_create
procedure :: destroy => vgwf_destroy
procedure :: prepare_stage => vgwf_prepare_stage
! private
Expand All @@ -39,39 +38,28 @@ module VirtualGwfModelModule

contains

!> @brief Add virtual GWF model
!> @brief Create and register a virtual GWF model
!<
subroutine add_virtual_gwf_model(model_id, model_name, model)
subroutine register_virtual_gwf(model_id, model_name, model)
use VirtualDataListsModule, only: virtual_model_list
integer(I4B) :: model_id !< global model id
character(len=*) :: model_name !< model name
class(NumericalModelType), pointer :: model !< the actual model (can be null() when remote)
integer(I4B), intent(in) :: model_id !< global model id
character(len=*), intent(in) :: model_name !< model name
class(NumericalModelType), pointer, intent(inout) :: model !< the actual model (can be null() when remote)
! local
class(VirtualGwfModelType), pointer :: virtual_gwf_model
class(*), pointer :: obj

allocate (virtual_gwf_model)
call virtual_gwf_model%create(model_name, model_id, model)
call virtual_gwf_model%VirtualModelType%create(model_name, model_id, model)
virtual_gwf_model%container_type = VDC_GWFMODEL_TYPE

call virtual_gwf_model%allocate_data()
call virtual_gwf_model%init_virtual_data()

obj => virtual_gwf_model
call virtual_model_list%Add(obj)

end subroutine add_virtual_gwf_model

subroutine vgwf_create(this, name, id, model)
class(VirtualGwfModelType) :: this
character(len=*) :: name
integer(I4B) :: id
class(NumericalModelType), pointer :: model

! create base
call this%VirtualModelType%create(name, id, model)
this%container_type = VDC_GWFMODEL_TYPE

call this%allocate_data()
call this%init_virtual_data()

end subroutine vgwf_create
end subroutine register_virtual_gwf

subroutine init_virtual_data(this)
class(VirtualGwfModelType) :: this
Expand Down
34 changes: 11 additions & 23 deletions src/Distributed/VirtualGwtModel.f90
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module VirtualGwtModelModule
implicit none
private

public :: add_virtual_gwt_model
public :: register_virtual_gwt

type, extends(VirtualModelType) :: VirtualGwtModelType
! DSP
Expand All @@ -32,7 +32,6 @@ module VirtualGwtModelModule
type(VirtualIntType), pointer :: inmst => null()
contains
! public
procedure :: create => vgwt_create
procedure :: prepare_stage => vgwt_prepare_stage
procedure :: destroy => vgwt_destroy
! private
Expand All @@ -43,37 +42,26 @@ module VirtualGwtModelModule

contains

subroutine add_virtual_gwt_model(model_id, model_name, model)
subroutine register_virtual_gwt(model_id, model_name, model)
use VirtualDataListsModule, only: virtual_model_list
integer(I4B) :: model_id !< global model id
character(len=*) :: model_name !< model name
class(NumericalModelType), pointer :: model !< the actual model (can be null() when remote)
integer(I4B), intent(in) :: model_id !< global model id
character(len=*), intent(in) :: model_name !< model name
class(NumericalModelType), pointer, intent(inout) :: model !< the actual model (can be null() when remote)
! local
class(VirtualGwtModelType), pointer :: virtual_gwt_model
class(*), pointer :: obj

allocate (virtual_gwt_model)
call virtual_gwt_model%create(model_name, model_id, model)
call virtual_gwt_model%VirtualModelType%create(model_name, model_id, model)
virtual_gwt_model%container_type = VDC_GWTMODEL_TYPE

call virtual_gwt_model%allocate_data()
call virtual_gwt_model%init_virtual_data()

obj => virtual_gwt_model
call virtual_model_list%Add(obj)

end subroutine add_virtual_gwt_model

subroutine vgwt_create(this, name, id, model)
class(VirtualGwtModelType) :: this
character(len=*) :: name
integer(I4B) :: id
class(NumericalModelType), pointer :: model

! create base
call this%VirtualModelType%create(name, id, model)
this%container_type = VDC_GWTMODEL_TYPE

call this%allocate_data()
call this%init_virtual_data()

end subroutine vgwt_create
end subroutine register_virtual_gwt

subroutine init_virtual_data(this)
class(VirtualGwtModelType) :: this
Expand Down
21 changes: 6 additions & 15 deletions src/Distributed/VirtualPrtModel.f90
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ module VirtualPrtModelModule
implicit none
private

public :: add_virtual_prt_model
public :: register_virtual_prt

type, extends(VirtualModelType) :: VirtualPrtModelType
contains
! public
procedure :: create => vprt_create
procedure :: prepare_stage => vprt_prepare_stage
procedure :: destroy => vprt_destroy
! private
Expand All @@ -23,20 +22,12 @@ module VirtualPrtModelModule

contains

subroutine add_virtual_prt_model(model_id, model_name, model)
integer(I4B) :: model_id !< global model id
character(len=*) :: model_name !< model name
class(NumericalModelType), pointer :: model !< the actual model (can be null() when remote)
subroutine register_virtual_prt(model_id, model_name, model)
integer(I4B), intent(in) :: model_id !< global model id
character(len=*), intent(in) :: model_name !< model name
class(NumericalModelType), pointer, intent(inout) :: model !< the actual model (can be null() when remote)
! noop
end subroutine add_virtual_prt_model

subroutine vprt_create(this, name, id, model)
class(VirtualPrtModelType) :: this
character(len=*) :: name
integer(I4B) :: id
class(NumericalModelType), pointer :: model
! noop
end subroutine vprt_create
end subroutine register_virtual_prt

subroutine init_virtual_data(this)
class(VirtualPrtModelType) :: this
Expand Down
21 changes: 6 additions & 15 deletions src/Distributed/VirtualSwfModel.f90
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ module VirtualSwfModelModule
implicit none
private

public :: add_virtual_swf_model
public :: register_virtual_swf

type, extends(VirtualModelType) :: VirtualSwfModelType
contains
! public
procedure :: create => vswf_create
procedure :: prepare_stage => vswf_prepare_stage
procedure :: destroy => vswf_destroy
! private
Expand All @@ -23,20 +22,12 @@ module VirtualSwfModelModule

contains

subroutine add_virtual_swf_model(model_id, model_name, model)
integer(I4B) :: model_id !< global model id
character(len=*) :: model_name !< model name
class(NumericalModelType), pointer :: model !< the actual model (can be null() when remote)
subroutine register_virtual_swf(model_id, model_name, model)
integer(I4B), intent(in) :: model_id !< global model id
character(len=*), intent(in) :: model_name !< model name
class(NumericalModelType), pointer, intent(inout) :: model !< the actual model (can be null() when remote)
! noop
end subroutine add_virtual_swf_model

subroutine vswf_create(this, name, id, model)
class(VirtualSwfModelType) :: this
character(len=*) :: name
integer(I4B) :: id
class(NumericalModelType), pointer :: model
! noop
end subroutine vswf_create
end subroutine register_virtual_swf

subroutine init_virtual_data(this)
class(VirtualSwfModelType) :: this
Expand Down
2 changes: 1 addition & 1 deletion src/Model/Connection/GweInterfaceModel.f90
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ module GweInterfaceModelModule
contains

!> @brief Create the interface model, analogously to what
!< happens in gwe_cr
!< happens in register_gwe
subroutine gweifmod_cr(this, name, iout, gridConn)
! -- modules
use GweInputDataModule, only: gweshared_dat_cr
Expand Down
2 changes: 1 addition & 1 deletion src/Model/Connection/GwfInterfaceModel.f90
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ module GwfInterfaceModelModule
contains

!> @brief set up the interface model, analogously to what
!< happens in gwf_cr
!< happens in register_gwf
subroutine gwfifm_cr(this, name, iout, gridConn)
class(GwfInterfaceModelType) :: this !< the GWF interface model
character(len=*), intent(in) :: name !< the interface model's name
Expand Down
2 changes: 1 addition & 1 deletion src/Model/Connection/GwtInterfaceModel.f90
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ module GwtInterfaceModelModule
contains

!> @brief Create the interface model, analogously to what
!< happens in gwt_cr
!< happens in register_gwt
subroutine gwtifmod_cr(this, name, iout, gridConn)
! -- dummy
class(GwtInterfaceModelType) :: this !< the GWT interface model
Expand Down
8 changes: 4 additions & 4 deletions src/Model/GroundWaterEnergy/gwe.f90
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module GweModule
implicit none

private
public :: gwe_cr
public :: register_gwe
public :: GweModelType
public :: CastAsGweModel

Expand Down Expand Up @@ -92,7 +92,7 @@ module GweModule

!> @brief Create a new groundwater energy transport model object
!<
subroutine gwe_cr(filename, id, modelname)
subroutine register_gwe(id, modelname, filename)
! -- modules
use ListsModule, only: basemodellist
use BaseModelModule, only: AddBaseModelToList
Expand All @@ -103,9 +103,9 @@ subroutine gwe_cr(filename, id, modelname)
use BudgetModule, only: budget_cr
use GweInputDataModule, only: gweshared_dat_cr
! -- dummy
character(len=*), intent(in) :: filename !< input file
integer(I4B), intent(in) :: id !< consecutive model number listed in mfsim.nam
character(len=*), intent(in) :: modelname !< name of the model
character(len=*), intent(in) :: filename !< input file
! -- local
integer(I4B) :: indis
type(GweModelType), pointer :: this
Expand Down Expand Up @@ -137,7 +137,7 @@ subroutine gwe_cr(filename, id, modelname)
!
! -- Return
return
end subroutine gwe_cr
end subroutine register_gwe

!> @brief Define packages of the GWE model
!!
Expand Down
2 changes: 1 addition & 1 deletion src/Model/GroundWaterFlow/gwf-mvr.f90
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
! water, but this value decreases as the mover object consumes water from
! it.
!
! 2. In gwf_cr create the mover package by calling the CR subroutine:
! 2. In register_gwf create the mover package by calling the CR subroutine:
!
! call mvr_cr(this%mvr, this%name, this%inmvr, this%iout)
!
Expand Down
Loading

0 comments on commit 73cdb32

Please sign in to comment.