49 use json_module,
only : json_file, json_core, json_value
72 use mpi_f08,
only : mpi_allreduce, mpi_integer, mpi_max
74 viscous_regularization_factory
82 type(
field_t) :: rho_res, m_x_res, m_y_res, m_z_res, m_e_res
83 type(
field_t) :: drho, dm_x, dm_y, dm_z, de
85 class(
ax_t),
allocatable :: ax
86 class(
ax_t),
allocatable :: ax_stress
91 logical :: if_viscous_regularization
104 procedure, pass(this) :: setup_bcs &
117 module subroutine density_bc_factory(object, scheme, json, coef,
user)
118 class(
bc_t),
pointer,
intent(inout) :: object
119 type(fluid_scheme_compressible_ns_t),
intent(in) :: scheme
120 type(json_file),
intent(inout) :: json
121 type(
coef_t),
intent(in) :: coef
123 end subroutine density_bc_factory
134 module subroutine pressure_bc_factory(object, scheme, json, coef,
user)
135 class(
bc_t),
pointer,
intent(inout) :: object
136 type(fluid_scheme_compressible_ns_t),
intent(inout) :: scheme
137 type(json_file),
intent(inout) :: json
138 type(
coef_t),
intent(in) :: coef
140 end subroutine pressure_bc_factory
151 module subroutine velocity_bc_factory(object, scheme, json, coef,
user)
152 class(
bc_t),
pointer,
intent(inout) :: object
153 type(fluid_scheme_compressible_ns_t),
intent(in) :: scheme
154 type(json_file),
intent(inout) :: json
155 type(
coef_t),
intent(in) :: coef
157 end subroutine velocity_bc_factory
168 subroutine fluid_scheme_compressible_ns_init(this, msh, lx, params, user, &
170 class(fluid_scheme_compressible_ns_t),
target,
intent(inout) :: this
171 type(
mesh_t),
target,
intent(inout) :: msh
172 integer,
intent(in) :: lx
173 type(json_file),
target,
intent(inout) :: params
174 type(
user_t),
target,
intent(in) :: user
175 type(
chkp_t),
target,
intent(inout) :: chkp
176 character(len=12),
parameter :: scheme =
'compressible'
182 call this%scheme_init(msh, lx, params, scheme,
user)
184 call compressible_rhs_factory(this%compressible_rhs, this%gamma)
186 associate(xh_lx => this%Xh%lx, xh_ly => this%Xh%ly, xh_lz => this%Xh%lz, &
187 dm_xh => this%dm_Xh, nelv => this%msh%nelv)
189 call this%drho%init(dm_xh,
'drho')
190 call this%dm_x%init(dm_xh,
'dm_x')
191 call this%dm_y%init(dm_xh,
'dm_y')
192 call this%dm_z%init(dm_xh,
'dm_z')
193 call this%dE%init(dm_xh,
'dE')
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_allocator(this%Ax, type_name =
"standard")
225 call ax_helm_allocator(this%Ax_stress, type_name =
"full")
229 call this%bcs_vel_projector%init(this%c_Xh)
232 call this%setup_viscous_regularization(params)
235 call json_get_or_default(params,
'case.numerics.time_order', rk_order, 4)
236 call this%rk_scheme%init(rk_order)
238 call neko_log%section(
"Fluid boundary conditions")
240 call this%setup_bcs(
user, params)
241 call neko_log%end_section()
243 end subroutine fluid_scheme_compressible_ns_init
247 subroutine fluid_scheme_compressible_ns_free(this)
248 class(fluid_scheme_compressible_ns_t),
intent(inout) :: this
249 class(bc_t),
pointer :: bc
252 if (
allocated(this%Ax))
then
257 if (
allocated(this%Ax_stress))
then
258 call this%Ax_stress%free()
259 deallocate(this%Ax_stress)
262 call this%scheme_free()
264 if (
allocated(this%compressible_rhs))
then
265 deallocate(this%compressible_rhs)
268 call this%drho%free()
269 call this%dm_x%free()
270 call this%dm_y%free()
271 call this%dm_z%free()
274 if (
allocated(this%viscous_regularization))
then
275 call this%viscous_regularization%free()
276 deallocate(this%viscous_regularization)
279 do i = 1, this%bcs_density%size()
280 bc => this%bcs_density%get(i)
281 if (
associated(
bc))
then
286 call this%bcs_density%free()
287 call this%bcs_vel_projector%free()
289 end subroutine fluid_scheme_compressible_ns_free
296 subroutine fluid_scheme_compressible_ns_step(this, time, dt_controller)
297 class(fluid_scheme_compressible_ns_t),
target,
intent(inout) :: this
298 type(time_state_t),
intent(in) :: time
299 type(time_step_controller_t),
intent(in) :: dt_controller
300 type(field_t),
pointer :: temp
301 integer :: temp_indices(1)
305 class(bc_t),
pointer :: b
307 n = this%dm_Xh%size()
308 call neko_scratch_registry%request_field(temp, temp_indices(1), .false.)
311 call profiler_start_region(
'Fluid compressible', 1)
312 associate(u => this%u, v => this%v, w => this%w, p => this%p, &
313 m_x=> this%m_x, m_y => this%m_y, m_z => this%m_z, &
314 xh => this%Xh, msh => this%msh, ax => this%Ax, &
315 c_xh => this%c_Xh, dm_xh => this%dm_Xh, gs_xh => this%gs_Xh, &
316 e => this%E, rho => this%rho, &
317 f_x => this%f_x, f_y => this%f_y, f_z => this%f_z, &
318 drho => this%drho, dm_x => this%dm_x, dm_y => this%dm_y, &
319 dm_z => this%dm_z, de => this%dE, &
320 compressible_rhs => this%compressible_rhs, &
321 t => time%t, tstep => time%tstep, dt => time%dt, &
322 rk_scheme => this%rk_scheme)
325 if (
allocated(this%viscous_regularization))
then
326 call this%viscous_regularization%update(this%artificial_visc)
330 call this%update_material_properties(time)
333 call compressible_rhs%step(rho, m_x, m_y, m_z, e, &
334 p, u, v, w, this%Ax, &
335 this%Ax_stress, c_xh, gs_xh, this%artificial_visc, this%mu, &
336 this%kappa, this%bcs_vel, time, rk_scheme,
real(dt, kind=rp))
339 call this%bcs_density%apply(rho, time)
343 if (neko_bcknd_device .eq. 1)
then
344 call compressible_ops_device_update_uvw(u%x_d, v%x_d, w%x_d, &
345 m_x%x_d, m_y%x_d, m_z%x_d, rho%x_d, n)
347 call compressible_ops_cpu_update_uvw(u%x, v%x, w%x, &
348 m_x%x, m_y%x, m_z%x, rho%x, n)
352 call this%bcs_vel%apply_vector(u%x, v%x, w%x, &
353 dm_xh%size(), time, strong = .true.)
356 if (neko_bcknd_device .eq. 1)
then
357 call compressible_ops_device_update_mxyz_p_ruvw(m_x%x_d, m_y%x_d, &
358 m_z%x_d, p%x_d, temp%x_d, u%x_d, v%x_d, w%x_d, e%x_d, &
359 rho%x_d, this%gamma, n)
361 call compressible_ops_cpu_update_mxyz_p_ruvw(m_x%x, m_y%x, m_z%x, &
362 p%x, temp%x, u%x, v%x, w%x, e%x, rho%x, this%gamma, n)
366 call this%bcs_prs%apply(p, time)
370 if (neko_bcknd_device .eq. 1)
then
371 call compressible_ops_device_update_e(e%x_d, p%x_d, &
372 temp%x_d, this%gamma, n)
374 call compressible_ops_cpu_update_e(e%x, p%x, temp%x, this%gamma, n)
378 if (neko_bcknd_device .eq. 1)
then
379 call compressible_ops_device_update_temperature( &
380 this%temperature%x_d, p%x_d, rho%x_d, this%gamma, n)
388 this%temperature%x(i,1,1,1) = p%x(i,1,1,1) / &
389 (rho%x(i,1,1,1) * (this%gamma - 1.0_rp))
395 call this%compute_max_wave_speed()
397 do i = 1, this%bcs_vel%size()
398 b => this%bcs_vel%get(i)
402 do i = 1, this%bcs_prs%size()
403 b => this%bcs_prs%get(i)
407 do i = 1, this%bcs_density%size()
408 b => this%bcs_density%get(i)
414 call profiler_end_region(
'Fluid compressible', 1)
416 call neko_scratch_registry%relinquish_field(temp_indices)
418 end subroutine fluid_scheme_compressible_ns_step
424 subroutine fluid_scheme_compressible_ns_setup_bcs(this, user, params)
425 class(fluid_scheme_compressible_ns_t),
target,
intent(inout) :: this
426 type(user_t),
target,
intent(in) :: user
427 type(json_file),
intent(inout) :: params
428 integer :: i, n_bcs, zone_index, j, zone_size, global_zone_size, ierr
429 class(bc_t),
pointer :: bc_i
430 type(json_core) :: core
431 type(json_value),
pointer :: bc_object
432 type(json_file) :: bc_subdict
434 integer,
allocatable :: zone_indices(:)
435 character(len=LOG_SIZE) :: log_buf
438 if (params%valid_path(
'case.fluid.boundary_conditions'))
then
439 call params%info(
'case.fluid.boundary_conditions', n_children = n_bcs)
440 call params%get_core(core)
441 call params%get(
'case.fluid.boundary_conditions', bc_object, found)
446 call this%bcs_vel%init(n_bcs)
450 call json_extract_item(core, bc_object, i, bc_subdict)
451 call json_get(bc_subdict,
"zone_indices", zone_indices)
454 do j = 1,
size(zone_indices)
455 zone_size = this%msh%labeled_zones(zone_indices(j))%size
456 call mpi_allreduce(zone_size, global_zone_size, 1, &
457 mpi_integer, mpi_max, neko_comm, ierr)
459 if (global_zone_size .eq. 0)
then
460 write(log_buf,
'(A,I0,A)')
"Error: Zone ", zone_indices(j), &
462 call neko_error(log_buf)
468 call velocity_bc_factory(bc_i, this, bc_subdict, this%c_Xh,
user)
471 if (
associated(bc_i))
then
472 call this%bcs_vel_projector%mark(bc_i)
473 call this%bcs_vel%append(bc_i)
480 call this%bcs_prs%init(n_bcs)
484 call json_extract_item(core, bc_object, i, bc_subdict)
486 call pressure_bc_factory(bc_i, this, bc_subdict, this%c_Xh,
user)
490 if (
associated(bc_i))
then
491 call this%bcs_prs%append(bc_i)
498 call this%bcs_density%init(n_bcs)
502 call json_extract_item(core, bc_object, i, bc_subdict)
504 call density_bc_factory(bc_i, this, bc_subdict, this%c_Xh,
user)
508 if (
associated(bc_i))
then
509 call this%bcs_density%append(bc_i)
514 do i = 1,
size(this%msh%labeled_zones)
515 if (this%msh%labeled_zones(i)%size .gt. 0)
then
516 call neko_error(
"No boundary_conditions entry in the case file!")
522 call this%bcs_prs%init()
523 call this%bcs_vel%init()
524 call this%bcs_density%init()
528 call this%bcs_vel_projector%finalize(rebuild_mask = .true.)
529 end subroutine fluid_scheme_compressible_ns_setup_bcs
535 subroutine fluid_scheme_compressible_ns_restart(this, chkp)
536 class(fluid_scheme_compressible_ns_t),
target,
intent(inout) :: this
537 type(chkp_t),
intent(inout) :: chkp
538 end subroutine fluid_scheme_compressible_ns_restart
540 subroutine setup_viscous_regularization(this, params)
541 class(fluid_scheme_compressible_ns_t),
target,
intent(inout) :: this
542 type(json_file),
intent(inout) :: params
543 type(json_file) :: reg_json
545 character(len=:),
allocatable :: viscous_regularization_type
548 if (this%params%valid_path(
'case.fluid.viscous_regularization'))
then
549 call json_get(params,
'case.fluid.viscous_regularization', &
554 if (.not. found)
then
556 this%if_viscous_regularization = .false.
559 this%if_viscous_regularization = .true.
562 call json_get(reg_json,
'type', viscous_regularization_type)
563 call viscous_regularization_factory(this%viscous_regularization, &
564 viscous_regularization_type, &
565 reg_json, this%c_Xh, this%dm_Xh)
567 call reg_json%destroy()
569 if (
allocated(viscous_regularization_type)) &
570 deallocate(viscous_regularization_type)
572 end subroutine setup_viscous_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.
Defines format-independent checkpoint registration and restart state.
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.
Device abstraction, common interface for various accelerators.
integer, parameter, public host_to_device
Contains the field_serties_t type.
subroutine fluid_scheme_compressible_ns_restart(this, chkp)
Restart the simulation from saved state.
subroutine setup_viscous_regularization(this, params)
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.
Defines Gather-scatter operations.
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
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.
Implements boundary condition projectors for vector fields. Two types concrete types are provided: se...
Defines the base interface for viscous regularization methods.
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.
Collection of live simulation data registered for checkpointing.
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...
A coupled projector for vector fields, suitable for mixed boundary conditions.
Abstract type for resolving vector boundary conditions.
Base abstract type for viscous regularization methods.