MODFLOW 6  version 6.8.0.dev0
USGS Modular Hydrologic Model
mf6bmigrid Module Reference

This module contains BMI routines to expose the MODFLOW 6 discretization. More...

Functions/Subroutines

integer(kind=c_int) function get_var_grid (c_var_address, var_grid)
 
integer(kind=c_int) function get_grid_type (grid_id, grid_type)
 
integer(kind=c_int) function get_grid_rank (grid_id, grid_rank)
 
integer(kind=c_int) function get_grid_size (grid_id, grid_size)
 
integer(kind=c_int) function get_grid_shape (grid_id, grid_shape)
 
integer(kind=c_int) function get_grid_x (grid_id, grid_x)
 
integer(kind=c_int) function get_grid_y (grid_id, grid_y)
 
integer(kind=c_int) function get_grid_node_count (grid_id, count)
 
integer(kind=c_int) function get_grid_face_count (grid_id, count)
 
integer(kind=c_int) function get_grid_face_nodes (grid_id, face_nodes)
 
integer(kind=c_int) function get_grid_nodes_per_face (grid_id, nodes_per_face)
 

Detailed Description

NB: this module is experimental and still under development:

  • add error handling
  • add var address checks
  • ...

Function/Subroutine Documentation

◆ get_grid_face_count()

integer(kind=c_int) function mf6bmigrid::get_grid_face_count ( integer(kind=c_int), intent(in)  grid_id,
integer(kind=c_int), intent(out)  count 
)

Definition at line 292 of file mf6bmiGrid.f90.

294  !DIR$ ATTRIBUTES DLLEXPORT :: get_grid_face_count
295  ! -- modules
296  use listsmodule, only: basemodellist
298  ! -- dummy variables
299  integer(kind=c_int), intent(in) :: grid_id
300  integer(kind=c_int), intent(out) :: count
301  integer(kind=c_int) :: bmi_status
302  ! -- local variables
303  character(len=LENMODELNAME) :: model_name
304  integer(I4B) :: i
305  class(NumericalModelType), pointer :: numericalModel
306 
307  ! make sure function is only used for DISU grids
308  bmi_status = bmi_failure
309  if (.not. confirm_grid_type(grid_id, "DISU")) return
310 
311  model_name = get_model_name(grid_id)
312  do i = 1, basemodellist%Count()
313  numericalmodel => getnumericalmodelfromlist(basemodellist, i)
314  if (numericalmodel%name == model_name) then
315  count = numericalmodel%dis%nodes
316  end if
317  end do
318  bmi_status = bmi_success
type(listtype), public basemodellist
Definition: mf6lists.f90:16
class(numericalmodeltype) function, pointer, public getnumericalmodelfromlist(list, idx)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_grid_face_nodes()

integer(kind=c_int) function mf6bmigrid::get_grid_face_nodes ( integer(kind=c_int), intent(in)  grid_id,
integer(kind=c_int), dimension(*), intent(out)  face_nodes 
)

Definition at line 322 of file mf6bmiGrid.f90.

324  !DIR$ ATTRIBUTES DLLEXPORT :: get_grid_face_nodes
325  ! -- dummy variables
326  integer(kind=c_int), intent(in) :: grid_id
327  integer(kind=c_int), intent(out) :: face_nodes(*)
328  integer(kind=c_int) :: bmi_status
329  ! -- local variables
330  character(len=LENMODELNAME) :: model_name
331  integer, dimension(:), pointer, contiguous :: javert_ptr
332  integer, dimension(:), allocatable :: nodes_per_face
333  integer :: face_count
334  integer :: face_nodes_count
335 
336  ! make sure function is only used for DISU grids
337  bmi_status = bmi_failure
338  if (.not. confirm_grid_type(grid_id, "DISU")) return
339 
340  model_name = get_model_name(grid_id)
341  call mem_setptr(javert_ptr, "JAVERT", create_mem_path(model_name, 'DIS'))
342 
343  bmi_status = get_grid_face_count(grid_id, face_count)
344  if (bmi_status == bmi_failure) return
345 
346  allocate (nodes_per_face(face_count))
347  bmi_status = get_grid_nodes_per_face(grid_id, nodes_per_face)
348  if (bmi_status == bmi_failure) return
349 
350  face_nodes_count = sum(nodes_per_face + 1)
351 
352  face_nodes(1:face_nodes_count) = javert_ptr(:)
353  bmi_status = bmi_success
Here is the call graph for this function:

◆ get_grid_node_count()

integer(kind=c_int) function mf6bmigrid::get_grid_node_count ( integer(kind=c_int), intent(in)  grid_id,
integer(kind=c_int), intent(out)  count 
)

Definition at line 269 of file mf6bmiGrid.f90.

271  !DIR$ ATTRIBUTES DLLEXPORT :: get_grid_node_count
272  ! -- dummy variables
273  integer(kind=c_int), intent(in) :: grid_id
274  integer(kind=c_int), intent(out) :: count
275  integer(kind=c_int) :: bmi_status
276  ! -- local variables
277  character(len=LENMODELNAME) :: model_name
278  integer(I4B), pointer :: nvert_ptr
279 
280  ! make sure function is only used for DISU grids
281  bmi_status = bmi_failure
282  if (.not. confirm_grid_type(grid_id, "DISU")) return
283 
284  model_name = get_model_name(grid_id)
285  call mem_setptr(nvert_ptr, "NVERT", create_mem_path(model_name, 'DIS'))
286  count = nvert_ptr
287  bmi_status = bmi_success
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_grid_nodes_per_face()

integer(kind=c_int) function mf6bmigrid::get_grid_nodes_per_face ( integer(kind=c_int), intent(in)  grid_id,
integer(kind=c_int), dimension(*), intent(out)  nodes_per_face 
)

Definition at line 357 of file mf6bmiGrid.f90.

359  !DIR$ ATTRIBUTES DLLEXPORT :: get_grid_nodes_per_face
360  ! -- dummy variables
361  integer(kind=c_int), intent(in) :: grid_id
362  integer(kind=c_int), intent(out) :: nodes_per_face(*)
363  integer(kind=c_int) :: bmi_status
364  ! -- local variables
365  integer(I4B) :: i
366  character(len=LENMODELNAME) :: model_name
367  integer, dimension(:), pointer, contiguous :: iavert_ptr
368 
369  ! make sure function is only used for DISU grids
370  bmi_status = bmi_failure
371  if (.not. confirm_grid_type(grid_id, "DISU")) return
372 
373  model_name = get_model_name(grid_id)
374  call mem_setptr(iavert_ptr, "IAVERT", create_mem_path(model_name, 'DIS'))
375 
376  do i = 1, size(iavert_ptr) - 1
377  nodes_per_face(i) = iavert_ptr(i + 1) - iavert_ptr(i) - 1
378  end do
379  bmi_status = bmi_success
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_grid_rank()

integer(kind=c_int) function mf6bmigrid::get_grid_rank ( integer(kind=c_int), intent(in)  grid_id,
integer(kind=c_int), intent(out)  grid_rank 
)

Definition at line 90 of file mf6bmiGrid.f90.

92  !DIR$ ATTRIBUTES DLLEXPORT :: get_grid_rank
93  ! -- dummy variables
94  integer(kind=c_int), intent(in) :: grid_id
95  integer(kind=c_int), intent(out) :: grid_rank
96  integer(kind=c_int) :: bmi_status
97  ! -- local variables
98  character(len=LENMODELNAME) :: model_name
99  integer(I4B), dimension(:), pointer, contiguous :: grid_shape
100 
101  bmi_status = bmi_failure
102  ! TODO: It is currently only implemented for DIS grids
103  if (.not. confirm_grid_type(grid_id, "DIS")) return
104 
105  ! get shape array
106  model_name = get_model_name(grid_id)
107  call mem_setptr(grid_shape, "MSHAPE", create_mem_path(model_name, 'DIS'))
108 
109  if (grid_shape(1) == 1) then
110  grid_rank = 2
111  else
112  grid_rank = 3
113  end if
114  bmi_status = bmi_success
Here is the call graph for this function:

◆ get_grid_shape()

integer(kind=c_int) function mf6bmigrid::get_grid_shape ( integer(kind=c_int), intent(in)  grid_id,
integer(kind=c_int), dimension(*), intent(out)  grid_shape 
)

Definition at line 152 of file mf6bmiGrid.f90.

154  !DIR$ ATTRIBUTES DLLEXPORT :: get_grid_shape
155  ! -- dummy variables
156  integer(kind=c_int), intent(in) :: grid_id
157  integer(kind=c_int), intent(out) :: grid_shape(*)
158  integer(kind=c_int) :: bmi_status
159  ! -- local variables
160  integer, dimension(:), pointer, contiguous :: grid_shape_ptr
161  character(len=LENMODELNAME) :: model_name
162  character(kind=c_char) :: grid_type(BMI_LENGRIDTYPE)
163 
164  bmi_status = bmi_failure
165  ! make sure function is only used for implemented grid_types
166  if (get_grid_type(grid_id, grid_type) /= bmi_success) return
167 
168  ! get shape array
169  model_name = get_model_name(grid_id)
170  call mem_setptr(grid_shape_ptr, "MSHAPE", create_mem_path(model_name, 'DIS'))
171 
172  if (grid_shape_ptr(1) == 1) then
173  grid_shape(1:2) = grid_shape_ptr(2:3) ! 2D
174  else
175  grid_shape(1:3) = grid_shape_ptr ! 3D
176  end if
177  bmi_status = bmi_success
Here is the call graph for this function:

◆ get_grid_size()

integer(kind=c_int) function mf6bmigrid::get_grid_size ( integer(kind=c_int), intent(in)  grid_id,
integer(kind=c_int), intent(out)  grid_size 
)

Definition at line 118 of file mf6bmiGrid.f90.

120  !DIR$ ATTRIBUTES DLLEXPORT :: get_grid_size
121  ! -- dummy variables
122  integer(kind=c_int), intent(in) :: grid_id
123  integer(kind=c_int), intent(out) :: grid_size
124  integer(kind=c_int) :: bmi_status
125  ! -- local variables
126  character(len=LENMODELNAME) :: model_name
127  integer(I4B), dimension(:), pointer, contiguous :: grid_shape
128  character(kind=c_char) :: grid_type(BMI_LENGRIDTYPE)
129  character(len=LENGRIDTYPE) :: grid_type_f
130  integer(I4B) :: status
131 
132  bmi_status = bmi_failure
133 
134  if (get_grid_type(grid_id, grid_type) /= bmi_success) return
135  grid_type_f = char_array_to_string(grid_type, &
136  strlen(grid_type, lengridtype + 1))
137  model_name = get_model_name(grid_id)
138 
139  if (grid_type_f == "rectilinear") then
140  call mem_setptr(grid_shape, "MSHAPE", create_mem_path(model_name, 'DIS'))
141  grid_size = grid_shape(1) * grid_shape(2) * grid_shape(3)
142  bmi_status = bmi_success
143  return
144  else if (grid_type_f == "unstructured") then
145  status = get_grid_node_count(grid_id, grid_size)
146  bmi_status = bmi_success
147  return
148  end if
Here is the call graph for this function:

◆ get_grid_type()

integer(kind=c_int) function mf6bmigrid::get_grid_type ( integer(kind=c_int), intent(in)  grid_id,
character(kind=c_char), dimension(bmi_lengridtype), intent(inout)  grid_type 
)

Definition at line 60 of file mf6bmiGrid.f90.

62  !DIR$ ATTRIBUTES DLLEXPORT :: get_grid_type
63  ! -- dummy variables
64  integer(kind=c_int), intent(in) :: grid_id
65  character(kind=c_char), intent(inout) :: grid_type(BMI_LENGRIDTYPE)
66  integer(kind=c_int) :: bmi_status
67  ! -- local variables
68  character(len=LENGRIDTYPE) :: grid_type_f
69  character(len=LENMODELNAME) :: model_name
70 
71  bmi_status = bmi_failure
72  model_name = get_model_name(grid_id)
73  if (model_name == '') return
74 
75  call get_grid_type_model(model_name, grid_type_f)
76 
77  if (grid_type_f == "DIS") then
78  grid_type_f = "rectilinear"
79  else if ((grid_type_f == "DISV") .or. (grid_type_f == "DISU")) then
80  grid_type_f = "unstructured"
81  else
82  return
83  end if
84  grid_type(1:len_trim(grid_type_f) + 1) = &
85  string_to_char_array(trim(grid_type_f), len_trim(grid_type_f))
86  bmi_status = bmi_success
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_grid_x()

integer(kind=c_int) function mf6bmigrid::get_grid_x ( integer(kind=c_int), intent(in)  grid_id,
real(kind=c_double), dimension(*), intent(out)  grid_x 
)

Definition at line 181 of file mf6bmiGrid.f90.

183  !DIR$ ATTRIBUTES DLLEXPORT :: get_grid_x
184  ! -- dummy variables
185  integer(kind=c_int), intent(in) :: grid_id
186  real(kind=c_double), intent(out) :: grid_x(*)
187  integer(kind=c_int) :: bmi_status
188  ! -- local variables
189  integer(I4B) :: i
190  integer, dimension(:), pointer, contiguous :: grid_shape_ptr
191  character(len=LENMODELNAME) :: model_name
192  character(kind=c_char) :: grid_type(BMI_LENGRIDTYPE)
193  real(DP), dimension(:, :), pointer, contiguous :: vertices_ptr
194  character(len=LENGRIDTYPE) :: grid_type_f
195  integer(I4B) :: x_size
196 
197  bmi_status = bmi_failure
198  ! make sure function is only used for implemented grid_types
199  if (get_grid_type(grid_id, grid_type) /= bmi_success) return
200  grid_type_f = char_array_to_string(grid_type, &
201  strlen(grid_type, lengridtype + 1))
202 
203  model_name = get_model_name(grid_id)
204  if (grid_type_f == "rectilinear") then
205  call mem_setptr(grid_shape_ptr, "MSHAPE", &
206  create_mem_path(model_name, 'DIS'))
207  ! The dimension of x is in the last element of the shape array.
208  ! + 1 because we count corners, not centers.
209  x_size = grid_shape_ptr(size(grid_shape_ptr)) + 1
210  grid_x(1:x_size) = [(i, i=0, x_size - 1)]
211  else if (grid_type_f == "unstructured") then
212  call mem_setptr(vertices_ptr, "VERTICES", &
213  create_mem_path(model_name, 'DIS'))
214  ! x-coordinates are in the 1st column
215  x_size = size(vertices_ptr(1, :))
216  grid_x(1:x_size) = vertices_ptr(1, :)
217  else
218  bmi_status = bmi_failure
219  return
220  end if
221  bmi_status = bmi_success
Here is the call graph for this function:

◆ get_grid_y()

integer(kind=c_int) function mf6bmigrid::get_grid_y ( integer(kind=c_int), intent(in)  grid_id,
real(kind=c_double), dimension(*), intent(out)  grid_y 
)

Definition at line 225 of file mf6bmiGrid.f90.

227  !DIR$ ATTRIBUTES DLLEXPORT :: get_grid_y
228  ! -- dummy variables
229  integer(kind=c_int), intent(in) :: grid_id
230  real(kind=c_double), intent(out) :: grid_y(*)
231  integer(kind=c_int) :: bmi_status
232  ! -- local variables
233  integer(I4B) :: i
234  integer, dimension(:), pointer, contiguous :: grid_shape_ptr
235  character(len=LENMODELNAME) :: model_name
236  character(kind=c_char) :: grid_type(BMI_LENGRIDTYPE)
237  real(DP), dimension(:, :), pointer, contiguous :: vertices_ptr
238  character(len=LENGRIDTYPE) :: grid_type_f
239  integer(I4B) :: y_size
240 
241  bmi_status = bmi_failure
242  if (get_grid_type(grid_id, grid_type) /= bmi_success) return
243  grid_type_f = char_array_to_string(grid_type, &
244  strlen(grid_type, lengridtype + 1))
245 
246  model_name = get_model_name(grid_id)
247  if (grid_type_f == "rectilinear") then
248  call mem_setptr(grid_shape_ptr, "MSHAPE", &
249  create_mem_path(model_name, 'DIS'))
250  ! The dimension of y is in the second last element of the shape array.
251  ! + 1 because we count corners, not centers.
252  y_size = grid_shape_ptr(size(grid_shape_ptr - 1)) + 1
253  grid_y(1:y_size) = [(i, i=y_size - 1, 0, -1)]
254  else if (grid_type_f == "unstructured") then
255  call mem_setptr(vertices_ptr, "VERTICES", &
256  create_mem_path(model_name, 'DIS'))
257  ! y-coordinates are in the 2nd column
258  y_size = size(vertices_ptr(2, :))
259  grid_y(1:y_size) = vertices_ptr(2, :)
260  else
261  bmi_status = bmi_failure
262  return
263  end if
264  bmi_status = bmi_success
Here is the call graph for this function:

◆ get_var_grid()

integer(kind=c_int) function mf6bmigrid::get_var_grid ( character(kind=c_char), dimension(*), intent(in)  c_var_address,
integer(kind=c_int), intent(out)  var_grid 
)

Definition at line 21 of file mf6bmiGrid.f90.

23  !DIR$ ATTRIBUTES DLLEXPORT :: get_var_grid
24  ! -- modules
25  use listsmodule, only: basemodellist
27  ! -- dummy variables
28  character(kind=c_char), intent(in) :: c_var_address(*)
29  integer(kind=c_int), intent(out) :: var_grid
30  integer(kind=c_int) :: bmi_status
31  ! -- local variables
32  character(len=LENMODELNAME) :: model_name
33  character(len=LENMEMPATH) :: var_address
34  integer(I4B) :: i
35  logical(LGP) :: success
36  class(BaseModelType), pointer :: baseModel
37 
38  var_grid = -1
39 
40  bmi_status = bmi_failure
41  var_address = char_array_to_string(c_var_address, &
42  strlen(c_var_address, lenmemaddress + 1))
43  model_name = extract_model_name(var_address, success)
44  if (.not. success) then
45  ! we failed
46  return
47  end if
48 
49  do i = 1, basemodellist%Count()
50  basemodel => getbasemodelfromlist(basemodellist, i)
51  if (basemodel%name == model_name) then
52  var_grid = basemodel%id
53  bmi_status = bmi_success
54  return
55  end if
56  end do
class(basemodeltype) function, pointer, public getbasemodelfromlist(list, idx)
Definition: BaseModel.f90:171
Highest level model type. All models extend this parent type.
Definition: BaseModel.f90:16
Here is the call graph for this function: