Neko  0.9.0
A portable framework for high-order spectral element flow simulations
field_list.f90
Go to the documentation of this file.
1 module field_list
2  use field, only : field_ptr_t, field_t
3  use iso_c_binding, only : c_ptr
4  use num_types, only : rp
5  use space, only : space_t
6  use dofmap, only : dofmap_t
7  use mesh, only : mesh_t
8  use utils, only : neko_error
9  implicit none
10  private
11 
13  type, public :: field_list_t
14  type(field_ptr_t), allocatable :: items(:)
15  contains
17  procedure, pass(this) :: init => field_list_init
19  procedure, pass(this) :: free => field_list_free
21  procedure, pass(this) :: append => field_list_append
22  generic :: get => get_by_index, get_by_name
24  procedure, pass(this) :: get_by_index => field_list_get_by_index
26  procedure, pass(this) :: get_by_name => field_list_get_by_name
28  generic :: assign => assign_to_ptr, assign_to_field_ptr
29  procedure, pass(this) :: assign_to_ptr => field_list_assign_to_ptr
30  procedure, pass(this) :: assign_to_field_ptr => field_list_assign_to_field_ptr
31  procedure, pass(this) :: assign_to_field => field_list_assign_to_field
32 
34  procedure, pass(this) :: x_d => field_list_x_d
36  procedure, pass(this) :: x => field_list_x
38  procedure, pass(this) :: size => field_list_size
40  procedure, pass(this) :: item_size => field_list_item_size
42  procedure, pass(this) :: dof => field_list_dof
44  procedure, pass(this) :: xh => field_list_space
46  procedure, pass(this) :: msh => field_list_msh
48  procedure, pass(this) :: internal_dofmap => field_list_internal_dofmap
50  procedure, pass(this) :: name => field_list_name
51  end type field_list_t
52 
53 contains
56  subroutine field_list_init(this, size)
57  class(field_list_t), intent(inout) :: this
58  integer, intent(in) :: size
59 
60  call this%free()
61 
62  allocate(this%items(size))
63  end subroutine field_list_init
64 
66  pure function field_list_size(this) result(n)
67  class(field_list_t), intent(in) :: this
68  integer :: n
69  n = size(this%items)
70  end function field_list_size
71 
74  function field_list_get_by_index(this, i) result(f)
75  class(field_list_t), intent(inout) :: this
76  type(field_t), pointer :: f
77  integer, intent(in) :: i
78  f => this%items(i)%ptr
79  end function field_list_get_by_index
80 
83  function field_list_get_by_name(this, name) result(f)
84  class(field_list_t), intent(inout) :: this
85  type(field_t), pointer :: f
86  character(len=*), intent(in) :: name
87  integer :: i
88 
89  do i=1, this%size()
90  if (this%name(i) .eq. trim(name)) then
91  f => this%items(i)%ptr
92  return
93  end if
94  end do
95 
96  call neko_error("No field with name " // trim(name) // " found in list")
97  end function field_list_get_by_name
98 
101  subroutine field_list_append(this, f)
102  class(field_list_t), intent(inout) :: this
103  class(field_t), intent(in), target :: f
104  type(field_ptr_t), allocatable :: tmp(:)
105  integer :: len
106 
107  len = size(this%items)
108 
109  allocate(tmp(len+1))
110  tmp(1:len) = this%items
111  call move_alloc(tmp, this%items)
112  this%items(len+1)%ptr => f
113 
114  end subroutine field_list_append
115 
117  subroutine field_list_free(this)
118  class(field_list_t), intent(inout) :: this
119  integer :: i, n_fields
120 
121  if (allocated(this%items)) then
122  n_fields = this%size()
123  do i=1, n_fields
124  if (associated(this%items(i)%ptr)) then
125  call this%items(i)%ptr%free()
126  end if
127  nullify(this%items(i)%ptr)
128  end do
129  deallocate(this%items)
130  end if
131 
132  end subroutine field_list_free
133 
136  function field_list_x_d(this, i) result(ptr)
137  class(field_list_t), intent(in) :: this
138  integer, intent(in) :: i
139  type(c_ptr) :: ptr
140 
141  ptr = this%items(i)%ptr%x_d
142  end function field_list_x_d
143 
144  function field_list_x(this, i) result(x)
145  class(field_list_t), target, intent(in) :: this
146  real(kind=rp), pointer :: x(:,:,:,:)
147  integer, intent(in) :: i
148  x => this%items(i)%ptr%x
149  end function field_list_x
150 
153  function field_list_item_size(this, i) result(size)
154  class(field_list_t), target, intent(in) :: this
155  integer, intent(in) :: i
156  integer :: size
157 
158  size = this%items(i)%ptr%size()
159 
160  end function field_list_item_size
161 
165  subroutine field_list_assign_to_ptr(this, i, ptr)
166  class(field_list_t), intent(inout) :: this
167  integer, intent(in) :: i
168  type(field_t), pointer, intent(in) :: ptr
169 
170  this%items(i)%ptr => ptr
171  end subroutine field_list_assign_to_ptr
172 
176  subroutine field_list_assign_to_field_ptr(this, i, ptr)
177  class(field_list_t), intent(inout) :: this
178  integer, intent(in) :: i
179  type(field_ptr_t), target, intent(in) :: ptr
180 
181  this%items(i)%ptr => ptr%ptr
182  end subroutine field_list_assign_to_field_ptr
183 
187  subroutine field_list_assign_to_field(this, i, fld)
188  class(field_list_t), intent(inout) :: this
189  integer, intent(in) :: i
190  type(field_t), target, intent(in) :: fld
191 
192  this%items(i)%ptr => fld
193  end subroutine field_list_assign_to_field
194 
197  function field_list_dof(this, i) result(result)
198  class(field_list_t), target, intent(in) :: this
199  integer, intent(in) :: i
200  type(dofmap_t), pointer :: result
201 
202  result => this%items(i)%ptr%dof
203  end function field_list_dof
204 
207  function field_list_space(this, i) result(result)
208  class(field_list_t), target, intent(in) :: this
209  integer, intent(in) :: i
210  type(space_t), pointer :: result
211 
212  result => this%items(i)%ptr%Xh
213  end function field_list_space
214 
217  function field_list_msh(this, i) result(result)
218  class(field_list_t), target, intent(in) :: this
219  integer, intent(in) :: i
220  type(mesh_t), pointer :: result
221 
222  result => this%items(i)%ptr%msh
223  end function field_list_msh
224 
227  function field_list_internal_dofmap(this, i) result(result)
228  class(field_list_t), target, intent(in) :: this
229  integer, intent(in) :: i
230  logical :: result
231 
232  result = this%items(i)%ptr%internal_dofmap
233  end function field_list_internal_dofmap
234 
237  function field_list_name(this, i) result(result)
238  class(field_list_t), target, intent(in) :: this
239  integer, intent(in) :: i
240  character(len=80) :: result
241 
242  result = this%items(i)%ptr%name
243  end function field_list_name
244 
245 
246 end module field_list
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.
Definition: field_list.f90:198
subroutine field_list_init(this, size)
Constructor. Just allocates the array.
Definition: field_list.f90:57
type(space_t) function, pointer field_list_space(this, i)
Get the the space for item i.
Definition: field_list.f90:208
subroutine field_list_assign_to_ptr(this, i, ptr)
Point item at a given index.
Definition: field_list.f90:166
pure integer function field_list_size(this)
Get number of items in the list.
Definition: field_list.f90:67
subroutine field_list_assign_to_field_ptr(this, i, ptr)
Point item at a given index.
Definition: field_list.f90:177
integer function field_list_item_size(this, i)
Get the size of the dofmap for item i.
Definition: field_list.f90:154
character(len=80) function field_list_name(this, i)
Get the name for an item in the list.
Definition: field_list.f90:238
logical function field_list_internal_dofmap(this, i)
Whether the dofmap is internal for item i.
Definition: field_list.f90:228
real(kind=rp) function, dimension(:,:,:,:), pointer field_list_x(this, i)
Definition: field_list.f90:145
type(field_t) function, pointer field_list_get_by_index(this, i)
Get an item pointer by array index.
Definition: field_list.f90:75
type(mesh_t) function, pointer field_list_msh(this, i)
Get the the mesh for item i.
Definition: field_list.f90:218
subroutine field_list_assign_to_field(this, i, fld)
Point item at a given index.
Definition: field_list.f90:188
type(c_ptr) function field_list_x_d(this, i)
Get device pointer for a given index.
Definition: field_list.f90:137
subroutine field_list_free(this)
Destructor.
Definition: field_list.f90:118
subroutine field_list_append(this, f)
Append a field to the list.
Definition: field_list.f90:102
type(field_t) function, pointer field_list_get_by_name(this, name)
Get an item pointer by array index.
Definition: field_list.f90:84
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:80
field_list_t, To be able to group fields together
Definition: field_list.f90:13
The function space for the SEM solution fields.
Definition: space.f90:62