Neko 1.99.3
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
field_list.f90
Go to the documentation of this file.
2 use, intrinsic :: iso_fortran_env, only : error_unit
3 use field, only : field_ptr_t, field_t
4 use iso_c_binding, only : c_ptr
5 use num_types, only : rp
6 use space, only : space_t
7 use dofmap, only : dofmap_t
8 use mesh, only : mesh_t
9 use utils, only : neko_error
10 use comm, only : pe_rank
11 implicit none
12 private
13
15 type, public :: field_list_t
16 type(field_ptr_t), allocatable :: items(:)
17 contains
19 procedure, pass(this) :: init => field_list_init
21 procedure, pass(this) :: free => field_list_free
23 procedure, pass(this) :: append => field_list_append
24 generic :: get => get_by_index, get_by_name
26 procedure, pass(this) :: get_by_index => field_list_get_by_index
28 procedure, pass(this) :: get_by_name => field_list_get_by_name
30 generic :: assign => assign_to_ptr, assign_to_field_ptr, &
31 assign_to_list
32 procedure, pass(this) :: assign_to_ptr => field_list_assign_to_ptr
33 procedure, pass(this) :: assign_to_field_ptr => &
35 procedure, pass(this) :: assign_to_field => field_list_assign_to_field
36 procedure, pass(this) :: assign_to_list => field_list_assign_to_field_list
37
39 procedure, pass(this) :: x_d => field_list_x_d
41 procedure, pass(this) :: x => field_list_x
43 procedure, pass(this) :: size => field_list_size
45 procedure, pass(this) :: item_size => field_list_item_size
47 procedure, pass(this) :: dof => field_list_dof
49 procedure, pass(this) :: xh => field_list_space
51 procedure, pass(this) :: msh => field_list_msh
53 procedure, pass(this) :: internal_dofmap => field_list_internal_dofmap
55 procedure, pass(this) :: name => field_list_name
57 procedure, pass(this) :: copy_from => field_list_copy_from
58 end type field_list_t
59
60contains
63 subroutine field_list_init(this, size)
64 class(field_list_t), intent(inout) :: this
65 integer, intent(in) :: size
66
67 call this%free()
68 allocate(this%items(size))
69
70 end subroutine field_list_init
71
73 pure function field_list_size(this) result(n)
74 class(field_list_t), intent(in) :: this
75 integer :: n
76
77 if (allocated(this%items)) then
78 n = size(this%items)
79 else
80 n = 0
81 end if
82
83 end function field_list_size
84
87 function field_list_get_by_index(this, i) result(f)
88 class(field_list_t), intent(inout) :: this
89 type(field_t), pointer :: f
90 integer, intent(in) :: i
91 f => this%items(i)%ptr
92 end function field_list_get_by_index
93
96 function field_list_get_by_name(this, name) result(f)
97 class(field_list_t), intent(inout) :: this
98 type(field_t), pointer :: f
99 character(len=*), intent(in) :: name
100 integer :: i
101
102 nullify(f)
103
104 do i = 1, this%size()
105 if (this%name(i) .eq. trim(name)) then
106 f => this%items(i)%ptr
107 return
108 end if
109 end do
110
111 if (pe_rank .eq. 0) then
112 write(error_unit,*) "Current field list contents:"
113
114 do i = 1, this%size()
115 write(error_unit,*) "- ", this%name(i)
116 end do
117 end if
118
119 call neko_error("No field with name " // trim(name) // " found in list")
120 end function field_list_get_by_name
121
124 subroutine field_list_append(this, f)
125 class(field_list_t), intent(inout) :: this
126 class(field_t), intent(in), target :: f
127 type(field_ptr_t), allocatable :: tmp(:)
128 integer :: len
129
130 if (.not. allocated(this%items)) then
131 allocate(this%items(1))
132 call this%items(1)%init(f)
133 return
134 end if
135
136 len = size(this%items)
137
138 allocate(tmp(len+1))
139 tmp(1:len) = this%items
140 call move_alloc(tmp, this%items)
141 call this%items(len+1)%init(f)
142
143 end subroutine field_list_append
144
146 subroutine field_list_free(this)
147 class(field_list_t), intent(inout) :: this
148 integer :: i, n_fields
149
150 if (allocated(this%items)) then
151 n_fields = this%size()
152 do i = 1, n_fields
153 call this%items(i)%free()
154 end do
155 deallocate(this%items)
156 end if
157
158 end subroutine field_list_free
159
162 function field_list_x_d(this, i) result(ptr)
163 class(field_list_t), intent(in) :: this
164 integer, intent(in) :: i
165 type(c_ptr) :: ptr
166
167 ptr = this%items(i)%ptr%x_d
168 end function field_list_x_d
169
170 function field_list_x(this, i) result(x)
171 class(field_list_t), target, intent(in) :: this
172 real(kind=rp), pointer, contiguous :: x(:,:,:,:)
173 integer, intent(in) :: i
174 x => this%items(i)%ptr%x
175 end function field_list_x
176
179 function field_list_item_size(this, i) result(size)
180 class(field_list_t), target, intent(in) :: this
181 integer, intent(in) :: i
182 integer :: size
183
184 size = this%items(i)%ptr%size()
185
186 end function field_list_item_size
187
191 subroutine field_list_assign_to_ptr(this, i, ptr)
192 class(field_list_t), intent(inout) :: this
193 integer, intent(in) :: i
194 type(field_t), pointer, intent(in) :: ptr
195
196 call this%items(i)%init(ptr)
197
198 end subroutine field_list_assign_to_ptr
199
203 subroutine field_list_assign_to_field_ptr(this, i, ptr)
204 class(field_list_t), intent(inout) :: this
205 integer, intent(in) :: i
206 type(field_ptr_t), target, intent(in) :: ptr
207
208 call this%items(i)%init(ptr%ptr)
209 end subroutine field_list_assign_to_field_ptr
210
214 subroutine field_list_assign_to_field(this, i, fld)
215 class(field_list_t), intent(inout) :: this
216 integer, intent(in) :: i
217 type(field_t), target, intent(in) :: fld
218
219 call this%items(i)%init(fld)
220 end subroutine field_list_assign_to_field
221
225 subroutine field_list_assign_to_field_list(this, other)
226 class(field_list_t), intent(inout) :: this
227 type(field_list_t), intent(in) :: other
228 integer :: i
229
230 call this%free()
231 call this%init(other%size())
232 do i = 1, other%size()
233 call this%assign(i, other%items(i)%ptr)
234 end do
236
239 function field_list_dof(this, i) result(result)
240 class(field_list_t), target, intent(in) :: this
241 integer, intent(in) :: i
242 type(dofmap_t), pointer :: result
243
244 result => this%items(i)%ptr%dof
245 end function field_list_dof
246
249 function field_list_space(this, i) result(result)
250 class(field_list_t), target, intent(in) :: this
251 integer, intent(in) :: i
252 type(space_t), pointer :: result
253
254 result => this%items(i)%ptr%Xh
255 end function field_list_space
256
259 function field_list_msh(this, i) result(result)
260 class(field_list_t), target, intent(in) :: this
261 integer, intent(in) :: i
262 type(mesh_t), pointer :: result
263
264 result => this%items(i)%ptr%msh
265 end function field_list_msh
266
269 function field_list_internal_dofmap(this, i) result(result)
270 class(field_list_t), target, intent(in) :: this
271 integer, intent(in) :: i
272 logical :: result
273
274 result = this%items(i)%ptr%internal_dofmap
275 end function field_list_internal_dofmap
276
279 function field_list_name(this, i) result(result)
280 class(field_list_t), target, intent(in) :: this
281 integer, intent(in) :: i
282 character(len=80) :: result
283
284 result = this%items(i)%ptr%name
285 end function field_list_name
286
292 subroutine field_list_copy_from(this, memdir, sync)
293 class(field_list_t), intent(inout) :: this
294 integer, intent(in) :: memdir
295 logical, intent(in) :: sync
296 integer :: i, n
297
298 n = this%size()
299 if (n .eq. 0) return
300
301 do i = 1, n - 1
302 call this%items(i)%ptr%copy_from(memdir, .false.)
303 end do
304 call this%items(n)%ptr%copy_from(memdir, sync)
305
306 end subroutine field_list_copy_from
307
308end module field_list
Definition comm.F90:1
integer, public pe_rank
MPI rank.
Definition comm.F90:56
Defines a mapping of the degrees of freedom.
Definition dofmap.f90:35
type(dofmap_t) function, pointer field_list_dof(this, i)
Get the the dofmap for item i.
subroutine field_list_init(this, size)
Constructor. Just allocates the array.
type(space_t) function, pointer field_list_space(this, i)
Get the the space for item i.
subroutine field_list_assign_to_field_list(this, other)
Point item at a given index.
subroutine field_list_assign_to_ptr(this, i, ptr)
Point item at a given index.
pure integer function field_list_size(this)
Get number of items in the list.
subroutine field_list_assign_to_field_ptr(this, i, ptr)
Point item at a given index.
integer function field_list_item_size(this, i)
Get the size of the dofmap for item i.
character(len=80) function field_list_name(this, i)
Get the name for an item in the list.
subroutine field_list_copy_from(this, memdir, sync)
Copy all fields to or from device.
logical function field_list_internal_dofmap(this, i)
Whether the dofmap is internal for item i.
real(kind=rp) function, dimension(:,:,:,:), pointer, contiguous field_list_x(this, i)
type(field_t) function, pointer field_list_get_by_index(this, i)
Get an item pointer by array index.
type(mesh_t) function, pointer field_list_msh(this, i)
Get the the mesh for item i.
subroutine field_list_assign_to_field(this, i, fld)
Point item at a given index.
type(c_ptr) function field_list_x_d(this, i)
Get device pointer for a given index.
subroutine field_list_free(this)
Destructor.
subroutine field_list_append(this, f)
Append a field to the list.
type(field_t) function, pointer field_list_get_by_name(this, name)
Get an item pointer by array index.
Defines a field.
Definition field.f90:34
Defines a mesh.
Definition mesh.f90:34
integer, parameter, public rp
Global precision used in computations.
Definition num_types.f90:12
Defines a function space.
Definition space.f90:34
Utilities.
Definition utils.f90:35
field_ptr_t, To easily obtain a pointer to a field
Definition field.f90:83
field_list_t, To be able to group fields together
The function space for the SEM solution fields.
Definition space.f90:63