Neko 1.99.9
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
vector_series.f90
Go to the documentation of this file.
1! Copyright (c) 2021-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!
35 use num_types, only : rp
36 use vector, only : vector_t
37 implicit none
38 private
39
43 type, public :: vector_series_t
44 type(vector_t), pointer :: v => null()
45 type(vector_t), allocatable :: lv(:)
46 integer, private :: len = 0
48 integer, private :: n_filled = 0
49 contains
51 procedure, pass(this) :: init => vector_series_init
53 procedure, pass(this) :: free => vector_series_free
54 procedure, pass(this) :: update => vector_series_update
55 procedure, pass(this) :: set => vector_series_set
57 procedure, pass(this) :: reset => vector_series_reset
59 procedure, pass(this) :: size => vector_series_size
61 procedure, pass(this) :: filled_size => vector_series_filled_size
62 end type vector_series_t
63
65 type, public :: vector_series_ptr_t
66 type(vector_series_t), pointer :: ptr => null()
67 end type vector_series_ptr_t
68
69contains
70
72 subroutine vector_series_init(this, v, len)
73 class(vector_series_t), intent(inout) :: this
74 type(vector_t), intent(inout), target :: v
75 integer :: len
76 character(len=80) :: name
77 character(len=5) :: id_str
78 integer :: i
79
80 call this%free()
81
82 this%v => v
83 this%len = len
84 this%n_filled = 0
85
86 allocate(this%lv(len))
87
88 do i = 1, this%len
89 write(id_str, '(I0)') i
90 name = trim(this%v%name)//'_lag'//id_str
91 call this%lv(i)%init(this%v%size(), name)
92 end do
93
94 end subroutine vector_series_init
95
97 subroutine vector_series_free(this)
98 class(vector_series_t), intent(inout) :: this
99 integer :: i
100
101 if (associated(this%v)) then
102 nullify(this%v)
103 end if
104
105
106 if (allocated(this%lv)) then
107 do i = 1, this%len
108 call this%lv(i)%free()
109 end do
110
111 deallocate(this%lv)
112 end if
113
114 this%len = 0
115 this%n_filled = 0
116
117 end subroutine vector_series_free
118
120 function vector_series_size(this) result(len)
121 class(vector_series_t), intent(in) :: this
122 integer :: len
123 len = this%len
124 end function vector_series_size
125
127 function vector_series_filled_size(this) result(n_filled)
128 class(vector_series_t), intent(in) :: this
129 integer :: n_filled
130
131 n_filled = this%n_filled
132 end function vector_series_filled_size
133
135 subroutine vector_series_update(this)
136 class(vector_series_t), intent(inout) :: this
137 integer :: i
138
139 do i = this%len, 2, -1
140 this%lv(i) = this%lv(i-1)
141 end do
142
143 this%lv(1) = this%v
144 this%n_filled = min(this%n_filled + 1, this%len)
145
146 end subroutine vector_series_update
147
149 subroutine vector_series_set(this, g)
150 class(vector_series_t), intent(inout) :: this
151 type(vector_t), intent(in) :: g
152 integer :: i
153
154 do i = 1, this%len
155 this%lv(i) = g
156 end do
157
158 this%n_filled = this%len
159
160 end subroutine vector_series_set
161
163 subroutine vector_series_reset(this)
164 class(vector_series_t), intent(inout) :: this
165 integer :: i
166
167 do i = 1, this%len
168 this%lv(i) = 0.0_rp
169 end do
170
171 this%n_filled = 0
172 end subroutine vector_series_reset
173
174end module vector_series
integer, parameter, public rp
Global precision used in computations.
Definition num_types.f90:14
Contains the vector_series_t type.
subroutine vector_series_set(this, g)
Set all vectors in a series to g.
integer function vector_series_filled_size(this)
Return the number of lag entries containing valid history.
subroutine vector_series_reset(this)
Reset the series to contain no valid history.
subroutine vector_series_free(this)
Deallocates a vector series.
integer function vector_series_size(this)
Return the size of the vector series.
subroutine vector_series_init(this, v, len)
Initialize a vector series of length len for a vector v.
subroutine vector_series_update(this)
Update a vector series (evict oldest entry)
Defines a vector.
Definition vector.f90:34
A wrapper for a pointer to a vector_series_t.
Stores a series (sequence) of vectors, logically connected to a base vector, and arranged according t...