39 use json_module,
only : json_file
45 use,
intrinsic :: iso_c_binding, only : c_ptr, c_null_ptr
51 "rst",
"rs",
"rt",
"st",
"r",
"s",
"t"]
53 [character(len=10) :: &
54 "one-sided",
"factorized"]
66 character(len=:),
allocatable :: direction
68 character(len=:),
allocatable :: formulation
70 character(len=:),
allocatable :: kernel_type
72 type(
coef_t),
pointer :: coef => null()
74 real(kind=
rp),
allocatable :: h1(:,:,:,:)
75 type(c_ptr) :: h1_d = c_null_ptr
77 real(kind=
rp),
allocatable :: ident(:,:)
78 type(c_ptr) :: ident_d = c_null_ptr
80 real(kind=
rp),
allocatable :: br(:,:), bs(:,:), bt(:,:)
81 type(c_ptr) :: br_d = c_null_ptr
82 type(c_ptr) :: bs_d = c_null_ptr
83 type(c_ptr) :: bt_d = c_null_ptr
85 character(len=:),
allocatable :: nue_field_name
88 logical :: tvar_h1 = .false.
103 class(
svv_t),
intent(inout) :: this
104 type(json_file),
intent(inout) :: json
105 type(
coef_t),
intent(in),
target :: coef
106 type(
field_t),
intent(in) :: rho
107 real(kind=
rp),
allocatable :: transfer(:)
108 real(kind=
rp) :: nu_val, power_coef, exponent_factor
109 character(len=:),
allocatable :: nu_type, direction, formulation
119 this%formulation = trim(formulation)
126 this%direction = trim(direction)
132 allocate(transfer(lx))
134 call json_get(json,
"svv.kernel.type", this%kernel_type)
135 select case (trim(this%kernel_type))
138 if (power_coef .eq. 0.0_rp)
then
141 if (this%formulation .eq.
"factorized")
then
142 exponent_factor = 0.5_rp
144 exponent_factor = 1.0_rp
147 transfer(i) = 1.0_rp - ((i - 1.0_rp) / (lx - 1.0_rp)) ** &
148 (exponent_factor * (lx - 1.0_rp) * power_coef)
156 call this%filter%init_from_components(coef,
"nonBoyd", transfer)
159 allocate(this%ident(lx, lx))
162 this%ident(i, i) = 1.0_rp
165 if (this%formulation .eq.
"factorized")
then
169 allocate(this%h1(lx, lx, lx, coef%msh%nelv))
171 call device_map(this%ident, this%ident_d, lx * lx)
174 call device_map(this%h1, this%h1_d, coef%dof%size())
177 call rzero(this%h1, coef%dof%size())
180 call json_get(json,
"svv.nu.type", nu_type)
181 select case (trim(nu_type))
186 call device_col2(this%h1_d, rho%x_d, coef%dof%size())
188 call cfill(this%h1, nu_val, coef%dof%size())
189 call col2(this%h1, rho%x, coef%dof%size())
193 this%tvar_h1, .true.)
194 call json_get(json,
"svv.nu.field_name", this%nue_field_name)
198 else if (.not. this%tvar_h1)
then
199 call neko_error(
"The static SVV viscosity field `" // &
200 this%nue_field_name //
"` does not exist")
203 call neko_error(
"Invalid svv.nu.type: " // trim(nu_type))
206 if (
allocated(nu_type))
deallocate(nu_type)
207 if (
allocated(direction))
deallocate(direction)
208 if (
allocated(formulation))
deallocate(formulation)
214 class(
svv_t),
intent(inout) :: this
215 real(kind=
rp),
allocatable :: complementary_filter(:,:)
219 allocate(complementary_filter(lx, lx))
220 allocate(this%Br(lx, lx), this%Bs(lx, lx), this%Bt(lx, lx))
222 complementary_filter = this%ident - this%filter%fh
226 if (index(this%direction,
"r") > 0)
then
227 this%Br = matmul(complementary_filter, this%coef%Xh%dx)
229 if (index(this%direction,
"s") > 0)
then
230 this%Bs = matmul(complementary_filter, this%coef%Xh%dy)
232 if (index(this%direction,
"t") > 0)
then
233 this%Bt = matmul(complementary_filter, this%coef%Xh%dz)
248 deallocate(complementary_filter)
256 class(
svv_t),
intent(inout) :: this
257 type(
field_t),
intent(in) :: rho
258 integer,
intent(in) :: tstep
260 if (.not. this%tvar_h1)
return
261 if (.not.
associated(this%nue))
then
262 if (.not.
neko_registry%field_exists(this%nue_field_name))
then
263 call neko_error(
"The SVV viscosity field `" // &
264 this%nue_field_name //
"` does not exist at time step " // &
276 class(
svv_t),
intent(inout) :: this
277 type(
field_t),
intent(in) :: rho
280 call device_copy(this%h1_d, this%nue%x_d, this%coef%dof%size())
281 call device_col2(this%h1_d, rho%x_d, this%coef%dof%size())
283 call copy(this%h1, this%nue%x, this%coef%dof%size())
284 call col2(this%h1, rho%x, this%coef%dof%size())
291 class(
svv_t),
intent(inout) :: this
293 call this%filter%free()
294 if (
allocated(this%h1))
then
300 if (
allocated(this%ident))
then
304 deallocate(this%ident)
306 if (
allocated(this%Br))
then
310 if (
allocated(this%Bs))
then
314 if (
allocated(this%Bt))
then
318 if (
allocated(this%direction))
deallocate(this%direction)
319 if (
allocated(this%formulation))
deallocate(this%formulation)
320 if (
allocated(this%kernel_type))
deallocate(this%kernel_type)
321 if (
allocated(this%nue_field_name))
deallocate(this%nue_field_name)
324 this%h1_d = c_null_ptr
325 this%ident_d = c_null_ptr
326 this%Br_d = c_null_ptr
327 this%Bs_d = c_null_ptr
328 this%Bt_d = c_null_ptr
329 this%tvar_h1 = .false.
335 integer,
intent(in) :: value
336 character(len=32) :: string
337 write(string,
'(I0)')
value
Map a Fortran array to a device (allocate and associate).
Copy data between host and device (or device and device).
Unmap a Fortran array from a device (deassociate and free).
Retrieves a parameter by name or assigns a provided default value. In the latter case also adds the m...
Retrieves a parameter by name or throws an error.
subroutine, public device_rzero(a_d, n, strm)
Zero a real vector.
subroutine, public device_copy(a_d, b_d, n, strm)
Copy a vector .
subroutine, public device_col2(a_d, b_d, n, strm)
Vector multiplication .
subroutine, public device_cfill(a_d, c, n, strm)
Set all elements to a constant c .
Device abstraction, common interface for various accelerators.
integer, parameter, public host_to_device
Implements elementwise_filter_t.
Filter to be applied to a scalar field.
Utilities for retrieving parameters from the case files.
subroutine, public cfill(a, c, n)
Set all elements to a constant c .
subroutine, public col2(a, b, n)
Vector multiplication .
subroutine, public copy(a, b, n)
Copy a vector .
subroutine, public rzero(a, n)
Zero a real vector.
integer, parameter neko_bcknd_device
integer, parameter, public rp
Global precision used in computations.
Defines a registry for storing solution fields.
type(registry_t), target, public neko_registry
Global field registry.
Data and filter construction for spectral vanishing viscosity.
subroutine svv_free(this)
Release all resources owned by an SVV object.
subroutine svv_update_h1(this, rho, tstep)
Update a time-varying, field-valued SVV viscosity.
subroutine svv_copy_viscosity(this, rho)
Copy the configured viscosity field and multiply it by density.
subroutine svv_build_complementary_derivatives(this)
Build the complementary derivative matrices used by factorized SVV.
subroutine svv_init_from_json(this, json, coef, rho)
Construct an SVV object from case parameters.
character(len=10), dimension(2), parameter known_formulations
character(len=5), dimension(1), parameter known_kernel_types
character(len=5), dimension(2), parameter known_nu_types
character(len=3), dimension(7), parameter known_directions
character(len=32) function to_string(value)
Convert an integer to a compact string.
subroutine, public neko_type_error(base_type, wrong_type, known_types)
Reports an error allocating a type for a particular base pointer class.
Coefficients defined on a given (mesh, ) tuple. Arrays use indices (i,j,k,e): element e,...
Implements the elementwise filter for SEM.
Spectral vanishing viscosity configuration and coefficients.