51 use json_module,
only : json_file, json_core, json_value
74 use mpi_f08,
only : mpi_allreduce, mpi_integer, mpi_max
81 type(
field_t) :: rho_res, m_x_res, m_y_res, m_z_res, m_e_res
82 type(
field_t) :: drho, dm_x, dm_y, dm_z, de
84 real(kind=
rp) :: c_avisc_low
86 class(
ax_t),
allocatable :: ax
87 class(
ax_t),
allocatable :: ax_stress
102 procedure, pass(this) :: setup_bcs &
116 module subroutine density_bc_factory(object, scheme, json, coef,
user)
117 class(
bc_t),
pointer,
intent(inout) :: object
118 type(fluid_scheme_compressible_ns_t),
intent(in) :: scheme
119 type(json_file),
intent(inout) :: json
120 type(
coef_t),
intent(in) :: coef
122 end subroutine density_bc_factory
133 module subroutine pressure_bc_factory(object, scheme, json, coef,
user)
134 class(
bc_t),
pointer,
intent(inout) :: object
135 type(fluid_scheme_compressible_ns_t),
intent(inout) :: scheme
136 type(json_file),
intent(inout) :: json
137 type(
coef_t),
intent(in) :: coef
139 end subroutine pressure_bc_factory
150 module subroutine velocity_bc_factory(object, scheme, json, coef,
user)
151 class(
bc_t),
pointer,
intent(inout) :: object
152 type(fluid_scheme_compressible_ns_t),
intent(in) :: scheme
153 type(json_file),
intent(inout) :: json
154 type(
coef_t),
intent(in) :: coef
156 end subroutine velocity_bc_factory
167 subroutine fluid_scheme_compressible_ns_init(this, msh, lx, params, user, &
169 class(fluid_scheme_compressible_ns_t),
target,
intent(inout) :: this
170 type(
mesh_t),
target,
intent(inout) :: msh
171 integer,
intent(in) :: lx
172 type(json_file),
target,
intent(inout) :: params
173 type(
user_t),
target,
intent(in) :: user
174 type(
chkp_t),
target,
intent(inout) :: chkp
175 character(len=12),
parameter :: scheme =
'compressible'
181 call this%scheme_init(msh, lx, params, scheme,
user)
183 call compressible_rhs_factory(this%compressible_rhs, this%gamma)
185 associate(xh_lx => this%Xh%lx, xh_ly => this%Xh%ly, xh_lz => this%Xh%lz, &
186 dm_xh => this%dm_Xh, nelv => this%msh%nelv)
188 call this%drho%init(dm_xh,
'drho')
189 call this%dm_x%init(dm_xh,
'dm_x')
190 call this%dm_y%init(dm_xh,
'dm_y')
191 call this%dm_z%init(dm_xh,
'dm_z')
192 call this%dE%init(dm_xh,
'dE')
193 call this%h%init(dm_xh,
'h')
198 associate(p => this%p, rho => this%rho, &
199 u => this%u, v => this%v, w => this%w, &
200 m_x => this%m_x, m_y => this%m_y, m_z => this%m_z, &
201 artificial_visc => this%artificial_visc)
224 call ax_helm_factory(this%Ax, full_formulation = .false.)
225 call ax_helm_factory(this%Ax_stress, full_formulation = .true.)
228 call this%compute_h()
231 call this%setup_regularization(params)
234 call json_get_or_default(params,
'case.numerics.time_order', rk_order, 4)
235 call this%rk_scheme%init(rk_order)
237 call neko_log%section(
"Fluid boundary conditions")
239 call this%setup_bcs(
user, params)
240 call neko_log%end_section()
242 end subroutine fluid_scheme_compressible_ns_init
246 subroutine fluid_scheme_compressible_ns_free(this)
247 class(fluid_scheme_compressible_ns_t),
intent(inout) :: this
248 class(bc_t),
pointer :: bc
251 call this%scheme_free()
253 if (
allocated(this%Ax))
then
257 if (
allocated(this%Ax_stress))
then
258 deallocate(this%Ax_stress)
261 if (
allocated(this%compressible_rhs))
then
262 deallocate(this%compressible_rhs)
265 call this%drho%free()
266 call this%dm_x%free()
267 call this%dm_y%free()
268 call this%dm_z%free()
272 if (
allocated(this%regularization))
then
273 call this%regularization%free()
274 deallocate(this%regularization)
277 do i = 1, this%bcs_density%size()
278 bc => this%bcs_density%get(i)
279 if (
associated(
bc))
then
284 call this%bcs_density%free()
286 end subroutine fluid_scheme_compressible_ns_free
293 subroutine fluid_scheme_compressible_ns_step(this, time, dt_controller)
295 class(fluid_scheme_compressible_ns_t),
target,
intent(inout) :: this
296 type(time_state_t),
intent(in) :: time
297 type(time_step_controller_t),
intent(in) :: dt_controller
298 type(field_t),
pointer :: temp
299 integer :: temp_indices(1)
303 class(bc_t),
pointer :: b
305 n = this%dm_Xh%size()
306 call neko_scratch_registry%request_field(temp, temp_indices(1), .false.)
309 call profiler_start_region(
'Fluid compressible', 1)
310 associate(u => this%u, v => this%v, w => this%w, p => this%p, &
311 m_x=> this%m_x, m_y => this%m_y, m_z => this%m_z, &
312 xh => this%Xh, msh => this%msh, ax => this%Ax, &
313 c_xh => this%c_Xh, dm_xh => this%dm_Xh, gs_xh => this%gs_Xh, &
314 e => this%E, rho => this%rho, mu => this%mu, &
315 f_x => this%f_x, f_y => this%f_y, f_z => this%f_z, &
316 drho => this%drho, dm_x => this%dm_x, dm_y => this%dm_y, &
317 dm_z => this%dm_z, de => this%dE, &
318 compressible_rhs => this%compressible_rhs, h => this%h, &
319 t => time%t, tstep => time%tstep, dt => time%dt, &
320 c_avisc_low => this%c_avisc_low, rk_scheme => this%rk_scheme)
323 call this%regularization%compute(time, time%tstep, time%dt)
326 call this%update_material_properties(time)
329 call compressible_rhs%step(rho, m_x, m_y, m_z, e, &
330 p, u, v, w, this%Ax, &
331 this%Ax_stress, c_xh, gs_xh, h, this%artificial_visc, this%mu, &
332 this%kappa, this%bcs_vel, time, rk_scheme, dt)
335 call this%bcs_density%apply(rho, time)
339 if (neko_bcknd_device .eq. 1)
then
340 call compressible_ops_device_update_uvw(u%x_d, v%x_d, w%x_d, &
341 m_x%x_d, m_y%x_d, m_z%x_d, rho%x_d, n)
343 call compressible_ops_cpu_update_uvw(u%x, v%x, w%x, &
344 m_x%x, m_y%x, m_z%x, rho%x, n)
348 call this%bcs_vel%apply_vector(u%x, v%x, w%x, &
349 dm_xh%size(), time, strong = .true.)
352 if (neko_bcknd_device .eq. 1)
then
353 call compressible_ops_device_update_mxyz_p_ruvw(m_x%x_d, m_y%x_d, &
354 m_z%x_d, p%x_d, temp%x_d, u%x_d, v%x_d, w%x_d, e%x_d, &
355 rho%x_d, this%gamma, n)
357 call compressible_ops_cpu_update_mxyz_p_ruvw(m_x%x, m_y%x, m_z%x, &
358 p%x, temp%x, u%x, v%x, w%x, e%x, rho%x, this%gamma, n)
362 call this%bcs_prs%apply(p, time)
366 if (neko_bcknd_device .eq. 1)
then
367 call compressible_ops_device_update_e(e%x_d, p%x_d, &
368 temp%x_d, this%gamma, n)
370 call compressible_ops_cpu_update_e(e%x, p%x, temp%x, this%gamma, n)
374 if (neko_bcknd_device .eq. 1)
then
375 call compressible_ops_device_update_temperature( &
376 this%temperature%x_d, p%x_d, rho%x_d, this%gamma, n)
384 this%temperature%x(i,1,1,1) = p%x(i,1,1,1) / &
385 (rho%x(i,1,1,1) * (this%gamma - 1.0_rp))
393 if (
allocated(this%regularization))
then
394 select type (reg => this%regularization)
396 call reg%update_lag()
401 call this%compute_entropy()
404 call this%compute_max_wave_speed()
406 do i = 1, this%bcs_vel%size()
407 b => this%bcs_vel%get(i)
411 do i = 1, this%bcs_prs%size()
412 b => this%bcs_prs%get(i)
416 do i = 1, this%bcs_density%size()
417 b => this%bcs_density%get(i)
423 call profiler_end_region(
'Fluid compressible', 1)
425 call neko_scratch_registry%relinquish_field(temp_indices)
427 end subroutine fluid_scheme_compressible_ns_step
433 subroutine fluid_scheme_compressible_ns_setup_bcs(this, user, params)
434 class(fluid_scheme_compressible_ns_t),
target,
intent(inout) :: this
435 type(user_t),
target,
intent(in) :: user
436 type(json_file),
intent(inout) :: params
437 integer :: i, n_bcs, zone_index, j, zone_size, global_zone_size, ierr
438 class(bc_t),
pointer :: bc_i
439 type(json_core) :: core
440 type(json_value),
pointer :: bc_object
441 type(json_file) :: bc_subdict
443 integer,
allocatable :: zone_indices(:)
444 character(len=LOG_SIZE) :: log_buf
447 if (params%valid_path(
'case.fluid.boundary_conditions'))
then
448 call params%info(
'case.fluid.boundary_conditions', n_children = n_bcs)
449 call params%get_core(core)
450 call params%get(
'case.fluid.boundary_conditions', bc_object, found)
455 call this%bcs_vel%init(n_bcs)
459 call json_extract_item(core, bc_object, i, bc_subdict)
460 call json_get(bc_subdict,
"zone_indices", zone_indices)
463 do j = 1,
size(zone_indices)
464 zone_size = this%msh%labeled_zones(zone_indices(j))%size
465 call mpi_allreduce(zone_size, global_zone_size, 1, &
466 mpi_integer, mpi_max, neko_comm, ierr)
468 if (global_zone_size .eq. 0)
then
469 write(log_buf,
'(A,I0,A)')
"Error: Zone ", zone_indices(j), &
471 call neko_error(log_buf)
477 call velocity_bc_factory(bc_i, this, bc_subdict, this%c_Xh,
user)
480 if (
associated(bc_i))
then
481 call this%bcs_vel%append(bc_i)
488 call this%bcs_prs%init(n_bcs)
492 call json_extract_item(core, bc_object, i, bc_subdict)
494 call pressure_bc_factory(bc_i, this, bc_subdict, this%c_Xh,
user)
498 if (
associated(bc_i))
then
499 call this%bcs_prs%append(bc_i)
506 call this%bcs_density%init(n_bcs)
510 call json_extract_item(core, bc_object, i, bc_subdict)
512 call density_bc_factory(bc_i, this, bc_subdict, this%c_Xh,
user)
516 if (
associated(bc_i))
then
517 call this%bcs_density%append(bc_i)
522 do i = 1,
size(this%msh%labeled_zones)
523 if (this%msh%labeled_zones(i)%size .gt. 0)
then
524 call neko_error(
"No boundary_conditions entry in the case file!")
530 call this%bcs_prs%init()
531 call this%bcs_vel%init()
532 call this%bcs_density%init()
535 end subroutine fluid_scheme_compressible_ns_setup_bcs
541 subroutine compute_h(this)
542 class(fluid_scheme_compressible_ns_t),
intent(inout) :: this
543 integer :: lx, ly, lz
548 call compute_h_cpu(this%h%x, this%c_Xh%dof%x, this%c_Xh%dof%y, &
549 this%c_Xh%dof%z, lx, ly, lz, this%c_Xh%msh%nelv)
551 if (neko_bcknd_device .eq. 1)
then
552 call device_memcpy(this%h%x, this%h%x_d, this%h%dof%size(),&
553 host_to_device, sync = .false.)
554 call this%gs_Xh%op(this%h, gs_op_add)
555 call device_col2(this%h%x_d, this%c_Xh%mult_d, this%h%dof%size())
557 call this%gs_Xh%op(this%h, gs_op_add)
558 call col2(this%h%x, this%c_Xh%mult, this%h%dof%size())
561 end subroutine compute_h
563 subroutine compute_h_cpu(h, x, y, z, lx, ly, lz, nelv)
564 integer,
intent(in) :: lx, ly, lz, nelv
565 real(kind=rp),
intent(out) :: h(lx, ly, lz, nelv)
566 real(kind=rp),
intent(in) :: x(lx, ly, lz, nelv)
567 real(kind=rp),
intent(in) :: y(lx, ly, lz, nelv)
568 real(kind=rp),
intent(in) :: z(lx, ly, lz, nelv)
569 integer :: e, i, j, k
570 integer :: im, ip, jm, jp, km, kp
571 real(kind=rp) :: di, dj, dk
585 di = (x(ip, j, k, e) - x(im, j, k, e))**2 &
586 + (y(ip, j, k, e) - y(im, j, k, e))**2 &
587 + (z(ip, j, k, e) - z(im, j, k, e))**2
589 dj = (x(i, jp, k, e) - x(i, jm, k, e))**2 &
590 + (y(i, jp, k, e) - y(i, jm, k, e))**2 &
591 + (z(i, jp, k, e) - z(i, jm, k, e))**2
593 dk = (x(i, j, kp, e) - x(i, j, km, e))**2 &
594 + (y(i, j, kp, e) - y(i, j, km, e))**2 &
595 + (z(i, j, kp, e) - z(i, j, km, e))**2
597 di = sqrt(di) / (ip - im)
598 dj = sqrt(dj) / (jp - jm)
599 dk = sqrt(dk) / (kp - km)
600 h(i,j,k,e) = (di * dj * dk)**(1.0_rp / 3.0_rp)
606 end subroutine compute_h_cpu
612 subroutine fluid_scheme_compressible_ns_restart(this, chkp)
613 class(fluid_scheme_compressible_ns_t),
target,
intent(inout) :: this
614 type(chkp_t),
intent(inout) :: chkp
615 end subroutine fluid_scheme_compressible_ns_restart
617 subroutine setup_regularization(this, params)
620 class(fluid_scheme_compressible_ns_t),
target,
intent(inout) :: this
621 type(json_file),
intent(inout) :: params
622 type(json_file) :: reg_json
623 type(json_core) :: json_core_inst
624 type(json_value),
pointer :: reg_params
625 character(len=:),
allocatable :: buffer
626 real(kind=rp) :: c_avisc_entropy_val
627 character(len=:),
allocatable :: regularization_type
629 call json_get_or_default(params,
'case.numerics.c_avisc_low', &
630 this%c_avisc_low, 0.5_rp)
631 call json_get_or_default(params,
'case.numerics.c_avisc_entropy', &
632 c_avisc_entropy_val, 1.0_rp)
634 call json_core_inst%initialize()
635 call json_core_inst%create_object(reg_params,
'')
636 call json_core_inst%add(reg_params,
'c_avisc_entropy', c_avisc_entropy_val)
637 call json_core_inst%add(reg_params,
'c_avisc_low', this%c_avisc_low)
638 call json_core_inst%print_to_string(reg_params,
buffer)
639 call json_core_inst%destroy(reg_params)
641 call reg_json%initialize()
642 call reg_json%load_from_string(
buffer)
644 regularization_type =
'entropy_viscosity'
646 call regularization_factory(this%regularization, regularization_type, &
647 reg_json, this%c_Xh, this%dm_Xh, this%artificial_visc)
649 select type (reg => this%regularization)
652 this%h, this%max_wave_speed, this%msh, this%Xh, this%gs_Xh)
655 call reg_json%destroy()
657 end subroutine setup_regularization
Abstract interface to evaluate rhs.
Copy data between host and device (or device and device)
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_temperature(t_d, p_d, rho_d, gamma, n)
Update temperature field.
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_ns_restart(this, chkp)
Restart the simulation from saved state.
subroutine fluid_scheme_compressible_ns_step(this, time, dt_controller)
Advance the fluid simulation one timestep.
subroutine fluid_scheme_compressible_ns_free(this)
Free allocated memory and cleanup.
subroutine fluid_scheme_compressible_ns_init(this, msh, lx, params, user, chkp)
Boundary condition factory for density.
subroutine fluid_scheme_compressible_ns_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...