47 real(kind=
rp),
allocatable :: x(:,:,:,:)
53 logical :: internal_dofmap = .false.
54 character(len=80) :: name
55 type(c_ptr) :: x_d = c_null_ptr
58 procedure,
private, pass(this) :: init_external_dof => &
60 procedure,
private, pass(this) :: init_internal_dof => &
70 generic :: init => init_external_dof, init_internal_dof
72 generic ::
assignment(=) => assign_field, assign_scalar
76 generic :: add => add_field, add_scalar
88 class(
field_t),
intent(inout) :: this
89 type(
mesh_t),
target,
intent(in) :: msh
90 type(
space_t),
target,
intent(in) :: space
91 character(len=*),
optional :: fld_name
99 call this%dof%init(this%msh, this%Xh)
100 this%internal_dofmap = .true.
102 if (
present(fld_name))
then
103 call this%init_common(fld_name)
105 call this%init_common()
112 class(
field_t),
intent(inout) :: this
113 type(
dofmap_t),
target,
intent(in) :: dof
114 character(len=*),
optional :: fld_name
122 if (
present(fld_name))
then
123 call this%init_common(fld_name)
125 call this%init_common()
132 class(
field_t),
intent(inout) :: this
133 character(len=*),
optional :: fld_name
137 associate(lx => this%Xh%lx, ly => this%Xh%ly, &
138 lz => this%Xh%lz, nelv => this%msh%nelv)
140 if (.not.
allocated(this%x))
then
141 allocate(this%x(lx, ly, lz, nelv), stat = ierr)
145 if (
present(fld_name))
then
152 n = lx * ly * lz * nelv
161 class(
field_t),
intent(inout) :: this
163 if (
allocated(this%x))
then
167 if (this%internal_dofmap)
then
169 this%internal_dofmap = .false.
176 if (c_associated(this%x_d))
then
177 call device_free(this%x_d)
186 class(
field_t),
intent(inout) :: this
189 if (
allocated(this%x))
then
190 if (this%Xh .ne. g%Xh)
then
204 if (.not.
allocated(this%x))
then
206 allocate(this%x(this%Xh%lx, this%Xh%ly, this%Xh%lz, this%msh%nelv))
208 if (neko_bcknd_device .eq. 1)
then
209 call device_map(this%x, this%x_d, this%size())
214 if (neko_bcknd_device .eq. 1)
then
215 call device_copy(this%x_d, g%x_d, this%size())
217 call copy(this%x, g%x, this%dof%size())
224 class(
field_t),
intent(inout) :: this
225 real(kind=rp),
intent(in) :: a
226 integer :: i, j, k, l
228 if (neko_bcknd_device .eq. 1)
then
229 call device_cfill(this%x_d, a, this%size())
231 do i = 1, this%msh%nelv
235 this%x(j, k, l, i) = a
248 class(
field_t),
intent(inout) :: this
251 if (neko_bcknd_device .eq. 1)
then
252 call device_add2(this%x_d, g%x_d, this%size())
254 call add2(this%x, g%x, this%size())
263 class(
field_t),
intent(inout) :: this
264 real(kind=rp),
intent(in) :: a
266 if (neko_bcknd_device .eq. 1)
then
267 call device_cadd(this%x_d, a, this%size())
269 call cadd(this%x, a, this%size())
276 class(
field_t),
intent(in) :: this
279 size = this%dof%size()
Map a Fortran array to a device (allocate and associate)
Device abstraction, common interface for various accelerators.
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_add_scalar(this, a)
Add .
subroutine field_assign_scalar(this, a)
Assignment .
subroutine field_init_common(this, fld_name)
Initialize a field this.
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 copy(a, b, n)
Copy a vector .
integer, parameter neko_bcknd_device
integer, parameter, public rp
Global precision used in computations.
Defines a function space.
field_ptr_t, To easily obtain a pointer to a field
The function space for the SEM solution fields.