44 use,
intrinsic :: iso_c_binding
49 real(kind=
rp),
allocatable :: x(:,:,:,:)
55 logical :: internal_dofmap = .false.
56 character(len=NEKO_VARNAME_LEN) :: name =
""
57 type(c_ptr) :: x_d = c_null_ptr
60 procedure,
private, pass(this) :: init_external_dof => &
62 procedure,
private, pass(this) :: init_internal_dof => &
73 generic :: init => init_external_dof, init_internal_dof
75 generic ::
assignment(=) => assign_field, assign_scalar
79 generic :: add => add_field, add_scalar
97 generic :: init => init_field, init_internal_dof, init_external_dof
101 procedure, pass(this) :: init_internal_dof => &
104 procedure, pass(this) :: init_external_dof => &
114 class(
field_t),
intent(inout) :: this
115 type(
mesh_t),
target,
intent(in) :: msh
116 type(
space_t),
target,
intent(in) :: space
117 character(len=*),
optional :: fld_name
125 call this%dof%init(this%msh, this%Xh)
126 this%internal_dofmap = .true.
128 if (
present(fld_name))
then
129 call this%init_common(fld_name)
131 call this%init_common()
138 class(
field_t),
intent(inout) :: this
139 type(
dofmap_t),
target,
intent(in) :: dof
140 character(len=*),
optional :: fld_name
148 if (
present(fld_name))
then
149 call this%init_common(fld_name)
151 call this%init_common()
158 class(
field_t),
intent(inout) :: this
159 character(len=*),
optional :: fld_name
164 associate(lx => this%Xh%lx, ly => this%Xh%ly, &
165 lz => this%Xh%lz, nelv => this%msh%nelv)
167 fresh = .not.
allocated(this%x)
169 allocate(this%x(lx, ly, lz, nelv), stat = ierr)
172 if (
present(fld_name))
then
179 n = lx * ly * lz * nelv
182 real(c_rp) :: rp_dummy
183 integer(c_size_t) :: s
184 s = c_sizeof(rp_dummy) * n
202 class(
field_t),
intent(inout) :: this
205 if (
allocated(this%x))
then
206 if (neko_bcknd_device .eq. 1)
then
207 call device_unmap(this%x, this%x_d)
212 if (this%internal_dofmap)
then
215 this%internal_dofmap = .false.
229 class(
field_t),
intent(inout) :: this
230 integer,
intent(in) :: memdir
231 logical,
intent(in) :: sync
233 if (neko_bcknd_device .eq. 1)
then
234 call device_memcpy(this%x, this%x_d, this%size(), memdir, sync)
244 class(
field_t),
intent(inout) :: this
247 if (
allocated(this%x))
then
248 if (.not.
associated(this%Xh, g%Xh))
then
255 if (len_trim(this%name) == 0)
then
259 if (.not. g%internal_dofmap)
then
260 if (this%internal_dofmap)
then
263 this%internal_dofmap = .false.
267 if (this%internal_dofmap)
then
271 this%internal_dofmap = .true.
273 call this%dof%init(this%msh, this%Xh)
276 if (.not.
allocated(this%x))
then
278 allocate(this%x(this%Xh%lx, this%Xh%ly, this%Xh%lz, this%msh%nelv))
280 if (neko_bcknd_device .eq. 1)
then
281 call device_map(this%x, this%x_d, this%size())
286 if (neko_bcknd_device .eq. 1)
then
287 call device_copy(this%x_d, g%x_d, this%size())
289 call copy(this%x, g%x, this%dof%size())
296 class(
field_t),
intent(inout) :: this
297 real(kind=rp),
intent(in) :: a
299 if (neko_bcknd_device .eq. 1)
then
300 call device_cfill(this%x_d, a, this%size())
302 call cfill(this%x, a, this%size())
311 class(
field_t),
intent(inout) :: this
314 if (neko_bcknd_device .eq. 1)
then
315 call device_add2(this%x_d, g%x_d, this%size())
317 call add2(this%x, g%x, this%size())
326 class(
field_t),
intent(inout) :: this
327 real(kind=rp),
intent(in) :: a
329 if (neko_bcknd_device .eq. 1)
then
330 call device_cadd(this%x_d, a, this%size())
332 call cadd(this%x, a, this%size())
339 class(
field_t),
intent(in) :: this
342 size = this%dof%size()
350 type(
field_t),
target,
intent(in) :: ptr
361 if (
associated(this%ptr))
then
382 type(mesh_t),
target,
intent(in) :: msh
383 type(space_t),
target,
intent(in) :: space
384 character(len=*),
optional :: fld_name
388 call this%field%init(msh,
space, fld_name)
394 type(dofmap_t),
target,
intent(in) :: dof
395 character(len=*),
optional :: fld_name
399 call this%field%init(dof, fld_name)
406 if (
associated(this%field))
then
407 call this%field%free()
408 deallocate(this%field)
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)
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_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.
integer, parameter, public neko_varname_len
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.