Neko 1.99.3
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
coriolis_source_term.f90
Go to the documentation of this file.
1! Copyright (c) 2024, 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
47 use field, only : field_t
48 use registry, only : neko_registry
49 use time_state, only : time_state_t
50 implicit none
51 private
52
54 type, public, extends(source_term_t) :: coriolis_source_term_t
56 real(kind=rp) :: omega(3)
58 real(kind=rp) :: u_geo(3) = 0
59 contains
61 procedure, pass(this) :: init => coriolis_source_term_init_from_json
63 procedure, pass(this) :: init_from_compenents => &
66 procedure, pass(this) :: free => coriolis_source_term_free
68 procedure, pass(this) :: compute_ => coriolis_source_term_compute
70
71contains
77 subroutine coriolis_source_term_init_from_json(this, json, fields, coef, &
78 variable_name)
79 class(coriolis_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 ! Rotation vector and geostrophic wind
85 real(kind=rp), allocatable :: rotation_vec(:), u_geo(:)
86 ! Alternative parameters to set the rotation vector
87 real(kind=rp) :: omega, phi, f, pi
88 real(kind=rp) :: start_time, end_time
89
90 call json_get_or_lookup_or_default(json, "start_time", start_time, 0.0_rp)
91 call json_get_or_lookup_or_default(json, "end_time", end_time, huge(0.0_rp))
92
93 if (json%valid_path("geostrophic_wind")) then
94 call json_get_or_lookup(json, "geostrophic_wind", u_geo)
95
96 if (size(u_geo) .ne. 3) then
97 call neko_error("The geostrophic wind should have 3 components.")
98 end if
99 else
100 allocate(u_geo(3))
101 u_geo = 0.0_rp
102 end if
103
104 if (json%valid_path("rotation_vector")) then
105 call json_get_or_lookup(json, "rotation_vector", rotation_vec)
106
107 if (size(rotation_vec) .ne. 3) then
108 call neko_error("The rotation vector should have 3 components.")
109 end if
110 else if (json%valid_path("omega") .and. json%valid_path("phi")) then
111 call json_get_or_lookup(json, "phi", phi)
112 call json_get_or_lookup(json, "omega", omega)
113
114 allocate(rotation_vec(3))
115 pi = 4 * atan(1.0_rp)
116 rotation_vec(1) = 0.0_rp
117 rotation_vec(2) = omega * cos(phi * pi / 180 )
118 rotation_vec(3) = omega * sin(phi * pi / 180)
119 else if (json%valid_path("f")) then
120 call json_get_or_lookup(json, "f", f)
121
122 allocate(rotation_vec(3))
123 rotation_vec(1) = 0.0_rp
124 rotation_vec(2) = 0.0_rp
125 rotation_vec(3) = 0.5_rp * f
126 else
127 call neko_error("Specify either rotation_vector, phi and omega, or f &
128 & for the Coriolis source term.")
129 end if
130
131
132
133 call coriolis_source_term_init_from_components(this, fields, rotation_vec, &
134 u_geo, coef, start_time, end_time)
135
137
145 subroutine coriolis_source_term_init_from_components(this, fields, omega, &
146 u_geo, coef, start_time, end_time)
147 class(coriolis_source_term_t), intent(inout) :: this
148 class(field_list_t), intent(in), target :: fields
149 real(kind=rp), intent(in) :: omega(3)
150 real(kind=rp), intent(in) :: u_geo(3)
151 type(coef_t) :: coef
152 real(kind=rp), intent(in) :: start_time
153 real(kind=rp), intent(in) :: end_time
154
155 call this%free()
156 call this%init_base(fields, coef, start_time, end_time)
157
158 if (fields%size() .ne. 3) then
159 call neko_error("Number of fields for the Coriolis force must be 3.")
160 end if
161
162 this%omega = omega
163 this%u_geo = u_geo
165
168 class(coriolis_source_term_t), intent(inout) :: this
169
170 call this%free_base()
171 end subroutine coriolis_source_term_free
172
175 subroutine coriolis_source_term_compute(this, time)
176 class(coriolis_source_term_t), intent(inout) :: this
177 type(time_state_t), intent(in) :: time
178 type(field_t), pointer :: u, v, w
179
180 u => neko_registry%get_field("u")
181 v => neko_registry%get_field("v")
182 w => neko_registry%get_field("w")
183
184 if (neko_bcknd_device .eq. 1) then
185 call coriolis_source_term_compute_device(u, v, w, this%fields, &
186 this%omega, this%u_geo)
187 else
188 call coriolis_source_term_compute_cpu(u, v, w, this%fields, this%omega, &
189 this%u_geo)
190 end if
191 end subroutine coriolis_source_term_compute
192
193end module coriolis_source_term
Coefficients.
Definition coef.f90:34
Implements the cpu kernel for the coriolis_source_term_t type. Maintainer: Timofey Mukha.
subroutine, public coriolis_source_term_compute_cpu(u, v, w, fields, omega, u_geo)
Computes the generic Coriolis source term on the cpu.
Implements the device kernel for the coriolis_source_term_t type.
subroutine, public coriolis_source_term_compute_device(u, v, w, fields, omega, u_geo)
Computes the Coriolis source term on the device.
Implements the coriolis_source_term_t type. Maintainer: Timofey Mukha.
subroutine coriolis_source_term_compute(this, time)
Computes the source term and adds the result to fields.
subroutine coriolis_source_term_init_from_components(this, fields, omega, u_geo, coef, start_time, end_time)
The constructor from type components.
subroutine coriolis_source_term_free(this)
Destructor.
subroutine coriolis_source_term_init_from_json(this, json, fields, coef, variable_name)
The common constructor using a JSON object.
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
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
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:58
This source term adds the Coriolis force.
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.