MODFLOW 6 version 6.9.0.dev0
USGS Modular Hydrologic Model
Loading...
Searching...
No Matches
InterfaceMap.f90
Go to the documentation of this file.
2 use kindmodule, only: i4b
6
7 implicit none
8 private
9
10 type, public :: interfacemaptype
11 integer(I4B) :: nr_models
12 integer(I4B), dimension(:), pointer, contiguous :: model_ids => null()
13 character(len=LENMODELNAME), dimension(:), &
14 pointer, contiguous :: model_names => null()
15 integer(I4B) :: nr_exchanges
16 integer(I4B), dimension(:), pointer, contiguous :: exchange_ids => null()
17 character(len=LENEXCHANGENAME), dimension(:), &
18 pointer, contiguous :: exchange_names => null()
19 integer(I4B) :: prim_exg_idx
20 type(indexmaptype), dimension(:), pointer :: node_maps => null()
21 type(indexmaptype), dimension(:), pointer :: conn_maps => null()
22 type(indexmapsgntype), dimension(:), pointer :: exchange_maps => null()
23 contains
24 procedure :: init
25 procedure :: add
26 procedure :: destroy
27 procedure :: get_node_map
28 procedure :: get_connection_map
29 procedure :: print_interface
30 end type interfacemaptype
31
32contains
33
34 subroutine init(this, nr_models, nr_exchanges)
35 class(interfacemaptype) :: this
36 integer(I4B) :: nr_models
37 integer(I4B) :: nr_exchanges
38
39 this%nr_models = nr_models
40 this%nr_exchanges = nr_exchanges
41
42 allocate (this%model_ids(nr_models))
43 allocate (this%model_names(nr_models))
44 allocate (this%exchange_ids(nr_exchanges))
45 allocate (this%exchange_names(nr_exchanges))
46
47 allocate (this%node_maps(nr_models))
48 allocate (this%conn_maps(nr_models))
49 allocate (this%exchange_maps(nr_exchanges))
50
51 ! model id == -1 when not set
52 this%model_ids = -1
53 this%exchange_ids = -1
54
55 end subroutine init
56
57 !> @ Adds a map, either by extending the existing map
58 !! for a certain model or exchange, or by assigning
59 !! the map to an empty slot.
60 !!
61 !! The map to which is added, should be properly
62 !< initialized beforehand
63 subroutine add(this, map_to_add)
64 class(interfacemaptype) :: this
65 class(interfacemaptype) :: map_to_add
66 ! local
67 integer(I4B) :: im, ie
68 integer(I4B) :: m_id, m_index
69 integer(I4B) :: e_id, e_index
70
71 ! add models
72 do im = 1, map_to_add%nr_models
73 m_id = map_to_add%model_ids(im)
74 m_index = ifind(this%model_ids, m_id)
75 if (m_index > 0) then
76 ! extend existing index map
77 call this%node_maps(m_index)%add(map_to_add%node_maps(im))
78 call this%conn_maps(m_index)%add(map_to_add%conn_maps(im))
79 else
80 ! place in first empty spot
81 m_index = ifind(this%model_ids, -1)
82 this%model_ids(m_index) = m_id
83 this%model_names(m_index) = map_to_add%model_names(im)
84 call this%node_maps(m_index)%copy(map_to_add%node_maps(im))
85 call this%conn_maps(m_index)%copy(map_to_add%conn_maps(im))
86 end if
87 end do
88
89 ! add exchanges
90 do ie = 1, map_to_add%nr_exchanges
91 e_id = map_to_add%exchange_ids(ie)
92 e_index = ifind(this%exchange_ids, e_id)
93 if (e_index > 0) then
94 ! extend existing index map
95 call this%exchange_maps(e_index)%add(map_to_add%exchange_maps(ie))
96 else
97 ! place in first empty spot
98 e_index = ifind(this%exchange_ids, -1)
99 this%exchange_ids(e_index) = e_id
100 this%exchange_names(e_index) = map_to_add%exchange_names(ie)
101 call this%exchange_maps(e_index)%copy(map_to_add%exchange_maps(ie))
102 end if
103 end do
104
105 end subroutine add
106
107 function get_node_map(this, model_id) result(node_map)
108 use simmodule, only: ustop
109 class(interfacemaptype) :: this
110 integer(I4B) :: model_id
111 type(indexmaptype), pointer :: node_map
112 ! local
113 integer(I4B) :: m_idx
114
115 node_map => null()
116 m_idx = ifind(this%model_ids, model_id)
117 if (m_idx > 0) then
118 node_map => this%node_maps(m_idx)
119 else
120 call ustop("Internal error. Can't find node map in interface")
121 end if
122
123 end function get_node_map
124
125 function get_connection_map(this, model_id) result(connection_map)
126 class(interfacemaptype) :: this
127 integer(I4B) :: model_id
128 type(indexmaptype), pointer :: connection_map
129 ! local
130 integer(I4B) :: m_idx
131
132 connection_map => null()
133 m_idx = ifind(this%model_ids, model_id)
134 if (m_idx > 0) then
135 connection_map => this%conn_maps(m_idx)
136 end if
137
138 end function get_connection_map
139
140 !> @brief Dumps interface data to the screen
141 !<
142 subroutine print_interface(this, outunit)
143 class(interfacemaptype) :: this
144 integer(I4B) :: outunit
145 ! local
146 integer(I4B) :: i, n
147
148 write (outunit, '(a,i0)') "nr. models: ", this%nr_models
149 write (outunit, '(a,i0)') "nr. exchanges: ", this%nr_exchanges
150 do i = 1, this%nr_models
151 if (this%model_ids(i) == -1) cycle
152 write (outunit, '(3a,i0,a)') "model: ", trim(this%model_names(i)), &
153 "[", this%model_ids(i), "]"
154 write (outunit, *) "node map:"
155 do n = 1, size(this%node_maps(i)%src_idx)
156 write (outunit, '(i7,a,i7)') this%node_maps(i)%src_idx(n), &
157 " ", this%node_maps(i)%tgt_idx(n)
158 end do
159 write (outunit, *) "connection map:"
160 do n = 1, size(this%conn_maps(i)%src_idx)
161 write (outunit, '(i7,a,i7)') this%conn_maps(i)%src_idx(n), &
162 " ", this%conn_maps(i)%tgt_idx(n)
163 end do
164 end do
165
166 do i = 1, this%nr_exchanges
167 if (this%exchange_ids(i) == -1) cycle
168 write (outunit, '(3a,i0,a)') "exchange: ", trim(this%exchange_names(i)), &
169 "[", this%exchange_ids(i), "]"
170 write (outunit, *) "exchange map:"
171 do n = 1, size(this%exchange_maps(i)%src_idx)
172 write (outunit, '(i7,a,i7,a,i7)') this%exchange_maps(i)%src_idx(n), &
173 " ", this%exchange_maps(i)%tgt_idx(n), &
174 " ", this%exchange_maps(i)%sign(n)
175 end do
176 end do
177
178 end subroutine print_interface
179
180 subroutine destroy(this)
181 class(interfacemaptype) :: this
182 ! local
183 integer(I4B) :: i
184
185 do i = 1, this%nr_models
186 if (this%model_ids(i) == -1) cycle
187 deallocate (this%node_maps(i)%src_idx)
188 deallocate (this%node_maps(i)%tgt_idx)
189 deallocate (this%conn_maps(i)%src_idx)
190 deallocate (this%conn_maps(i)%tgt_idx)
191 end do
192 deallocate (this%node_maps)
193 deallocate (this%conn_maps)
194
195 do i = 1, this%nr_exchanges
196 if (this%exchange_ids(i) == -1) cycle
197 deallocate (this%exchange_maps(i)%src_idx)
198 deallocate (this%exchange_maps(i)%tgt_idx)
199 deallocate (this%exchange_maps(i)%sign)
200 end do
201 deallocate (this%exchange_maps)
202
203 deallocate (this%model_ids)
204 deallocate (this%model_names)
205 deallocate (this%exchange_ids)
206 deallocate (this%exchange_names)
207
208 end subroutine destroy
209
210end module interfacemapmodule
This module contains simulation constants.
Definition Constants.f90:9
integer(i4b), parameter lenmodelname
maximum length of the model name
Definition Constants.f90:22
integer(i4b), parameter lenexchangename
maximum length of the exchange name
Definition Constants.f90:24
subroutine destroy(this)
type(indexmaptype) function, pointer get_connection_map(this, model_id)
subroutine print_interface(this, outunit)
Dumps interface data to the screen.
subroutine add(this, map_to_add)
@ Adds a map, either by extending the existing map for a certain model or exchange,...
subroutine init(this, nr_models, nr_exchanges)
type(indexmaptype) function, pointer get_node_map(this, model_id)
This module defines variable data types.
Definition kind.f90:8
This module contains simulation methods.
Definition Sim.f90:10
subroutine, public ustop(stopmess, ioutlocal)
Stop the simulation.
Definition Sim.f90:317