Neko 1.99.6
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
compressible_ops_cpu.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 implicit none
37 private
38
42
43
44contains
45
48 u, v, w, gamma, p, rho, n)
49 integer, intent(in) :: n
50 real(kind=rp), intent(in) :: gamma
51 real(kind=rp), dimension(n), intent(in) :: u, v, w, p, rho
52 real(kind=rp), dimension(n), intent(inout) :: max_wave_speed
53 integer :: i
54 real(kind=rp) :: vel_mag, sound_speed
55
56 ! Compute maximum wave speed:
57 ! |u| + c = sqrt(u^2 + v^2 + w^2) + sqrt(gamma * p / rho)
58 !OCL NORECURRENCE, NOVREC, NOALIAS
59 !DIR$ CONCURRENT
60 !DIR$ IVDEP
61 !GCC$ ivdep
62 !$omp parallel do simd private(vel_mag, sound_speed)
63 do i = 1, n
64 vel_mag = sqrt(u(i)*u(i) + v(i)*v(i) + &
65 w(i)*w(i))
66 sound_speed = sqrt(gamma * p(i) / rho(i))
67 max_wave_speed(i) = vel_mag + sound_speed
68 end do
69 !$omp end parallel do simd
70
72
75 subroutine compressible_ops_cpu_compute_entropy(S, p, rho, gamma, n)
76 integer, intent(in) :: n
77 real(kind=rp), intent(in) :: gamma
78 real(kind=rp), dimension(n), intent(in) :: p, rho
79 real(kind=rp), dimension(n), intent(inout) :: s
80 integer :: i
81 real(kind=rp) :: inv_gamma_m1
82
83 inv_gamma_m1 = 1.0_rp / (gamma - 1.0_rp)
84
85 ! Compute entropy: S = 1/(gamma-1) * rho * (log(p) - gamma * log(rho))
86 !OCL NORECURRENCE, NOVREC, NOALIAS
87 !DIR$ CONCURRENT
88 !DIR$ IVDEP
89 !GCC$ ivdep
90 !$omp parallel do simd
91 do i = 1, n
92 s(i) = inv_gamma_m1 * rho(i) * &
93 (log(p(i)) - gamma * log(rho(i)))
94 end do
95 !$omp end parallel do simd
96
98
100 subroutine compressible_ops_cpu_update_uvw(u, v, w, m_x, m_y, m_z, rho, n)
101 integer, intent(in) :: n
102 real(kind=rp), dimension(n), intent(inout) :: u, v, w
103 real(kind=rp), dimension(n), intent(in) :: m_x, m_y, m_z, rho
104 integer :: i
105
106 !OCL NORECURRENCE, NOVREC, NOALIAS
107 !DIR$ CONCURRENT
108 !DIR$ IVDEP
109 !GCC$ ivdep
110 !$omp parallel do simd
111 do i = 1, n
112 u(i) = m_x(i) / rho(i)
113 v(i) = m_y(i) / rho(i)
114 w(i) = m_z(i) / rho(i)
115 end do
116 !$omp end parallel do simd
117
119
121 subroutine compressible_ops_cpu_update_mxyz_p_ruvw(m_x, m_y, m_z, p, ruvw, &
122 u, v, w, E, rho, gamma, n)
123 integer, intent(in) :: n
124 real(kind=rp), dimension(n), intent(inout) :: m_x, m_y, m_z, p, ruvw
125 real(kind=rp), dimension(n), intent(in) :: u, v, w, e, rho
126 real(kind=rp), intent(in) :: gamma
127 real(kind=rp) :: tmp
128 integer :: i
129
130 !OCL NORECURRENCE, NOVREC, NOALIAS
131 !DIR$ CONCURRENT
132 !DIR$ IVDEP
133 !GCC$ ivdep
134 !$omp parallel do simd private(tmp)
135 do i = 1, n
136 m_x(i) = u(i) * rho(i)
137 m_y(i) = v(i) * rho(i)
138 m_z(i) = w(i) * rho(i)
139 tmp = 0.5_rp * rho(i) * (u(i)**2 + v(i)**2 + w(i)**2)
140 p(i) = (gamma - 1.0_rp) * (e(i) - tmp)
141 ruvw(i) = tmp
142 end do
143 !$omp end parallel do simd
144
146
148 subroutine compressible_ops_cpu_update_e(E, p, ruvw, gamma, n)
149 integer, intent(in) :: n
150 real(kind=rp), dimension(n), intent(inout) :: e, p
151 ! ruvw = 0.5 * rho * (u^2 + v^2 + w^2)
152 real(kind=rp), dimension(n), intent(in) :: ruvw
153 real(kind=rp), intent(in) :: gamma
154 integer :: i
155 real(kind=rp) :: inv_gamma_m1
156
157 inv_gamma_m1 = 1.0_rp / (gamma - 1.0_rp)
158
159 !OCL NORECURRENCE, NOVREC, NOALIAS
160 !DIR$ CONCURRENT
161 !DIR$ IVDEP
162 !GCC$ ivdep
163 !$omp parallel do simd
164 do i = 1, n
165 ! Ensure pressure is positive
166 p(i) = max(p(i), 1.0e-12_rp)
167 ! E = p / (gamma - 1) + 0.5 * rho * (u^2 + v^2 + w^2)
168 e(i) = p(i) * inv_gamma_m1 + ruvw(i)
169 end do
170 !$omp end parallel do simd
171 end subroutine compressible_ops_cpu_update_e
172
173end module compressible_ops_cpu
CPU implementation of compressible flow operations.
subroutine, public compressible_ops_cpu_update_uvw(u, v, w, m_x, m_y, m_z, rho, n)
Update u,v,w fields.
subroutine, public compressible_ops_cpu_update_e(e, p, ruvw, gamma, n)
Update E field.
subroutine, public compressible_ops_cpu_compute_entropy(s, p, rho, gamma, n)
Compute entropy field S = 1/(gamma-1) * rho * (log(p) - gamma * log(rho)) on CPU.
subroutine, public compressible_ops_cpu_compute_max_wave_speed(max_wave_speed, u, v, w, gamma, p, rho, n)
Compute maximum wave speed for compressible flows on CPU.
subroutine, public compressible_ops_cpu_update_mxyz_p_ruvw(m_x, m_y, m_z, p, ruvw, u, v, w, e, rho, gamma, n)
Update m_x, m_y, m_z, p, ruvw, fields.
integer, parameter, public rp
Global precision used in computations.
Definition num_types.f90:12
#define max(a, b)
Definition tensor.cu:40