Neko 1.99.1
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 use time_state, only : time_state_t
49 implicit none
50 private
51
60 type, public, extends(source_term_t) :: boussinesq_source_term_t
62 type(field_t), pointer :: s => null()
64 real(kind=rp) :: ref_value = 0
66 real(kind=rp) :: g(3)
68 real(kind=rp) :: beta
69 contains
71 procedure, pass(this) :: init => boussinesq_source_term_init_from_json
73 procedure, pass(this) :: init_from_compenents => &
76 procedure, pass(this) :: free => boussinesq_source_term_free
78 procedure, pass(this) :: compute_ => boussinesq_source_term_compute
80
81contains
87 subroutine boussinesq_source_term_init_from_json(this, json, fields, coef, &
88 variable_name)
89 class(boussinesq_source_term_t), intent(inout) :: this
90 type(json_file), intent(inout) :: json
91 type(field_list_t), intent(in), target :: fields
92 type(coef_t), intent(in), target :: coef
93 character(len=*), intent(in) :: variable_name
94 real(kind=rp), allocatable :: values(:)
95 real(kind=rp) :: start_time, end_time, ref_value
96 character(len=:), allocatable :: scalar_name
97 real(kind=rp), allocatable :: g(:)
98 real(kind=rp) :: beta
99
100 if (.not. fields%size() == 3) then
101 call neko_error("Boussinesq term expects 3 fields to work on.")
102 end if
103
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 json_get_or_default(json, "scalar_field", scalar_name, "temperature")
108 call json_get(json, "g", g)
109
110 if (.not. size(g) == 3) then
111 call neko_error("The gravity vector should have 3 components")
112 end if
113
114 call json_get(json, "reference_value", ref_value)
115 call json_get_or_default(json, "beta", beta, 1.0_rp/ref_value)
116
117 call boussinesq_source_term_init_from_components(this, fields, scalar_name,&
118 ref_value, g, beta, coef, start_time, end_time)
119
121
132 scalar_name, ref_value, g, beta, coef, start_time, end_time)
133 class(boussinesq_source_term_t), intent(inout) :: this
134 class(field_list_t), intent(in), target :: fields
135 character(len=*), intent(in) :: scalar_name
136 real(kind=rp), intent(in) :: ref_value
137 real(kind=rp), intent(in) :: g(3)
138 real(kind=rp), intent(in) :: beta
139 type(coef_t) :: coef
140 real(kind=rp), intent(in) :: start_time
141 real(kind=rp), intent(in) :: end_time
142
143 call this%free()
144 call this%init_base(fields, coef, start_time, end_time)
145
146 if (.not. neko_field_registry%field_exists(scalar_name)) then
147 call neko_field_registry%add_field(this%fields%dof(1), scalar_name)
148 end if
149 this%s => neko_field_registry%get_field(scalar_name)
150
151 this%ref_value = ref_value
152 this%g = g
153 this%beta = beta
155
158 class(boussinesq_source_term_t), intent(inout) :: this
159
160 call this%free_base()
161 nullify(this%s)
162 end subroutine boussinesq_source_term_free
163
167 subroutine boussinesq_source_term_compute(this, time)
168 class(boussinesq_source_term_t), intent(inout) :: this
169 type(time_state_t), intent(in) :: time
170 integer :: n_fields, i, n
171
172 n_fields = this%fields%size()
173 n = this%fields%item_size(1)
174
175 if (neko_bcknd_device .eq. 1) then
176 call boussinesq_source_term_compute_device(this%fields, this%s,&
177 this%ref_value, this%g, this%beta)
178 else
179 call boussinesq_source_term_compute_cpu(this%fields, this%s,&
180 this%ref_value, this%g, this%beta)
181 end if
182 end subroutine boussinesq_source_term_compute
183
184end 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_init_from_json(this, json, fields, coef, variable_name)
The common constructor using a JSON object.
subroutine boussinesq_source_term_compute(this, time)
Computes the source term and adds the result to fields.
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.
Module with things related to the simulation time.
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.
A struct that contains all info about the time, expand as needed.