Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Develop

- Added `vector_list_t` and `name` to `vector_t`.
- Update the simcomp wrappers to better handle allocation and deallocation.
- Added a factory subroutine for scalar schemes, allowing for more flexible
creation of scalar scheme objects based on JSON input.
Expand Down
3 changes: 2 additions & 1 deletion src/.depends
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ math/bcknd/sx/fdm_sx.lo : math/bcknd/sx/fdm_sx.f90 math/bcknd/sx/tensor_sx.lo co
math/bcknd/xsmm/fdm_xsmm.lo : math/bcknd/xsmm/fdm_xsmm.f90 math/bcknd/xsmm/tensor_xsmm.lo config/num_types.lo
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
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
math/vector_list.lo : math/vector_list.f90 comm/comm.lo common/utils.lo config/num_types.lo math/vector.lo
math/vector_math.lo : math/vector_math.f90 math/bcknd/device/device_math.lo math/math.lo device/device.lo math/vector.lo config/num_types.lo config/neko_config.lo
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
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
Expand Down Expand Up @@ -398,4 +399,4 @@ wall_models/spalding.lo : wall_models/spalding.f90 registries/scratch_registry.l
wall_models/bcknd/cpu/spalding_cpu.lo : wall_models/bcknd/cpu/spalding_cpu.f90 common/log.lo config/num_types.lo
wall_models/bcknd/device/spalding_device.lo : wall_models/bcknd/device/spalding_device.F90 common/utils.lo config/num_types.lo
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
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
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
1 change: 1 addition & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ neko_fortran_SOURCES = \
math/bcknd/xsmm/fdm_xsmm.f90\
math/schwarz.f90\
math/vector.f90\
math/vector_list.f90\
math/vector_math.f90\
registries/registry.f90\
registries/registry_entry.f90\
Expand Down
42 changes: 40 additions & 2 deletions src/math/vector.f90
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ module vector
type, public :: vector_t
!> Vector entries.
real(kind=rp), allocatable :: x(:)
character(len=80) :: name = "" !< Name of the vector
!> Device pointer.
type(c_ptr) :: x_d = C_NULL_PTR
!> Size of vector.
Expand Down Expand Up @@ -78,15 +79,21 @@ module vector
end type vector_t

type, public :: vector_ptr_t
type(vector_t), pointer :: ptr
type(vector_t), pointer :: ptr => null()
contains
!> Constructor. Just assigns the pointer
procedure, pass(this) :: init => vector_ptr_init
!> Destructor. Just nullifies the pointer.
procedure, pass(this) :: free => vector_ptr_free
end type vector_ptr_t

contains

!> Initialise a vector of size @a n.
subroutine vector_init(v, n)
subroutine vector_init(v, n, name)
class(vector_t), intent(inout) :: v
integer, intent(in) :: n
character(len=*), intent(in), optional :: name

call v%alloc(n)
call cfill(v%x, 0.0_rp, n)
Expand All @@ -95,6 +102,10 @@ subroutine vector_init(v, n)
call device_sync()
end if

if (present(name)) then
v%name = name
end if

end subroutine vector_init

!> Vector allocation without initialisation.
Expand Down Expand Up @@ -128,6 +139,7 @@ subroutine vector_free(v)
end if

v%n = 0
v%name = ""

end subroutine vector_free

Expand Down Expand Up @@ -166,6 +178,8 @@ subroutine vector_assign_vector(v, w)
call copy(v%x, w%x, v%n)
end if

v%name = w%name

end subroutine vector_assign_vector

!> Assignment \f$ v = s \f$.
Expand All @@ -179,6 +193,8 @@ subroutine vector_assign_scalar(v, s)
call cfill(v%x, s, v%n)
end if

v%name = "Vector"

end subroutine vector_assign_scalar

!> Assignment \f$ v = array \f$.
Expand All @@ -193,6 +209,28 @@ subroutine vector_assign_array(v, array)
call v%copy_from(HOST_TO_DEVICE, .true.)
end if

v%name = "Vector"

end subroutine vector_assign_array

! ========================================================================== !
! vector pointer type subroutines

subroutine vector_ptr_init(this, ptr)
class(vector_ptr_t), intent(inout) :: this
type(vector_t), target, intent(in) :: ptr

call this%free()
this%ptr => ptr
end subroutine vector_ptr_init

subroutine vector_ptr_free(this)
class(vector_ptr_t), intent(inout) :: this

if (associated(this%ptr)) then
nullify(this%ptr)
end if

end subroutine vector_ptr_free

end module vector
245 changes: 245 additions & 0 deletions src/math/vector_list.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,245 @@
! Copyright (c) 2018-2025, The Neko Authors
! All rights reserved.
!
! Redistribution and use in source and binary forms, with or without
! modification, are permitted provided that the following conditions
! are met:
!
! * Redistributions of source code must retain the above copyright
! notice, this list of conditions and the following disclaimer.
!
! * Redistributions in binary form must reproduce the above
! copyright notice, this list of conditions and the following
! disclaimer in the documentation and/or other materials provided
! with the distribution.
!
! * Neither the name of the authors nor the names of its
! contributors may be used to endorse or promote products derived
! from this software without specific prior written permission.
!
! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
! "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
! LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
! FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
! COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
! INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
! BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
! LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
! CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
! LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
! ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
! POSSIBILITY OF SUCH DAMAGE.
!
! Defines a vector list
module vector_list
use, intrinsic :: iso_fortran_env, only : error_unit
use vector, only : vector_ptr_t, vector_t
use iso_c_binding, only : c_ptr
use num_types, only : rp
use utils, only : neko_error
use comm, only : pe_rank
implicit none
private

!> vector_list_t, To be able to group vectors together
type, public :: vector_list_t
type(vector_ptr_t), allocatable :: items(:)
contains
!> Constructor. Allocates array and pointers.
procedure, pass(this) :: init => vector_list_init
!> Destructor.
procedure, pass(this) :: free => vector_list_free
!> Append a vector to the list.
procedure, pass(this) :: append => vector_list_append
generic :: get => get_by_index, get_by_name
!> Get an item pointer by array index
procedure, pass(this) :: get_by_index => vector_list_get_by_index
!> Get an item pointer by vector name
procedure, pass(this) :: get_by_name => vector_list_get_by_name
!> Point item at given index.
generic :: assign => assign_to_ptr, assign_to_vector_ptr
procedure, pass(this) :: assign_to_ptr => vector_list_assign_to_ptr
procedure, pass(this) :: assign_to_vector_ptr => &
vector_list_assign_to_vector_ptr
procedure, pass(this) :: assign_to_vector => vector_list_assign_to_vector

!> Get device pointer for a given index.
procedure, pass(this) :: x_d => vector_list_x_d
!> Get pointer to the raw data array for a given index.
procedure, pass(this) :: x => vector_list_x
!> Get number of items in the list.
procedure, pass(this) :: size => vector_list_size
!> Get the size of an item in the list.
procedure, pass(this) :: item_size => vector_list_item_size
!> Get the name for an item in the list.
procedure, pass(this) :: name => vector_list_name
end type vector_list_t

contains
!> Constructor. Just allocates the array.
!! @param size The size of the list to preallocate
subroutine vector_list_init(this, size)
class(vector_list_t), intent(inout) :: this
integer, intent(in) :: size

call this%free()

allocate(this%items(size))
end subroutine vector_list_init

!> Get number of items in the list.
pure function vector_list_size(this) result(n)
class(vector_list_t), intent(in) :: this
integer :: n
n = size(this%items)
end function vector_list_size

!> Get an item pointer by array index
!! @param i The index of the item.
function vector_list_get_by_index(this, i) result(f)
class(vector_list_t), target, intent(inout) :: this
type(vector_t), pointer :: f
integer, intent(in) :: i
f => this%items(i)%ptr
end function vector_list_get_by_index

!> Get an item pointer by array index
!! @param name The name of the item.
function vector_list_get_by_name(this, name) result(f)
class(vector_list_t), target, intent(inout) :: this
type(vector_t), pointer :: f
character(len=*), intent(in) :: name
integer :: i

nullify(f)

do i = 1, this%size()
if (this%name(i) .eq. trim(name)) then
f => this%items(i)%ptr
return
end if
end do

if (pe_rank .eq. 0) then
write(error_unit,*) "Current vector list contents:"

do i = 1, this%size()
write(error_unit,*) "- ", this%name(i)
end do
end if

call neko_error("No vector with name " // trim(name) // " found in list")
end function vector_list_get_by_name

!> Append a vector to the list.
!! @param f The vector to append.
subroutine vector_list_append(this, f)
class(vector_list_t), intent(inout) :: this
class(vector_t), intent(in), target :: f
type(vector_ptr_t), allocatable :: tmp(:)
integer :: len

if (.not. allocated(this%items)) then
allocate(this%items(1))
call this%items(1)%init(f)
return
end if

len = size(this%items)

allocate(tmp(len+1))
tmp(1:len) = this%items
call move_alloc(tmp, this%items)
call this%items(len+1)%init(f)

end subroutine vector_list_append

!> Destructor.
subroutine vector_list_free(this)
class(vector_list_t), intent(inout) :: this
integer :: i, n_fields

if (allocated(this%items)) then
n_fields = this%size()
do i = 1, n_fields
call this%items(i)%free()
end do
deallocate(this%items)
end if

end subroutine vector_list_free

!> Get device pointer for a given index
!! @param i The index of the item.
function vector_list_x_d(this, i) result(ptr)
class(vector_list_t), intent(in) :: this
integer, intent(in) :: i
type(c_ptr) :: ptr

ptr = this%items(i)%ptr%x_d
end function vector_list_x_d

function vector_list_x(this, i) result(x)
class(vector_list_t), target, intent(in) :: this
real(kind=rp), pointer, contiguous :: x(:)
integer, intent(in) :: i
x => this%items(i)%ptr%x
end function vector_list_x

!> Get the size of item `i`.
!! @param i The index of the item.
function vector_list_item_size(this, i) result(size)
class(vector_list_t), target, intent(in) :: this
integer, intent(in) :: i
integer :: size

size = this%items(i)%ptr%size()

end function vector_list_item_size

!> Point item at a given index.
!! @param i The index of the item.
!! @param ptr A vector pointer to point the item to.
subroutine vector_list_assign_to_ptr(this, i, ptr)
class(vector_list_t), intent(inout) :: this
integer, intent(in) :: i
type(vector_t), pointer, intent(in) :: ptr

call this%items(i)%init(ptr)

end subroutine vector_list_assign_to_ptr

!> Point item at a given index.
!! @param i The index of the item.
!! @param ptr An encapsulated vector pointer to point the item to.
subroutine vector_list_assign_to_vector_ptr(this, i, ptr)
class(vector_list_t), intent(inout) :: this
integer, intent(in) :: i
type(vector_ptr_t), target, intent(in) :: ptr

call this%items(i)%init(ptr%ptr)
end subroutine vector_list_assign_to_vector_ptr

!> Point item at a given index.
!! @param i The index of the item.
!! @param vec A vector to point the item to.
subroutine vector_list_assign_to_vector(this, i, vec)
class(vector_list_t), intent(inout) :: this
integer, intent(in) :: i
type(vector_t), target, intent(in) :: vec

call this%items(i)%init(vec)
end subroutine vector_list_assign_to_vector

!> Get the name for an item in the list.
!! @param i The index of the item.
function vector_list_name(this, i) result(result)
class(vector_list_t), target, intent(in) :: this
integer, intent(in) :: i
character(len=80) :: result

result = this%items(i)%ptr%name
end function vector_list_name


end module vector_list
1 change: 1 addition & 0 deletions src/neko.f90
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ module neko
use field_list, only : field_list_t
use user_source_term, only : user_source_term_t
use vector, only : vector_t, vector_ptr_t
use vector_list, only : vector_list_t
use matrix, only : matrix_t
use tensor
use simulation_component, only : simulation_component_t, &
Expand Down
Loading