57 use json_module,
only : json_file
62 use mpi_f08,
only : mpi_allreduce, mpi_integer, mpi_sum
63 use,
intrinsic :: iso_c_binding, only : c_ptr
75 character(len=:),
allocatable :: field_name
83 type(
vector_t) :: x_interface_dof, y_interface_dof, z_interface_dof
87 integer :: iextm_order = 1
88 integer :: last_tstep = -1
92 integer :: n_int_tot = 0
93 logical :: find_interface = .false.
94 logical :: setup = .false.
95 logical :: log = .false.
100 morph_interface => null()
106 procedure, pass(this) :: init_from_components => &
117 procedure, pass(this) :: apply_vector_dev => &
120 procedure, pass(this) :: apply_scalar_dev => &
154 interface_mask, time, bc_name, &
159 type(
mask_t),
intent(in) :: interface_mask
161 character(len=*),
intent(in) :: bc_name
162 logical,
intent(inout) :: find_interface
175 type(
coef_t),
target,
intent(in) :: coef
176 type(json_file),
intent(inout) :: json
177 character(len=:),
allocatable :: field_name
178 real(kind=
rp) :: tol, pad
181 call json_get(json,
"field_name", field_name)
185 if (this%iextm_order .lt. 1 .or. this%iextm_order .gt. 3)
then
186 call neko_error(
"The order of the IEXTm time scheme must be 1 to 3.")
190 call this%init_from_components(coef, field_name, tol, pad, log)
191 if (
allocated(field_name))
deallocate(field_name)
200 type(
coef_t),
intent(in) :: coef
201 character(len=*),
intent(in) :: field_name
202 real(kind=
rp),
intent(in),
optional :: tol, pad
203 logical,
intent(in),
optional :: log
204 character(len=256) :: log_buf
206 call this%init_base(coef)
208 if (
present(tol))
then
209 if (tol .gt. 0.0_rp)
then
210 this%interpolation_settings%tolerance = tol
214 if (
present(pad))
then
215 if (pad .gt. 0.0_rp)
then
216 this%interpolation_settings%padding = pad
220 if (
present(log))
then
224 this%field_name = field_name
225 write (log_buf,
'(A,A)')
"Coupling overset interface for: ", &
226 trim(this%field_name)
229 call this%bc_s%init_from_components(coef, this%field_name)
230 call this%field_list%init(1)
231 call this%field_list%assign_to_field(1, this%bc_s%field_bc)
233 call this%x_dof%init(this%dof%size(),
'x')
234 call this%y_dof%init(this%dof%size(),
'y')
235 call this%z_dof%init(this%dof%size(),
'z')
238 call device_copy(this%x_dof%x_d, this%dof%x_d, this%dof%size())
239 call device_copy(this%y_dof%x_d, this%dof%y_d, this%dof%size())
240 call device_copy(this%z_dof%x_d, this%dof%z_d, this%dof%size())
246 call copy(this%x_dof%x, this%dof%x, this%dof%size())
247 call copy(this%y_dof%x, this%dof%y, this%dof%size())
248 call copy(this%z_dof%x, this%dof%z, this%dof%size())
257 call this%bc_s%free()
258 call this%field_list%free()
259 call this%interface_dof%free()
260 call this%interface_field%free()
262 call this%x_dof%free()
263 call this%y_dof%free()
264 call this%z_dof%free()
266 call this%x_interface_dof%free()
267 call this%y_interface_dof%free()
268 call this%z_interface_dof%free()
269 call this%s_interface%free()
270 call this%s_interface_lag%free()
272 if (
allocated(this%field_name))
then
273 deallocate(this%field_name)
276 call this%interface_interpolator%free()
278 call this%interface_dof_mask%free()
279 call this%domain_element_mask%free()
281 call this%free_base()
290 integer,
intent(in) :: n
291 real(kind=
rp),
intent(inout),
dimension(n) :: x
293 logical,
intent(in),
optional :: strong
296 if (
present(strong))
then
303 if (.not. this%updated)
then
304 call this%update(time)
305 this%updated = .true.
308 call masked_copy_0(x, this%bc_s%field_bc%x, this%msk, n, this%msk(0))
319 type(c_ptr),
intent(inout) :: x_d
321 logical,
intent(in),
optional :: strong
322 type(c_ptr),
intent(inout) :: strm
325 if (
present(strong))
then
332 if (.not. this%updated)
then
333 call this%update(time)
334 this%updated = .true.
337 if (this%msk(0) .gt. 0)
then
339 this%bc_s%msk_d, this%bc_s%dof%size(), this%msk(0), strm)
348 integer,
intent(in) :: n
349 real(kind=
rp),
intent(inout),
dimension(n) :: x
350 real(kind=
rp),
intent(inout),
dimension(n) :: y
351 real(kind=
rp),
intent(inout),
dimension(n) :: z
353 logical,
intent(in),
optional :: strong
355 call neko_error(
"overset_interface cannot apply vector BCs.&
356 & Use overset_interface_vector instead!")
364 type(c_ptr),
intent(inout) :: x_d
365 type(c_ptr),
intent(inout) :: y_d
366 type(c_ptr),
intent(inout) :: z_d
368 logical,
intent(in),
optional :: strong
369 type(c_ptr),
intent(inout) :: strm
371 call neko_error(
"overset_interface cannot apply vector BCs.&
372 & Use overset_interface_vector instead!")
379 logical,
optional,
intent(in) :: only_facets
380 logical :: only_facets_
382 if (
present(only_facets))
then
383 only_facets_ = only_facets
385 only_facets_ = .false.
388 call this%finalize_base(only_facets_)
390 call this%bc_s%mark_facets(this%marked_facet)
391 call this%bc_s%finalize(only_facets_)
393 call this%build_masks_()
395 call this%x_interface_dof%init(this%interface_dof_mask%size(), &
397 call this%y_interface_dof%init(this%interface_dof_mask%size(), &
399 call this%z_interface_dof%init(this%interface_dof_mask%size(), &
401 call this%gather_interface_dofs_()
403 call this%setup_interpolator_()
405 call this%s_interface%init(this%interface_dof_mask%size(),
's_interface')
407 call this%interface_dof%init(3)
408 call this%interface_dof%assign_to_vector(1, this%x_interface_dof)
409 call this%interface_dof%assign_to_vector(2, this%y_interface_dof)
410 call this%interface_dof%assign_to_vector(3, this%z_interface_dof)
412 call this%interface_field%init(1)
413 call this%interface_field%assign_to_vector(1, this%s_interface)
415 call this%s_interface_lag%init(this%s_interface, this%iextm_order)
417 call mpi_allreduce(this%s_interface%size(), this%n_int_tot, 1, mpi_integer, &
428 integer :: nhist, ihist
429 real(kind=
rp) :: iextm_coeffs(4)
432 call this%morph_interface(this%interface_dof, this%interface_field, &
433 this%interface_dof_mask, time, this%name, &
437 if (this%find_interface)
then
440 call this%x_interface_dof%copy_from(
device_to_host, sync = .false.)
441 call this%y_interface_dof%copy_from(
device_to_host, sync = .false.)
442 call this%z_interface_dof%copy_from(
device_to_host, sync = .true.)
444 call this%interface_interpolator%find_points(this%x_interface_dof%x, &
445 this%y_interface_dof%x, this%z_interface_dof%x, &
446 this%x_interface_dof%size())
447 this%find_interface = .false.
453 call this%interface_interpolator%evaluate_masked(this%s_interface%x, s%x, &
454 this%domain_element_mask, .false.)
457 call this%log_interface_error_(s)
460 if (time%tstep .ne. this%last_tstep)
then
461 this%last_tstep = time%tstep
463 call this%s_interface_lag%update()
465 nhist = min(time%tstep, this%iextm_order)
466 call time_scheme%compute_coeffs(iextm_coeffs, time%dtlag, nhist)
468 call vector_cmult2(this%s_interface, this%s_interface_lag%lv(1), &
471 call vector_add2s2(this%s_interface, this%s_interface_lag%lv(ihist), &
477 this%s_interface, this%interface_dof_mask, this%bc_s%dof%size())
486 type(
field_t),
pointer,
intent(in) :: s
487 real(kind=
rp) :: s_int_norm
490 logical :: clear_scratch = .false.
491 character(len=256) :: log_buf
501 write(log_buf,
'(A12,A3,A10,1x,E15.7)')
'Interface BC',
' | ', &
502 'L2 Error: ', s_int_norm
515 logical,
allocatable :: found(:)
516 integer :: i, j, k, e, nelems
517 integer :: lx, ly, lz
518 integer :: nonlinear_idx(4), linear_idx
521 call this%interface_dof_mask%init(this%msk(1:this%msk(0)), this%msk(0))
527 allocate(found(this%msh%nelv))
530 do i = 1, this%msk(0)
531 linear_idx = this%msk(i)
533 found(nonlinear_idx(4)) = .true.
537 call idx_stack%init()
538 do e = 1, this%msh%nelv
545 call idx_stack%push(linear_idx)
554 call temp_mask%init(idx_stack%array(), idx_stack%size())
555 call idx_stack%free()
557 call this%domain_element_mask%invert_mask(temp_mask, this%dof%size())
558 call temp_mask%free()
567 this%interface_dof_mask, this%dof%size())
569 this%interface_dof_mask, this%dof%size())
571 this%interface_dof_mask, this%dof%size())
573 call this%x_interface_dof%copy_from(
device_to_host, sync = .false.)
574 call this%y_interface_dof%copy_from(
device_to_host, sync = .false.)
575 call this%z_interface_dof%copy_from(
device_to_host, sync = .true.)
583 call this%interface_interpolator%init(this%dof, &
585 tol = this%interpolation_settings%tolerance, &
586 pad = this%interpolation_settings%padding, &
587 mask = this%domain_element_mask)
589 call this%interface_interpolator%find_points(this%x_interface_dof%x, &
590 this%y_interface_dof%x, this%z_interface_dof%x, &
591 this%x_interface_dof%size())
__inline__ __device__ void nonlinear_index(const int idx, const int lx, int *index)
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.
User callback for overset-interface morphing and boundary-value updates.
Defines a boundary condition.
type(mpi_comm), public neko_global_comm
subroutine, public device_copy(a_d, b_d, n, strm)
Copy a vector .
subroutine, public device_masked_copy_0(a_d, b_d, mask_d, n, n_mask, strm)
Copy a masked vector .
Device abstraction, common interface for various accelerators.
integer, parameter, public device_to_host
Defines user dirichlet condition for a scalar field.
Implements global_interpolation given a dofmap.
Utilities for retrieving parameters from the case files.
type(log_t), public neko_log
Global log stream.
integer, parameter, public log_size
Object for handling masks in Neko.
subroutine, public copy(a, b, n)
Copy a vector .
subroutine, public masked_copy_0(a, b, mask, n, n_mask)
Copy a masked vector .
integer, parameter neko_bcknd_device
integer, parameter, public rp
Global precision used in computations.
Defines overset interface scalar boundary conditions.
subroutine overset_interface_finalize(this, only_facets)
Finalize by building the mask arrays and preparing interpolation data.
subroutine overset_interface_update(this, time)
Update values at the overset interface.
subroutine overset_interface_apply_scalar(this, x, n, time, strong)
Apply scalar.
subroutine gather_interface_dofs_(this)
Gather interface dofs.
subroutine overset_interface_apply_vector(this, x, y, z, n, time, strong)
(No-op) Apply vector.
subroutine overset_interface_free(this)
Destructor.
subroutine overset_interface_apply_scalar_dev(this, x_d, time, strong, strm)
Apply scalar (device).
subroutine log_interface_error_(this, s)
Log interface RMSE for the scalar field.
subroutine overset_interface_init(this, coef, json)
Constructor.
subroutine setup_interpolator_(this)
Set up the global interpolator.
subroutine build_masks_(this)
Build masks.
subroutine overset_interface_apply_vector_dev(this, x_d, y_d, z_d, time, strong, strm)
(No-op) Apply vector (device).
subroutine overset_interface_init_from_components(this, coef, field_name, tol, pad, log)
Constructor from components.
Defines a registry for storing solution fields.
type(registry_t), target, public neko_registry
Global field registry.
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.
Implements a dynamic stack ADT.
Base class for time integration schemes.
Module with things related to the simulation time.
pure integer function, public linear_index(i, j, k, l, lx, ly, lz)
Compute the address of a (i,j,k,l) array with sizes (1:lx, 1:ly, 1:lz, :)
subroutine, public vector_masked_gather_copy(a, b, mask, n)
Gather a vector to reduced contigous array .
real(kind=rp) function, public vector_glsc2(a, b, n)
subroutine, public vector_add2s2(a, b, c1, n)
Vector addition with scalar multiplication (multiplication on second argument)
subroutine, public vector_masked_scatter_copy(a, b, mask, n)
Scatter a contiguous vector into an array .
subroutine, public vector_cmult2(a, b, c, n)
Multiplication by constant c .
Contains the vector_series_t type.
Base type for a boundary condition.
Coefficients defined on a given (mesh, ) tuple. Arrays use indices (i,j,k,e): element e,...
User defined dirichlet condition, for which the user can work with an entire field....
field_list_t, To be able to group fields together
Implements the settings helper data container for global interpolation.
Implements global interpolation for arbitrary points in the domain.
Explicit interface extrapolation scheme for overset grids.
Type for consistently handling masks in Neko. This type encapsulates the mask array and its associate...
Overset interface BC for a scalar field.
A struct that contains all info about the time, expand as needed.
vector_list_t, To be able to group vectors together
Stores a series (sequence) of vectors, logically connected to a base vector, and arranged according t...