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 procedure, pass(this) :: assign_to_ptr => field_list_assign_to_ptr
32 procedure, pass(this) :: assign_to_field_ptr => &
34 procedure, pass(this) :: assign_to_field => field_list_assign_to_field
35
37 procedure, pass(this) :: x_d => field_list_x_d
39 procedure, pass(this) :: x => field_list_x
41 procedure, pass(this) :: size => field_list_size
43 procedure, pass(this) :: item_size => field_list_item_size
45 procedure, pass(this) :: dof => field_list_dof
47 procedure, pass(this) :: xh => field_list_space
49 procedure, pass(this) :: msh => field_list_msh
51 procedure, pass(this) :: internal_dofmap => field_list_internal_dofmap
53 procedure, pass(this) :: name => field_list_name
54 end type field_list_t
55
56contains
59 subroutine field_list_init(this, size)
60 class(field_list_t), intent(inout) :: this
61 integer, intent(in) :: size
62
63 call this%free()
64 allocate(this%items(size))
65
66 end subroutine field_list_init
67
69 pure function field_list_size(this) result(n)
70 class(field_list_t), intent(in) :: this
71 integer :: n
72
73 if (allocated(this%items)) then
74 n = size(this%items)
75 else
76 n = 0
77 end if
78
79 end function field_list_size
80
83 function field_list_get_by_index(this, i) result(f)
84 class(field_list_t), intent(inout) :: this
85 type(field_t), pointer :: f
86 integer, intent(in) :: i
87 f => this%items(i)%ptr
88 end function field_list_get_by_index
89
92 function field_list_get_by_name(this, name) result(f)
93 class(field_list_t), intent(inout) :: this
94 type(field_t), pointer :: f
95 character(len=*), intent(in) :: name
96 integer :: i
97
98 nullify(f)
99
100 do i = 1, this%size()
101 if (this%name(i) .eq. trim(name)) then
102 f => this%items(i)%ptr
103 return
104 end if
105 end do
106
107 if (pe_rank .eq. 0) then
108 write(error_unit,*) "Current field list contents:"
109
110 do i = 1, this%size()
111 write(error_unit,*) "- ", this%name(i)
112 end do
113 end if
114
115 call neko_error("No field with name " // trim(name) // " found in list")
116 end function field_list_get_by_name
117
120 subroutine field_list_append(this, f)
121 class(field_list_t), intent(inout) :: this
122 class(field_t), intent(in), target :: f
123 type(field_ptr_t), allocatable :: tmp(:)
124 integer :: len
125
126 if (.not. allocated(this%items)) then
127 allocate(this%items(1))
128 call this%items(1)%init(f)
129 return
130 end if
131
132 len = size(this%items)
133
134 allocate(tmp(len+1))
135 tmp(1:len) = this%items
136 call move_alloc(tmp, this%items)
137 call this%items(len+1)%init(f)
138
139 end subroutine field_list_append
140
142 subroutine field_list_free(this)
143 class(field_list_t), intent(inout) :: this
144 integer :: i, n_fields
145
146 if (allocated(this%items)) then
147 n_fields = this%size()
148 do i = 1, n_fields
149 call this%items(i)%free()
150 end do
151 deallocate(this%items)
152 end if
153
154 end subroutine field_list_free
155
158 function field_list_x_d(this, i) result(ptr)
159 class(field_list_t), intent(in) :: this
160 integer, intent(in) :: i
161 type(c_ptr) :: ptr
162
163 ptr = this%items(i)%ptr%x_d
164 end function field_list_x_d
165
166 function field_list_x(this, i) result(x)
167 class(field_list_t), target, intent(in) :: this
168 real(kind=rp), pointer, contiguous :: x(:,:,:,:)
169 integer, intent(in) :: i
170 x => this%items(i)%ptr%x
171 end function field_list_x
172
175 function field_list_item_size(this, i) result(size)
176 class(field_list_t), target, intent(in) :: this
177 integer, intent(in) :: i
178 integer :: size
179
180 size = this%items(i)%ptr%size()
181
182 end function field_list_item_size
183
187 subroutine field_list_assign_to_ptr(this, i, ptr)
188 class(field_list_t), intent(inout) :: this
189 integer, intent(in) :: i
190 type(field_t), pointer, intent(in) :: ptr
191
192 call this%items(i)%init(ptr)
193
194 end subroutine field_list_assign_to_ptr
195
199 subroutine field_list_assign_to_field_ptr(this, i, ptr)
200 class(field_list_t), intent(inout) :: this
201 integer, intent(in) :: i
202 type(field_ptr_t), target, intent(in) :: ptr
203
204 call this%items(i)%init(ptr%ptr)
205 end subroutine field_list_assign_to_field_ptr
206
210 subroutine field_list_assign_to_field(this, i, fld)
211 class(field_list_t), intent(inout) :: this
212 integer, intent(in) :: i
213 type(field_t), target, intent(in) :: fld
214
215 call this%items(i)%init(fld)
216 end subroutine field_list_assign_to_field
217
220 function field_list_dof(this, i) result(result)
221 class(field_list_t), target, intent(in) :: this
222 integer, intent(in) :: i
223 type(dofmap_t), pointer :: result
224
225 result => this%items(i)%ptr%dof
226 end function field_list_dof
227
230 function field_list_space(this, i) result(result)
231 class(field_list_t), target, intent(in) :: this
232 integer, intent(in) :: i
233 type(space_t), pointer :: result
234
235 result => this%items(i)%ptr%Xh
236 end function field_list_space
237
240 function field_list_msh(this, i) result(result)
241 class(field_list_t), target, intent(in) :: this
242 integer, intent(in) :: i
243 type(mesh_t), pointer :: result
244
245 result => this%items(i)%ptr%msh
246 end function field_list_msh
247
250 function field_list_internal_dofmap(this, i) result(result)
251 class(field_list_t), target, intent(in) :: this
252 integer, intent(in) :: i
253 logical :: result
254
255 result = this%items(i)%ptr%internal_dofmap
256 end function field_list_internal_dofmap
257
260 function field_list_name(this, i) result(result)
261 class(field_list_t), target, intent(in) :: this
262 integer, intent(in) :: i
263 character(len=80) :: result
264
265 result = this%items(i)%ptr%name
266 end function field_list_name
267
268
269end 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_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.
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:82
field_list_t, To be able to group fields together
The function space for the SEM solution fields.
Definition space.f90:63