|
| 1 | +module CellConnectionExchangeModule |
| 2 | + |
| 3 | + use KindModule, only: DP, I4B, LGP |
| 4 | + use ConstantsModule, only: LENEXCHANGENAME, LENMEMPATH |
| 5 | + use ListModule, only: ListType |
| 6 | + use BaseExchangeModule, only: BaseExchangeType, AddBaseExchangeToList |
| 7 | + use BaseModelModule, only: BaseModelType |
| 8 | + |
| 9 | + implicit none |
| 10 | + |
| 11 | + private |
| 12 | + public :: CellConnectionExchangeType, AddCellConnectionExchangeToList, & |
| 13 | + GetCellConnectionExchangeFromList |
| 14 | + |
| 15 | + !> @brief CellConnectionExchangeType |
| 16 | + !! |
| 17 | + !! Base exchange type that stores the topological cell-to-cell connections |
| 18 | + !! between models. This type represents pure connectivity information without |
| 19 | + !! geometric data (connection lengths, areas, etc.). It stores: |
| 20 | + !! - nexg: number of connected cell pairs |
| 21 | + !! - nodem1, nodem2: node numbers in each model (reduced, 0-based) |
| 22 | + !! - ihc: horizontal connection indicator (0=vertical, 1=horizontal) |
| 23 | + !! |
| 24 | + !! This is the foundation for more specialized exchange types that add |
| 25 | + !! geometric information (GeometricConnectionExchangeType) or numerical |
| 26 | + !! coupling methods (NumericalExchangeType). |
| 27 | + !< |
| 28 | + type, extends(BaseExchangeType) :: CellConnectionExchangeType |
| 29 | + integer(I4B), pointer :: nexg => null() !< number of connected cell pairs |
| 30 | + integer(I4B), dimension(:), pointer, contiguous :: nodem1 => null() !< node numbers in model 1 (reduced, 0-based) |
| 31 | + integer(I4B), dimension(:), pointer, contiguous :: nodem2 => null() !< node numbers in model 2 (reduced, 0-based) |
| 32 | + integer(I4B), dimension(:), pointer, contiguous :: ihc => null() !< horizontal connection indicator (0=vertical, 1=horizontal) |
| 33 | + contains |
| 34 | + procedure :: exg_df |
| 35 | + procedure :: exg_ar |
| 36 | + procedure :: exg_da |
| 37 | + procedure :: allocate_scalars |
| 38 | + procedure :: allocate_arrays |
| 39 | + end type CellConnectionExchangeType |
| 40 | + |
| 41 | +contains |
| 42 | + |
| 43 | + subroutine exg_df(this) |
| 44 | + class(CellConnectionExchangeType) :: this !< instance of cell connection exchange object |
| 45 | + ! override in child types |
| 46 | + end subroutine exg_df |
| 47 | + |
| 48 | + subroutine exg_ar(this) |
| 49 | + class(CellConnectionExchangeType) :: this !< instance of cell connection exchange object |
| 50 | + ! override in child types |
| 51 | + end subroutine exg_ar |
| 52 | + |
| 53 | + !> @brief Allocate scalar variables for this cell connection exchange |
| 54 | + !< |
| 55 | + subroutine allocate_scalars(this) |
| 56 | + ! -- modules |
| 57 | + use MemoryManagerModule, only: mem_allocate |
| 58 | + ! -- dummy |
| 59 | + class(CellConnectionExchangeType) :: this !< instance of cell connection exchange object |
| 60 | + ! |
| 61 | + call mem_allocate(this%nexg, 'NEXG', this%memoryPath) |
| 62 | + this%nexg = 0 |
| 63 | + end subroutine allocate_scalars |
| 64 | + |
| 65 | + !> @brief Allocate array data for this cell connection exchange, |
| 66 | + !! using the number of connected nodes nexg |
| 67 | + !< |
| 68 | + subroutine allocate_arrays(this) |
| 69 | + ! -- modules |
| 70 | + use MemoryManagerModule, only: mem_allocate |
| 71 | + ! -- dummy |
| 72 | + class(CellConnectionExchangeType) :: this !< instance of cell connection exchange object |
| 73 | + ! |
| 74 | + call mem_allocate(this%nodem1, this%nexg, 'NODEM1', this%memoryPath) |
| 75 | + call mem_allocate(this%nodem2, this%nexg, 'NODEM2', this%memoryPath) |
| 76 | + call mem_allocate(this%ihc, this%nexg, 'IHC', this%memoryPath) |
| 77 | + end subroutine allocate_arrays |
| 78 | + |
| 79 | + !> @brief Deallocate memory associated with this cell connection exchange |
| 80 | + !< |
| 81 | + subroutine exg_da(this) |
| 82 | + ! -- modules |
| 83 | + use MemoryManagerModule, only: mem_deallocate |
| 84 | + ! -- dummy |
| 85 | + class(CellConnectionExchangeType) :: this !< instance of cell connection exchange object |
| 86 | + ! |
| 87 | + call mem_deallocate(this%nodem1) |
| 88 | + call mem_deallocate(this%nodem2) |
| 89 | + call mem_deallocate(this%ihc) |
| 90 | + call mem_deallocate(this%nexg) |
| 91 | + end subroutine exg_da |
| 92 | + |
| 93 | + function CastAsCellConnectionExchangeClass(obj) result(res) |
| 94 | + implicit none |
| 95 | + class(*), pointer, intent(inout) :: obj |
| 96 | + class(CellConnectionExchangeType), pointer :: res |
| 97 | + |
| 98 | + res => null() |
| 99 | + if (.not. associated(obj)) return |
| 100 | + |
| 101 | + select type (obj) |
| 102 | + class is (CellConnectionExchangeType) |
| 103 | + res => obj |
| 104 | + end select |
| 105 | + end function CastAsCellConnectionExchangeClass |
| 106 | + |
| 107 | + subroutine AddCellConnectionExchangeToList(list, exchange) |
| 108 | + implicit none |
| 109 | + type(ListType), intent(inout) :: list |
| 110 | + class(CellConnectionExchangeType), pointer, intent(in) :: exchange |
| 111 | + class(*), pointer :: obj |
| 112 | + |
| 113 | + obj => exchange |
| 114 | + call list%Add(obj) |
| 115 | + end subroutine AddCellConnectionExchangeToList |
| 116 | + |
| 117 | + function GetCellConnectionExchangeFromList(list, idx) result(res) |
| 118 | + implicit none |
| 119 | + type(ListType), intent(inout) :: list |
| 120 | + integer(I4B), intent(in) :: idx |
| 121 | + class(CellConnectionExchangeType), pointer :: res |
| 122 | + class(*), pointer :: obj |
| 123 | + |
| 124 | + obj => list%GetItem(idx) |
| 125 | + res => CastAsCellConnectionExchangeClass(obj) |
| 126 | + end function GetCellConnectionExchangeFromList |
| 127 | + |
| 128 | +end module CellConnectionExchangeModule |
0 commit comments