Neko 1.99.1
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
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_default(json, "start_time", start_time, 0.0_rp)
91 call json_get_or_default(json, "end_time", end_time, huge(0.0_rp))
92
93 if (json%valid_path("geostrophic_wind")) then
94 call json_get(json, "geostrophic_wind", u_geo)
95 else
96 allocate(u_geo(3))
97 u_geo = 0.0_rp
98 end if
99
100 if (json%valid_path("rotation_vector")) then
101 call json_get(json, "rotation_vector", rotation_vec)
102 else if (json%valid_path("omega") .and. json%valid_path("phi")) then
103 call json_get(json, "phi", phi)
104 call json_get(json, "omega", omega)
105
106 allocate(rotation_vec(3))
107 pi = 4 * atan(1.0_rp)
108 rotation_vec(1) = 0.0_rp
109 rotation_vec(2) = omega * cos(phi * pi / 180 )
110 rotation_vec(3) = omega * sin(phi * pi / 180)
111 else if (json%valid_path("f")) then
112 call json_get(json, "f", f)
113
114 allocate(rotation_vec(3))
115 rotation_vec(1) = 0.0_rp
116 rotation_vec(2) = 0.0_rp
117 rotation_vec(3) = 0.5_rp * f
118 else
119 call neko_error("Specify either rotation_vector, phi and omega, or f &
120 & for the Coriolis source term.")
121 end if
122
123
124
125 call coriolis_source_term_init_from_components(this, fields, rotation_vec, &
126 u_geo, coef, start_time, end_time)
127
129
137 subroutine coriolis_source_term_init_from_components(this, fields, omega, &
138 u_geo, coef, start_time, end_time)
139 class(coriolis_source_term_t), intent(inout) :: this
140 class(field_list_t), intent(in), target :: fields
141 real(kind=rp), intent(in) :: omega(3)
142 real(kind=rp), intent(in) :: u_geo(3)
143 type(coef_t) :: coef
144 real(kind=rp), intent(in) :: start_time
145 real(kind=rp), intent(in) :: end_time
146
147 call this%free()
148 call this%init_base(fields, coef, start_time, end_time)
149
150 if (fields%size() .ne. 3) then
151 call neko_error("Number of fields for the Coriolis force must be 3.")
152 end if
153
154 this%omega = omega
155 this%u_geo = u_geo
157
160 class(coriolis_source_term_t), intent(inout) :: this
161
162 call this%free_base()
163 end subroutine coriolis_source_term_free
164
167 subroutine coriolis_source_term_compute(this, time)
168 class(coriolis_source_term_t), intent(inout) :: this
169 type(time_state_t), intent(in) :: time
170 type(field_t), pointer :: u, v, w
171
172 u => neko_field_registry%get_field("u")
173 v => neko_field_registry%get_field("v")
174 w => neko_field_registry%get_field("w")
175
176 if (neko_bcknd_device .eq. 1) then
177 call coriolis_source_term_compute_device(u, v, w, this%fields, &
178 this%omega, this%u_geo)
179 else
180 call coriolis_source_term_compute_cpu(u, v, w, this%fields, this%omega, &
181 this%u_geo)
182 end if
183 end subroutine coriolis_source_term_compute
184
185end module coriolis_source_term
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.
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 registry for storing solution fields.
type(field_registry_t), target, public neko_field_registry
Global field registry.
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
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:55
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.