44 use json_module,
only : json_file
45 use,
intrinsic :: iso_c_binding, only : c_ptr, c_null_ptr, c_associated
55 integer,
allocatable :: unique_mask(:)
56 integer,
allocatable :: msk_to_unique(:)
57 type(c_ptr) :: unique_mask_d = c_null_ptr
65 procedure, pass(this) :: apply_surfvec_dev => &
72 procedure, pass(this) :: init_from_components => &
87 type(
coef_t),
target,
intent(in) :: coef
88 type(json_file),
intent(inout) :: json
90 call this%init_from_components(coef)
97 type(
coef_t),
target,
intent(in) :: coef
99 call this%init_base(coef)
106 integer,
intent(in) :: n
107 real(kind=
rp),
intent(inout),
dimension(n) :: x
109 logical,
intent(in),
optional :: strong
115 type(c_ptr),
intent(inout) :: x_d
117 logical,
intent(in),
optional :: strong
118 type(c_ptr),
intent(inout) :: strm
126 type(c_ptr),
intent(inout) :: x_d
127 type(c_ptr),
intent(inout) :: y_d
128 type(c_ptr),
intent(inout) :: z_d
130 logical,
intent(in),
optional :: strong
131 type(c_ptr),
intent(inout) :: strm
138 integer,
intent(in) :: n
139 real(kind=
rp),
intent(inout),
dimension(n) :: x
140 real(kind=
rp),
intent(inout),
dimension(n) :: y
141 real(kind=
rp),
intent(inout),
dimension(n) :: z
143 logical,
intent(in),
optional :: strong
149 integer,
intent(in) :: n
150 real(kind=
rp),
intent(inout),
dimension(n) :: x
151 real(kind=
rp),
intent(inout),
dimension(n) :: y
152 real(kind=
rp),
intent(inout),
dimension(n) :: z
153 real(kind=
rp),
intent(inout),
dimension(n) :: u
154 real(kind=
rp),
intent(inout),
dimension(n) :: v
155 real(kind=
rp),
intent(inout),
dimension(n) :: w
157 integer :: i, m, k, idx(4), facet
158 real(kind=
rp) :: normal(3), area
160 m = this%unique_mask(0)
165 k = this%unique_mask(i)
166 x(k) = u(k) * this%nx%x(i)
167 y(k) = v(k) * this%ny%x(i)
168 z(k) = w(k) * this%nz%x(i)
176 u_d, v_d, w_d, time, strm)
178 type(c_ptr) :: x_d, y_d, z_d, u_d, v_d, w_d
180 type(c_ptr),
optional :: strm
184 n = this%coef%dof%size()
185 m = this%unique_mask(0)
187 if (
present(strm))
then
195 this%unique_mask_d, n, m, strm_)
196 call device_col2(this%work%x_d, this%nx%x_d, m, strm_)
198 this%unique_mask_d, n, m, strm_)
200 this%unique_mask_d, n, m, strm_)
201 call device_col2(this%work%x_d, this%ny%x_d, m, strm_)
203 this%unique_mask_d, n, m, strm_)
205 this%unique_mask_d, n, m, strm_)
206 call device_col2(this%work%x_d, this%nz%x_d, m, strm)
208 this%unique_mask_d, n, m, strm_)
217 call this%free_base()
218 if (
allocated(this%unique_mask))
then
222 deallocate(this%unique_mask)
224 if (
allocated(this%msk_to_unique))
deallocate(this%msk_to_unique)
229 call this%work%free()
237 integer :: htable_data, rcode, i, j, idx(4), facet
238 real(kind=
rp) :: area, normal(3)
241 call this%coef%require_facets(
'facet_normal')
243 call this%finalize_base()
255 if (
allocated(this%unique_mask))
then
259 deallocate(this%unique_mask)
261 if (
allocated(this%msk_to_unique))
deallocate(this%msk_to_unique)
263 call unique_point_idx%init(this%facet_node_msk(0), htable_data)
265 do i = 1, this%facet_node_msk(0)
266 if (unique_point_idx%get(this%facet_node_msk(i), &
267 htable_data) .ne. 0)
then
270 call unique_point_idx%set(this%facet_node_msk(i), j)
275 if (unique_point_idx%num_entries() .gt. 0 )
then
276 call this%nx%init(unique_point_idx%num_entries())
277 call this%ny%init(unique_point_idx%num_entries())
278 call this%nz%init(unique_point_idx%num_entries())
279 call this%work%init(unique_point_idx%num_entries())
281 allocate(this%unique_mask(0:unique_point_idx%num_entries()))
282 allocate(this%msk_to_unique(this%facet_node_msk(0)))
284 this%unique_mask(0) = unique_point_idx%num_entries()
285 do i = 1, this%unique_mask(0)
286 this%unique_mask(i) = 0
290 do i = 1, this%facet_node_msk(0)
291 rcode = unique_point_idx%get(this%facet_node_msk(i), htable_data)
292 if (rcode .ne. 0)
call neko_error(
"Facet normal: htable get failed.")
293 this%unique_mask(htable_data) = this%facet_node_msk(i)
296 this%msk_to_unique(i) = htable_data
297 facet = this%facet(i)
299 idx =
nonlinear_index(this%facet_node_msk(i), this%Xh%lx, this%Xh%lx, &
301 normal = this%coef%get_normal(idx(1), idx(2), idx(3), idx(4), facet)
302 area = this%coef%get_area(idx(1), idx(2), idx(3), idx(4), facet)
303 normal = normal * area
304 this%nx%x(htable_data) = this%nx%x(htable_data) + normal(1)
305 this%ny%x(htable_data) = this%ny%x(htable_data) + normal(2)
306 this%nz%x(htable_data) = this%nz%x(htable_data) + normal(3)
310 (unique_point_idx%num_entries() .gt. 0 ))
then
311 call device_map(this%unique_mask, this%unique_mask_d, &
312 size(this%unique_mask))
323 call unique_point_idx%free()
330 integer :: i, htable_data, idx(4), facet
331 real(kind=
rp) :: area, normal(3)
333 if (.not.
allocated(this%unique_mask))
return
334 if (this%unique_mask(0) .eq. 0)
return
336 do i = 1, this%unique_mask(0)
337 this%nx%x(i) = 0.0_rp
338 this%ny%x(i) = 0.0_rp
339 this%nz%x(i) = 0.0_rp
342 do i = 1, this%facet_node_msk(0)
343 htable_data = this%msk_to_unique(i)
344 facet = this%facet(i)
346 idx =
nonlinear_index(this%facet_node_msk(i), this%Xh%lx, this%Xh%lx, &
348 normal = this%coef%get_normal(idx(1), idx(2), idx(3), idx(4), facet)
349 area = this%coef%get_area(idx(1), idx(2), idx(3), idx(4), facet)
350 normal = normal * area
351 this%nx%x(htable_data) = this%nx%x(htable_data) + normal(1)
352 this%ny%x(htable_data) = this%ny%x(htable_data) + normal(2)
353 this%nz%x(htable_data) = this%nz%x(htable_data) + normal(3)
__inline__ __device__ void nonlinear_index(const int idx, const int lx, int *index)
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.
integer, parameter, public bc_dirichlet
Supported boundary condition types. The values are set in order of precedence for global resolution....
subroutine, public device_masked_scatter_copy_0(a_d, b_d, mask_d, n, n_mask, strm)
Scatter a masked vector .
subroutine, public device_col2(a_d, b_d, n, strm)
Vector multiplication .
subroutine, public device_masked_gather_copy_0(a_d, b_d, mask_d, n, n_mask, strm)
Gather a masked vector .
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.
Dirichlet condition applied in the facet normal direction.
subroutine facet_normal_init_from_components(this, coef)
Constructor from components.
subroutine facet_normal_apply_vector_dev(this, x_d, y_d, z_d, time, strong, strm)
No-op vector apply on device.
subroutine facet_normal_apply_scalar_dev(this, x_d, time, strong, strm)
No-op scalar apply on device.
subroutine facet_normal_init(this, coef, json)
Constructor.
subroutine facet_normal_recompute_normals(this)
Recompute area-weighted normals from the current mesh.
subroutine facet_normal_apply_scalar(this, x, n, time, strong)
No-op scalar apply.
subroutine facet_normal_finalize(this)
Finalize.
subroutine facet_normal_apply_surfvec_dev(this, x_d, y_d, z_d, u_d, v_d, w_d, time, strm)
Apply in facet normal direction (vector valued, device version)
subroutine facet_normal_apply_surfvec(this, x, y, z, u, v, w, n, time)
Apply in facet normal direction (vector valued)
subroutine facet_normal_apply_vector(this, x, y, z, n, time, strong)
No-op vector apply.
subroutine facet_normal_free(this)
Destructor.
Implements a hash table ADT.
subroutine, public cfill_mask(a, c, n, mask, n_mask)
Fill a constant to a masked vector. .
integer, parameter neko_bcknd_device
integer, parameter, public rp
Global precision used in computations.
Module with things related to the simulation time.
Base type for a boundary condition.
Coefficients defined on a given (mesh, ) tuple. Arrays use indices (i,j,k,e): element e,...
Dirichlet condition in facet normal direction.
Integer based hash table.
A struct that contains all info about the time, expand as needed.