Neko  0.8.1
A portable framework for high-order spectral element flow simulations
mean_field.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 !
34 !
35 module mean_field
36  use neko_config
37  use stats_quant
38  use num_types, only : rp
39  use field, only : field_t
40  use math, only : add2s2
42  implicit none
43  private
44 
45  type, public, extends(stats_quant_t) :: mean_field_t
46  type(field_t), pointer :: f => null()
47  type(field_t) :: mf
48  real(kind=rp) :: time
49  contains
50  procedure, pass(this) :: init => mean_field_init
51  procedure, pass(this) :: free => mean_field_free
52  procedure, pass(this) :: update => mean_field_update
53  procedure, pass(this) :: reset => mean_field_reset
54  end type mean_field_t
55 
56 contains
57 
59  subroutine mean_field_init(this, f, field_name)
60  class(mean_field_t), intent(inout) :: this
61  type(field_t), intent(inout), target :: f
62  character(len=*), optional, intent(in) :: field_name
63  character(len=80) :: name
64 
65 
66  call this%free()
67 
68  this%f => f
69  this%time = 0.0_rp
70  if (present(field_name)) then
71  name = field_name
72  else
73  write(name, '(A,A)') 'mean_',trim(f%name)
74  end if
75 
76  call this%mf%init(f%dof, name)
77 
78  end subroutine mean_field_init
79 
81  subroutine mean_field_free(this)
82  class(mean_field_t), intent(inout) :: this
83 
84  if (associated(this%f)) then
85  nullify(this%f)
86  end if
87  call this%mf%free()
88 
89  end subroutine mean_field_free
90 
92  subroutine mean_field_reset(this)
93  class(mean_field_t), intent(inout) :: this
94 
95  this%time = 0.0
96  this%mf = 0.0_rp
97  end subroutine mean_field_reset
98 
99 
101  subroutine mean_field_update(this, k)
102  class(mean_field_t), intent(inout) :: this
103  real(kind=rp), intent(in) :: k
104 
105  if (neko_bcknd_device .eq. 1) then
106  call device_cmult(this%mf%x_d, this%time, size(this%mf%x))
107  call device_add2s2(this%mf%x_d, this%f%x_d, k, size(this%mf%x))
108  this%time = this%time + k
109  call device_cmult(this%mf%x_d, 1.0_rp / this%time, size(this%mf%x))
110  else
111  this%mf%x = this%mf%x * this%time
112  call add2s2(this%mf%x, this%f%x, k, this%mf%dof%size())
113  this%time = this%time + k
114  this%mf%x = this%mf%x / this%time
115  end if
116 
117  end subroutine mean_field_update
118 
119 end module mean_field
120 
subroutine, public device_add2s2(a_d, b_d, c1, n)
subroutine, public device_cmult(a_d, c, n)
Defines a field.
Definition: field.f90:34
Definition: math.f90:60
subroutine, public add2s2(a, b, c1, n)
Vector addition with scalar multiplication (multiplication on second argument)
Definition: math.f90:589
Defines a mean field.
Definition: mean_field.f90:35
subroutine mean_field_update(this, k)
Update a mean field.
Definition: mean_field.f90:102
subroutine mean_field_init(this, f, field_name)
Initialize a mean field for a field f.
Definition: mean_field.f90:60
subroutine mean_field_reset(this)
Resets a mean field.
Definition: mean_field.f90:93
subroutine mean_field_free(this)
Deallocates a mean field.
Definition: mean_field.f90:82
Build configurations.
Definition: neko_config.f90:34
integer, parameter neko_bcknd_device
Definition: neko_config.f90:44
integer, parameter, public rp
Global precision used in computations.
Definition: num_types.f90:12
Defines a statistical quantity.
Definition: stats_quant.f90:34
Abstract type defining a statistical quantity.
Definition: stats_quant.f90:40