Neko 1.99.1
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
const_source_term.f90
Go to the documentation of this file.
1! Copyright (c) 2023, 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 json_module, only : json_file
39 use source_term, only : source_term_t
40 use coefs, only : coef_t
42 use utils, only : neko_error
45 use time_state, only : time_state_t
46 implicit none
47 private
48
52 type, public, extends(source_term_t) :: const_source_term_t
54 real(kind=rp), allocatable :: values(:)
55 contains
57 procedure, pass(this) :: init => const_source_term_init_from_json
59 procedure, pass(this) :: init_from_compenents => &
62 procedure, pass(this) :: free => const_source_term_free
64 procedure, pass(this) :: compute_ => const_source_term_compute
65 end type const_source_term_t
66
67contains
73 subroutine const_source_term_init_from_json(this, json, fields, coef, &
74 variable_name)
75 class(const_source_term_t), intent(inout) :: this
76 type(json_file), intent(inout) :: json
77 type(field_list_t), intent(in), target :: fields
78 type(coef_t), intent(in), target :: coef
79 character(len=*), intent(in) :: variable_name
80 real(kind=rp), allocatable :: values(:)
81 real(kind=rp) :: start_time, end_time
82
83 call json_get(json, "values", values)
84 call json_get_or_default(json, "start_time", start_time, 0.0_rp)
85 call json_get_or_default(json, "end_time", end_time, huge(0.0_rp))
86
87
88 call const_source_term_init_from_components(this, fields, values, coef, &
89 start_time, end_time)
90
92
99 subroutine const_source_term_init_from_components(this, fields, values, &
100 coef, start_time, end_time)
101 class(const_source_term_t), intent(inout) :: this
102 class(field_list_t), intent(in), target :: fields
103 real(kind=rp), intent(in) :: values(:)
104 type(coef_t) :: coef
105 real(kind=rp), intent(in) :: start_time
106 real(kind=rp), intent(in) :: end_time
107
108 call this%free()
109 call this%init_base(fields, coef, start_time, end_time)
110
111 if (size(values) .ne. fields%size()) then
112 call neko_error("Number of fields and values inconsistent.")
113 end if
114
115 this%values = values
117
119 subroutine const_source_term_free(this)
120 class(const_source_term_t), intent(inout) :: this
121
122 call this%free_base()
123 end subroutine const_source_term_free
124
127 subroutine const_source_term_compute(this, time)
128 class(const_source_term_t), intent(inout) :: this
129 type(time_state_t), intent(in) :: time
130 integer :: n_fields, i, n
131
132 n_fields = this%fields%size()
133
134 n = this%fields%item_size(1)
135
136 if (neko_bcknd_device .eq. 1) then
137 call const_source_term_compute_device(this%fields, this%values)
138 else
139 call const_source_term_compute_cpu(this%fields, this%values)
140 end if
141 end subroutine const_source_term_compute
142
143end module const_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 const_source_term_t type.
subroutine, public const_source_term_compute_cpu(fields, values)
Computes the constant source term on the cpu.
Implements the device kernel for the const_source_term_t type.
subroutine, public const_source_term_compute_device(fields, values)
Computes the constant source term on the device.
Implements the const_source_term_t type.
subroutine const_source_term_free(this)
Destructor.
subroutine const_source_term_init_from_components(this, fields, values, coef, start_time, end_time)
The constructor from type components.
subroutine const_source_term_compute(this, time)
Computes the source term and adds the result to fields.
subroutine const_source_term_init_from_json(this, json, fields, coef, variable_name)
The common constructor using a JSON object.
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
A constant source term. The strength is specified with the values keyword, which should be an array,...
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.