MODFLOW 6  version 6.7.0.dev2
USGS Modular Hydrologic Model
DisUtils.f90
Go to the documentation of this file.
2  use kindmodule, only: dp, i4b
3  use constantsmodule, only: dsame, done
4  use basedismodule, only: disbasetype
5 
6  implicit none
7  private
8 
9  public :: number_connected_faces
10  public :: cell_center
11  public :: node_distance
12 
13 contains
14 
15  !> @brief Returns the number of connected faces for a given cell.
16  !!
17  !! This function computes the number of faces of cell `n` that are connected to neighboring cells
18  !! in the discretization. The value is determined from the connectivity information in the
19  !! connection arrays, and does not include boundary faces (faces not connected to another cell).
20  !<
21  function number_connected_faces(dis, n) result(connected_faces_count)
22  class(disbasetype), intent(in) :: dis
23  integer(I4B), intent(in) :: n
24  integer(I4B) :: connected_faces_count
25 
26  connected_faces_count = dis%con%ia(n + 1) - dis%con%ia(n) - 1
27  end function number_connected_faces
28 
29  !> @brief Returns the vector distance from cell n to cell m.
30  !!
31  !! This function computes the vector from the center of cell `n` to the center of cell `m`
32  !! in the discretization. If the cells are directly connected, the vector is computed along
33  !! the connection direction, taking into account cell geometry and, if available, cell saturation.
34  !! If the cells are not directly connected (e.g., when using an extended stencil such as neighbors-of-neighbors),
35  !! the vector is simply the difference between their centroids: `d = centroid(m) - centroid(n)`.
36  !! The returned vector always points from cell `n` to cell `m`.
37  !<
38  function node_distance(dis, n, m) result(d)
39  !-- modules
40  use tspfmimodule, only: tspfmitype
41  ! -- return
42  real(dp), dimension(3) :: d
43  ! -- dummy
44  class(disbasetype), intent(in) :: dis
45  integer(I4B), intent(in) :: n, m
46  ! -- local
47  real(dp) :: x_dir, y_dir, z_dir, length
48  integer(I4B) :: ipos, isympos, ihc
49  real(dp), dimension(3) :: xn, xm
50 
51  ! -- Find the connection position (isympos) between cell n and cell m
52  isympos = -1
53  do ipos = dis%con%ia(n) + 1, dis%con%ia(n + 1) - 1
54  if (dis%con%ja(ipos) == m) then
55  isympos = dis%con%jas(ipos)
56  exit
57  end if
58  end do
59 
60  ! -- if the connection is not found, then return the distance between the two nodes
61  ! -- This can happen when using an extended stencil (neighbours-of-neigbhours) to compute the gradients
62  if (isympos == -1) then
63  xn = cell_center(dis, n)
64  xm = cell_center(dis, m)
65 
66  d = xm - xn
67  return
68  end if
69 
70  ! -- Get the connection direction and length
71  ihc = dis%con%ihc(isympos)
72  call dis%connection_vector(n, m, .false., done, done, ihc, x_dir, &
73  y_dir, z_dir, length)
74 
75  ! -- Compute the distance vector
76  d(1) = x_dir * length
77  d(2) = y_dir * length
78  d(3) = z_dir * length
79 
80  end function node_distance
81 
82  !> @brief Returns the center coordinates of a given cell.
83  !!
84  !! This function computes the center of cell `n` in the discretization.
85  !! The center is returned as a 3-element vector containing the x, y, and z coordinates.
86  !! The x and y coordinates are taken directly from the cell center arrays, while the z coordinate
87  !! is computed as the average of the cell's top and bottom elevations.
88  !<
89  function cell_center(dis, n) result(center)
90  ! -- dummy
91  class(disbasetype), intent(in) :: dis
92  integer(I4B), intent(in) :: n
93  real(dp), dimension(3) :: center
94 
95  center(1) = dis%xc(n)
96  center(2) = dis%yc(n)
97  center(3) = (dis%top(n) + dis%bot(n)) / 2.0_dp
98  end function cell_center
99 end module disutilsmodule
This module contains simulation constants.
Definition: Constants.f90:9
real(dp), parameter dsame
real constant for values that are considered the same based on machine precision
Definition: Constants.f90:122
real(dp), parameter done
real constant 1
Definition: Constants.f90:76
real(dp) function, dimension(3), public cell_center(dis, n)
Returns the center coordinates of a given cell.
Definition: DisUtils.f90:90
integer(i4b) function, public number_connected_faces(dis, n)
Returns the number of connected faces for a given cell.
Definition: DisUtils.f90:22
real(dp) function, dimension(3), public node_distance(dis, n, m)
Returns the vector distance from cell n to cell m.
Definition: DisUtils.f90:39
This module defines variable data types.
Definition: kind.f90:8