Skip to content

Commit bb7ecdb

Browse files
adperezmtimfelle
andauthored
Feature/vector list (#2327)
Added vector list with the same characteristics as field_list_t. @timfelle , if you already had this somewhere, then of course ignore :). I think it would be nice to add names to the vectors. The particular use-case I was thinking about was to further extend #2325 once it is merged. I would like that functionality to accept a list of keys to read, and since `fld_file_data_t` uses `vector_t`, it would be nice if one could search a vector by name. This would also help to have a unique interface with hdf5, I believe. I do not like that these searches need to always traverse the list. But I suppose that having hashtables with these types is overkill, considering that we never have crazy many entries. --------- Co-authored-by: Tim Felle Olsen <timfelle@hotmail.com>
1 parent 8119f94 commit bb7ecdb

File tree

6 files changed

+286
-3
lines changed

6 files changed

+286
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Develop
44

5+
- Added `vector_list_t` and `name` to `vector_t`.
56
- Rework hash table iterators, significantly faster (O(tsize) => O(entries)
67
- Remove redundant directory in `site-packages` when installing pyneko
78
- Added options to used masked parts of the domain when performing interpolation

src/.depends

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ math/bcknd/sx/fdm_sx.lo : math/bcknd/sx/fdm_sx.f90 math/bcknd/sx/tensor_sx.lo co
116116
math/bcknd/xsmm/fdm_xsmm.lo : math/bcknd/xsmm/fdm_xsmm.f90 math/bcknd/xsmm/tensor_xsmm.lo config/num_types.lo
117117
math/schwarz.lo : math/schwarz.f90 bc/bc_list.lo config/neko_config.lo device/device.lo math/fdm.lo math/bcknd/device/device_math.lo math/bcknd/device/device_schwarz.lo gs/gather_scatter.lo sem/dofmap.lo sem/space.lo mesh/mesh.lo math/math.lo config/num_types.lo
118118
math/vector.lo : math/vector.f90 common/utils.lo math/bcknd/device/device_math.lo math/math.lo device/device.lo config/num_types.lo config/neko_config.lo
119+
math/vector_list.lo : math/vector_list.f90 comm/comm.lo common/utils.lo config/num_types.lo math/vector.lo
119120
math/vector_math.lo : math/vector_math.f90 math/bcknd/device/device_math.lo math/math.lo common/utils.lo device/device.lo common/mask.lo math/vector.lo config/num_types.lo config/neko_config.lo
120121
registries/registry.lo : registries/registry.f90 common/log.lo common/utils.lo sem/dofmap.lo registries/registry_entry.lo math/matrix.lo math/vector.lo field/field.lo config/num_types.lo
121122
registries/registry_entry.lo : registries/registry_entry.f90 common/utils.lo sem/dofmap.lo math/matrix.lo math/vector.lo field/field.lo config/num_types.lo
@@ -398,4 +399,4 @@ wall_models/spalding.lo : wall_models/spalding.f90 registries/scratch_registry.l
398399
wall_models/bcknd/cpu/spalding_cpu.lo : wall_models/bcknd/cpu/spalding_cpu.f90 common/log.lo config/num_types.lo
399400
wall_models/bcknd/device/spalding_device.lo : wall_models/bcknd/device/spalding_device.F90 common/utils.lo config/num_types.lo
400401
wall_models/wall_model_fctry.lo : wall_models/wall_model_fctry.f90 common/utils.lo wall_models/rough_log_law.lo wall_models/spalding.lo les/vreman.lo wall_models/wall_model.lo
401-
neko.lo : neko.f90 common/user_access_singleton.lo source_terms/source_term.lo common/time_step_controller.lo common/time_based_controller.lo simulation_components/lambda2.lo simulation_components/force_torque.lo simulation_components/weak_gradient_simcomp.lo simulation_components/gradient_simcomp.lo simulation_components/curl_simcomp.lo simulation_components/divergence_simcomp.lo simulation_components/derivative_simcomp.lo simulation_components/field_writer.lo les/les_model.lo common/json_utils.lo common/runtime_statistics.lo bc/field_dirichlet_vector.lo bc/field_dirichlet.lo mesh/point_zone_registry.lo mesh/point_zones/sphere_point_zone.lo mesh/point_zones/box_point_zone.lo mesh/point_zone.lo sem/point_interpolator.lo common/time_interpolator.lo io/data_streamer.lo simulation_components/simcomp_executor.lo registries/scratch_registry.lo registries/registry.lo qoi/drag_torque.lo common/system.lo common/profiler.lo simulation_components/spectral_error.lo simulation_components/probes.lo simulation_components/simulation_component.lo math/tensor.lo math/matrix.lo math/vector.lo source_terms/user_source_term.lo field/field_list.lo fluid/fluid_stats.lo sem/cpr.lo sem/map_2d.lo sem/map_1d.lo math/bcknd/device/device_math.lo device/device.lo common/jobctrl.lo common/time_state.lo common/signal.lo common/user_intf.lo common/projection.lo math/mathops.lo math/operators.lo simulation.lo io/output.lo io/output_controller.lo case.lo config/neko_config.lo comm/parmetis.lo math/ax.lo bc/dirichlet.lo bc/bc_list.lo bc/zero_dirichlet.lo bc/bc.lo sem/coef.lo krylov/krylov.lo gs/gather_scatter.lo comm/mpi_types.lo math/field_math.lo field/field.lo io/file.lo global_interpolation/global_interpolation.lo math/mxm_wrapper.lo io/format/map.lo field/mesh_field.lo mesh/point.lo mesh/mesh.lo adt/tuple.lo adt/stack.lo adt/uset.lo adt/htable.lo sem/space.lo sem/dofmap.lo sem/speclib.lo math/math.lo common/log.lo common/utils.lo comm/comm.lo config/num_types.lo
402+
neko.lo : neko.f90 common/user_access_singleton.lo source_terms/source_term.lo common/time_step_controller.lo common/time_based_controller.lo simulation_components/lambda2.lo simulation_components/force_torque.lo simulation_components/weak_gradient_simcomp.lo simulation_components/gradient_simcomp.lo simulation_components/curl_simcomp.lo simulation_components/divergence_simcomp.lo simulation_components/derivative_simcomp.lo simulation_components/field_writer.lo les/les_model.lo common/json_utils.lo common/runtime_statistics.lo bc/field_dirichlet_vector.lo bc/field_dirichlet.lo mesh/point_zone_registry.lo mesh/point_zones/sphere_point_zone.lo mesh/point_zones/box_point_zone.lo mesh/point_zone.lo sem/point_interpolator.lo common/time_interpolator.lo io/data_streamer.lo simulation_components/simcomp_executor.lo registries/scratch_registry.lo registries/registry.lo qoi/drag_torque.lo common/system.lo common/profiler.lo simulation_components/spectral_error.lo simulation_components/probes.lo simulation_components/simulation_component.lo math/tensor.lo math/matrix.lo math/vector_list.lo math/vector.lo source_terms/user_source_term.lo field/field_list.lo fluid/fluid_stats.lo sem/cpr.lo sem/map_2d.lo sem/map_1d.lo math/bcknd/device/device_math.lo device/device.lo common/jobctrl.lo common/time_state.lo common/signal.lo common/user_intf.lo common/projection.lo math/mathops.lo math/operators.lo simulation.lo io/output.lo io/output_controller.lo case.lo config/neko_config.lo comm/parmetis.lo math/ax.lo bc/dirichlet.lo bc/bc_list.lo bc/zero_dirichlet.lo bc/bc.lo sem/coef.lo krylov/krylov.lo gs/gather_scatter.lo comm/mpi_types.lo math/field_math.lo field/field.lo io/file.lo global_interpolation/global_interpolation.lo math/mxm_wrapper.lo io/format/map.lo field/mesh_field.lo mesh/point.lo mesh/mesh.lo adt/tuple.lo adt/stack.lo adt/uset.lo adt/htable.lo sem/space.lo sem/dofmap.lo sem/speclib.lo math/math.lo common/log.lo common/utils.lo comm/comm.lo config/num_types.lo

src/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ neko_fortran_SOURCES = \
119119
math/bcknd/xsmm/fdm_xsmm.f90\
120120
math/schwarz.f90\
121121
math/vector.f90\
122+
math/vector_list.f90\
122123
math/vector_math.f90\
123124
registries/registry.f90\
124125
registries/registry_entry.f90\

src/math/vector.f90

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ module vector
4848
type, public :: vector_t
4949
!> Vector entries.
5050
real(kind=rp), allocatable :: x(:)
51+
character(len=80) :: name = "" !< Name of the vector
5152
!> Device pointer.
5253
type(c_ptr) :: x_d = C_NULL_PTR
5354
!> Size of vector.
@@ -78,15 +79,21 @@ module vector
7879
end type vector_t
7980

8081
type, public :: vector_ptr_t
81-
type(vector_t), pointer :: ptr
82+
type(vector_t), pointer :: ptr => null()
83+
contains
84+
!> Constructor. Just assigns the pointer
85+
procedure, pass(this) :: init => vector_ptr_init
86+
!> Destructor. Just nullifies the pointer.
87+
procedure, pass(this) :: free => vector_ptr_free
8288
end type vector_ptr_t
8389

8490
contains
8591

8692
!> Initialise a vector of size @a n.
87-
subroutine vector_init(v, n)
93+
subroutine vector_init(v, n, name)
8894
class(vector_t), intent(inout) :: v
8995
integer, intent(in) :: n
96+
character(len=*), intent(in), optional :: name
9097

9198
call v%alloc(n)
9299
call cfill(v%x, 0.0_rp, n)
@@ -95,6 +102,10 @@ subroutine vector_init(v, n)
95102
call device_sync()
96103
end if
97104

105+
if (present(name)) then
106+
v%name = name
107+
end if
108+
98109
end subroutine vector_init
99110

100111
!> Vector allocation without initialisation.
@@ -128,6 +139,7 @@ subroutine vector_free(v)
128139
end if
129140

130141
v%n = 0
142+
v%name = ""
131143

132144
end subroutine vector_free
133145

@@ -166,6 +178,8 @@ subroutine vector_assign_vector(v, w)
166178
call copy(v%x, w%x, v%n)
167179
end if
168180

181+
v%name = w%name
182+
169183
end subroutine vector_assign_vector
170184

171185
!> Assignment \f$ v = s \f$.
@@ -195,4 +209,24 @@ subroutine vector_assign_array(v, array)
195209

196210
end subroutine vector_assign_array
197211

212+
! ========================================================================== !
213+
! vector pointer type subroutines
214+
215+
subroutine vector_ptr_init(this, ptr)
216+
class(vector_ptr_t), intent(inout) :: this
217+
type(vector_t), target, intent(in) :: ptr
218+
219+
call this%free()
220+
this%ptr => ptr
221+
end subroutine vector_ptr_init
222+
223+
subroutine vector_ptr_free(this)
224+
class(vector_ptr_t), intent(inout) :: this
225+
226+
if (associated(this%ptr)) then
227+
nullify(this%ptr)
228+
end if
229+
230+
end subroutine vector_ptr_free
231+
198232
end module vector

src/math/vector_list.f90

Lines changed: 245 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,245 @@
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
34+
module 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+
44+
!> vector_list_t, To be able to group vectors together
45+
type, public :: vector_list_t
46+
type(vector_ptr_t), allocatable :: items(:)
47+
contains
48+
!> Constructor. Allocates array and pointers.
49+
procedure, pass(this) :: init => vector_list_init
50+
!> Destructor.
51+
procedure, pass(this) :: free => vector_list_free
52+
!> Append a vector to the list.
53+
procedure, pass(this) :: append => vector_list_append
54+
generic :: get => get_by_index, get_by_name
55+
!> Get an item pointer by array index
56+
procedure, pass(this) :: get_by_index => vector_list_get_by_index
57+
!> Get an item pointer by vector name
58+
procedure, pass(this) :: get_by_name => vector_list_get_by_name
59+
!> Point item at given index.
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 => &
63+
vector_list_assign_to_vector_ptr
64+
procedure, pass(this) :: assign_to_vector => vector_list_assign_to_vector
65+
66+
!> Get device pointer for a given index.
67+
procedure, pass(this) :: x_d => vector_list_x_d
68+
!> Get pointer to the raw data array for a given index.
69+
procedure, pass(this) :: x => vector_list_x
70+
!> Get number of items in the list.
71+
procedure, pass(this) :: size => vector_list_size
72+
!> Get the size of an item in the list.
73+
procedure, pass(this) :: item_size => vector_list_item_size
74+
!> Get the name for an item in the list.
75+
procedure, pass(this) :: name => vector_list_name
76+
end type vector_list_t
77+
78+
contains
79+
!> Constructor. Just allocates the array.
80+
!! @param size The size of the list to preallocate
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+
90+
!> Get number of items in the list.
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+
97+
!> Get an item pointer by array index
98+
!! @param i The index of the item.
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+
106+
!> Get an item pointer by array index
107+
!! @param name The name of the item.
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+
134+
!> Append a vector to the list.
135+
!! @param f The vector to append.
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+
157+
!> Destructor.
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+
172+
!> Get device pointer for a given index
173+
!! @param i The index of the item.
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+
189+
!> Get the size of item `i`.
190+
!! @param i The index of the item.
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+
200+
!> Point item at a given index.
201+
!! @param i The index of the item.
202+
!! @param ptr A vector pointer to point the item to.
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+
212+
!> Point item at a given index.
213+
!! @param i The index of the item.
214+
!! @param ptr An encapsulated vector pointer to point the item to.
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)
221+
end subroutine vector_list_assign_to_vector_ptr
222+
223+
!> Point item at a given index.
224+
!! @param i The index of the item.
225+
!! @param vec A vector to point the item to.
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+
234+
!> Get the name for an item in the list.
235+
!! @param i The index of the item.
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+
245+
end module vector_list

src/neko.f90

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ module neko
100100
use field_list, only : field_list_t
101101
use user_source_term, only : user_source_term_t
102102
use vector, only : vector_t, vector_ptr_t
103+
use vector_list, only : vector_list_t
103104
use matrix, only : matrix_t
104105
use tensor
105106
use simulation_component, only : simulation_component_t, &

0 commit comments

Comments
 (0)