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.
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
47 type, public :: field_list_t
48 type(field_ptr_t), allocatable :: items(:)
49 contains
51 procedure, pass(this) :: init => field_list_init
53 procedure, pass(this) :: free => field_list_free
55 procedure, pass(this) :: append => field_list_append
56 generic :: get => get_by_index, get_by_name
58 procedure, pass(this) :: get_by_index => field_list_get_by_index
60 procedure, pass(this) :: get_by_name => field_list_get_by_name
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
71 procedure, pass(this) :: x_d => field_list_x_d
73 procedure, pass(this) :: x => field_list_x
75 procedure, pass(this) :: size => field_list_size
77 procedure, pass(this) :: item_size => field_list_item_size
79 procedure, pass(this) :: dof => field_list_dof
81 procedure, pass(this) :: xh => field_list_space
83 procedure, pass(this) :: msh => field_list_msh
85 procedure, pass(this) :: internal_dofmap => field_list_internal_dofmap
87 procedure, pass(this) :: name => field_list_name
89 procedure, pass(this) :: copy_from => field_list_copy_from
90 end type field_list_t
91
92contains
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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:58
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