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
65 allocate(this%items(size))
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 n = size(this%items)
73 end function field_list_size
74
77 function field_list_get_by_index(this, i) result(f)
78 class(field_list_t), intent(inout) :: this
79 type(field_t), pointer :: f
80 integer, intent(in) :: i
81 f => this%items(i)%ptr
82 end function field_list_get_by_index
83
86 function field_list_get_by_name(this, name) result(f)
87 class(field_list_t), intent(inout) :: this
88 type(field_t), pointer :: f
89 character(len=*), intent(in) :: name
90 integer :: i
91
92 nullify(f)
93
94 do i = 1, this%size()
95 if (this%name(i) .eq. trim(name)) then
96 f => this%items(i)%ptr
97 return
98 end if
99 end do
100
101 if (pe_rank .eq. 0) then
102 write(error_unit,*) "Current field list contents:"
103
104 do i = 1, this%size()
105 write(error_unit,*) "- ", this%name(i)
106 end do
107 end if
108
109 call neko_error("No field with name " // trim(name) // " found in list")
110 end function field_list_get_by_name
111
114 subroutine field_list_append(this, f)
115 class(field_list_t), intent(inout) :: this
116 class(field_t), intent(in), target :: f
117 type(field_ptr_t), allocatable :: tmp(:)
118 integer :: len
119
120 if (.not. allocated(this%items)) then
121 allocate(this%items(1))
122 call this%items(1)%init(f)
123 return
124 end if
125
126 len = size(this%items)
127
128 allocate(tmp(len+1))
129 tmp(1:len) = this%items
130 call move_alloc(tmp, this%items)
131 call this%items(len+1)%init(f)
132
133 end subroutine field_list_append
134
136 subroutine field_list_free(this)
137 class(field_list_t), intent(inout) :: this
138 integer :: i, n_fields
139
140 if (allocated(this%items)) then
141 n_fields = this%size()
142 do i = 1, n_fields
143 call this%items(i)%free()
144 end do
145 deallocate(this%items)
146 end if
147
148 end subroutine field_list_free
149
152 function field_list_x_d(this, i) result(ptr)
153 class(field_list_t), intent(in) :: this
154 integer, intent(in) :: i
155 type(c_ptr) :: ptr
156
157 ptr = this%items(i)%ptr%x_d
158 end function field_list_x_d
159
160 function field_list_x(this, i) result(x)
161 class(field_list_t), target, intent(in) :: this
162 real(kind=rp), pointer, contiguous :: x(:,:,:,:)
163 integer, intent(in) :: i
164 x => this%items(i)%ptr%x
165 end function field_list_x
166
169 function field_list_item_size(this, i) result(size)
170 class(field_list_t), target, intent(in) :: this
171 integer, intent(in) :: i
172 integer :: size
173
174 size = this%items(i)%ptr%size()
175
176 end function field_list_item_size
177
181 subroutine field_list_assign_to_ptr(this, i, ptr)
182 class(field_list_t), intent(inout) :: this
183 integer, intent(in) :: i
184 type(field_t), pointer, intent(in) :: ptr
185
186 call this%items(i)%init(ptr)
187
188 end subroutine field_list_assign_to_ptr
189
193 subroutine field_list_assign_to_field_ptr(this, i, ptr)
194 class(field_list_t), intent(inout) :: this
195 integer, intent(in) :: i
196 type(field_ptr_t), target, intent(in) :: ptr
197
198 call this%items(i)%init(ptr%ptr)
199 end subroutine field_list_assign_to_field_ptr
200
204 subroutine field_list_assign_to_field(this, i, fld)
205 class(field_list_t), intent(inout) :: this
206 integer, intent(in) :: i
207 type(field_t), target, intent(in) :: fld
208
209 call this%items(i)%init(fld)
210 end subroutine field_list_assign_to_field
211
214 function field_list_dof(this, i) result(result)
215 class(field_list_t), target, intent(in) :: this
216 integer, intent(in) :: i
217 type(dofmap_t), pointer :: result
218
219 result => this%items(i)%ptr%dof
220 end function field_list_dof
221
224 function field_list_space(this, i) result(result)
225 class(field_list_t), target, intent(in) :: this
226 integer, intent(in) :: i
227 type(space_t), pointer :: result
228
229 result => this%items(i)%ptr%Xh
230 end function field_list_space
231
234 function field_list_msh(this, i) result(result)
235 class(field_list_t), target, intent(in) :: this
236 integer, intent(in) :: i
237 type(mesh_t), pointer :: result
238
239 result => this%items(i)%ptr%msh
240 end function field_list_msh
241
244 function field_list_internal_dofmap(this, i) result(result)
245 class(field_list_t), target, intent(in) :: this
246 integer, intent(in) :: i
247 logical :: result
248
249 result = this%items(i)%ptr%internal_dofmap
250 end function field_list_internal_dofmap
251
254 function field_list_name(this, i) result(result)
255 class(field_list_t), target, intent(in) :: this
256 integer, intent(in) :: i
257 character(len=80) :: result
258
259 result = this%items(i)%ptr%name
260 end function field_list_name
261
262
263end 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