Neko  0.9.99
A portable framework for high-order spectral element flow simulations
vreman_cpu.f90
Go to the documentation of this file.
1 ! Copyright (c) 2023-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 !
34 module vreman_cpu
35  use num_types, only : rp
36  use field_list, only : field_list_t
37  use math, only : cadd, neko_eps
40  use field, only : field_t
41  use operators, only : dudxyz
42  use coefs, only : coef_t
43  use gs_ops, only : gs_op_add
44  implicit none
45  private
46 
47  public :: vreman_compute_cpu
48 
49 contains
50 
58  subroutine vreman_compute_cpu(t, tstep, coef, nut, delta, c)
59  real(kind=rp), intent(in) :: t
60  integer, intent(in) :: tstep
61  type(coef_t), intent(in) :: coef
62  type(field_t), intent(inout) :: nut
63  type(field_t), intent(in) :: delta
64  real(kind=rp), intent(in) :: c
65  ! This is the alpha tensor in the paper
66  type(field_t), pointer :: a11, a12, a13, a21, a22, a23, a31, a32, a33
67  type(field_t), pointer :: u, v, w
68 
69  real(kind=rp) :: beta11
70  real(kind=rp) :: beta12
71  real(kind=rp) :: beta13
72  real(kind=rp) :: beta22
73  real(kind=rp) :: beta23
74  real(kind=rp) :: beta33
75  real(kind=rp) :: b_beta
76  real(kind=rp) :: aijaij
77  integer :: temp_indices(9)
78  integer :: e, i
79 
80  u => neko_field_registry%get_field_by_name("u")
81  v => neko_field_registry%get_field_by_name("v")
82  w => neko_field_registry%get_field_by_name("w")
83 
84  call neko_scratch_registry%request_field(a11, temp_indices(1))
85  call neko_scratch_registry%request_field(a12, temp_indices(2))
86  call neko_scratch_registry%request_field(a13, temp_indices(3))
87  call neko_scratch_registry%request_field(a21, temp_indices(4))
88  call neko_scratch_registry%request_field(a22, temp_indices(5))
89  call neko_scratch_registry%request_field(a23, temp_indices(6))
90  call neko_scratch_registry%request_field(a31, temp_indices(7))
91  call neko_scratch_registry%request_field(a32, temp_indices(8))
92  call neko_scratch_registry%request_field(a33, temp_indices(9))
93 
94 
95  ! Compute the derivatives of the velocity (the alpha tensor)
96  call dudxyz (a11%x, u%x, coef%drdx, coef%dsdx, coef%dtdx, coef)
97  call dudxyz (a12%x, u%x, coef%drdy, coef%dsdy, coef%dtdy, coef)
98  call dudxyz (a13%x, u%x, coef%drdz, coef%dsdz, coef%dtdz, coef)
99 
100  call dudxyz (a21%x, v%x, coef%drdx, coef%dsdx, coef%dtdx, coef)
101  call dudxyz (a22%x, v%x, coef%drdy, coef%dsdy, coef%dtdy, coef)
102  call dudxyz (a23%x, v%x, coef%drdz, coef%dsdz, coef%dtdz, coef)
103 
104  call dudxyz (a31%x, w%x, coef%drdx, coef%dsdx, coef%dtdx, coef)
105  call dudxyz (a32%x, w%x, coef%drdy, coef%dsdy, coef%dtdy, coef)
106  call dudxyz (a33%x, w%x, coef%drdz, coef%dsdz, coef%dtdz, coef)
107 
108  call coef%gs_h%op(a11, gs_op_add)
109  call coef%gs_h%op(a12, gs_op_add)
110  call coef%gs_h%op(a13, gs_op_add)
111  call coef%gs_h%op(a21, gs_op_add)
112  call coef%gs_h%op(a22, gs_op_add)
113  call coef%gs_h%op(a23, gs_op_add)
114  call coef%gs_h%op(a31, gs_op_add)
115  call coef%gs_h%op(a32, gs_op_add)
116  call coef%gs_h%op(a33, gs_op_add)
117 
118  do concurrent(i = 1:a11%dof%size())
119  a11%x(i,1,1,1) = a11%x(i,1,1,1) * coef%mult(i,1,1,1)
120  a12%x(i,1,1,1) = a12%x(i,1,1,1) * coef%mult(i,1,1,1)
121  a13%x(i,1,1,1) = a13%x(i,1,1,1) * coef%mult(i,1,1,1)
122  a21%x(i,1,1,1) = a21%x(i,1,1,1) * coef%mult(i,1,1,1)
123  a22%x(i,1,1,1) = a22%x(i,1,1,1) * coef%mult(i,1,1,1)
124  a23%x(i,1,1,1) = a23%x(i,1,1,1) * coef%mult(i,1,1,1)
125  a31%x(i,1,1,1) = a31%x(i,1,1,1) * coef%mult(i,1,1,1)
126  a32%x(i,1,1,1) = a32%x(i,1,1,1) * coef%mult(i,1,1,1)
127  a33%x(i,1,1,1) = a33%x(i,1,1,1) * coef%mult(i,1,1,1)
128  end do
129 
130  do concurrent(e = 1:coef%msh%nelv)
131  do concurrent(i = 1:coef%Xh%lxyz)
132  ! beta_ij = alpha_mi alpha_mj
133  beta11 = a11%x(i,1,1,e)**2 + a21%x(i,1,1,e)**2 + a31%x(i,1,1,e)**2
134  beta22 = a12%x(i,1,1,e)**2 + a22%x(i,1,1,e)**2 + a32%x(i,1,1,e)**2
135  beta33 = a13%x(i,1,1,e)**2 + a23%x(i,1,1,e)**2 + a33%x(i,1,1,e)**2
136  beta12 = a11%x(i,1,1,e)*a12%x(i,1,1,e) + &
137  a21%x(i,1,1,e)*a22%x(i,1,1,e) + &
138  a31%x(i,1,1,e)*a32%x(i,1,1,e)
139  beta13 = a11%x(i,1,1,e)*a13%x(i,1,1,e) + &
140  a21%x(i,1,1,e)*a23%x(i,1,1,e) + &
141  a31%x(i,1,1,e)*a33%x(i,1,1,e)
142  beta23 = a12%x(i,1,1,e)*a13%x(i,1,1,e) + &
143  a22%x(i,1,1,e)*a23%x(i,1,1,e) + &
144  a32%x(i,1,1,e)*a33%x(i,1,1,e)
145 
146  b_beta = beta11*beta22 - beta12*beta12 + beta11*beta33 - beta13*beta13 &
147  + beta22*beta33 - beta23*beta23
148 
149  b_beta = max(0.0_rp, b_beta)
150 
151  ! alpha_ij alpha_ij
152  aijaij = beta11 + beta22 + beta33
153 
154  nut%x(i,1,1,e) = c*delta%x(i,1,1,e)*delta%x(i,1,1,e) &
155  * sqrt(b_beta/(aijaij + neko_eps))
156  end do
157  end do
158 
159  call neko_scratch_registry%relinquish_field(temp_indices)
160  end subroutine vreman_compute_cpu
161 
162 end module vreman_cpu
163 
Coefficients.
Definition: coef.f90:34
Defines a registry for storing solution fields.
type(field_registry_t), target, public neko_field_registry
Global field registry.
Defines a field.
Definition: field.f90:34
Defines Gather-scatter operations.
Definition: gs_ops.f90:34
integer, parameter, public gs_op_add
Definition: gs_ops.f90:36
Definition: math.f90:60
subroutine, public cadd(a, s, n)
Add a scalar to vector .
Definition: math.f90:323
real(kind=rp), parameter, public neko_eps
Machine epsilon .
Definition: math.f90:70
integer, parameter, public rp
Global precision used in computations.
Definition: num_types.f90:12
Operators.
Definition: operators.f90:34
subroutine, public dudxyz(du, u, dr, ds, dt, coef)
Compute derivative of a scalar field along a single direction.
Definition: operators.f90:76
Defines a registry for storing and requesting temporary fields This can be used when you have a funct...
type(scratch_registry_t), target, public neko_scratch_registry
Global scratch registry.
Implements the CPU kernel for the vreman_t type.
Definition: vreman_cpu.f90:34
subroutine, public vreman_compute_cpu(t, tstep, coef, nut, delta, c)
Compute eddy viscosity on the CPU.
Definition: vreman_cpu.f90:59
Coefficients defined on a given (mesh, ) tuple. Arrays use indices (i,j,k,e): element e,...
Definition: coef.f90:55
field_list_t, To be able to group fields together
Definition: field_list.f90:13
#define max(a, b)
Definition: tensor.cu:40