Neko 1.99.5
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
spatial_average_output.f90
Go to the documentation of this file.
1! Copyright (c) 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 field, only : field_t
37 use field_list, only : field_list_t
39 use map_1d, only : map_1d_t
40 use map_2d, only : map_2d_t
41 use coefs, only : coef_t
42 use device, only : device_to_host
43 use field_math, only : field_copy
44 use matrix, only : matrix_t
45 use output, only : output_t
46 use registry, only : neko_registry
49 implicit none
50 private
51
53 type, public, extends(output_t) :: spatial_average_output_t
55 type(field_list_t) :: fields
61 integer :: output_dim = 0
62 contains
64 procedure, pass(this) :: init => spatial_average_output_init
66 procedure, pass(this) :: free => spatial_average_output_free
68 procedure, pass(this) :: sample => spatial_average_output_sample
70
71contains
72
79 subroutine spatial_average_output_init(this, fields, coef, &
80 avg_direction, filename)
81 class(spatial_average_output_t), intent(inout) :: this
82 character(len=*), intent(in) :: fields(:)
83 type(coef_t), target, intent(inout) :: coef
84 character(len=*), intent(in) :: avg_direction
85 character(len=*), intent(in) :: filename
86 character(len=NEKO_FNAME_LEN) :: output_filename
87 integer :: i
88
89 call this%free()
90 output_filename = trim(filename)
91
92 call this%fields%init(size(fields))
93 do i = 1, size(fields)
94 call this%fields%assign(i, neko_registry%get_field(trim(fields(i))))
95 end do
96
97 select case (trim(avg_direction))
98 case ('x', 'y', 'z')
99 this%output_dim = 2
100 output_filename = trim(output_filename) // '.fld'
101 call this%map_2d%init_char(coef, avg_direction, 1e-7_rp)
102 case ('xy', 'xz', 'yz')
103 this%output_dim = 1
104 output_filename = trim(output_filename) // '.csv'
105 call this%map_1d%init_char(coef, avg_direction, 1e-7_rp)
106 case default
107 call neko_error('Unsupported avg_direction for spatial_average: ' // &
108 trim(avg_direction))
109 end select
110
111 call this%init_base(output_filename)
112 end subroutine spatial_average_output_init
113
116 class(spatial_average_output_t), intent(inout) :: this
117
118 call this%free_base()
119 call this%fields%free()
120 call this%map_1d%free()
121 call this%map_2d%free()
122
123 this%output_dim = 0
124 end subroutine spatial_average_output_free
125
129 class(spatial_average_output_t), intent(inout) :: this
130 real(kind=rp), intent(in) :: t
131 type(fld_file_data_t) :: output_2d
132 type(matrix_t) :: output_1d
133 type(field_list_t) :: temp_fields
134 type(field_t), pointer :: temp_field
135 integer, allocatable :: temp_indices(:)
136 integer :: i
137
138 select case (this%output_dim)
139 case (1)
140 call this%fields%copy_from(device_to_host, .true.)
141 call this%map_1d%average_planes(output_1d, this%fields)
142 call this%file_%write(output_1d, t)
143 call output_1d%free()
144 case (2)
145 ! map_2d mutates input, so we need temporaries from the scratch registry
146 allocate(temp_indices(this%fields%size()))
147 call temp_fields%init(this%fields%size())
148 do i = 1, this%fields%size()
149 call neko_scratch_registry%request_field(temp_field, &
150 temp_indices(i), .false.)
151 call field_copy(temp_field, this%fields%items(i)%ptr)
152 call temp_fields%assign(i, temp_field)
153 end do
154 call temp_fields%copy_from(device_to_host, .true.)
155 call this%map_2d%average(output_2d, temp_fields)
156 call this%file_%write(output_2d, t)
157 call output_2d%free()
158 call temp_fields%free()
159 call neko_scratch_registry%relinquish_field(temp_indices)
160 deallocate(temp_indices)
161 case default
162 call neko_error('Invalid spatial_average output dimension')
163 end select
164 end subroutine spatial_average_output_sample
165
166end module spatial_average_output
Coefficients.
Definition coef.f90:34
Device abstraction, common interface for various accelerators.
Definition device.F90:34
integer, parameter, public device_to_host
Definition device.F90:48
subroutine, public field_copy(a, b, n)
Copy a vector .
Defines a field.
Definition field.f90:34
Simple module to handle fld file series. Provides an interface to the different fields sotred in a fl...
Creates a 1d GLL point map along a specified direction based on the connectivity in the mesh.
Definition map_1d.f90:36
Maps a 3D dofmap to a 2D spectral element grid.
Definition map_2d.f90:36
Defines a matrix.
Definition matrix.f90:34
integer, parameter, public rp
Global precision used in computations.
Definition num_types.f90:12
Defines an output.
Definition output.f90:34
Defines a registry for storing solution fields.
Definition registry.f90:34
type(registry_t), target, public neko_registry
Global field registry.
Definition registry.f90:144
Defines a registry for storing and requesting temporary objects This can be used when you have a func...
type(scratch_registry_t), target, public neko_scratch_registry
Global scratch registry.
Output for spatially averaged fields.
subroutine spatial_average_output_free(this)
Destructor.
subroutine spatial_average_output_init(this, fields, coef, avg_direction, filename)
Constructor.
subroutine spatial_average_output_sample(this, t)
Sample the current fields, spatially average, and write.
Utilities.
Definition utils.f90:35
integer, parameter, public neko_fname_len
Definition utils.f90:42
Coefficients defined on a given (mesh, ) tuple. Arrays use indices (i,j,k,e): element e,...
Definition coef.f90:62
field_list_t, To be able to group fields together
Map every GLL point in the mesh to a level in one physical direction. Can be used to average across t...
Definition map_1d.f90:88
Abstract type defining an output type.
Definition output.f90:41