Neko 1.99.2
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
41 use source_term, only : source_term_t
42 use coefs, only : coef_t
44 use utils, only : neko_error
48 use registry, only : neko_registry
49 use time_state, only : time_state_t
50 implicit none
51 private
52
61 type, public, extends(source_term_t) :: boussinesq_source_term_t
63 type(field_t), pointer :: s => null()
65 real(kind=rp) :: ref_value = 0
67 real(kind=rp) :: g(3)
69 real(kind=rp) :: beta
70 contains
72 procedure, pass(this) :: init => boussinesq_source_term_init_from_json
74 procedure, pass(this) :: init_from_compenents => &
77 procedure, pass(this) :: free => boussinesq_source_term_free
79 procedure, pass(this) :: compute_ => boussinesq_source_term_compute
81
82contains
88 subroutine boussinesq_source_term_init_from_json(this, json, fields, coef, &
89 variable_name)
90 class(boussinesq_source_term_t), intent(inout) :: this
91 type(json_file), intent(inout) :: json
92 type(field_list_t), intent(in), target :: fields
93 type(coef_t), intent(in), target :: coef
94 character(len=*), intent(in) :: variable_name
95 real(kind=rp), allocatable :: values(:)
96 real(kind=rp) :: start_time, end_time, ref_value
97 character(len=:), allocatable :: scalar_name
98 real(kind=rp), allocatable :: g(:)
99 real(kind=rp) :: beta
100
101 if (.not. fields%size() == 3) then
102 call neko_error("Boussinesq term expects 3 fields to work on.")
103 end if
104
105 call json_get_or_default(json, "start_time", start_time, 0.0_rp)
106 call json_get_or_default(json, "end_time", end_time, huge(0.0_rp))
107
108 call json_get_or_default(json, "scalar_field", scalar_name, "temperature")
109
110 call json_get_or_lookup(json, "g", g)
111
112 if (.not. size(g) == 3) then
113 call neko_error("The gravity vector should have 3 components")
114 end if
115
116 call json_get_or_lookup(json, "reference_value", ref_value)
117 call json_get_or_default(json, "beta", beta, 1.0_rp/ref_value)
118
119 call boussinesq_source_term_init_from_components(this, fields, scalar_name,&
120 ref_value, g, beta, coef, start_time, end_time)
121
123
134 scalar_name, ref_value, g, beta, coef, start_time, end_time)
135 class(boussinesq_source_term_t), intent(inout) :: this
136 class(field_list_t), intent(in), target :: fields
137 character(len=*), intent(in) :: scalar_name
138 real(kind=rp), intent(in) :: ref_value
139 real(kind=rp), intent(in) :: g(3)
140 real(kind=rp), intent(in) :: beta
141 type(coef_t) :: coef
142 real(kind=rp), intent(in) :: start_time
143 real(kind=rp), intent(in) :: end_time
144
145 call this%free()
146 call this%init_base(fields, coef, start_time, end_time)
147
148 if (.not. neko_registry%field_exists(scalar_name)) then
149 call neko_registry%add_field(this%fields%dof(1), scalar_name)
150 end if
151 this%s => neko_registry%get_field(scalar_name)
152
153 this%ref_value = ref_value
154 this%g = g
155 this%beta = beta
157
160 class(boussinesq_source_term_t), intent(inout) :: this
161
162 call this%free_base()
163 nullify(this%s)
164 end subroutine boussinesq_source_term_free
165
169 subroutine boussinesq_source_term_compute(this, time)
170 class(boussinesq_source_term_t), intent(inout) :: this
171 type(time_state_t), intent(in) :: time
172 integer :: n_fields, i, n
173
174 n_fields = this%fields%size()
175 n = this%fields%item_size(1)
176
177 if (neko_bcknd_device .eq. 1) then
178 call boussinesq_source_term_compute_device(this%fields, this%s,&
179 this%ref_value, this%g, this%beta)
180 else
181 call boussinesq_source_term_compute_cpu(this%fields, this%s,&
182 this%ref_value, this%g, this%beta)
183 end if
184 end subroutine boussinesq_source_term_compute
185
186end 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 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:149
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:56
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.