Neko 1.99.6
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
runge_kutta_scheme.f90
Go to the documentation of this file.
1! Copyright (c) 2025, The Neko Authors
2! All rights reserved.
3!
4! Redistribution and use in source and binary forms, with or without
5! modification, are permitted provided that the following conditions
6! are met:
7!
8! * Redistributions of source code must retain the above copyright
9! notice, this list of conditions and the following disclaimer.
10!
11! * Redistributions in binary form must reproduce the above
12! copyright notice, this list of conditions and the following
13! disclaimer in the documentation and/or other materials provided
14! with the distribution.
15!
16! * Neither the name of the authors nor the names of its
17! contributors may be used to endorse or promote products derived
18! from this software without specific prior written permission.
19!
20! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21! "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22! LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23! FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24! COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25! INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26! BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27! LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28! CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29! LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30! ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31! POSSIBILITY OF SUCH DAMAGE.
32!
35 use num_types, only : rp
36 use time_scheme, only : time_scheme_t
37 use math, only : rzero
38 use utils, only : neko_error
40 use, intrinsic :: iso_c_binding, only : c_ptr, c_associated, c_null_ptr
41 implicit none
42 private
43
45 real(kind=rp), allocatable :: coeffs_a(:, :)
46 real(kind=rp), allocatable :: coeffs_b(:)
47 real(kind=rp), allocatable :: coeffs_c(:)
48 type(c_ptr) :: coeffs_a_d = c_null_ptr
49 type(c_ptr) :: coeffs_b_d = c_null_ptr
50 type(c_ptr) :: coeffs_c_d = c_null_ptr
51 integer :: order
52 contains
54 procedure, pass(this) :: init => runge_kutta_scheme_coeffs_init
56 procedure, pass(this) :: free => runge_kutta_scheme_coeffs_free
58
59contains
67 subroutine runge_kutta_scheme_coeffs_init(this, order)
68 class(runge_kutta_time_scheme_t), intent(inout) :: this
69 integer, intent(in) :: order
70 integer :: s
71
72 call this%free()
73
74 ! Assume number of stages is equal to the order
75 s = order
76 this%order = order
77 allocate(this%coeffs_A(order, order))
78 allocate(this%coeffs_b(order))
79 allocate(this%coeffs_c(order))
80
81 associate( &
82 coeffs_a => this%coeffs_A, &
83 coeffs_b => this%coeffs_b, &
84 coeffs_c => this%coeffs_c, &
85 coeffs_a_d => this%coeffs_A_d, &
86 coeffs_b_d => this%coeffs_b_d, &
87 coeffs_c_d => this%coeffs_c_d)
88
89 if (neko_bcknd_device .eq. 1) then
90 call device_map(coeffs_a, coeffs_a_d, s)
91 call device_map(coeffs_b, coeffs_b_d, s)
92 call device_map(coeffs_c, coeffs_c_d, s)
93 end if
94
95 select case (order)
96 case (1)
98 coeffs_a(1, 1) = 0.0_rp
99 coeffs_b(1) = 1.0_rp
100 coeffs_c(1) = 0.0_rp
101 case (2)
103 coeffs_a = 0.0_rp
104 coeffs_a(2, 1) = 1.0_rp
105
106 coeffs_b(1) = 0.5_rp
107 coeffs_b(2) = 0.5_rp
108
109 coeffs_c(1) = 0.0_rp
110 coeffs_c(2) = 1.0_rp
111 case (3)
113 coeffs_a = 0.0_rp
114 coeffs_a(2, 1) = 1.0_rp
115 coeffs_a(3, 1) = 0.25_rp
116 coeffs_a(3, 2) = 0.25_rp
117
118 coeffs_b(1) = 1.0_rp / 6.0_rp
119 coeffs_b(2) = 1.0_rp / 6.0_rp
120 coeffs_b(3) = 2.0_rp / 3.0_rp
121
122 coeffs_c(1) = 0.0_rp
123 coeffs_c(2) = 1.0_rp
124 coeffs_c(3) = 0.5_rp
125 case (4)
127 coeffs_a = 0.0_rp
128 coeffs_a(2, 1) = 0.5_rp
129 coeffs_a(3, 2) = 0.5_rp
130 coeffs_a(4, 3) = 1.0_rp
131
132 coeffs_b(1) = 1.0_rp / 6.0_rp
133 coeffs_b(2) = 1.0_rp / 3.0_rp
134 coeffs_b(3) = 1.0_rp / 3.0_rp
135 coeffs_b(4) = 1.0_rp / 6.0_rp
136
137 coeffs_c(1) = 0.0_rp
138 coeffs_c(2) = 0.5_rp
139 coeffs_c(3) = 0.5_rp
140 coeffs_c(4) = 1.0_rp
141 case default
142 call neko_error("The time order must be 1 to 4.")
143 end select
144
145 if (c_associated(coeffs_a_d)) then
146 call device_memcpy(coeffs_a, coeffs_a_d, s, &
147 host_to_device, sync = .false.)
148 end if
149
150 if (c_associated(coeffs_b_d)) then
151 call device_memcpy(coeffs_b, coeffs_b_d, s, &
152 host_to_device, sync = .false.)
153 end if
154
155 if (c_associated(coeffs_c_d)) then
156 call device_memcpy(coeffs_c, coeffs_c_d, s, &
157 host_to_device, sync = .false.)
158 end if
159 end associate
160
161 end subroutine runge_kutta_scheme_coeffs_init
162
166 implicit none
167 class(runge_kutta_time_scheme_t) :: this
168
169 if (allocated(this%coeffs_A)) then
170 if (neko_bcknd_device .eq. 1) then
171 call device_unmap(this%coeffs_A, this%coeffs_A_d)
172 end if
173 deallocate(this%coeffs_A)
174 end if
175 if (allocated(this%coeffs_b)) then
176 if (neko_bcknd_device .eq. 1) then
177 call device_unmap(this%coeffs_b, this%coeffs_b_d)
178 end if
179 deallocate(this%coeffs_b)
180 end if
181 if (allocated(this%coeffs_c)) then
182 if (neko_bcknd_device .eq. 1) then
183 call device_unmap(this%coeffs_c, this%coeffs_c_d)
184 end if
185 deallocate(this%coeffs_c)
186 end if
187 end subroutine runge_kutta_scheme_coeffs_free
188
Map a Fortran array to a device (allocate and associate)
Definition device.F90:78
Copy data between host and device (or device and device)
Definition device.F90:72
Unmap a Fortran array from a device (deassociate and free)
Definition device.F90:84
Device abstraction, common interface for various accelerators.
Definition device.F90:34
integer, parameter, public host_to_device
Definition device.F90:48
Definition math.f90:60
subroutine, public rzero(a, n)
Zero a real vector.
Definition math.f90:235
Build configurations.
integer, parameter neko_bcknd_device
integer, parameter, public rp
Global precision used in computations.
Definition num_types.f90:12
subroutine runge_kutta_scheme_coeffs_free(this)
Destructor - deallocates device memory.
subroutine runge_kutta_scheme_coeffs_init(this, order)
Constructor for Runge-Kutta time scheme.
Base class for time integration schemes.
Utilities.
Definition utils.f90:35
Base abstract class for time integration schemes.