Neko  0.9.0
A portable framework for high-order spectral element flow simulations
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
41  use neko_config, only : neko_bcknd_device
42  use utils, only : neko_error
45  implicit none
46  private
47 
51  type, public, extends(source_term_t) :: const_source_term_t
53  real(kind=rp), allocatable :: values(:)
54  contains
56  procedure, pass(this) :: init => const_source_term_init_from_json
58  procedure, pass(this) :: init_from_compenents => &
61  procedure, pass(this) :: free => const_source_term_free
63  procedure, pass(this) :: compute_ => const_source_term_compute
64  end type const_source_term_t
65 
66 contains
71  subroutine const_source_term_init_from_json(this, json, fields, coef)
72  class(const_source_term_t), intent(inout) :: this
73  type(json_file), intent(inout) :: json
74  type(field_list_t), intent(inout), target :: fields
75  type(coef_t), intent(inout), target :: coef
76  real(kind=rp), allocatable :: values(:)
77  real(kind=rp) :: start_time, end_time
78 
79  call json_get(json, "values", values)
80  call json_get_or_default(json, "start_time", start_time, 0.0_rp)
81  call json_get_or_default(json, "end_time", end_time, huge(0.0_rp))
82 
83 
84  call const_source_term_init_from_components(this, fields, values, coef, &
85  start_time, end_time)
86 
88 
95  subroutine const_source_term_init_from_components(this, fields, values, &
96  coef, start_time, end_time)
97  class(const_source_term_t), intent(inout) :: this
98  class(field_list_t), intent(inout), target :: fields
99  real(kind=rp), intent(in) :: values(:)
100  type(coef_t) :: coef
101  real(kind=rp), intent(in) :: start_time
102  real(kind=rp), intent(in) :: end_time
103 
104  call this%free()
105  call this%init_base(fields, coef, start_time, end_time)
106 
107  if (size(values) .ne. fields%size()) then
108  call neko_error("Number of fields and values inconsistent.")
109  end if
110 
111  this%values = values
113 
115  subroutine const_source_term_free(this)
116  class(const_source_term_t), intent(inout) :: this
117 
118  call this%free_base()
119  end subroutine const_source_term_free
120 
124  subroutine const_source_term_compute(this, t, tstep)
125  class(const_source_term_t), intent(inout) :: this
126  real(kind=rp), intent(in) :: t
127  integer, intent(in) :: tstep
128  integer :: n_fields, i, n
129 
130  n_fields = this%fields%size()
131 
132  n = this%fields%item_size(1)
133 
134  if (neko_bcknd_device .eq. 1) then
135  call const_source_term_compute_device(this%fields, this%values)
136  else
137  call const_source_term_compute_cpu(this%fields, this%values)
138  end if
139  end subroutine const_source_term_compute
140 
141 end module const_source_term
Retrieves a parameter by name or assigns a provided default value. In the latter case also adds the m...
Definition: json_utils.f90:54
Retrieves a parameter by name or throws an error.
Definition: json_utils.f90:45
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, t, tstep)
Computes the source term and adds the result to fields.
subroutine const_source_term_init_from_json(this, json, fields, coef)
The common constructor using a JSON object.
Utilities for retrieving parameters from the case files.
Definition: json_utils.f90:34
Build configurations.
Definition: neko_config.f90:34
integer, parameter neko_bcknd_device
Definition: neko_config.f90:44
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.
Definition: source_term.f90:34
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
Definition: field_list.f90:13
Base abstract type for source terms.
Definition: source_term.f90:43