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)
105 integer,
intent(in) :: n
106 real(kind=
rp),
intent(inout),
dimension(n) :: x
108 logical,
intent(in),
optional :: strong
114 type(c_ptr),
intent(inout) :: x_d
116 logical,
intent(in),
optional :: strong
117 type(c_ptr),
intent(inout) :: strm
125 type(c_ptr),
intent(inout) :: x_d
126 type(c_ptr),
intent(inout) :: y_d
127 type(c_ptr),
intent(inout) :: z_d
129 logical,
intent(in),
optional :: strong
130 type(c_ptr),
intent(inout) :: strm
137 integer,
intent(in) :: n
138 real(kind=
rp),
intent(inout),
dimension(n) :: x
139 real(kind=
rp),
intent(inout),
dimension(n) :: y
140 real(kind=
rp),
intent(inout),
dimension(n) :: z
142 logical,
intent(in),
optional :: strong
148 integer,
intent(in) :: n
149 real(kind=
rp),
intent(inout),
dimension(n) :: x
150 real(kind=
rp),
intent(inout),
dimension(n) :: y
151 real(kind=
rp),
intent(inout),
dimension(n) :: z
152 real(kind=
rp),
intent(inout),
dimension(n) :: u
153 real(kind=
rp),
intent(inout),
dimension(n) :: v
154 real(kind=
rp),
intent(inout),
dimension(n) :: w
156 integer :: i, m, k, idx(4), facet
157 real(kind=
rp) :: normal(3), area
159 m = this%unique_mask(0)
164 k = this%unique_mask(i)
165 x(k) = u(k) * this%nx%x(i)
166 y(k) = v(k) * this%ny%x(i)
167 z(k) = w(k) * this%nz%x(i)
175 u_d, v_d, w_d, time, strm)
177 type(c_ptr) :: x_d, y_d, z_d, u_d, v_d, w_d
179 type(c_ptr),
optional :: strm
183 n = this%coef%dof%size()
184 m = this%unique_mask(0)
186 if (
present(strm))
then
194 this%unique_mask_d, n, m, strm_)
195 call device_col2(this%work%x_d, this%nx%x_d, m, strm_)
197 this%unique_mask_d, n, m, strm_)
199 this%unique_mask_d, n, m, strm_)
200 call device_col2(this%work%x_d, this%ny%x_d, m, strm_)
202 this%unique_mask_d, n, m, strm_)
204 this%unique_mask_d, n, m, strm_)
205 call device_col2(this%work%x_d, this%nz%x_d, m, strm)
207 this%unique_mask_d, n, m, strm_)
216 call this%free_base()
217 if (
allocated(this%unique_mask))
then
221 deallocate(this%unique_mask)
223 if (
allocated(this%msk_to_unique))
deallocate(this%msk_to_unique)
228 call this%work%free()
235 logical,
optional,
intent(in) :: only_facets
236 logical :: only_facets_
238 integer :: htable_data, rcode, i, j, idx(4), facet
239 real(kind=
rp) :: area, normal(3)
241 if (
present(only_facets))
then
242 if (.not. only_facets)
then
243 call neko_error(
"For facet_normal_t, only_facets has to be true.")
247 call this%finalize_base(.true.)
258 if (
allocated(this%unique_mask))
then
262 deallocate(this%unique_mask)
264 if (
allocated(this%msk_to_unique))
deallocate(this%msk_to_unique)
266 call unique_point_idx%init(this%msk(0), htable_data)
268 do i = 1, this%msk(0)
269 if (unique_point_idx%get(this%msk(i), htable_data) .ne. 0)
then
272 call unique_point_idx%set(this%msk(i), j)
277 if (unique_point_idx%num_entries() .gt. 0 )
then
278 call this%nx%init(unique_point_idx%num_entries())
279 call this%ny%init(unique_point_idx%num_entries())
280 call this%nz%init(unique_point_idx%num_entries())
281 call this%work%init(unique_point_idx%num_entries())
283 allocate(this%unique_mask(0:unique_point_idx%num_entries()))
284 allocate(this%msk_to_unique(this%msk(0)))
286 this%unique_mask(0) = unique_point_idx%num_entries()
287 do i = 1, this%unique_mask(0)
288 this%unique_mask(i) = 0
292 do i = 1, this%msk(0)
293 rcode = unique_point_idx%get(this%msk(i), htable_data)
294 if (rcode .ne. 0)
call neko_error(
"Facet normal: htable get failed.")
295 this%unique_mask(htable_data) = this%msk(i)
298 this%msk_to_unique(i) = htable_data
299 facet = this%facet(i)
302 normal = this%coef%get_normal(idx(1), idx(2), idx(3), idx(4), facet)
303 area = this%coef%get_area(idx(1), idx(2), idx(3), idx(4), facet)
304 normal = normal * area
305 this%nx%x(htable_data) = this%nx%x(htable_data) + normal(1)
306 this%ny%x(htable_data) = this%ny%x(htable_data) + normal(2)
307 this%nz%x(htable_data) = this%nz%x(htable_data) + normal(3)
311 (unique_point_idx%num_entries() .gt. 0 ))
then
312 call device_map(this%unique_mask, this%unique_mask_d, &
313 size(this%unique_mask))
324 call unique_point_idx%free()
331 integer :: i, htable_data, idx(4), facet
332 real(kind=
rp) :: area, normal(3)
334 if (.not.
allocated(this%unique_mask))
return
335 if (this%unique_mask(0) .eq. 0)
return
337 do i = 1, this%unique_mask(0)
338 this%nx%x(i) = 0.0_rp
339 this%ny%x(i) = 0.0_rp
340 this%nz%x(i) = 0.0_rp
343 do i = 1, this%msk(0)
344 htable_data = this%msk_to_unique(i)
345 facet = this%facet(i)
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.
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_finalize(this, only_facets)
Finalize.
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_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.