43 use,
intrinsic :: iso_c_binding
48 real(kind=
rp),
allocatable :: x(:,:,:,:)
54 logical :: internal_dofmap = .false.
55 character(len=80) :: name =
""
56 type(c_ptr) :: x_d = c_null_ptr
59 procedure,
private, pass(this) :: init_external_dof => &
61 procedure,
private, pass(this) :: init_internal_dof => &
72 generic :: init => init_external_dof, init_internal_dof
74 generic ::
assignment(=) => assign_field, assign_scalar
78 generic :: add => add_field, add_scalar
96 generic :: init => init_field, init_internal_dof, init_external_dof
100 procedure, pass(this) :: init_internal_dof => &
103 procedure, pass(this) :: init_external_dof => &
113 class(
field_t),
intent(inout) :: this
114 type(
mesh_t),
target,
intent(in) :: msh
115 type(
space_t),
target,
intent(in) :: space
116 character(len=*),
optional :: fld_name
124 call this%dof%init(this%msh, this%Xh)
125 this%internal_dofmap = .true.
127 if (
present(fld_name))
then
128 call this%init_common(fld_name)
130 call this%init_common()
137 class(
field_t),
intent(inout) :: this
138 type(
dofmap_t),
target,
intent(in) :: dof
139 character(len=*),
optional :: fld_name
147 if (
present(fld_name))
then
148 call this%init_common(fld_name)
150 call this%init_common()
157 class(
field_t),
intent(inout) :: this
158 character(len=*),
optional :: fld_name
162 associate(lx => this%Xh%lx, ly => this%Xh%ly, &
163 lz => this%Xh%lz, nelv => this%msh%nelv)
165 if (.not.
allocated(this%x))
then
166 allocate(this%x(lx, ly, lz, nelv), stat = ierr)
170 if (
present(fld_name))
then
177 n = lx * ly * lz * nelv
180 real(c_rp) :: rp_dummy
181 integer(c_size_t) :: s
182 s = c_sizeof(rp_dummy) * n
192 class(
field_t),
intent(inout) :: this
195 if (
allocated(this%x))
then
199 if (this%internal_dofmap)
then
202 this%internal_dofmap = .false.
209 if (c_associated(this%x_d))
then
210 call device_free(this%x_d)
220 class(
field_t),
intent(inout) :: this
221 integer,
intent(in) :: memdir
222 logical,
intent(in) :: sync
224 if (neko_bcknd_device .eq. 1)
then
225 call device_memcpy(this%x, this%x_d, this%size(), memdir, sync)
235 class(
field_t),
intent(inout) :: this
238 if (
allocated(this%x))
then
239 if (.not.
associated(this%Xh, g%Xh))
then
246 if (len_trim(this%name) == 0)
then
250 if (.not. g%internal_dofmap)
then
253 if (this%internal_dofmap)
then
257 this%internal_dofmap = .true.
259 call this%dof%init(this%msh, this%Xh)
262 if (.not.
allocated(this%x))
then
264 allocate(this%x(this%Xh%lx, this%Xh%ly, this%Xh%lz, this%msh%nelv))
266 if (neko_bcknd_device .eq. 1)
then
267 call device_map(this%x, this%x_d, this%size())
272 if (neko_bcknd_device .eq. 1)
then
273 call device_copy(this%x_d, g%x_d, this%size())
275 call copy(this%x, g%x, this%dof%size())
282 class(
field_t),
intent(inout) :: this
283 real(kind=rp),
intent(in) :: a
284 integer :: i, j, k, l
286 if (neko_bcknd_device .eq. 1)
then
287 call device_cfill(this%x_d, a, this%size())
289 call cfill(this%x, a, this%size())
298 class(
field_t),
intent(inout) :: this
301 if (neko_bcknd_device .eq. 1)
then
302 call device_add2(this%x_d, g%x_d, this%size())
304 call add2(this%x, g%x, this%size())
313 class(
field_t),
intent(inout) :: this
314 real(kind=rp),
intent(in) :: a
316 if (neko_bcknd_device .eq. 1)
then
317 call device_cadd(this%x_d, a, this%size())
319 call cadd(this%x, a, this%size())
326 class(
field_t),
intent(in) :: this
329 size = this%dof%size()
337 type(
field_t),
target,
intent(in) :: ptr
348 if (
associated(this%ptr))
then
369 type(mesh_t),
target,
intent(in) :: msh
370 type(space_t),
target,
intent(in) :: space
371 character(len=*),
optional :: fld_name
375 call this%field%init(msh,
space, fld_name)
381 type(dofmap_t),
target,
intent(in) :: dof
382 character(len=*),
optional :: fld_name
386 call this%field%init(dof, fld_name)
393 if (
associated(this%field))
then
394 call this%field%free()
395 deallocate(this%field)
Map a Fortran array to a device (allocate and associate)
Copy data between host and device (or device and device)
subroutine, public device_add2(a_d, b_d, n, strm)
Vector addition .
subroutine, public device_copy(a_d, b_d, n, strm)
Copy a vector .
subroutine, public device_cfill(a_d, c, n, strm)
Set all elements to a constant c .
Device abstraction, common interface for various accelerators.
subroutine, public device_free(x_d)
Deallocate memory on the device.
subroutine, public device_memset(x_d, v, s, sync, strm)
Set memory on the device to a value.
Defines a mapping of the degrees of freedom.
subroutine field_add_field(this, g)
Add .
pure integer function field_size(this)
Return the size of the field based on the underlying dofmap.
subroutine field_assign_field(this, g)
Assignment .
subroutine field_wrapper_free(this)
subroutine field_add_scalar(this, a)
Add .
subroutine field_copy_from(this, memdir, sync)
Easy way to copy between host and device.
subroutine field_assign_scalar(this, a)
Assignment .
subroutine field_ptr_init(this, ptr)
subroutine field_ptr_free(this)
subroutine field_wrapper_init_internal_dof(this, msh, space, fld_name)
subroutine field_init_common(this, fld_name)
Initialize a field this.
subroutine field_wrapper_init_external_dof(this, dof, fld_name)
subroutine field_wrapper_init_field(this, f)
subroutine field_init_external_dof(this, dof, fld_name)
Initialize a field this on the mesh msh using an internal dofmap.
subroutine field_init_internal_dof(this, msh, space, fld_name)
Initialize a field this on the mesh msh using an internal dofmap.
subroutine field_free(this)
Deallocate a field f.
subroutine, public cadd(a, s, n)
Add a scalar to vector .
subroutine, public add2(a, b, n)
Vector addition .
subroutine, public cfill(a, c, n)
Set all elements to a constant c .
subroutine, public copy(a, b, n)
Copy a vector .
integer, parameter neko_bcknd_device
integer, parameter, public c_rp
integer, parameter, public rp
Global precision used in computations.
Defines a function space.
field_ptr_t, To easily obtain a pointer to a field
field_wrapper_t, used to wrap an allocated field for use in a field list
The function space for the SEM solution fields.