39 use iso_c_binding,
only : c_associated
54 use,
intrinsic :: iso_c_binding, only : c_ptr, c_null_ptr
55 use json_module,
only : json_file
72 type,
public,
abstract ::
bc_t
74 integer,
allocatable :: msk(:)
76 integer,
allocatable :: facet_node_msk(:)
78 integer,
allocatable :: facet(:)
82 type(
coef_t),
pointer :: coef => null()
84 type(
mesh_t),
pointer :: msh => null()
90 type(c_ptr) :: msk_d = c_null_ptr
92 type(c_ptr) :: facet_node_msk_d = c_null_ptr
94 type(c_ptr) :: facet_d = c_null_ptr
96 integer :: bc_type = -1
99 logical :: updated = .false.
101 character(len=:),
allocatable :: name
103 integer,
allocatable :: zone_indices(:)
149 class(
bc_t),
pointer :: ptr => null()
154 class(
bc_t),
allocatable :: obj
162 class(
bc_t),
intent(inout),
target :: this
163 type(
coef_t),
target,
intent(in) :: coef
164 type(json_file),
intent(inout) :: json
172 class(
bc_t),
intent(inout),
target :: this
180 class(
bc_t),
intent(inout),
target :: this
193 class(
bc_t),
intent(inout) :: this
194 integer,
intent(in) :: n
195 real(kind=
rp),
intent(inout),
dimension(n) :: x
197 logical,
intent(in),
optional :: strong
213 class(
bc_t),
intent(inout) :: this
214 integer,
intent(in) :: n
215 real(kind=
rp),
intent(inout),
dimension(n) :: x
216 real(kind=
rp),
intent(inout),
dimension(n) :: y
217 real(kind=
rp),
intent(inout),
dimension(n) :: z
219 logical,
intent(in),
optional :: strong
233 class(
bc_t),
intent(inout),
target :: this
234 type(c_ptr),
intent(inout) :: x_d
236 logical,
intent(in),
optional :: strong
237 type(c_ptr),
intent(inout) :: strm
252 class(
bc_t),
intent(inout),
target :: this
253 type(c_ptr),
intent(inout) :: x_d
254 type(c_ptr),
intent(inout) :: y_d
255 type(c_ptr),
intent(inout) :: z_d
257 logical,
intent(in),
optional :: strong
258 type(c_ptr),
intent(inout) :: strm
267 class(
bc_t),
intent(inout) :: this
268 type(
coef_t),
target,
intent(in) :: coef
274 this%Xh => this%dof%Xh
275 this%msh => this%dof%msh
277 call this%marked_facet%init()
283 class(
bc_t),
intent(inout) :: this
285 call this%marked_facet%free()
292 if (
allocated(this%msk))
then
299 if (
allocated(this%facet_node_msk))
then
301 call device_unmap(this%facet_node_msk, this%facet_node_msk_d)
303 deallocate(this%facet_node_msk)
306 if (
allocated(this%facet))
then
310 deallocate(this%facet)
313 if (
allocated(this%name))
then
314 deallocate(this%name)
317 if (
allocated(this%zone_indices))
then
318 deallocate(this%zone_indices)
324 this%updated = .false.
337 class(
bc_t),
intent(inout) :: this
338 type(
field_t),
intent(inout) :: x
339 type(
field_t),
intent(inout) :: y
340 type(
field_t),
intent(inout) :: z
342 logical,
intent(in),
optional :: strong
343 type(c_ptr),
intent(inout),
optional :: strm
346 character(len=256) :: msg
352 if (y%size() .ne. n .or. z%size() .ne. n)
then
353 msg =
"Fields x, y, z must have the same size in " // &
354 "bc_list_apply_vector_field"
360 if (
present(strm))
then
366 call this%apply_vector_dev(x%x_d, y%x_d, z%x_d, time = time, &
367 strong = strong, strm = strm_)
369 call this%apply_vector(x%x, y%x, z%x, n, time = time, strong = strong)
381 class(
bc_t),
intent(inout) :: this
382 type(
field_t),
intent(inout) :: x
384 logical,
intent(in),
optional :: strong
385 type(c_ptr),
intent(inout),
optional :: strm
394 if (
present(strm))
then
400 call this%apply_scalar_dev(x%x_d, time = time, strong = strong, &
403 call this%apply_scalar(x%x, n, time = time)
412 class(
bc_t),
intent(inout) :: this
413 integer,
intent(in) :: facet
414 integer,
intent(in) :: el
418 call this%marked_facet%push(t)
425 class(
bc_t),
intent(inout) :: this
430 fp => facet_list%array()
431 do i = 1, facet_list%size()
432 call this%marked_facet%push(fp(i))
440 class(
bc_t),
intent(inout) :: this
443 do i = 1, bc_zone%size
444 call this%marked_facet%push(bc_zone%facet_el(i))
451 class(
bc_t),
intent(inout) :: this
452 integer,
intent(in) :: zone_index
453 integer,
allocatable :: tmp(:)
455 character(len=LOG_SIZE) :: log_buf
457 if (
allocated(this%zone_indices))
then
458 do i = 1,
size(this%zone_indices)
459 if (this%zone_indices(i) .eq. zone_index)
then
460 write(log_buf,
'(A,I0,A)')
'Zone index ', zone_index, &
461 ' already marked for this boundary condition'
467 allocate(tmp(
size(this%zone_indices) + 1))
468 tmp(1:
size(this%zone_indices)) = this%zone_indices
469 tmp(
size(tmp)) = zone_index
470 call move_alloc(tmp, this%zone_indices)
472 allocate(this%zone_indices(1))
473 this%zone_indices(1) = zone_index
476 call this%mark_zone(this%msh%labeled_zones(zone_index))
482 class(
bc_t),
intent(inout) :: this
483 integer,
intent(in) :: zone_indices(:)
486 do i = 1,
size(zone_indices)
487 call this%mark_labeled_zone(zone_indices(i))
496 class(
bc_t),
target,
intent(inout) :: this
500 integer :: facet_size, facet, el
501 integer :: i, j, k, l, msk_c
502 integer :: lx, ly, lz, n
503 character(len=LOG_SIZE) :: log_buf
511 n = facet_size * this%marked_facet%size()
512 allocate(this%facet_node_msk(0:n))
513 allocate(this%facet(0:n))
516 call device_map(this%facet_node_msk, this%facet_node_msk_d, n + 1)
517 call device_map(this%facet, this%facet_d, n + 1)
521 bfp => this%marked_facet%array()
527 do i = 1, this%marked_facet%size()
529 facet = bc_facet%x(1)
536 this%facet_node_msk(msk_c) = &
538 this%facet(msk_c) = 1
545 this%facet_node_msk(msk_c) = &
547 this%facet(msk_c) = 2
554 this%facet_node_msk(msk_c) = &
556 this%facet(msk_c) = 3
563 this%facet_node_msk(msk_c) = &
565 this%facet(msk_c) = 4
572 this%facet_node_msk(msk_c) = &
574 this%facet(msk_c) = 5
581 this%facet_node_msk(msk_c) = &
583 this%facet(msk_c) = 6
588 this%facet_node_msk(0) = msk_c
589 this%facet(0) = msk_c
593 call device_memcpy(this%facet_node_msk, this%facet_node_msk_d, n, &
600 call test_field%init(this%dof)
602 n = test_field%size()
603 test_field%x = 0.0_rp
605 do i = 1, this%facet_node_msk(0)
606 test_field%x(this%facet_node_msk(i),1,1,1) = 1.0
613 call this%coef%gs_h%op(test_field,
gs_op_add)
619 do i = 1, this%dof%size()
620 if (test_field%x(i,1,1,1) .gt. 0.5)
then
625 allocate(this%msk(0:msk_c))
627 do i = 1, this%dof%size()
628 if (test_field%x(i,1,1,1) .gt. 0.5)
then
634 call test_field%free()
645 if (.not.
allocated(this%name))
then
649 write(log_buf,
'(A,A)')
'BC assigned name : ', trim(this%name)
665 class(
bc_t),
intent(inout) :: this
666 character(len=*),
intent(in) :: file_name
671 call bdry_field%init(this%coef%dof,
'bdry')
675 bdry_field%x(k,1,1,1) = 1.0_rp
677 call dump_file%init(file_name)
678 call dump_file%write(bdry_field)
Apply the boundary condition to a scalar field on the device.
Apply the boundary condition to a scalar field.
Apply the boundary condition to a vector field on the device.
Apply the boundary condition to a vector field.
Finalize by building the mask and facet arrays.
Map a Fortran array to a device (allocate and associate)
Copy data between host and device (or device and device)
Unmap a Fortran array from a device (deassociate and free)
Defines a boundary condition.
subroutine bc_mark_zone(this, bc_zone)
Mark all facets from a zone.
subroutine bc_finalize_base(this)
Finalize the construction of the bc by populting the msk and facet arrays.
integer, parameter, public bc_mixed_constrains_tangent
subroutine bc_free_base(this)
Destructor for the base type, bc_t.
subroutine bc_mark_labeled_zones(this, zone_indices)
Mark all facets from labeled zones.
integer, parameter, public bc_mixed_constrains_normal
subroutine bc_mark_labeled_zone(this, zone_index)
Mark all facets from a labeled zone.
subroutine bc_init_base(this, coef)
Constructor.
subroutine bc_apply_scalar_generic(this, x, time, strong, strm)
Apply the boundary condition to a scalar field. Dispatches to the CPU or the device version.
integer, parameter, public bc_dirichlet
Supported boundary condition types. The values are set in order of precedence for global resolution....
subroutine bc_apply_vector_generic(this, x, y, z, time, strong, strm)
Apply the boundary condition to a vector field. Dispatches to the CPU or the device version.
subroutine bc_debug_mask(this, file_name)
Write a field showing the mask of the bc.
subroutine bc_mark_facet(this, facet, el)
Mark facet on element el as part of the boundary condition.
subroutine bc_mark_facets(this, facet_list)
Mark all facets from a (facet, el) tuple list.
integer, parameter, public bc_neumann
subroutine, public device_cfill(a_d, c, n, strm)
Set all elements to a constant c .
Device abstraction, common interface for various accelerators.
integer, parameter, public host_to_device
integer, parameter, public device_to_host
type(c_ptr), bind(C), public glb_cmd_queue
Global command queue.
Defines a mapping of the degrees of freedom.
Defines a zone as a subset of facets in a mesh.
Module for file I/O operations.
Defines Gather-scatter operations.
integer, parameter, public gs_op_add
type(log_t), public neko_log
Global log stream.
integer, parameter, public log_size
Object for handling masks in Neko.
subroutine, public rzero(a, n)
Zero a real vector.
integer, parameter, public neko_msh_max_zlbls
Max num. zone labels.
integer, parameter, public neko_msh_max_zlbl_len
Max length of a zone label.
integer, parameter neko_bcknd_device
integer, parameter, public rp
Global precision used in computations.
Defines a function space.
Implements a dynamic stack ADT.
Module with things related to the simulation time.
character(len=100) function, dimension(:), allocatable, public split_string(string, delimiter)
Split a string based on delimiter (tokenizer) OBS: very hacky, this should really be improved,...
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 neko_warning(warning_msg)
Reports a warning to standard output.
Base type for a boundary condition.
Coefficients defined on a given (mesh, ) tuple. Arrays use indices (i,j,k,e): element e,...
A wrapper around a polymorphic generic_file_t that handles its init. This is essentially a factory fo...
Type for consistently handling masks in Neko. This type encapsulates the mask array and its associate...
The function space for the SEM solution fields.
Integer 2-tuple based stack.
A struct that contains all info about the time, expand as needed.