Neko 1.99.3
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
hpfrt_source_term.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 json_module, only : json_file
41 use source_term, only : source_term_t
42 use coefs, only : coef_t
44 use registry, only : neko_registry
46 use time_state, only : time_state_t
47 use utils, only : neko_error
48 implicit none
49 private
50
65 type, public, extends(source_term_t) :: hpfrt_source_term_t
67 integer :: filter_modes = 0
69 real(kind=rp) :: chi = 0.0_rp
73 type(field_list_t) :: source_fields
74 contains
76 procedure, pass(this) :: init => hpfrt_source_term_init_from_json
78 procedure, pass(this) :: init_from_components => &
81 procedure, pass(this) :: free => hpfrt_source_term_free
83 procedure, pass(this) :: compute_ => hpfrt_source_term_compute
84 end type hpfrt_source_term_t
85
86contains
92 subroutine hpfrt_source_term_init_from_json(this, json, fields, coef, &
93 variable_name)
94 class(hpfrt_source_term_t), intent(inout) :: this
95 type(json_file), intent(inout) :: json
96 type(field_list_t), intent(in), target :: fields
97 type(coef_t), intent(in), target :: coef
98 character(len=*), intent(in) :: variable_name
99 real(kind=rp) :: filter_weight, start_time, end_time
100 integer :: filter_modes
101
102 call json_get_or_lookup(json, "filter_weight", filter_weight)
103 call json_get_or_lookup(json, "filter_modes", filter_modes)
104 call json_get_or_default(json, "start_time", start_time, 0.0_rp)
105 call json_get_or_default(json, "end_time", end_time, huge(0.0_rp))
106
107 call hpfrt_source_term_init_from_components(this, fields, coef, &
108 filter_weight, filter_modes, start_time, end_time, variable_name)
109
111
120 subroutine hpfrt_source_term_init_from_components(this, fields, coef, &
121 filter_weight, filter_modes, start_time, end_time, field_name)
122 class(hpfrt_source_term_t), intent(inout) :: this
123 class(field_list_t), intent(in), target :: fields
124 type(coef_t), intent(in), target :: coef
125 real(kind=rp), intent(in) :: filter_weight
126 integer, intent(in) :: filter_modes
127 real(kind=rp), intent(in) :: start_time
128 real(kind=rp), intent(in) :: end_time
129 character(len=*), intent(in) :: field_name
130 integer :: nx, i, k0
131 real(kind=rp) :: amp
132 real(kind=rp), allocatable :: transfer(:)
133 type(field_t), pointer :: source_field
134
135 call this%free()
136 call this%init_base(fields, coef, start_time, end_time)
137
138 if (fields%size() .ne. 1 .and. fields%size() .ne. 3) then
139 call neko_error("HPFRT source term expects either 1 or 3 fields.")
140 end if
141
142 nx = coef%dof%xh%lx
143 if (filter_modes .lt. 1 .or. filter_modes .gt. nx) then
144 call neko_error("HPFRT filter_modes must be between 1 and lx.")
145 end if
146
147 this%filter_modes = filter_modes
148 this%chi = -abs(filter_weight)
149
150 allocate(transfer(nx))
151 transfer = 1.0_rp
152 k0 = nx - filter_modes
153 do i = k0 + 1, nx
154 amp = real((i - k0) * (i - k0), kind=rp) / &
155 real(filter_modes * filter_modes, kind=rp)
156 transfer(i) = 1.0_rp - amp
157 end do
158
159 call this%filter%init_from_components(coef, "nonBoyd", transfer)
160
161 call this%source_fields%init(fields%size())
162
163 if (fields%size() .eq. 3) then
164 call this%source_fields%assign(1, neko_registry%get_field("u"))
165 call this%source_fields%assign(2, neko_registry%get_field("v"))
166 call this%source_fields%assign(3, neko_registry%get_field("w"))
167 else
168 if (.not. neko_registry%field_exists(field_name)) then
169 call neko_error("HPFRT source field does not exist: " // &
170 trim(field_name))
171 end if
172 source_field => neko_registry%get_field(field_name)
173 call this%source_fields%assign(1, source_field)
174 end if
175
176 deallocate(transfer)
177
179
181 subroutine hpfrt_source_term_free(this)
182 class(hpfrt_source_term_t), intent(inout) :: this
183
184 call this%free_base()
185 call this%filter%free()
186 call this%source_fields%free()
187
188 this%filter_modes = 0
189 this%chi = 0.0_rp
190
191 end subroutine hpfrt_source_term_free
192
195 subroutine hpfrt_source_term_compute(this, time)
196 class(hpfrt_source_term_t), intent(inout) :: this
197 type(time_state_t), intent(in) :: time
198 type(field_t), pointer :: rhs, source, work
199 integer :: i, work_idx
200
201 call neko_scratch_registry%request_field(work, work_idx, .false.)
202
203 do i = 1, this%fields%size()
204 rhs => this%fields%get(i)
205 source => this%source_fields%get(i)
206
207 call this%filter%apply(work, source)
208 call field_sub3(work, source, work)
209 call field_cmult(work, this%chi)
210 call field_add2(rhs, work)
211 end do
212
213 call neko_scratch_registry%relinquish_field(work_idx)
214
215 end subroutine hpfrt_source_term_compute
216
217end module hpfrt_source_term
double real
Retrieves a parameter by name or assigns a provided default value. In the latter case also adds the m...
Coefficients.
Definition coef.f90:34
Implements elementwise_filter_t.
subroutine, public field_sub3(a, b, c, n)
Vector subtraction .
subroutine, public field_add2(a, b, n)
Vector addition .
subroutine, public field_cmult(a, c, n)
Multiplication by constant c .
Defines a field.
Definition field.f90:34
Filter to be applied to a scalar field.
Definition filter.f90:38
Implements the hpfrt_source_term_t type.
subroutine hpfrt_source_term_init_from_components(this, fields, coef, filter_weight, filter_modes, start_time, end_time, field_name)
The constructor from type components.
subroutine hpfrt_source_term_free(this)
Destructor.
subroutine hpfrt_source_term_compute(this, time)
Computes the source term and adds the result to fields.
subroutine hpfrt_source_term_init_from_json(this, json, fields, coef, variable_name)
The common constructor using a JSON object.
Utilities for retrieving parameters from the case files.
integer, parameter, public rp
Global precision used in computations.
Definition num_types.f90:12
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.
Implements the source_term_t type and a wrapper source_term_wrapper_t.
Module with things related to the simulation time.
Utilities.
Definition utils.f90:35
Coefficients defined on a given (mesh, ) tuple. Arrays use indices (i,j,k,e): element e,...
Definition coef.f90:63
Implements the elementwise filter for SEM.
field_list_t, To be able to group fields together
High-pass filter relaxation source term.
Base abstract type for source terms.
A struct that contains all info about the time, expand as needed.