Neko 1.99.3
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
vector_list.f90
Go to the documentation of this file.
1! Copyright (c) 2018-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!
33! Defines a vector list
35 use, intrinsic :: iso_fortran_env, only : error_unit
36 use vector, only : vector_ptr_t, vector_t
37 use iso_c_binding, only : c_ptr
38 use num_types, only : rp
39 use utils, only : neko_error
40 use comm, only : pe_rank
41 implicit none
42 private
43
45 type, public :: vector_list_t
46 type(vector_ptr_t), allocatable :: items(:)
47 contains
49 procedure, pass(this) :: init => vector_list_init
51 procedure, pass(this) :: free => vector_list_free
53 procedure, pass(this) :: append => vector_list_append
54 generic :: get => get_by_index, get_by_name
56 procedure, pass(this) :: get_by_index => vector_list_get_by_index
58 procedure, pass(this) :: get_by_name => vector_list_get_by_name
60 generic :: assign => assign_to_ptr, assign_to_vector_ptr
61 procedure, pass(this) :: assign_to_ptr => vector_list_assign_to_ptr
62 procedure, pass(this) :: assign_to_vector_ptr => &
64 procedure, pass(this) :: assign_to_vector => vector_list_assign_to_vector
65
67 procedure, pass(this) :: x_d => vector_list_x_d
69 procedure, pass(this) :: x => vector_list_x
71 procedure, pass(this) :: size => vector_list_size
73 procedure, pass(this) :: item_size => vector_list_item_size
75 procedure, pass(this) :: name => vector_list_name
76 end type vector_list_t
77
78contains
81 subroutine vector_list_init(this, size)
82 class(vector_list_t), intent(inout) :: this
83 integer, intent(in) :: size
84
85 call this%free()
86
87 allocate(this%items(size))
88 end subroutine vector_list_init
89
91 pure function vector_list_size(this) result(n)
92 class(vector_list_t), intent(in) :: this
93 integer :: n
94 n = size(this%items)
95 end function vector_list_size
96
99 function vector_list_get_by_index(this, i) result(f)
100 class(vector_list_t), target, intent(inout) :: this
101 type(vector_t), pointer :: f
102 integer, intent(in) :: i
103 f => this%items(i)%ptr
104 end function vector_list_get_by_index
105
108 function vector_list_get_by_name(this, name) result(f)
109 class(vector_list_t), target, intent(inout) :: this
110 type(vector_t), pointer :: f
111 character(len=*), intent(in) :: name
112 integer :: i
113
114 nullify(f)
115
116 do i = 1, this%size()
117 if (this%name(i) .eq. trim(name)) then
118 f => this%items(i)%ptr
119 return
120 end if
121 end do
122
123 if (pe_rank .eq. 0) then
124 write(error_unit,*) "Current vector list contents:"
125
126 do i = 1, this%size()
127 write(error_unit,*) "- ", this%name(i)
128 end do
129 end if
130
131 call neko_error("No vector with name " // trim(name) // " found in list")
132 end function vector_list_get_by_name
133
136 subroutine vector_list_append(this, f)
137 class(vector_list_t), intent(inout) :: this
138 class(vector_t), intent(in), target :: f
139 type(vector_ptr_t), allocatable :: tmp(:)
140 integer :: len
141
142 if (.not. allocated(this%items)) then
143 allocate(this%items(1))
144 call this%items(1)%init(f)
145 return
146 end if
147
148 len = size(this%items)
149
150 allocate(tmp(len+1))
151 tmp(1:len) = this%items
152 call move_alloc(tmp, this%items)
153 call this%items(len+1)%init(f)
154
155 end subroutine vector_list_append
156
158 subroutine vector_list_free(this)
159 class(vector_list_t), intent(inout) :: this
160 integer :: i, n_fields
161
162 if (allocated(this%items)) then
163 n_fields = this%size()
164 do i = 1, n_fields
165 call this%items(i)%free()
166 end do
167 deallocate(this%items)
168 end if
169
170 end subroutine vector_list_free
171
174 function vector_list_x_d(this, i) result(ptr)
175 class(vector_list_t), intent(in) :: this
176 integer, intent(in) :: i
177 type(c_ptr) :: ptr
178
179 ptr = this%items(i)%ptr%x_d
180 end function vector_list_x_d
181
182 function vector_list_x(this, i) result(x)
183 class(vector_list_t), target, intent(in) :: this
184 real(kind=rp), pointer, contiguous :: x(:)
185 integer, intent(in) :: i
186 x => this%items(i)%ptr%x
187 end function vector_list_x
188
191 function vector_list_item_size(this, i) result(size)
192 class(vector_list_t), target, intent(in) :: this
193 integer, intent(in) :: i
194 integer :: size
195
196 size = this%items(i)%ptr%size()
197
198 end function vector_list_item_size
199
203 subroutine vector_list_assign_to_ptr(this, i, ptr)
204 class(vector_list_t), intent(inout) :: this
205 integer, intent(in) :: i
206 type(vector_t), pointer, intent(in) :: ptr
207
208 call this%items(i)%init(ptr)
209
210 end subroutine vector_list_assign_to_ptr
211
215 subroutine vector_list_assign_to_vector_ptr(this, i, ptr)
216 class(vector_list_t), intent(inout) :: this
217 integer, intent(in) :: i
218 type(vector_ptr_t), target, intent(in) :: ptr
219
220 call this%items(i)%init(ptr%ptr)
222
226 subroutine vector_list_assign_to_vector(this, i, vec)
227 class(vector_list_t), intent(inout) :: this
228 integer, intent(in) :: i
229 type(vector_t), target, intent(in) :: vec
230
231 call this%items(i)%init(vec)
232 end subroutine vector_list_assign_to_vector
233
236 function vector_list_name(this, i) result(result)
237 class(vector_list_t), target, intent(in) :: this
238 integer, intent(in) :: i
239 character(len=80) :: result
240
241 result = this%items(i)%ptr%name
242 end function vector_list_name
243
244
245end module vector_list
Definition comm.F90:1
integer, public pe_rank
MPI rank.
Definition comm.F90:56
integer, parameter, public rp
Global precision used in computations.
Definition num_types.f90:12
Utilities.
Definition utils.f90:35
type(c_ptr) function vector_list_x_d(this, i)
Get device pointer for a given index.
subroutine vector_list_assign_to_vector_ptr(this, i, ptr)
Point item at a given index.
subroutine vector_list_assign_to_vector(this, i, vec)
Point item at a given index.
subroutine vector_list_free(this)
Destructor.
type(vector_t) function, pointer vector_list_get_by_index(this, i)
Get an item pointer by array index.
character(len=80) function vector_list_name(this, i)
Get the name for an item in the list.
integer function vector_list_item_size(this, i)
Get the size of item i.
pure integer function vector_list_size(this)
Get number of items in the list.
subroutine vector_list_assign_to_ptr(this, i, ptr)
Point item at a given index.
subroutine vector_list_append(this, f)
Append a vector to the list.
real(kind=rp) function, dimension(:), pointer, contiguous vector_list_x(this, i)
subroutine vector_list_init(this, size)
Constructor. Just allocates the array.
type(vector_t) function, pointer vector_list_get_by_name(this, name)
Get an item pointer by array index.
Defines a vector.
Definition vector.f90:34
vector_list_t, To be able to group vectors together