49 use json_module,
only : json_file, json_core, json_value
64 use mpi_f08,
only : mpi_allreduce, mpi_integer, mpi_max
70 type(
field_t) :: rho_res, m_x_res, m_y_res, m_z_res, m_e_res
71 type(
field_t) :: drho, dm_x, dm_y, dm_z, de
73 real(kind=
rp) :: c_avisc_low
75 class(
ax_t),
allocatable :: ax
87 procedure, pass(this) :: setup_bcs &
100 module subroutine density_bc_factory(object, scheme, json, coef,
user)
101 class(
bc_t),
pointer,
intent(inout) :: object
102 type(fluid_scheme_compressible_euler_t),
intent(in) :: scheme
103 type(json_file),
intent(inout) :: json
104 type(
coef_t),
intent(in) :: coef
106 end subroutine density_bc_factory
117 module subroutine pressure_bc_factory(object, scheme, json, coef,
user)
118 class(
bc_t),
pointer,
intent(inout) :: object
119 type(fluid_scheme_compressible_euler_t),
intent(inout) :: scheme
120 type(json_file),
intent(inout) :: json
121 type(
coef_t),
intent(in) :: coef
123 end subroutine pressure_bc_factory
134 module subroutine velocity_bc_factory(object, scheme, json, coef,
user)
135 class(
bc_t),
pointer,
intent(inout) :: object
136 type(fluid_scheme_compressible_euler_t),
intent(in) :: scheme
137 type(json_file),
intent(inout) :: json
138 type(
coef_t),
intent(in) :: coef
140 end subroutine velocity_bc_factory
151 subroutine fluid_scheme_compressible_euler_init(this, msh, lx, params, user, &
153 class(fluid_scheme_compressible_euler_t),
target,
intent(inout) :: this
154 type(
mesh_t),
target,
intent(inout) :: msh
155 integer,
intent(in) :: lx
156 type(json_file),
target,
intent(inout) :: params
157 type(
user_t),
target,
intent(in) :: user
158 type(
chkp_t),
target,
intent(inout) :: chkp
159 character(len=12),
parameter :: scheme =
'compressible'
165 call this%scheme_init(msh, lx, params, scheme,
user)
167 call euler_rhs_factory(this%euler_rhs)
169 associate(xh_lx => this%Xh%lx, xh_ly => this%Xh%ly, xh_lz => this%Xh%lz, &
170 dm_xh => this%dm_Xh, nelv => this%msh%nelv)
172 call this%drho%init(dm_xh,
'drho')
173 call this%dm_x%init(dm_xh,
'dm_x')
174 call this%dm_y%init(dm_xh,
'dm_y')
175 call this%dm_z%init(dm_xh,
'dm_z')
176 call this%dE%init(dm_xh,
'dE')
177 call this%h%init(dm_xh,
'h')
182 associate(p => this%p, rho => this%rho, &
183 u => this%u, v => this%v, w => this%w, &
184 m_x => this%m_x, m_y => this%m_y, m_z => this%m_z)
205 call ax_helm_factory(this%Ax, full_formulation = .false.)
208 call this%compute_h()
209 call json_get_or_default(params,
'case.numerics.c_avisc_low', &
210 this%c_avisc_low, 0.5_rp)
213 call json_get_or_default(params,
'case.numerics.time_order', rk_order, 4)
214 call this%rk_scheme%init(rk_order)
217 call this%setup_bcs(
user, params)
219 end subroutine fluid_scheme_compressible_euler_init
223 subroutine fluid_scheme_compressible_euler_free(this)
224 class(fluid_scheme_compressible_euler_t),
intent(inout) :: this
226 call this%scheme_free()
228 if (
allocated(this%Ax))
then
232 call this%drho%free()
233 call this%dm_x%free()
234 call this%dm_y%free()
235 call this%dm_z%free()
239 end subroutine fluid_scheme_compressible_euler_free
246 subroutine fluid_scheme_compressible_euler_step(this, time, dt_controller)
247 class(fluid_scheme_compressible_euler_t),
target,
intent(inout) :: this
248 type(time_state_t),
intent(in) :: time
249 type(time_step_controller_t),
intent(in) :: dt_controller
250 type(field_t),
pointer :: temp
251 integer :: temp_indices(1)
255 class(bc_t),
pointer :: b
257 n = this%dm_Xh%size()
258 call neko_scratch_registry%request_field(temp, temp_indices(1), .false.)
261 call profiler_start_region(
'Fluid compressible', 1)
262 associate(u => this%u, v => this%v, w => this%w, p => this%p, &
263 m_x=> this%m_x, m_y => this%m_y, m_z => this%m_z, &
264 xh => this%Xh, msh => this%msh, ax => this%Ax, &
265 c_xh => this%c_Xh, dm_xh => this%dm_Xh, gs_xh => this%gs_Xh, &
266 e => this%E, rho => this%rho, mu => this%mu, &
267 f_x => this%f_x, f_y => this%f_y, f_z => this%f_z, &
268 drho => this%drho, dm_x => this%dm_x, dm_y => this%dm_y, &
269 dm_z => this%dm_z, de => this%dE, &
270 euler_rhs => this%euler_rhs, h => this%h, &
271 t => time%t, tstep => time%tstep, dt => time%dt, &
272 ext_bdf => this%ext_bdf, &
273 c_avisc_low => this%c_avisc_low, rk_scheme => this%rk_scheme)
275 call euler_rhs%step(rho, m_x, m_y, m_z, e, &
277 c_xh, gs_xh, h, c_avisc_low, &
281 call this%bcs_density%apply(rho, time)
285 call field_copy(u, m_x, n)
286 call field_invcol2(u, rho, n)
287 call field_copy(v, m_y, n)
288 call field_invcol2(v, rho, n)
289 call field_copy(w, m_z, n)
290 call field_invcol2(w, rho, n)
293 call this%bcs_vel%apply_vector(u%x, v%x, w%x, &
294 dm_xh%size(), time, strong = .true.)
295 call field_copy(m_x, u, n)
296 call field_col2(m_x, rho, n)
297 call field_copy(m_y, v, n)
298 call field_col2(m_y, rho, n)
299 call field_copy(m_z, w, n)
300 call field_col2(m_z, rho, n)
303 call field_col3(temp, u, u, n)
304 call field_addcol3(temp, v, v, n)
305 call field_addcol3(temp, w, w, n)
306 call field_col2(temp, rho, n)
307 call field_cmult(temp, 0.5_rp, n)
308 call field_copy(p, e, n)
309 call field_sub2(p, temp, n)
310 call field_cmult(p, this%gamma - 1.0_rp, n)
313 call this%bcs_prs%apply(p, time)
316 call field_copy(e, p, n)
317 call field_cmult(e, 1.0_rp / (this%gamma - 1.0_rp), n)
319 call field_add2(e, temp, n)
322 call this%compute_entropy()
325 call this%compute_max_wave_speed()
327 do i = 1, this%bcs_vel%size()
328 b => this%bcs_vel%get(i)
332 do i = 1, this%bcs_prs%size()
333 b => this%bcs_prs%get(i)
337 do i = 1, this%bcs_density%size()
338 b => this%bcs_density%get(i)
344 call profiler_end_region(
'Fluid compressible', 1)
346 call neko_scratch_registry%relinquish_field(temp_indices)
348 end subroutine fluid_scheme_compressible_euler_step
354 subroutine fluid_scheme_compressible_euler_setup_bcs(this, user, params)
355 class(fluid_scheme_compressible_euler_t),
target,
intent(inout) :: this
356 type(user_t),
target,
intent(in) :: user
357 type(json_file),
intent(inout) :: params
358 integer :: i, n_bcs, zone_index, j, zone_size, global_zone_size, ierr
359 class(bc_t),
pointer :: bc_i
360 type(json_core) :: core
361 type(json_value),
pointer :: bc_object
362 type(json_file) :: bc_subdict
364 integer,
allocatable :: zone_indices(:)
365 character(len=LOG_SIZE) :: log_buf
368 if (params%valid_path(
'case.fluid.boundary_conditions'))
then
369 call params%info(
'case.fluid.boundary_conditions', n_children = n_bcs)
370 call params%get_core(core)
371 call params%get(
'case.fluid.boundary_conditions', bc_object, found)
376 call this%bcs_vel%init(n_bcs)
380 call json_extract_item(core, bc_object, i, bc_subdict)
381 call json_get(bc_subdict,
"zone_indices", zone_indices)
384 do j = 1,
size(zone_indices)
385 zone_size = this%msh%labeled_zones(zone_indices(j))%size
386 call mpi_allreduce(zone_size, global_zone_size, 1, &
387 mpi_integer, mpi_max, neko_comm, ierr)
389 if (global_zone_size .eq. 0)
then
390 write(log_buf,
'(A,I0,A)')
"Error: Zone ", zone_indices(j), &
392 call neko_error(log_buf)
398 call velocity_bc_factory(bc_i, this, bc_subdict, this%c_Xh,
user)
401 if (
associated(bc_i))
then
402 call this%bcs_vel%append(bc_i)
409 call this%bcs_prs%init(n_bcs)
413 call json_extract_item(core, bc_object, i, bc_subdict)
415 call pressure_bc_factory(bc_i, this, bc_subdict, this%c_Xh,
user)
419 if (
associated(bc_i))
then
420 call this%bcs_prs%append(bc_i)
427 call this%bcs_density%init(n_bcs)
431 call json_extract_item(core, bc_object, i, bc_subdict)
433 call density_bc_factory(bc_i, this, bc_subdict, this%c_Xh,
user)
437 if (
associated(bc_i))
then
438 call this%bcs_density%append(bc_i)
443 do i = 1,
size(this%msh%labeled_zones)
444 if (this%msh%labeled_zones(i)%size .gt. 0)
then
445 call neko_error(
"No boundary_conditions entry in the case file!")
451 call this%bcs_prs%init()
452 call this%bcs_vel%init()
453 call this%bcs_density%init()
456 end subroutine fluid_scheme_compressible_euler_setup_bcs
462 subroutine compute_h(this)
463 class(fluid_scheme_compressible_euler_t),
intent(inout) :: this
464 integer :: e, i, j, k
465 integer :: im, ip, jm, jp, km, kp
466 real(kind=rp) :: di, dj, dk, ndim_inv
467 integer :: lx_half, ly_half, lz_half
469 lx_half = this%c_Xh%Xh%lx / 2
470 ly_half = this%c_Xh%Xh%ly / 2
471 lz_half = this%c_Xh%Xh%lz / 2
473 do e = 1, this%c_Xh%msh%nelv
474 do k = 1, this%c_Xh%Xh%lz
476 kp = min(this%c_Xh%Xh%lz, k+1)
478 do j = 1, this%c_Xh%Xh%ly
480 jp = min(this%c_Xh%Xh%ly, j+1)
482 do i = 1, this%c_Xh%Xh%lx
484 ip = min(this%c_Xh%Xh%lx, i+1)
486 di = (this%c_Xh%dof%x(ip, j, k, e) - &
487 this%c_Xh%dof%x(im, j, k, e))**2 &
488 + (this%c_Xh%dof%y(ip, j, k, e) - &
489 this%c_Xh%dof%y(im, j, k, e))**2 &
490 + (this%c_Xh%dof%z(ip, j, k, e) - &
491 this%c_Xh%dof%z(im, j, k, e))**2
493 dj = (this%c_Xh%dof%x(i, jp, k, e) - &
494 this%c_Xh%dof%x(i, jm, k, e))**2 &
495 + (this%c_Xh%dof%y(i, jp, k, e) - &
496 this%c_Xh%dof%y(i, jm, k, e))**2 &
497 + (this%c_Xh%dof%z(i, jp, k, e) - &
498 this%c_Xh%dof%z(i, jm, k, e))**2
500 dk = (this%c_Xh%dof%x(i, j, kp, e) - &
501 this%c_Xh%dof%x(i, j, km, e))**2 &
502 + (this%c_Xh%dof%y(i, j, kp, e) - &
503 this%c_Xh%dof%y(i, j, km, e))**2 &
504 + (this%c_Xh%dof%z(i, j, kp, e) - &
505 this%c_Xh%dof%z(i, j, km, e))**2
507 di = sqrt(di) / (ip - im)
508 dj = sqrt(dj) / (jp - jm)
509 dk = sqrt(dk) / (kp - km)
510 this%h%x(i,j,k,e) = (di * dj * dk)**(1.0_rp / 3.0_rp)
517 if (neko_bcknd_device .eq. 1)
then
518 call device_memcpy(this%h%x, this%h%x_d, this%h%dof%size(),&
519 host_to_device, sync = .false.)
520 call this%gs_Xh%op(this%h, gs_op_add)
521 call device_col2(this%h%x_d, this%c_Xh%mult_d, this%h%dof%size())
523 call this%gs_Xh%op(this%h, gs_op_add)
524 call col2(this%h%x, this%c_Xh%mult, this%h%dof%size())
527 end subroutine compute_h
533 subroutine fluid_scheme_compressible_euler_restart(this, chkp)
534 class(fluid_scheme_compressible_euler_t),
target,
intent(inout) :: this
535 type(chkp_t),
intent(inout) :: chkp
536 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.
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.
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...