Neko 1.99.11
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
field_list.f90
Go to the documentation of this file.
1! Copyright (c) 2023-2026, The Neko Authors
2! All rights reserved.
3!
4! Redistribution and use in source and binary forms, with or without
5! modification, are permitted provided that the following conditions
6! are met:
7!
8! * Redistributions of source code must retain the above copyright
9! notice, this list of conditions and the following disclaimer.
10!
11! * Redistributions in binary form must reproduce the above
12! copyright notice, this list of conditions and the following
13! disclaimer in the documentation and/or other materials provided
14! with the distribution.
15!
16! * Neither the name of the authors nor the names of its
17! contributors may be used to endorse or promote products derived
18! from this software without specific prior written permission.
19!
20! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21! "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22! LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23! FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24! COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25! INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26! BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27! LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28! CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29! LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30! ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31! POSSIBILITY OF SUCH DAMAGE.
32!
34 use, intrinsic :: iso_fortran_env, only : error_unit
35 use field, only : field_ptr_t, field_t
36 use iso_c_binding, only : c_ptr
37 use num_types, only : rp
38 use space, only : space_t
39 use dofmap, only : dofmap_t
40 use mesh, only : mesh_t
41 use utils, only : neko_error
42 use comm, only : pe_rank
43 implicit none
44 private
45
46 !> field_list_t, To be able to group fields together
47 type, public :: field_list_t
48 type(field_ptr_t), allocatable :: items(:)
49 contains
50 !> Constructor. Allocates array and pointers.
51 procedure, pass(this) :: init => field_list_init
52 !> Destructor.
53 procedure, pass(this) :: free => field_list_free
54 !> Append a field to the list.
55 procedure, pass(this) :: append => field_list_append
56 generic :: get => get_by_index, get_by_name
57 !> Get an item pointer by array index
58 procedure, pass(this) :: get_by_index => field_list_get_by_index
59 !> Get an item pointer by field name
60 procedure, pass(this) :: get_by_name => field_list_get_by_name
61 !> Point item at given index.
62 generic :: assign => assign_to_ptr, assign_to_field_ptr, &
63 assign_to_list
64 procedure, pass(this) :: assign_to_ptr => field_list_assign_to_ptr
65 procedure, pass(this) :: assign_to_field_ptr => &
67 procedure, pass(this) :: assign_to_field => field_list_assign_to_field
68 procedure, pass(this) :: assign_to_list => field_list_assign_to_field_list
69
70 !> Get device pointer for a given index.
71 procedure, pass(this) :: x_d => field_list_x_d
72 !> Get pointer to the raw data array for a given index.
73 procedure, pass(this) :: x => field_list_x
74 !> Get number of items in the list.
75 procedure, pass(this) :: size => field_list_size
76 !> Get the size of dofmap for an item in the list.
77 procedure, pass(this) :: item_size => field_list_item_size
78 !> Get the dofmap for an item in the list.
79 procedure, pass(this) :: dof => field_list_dof
80 !> Get the space for an item in the list.
81 procedure, pass(this) :: xh => field_list_space
82 !> Get the mesh for an item in the list.
83 procedure, pass(this) :: msh => field_list_msh
84 !> Check wether the dofmap is internal for an item in the list.
85 procedure, pass(this) :: internal_dofmap => field_list_internal_dofmap
86 !> Get the name for an item in the list.
87 procedure, pass(this) :: name => field_list_name
88 !> Copy all fields to or from the design.
89 procedure, pass(this) :: copy_from => field_list_copy_from
90 end type field_list_t
91
92contains
93 !> Constructor. Just allocates the array.
94 !! @param size The size of the list to preallocate
95 subroutine field_list_init(this, size)
96 class(field_list_t), intent(inout) :: this
97 integer, intent(in) :: size
98
99 call this%free()
100 allocate(this%items(size))
101
102 end subroutine field_list_init
103
104 !> Get number of items in the list.
105 pure function field_list_size(this) result(n)
106 class(field_list_t), intent(in) :: this
107 integer :: n
108
109 if (allocated(this%items)) then
110 n = size(this%items)
111 else
112 n = 0
113 end if
114
115 end function field_list_size
116
117 !> Get an item pointer by array index
118 !! @param i The index of the item.
119 function field_list_get_by_index(this, i) result(f)
120 class(field_list_t), intent(inout) :: this
121 type(field_t), pointer :: f
122 integer, intent(in) :: i
123 f => this%items(i)%ptr
124 end function field_list_get_by_index
125
126 !> Get an item pointer by array index
127 !! @param i The index of the item.
128 function field_list_get_by_name(this, name) result(f)
129 class(field_list_t), intent(inout) :: this
130 type(field_t), pointer :: f
131 character(len=*), intent(in) :: name
132 integer :: i
133
134 nullify(f)
135
136 do i = 1, this%size()
137 if (this%name(i) .eq. trim(name)) then
138 f => this%items(i)%ptr
139 return
140 end if
141 end do
142
143 if (pe_rank .eq. 0) then
144 write(error_unit,*) "Current field list contents:"
145
146 do i = 1, this%size()
147 write(error_unit,*) "- ", this%name(i)
148 end do
149 end if
150
151 call neko_error("No field with name " // trim(name) // " found in list")
152 end function field_list_get_by_name
153
154 !> Append a field to the list.
155 !! @param f The field to append.
156 subroutine field_list_append(this, f)
157 class(field_list_t), intent(inout) :: this
158 class(field_t), intent(in), target :: f
159 type(field_ptr_t), allocatable :: tmp(:)
160 integer :: len
161
162 if (.not. allocated(this%items)) then
163 allocate(this%items(1))
164 call this%items(1)%init(f)
165 return
166 end if
167
168 len = size(this%items)
169
170 allocate(tmp(len+1))
171 tmp(1:len) = this%items
172 call move_alloc(tmp, this%items)
173 call this%items(len+1)%init(f)
174
175 end subroutine field_list_append
176
177 !> Destructor.
178 subroutine field_list_free(this)
179 class(field_list_t), intent(inout) :: this
180 integer :: i, n_fields
181
182 if (allocated(this%items)) then
183 n_fields = this%size()
184 do i = 1, n_fields
185 call this%items(i)%free()
186 end do
187 deallocate(this%items)
188 end if
189
190 end subroutine field_list_free
191
192 !> Get device pointer for a given index
193 !! @param i The index of the item.
194 function field_list_x_d(this, i) result(ptr)
195 class(field_list_t), intent(in) :: this
196 integer, intent(in) :: i
197 type(c_ptr) :: ptr
198
199 ptr = this%items(i)%ptr%x_d
200 end function field_list_x_d
201
202 function field_list_x(this, i) result(x)
203 class(field_list_t), target, intent(in) :: this
204 real(kind=rp), pointer, contiguous :: x(:,:,:,:)
205 integer, intent(in) :: i
206 x => this%items(i)%ptr%x
207 end function field_list_x
208
209 !> Get the size of the dofmap for item `i`.
210 !! @param i The index of the item.
211 function field_list_item_size(this, i) result(size)
212 class(field_list_t), target, intent(in) :: this
213 integer, intent(in) :: i
214 integer :: size
215
216 size = this%items(i)%ptr%size()
217
218 end function field_list_item_size
219
220 !> Point item at a given index.
221 !! @param i The index of the item.
222 !! @param ptr A field pointer to point the item to.
223 subroutine field_list_assign_to_ptr(this, i, ptr)
224 class(field_list_t), intent(inout) :: this
225 integer, intent(in) :: i
226 type(field_t), pointer, intent(in) :: ptr
227
228 call this%items(i)%init(ptr)
229
230 end subroutine field_list_assign_to_ptr
231
232 !> Point item at a given index.
233 !! @param i The index of the item.
234 !! @param ptr An encapsulated field pointer to point the item to.
235 subroutine field_list_assign_to_field_ptr(this, i, ptr)
236 class(field_list_t), intent(inout) :: this
237 integer, intent(in) :: i
238 type(field_ptr_t), target, intent(in) :: ptr
239
240 call this%items(i)%init(ptr%ptr)
241 end subroutine field_list_assign_to_field_ptr
242
243 !> Point item at a given index.
244 !! @param i The index of the item.
245 !! @param field A field to point the item to.
246 subroutine field_list_assign_to_field(this, i, fld)
247 class(field_list_t), intent(inout) :: this
248 integer, intent(in) :: i
249 type(field_t), target, intent(in) :: fld
250
251 call this%items(i)%init(fld)
252 end subroutine field_list_assign_to_field
253
254 !> Point item at a given index.
255 !! @param i The index of the item.
256 !! @param field A field to point the item to.
257 subroutine field_list_assign_to_field_list(this, other)
258 class(field_list_t), intent(inout) :: this
259 type(field_list_t), intent(in) :: other
260 integer :: i
261
262 call this%free()
263 call this%init(other%size())
264 do i = 1, other%size()
265 call this%assign(i, other%items(i)%ptr)
266 end do
268
269 !> Get the the dofmap for item `i`.
270 !! @param i The index of the item.
271 function field_list_dof(this, i) result(result)
272 class(field_list_t), target, intent(in) :: this
273 integer, intent(in) :: i
274 type(dofmap_t), pointer :: result
275
276 result => this%items(i)%ptr%dof
277 end function field_list_dof
278
279 !> Get the the space for item `i`.
280 !! @param i The index of the item.
281 function field_list_space(this, i) result(result)
282 class(field_list_t), target, intent(in) :: this
283 integer, intent(in) :: i
284 type(space_t), pointer :: result
285
286 result => this%items(i)%ptr%Xh
287 end function field_list_space
288
289 !> Get the the mesh for item `i`.
290 !! @param i The index of the item.
291 function field_list_msh(this, i) result(result)
292 class(field_list_t), target, intent(in) :: this
293 integer, intent(in) :: i
294 type(mesh_t), pointer :: result
295
296 result => this%items(i)%ptr%msh
297 end function field_list_msh
298
299 !> Whether the dofmap is internal for item `i`.
300 !! @param i The index of the item.
301 function field_list_internal_dofmap(this, i) result(result)
302 class(field_list_t), target, intent(in) :: this
303 integer, intent(in) :: i
304 logical :: result
305
306 result = this%items(i)%ptr%internal_dofmap
307 end function field_list_internal_dofmap
308
309 !> Get the name for an item in the list.
310 !! @param i The index of the item.
311 function field_list_name(this, i) result(result)
312 class(field_list_t), target, intent(in) :: this
313 integer, intent(in) :: i
314 character(len=80) :: result
315
316 result = this%items(i)%ptr%name
317 end function field_list_name
318
319 !> Copy all fields to or from device.
320 !! @details Call the memory copy for each field in the list. If `sync` is
321 !! true, synchronize on the last copy.
322 !! @param memdir The direction of the copy.
323 !! @param sync Whether to synchronize after the copy.
324 subroutine field_list_copy_from(this, memdir, sync)
325 class(field_list_t), intent(inout) :: this
326 integer, intent(in) :: memdir
327 logical, intent(in) :: sync
328 integer :: i, n
329
330 n = this%size()
331 if (n .eq. 0) return
332
333 do i = 1, n - 1
334 call this%items(i)%ptr%copy_from(memdir, .false.)
335 end do
336 call this%items(n)%ptr%copy_from(memdir, sync)
337
338 end subroutine field_list_copy_from
339
340end module field_list
Definition comm.F90:1
integer, public pe_rank
MPI rank.
Definition comm.F90:59
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:14
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:64