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"
84 grid_type(1:len_trim(grid_type_f) + 1) = &
91 bind(C, name="get_grid_rank")
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
98 character(len=LENMODELNAME) :: model_name
99 integer(I4B),
dimension(:),
pointer,
contiguous :: grid_shape
109 if (grid_shape(1) == 1)
then
119 bind(C, name="get_grid_size")
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
126 character(len=LENMODELNAME) :: model_name
127 integer(I4B),
dimension(:),
pointer,
contiguous :: grid_shape
129 character(len=LENGRIDTYPE) :: grid_type_f
130 integer(I4B) :: status
139 if (grid_type_f ==
"rectilinear")
then
141 grid_size = grid_shape(1) * grid_shape(2) * grid_shape(3)
144 else if (grid_type_f ==
"unstructured")
then
153 bind(C, name="get_grid_shape")
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
160 integer,
dimension(:),
pointer,
contiguous :: grid_shape_ptr
161 character(len=LENMODELNAME) :: model_name
172 if (grid_shape_ptr(1) == 1)
then
173 grid_shape(1:2) = grid_shape_ptr(2:3)
175 grid_shape(1:3) = grid_shape_ptr
182 bind(C, name="get_grid_x")
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
190 integer,
dimension(:),
pointer,
contiguous :: grid_shape_ptr
191 character(len=LENMODELNAME) :: model_name
193 real(dp),
dimension(:, :),
pointer,
contiguous :: vertices_ptr
194 character(len=LENGRIDTYPE) :: grid_type_f
195 integer(I4B) :: x_size
204 if (grid_type_f ==
"rectilinear")
then
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
215 x_size =
size(vertices_ptr(1, :))
216 grid_x(1:x_size) = vertices_ptr(1, :)
226 bind(C, name="get_grid_y")
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
234 integer,
dimension(:),
pointer,
contiguous :: grid_shape_ptr
235 character(len=LENMODELNAME) :: model_name
237 real(dp),
dimension(:, :),
pointer,
contiguous :: vertices_ptr
238 character(len=LENGRIDTYPE) :: grid_type_f
239 integer(I4B) :: y_size
247 if (grid_type_f ==
"rectilinear")
then
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
258 y_size =
size(vertices_ptr(2, :))
259 grid_y(1:y_size) = vertices_ptr(2, :)
270 bind(C, name="get_grid_node_count")
273 integer(kind=c_int),
intent(in) :: grid_id
274 integer(kind=c_int),
intent(out) :: count
275 integer(kind=c_int) :: bmi_status
277 character(len=LENMODELNAME) :: model_name
278 integer(I4B),
pointer :: nvert_ptr
293 bind(C, name="get_grid_face_count")
299 integer(kind=c_int),
intent(in) :: grid_id
300 integer(kind=c_int),
intent(out) :: count
301 integer(kind=c_int) :: bmi_status
303 character(len=LENMODELNAME) :: model_name
314 if (numericalmodel%name == model_name)
then
315 count = numericalmodel%dis%nodes
323 bind(C, name="get_grid_face_nodes")
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
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
346 allocate (nodes_per_face(face_count))
350 face_nodes_count = sum(nodes_per_face + 1)
352 face_nodes(1:face_nodes_count) = javert_ptr(:)
358 bind(C, name="get_grid_nodes_per_face")
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
366 character(len=LENMODELNAME) :: model_name
367 integer,
dimension(:),
pointer,
contiguous :: iavert_ptr
376 do i = 1,
size(iavert_ptr) - 1
377 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.