51 use json_module,
only : json_file, json_core, json_value
72 use mpi_f08,
only : mpi_allreduce, mpi_integer, mpi_max
79 type(
field_t) :: rho_res, m_x_res, m_y_res, m_z_res, m_e_res
80 type(
field_t) :: drho, dm_x, dm_y, dm_z, de
82 real(kind=
rp) :: c_avisc_low
84 class(
ax_t),
allocatable :: ax
98 procedure, pass(this) :: setup_bcs &
112 module subroutine density_bc_factory(object, scheme, json, coef,
user)
113 class(
bc_t),
pointer,
intent(inout) :: object
114 type(fluid_scheme_compressible_euler_t),
intent(in) :: scheme
115 type(json_file),
intent(inout) :: json
116 type(
coef_t),
intent(in) :: coef
118 end subroutine density_bc_factory
129 module subroutine pressure_bc_factory(object, scheme, json, coef,
user)
130 class(
bc_t),
pointer,
intent(inout) :: object
131 type(fluid_scheme_compressible_euler_t),
intent(inout) :: scheme
132 type(json_file),
intent(inout) :: json
133 type(
coef_t),
intent(in) :: coef
135 end subroutine pressure_bc_factory
146 module subroutine velocity_bc_factory(object, scheme, json, coef,
user)
147 class(
bc_t),
pointer,
intent(inout) :: object
148 type(fluid_scheme_compressible_euler_t),
intent(in) :: scheme
149 type(json_file),
intent(inout) :: json
150 type(
coef_t),
intent(in) :: coef
152 end subroutine velocity_bc_factory
163 subroutine fluid_scheme_compressible_euler_init(this, msh, lx, params, user, &
165 class(fluid_scheme_compressible_euler_t),
target,
intent(inout) :: this
166 type(
mesh_t),
target,
intent(inout) :: msh
167 integer,
intent(in) :: lx
168 type(json_file),
target,
intent(inout) :: params
169 type(
user_t),
target,
intent(in) :: user
170 type(
chkp_t),
target,
intent(inout) :: chkp
171 character(len=12),
parameter :: scheme =
'compressible'
177 call this%scheme_init(msh, lx, params, scheme,
user)
179 call euler_rhs_factory(this%euler_rhs)
181 associate(xh_lx => this%Xh%lx, xh_ly => this%Xh%ly, xh_lz => this%Xh%lz, &
182 dm_xh => this%dm_Xh, nelv => this%msh%nelv)
184 call this%drho%init(dm_xh,
'drho')
185 call this%dm_x%init(dm_xh,
'dm_x')
186 call this%dm_y%init(dm_xh,
'dm_y')
187 call this%dm_z%init(dm_xh,
'dm_z')
188 call this%dE%init(dm_xh,
'dE')
189 call this%h%init(dm_xh,
'h')
194 associate(p => this%p, rho => this%rho, &
195 u => this%u, v => this%v, w => this%w, &
196 m_x => this%m_x, m_y => this%m_y, m_z => this%m_z, &
197 effective_visc => this%effective_visc)
220 call ax_helm_factory(this%Ax, full_formulation = .false.)
223 call this%compute_h()
226 call this%setup_regularization(params)
229 call json_get_or_default(params,
'case.numerics.time_order', rk_order, 4)
230 call this%rk_scheme%init(rk_order)
232 call neko_log%section(
"Fluid boundary conditions")
234 call this%setup_bcs(
user, params)
235 call neko_log%end_section()
237 end subroutine fluid_scheme_compressible_euler_init
241 subroutine fluid_scheme_compressible_euler_free(this)
242 class(fluid_scheme_compressible_euler_t),
intent(inout) :: this
244 call this%scheme_free()
246 if (
allocated(this%Ax))
then
250 if (
allocated(this%euler_rhs))
then
251 deallocate(this%euler_rhs)
254 call this%drho%free()
255 call this%dm_x%free()
256 call this%dm_y%free()
257 call this%dm_z%free()
261 if (
allocated(this%regularization))
then
262 call this%regularization%free()
263 deallocate(this%regularization)
266 call this%bcs_density%free()
268 end subroutine fluid_scheme_compressible_euler_free
275 subroutine fluid_scheme_compressible_euler_step(this, time, dt_controller)
277 class(fluid_scheme_compressible_euler_t),
target,
intent(inout) :: this
278 type(time_state_t),
intent(in) :: time
279 type(time_step_controller_t),
intent(in) :: dt_controller
280 type(field_t),
pointer :: temp
281 integer :: temp_indices(1)
285 class(bc_t),
pointer :: b
287 n = this%dm_Xh%size()
288 call neko_scratch_registry%request_field(temp, temp_indices(1), .false.)
291 call profiler_start_region(
'Fluid compressible', 1)
292 associate(u => this%u, v => this%v, w => this%w, p => this%p, &
293 m_x=> this%m_x, m_y => this%m_y, m_z => this%m_z, &
294 xh => this%Xh, msh => this%msh, ax => this%Ax, &
295 c_xh => this%c_Xh, dm_xh => this%dm_Xh, gs_xh => this%gs_Xh, &
296 e => this%E, rho => this%rho, mu => this%mu, &
297 f_x => this%f_x, f_y => this%f_y, f_z => this%f_z, &
298 drho => this%drho, dm_x => this%dm_x, dm_y => this%dm_y, &
299 dm_z => this%dm_z, de => this%dE, &
300 euler_rhs => this%euler_rhs, h => this%h, &
301 t => time%t, tstep => time%tstep, dt => time%dt, &
302 c_avisc_low => this%c_avisc_low, rk_scheme => this%rk_scheme)
305 call this%regularization%compute(time, time%tstep, time%dt)
308 call euler_rhs%step(rho, m_x, m_y, m_z, e, &
310 c_xh, gs_xh, h, this%effective_visc, &
314 call this%bcs_density%apply(rho, time)
318 if (neko_bcknd_device .eq. 1)
then
319 call compressible_ops_device_update_uvw(u%x_d, v%x_d, w%x_d, &
320 m_x%x_d, m_y%x_d, m_z%x_d, rho%x_d, n)
322 call compressible_ops_cpu_update_uvw(u%x, v%x, w%x, &
323 m_x%x, m_y%x, m_z%x, rho%x, n)
327 call this%bcs_vel%apply_vector(u%x, v%x, w%x, &
328 dm_xh%size(), time, strong = .true.)
331 if (neko_bcknd_device .eq. 1)
then
332 call compressible_ops_device_update_mxyz_p_ruvw(m_x%x_d, m_y%x_d, &
333 m_z%x_d, p%x_d, temp%x_d, u%x_d, v%x_d, w%x_d, e%x_d, &
334 rho%x_d, this%gamma, n)
336 call compressible_ops_cpu_update_mxyz_p_ruvw(m_x%x, m_y%x, m_z%x, &
337 p%x, temp%x, u%x, v%x, w%x, e%x, rho%x, this%gamma, n)
341 call this%bcs_prs%apply(p, time)
345 if (neko_bcknd_device .eq. 1)
then
346 call compressible_ops_device_update_e(e%x_d, p%x_d, &
347 temp%x_d, this%gamma, n)
349 call compressible_ops_cpu_update_e(e%x, p%x, temp%x, this%gamma, n)
354 call this%compute_entropy()
357 if (
allocated(this%regularization))
then
358 select type (reg => this%regularization)
360 call reg%update_lag()
365 call this%compute_max_wave_speed()
367 do i = 1, this%bcs_vel%size()
368 b => this%bcs_vel%get(i)
372 do i = 1, this%bcs_prs%size()
373 b => this%bcs_prs%get(i)
377 do i = 1, this%bcs_density%size()
378 b => this%bcs_density%get(i)
384 call profiler_end_region(
'Fluid compressible', 1)
386 call neko_scratch_registry%relinquish_field(temp_indices)
388 end subroutine fluid_scheme_compressible_euler_step
394 subroutine fluid_scheme_compressible_euler_setup_bcs(this, user, params)
395 class(fluid_scheme_compressible_euler_t),
target,
intent(inout) :: this
396 type(user_t),
target,
intent(in) :: user
397 type(json_file),
intent(inout) :: params
398 integer :: i, n_bcs, zone_index, j, zone_size, global_zone_size, ierr
399 class(bc_t),
pointer :: bc_i
400 type(json_core) :: core
401 type(json_value),
pointer :: bc_object
402 type(json_file) :: bc_subdict
404 integer,
allocatable :: zone_indices(:)
405 character(len=LOG_SIZE) :: log_buf
408 if (params%valid_path(
'case.fluid.boundary_conditions'))
then
409 call params%info(
'case.fluid.boundary_conditions', n_children = n_bcs)
410 call params%get_core(core)
411 call params%get(
'case.fluid.boundary_conditions', bc_object, found)
416 call this%bcs_vel%init(n_bcs)
420 call json_extract_item(core, bc_object, i, bc_subdict)
421 call json_get(bc_subdict,
"zone_indices", zone_indices)
424 do j = 1,
size(zone_indices)
425 zone_size = this%msh%labeled_zones(zone_indices(j))%size
426 call mpi_allreduce(zone_size, global_zone_size, 1, &
427 mpi_integer, mpi_max, neko_comm, ierr)
429 if (global_zone_size .eq. 0)
then
430 write(log_buf,
'(A,I0,A)')
"Error: Zone ", zone_indices(j), &
432 call neko_error(log_buf)
438 call velocity_bc_factory(bc_i, this, bc_subdict, this%c_Xh,
user)
441 if (
associated(bc_i))
then
442 call this%bcs_vel%append(bc_i)
449 call this%bcs_prs%init(n_bcs)
453 call json_extract_item(core, bc_object, i, bc_subdict)
455 call pressure_bc_factory(bc_i, this, bc_subdict, this%c_Xh,
user)
459 if (
associated(bc_i))
then
460 call this%bcs_prs%append(bc_i)
467 call this%bcs_density%init(n_bcs)
471 call json_extract_item(core, bc_object, i, bc_subdict)
473 call density_bc_factory(bc_i, this, bc_subdict, this%c_Xh,
user)
477 if (
associated(bc_i))
then
478 call this%bcs_density%append(bc_i)
483 do i = 1,
size(this%msh%labeled_zones)
484 if (this%msh%labeled_zones(i)%size .gt. 0)
then
485 call neko_error(
"No boundary_conditions entry in the case file!")
491 call this%bcs_prs%init()
492 call this%bcs_vel%init()
493 call this%bcs_density%init()
496 end subroutine fluid_scheme_compressible_euler_setup_bcs
502 subroutine compute_h(this)
503 class(fluid_scheme_compressible_euler_t),
intent(inout) :: this
504 integer :: lx, ly, lz
509 call compute_h_cpu(this%h%x, this%c_Xh%dof%x, this%c_Xh%dof%y, &
510 this%c_Xh%dof%z, lx, ly, lz, this%c_Xh%msh%nelv)
512 if (neko_bcknd_device .eq. 1)
then
513 call device_memcpy(this%h%x, this%h%x_d, this%h%dof%size(),&
514 host_to_device, sync = .false.)
515 call this%gs_Xh%op(this%h, gs_op_add)
516 call device_col2(this%h%x_d, this%c_Xh%mult_d, this%h%dof%size())
518 call this%gs_Xh%op(this%h, gs_op_add)
519 call col2(this%h%x, this%c_Xh%mult, this%h%dof%size())
522 end subroutine compute_h
524 subroutine compute_h_cpu(h, x, y, z, lx, ly, lz, nelv)
525 integer,
intent(in) :: lx, ly, lz, nelv
526 real(kind=rp),
intent(out) :: h(lx, ly, lz, nelv)
527 real(kind=rp),
intent(in) :: x(lx, ly, lz, nelv)
528 real(kind=rp),
intent(in) :: y(lx, ly, lz, nelv)
529 real(kind=rp),
intent(in) :: z(lx, ly, lz, nelv)
530 integer :: e, i, j, k
531 integer :: im, ip, jm, jp, km, kp
532 real(kind=rp) :: di, dj, dk
546 di = (x(ip, j, k, e) - x(im, j, k, e))**2 &
547 + (y(ip, j, k, e) - y(im, j, k, e))**2 &
548 + (z(ip, j, k, e) - z(im, j, k, e))**2
550 dj = (x(i, jp, k, e) - x(i, jm, k, e))**2 &
551 + (y(i, jp, k, e) - y(i, jm, k, e))**2 &
552 + (z(i, jp, k, e) - z(i, jm, k, e))**2
554 dk = (x(i, j, kp, e) - x(i, j, km, e))**2 &
555 + (y(i, j, kp, e) - y(i, j, km, e))**2 &
556 + (z(i, j, kp, e) - z(i, j, km, e))**2
558 di = sqrt(di) / (ip - im)
559 dj = sqrt(dj) / (jp - jm)
560 dk = sqrt(dk) / (kp - km)
561 h(i,j,k,e) = (di * dj * dk)**(1.0_rp / 3.0_rp)
567 end subroutine compute_h_cpu
573 subroutine fluid_scheme_compressible_euler_restart(this, chkp)
574 class(fluid_scheme_compressible_euler_t),
target,
intent(inout) :: this
575 type(chkp_t),
intent(inout) :: chkp
576 end subroutine fluid_scheme_compressible_euler_restart
578 subroutine setup_regularization(this, params)
581 class(fluid_scheme_compressible_euler_t),
target,
intent(inout) :: this
582 type(json_file),
intent(inout) :: params
583 type(json_file) :: reg_json
584 type(json_core) :: json_core_inst
585 type(json_value),
pointer :: reg_params
586 character(len=:),
allocatable :: buffer
587 real(kind=rp) :: c_avisc_entropy_val
588 character(len=:),
allocatable :: regularization_type
590 call json_get_or_default(params,
'case.numerics.c_avisc_low', &
591 this%c_avisc_low, 0.5_rp)
592 call json_get_or_default(params,
'case.numerics.c_avisc_entropy', &
593 c_avisc_entropy_val, 1.0_rp)
595 call json_core_inst%initialize()
596 call json_core_inst%create_object(reg_params,
'')
597 call json_core_inst%add(reg_params,
'c_avisc_entropy', c_avisc_entropy_val)
598 call json_core_inst%add(reg_params,
'c_avisc_low', this%c_avisc_low)
599 call json_core_inst%print_to_string(reg_params,
buffer)
600 call json_core_inst%destroy(reg_params)
602 call reg_json%initialize()
603 call reg_json%load_from_string(
buffer)
605 regularization_type =
'entropy_viscosity'
607 call regularization_factory(this%regularization, regularization_type, &
608 reg_json, this%c_Xh, this%dm_Xh, this%effective_visc)
610 select type (reg => this%regularization)
613 this%h, this%max_wave_speed, this%msh, this%Xh, this%gs_Xh)
616 call reg_json%destroy()
618 end subroutine setup_regularization
Copy data between host and device (or device and device)
Abstract interface to evaluate rhs.
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.
Compute the divergence of a vector field.
Apply cyclic boundary condition to a vector field.
Subroutines to add advection terms to the RHS of a transport equation.
Defines a Matrix-vector product.
Defines a boundary condition.
Backward-differencing scheme for time integration.
Generic buffer that is extended with buffers of varying rank.
type(mpi_comm), public neko_comm
MPI communicator.
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_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.
Device implementation of compressible flow operations.
subroutine, public compressible_ops_device_update_uvw(u_d, v_d, w_d, m_x_d, m_y_d, m_z_d, rho_d, n)
Update u,v,w fields.
subroutine, public compressible_ops_device_update_mxyz_p_ruvw(m_x_d, m_y_d, m_z_d, p_d, ruvw_d, u_d, v_d, w_d, e_d, rho_d, gamma, n)
Update m_x, m_y, m_z, p, ruvw, fields.
subroutine, public compressible_ops_device_update_e(e_d, p_d, ruvw_d, gamma, n)
Update E field.
subroutine, public device_col2(a_d, b_d, n, strm)
Vector multiplication .
Device abstraction, common interface for various accelerators.
integer, parameter, public host_to_device
subroutine, public entropy_viscosity_set_fields(this, s, u, v, w, h, max_wave_speed, msh, xh, gs)
Contains the field_serties_t type.
subroutine compute_h(this)
Copied from les_model_compute_delta in les_model.f90 TODO: move to a separate module Compute characte...
subroutine fluid_scheme_compressible_euler_init(this, msh, lx, params, user, chkp)
Boundary condition factory for density.
subroutine fluid_scheme_compressible_euler_step(this, time, dt_controller)
Advance the fluid simulation one timestep.
subroutine fluid_scheme_compressible_euler_free(this)
Free allocated memory and cleanup.
subroutine fluid_scheme_compressible_euler_restart(this, chkp)
Restart the simulation from saved state.
subroutine fluid_scheme_compressible_euler_setup_bcs(this, user, params)
Set up boundary conditions for the fluid scheme.
subroutine setup_regularization(this, params)
Defines Gather-scatter operations.
integer, parameter, public gs_op_add
integer, parameter, public gs_op_max
integer, parameter, public gs_op_min
Utilities for retrieving parameters from the case files.
type(log_t), public neko_log
Global log stream.
integer, parameter, public log_size
subroutine, public col2(a, b, n)
Vector multiplication .
integer, parameter neko_bcknd_device
integer, parameter, public rp
Global precision used in computations.
subroutine, public profiler_start_region(name, region_id)
Started a named (name) profiler region.
subroutine, public profiler_end_region(name, region_id)
End the most recently started profiler region.
Defines a registry for storing and requesting temporary objects This can be used when you have a func...
type(scratch_registry_t), target, public neko_scratch_registry
Global scratch registry.
Compound scheme for the advection and diffusion operators in a transport equation.
Module with things related to the simulation time.
Implements type time_step_controller.
Interfaces for user interaction with NEKO.
subroutine, public neko_type_error(base_type, wrong_type, known_types)
Reports an error allocating a type for a particular base pointer class.
Base abstract type for computing the advection operator.
Base type for a matrix-vector product providing .
Base type for a boundary condition.
A list of allocatable `bc_t`. Follows the standard interface of lists.
Implicit backward-differencing scheme for time integration.
Coefficients defined on a given (mesh, ) tuple. Arrays use indices (i,j,k,e): element e,...
Abstract type to compute rhs.
Stores a series (sequence) of fields, logically connected to a base field, and arranged according to ...
Base type of compressible fluid formulations.
Implements the logic to compute the time coefficients for the advection and diffusion operators in a ...
A struct that contains all info about the time, expand as needed.
Provides a tool to set time step dt.
A type collecting all the overridable user routines and flag to suppress type injection from custom m...