Neko 1.99.3
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
translation_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
37 use num_types, only : rp
38 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 utils, only : neko_error
45 use field, only : field_t
47 use operators, only : div
48 use device, only : device_sync
49 use registry, only : neko_registry
50 use time_state, only : time_state_t
52 implicit none
53 private
54
56 type, public, extends(source_term_t) :: translation_source_term_t
58 real(kind=rp) :: domain_vel(3)
59 contains
61 procedure, pass(this) :: init => translation_source_term_init_from_json
63 procedure, pass(this) :: init_from_components => &
66 procedure, pass(this) :: free => translation_source_term_free
68 procedure, pass(this) :: compute_ => translation_source_term_compute
70
71contains
77 subroutine translation_source_term_init_from_json(this, json, fields, coef, &
78 variable_name)
79 class(translation_source_term_t), intent(inout) :: this
80 type(json_file), intent(inout) :: json
81 type(field_list_t), intent(in), target :: fields
82 type(coef_t), intent(in), target :: coef
83 character(len=*), intent(in) :: variable_name
84 real(kind=rp), allocatable :: domain_vel(:)
85 ! Alternative parameters to set the rotation vector
86 real(kind=rp) :: start_time, end_time
87
88 call json_get_or_lookup_or_default(json, "start_time", start_time, 0.0_rp)
89 call json_get_or_lookup_or_default(json, "end_time", end_time, huge(0.0_rp))
90
91 if (json%valid_path("domain_velocity")) then
92 call json_get_or_lookup(json, "domain_velocity", domain_vel)
93
94 if (size(domain_vel) .ne. 3) then
95 call neko_error("The domain velocity should have 3 components.")
96 end if
97 else
98 allocate(domain_vel(3))
99 domain_vel = 0.0_rp
100 end if
101
103 domain_vel, coef, start_time, end_time)
104
106
113 subroutine translation_source_term_init_from_components(this, fields, domain_vel, &
114 coef, start_time, end_time)
115 class(translation_source_term_t), intent(inout) :: this
116 class(field_list_t), intent(in), target :: fields
117 real(kind=rp), intent(in) :: domain_vel(3)
118 type(coef_t) :: coef
119 real(kind=rp), intent(in) :: start_time
120 real(kind=rp), intent(in) :: end_time
121
122 call this%free()
123 call this%init_base(fields, coef, start_time, end_time)
124
125 if (fields%size() .ne. 3) then
126 call neko_error("Number of fields for the translation force must be 3.")
127 end if
128
129 this%domain_vel = domain_vel
131
134 class(translation_source_term_t), intent(inout) :: this
135
136 call this%free_base()
137 end subroutine translation_source_term_free
138
146 subroutine translation_source_term_compute(this, time)
147 class(translation_source_term_t), intent(inout) :: this
148 type(time_state_t), intent(in) :: time
149 type(field_t), pointer :: u, v, w
150 type(field_t), pointer :: work1, work2, work3
151 type(field_t), pointer :: work4, work5, work6, work7
152 integer :: tmp_index(7)
153 type(field_t), pointer :: fx, fy, fz
154
155 u => neko_registry%get_field("u")
156 v => neko_registry%get_field("v")
157 w => neko_registry%get_field("w")
158
159 fx => this%fields%get_by_index(1)
160 fy => this%fields%get_by_index(2)
161 fz => this%fields%get_by_index(3)
162
163
164 call neko_scratch_registry%request_field(work1, tmp_index(1), .false.)
165 call neko_scratch_registry%request_field(work2, tmp_index(2), .false.)
166 call neko_scratch_registry%request_field(work3, tmp_index(3), .false.)
167 call neko_scratch_registry%request_field(work4, tmp_index(4), .false.)
168 call neko_scratch_registry%request_field(work5, tmp_index(5), .false.)
169 call neko_scratch_registry%request_field(work6, tmp_index(6), .false.)
170 call neko_scratch_registry%request_field(work7, tmp_index(7), .false.)
171
172
173 ! Assign the velocities
174 work1 = this%domain_vel(1)
175 work2 = this%domain_vel(2)
176 work3 = this%domain_vel(3)
177
178 ! umesh_j * du/dx_j = div (umesh u) - u * div umesh but div umesh = 0 so we just calculate div (umesh u)
179 call field_col3(work4, u, work1, u%size())
180 call field_col3(work5, u, work2, u%size())
181 call field_col3(work6, u, work3, u%size())
182 call div(work7%x, work4%x, work5%x, work6%x, this%coef)
183 call field_add2(fx, work7, work7%size())
184
185 ! umesh_j * dv/dx_j
186 call field_col3(work4, v, work1, v%size())
187 call field_col3(work5, v, work2, v%size())
188 call field_col3(work6, v, work3, v%size())
189 call div(work7%x, work4%x, work5%x, work6%x, this%coef)
190 call field_add2(fy, work7, work7%size())
191
192 ! umesh_j * dw/dx_j
193 call field_col3(work4, w, work1, w%size())
194 call field_col3(work5, w, work2, w%size())
195 call field_col3(work6, w, work3, w%size())
196 call div(work7%x, work4%x, work5%x, work6%x, this%coef)
197 call field_add2(fz, work7, work7%size())
198
199 call device_sync()
200
201 ! Release the scratch fields
202 call neko_scratch_registry%relinquish_field(tmp_index)
203
204
206
Synchronize a device or stream.
Definition device.F90:113
Coefficients.
Definition coef.f90:34
Device abstraction, common interface for various accelerators.
Definition device.F90:34
subroutine, public field_add2(a, b, n)
Vector addition .
subroutine, public field_col3(a, b, c, n)
Vector multiplication with 3 vectors .
Defines a field.
Definition field.f90:34
Utilities for retrieving parameters from the case files.
Build configurations.
integer, parameter neko_bcknd_device
integer, parameter, public rp
Global precision used in computations.
Definition num_types.f90:12
Operators.
Definition operators.f90:34
subroutine, public div(res, ux, uy, uz, coef)
Compute the divergence of a vector field.
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.
Implements the coriolis_source_term_t type. Implements the translation_source_term_t type.
subroutine translation_source_term_free(this)
Destructor.
subroutine translation_source_term_init_from_json(this, json, fields, coef, variable_name)
The common constructor using a JSON object.
subroutine translation_source_term_compute(this, time)
Computes the source term and adds the result to fields.
subroutine translation_source_term_init_from_components(this, fields, domain_vel, coef, start_time, end_time)
The constructor from type components.
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
field_list_t, To be able to group fields together
Base abstract type for source terms.
A struct that contains all info about the time, expand as needed.
This source term adds the translation force.