Neko 1.99.3
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
field_array.f90
Go to the documentation of this file.
1! Copyright (c) 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_wrapper_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_array_t
48 type(field_wrapper_t), allocatable :: items(:)
49 contains
51 procedure, pass(this) :: init => field_array_init
53 procedure, pass(this) :: free => field_array_free
55 procedure, pass(this) :: append => field_array_append
56 generic :: get => get_by_index, get_by_name
58 procedure, pass(this) :: get_by_index => field_array_get_by_index
60 procedure, pass(this) :: get_by_name => field_array_get_by_name
62 generic :: assign => assign_to_field, assign_to_field_wrapper
63 procedure, pass(this) :: assign_to_field => field_array_assign_to_field
64 procedure, pass(this) :: assign_to_field_wrapper => &
66
68 procedure, pass(this) :: x_d => field_array_x_d
70 procedure, pass(this) :: x => field_array_x
72 procedure, pass(this) :: size => field_array_size
74 procedure, pass(this) :: item_size => field_array_item_size
76 procedure, pass(this) :: dof => field_array_dof
78 procedure, pass(this) :: xh => field_array_space
80 procedure, pass(this) :: msh => field_array_msh
82 procedure, pass(this) :: internal_dofmap => field_array_internal_dofmap
84 procedure, pass(this) :: name => field_array_name
85 end type field_array_t
86
87contains
90 subroutine field_array_init(this, size)
91 class(field_array_t), intent(inout) :: this
92 integer, intent(in) :: size
93
94 call this%free()
95
96 allocate(this%items(size))
97 end subroutine field_array_init
98
100 pure function field_array_size(this) result(n)
101 class(field_array_t), intent(in) :: this
102 integer :: n
103 n = size(this%items)
104 end function field_array_size
105
108 function field_array_get_by_index(this, i) result(f)
109 class(field_array_t), intent(inout) :: this
110 type(field_t), pointer :: f
111 integer, intent(in) :: i
112 f => this%items(i)%field
113 end function field_array_get_by_index
114
117 function field_array_get_by_name(this, name) result(f)
118 class(field_array_t), intent(inout) :: this
119 type(field_t), pointer :: f
120 character(len=*), intent(in) :: name
121 integer :: i
122
123 nullify(f)
124
125 do i = 1, this%size()
126 if (this%name(i) .eq. trim(name)) then
127 f => this%items(i)%field
128 return
129 end if
130 end do
131
132 if (pe_rank .eq. 0) then
133 write(error_unit,*) "Current field list contents:"
134
135 do i = 1, this%size()
136 write(error_unit,*) "- ", this%name(i)
137 end do
138 end if
139
140 call neko_error("No field with name " // trim(name) // " found in list")
141 end function field_array_get_by_name
142
145 subroutine field_array_append(this, f)
146 class(field_array_t), intent(inout) :: this
147 class(field_t), intent(in) :: f
148 type(field_wrapper_t), allocatable :: tmp(:)
149 integer :: len
150
151 len = size(this%items)
152
153 allocate(tmp(len+1))
154 tmp(1:len) = this%items
155 call move_alloc(tmp, this%items)
156 call this%items(len+1)%init(f)
157
158 end subroutine field_array_append
159
161 subroutine field_array_free(this)
162 class(field_array_t), intent(inout) :: this
163 integer :: i, n_fields
164
165 if (allocated(this%items)) then
166 n_fields = this%size()
167 do i = 1, n_fields
168 call this%items(i)%free()
169 end do
170 deallocate(this%items)
171 end if
172
173 end subroutine field_array_free
174
177 function field_array_x_d(this, i) result(x_d)
178 class(field_array_t), intent(in) :: this
179 integer, intent(in) :: i
180 type(c_ptr) :: x_d
181
182 x_d = this%items(i)%field%x_d
183 end function field_array_x_d
184
185 function field_array_x(this, i) result(x)
186 class(field_array_t), target, intent(in) :: this
187 real(kind=rp), pointer, contiguous :: x(:,:,:,:)
188 integer, intent(in) :: i
189 x => this%items(i)%field%x
190 end function field_array_x
191
194 function field_array_item_size(this, i) result(size)
195 class(field_array_t), target, intent(in) :: this
196 integer, intent(in) :: i
197 integer :: size
198
199 size = this%items(i)%field%size()
200
201 end function field_array_item_size
202
206 subroutine field_array_assign_to_field(this, i, f)
207 class(field_array_t), intent(inout) :: this
208 integer, intent(in) :: i
209 type(field_t), intent(in) :: f
210
211 call this%items(i)%init(f)
212
213 end subroutine field_array_assign_to_field
214
218 subroutine field_array_assign_to_field_wrapper(this, i, wrapper)
219 class(field_array_t), intent(inout) :: this
220 integer, intent(in) :: i
221 type(field_wrapper_t), target, intent(in) :: wrapper
222
223 call this%items(i)%init(wrapper%field)
225
228 function field_array_dof(this, i) result(result)
229 class(field_array_t), target, intent(in) :: this
230 integer, intent(in) :: i
231 type(dofmap_t), pointer :: result
232
233 result => this%items(i)%field%dof
234 end function field_array_dof
235
238 function field_array_space(this, i) result(result)
239 class(field_array_t), target, intent(in) :: this
240 integer, intent(in) :: i
241 type(space_t), pointer :: result
242
243 result => this%items(i)%field%Xh
244 end function field_array_space
245
248 function field_array_msh(this, i) result(result)
249 class(field_array_t), target, intent(in) :: this
250 integer, intent(in) :: i
251 type(mesh_t), pointer :: result
252
253 result => this%items(i)%field%msh
254 end function field_array_msh
255
258 function field_array_internal_dofmap(this, i) result(result)
259 class(field_array_t), target, intent(in) :: this
260 integer, intent(in) :: i
261 logical :: result
262
263 result = this%items(i)%field%internal_dofmap
264 end function field_array_internal_dofmap
265
268 function field_array_name(this, i) result(result)
269 class(field_array_t), target, intent(in) :: this
270 integer, intent(in) :: i
271 character(len=80) :: result
272
273 result = this%items(i)%field%name
274 end function field_array_name
275
276end module field_array
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
real(kind=rp) function, dimension(:,:,:,:), pointer, contiguous field_array_x(this, i)
type(field_t) function, pointer field_array_get_by_name(this, name)
Get an item pointer by array index.
type(field_t) function, pointer field_array_get_by_index(this, i)
Get an item pointer by array index.
subroutine field_array_assign_to_field_wrapper(this, i, wrapper)
Point item at a given index.
type(c_ptr) function field_array_x_d(this, i)
Get device pointer for a given index.
character(len=80) function field_array_name(this, i)
Get the name for an item in the list.
logical function field_array_internal_dofmap(this, i)
Whether the dofmap is internal for item i.
type(dofmap_t) function, pointer field_array_dof(this, i)
Get the the dofmap for item i.
pure integer function field_array_size(this)
Get number of items in the list.
subroutine field_array_free(this)
Destructor.
type(mesh_t) function, pointer field_array_msh(this, i)
Get the the mesh for item i.
integer function field_array_item_size(this, i)
Get the size of the dofmap for item i.
type(space_t) function, pointer field_array_space(this, i)
Get the the space for item i.
subroutine field_array_init(this, size)
Constructor. Just allocates the array.
subroutine field_array_append(this, f)
Append a field to the list, by copy assignment.
subroutine field_array_assign_to_field(this, i, f)
Assign item at a given index to field, by copy assignment.
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_wrapper_t, used to wrap an allocated field for use in a field list
Definition field.f90:93
field_array_t, To be able to group fields together
The function space for the SEM solution fields.
Definition space.f90:63