Neko  0.9.99
A portable framework for high-order spectral element flow simulations
field_series.f90
Go to the documentation of this file.
1 ! Copyright (c) 2021-2023, 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 field, only : field_t
37  implicit none
38  private
39 
40  type, public :: field_series_t
41  type(field_t), pointer :: f => null()
42  type(field_t), allocatable :: lf(:)
43  integer, private :: len = 0
44  contains
45  procedure, pass(this) :: init => field_series_init
46  procedure, pass(this) :: free => field_series_free
47  procedure, pass(this) :: update => field_series_update
48  procedure, pass(this) :: set => field_series_set
49  procedure, pass(this) :: size => field_series_size
50  end type field_series_t
51 
53  type, public :: field_series_ptr_t
54  type(field_series_t), pointer :: ptr => null()
55  end type field_series_ptr_t
56 
57 contains
58 
60  subroutine field_series_init(this, f, len)
61  class(field_series_t), intent(inout) :: this
62  type(field_t), intent(inout), target :: f
63  integer :: len
64  character(len=80) :: name
65  character(len=5) :: id_str
66  integer :: i
67 
68  call this%free()
69 
70  this%f => f
71  this%len = len
72 
73  allocate(this%lf(len))
74 
75  do i = 1, this%len
76  write(id_str, '(I0)') i
77  name = trim(f%name)//'_lag'//id_str
78  call this%lf(i)%init(this%f%dof, name)
79  end do
80 
81  end subroutine field_series_init
82 
84  subroutine field_series_free(this)
85  class(field_series_t), intent(inout) :: this
86  integer :: i
87 
88  if (associated(this%f)) then
89  nullify(this%f)
90  end if
91 
92  do i = 1, this%len
93  call this%lf(i)%free()
94  end do
95 
96  end subroutine field_series_free
97 
99  function field_series_size(this) result(len)
100  class(field_series_t), intent(in) :: this
101  integer :: len
102  len = this%len
103  end function field_series_size
104 
106  subroutine field_series_update(this)
107  class(field_series_t), intent(inout) :: this
108  integer :: i
109 
110  do i = this%len, 2, -1
111  this%lf(i) = this%lf(i-1)
112  end do
113 
114  this%lf(1) = this%f
115 
116  end subroutine field_series_update
117 
119  subroutine field_series_set(this, g)
120  class(field_series_t), intent(inout) :: this
121  type(field_t), intent(in) :: g
122  integer :: i
123 
124  do i = 1, this%len
125  this%lf(i) = g
126  end do
127 
128  end subroutine field_series_set
129 
130 end module field_series
Stores a series fields.
subroutine field_series_set(this, g)
Set all fields in a series to g.
subroutine field_series_update(this)
Update a field series (evict oldest entry)
integer function field_series_size(this)
Return the size of the field series.
subroutine field_series_free(this)
Deallocates a field series.
subroutine field_series_init(this, f, len)
Initialize a field series of length len for a field f.
Defines a field.
Definition: field.f90:34
integer, parameter, public rp
Global precision used in computations.
Definition: num_types.f90:12
field_series_ptr_t, To easily obtain a pointer to a field series