Neko 0.9.99
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
boussinesq_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 use num_types, only : rp
36 use field_list, only : field_list_t
37 use field, only : field_t
38 use json_module, only : json_file
40 use source_term, only : source_term_t
41 use coefs, only : coef_t
43 use utils, only : neko_error
48 implicit none
49 private
50
59 type, public, extends(source_term_t) :: boussinesq_source_term_t
61 type(field_t), pointer :: s => null()
63 real(kind=rp) :: ref_value = 0
65 real(kind=rp) :: g(3)
67 real(kind=rp) :: beta
68 contains
70 procedure, pass(this) :: init => boussinesq_source_term_init_from_json
72 procedure, pass(this) :: init_from_compenents => &
75 procedure, pass(this) :: free => boussinesq_source_term_free
77 procedure, pass(this) :: compute_ => boussinesq_source_term_compute
79
80contains
85 subroutine boussinesq_source_term_init_from_json(this, json, fields, coef)
86 class(boussinesq_source_term_t), intent(inout) :: this
87 type(json_file), intent(inout) :: json
88 type(field_list_t), intent(in), target :: fields
89 type(coef_t), intent(in), target :: coef
90 real(kind=rp), allocatable :: values(:)
91 real(kind=rp) :: start_time, end_time, ref_value
92 character(len=:), allocatable :: scalar_name
93 real(kind=rp), allocatable :: g(:)
94 real(kind=rp) :: beta
95
96 if (.not. fields%size() == 3) then
97 call neko_error("Boussinesq term expects 3 fields to work on.")
98 end if
99
100 call json_get_or_default(json, "start_time", start_time, 0.0_rp)
101 call json_get_or_default(json, "end_time", end_time, huge(0.0_rp))
102
103 call json_get_or_default(json, "scalar_field", scalar_name, "s")
104 call json_get(json, "g", g)
105
106 if (.not. size(g) == 3) then
107 call neko_error("The gravity vector should have 3 components")
108 end if
109
110 call json_get(json, "reference_value", ref_value)
111 call json_get_or_default(json, "beta", beta, 1.0_rp/ref_value)
112
113 call boussinesq_source_term_init_from_components(this, fields, scalar_name,&
114 ref_value, g, beta, coef, start_time, end_time)
115
117
128 scalar_name, ref_value, g, beta, coef, start_time, end_time)
129 class(boussinesq_source_term_t), intent(inout) :: this
130 class(field_list_t), intent(in), target :: fields
131 character(len=*), intent(in) :: scalar_name
132 real(kind=rp), intent(in) :: ref_value
133 real(kind=rp), intent(in) :: g(3)
134 real(kind=rp), intent(in) :: beta
135 type(coef_t) :: coef
136 real(kind=rp), intent(in) :: start_time
137 real(kind=rp), intent(in) :: end_time
138
139 call this%free()
140 call this%init_base(fields, coef, start_time, end_time)
141
142 if (.not. neko_field_registry%field_exists(scalar_name)) then
143 call neko_field_registry%add_field(this%fields%dof(1), "s")
144 end if
145 this%s => neko_field_registry%get_field("s")
146
147 this%ref_value = ref_value
148 this%g = g
149 this%beta = beta
151
154 class(boussinesq_source_term_t), intent(inout) :: this
155
156 call this%free_base()
157 nullify(this%s)
158 end subroutine boussinesq_source_term_free
159
163 subroutine boussinesq_source_term_compute(this, t, tstep)
164 class(boussinesq_source_term_t), intent(inout) :: this
165 real(kind=rp), intent(in) :: t
166 integer, intent(in) :: tstep
167 integer :: n_fields, i, n
168
169 n_fields = this%fields%size()
170 n = this%fields%item_size(1)
171
172 if (neko_bcknd_device .eq. 1) then
173 call boussinesq_source_term_compute_device(this%fields, this%s,&
174 this%ref_value, this%g, this%beta)
175 else
176 call boussinesq_source_term_compute_cpu(this%fields, this%s,&
177 this%ref_value, this%g, this%beta)
178 end if
179 end subroutine boussinesq_source_term_compute
180
181end module boussinesq_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.
Implements the cpu kernel for the boussinesq_source_term_t type.
subroutine, public boussinesq_source_term_compute_cpu(fields, s, ref_value, g, beta)
Computes the Boussinesq source term on the cpu.
Implements the device kernel for the boussinesq_source_term_t type.
subroutine, public boussinesq_source_term_compute_device(fields, s, ref_value, g, beta)
Computes the Boussinesq source term on the device.
Implements the boussinesq_source_term_t type.
subroutine boussinesq_source_term_compute(this, t, tstep)
Computes the source term and adds the result to fields.
subroutine boussinesq_source_term_init_from_json(this, json, fields, coef)
The common constructor using a JSON object.
subroutine boussinesq_source_term_init_from_components(this, fields, scalar_name, ref_value, g, beta, coef, start_time, end_time)
The constructor from type components.
subroutine boussinesq_source_term_free(this)
Destructor.
Coefficients.
Definition coef.f90:34
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.
Utilities.
Definition utils.f90:35
Bouyancy source term accroding to the Boussinesq approximation.
Coefficients defined on a given (mesh, ) tuple. Arrays use indices (i,j,k,e): element e,...
Definition coef.f90:55
field_list_t, To be able to group fields together
Base abstract type for source terms.