Neko  0.8.99
A portable framework for high-order spectral element flow simulations
scalar_ic.f90
Go to the documentation of this file.
1 ! Copyright (c) 2021, 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 !
34 module scalar_ic
35  use gather_scatter, only : gs_t, gs_op_add
36  use neko_config, only : neko_bcknd_device
37  use num_types, only : rp
38  use device_math, only : device_col2
40  use field, only : field_t
41  use utils, only : neko_error
42  use coefs, only : coef_t
43  use math, only : col2, cfill, cfill_mask
44  use user_intf, only : useric_scalar
45  use json_module, only : json_file
46  use json_utils, only: json_get
47  use point_zone, only: point_zone_t
49  implicit none
50  private
51 
52  interface set_scalar_ic
53  module procedure set_scalar_ic_int, set_scalar_ic_usr
54  end interface set_scalar_ic
55 
56  public :: set_scalar_ic
57 
58 contains
59 
69  subroutine set_scalar_ic_int(s, coef, gs, type, params)
70  type(field_t), intent(inout) :: s
71  type(coef_t), intent(in) :: coef
72  type(gs_t), intent(inout) :: gs
73  character(len=*) :: type
74  type(json_file), intent(inout) :: params
75 
76  ! Variables for retrieving JSON parameters
77  real(kind=rp) :: ic_value
78  character(len=:), allocatable :: zone_name
79  real(kind=rp) :: zone_value
80 
81  if (trim(type) .eq. 'uniform') then
82  call json_get(params, 'case.scalar.initial_condition.value', ic_value)
83  call set_scalar_ic_uniform(s, ic_value)
84  else if (trim(type) .eq. 'point_zone') then
85  call json_get(params, 'case.scalar.initial_condition.base_value', &
86  ic_value)
87  call json_get(params, 'case.scalar.initial_condition.zone_name', &
88  zone_name)
89  call json_get(params, 'case.scalar.initial_condition.zone_value', &
90  zone_value)
91  call set_scalar_ic_point_zone(s, ic_value, zone_name, zone_value)
92  else
93  call neko_error('Invalid initial condition')
94  end if
95 
96  call set_scalar_ic_common(s, coef, gs)
97 
98  end subroutine set_scalar_ic_int
99 
107  subroutine set_scalar_ic_usr(s, coef, gs, usr_ic, params)
108  type(field_t), intent(inout) :: s
109  type(coef_t), intent(in) :: coef
110  type(gs_t), intent(inout) :: gs
111  procedure(useric_scalar) :: usr_ic
112  type(json_file), intent(inout) :: params
113 
114  call usr_ic(s, params)
115 
116  call set_scalar_ic_common(s, coef, gs)
117 
118  end subroutine set_scalar_ic_usr
119 
126  subroutine set_scalar_ic_common(s, coef, gs)
127  type(field_t), intent(inout) :: s
128  type(coef_t), intent(in) :: coef
129  type(gs_t), intent(inout) :: gs
130  integer :: n
131 
132  n = s%dof%size()
133  if (neko_bcknd_device .eq. 1) then
134  call device_memcpy(s%x, s%x_d, n, &
135  host_to_device, sync=.false.)
136  end if
137 
138  ! Ensure continuity across elements for initial conditions
139  call gs%op(s%x, n, gs_op_add)
140 
141  if (neko_bcknd_device .eq. 1) then
142  call device_col2(s%x_d, coef%mult_d, n)
143  else
144  call col2(s%x, coef%mult, n)
145  end if
146 
147  end subroutine set_scalar_ic_common
148 
153  subroutine set_scalar_ic_uniform(s, ic_value)
154  type(field_t), intent(inout) :: s
155  real(kind=rp), intent(in) :: ic_value
156  integer :: n
157  s = ic_value
158  n = s%dof%size()
159  if (neko_bcknd_device .eq. 1) then
160  call cfill(s%x, ic_value, n)
161  end if
162 
163  end subroutine set_scalar_ic_uniform
164 
172  subroutine set_scalar_ic_point_zone(s, base_value, zone_name, zone_value)
173  type(field_t), intent(inout) :: s
174  real(kind=rp), intent(in):: base_value
175  character(len=*), intent(in) :: zone_name
176  real(kind=rp), intent(in) :: zone_value
177 
178  ! Internal variables
179  class(point_zone_t), pointer :: zone
180  integer :: size
181 
182  size = s%dof%size()
183  zone => neko_point_zone_registry%get_point_zone(trim(zone_name))
184 
185  call set_scalar_ic_uniform(s, base_value)
186  call cfill_mask(s%x, zone_value, size, zone%mask, zone%size)
187 
188  end subroutine set_scalar_ic_point_zone
189 
190 end module scalar_ic
Copy data between host and device (or device and device)
Definition: device.F90:51
Retrieves a parameter by name or throws an error.
Definition: json_utils.f90:44
Abstract interface for user defined scalar initial conditions.
Definition: user_intf.f90:70
Coefficients.
Definition: coef.f90:34
subroutine, public device_col2(a_d, b_d, n)
Vector multiplication .
Device abstraction, common interface for various accelerators.
Definition: device.F90:34
integer, parameter, public host_to_device
Definition: device.F90:47
Defines a field.
Definition: field.f90:34
Gather-scatter.
Utilities for retrieving parameters from the case files.
Definition: json_utils.f90:34
Definition: math.f90:60
subroutine, public cfill(a, c, n)
Set all elements to a constant c .
Definition: math.f90:314
subroutine, public col2(a, b, n)
Vector multiplication .
Definition: math.f90:689
subroutine, public cfill_mask(a, c, size, mask, mask_size)
Fill a constant to a masked vector. .
Definition: math.f90:263
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
type(point_zone_registry_t), target, public neko_point_zone_registry
Global point_zone registry.
Scalar initial condition.
Definition: scalar_ic.f90:34
subroutine set_scalar_ic_uniform(s, ic_value)
Uniform initial condition.
Definition: scalar_ic.f90:154
subroutine set_scalar_ic_point_zone(s, base_value, zone_name, zone_value)
Point zone initial condition.
Definition: scalar_ic.f90:173
subroutine set_scalar_ic_common(s, coef, gs)
Set scalar initial condition (common)
Definition: scalar_ic.f90:127
subroutine set_scalar_ic_usr(s, coef, gs, usr_ic, params)
Set scalar intial condition (user defined)
Definition: scalar_ic.f90:108
subroutine set_scalar_ic_int(s, coef, gs, type, params)
Set scalar initial condition (builtin)
Definition: scalar_ic.f90:70
Interfaces for user interaction with NEKO.
Definition: user_intf.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
Base abstract type for point zones.
Definition: point_zone.f90:47