11 use iso_c_binding,
only: c_double, c_ptr, c_loc
21 function get_var_grid(c_var_address, var_grid)
result(bmi_status) &
22 bind(C, name="get_var_grid")
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
32 character(len=LENMODELNAME) :: model_name
33 character(len=LENMEMPATH) :: var_address
35 logical(LGP) :: success
42 strlen(c_var_address, lenmemaddress + 1))
44 if (.not. success)
then
51 if (basemodel%name == model_name)
then
52 var_grid = basemodel%id
61 bind(C, name="get_grid_type")
64 integer(kind=c_int),
intent(in) :: grid_id
66 integer(kind=c_int) :: bmi_status
68 character(len=LENGRIDTYPE) :: grid_type_f
69 character(len=LENMODELNAME) :: model_name
73 if (model_name ==
'')
return
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"
90 bind(C, name="get_grid_rank")
93 integer(kind=c_int),
intent(in) :: grid_id
94 integer(kind=c_int),
intent(out) :: grid_rank
95 integer(kind=c_int) :: bmi_status
97 character(len=LENMODELNAME) :: model_name
98 integer(I4B),
dimension(:),
pointer,
contiguous :: grid_shape
108 if (grid_shape(1) == 1)
then
118 bind(C, name="get_grid_size")
121 integer(kind=c_int),
intent(in) :: grid_id
122 integer(kind=c_int),
intent(out) :: grid_size
123 integer(kind=c_int) :: bmi_status
125 character(len=LENMODELNAME) :: model_name
126 integer(I4B),
dimension(:),
pointer,
contiguous :: grid_shape
128 character(len=LENGRIDTYPE) :: grid_type_f
129 integer(I4B) :: status
138 if (grid_type_f ==
"rectilinear")
then
140 grid_size = grid_shape(1) * grid_shape(2) * grid_shape(3)
143 else if (grid_type_f ==
"unstructured")
then
152 bind(C, name="get_grid_shape")
155 integer(kind=c_int),
intent(in) :: grid_id
156 integer(kind=c_int),
intent(out) :: grid_shape(*)
157 integer(kind=c_int) :: bmi_status
159 integer,
dimension(:),
pointer,
contiguous :: grid_shape_ptr
160 character(len=LENMODELNAME) :: model_name
171 if (grid_shape_ptr(1) == 1)
then
172 grid_shape(1:2) = grid_shape_ptr(2:3)
174 grid_shape(1:3) = grid_shape_ptr
181 bind(C, name="get_grid_x")
184 integer(kind=c_int),
intent(in) :: grid_id
185 real(kind=c_double),
intent(out) :: grid_x(*)
186 integer(kind=c_int) :: bmi_status
189 integer,
dimension(:),
pointer,
contiguous :: grid_shape_ptr
190 character(len=LENMODELNAME) :: model_name
192 real(dp),
dimension(:, :),
pointer,
contiguous :: vertices_ptr
193 character(len=LENGRIDTYPE) :: grid_type_f
194 integer(I4B) :: x_size
203 if (grid_type_f ==
"rectilinear")
then
208 x_size = grid_shape_ptr(
size(grid_shape_ptr)) + 1
209 grid_x(1:x_size) = [(i, i=0, x_size - 1)]
210 else if (grid_type_f ==
"unstructured")
then
214 x_size =
size(vertices_ptr(1, :))
215 grid_x(1:x_size) = vertices_ptr(1, :)
225 bind(C, name="get_grid_y")
228 integer(kind=c_int),
intent(in) :: grid_id
229 real(kind=c_double),
intent(out) :: grid_y(*)
230 integer(kind=c_int) :: bmi_status
233 integer,
dimension(:),
pointer,
contiguous :: grid_shape_ptr
234 character(len=LENMODELNAME) :: model_name
236 real(dp),
dimension(:, :),
pointer,
contiguous :: vertices_ptr
237 character(len=LENGRIDTYPE) :: grid_type_f
238 integer(I4B) :: y_size
246 if (grid_type_f ==
"rectilinear")
then
251 y_size = grid_shape_ptr(
size(grid_shape_ptr - 1)) + 1
252 grid_y(1:y_size) = [(i, i=y_size - 1, 0, -1)]
253 else if (grid_type_f ==
"unstructured")
then
257 y_size =
size(vertices_ptr(2, :))
258 grid_y(1:y_size) = vertices_ptr(2, :)
269 bind(C, name="get_grid_node_count")
272 integer(kind=c_int),
intent(in) :: grid_id
273 integer(kind=c_int),
intent(out) :: count
274 integer(kind=c_int) :: bmi_status
276 character(len=LENMODELNAME) :: model_name
277 integer(I4B),
pointer :: nvert_ptr
292 bind(C, name="get_grid_face_count")
298 integer(kind=c_int),
intent(in) :: grid_id
299 integer(kind=c_int),
intent(out) :: count
300 integer(kind=c_int) :: bmi_status
302 character(len=LENMODELNAME) :: model_name
313 if (numericalmodel%name == model_name)
then
314 count = numericalmodel%dis%nodes
322 bind(C, name="get_grid_face_nodes")
325 integer(kind=c_int),
intent(in) :: grid_id
326 integer(kind=c_int),
intent(out) :: face_nodes(*)
327 integer(kind=c_int) :: bmi_status
329 character(len=LENMODELNAME) :: model_name
330 integer,
dimension(:),
pointer,
contiguous :: javert_ptr
331 integer,
dimension(:),
allocatable :: nodes_per_face
332 integer :: face_count
333 integer :: face_nodes_count
345 allocate (nodes_per_face(face_count))
349 face_nodes_count = sum(nodes_per_face + 1)
351 face_nodes(1:face_nodes_count) = javert_ptr(:)
357 bind(C, name="get_grid_nodes_per_face")
360 integer(kind=c_int),
intent(in) :: grid_id
361 integer(kind=c_int),
intent(out) :: nodes_per_face(*)
362 integer(kind=c_int) :: bmi_status
365 character(len=LENMODELNAME) :: model_name
366 integer,
dimension(:),
pointer,
contiguous :: iavert_ptr
375 do i = 1,
size(iavert_ptr) - 1
376 nodes_per_face(i) = iavert_ptr(i + 1) - iavert_ptr(i) - 1
class(basemodeltype) function, pointer, public getbasemodelfromlist(list, idx)
This module contains simulation constants.
integer(i4b), parameter lenmodelname
maximum length of the model name
integer(i4b), parameter lenmempath
maximum length of the memory path
This module defines variable data types.
type(listtype), public basemodellist
character(len=lenmempath) function create_mem_path(component, subcomponent, context)
returns the path to the memory object
Detailed error information for the BMI.
integer, parameter bmi_failure
BMI status code for failure (taken from bmi.f90, CSDMS)
integer, parameter bmi_success
BMI status code for success (taken from bmi.f90, CSDMS)
This module contains BMI routines to expose the MODFLOW 6 discretization.
integer(kind=c_int) function get_grid_rank(grid_id, grid_rank)
integer(kind=c_int) function get_grid_face_count(grid_id, count)
integer(kind=c_int) function get_grid_shape(grid_id, grid_shape)
integer(kind=c_int) function get_grid_face_nodes(grid_id, face_nodes)
integer(kind=c_int) function get_grid_type(grid_id, grid_type)
integer(kind=c_int) function get_var_grid(c_var_address, var_grid)
integer(kind=c_int) function get_grid_nodes_per_face(grid_id, nodes_per_face)
integer(kind=c_int) function get_grid_size(grid_id, grid_size)
integer(kind=c_int) function get_grid_node_count(grid_id, count)
integer(kind=c_int) function get_grid_y(grid_id, grid_y)
integer(kind=c_int) function get_grid_x(grid_id, grid_x)
This module contains helper routines and parameters for the MODFLOW 6 BMI.
character(len=lenmodelname) function get_model_name(grid_id)
Get the model name from the grid id.
subroutine get_grid_type_model(model_name, grid_type_f)
Get the grid type for a named model as a fortran string.
integer(c_int), bind(C, name="BMI_LENGRIDTYPE") bmi_lengridtype
max. length for grid type C-strings
integer(i4b), parameter lengridtype
max length for Fortran grid type string
logical function confirm_grid_type(grid_id, expected_type)
Confirm that grid is of an expected type.
pure character(kind=c_char, len=1) function, dimension(length+1) string_to_char_array(string, length)
Convert Fortran string to C-style character string.
pure integer(i4b) function strlen(char_array, max_len)
Returns the string length without the trailing null character.
pure character(len=length) function char_array_to_string(char_array, length)
Convert C-style string to Fortran character string.
character(len=lenmodelname) function extract_model_name(var_address, success)
Extract the model name from a memory address string.
class(numericalmodeltype) function, pointer, public getnumericalmodelfromlist(list, idx)
Highest level model type. All models extend this parent type.