Neko 1.99.5
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
spatial_average.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 json_module, only : json_file
38 use case, only : case_t
39 use time_state, only : time_state_t
41 use coefs, only : coef_t
44 implicit none
45 private
46
48 type, public, extends(simulation_component_t) :: spatial_average_t
51 contains
53 procedure, pass(this) :: init => spatial_average_init_from_json
55 procedure, pass(this) :: init_from_components => &
58 procedure, pass(this) :: free => spatial_average_free
60 procedure, pass(this) :: compute_ => spatial_average_compute
61 end type spatial_average_t
62
63contains
64
68 subroutine spatial_average_init_from_json(this, json, case)
69 class(spatial_average_t), intent(inout), target :: this
70 type(json_file), intent(inout) :: json
71 class(case_t), intent(inout), target :: case
72 character(len=:), allocatable :: name
73 character(len=:), allocatable :: avg_direction
74 character(len=:), allocatable :: output_filename
75 character(len=NEKO_VARNAME_LEN), allocatable :: fields(:)
76
77 call this%init_base(json, case)
78
79 call json_get_or_default(json, 'name', name, 'spatial_average')
80 call json_get(json, 'fields', fields)
81 call json_get(json, 'avg_direction', avg_direction)
82 call json_get_or_default(json, 'output_filename', output_filename, &
83 'spatial_average')
84
85 call this%init_from_components(name, fields, case%fluid%c_Xh, &
86 avg_direction, output_filename)
87
88 if (allocated(fields)) deallocate(fields)
89 if (allocated(output_filename)) deallocate(output_filename)
90 if (allocated(avg_direction)) deallocate(avg_direction)
91 if (allocated(name)) deallocate(name)
93
100 subroutine spatial_average_init_from_components(this, name, fields, coef, &
101 avg_direction, output_filename)
102 class(spatial_average_t), target, intent(inout) :: this
103 character(len=*), intent(in) :: name
104 character(len=*), intent(in) :: fields(:)
105 type(coef_t), target, intent(inout) :: coef
106 character(len=*), intent(in) :: avg_direction
107 character(len=*), intent(in) :: output_filename
108 character(len=NEKO_FNAME_LEN) :: resolved_output_filename
109
110 this%name = name
111
112 if (allocated(this%case%output_directory) .and. &
113 len_trim(this%case%output_directory) .gt. 0) then
114 resolved_output_filename = trim(this%case%output_directory) // &
115 trim(output_filename)
116 else
117 resolved_output_filename = trim(output_filename)
118 end if
119
120 call this%output%init(fields, coef, avg_direction, &
121 resolved_output_filename)
122 call this%case%output_controller%add(this%output, &
123 this%output_controller%control_value, &
124 this%output_controller%control_mode)
126
128 subroutine spatial_average_free(this)
129 class(spatial_average_t), intent(inout) :: this
130
131 call this%free_base()
132 call this%output%free()
133 end subroutine spatial_average_free
134
137 subroutine spatial_average_compute(this, time)
138 class(spatial_average_t), intent(inout) :: this
139 type(time_state_t), intent(in) :: time
140 end subroutine spatial_average_compute
141
142end module spatial_average
Retrieves a parameter by name or assigns a provided default value. In the latter case also adds the m...
Retrieves a parameter by name or throws an error.
Defines a simulation case.
Definition case.f90:34
Coefficients.
Definition coef.f90:34
Utilities for retrieving parameters from the case files.
integer, parameter, public rp
Global precision used in computations.
Definition num_types.f90:12
Defines an output.
Definition output.f90:34
Simulation components are objects that encapsulate functionality that can be fit to a particular comp...
subroutine compute_(this, time)
Dummy compute function.
Output for spatially averaged fields.
Implements the spatial_average_t type.
subroutine spatial_average_free(this)
Destructor.
subroutine spatial_average_init_from_json(this, json, case)
Constructor from json.
subroutine spatial_average_compute(this, time)
Here to comply with the interface, does nothing.
subroutine spatial_average_init_from_components(this, name, fields, coef, avg_direction, output_filename)
Constructor from components.
Module with things related to the simulation time.
Utilities.
Definition utils.f90:35
integer, parameter, public neko_fname_len
Definition utils.f90:42
integer, parameter, public neko_varname_len
Definition utils.f90:43
Coefficients defined on a given (mesh, ) tuple. Arrays use indices (i,j,k,e): element e,...
Definition coef.f90:62
Base abstract class for simulation components.
A simulation component that writes spatial averages of registry fields.
A struct that contains all info about the time, expand as needed.