Neko 1.99.9
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
mean_field.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!
34!
37 use stats_quant, only : stats_quant_t
38 use num_types, only : rp
39 use registry, only : neko_registry
40 use field, only : field_t
41 use utils, only : neko_varname_len
43 implicit none
44 private
45
47 type, public, extends(stats_quant_t) :: mean_field_t
51 type(field_t), pointer :: f => null()
53 type(field_t), pointer :: mf => null()
55 real(kind=rp) :: time
56 contains
58 procedure, pass(this) :: init => mean_field_init
60 procedure, pass(this) :: free => mean_field_free
62 procedure, pass(this) :: update => mean_field_update
64 procedure, pass(this) :: update_col3 => mean_field_update_col3
66 procedure, pass(this) :: update_dot3 => mean_field_update_dot3
68 procedure, pass(this) :: reset => mean_field_reset
69 end type mean_field_t
70
71contains
72
77 subroutine mean_field_init(this, f, field_name)
78 class(mean_field_t), intent(inout) :: this
79 type(field_t), intent(in), target :: f
80 character(len=*), optional, intent(in) :: field_name
81 character(len=NEKO_VARNAME_LEN) :: name
82
83 call this%free()
84
85 this%f => f
86 this%time = 0.0_rp
87
88 if (present(field_name)) then
89 name = field_name
90 else
91 write(name, '(A,A)') 'mean_', trim(f%name)
92 end if
93
94 call neko_registry%add_field(f%dof, trim(name))
95 this%mf => neko_registry%get_field(trim(name))
96
97 end subroutine mean_field_init
98
100 subroutine mean_field_free(this)
101 class(mean_field_t), intent(inout) :: this
102
103 if (associated(this%f)) then
104 nullify(this%f)
105 end if
106
107 if (associated(this%mf)) then
108 nullify(this%mf)
109 end if
110
111 end subroutine mean_field_free
112
114 subroutine mean_field_reset(this)
115 class(mean_field_t), intent(inout) :: this
116
117 this%time = 0.0
118 this%mf = 0.0_rp
119 end subroutine mean_field_reset
120
121
124 subroutine mean_field_update(this, k)
125 class(mean_field_t), intent(inout) :: this
126 real(kind=rp), intent(in) :: k
127
128 call field_cmult(this%mf, this%time, size(this%mf%x))
129 call field_add2s2(this%mf, this%f, k, size(this%mf%x))
130 this%time = this%time + k
131 call field_cmult(this%mf, 1.0_rp / this%time, size(this%mf%x))
132
133 end subroutine mean_field_update
134
140 subroutine mean_field_update_col3(this, k, a, b)
141 class(mean_field_t), intent(inout) :: this
142 real(kind=rp), intent(in) :: k
143 type(field_t), intent(in) :: a, b
144
145 call field_cmult(this%mf, this%time, size(this%mf%x))
146 call field_addcol3s2(this%mf, a, b, k, size(this%mf%x))
147 this%time = this%time + k
148 call field_cmult(this%mf, 1.0_rp / this%time, size(this%mf%x))
149
150 end subroutine mean_field_update_col3
151
157 subroutine mean_field_update_dot3(this, k, a1, a2, a3, b1, b2, b3)
158 class(mean_field_t), intent(inout) :: this
159 real(kind=rp), intent(in) :: k
160 type(field_t), intent(in) :: a1, a2, a3, b1, b2, b3
161
162 call field_cmult(this%mf, this%time, size(this%mf%x))
163 call field_addcol3s2(this%mf, a1, b1, k, size(this%mf%x))
164 call field_addcol3s2(this%mf, a2, b2, k, size(this%mf%x))
165 call field_addcol3s2(this%mf, a3, b3, k, size(this%mf%x))
166 this%time = this%time + k
167 call field_cmult(this%mf, 1.0_rp / this%time, size(this%mf%x))
168
169 end subroutine mean_field_update_dot3
170
171end module mean_field
172
subroutine, public field_add2s2(a, b, c1, n)
Vector addition with scalar multiplication (multiplication on second argument)
subroutine, public field_addcol3s2(a, b, c, s, n)
Returns .
subroutine, public field_cmult(a, c, n)
Multiplication by constant c .
Defines a field.
Definition field.f90:34
Implements mean_field_t.
subroutine mean_field_update_dot3(this, k, a1, a2, a3, b1, b2, b3)
Update the mean field using as the sample, without the need for a work field holding the sum.
subroutine mean_field_update_col3(this, k, a, b)
Update the mean field using the pointwise product as the sample, without the need for a work field h...
subroutine mean_field_update(this, k)
Update the mean field with a new sample.
subroutine mean_field_init(this, f, field_name)
Constructor.
subroutine mean_field_reset(this)
Resets a the mean field and the averaging time value to zero.
subroutine mean_field_free(this)
Destructor.
Build configurations.
integer, parameter neko_bcknd_device
integer, parameter, public rp
Global precision used in computations.
Definition num_types.f90:14
Defines a registry for storing solution fields.
Definition registry.f90:34
type(registry_t), target, public neko_registry
Global field registry.
Definition registry.f90:158
Defines a statistical quantity.
Utilities.
Definition utils.f90:35
integer, parameter, public neko_varname_len
Definition utils.f90:43
Computes the temporal mean of a field.
Abstract type defining a statistical quantity.