|
| 1 | +module m_base_backend |
| 2 | + use m_allocator, only: allocator_t, field_t |
| 3 | + use m_common, only: dp |
| 4 | + use m_tdsops, only: tdsops_t, dirps_t |
| 5 | + |
| 6 | + implicit none |
| 7 | + |
| 8 | + type, abstract :: base_backend_t |
| 9 | + !! base_backend class defines all the abstract operations that the |
| 10 | + !! solver class requires. |
| 11 | + !! |
| 12 | + !! For example, transport equation in solver class evaluates the |
| 13 | + !! derivatives in x, y, and z directions, and reorders the input |
| 14 | + !! fields as required. Then finally, combines all the directional |
| 15 | + !! derivatives to obtain the divergence of U*. |
| 16 | + !! |
| 17 | + !! All these high level operations solver class executes are |
| 18 | + !! defined here using the abstract interfaces. Every backend |
| 19 | + !! implementation extends the present abstact backend class to |
| 20 | + !! define the specifics of these operations based on the target |
| 21 | + !! architecture. |
| 22 | + |
| 23 | + real(dp) :: nu |
| 24 | + class(allocator_t), pointer :: allocator |
| 25 | + class(dirps_t), pointer :: xdirps, ydirps, zdirps |
| 26 | + contains |
| 27 | + procedure(transeq_ders), deferred :: transeq_x |
| 28 | + procedure(transeq_ders), deferred :: transeq_y |
| 29 | + procedure(transeq_ders), deferred :: transeq_z |
| 30 | + procedure(transposer), deferred :: trans_x2y |
| 31 | + procedure(transposer), deferred :: trans_x2z |
| 32 | + procedure(sum9into3), deferred :: sum_yzintox |
| 33 | + procedure(get_fields), deferred :: get_fields |
| 34 | + procedure(set_fields), deferred :: set_fields |
| 35 | + procedure(alloc_tdsops), deferred :: alloc_tdsops |
| 36 | + end type base_backend_t |
| 37 | + |
| 38 | + abstract interface |
| 39 | + subroutine transeq_ders(self, du, dv, dw, u, v, w, dirps) |
| 40 | + !! transeq equation obtains the derivatives direction by |
| 41 | + !! direction, and the exact algorithm used to obtain these |
| 42 | + !! derivatives are decided at runtime. Backend implementations |
| 43 | + !! are responsible from directing calls to transeq_ders into |
| 44 | + !! the correct algorithm. |
| 45 | + import :: base_backend_t |
| 46 | + import :: field_t |
| 47 | + import :: dirps_t |
| 48 | + implicit none |
| 49 | + |
| 50 | + class(base_backend_t) :: self |
| 51 | + class(field_t), intent(inout) :: du, dv, dw |
| 52 | + class(field_t), intent(in) :: u, v, w |
| 53 | + type(dirps_t), intent(in) :: dirps |
| 54 | + end subroutine transeq_ders |
| 55 | + end interface |
| 56 | + |
| 57 | + abstract interface |
| 58 | + subroutine transposer(self, u_, v_, w_, u, v, w) |
| 59 | + !! transposer subroutines are straightforward, they rearrange |
| 60 | + !! data into our specialist data structure so that regardless |
| 61 | + !! of the direction tridiagonal systems are solved efficiently |
| 62 | + !! and fast. |
| 63 | + import :: base_backend_t |
| 64 | + import :: field_t |
| 65 | + implicit none |
| 66 | + |
| 67 | + class(base_backend_t) :: self |
| 68 | + class(field_t), intent(inout) :: u_, v_, w_ |
| 69 | + class(field_t), intent(in) :: u, v, w |
| 70 | + end subroutine transposer |
| 71 | + end interface |
| 72 | + |
| 73 | + abstract interface |
| 74 | + subroutine sum9into3(self, du, dv, dw, du_y, dv_y, dw_y, du_z, dv_z, dw_z) |
| 75 | + !! sum9into3 subroutine combines all the directional velocity |
| 76 | + !! derivatives into the corresponding x directional fields. |
| 77 | + import :: base_backend_t |
| 78 | + import :: field_t |
| 79 | + implicit none |
| 80 | + |
| 81 | + class(base_backend_t) :: self |
| 82 | + class(field_t), intent(inout) :: du, dv, dw |
| 83 | + class(field_t), intent(in) :: du_y, dv_y, dw_y, du_z, dv_z, dw_z |
| 84 | + end subroutine sum9into3 |
| 85 | + end interface |
| 86 | + |
| 87 | + abstract interface |
| 88 | + subroutine get_fields(self, u_out, v_out, w_out, u, v, w) |
| 89 | + !! copy the specialist data structure from device or host back |
| 90 | + !! to a regular 3D data structure. |
| 91 | + import :: base_backend_t |
| 92 | + import :: dp |
| 93 | + import :: field_t |
| 94 | + implicit none |
| 95 | + |
| 96 | + class(base_backend_t) :: self |
| 97 | + real(dp), dimension(:, :, :), intent(out) :: u_out, v_out, w_out |
| 98 | + class(field_t), intent(in) :: u, v, w |
| 99 | + end subroutine get_fields |
| 100 | + |
| 101 | + subroutine set_fields(self, u, v, w, u_in, v_in, w_in) |
| 102 | + !! copy the initial condition stored in a regular 3D data |
| 103 | + !! structure into the specialist data structure arrays on the |
| 104 | + !! device or host. |
| 105 | + import :: base_backend_t |
| 106 | + import :: dp |
| 107 | + import :: field_t |
| 108 | + implicit none |
| 109 | + |
| 110 | + class(base_backend_t) :: self |
| 111 | + class(field_t), intent(inout) :: u, v, w |
| 112 | + real(dp), dimension(:, :, :), intent(in) :: u_in, v_in, w_in |
| 113 | + end subroutine set_fields |
| 114 | + end interface |
| 115 | + |
| 116 | + abstract interface |
| 117 | + subroutine alloc_tdsops(self, tdsops, n, dx, operation, scheme) |
| 118 | + import :: base_backend_t |
| 119 | + import :: dp |
| 120 | + import :: tdsops_t |
| 121 | + implicit none |
| 122 | + |
| 123 | + class(base_backend_t) :: self |
| 124 | + class(tdsops_t), allocatable, intent(inout) :: tdsops |
| 125 | + integer, intent(in) :: n |
| 126 | + real(dp), intent(in) :: dx |
| 127 | + character(*), intent(in) :: operation, scheme |
| 128 | + end subroutine alloc_tdsops |
| 129 | + end interface |
| 130 | + |
| 131 | +end module m_base_backend |
0 commit comments