48 use json_module,
only : json_file, json_core, json_value
63 use mpi_f08,
only : mpi_allreduce, mpi_integer, mpi_max
69 type(
field_t) :: rho_res, m_x_res, m_y_res, m_z_res, m_e_res
70 type(
field_t) :: drho, dm_x, dm_y, dm_z, de
72 real(kind=
rp) :: c_avisc_low
74 class(
ax_t),
allocatable :: ax
86 procedure, pass(this) :: setup_bcs &
99 module subroutine density_bc_factory(object, scheme, json, coef,
user)
100 class(
bc_t),
pointer,
intent(inout) :: object
101 type(fluid_scheme_compressible_euler_t),
intent(in) :: scheme
102 type(json_file),
intent(inout) :: json
103 type(
coef_t),
intent(in) :: coef
105 end subroutine density_bc_factory
116 module subroutine pressure_bc_factory(object, scheme, json, coef,
user)
117 class(
bc_t),
pointer,
intent(inout) :: object
118 type(fluid_scheme_compressible_euler_t),
intent(inout) :: scheme
119 type(json_file),
intent(inout) :: json
120 type(
coef_t),
intent(in) :: coef
122 end subroutine pressure_bc_factory
133 module subroutine velocity_bc_factory(object, scheme, json, coef,
user)
134 class(
bc_t),
pointer,
intent(inout) :: object
135 type(fluid_scheme_compressible_euler_t),
intent(in) :: scheme
136 type(json_file),
intent(inout) :: json
137 type(
coef_t),
intent(in) :: coef
139 end subroutine velocity_bc_factory
150 subroutine fluid_scheme_compressible_euler_init(this, msh, lx, params, user, &
152 class(fluid_scheme_compressible_euler_t),
target,
intent(inout) :: this
153 type(
mesh_t),
target,
intent(inout) :: msh
154 integer,
intent(in) :: lx
155 type(json_file),
target,
intent(inout) :: params
156 type(
user_t),
target,
intent(in) :: user
157 type(
chkp_t),
target,
intent(inout) :: chkp
158 character(len=12),
parameter :: scheme =
'compressible'
164 call this%scheme_init(msh, lx, params, scheme,
user)
166 call euler_rhs_factory(this%euler_rhs)
168 associate(xh_lx => this%Xh%lx, xh_ly => this%Xh%ly, xh_lz => this%Xh%lz, &
169 dm_xh => this%dm_Xh, nelv => this%msh%nelv)
171 call this%drho%init(dm_xh,
'drho')
172 call this%dm_x%init(dm_xh,
'dm_x')
173 call this%dm_y%init(dm_xh,
'dm_y')
174 call this%dm_z%init(dm_xh,
'dm_z')
175 call this%dE%init(dm_xh,
'dE')
176 call this%h%init(dm_xh,
'h')
181 associate(p => this%p, rho => this%rho, &
182 u => this%u, v => this%v, w => this%w, &
183 m_x => this%m_x, m_y => this%m_y, m_z => this%m_z)
204 call ax_helm_factory(this%Ax, full_formulation = .false.)
207 call this%compute_h()
208 call json_get_or_default(params,
'case.numerics.c_avisc_low', &
209 this%c_avisc_low, 0.5_rp)
212 call json_get_or_default(params,
'case.numerics.time_order', rk_order, 4)
213 call this%rk_scheme%init(rk_order)
216 call this%setup_bcs(
user, params)
218 end subroutine fluid_scheme_compressible_euler_init
222 subroutine fluid_scheme_compressible_euler_free(this)
223 class(fluid_scheme_compressible_euler_t),
intent(inout) :: this
225 call this%scheme_free()
227 if (
allocated(this%Ax))
then
231 call this%drho%free()
232 call this%dm_x%free()
233 call this%dm_y%free()
234 call this%dm_z%free()
238 end subroutine fluid_scheme_compressible_euler_free
245 subroutine fluid_scheme_compressible_euler_step(this, time, dt_controller)
246 class(fluid_scheme_compressible_euler_t),
target,
intent(inout) :: this
247 type(time_state_t),
intent(in) :: time
248 type(time_step_controller_t),
intent(in) :: dt_controller
249 type(field_t),
pointer :: temp
250 integer :: temp_indices(1)
254 class(bc_t),
pointer :: b
256 n = this%dm_Xh%size()
257 call this%scratch%request_field(temp, temp_indices(1))
260 call profiler_start_region(
'Fluid compressible', 1)
261 associate(u => this%u, v => this%v, w => this%w, p => this%p, &
262 m_x=> this%m_x, m_y => this%m_y, m_z => this%m_z, &
263 xh => this%Xh, msh => this%msh, ax => this%Ax, &
264 c_xh => this%c_Xh, dm_xh => this%dm_Xh, gs_xh => this%gs_Xh, &
265 e => this%E, rho => this%rho, mu => this%mu, &
266 f_x => this%f_x, f_y => this%f_y, f_z => this%f_z, &
267 drho => this%drho, dm_x => this%dm_x, dm_y => this%dm_y, &
268 dm_z => this%dm_z, de => this%dE, &
269 euler_rhs => this%euler_rhs, h => this%h, &
270 t => time%t, tstep => time%tstep, dt => time%dt, &
271 ext_bdf => this%ext_bdf, &
272 c_avisc_low => this%c_avisc_low, rk_scheme => this%rk_scheme)
274 call euler_rhs%step(rho, m_x, m_y, m_z, e, &
276 c_xh, gs_xh, h, c_avisc_low, &
280 call this%bcs_density%apply(rho, time)
284 call field_copy(u, m_x, n)
285 call field_invcol2(u, rho, n)
286 call field_copy(v, m_y, n)
287 call field_invcol2(v, rho, n)
288 call field_copy(w, m_z, n)
289 call field_invcol2(w, rho, n)
292 call this%bcs_vel%apply_vector(u%x, v%x, w%x, &
293 dm_xh%size(), time, strong = .true.)
294 call field_copy(m_x, u, n)
295 call field_col2(m_x, rho, n)
296 call field_copy(m_y, v, n)
297 call field_col2(m_y, rho, n)
298 call field_copy(m_z, w, n)
299 call field_col2(m_z, rho, n)
302 call field_col3(temp, u, u, n)
303 call field_addcol3(temp, v, v, n)
304 call field_addcol3(temp, w, w, n)
305 call field_col2(temp, rho, n)
306 call field_cmult(temp, 0.5_rp, n)
307 call field_copy(p, e, n)
308 call field_sub2(p, temp, n)
309 call field_cmult(p, this%gamma - 1.0_rp, n)
312 call this%bcs_prs%apply(p, time)
315 call field_copy(e, p, n)
316 call field_cmult(e, 1.0_rp / (this%gamma - 1.0_rp), n)
318 call field_add2(e, temp, n)
321 call this%compute_entropy()
324 call this%compute_max_wave_speed()
326 do i = 1, this%bcs_vel%size()
327 b => this%bcs_vel%get(i)
331 do i = 1, this%bcs_prs%size()
332 b => this%bcs_prs%get(i)
336 do i = 1, this%bcs_density%size()
337 b => this%bcs_density%get(i)
343 call profiler_end_region(
'Fluid compressible', 1)
345 call this%scratch%relinquish_field(temp_indices)
347 end subroutine fluid_scheme_compressible_euler_step
353 subroutine fluid_scheme_compressible_euler_setup_bcs(this, user, params)
354 class(fluid_scheme_compressible_euler_t),
target,
intent(inout) :: this
355 type(user_t),
target,
intent(in) :: user
356 type(json_file),
intent(inout) :: params
357 integer :: i, n_bcs, zone_index, j, zone_size, global_zone_size, ierr
358 class(bc_t),
pointer :: bc_i
359 type(json_core) :: core
360 type(json_value),
pointer :: bc_object
361 type(json_file) :: bc_subdict
363 integer,
allocatable :: zone_indices(:)
364 character(len=LOG_SIZE) :: log_buf
367 if (params%valid_path(
'case.fluid.boundary_conditions'))
then
368 call params%info(
'case.fluid.boundary_conditions', n_children = n_bcs)
369 call params%get_core(core)
370 call params%get(
'case.fluid.boundary_conditions', bc_object, found)
375 call this%bcs_vel%init(n_bcs)
379 call json_extract_item(core, bc_object, i, bc_subdict)
380 call json_get(bc_subdict,
"zone_indices", zone_indices)
383 do j = 1,
size(zone_indices)
384 zone_size = this%msh%labeled_zones(zone_indices(j))%size
385 call mpi_allreduce(zone_size, global_zone_size, 1, &
386 mpi_integer, mpi_max, neko_comm, ierr)
388 if (global_zone_size .eq. 0)
then
389 write(log_buf,
'(A,I0,A)')
"Error: Zone ", zone_indices(j), &
391 call neko_error(log_buf)
397 call velocity_bc_factory(bc_i, this, bc_subdict, this%c_Xh,
user)
400 if (
associated(bc_i))
then
401 call this%bcs_vel%append(bc_i)
408 call this%bcs_prs%init(n_bcs)
412 call json_extract_item(core, bc_object, i, bc_subdict)
414 call pressure_bc_factory(bc_i, this, bc_subdict, this%c_Xh,
user)
418 if (
associated(bc_i))
then
419 call this%bcs_prs%append(bc_i)
426 call this%bcs_density%init(n_bcs)
430 call json_extract_item(core, bc_object, i, bc_subdict)
432 call density_bc_factory(bc_i, this, bc_subdict, this%c_Xh,
user)
436 if (
associated(bc_i))
then
437 call this%bcs_density%append(bc_i)
442 do i = 1,
size(this%msh%labeled_zones)
443 if (this%msh%labeled_zones(i)%size .gt. 0)
then
444 call neko_error(
"No boundary_conditions entry in the case file!")
450 call this%bcs_prs%init()
451 call this%bcs_vel%init()
452 call this%bcs_density%init()
455 end subroutine fluid_scheme_compressible_euler_setup_bcs
461 subroutine compute_h(this)
462 class(fluid_scheme_compressible_euler_t),
intent(inout) :: this
463 integer :: e, i, j, k
464 integer :: im, ip, jm, jp, km, kp
465 real(kind=rp) :: di, dj, dk, ndim_inv
466 integer :: lx_half, ly_half, lz_half
468 lx_half = this%c_Xh%Xh%lx / 2
469 ly_half = this%c_Xh%Xh%ly / 2
470 lz_half = this%c_Xh%Xh%lz / 2
472 do e = 1, this%c_Xh%msh%nelv
473 do k = 1, this%c_Xh%Xh%lz
475 kp = min(this%c_Xh%Xh%lz, k+1)
477 do j = 1, this%c_Xh%Xh%ly
479 jp = min(this%c_Xh%Xh%ly, j+1)
481 do i = 1, this%c_Xh%Xh%lx
483 ip = min(this%c_Xh%Xh%lx, i+1)
485 di = (this%c_Xh%dof%x(ip, j, k, e) - &
486 this%c_Xh%dof%x(im, j, k, e))**2 &
487 + (this%c_Xh%dof%y(ip, j, k, e) - &
488 this%c_Xh%dof%y(im, j, k, e))**2 &
489 + (this%c_Xh%dof%z(ip, j, k, e) - &
490 this%c_Xh%dof%z(im, j, k, e))**2
492 dj = (this%c_Xh%dof%x(i, jp, k, e) - &
493 this%c_Xh%dof%x(i, jm, k, e))**2 &
494 + (this%c_Xh%dof%y(i, jp, k, e) - &
495 this%c_Xh%dof%y(i, jm, k, e))**2 &
496 + (this%c_Xh%dof%z(i, jp, k, e) - &
497 this%c_Xh%dof%z(i, jm, k, e))**2
499 dk = (this%c_Xh%dof%x(i, j, kp, e) - &
500 this%c_Xh%dof%x(i, j, km, e))**2 &
501 + (this%c_Xh%dof%y(i, j, kp, e) - &
502 this%c_Xh%dof%y(i, j, km, e))**2 &
503 + (this%c_Xh%dof%z(i, j, kp, e) - &
504 this%c_Xh%dof%z(i, j, km, e))**2
506 di = sqrt(di) / (ip - im)
507 dj = sqrt(dj) / (jp - jm)
508 dk = sqrt(dk) / (kp - km)
509 this%h%x(i,j,k,e) = (di * dj * dk)**(1.0_rp / 3.0_rp)
516 if (neko_bcknd_device .eq. 1)
then
517 call device_memcpy(this%h%x, this%h%x_d, this%h%dof%size(),&
518 host_to_device, sync = .false.)
519 call this%gs_Xh%op(this%h, gs_op_add)
520 call device_col2(this%h%x_d, this%c_Xh%mult_d, this%h%dof%size())
522 call this%gs_Xh%op(this%h, gs_op_add)
523 call col2(this%h%x, this%c_Xh%mult, this%h%dof%size())
526 end subroutine compute_h
532 subroutine fluid_scheme_compressible_euler_restart(this, chkp)
533 class(fluid_scheme_compressible_euler_t),
target,
intent(inout) :: this
534 type(chkp_t),
intent(inout) :: chkp
535 end subroutine fluid_scheme_compressible_euler_restart
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.
Subroutines to add advection terms to the RHS of a transport equation.
Defines a Matrix-vector product.
Defines a boundary condition.
type(mpi_comm), public neko_comm
MPI communicator.
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 field_invcol2(a, b, n)
Vector division .
subroutine, public field_col2(a, b, n)
Vector multiplication .
subroutine, public field_sub2(a, b, n)
Vector substraction .
subroutine, public field_cfill(a, c, n)
Set all elements to a constant c .
subroutine, public field_addcol3(a, b, c, n)
Returns .
subroutine, public field_add2(a, b, n)
Vector addition .
subroutine, public field_col3(a, b, c, n)
Vector multiplication with 3 vectors .
subroutine, public field_copy(a, b, n)
Copy a vector .
subroutine, public field_cmult(a, c, n)
Multiplication by constant c .
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.
Defines Gather-scatter operations.
integer, parameter, public gs_op_add
Utilities for retrieving parameters from the case files.
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.
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.
Coefficients defined on a given (mesh, ) tuple. Arrays use indices (i,j,k,e): element e,...
Abstract type to compute rhs.
Base type of compressible fluid formulations.
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...