Neko  0.8.1
A portable framework for high-order spectral element flow simulations
filters_cpu.f90
Go to the documentation of this file.
1 ! Copyright (c) 2024, 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 
38 contains
39 
40  ! ========================================================================== !
41  ! Internal functions and subroutines
42  ! ========================================================================== !
43 
45  elemental function smooth_step_cpu(x, edge0, edge1) result(res)
46  real(kind=rp), intent(in) :: x
47  real(kind=rp), intent(in) :: edge0, edge1
48  real(kind=rp) :: res, t
49 
50  t = clamp_cpu((x - edge0) / (edge1 - edge0), 0.0_rp, 1.0_rp)
51 
52  res = t**3 * (t * (6.0_rp * t - 15.0_rp) + 10.0_rp)
53 
54  end function smooth_step_cpu
55 
57  elemental function clamp_cpu(x, lowerlimit, upperlimit) result(res)
58  real(kind=rp), intent(in) :: x
59  real(kind=rp), intent(in) :: lowerlimit, upperlimit
60  real(kind=rp) :: res
61 
62  res = max(lowerlimit, min(upperlimit, x))
63  end function clamp_cpu
64 
66  elemental function step_function_cpu(x, x_step, value0, value1) result(res)
67  real(kind=rp), intent(in) :: x, x_step, value0, value1
68  real(kind=rp) :: res
69 
70  res = merge(value0, value1, x > x_step)
71 
72  end function step_function_cpu
73 
75  elemental function permeability_cpu(x, k_0, k_1, q) result(perm)
76  real(kind=rp), intent(in) :: x, k_0, k_1, q
77  real(kind=rp) :: perm
78 
79  perm = k_0 + (k_1 - k_0) * x * (q + 1.0_rp) / (q + x)
80 
81  end function permeability_cpu
82 
83 
84 end module filters_cpu
CPU implementations of the filter functions.
Definition: filters_cpu.f90:34
elemental real(kind=rp) function smooth_step_cpu(x, edge0, edge1)
Apply a smooth step function to a scalar.
Definition: filters_cpu.f90:46
elemental real(kind=rp) function clamp_cpu(x, lowerlimit, upperlimit)
Clamp a value between two limits.
Definition: filters_cpu.f90:58
elemental real(kind=rp) function permeability_cpu(x, k_0, k_1, q)
Apply a permeability function to a scalar.
Definition: filters_cpu.f90:76
elemental real(kind=rp) function step_function_cpu(x, x_step, value0, value1)
Apply a step function to a scalar.
Definition: filters_cpu.f90:67
integer, parameter, public rp
Global precision used in computations.
Definition: num_types.f90:12
#define max(a, b)
Definition: tensor.cu:40