|
| 1 | +!> |
| 2 | +!! @file |
| 3 | +!! @brief Contains module m_ibm |
| 4 | + |
| 5 | +#:include 'macros.fpp' |
| 6 | + |
| 7 | +!> @brief Contains helper functions specific to various patch gemoetries for determining if a grid cell lies inside of or outside of |
| 8 | +!! a patch geometry |
| 9 | +module m_patch_geometries |
| 10 | + |
| 11 | + use m_derived_types |
| 12 | + use m_global_parameters |
| 13 | + use m_variables_conversion |
| 14 | + use m_helper |
| 15 | + use m_helper_basic |
| 16 | + use m_constants |
| 17 | + use m_model |
| 18 | + |
| 19 | + implicit none |
| 20 | + |
| 21 | + public :: f_is_inside_sphere, f_is_inside_cylinder, f_is_inside_cuboid, f_is_inside_airfoil, f_is_inside_ellipse |
| 22 | + |
| 23 | +contains |
| 24 | + |
| 25 | + !> Check if the x, y, and z coordinates would be located inside a sphere with the patch_id's radius |
| 26 | + function f_is_inside_sphere(x, y, z, radius) result(is_inside) |
| 27 | +
|
| 28 | + $:GPU_ROUTINE(parallelism='[seq]') |
| 29 | +
|
| 30 | + real(wp), intent(in) :: radius, x, y, z |
| 31 | + logical :: is_inside |
| 32 | +
|
| 33 | + is_inside = x**2 + y**2 + z**2 <= radius**2 |
| 34 | +
|
| 35 | + end function f_is_inside_sphere |
| 36 | +
|
| 37 | + !> Check which length of the cylinder is not default. Use that direction as the height and the other two coordinate |
| 38 | + ! values as the radius check |
| 39 | + function f_is_inside_cylinder(polar_x, polar_y, height, radius, length) result(is_inside) |
| 40 | +
|
| 41 | + $:GPU_ROUTINE(parallelism='[seq]') |
| 42 | +
|
| 43 | + real(wp), intent(in) :: polar_x, polar_y, height, radius, length |
| 44 | + logical :: is_inside |
| 45 | +
|
| 46 | + ! check if the circular component of the cylinder is correct |
| 47 | + is_inside = polar_x**2 + polar_y**2 <= radius**2 |
| 48 | +
|
| 49 | + ! in 3D, also check the length of the cylinder |
| 50 | + if (num_dims == 3) is_inside = is_inside .and. -0.5_wp*length <= height .and. 0.5_wp*length >= height |
| 51 | +
|
| 52 | + end function f_is_inside_cylinder |
| 53 | +
|
| 54 | + !> Check if the x, y, and possibly z coordinates would be located inside a cuboid with the patch_id's lengths |
| 55 | + function f_is_inside_cuboid(x, y, z, length) result(is_inside) |
| 56 | + |
| 57 | + $:GPU_ROUTINE(parallelism='[seq]') |
| 58 | + |
| 59 | + real(wp), intent(in) :: x, y, z |
| 60 | + real(wp), dimension(3), intent(in) :: length |
| 61 | + logical :: is_inside |
| 62 | + |
| 63 | + ! check if x and y are inside the rectangle plane at z=0 |
| 64 | + is_inside = -0.5_wp*length(1) <= x .and. 0.5_wp*length(1) >= x .and. -0.5_wp*length(2) <= y .and. 0.5_wp*length(2) >= y |
| 65 | + |
| 66 | + ! if we are in 3D, this is a cuboid and so we must also check the z axis |
| 67 | + if (num_dims == 3) is_inside = is_inside .and. -0.5_wp*length(3) <= z .and. 0.5_wp*length(3) >= z |
| 68 | + |
| 69 | + end function f_is_inside_cuboid |
| 70 | + |
| 71 | + !> Check if the x, y, are bounded by a NACA airfoil. Check if the z coordinate is inside the left and right edges of the |
| 72 | + !! airfoil, if set. |
| 73 | + function f_is_inside_airfoil(x, y, z, length, airfoil_id) result(is_inside) |
| 74 | + |
| 75 | + $:GPU_ROUTINE(parallelism='[seq]') |
| 76 | + |
| 77 | + real(wp), intent(in) :: x, y, z, length |
| 78 | + integer, intent(in) :: airfoil_id |
| 79 | + logical :: is_inside |
| 80 | + integer :: k |
| 81 | + real(wp) :: f |
| 82 | + |
| 83 | + is_inside = .false. |
| 84 | + |
| 85 | + ! check the initial x bounds of the grid cell |
| 86 | + if (.not. (x >= 0._wp .and. x <= ib_airfoil(airfoil_id)%c)) return |
| 87 | + |
| 88 | + ! if we are in 3D, we must also check the z axis |
| 89 | + if (num_dims == 3 .and. (.not. (-0.5_wp*length <= z .and. 0.5_wp*length >= z))) return |
| 90 | + |
| 91 | + ! our check branches for the upper and lower half of the airfoil |
| 92 | + if (y >= 0._wp) then |
| 93 | + ! increment the iterator so we know where in the airfoil arrays to look |
| 94 | + k = 1 |
| 95 | + do while (ib_airfoil_grids(airfoil_id)%upper(k)%x < x) |
| 96 | + k = k + 1 |
| 97 | + end do |
| 98 | + |
| 99 | + ! If the values are approximately equivalent, skip the next check |
| 100 | + if (f_approx_equal(ib_airfoil_grids(airfoil_id)%upper(k)%x, x)) then |
| 101 | + if (y <= ib_airfoil_grids(airfoil_id)%upper(k)%y) is_inside = .true. |
| 102 | + else |
| 103 | + ! check if the y value is below the upper edge of the airfoil |
| 104 | + f = (ib_airfoil_grids(airfoil_id)%upper(k)%x - x)/(ib_airfoil_grids(airfoil_id)%upper(k)%x & |
| 105 | + & - ib_airfoil_grids(airfoil_id)%upper(k - 1)%x) |
| 106 | + if (y <= ((1._wp - f)*ib_airfoil_grids(airfoil_id)%upper(k)%y + f*ib_airfoil_grids(airfoil_id)%upper(k - 1)%y)) & |
| 107 | + & is_inside = .true. |
| 108 | + end if |
| 109 | + else |
| 110 | + ! increment the iterator so we know where in the airfoil arrays to look |
| 111 | + k = 1 |
| 112 | + do while (ib_airfoil_grids(airfoil_id)%lower(k)%x < x) |
| 113 | + k = k + 1 |
| 114 | + end do |
| 115 | + |
| 116 | + ! If the values are approximately equivalent, skip the next check |
| 117 | + if (f_approx_equal(ib_airfoil_grids(airfoil_id)%lower(k)%x, x)) then |
| 118 | + if (y >= ib_airfoil_grids(airfoil_id)%lower(k)%y) is_inside = .true. |
| 119 | + else |
| 120 | + ! check if the y value is above the lower edge of the airfoil |
| 121 | + f = (ib_airfoil_grids(airfoil_id)%lower(k)%x - x)/(ib_airfoil_grids(airfoil_id)%lower(k)%x & |
| 122 | + & - ib_airfoil_grids(airfoil_id)%lower(k - 1)%x) |
| 123 | + if (y >= ((1._wp - f)*ib_airfoil_grids(airfoil_id)%lower(k)%y + f*ib_airfoil_grids(airfoil_id)%lower(k - 1)%y)) & |
| 124 | + & is_inside = .true. |
| 125 | + end if |
| 126 | + end if |
| 127 | + |
| 128 | + end function f_is_inside_airfoil |
| 129 | + |
| 130 | + function f_is_inside_ellipse(x, y, length) result(is_inside) |
| 131 | + |
| 132 | + $:GPU_ROUTINE(parallelism='[seq]') |
| 133 | + |
| 134 | + real(wp), intent(in) :: x, y |
| 135 | + real(wp), dimension(3), intent(in) :: length |
| 136 | + logical :: is_inside |
| 137 | + |
| 138 | + ! Ellipse condition (x/a)^2 + (y/b)^2 <= 1 |
| 139 | + is_inside = (x/(0.5_wp*length(1)))**2 + (y/(0.5_wp*length(2)))**2 <= 1._wp |
| 140 | + |
| 141 | + end function f_is_inside_ellipse |
| 142 | + |
| 143 | +end module m_patch_geometries |
0 commit comments