Neko 1.99.9
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
scalar_ic.f90
Go to the documentation of this file.
1! Copyright (c) 2021-2026, 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 gather_scatter, only : gs_t, gs_op_add
37 use num_types, only : rp
38 use device_math, only : device_col2
40 use field, only : field_t
43 use coefs, only : coef_t
44 use math, only : col2, cfill, cfill_mask, abscmp
47 use json_module, only : json_file
51 use point_zone, only : point_zone_t
53 use logger, only : neko_log, log_size
55 use fld_file, only : fld_file_t
56 use checkpoint, only : chkp_t
57 use file, only : file_t
60 use space, only : space_t, gll
61 use field_list, only : field_list_t
64 implicit none
65 private
66
67 interface set_scalar_ic
68 module procedure set_scalar_ic_int, set_scalar_ic_usr
69 end interface set_scalar_ic
70
71 public :: set_scalar_ic
72
73contains
74
88 subroutine set_scalar_ic_int(s, coef, gs, type, params, i)
89 type(field_t), intent(inout) :: s
90 type(coef_t), intent(in) :: coef
91 type(gs_t), intent(inout) :: gs
92 character(len=*) :: type
93 type(json_file), intent(inout) :: params
94 integer, intent(in) :: i
95
96 ! Variables for retrieving JSON parameters
97 real(kind=rp) :: ic_value
98 character(len=:), allocatable :: read_str
99 real(kind=rp) :: zone_value
100
101 select case (trim(type))
102 case('uniform')
103
104 call json_get_or_lookup(params, 'value', ic_value)
105 call set_scalar_ic_uniform(s, ic_value)
106
107 case('expression')
108
109 call json_get(params, 'value', read_str)
110 call set_scalar_ic_expression(s, read_str)
111 if (allocated(read_str)) deallocate(read_str)
112
113 case('point_zone')
114
115 call json_get_or_lookup(params, 'base_value', ic_value)
116 call json_get(params, 'zone_name', read_str)
117 call json_get_or_lookup(params, 'zone_value', zone_value)
118
119 call set_scalar_ic_point_zone(s, ic_value, read_str, zone_value)
120
121 case('field')
122
123 block
124 character(len=NEKO_FNAME_LEN) :: fname, mesh_fname
125 logical :: interpolate
126 type(json_file) :: interp_subdict
127 integer :: tgt_scal_idx
128
129 call json_get(params, 'file_name', read_str)
130 fname = trim(read_str)
131
132 call json_get_or_default(params, 'mesh_file_name', read_str, "none")
133 mesh_fname = trim(read_str)
134
135 ! Give the user the option to select which scalar they want to import
136 ! the values from, in the fld file. 0 corresponds to temperature.
137 call json_get_or_default(params, 'target_index', tgt_scal_idx, i)
138
139 call json_get_or_default(params, 'interpolate', interpolate, .false.)
140 call json_get_subdict_or_empty(params, "interpolation", interp_subdict)
141
142 call set_scalar_ic_fld(s, fname, interpolate, mesh_fname, i, &
143 tgt_scal_idx, interp_subdict)
144
145 end block
146
147 case default
148 call neko_error('Invalid initial condition')
149 end select
150
151 call set_scalar_ic_common(s, coef, gs)
152
153 end subroutine set_scalar_ic_int
154
165 subroutine set_scalar_ic_usr(scheme_name, s, coef, gs, user_proc)
166 character(len=*), intent(in) :: scheme_name
167 type(field_t), target, intent(inout) :: s
168 type(coef_t), intent(in) :: coef
169 type(gs_t), intent(inout) :: gs
170 procedure(user_initial_conditions_intf) :: user_proc
171 real(kind=rp) :: sm, init
172 type(field_list_t) :: fields
173
174 call neko_log%message("Type: user")
175
176 call fields%init(1)
177 call fields%assign_to_field(1, s)
178
179 init = -huge(1.0_rp)
180 call field_cfill(s, init)
181
182 call user_proc(scheme_name, fields)
183
184 sm = field_glmin(s)
185 if (abscmp(sm, init)) call neko_error('Initial condition did not set s')
186
187 call set_scalar_ic_common(s, coef, gs)
188
189 end subroutine set_scalar_ic_usr
190
199 subroutine set_scalar_ic_common(s, coef, gs)
200 type(field_t), intent(inout) :: s
201 type(coef_t), intent(in) :: coef
202 type(gs_t), intent(inout) :: gs
203 integer :: n
204
205 n = s%dof%size()
206
207 ! Ensure continuity across elements for initial conditions
208 call gs%op(s%x, n, gs_op_add)
209
210 if (neko_bcknd_device .eq. 1) then
211 call device_col2(s%x_d, coef%mult_d, n)
212 else
213 call col2(s%x, coef%mult, n)
214 end if
215
216 end subroutine set_scalar_ic_common
217
222 subroutine set_scalar_ic_uniform(s, ic_value)
223 type(field_t), intent(inout) :: s
224 real(kind=rp), intent(in) :: ic_value
225 integer :: n
226 character(len=LOG_SIZE) :: log_buf
227
228 call neko_log%message("Type : uniform")
229 write (log_buf, '(A,ES12.6)') "Value: ", ic_value
230 call neko_log%message(log_buf)
231
232 call field_cfill(s, ic_value)
233
234 end subroutine set_scalar_ic_uniform
235
244 subroutine set_scalar_ic_expression(s, expr)
245 type(field_t), intent(inout) :: s
246 character(len=*), intent(in) :: expr
247
248 call neko_log%message("Type : expression")
249 call neko_log%message("Value: " // trim(expr))
250
251 call expression_eval_static(expr, s%x, s%dof%size(), &
252 s%dof%x%x, s%dof%y%x, s%dof%z%x, 'scalar initial condition')
253 call s%copy_from(host_to_device, .true.)
254
255 end subroutine set_scalar_ic_expression
256
264 subroutine set_scalar_ic_point_zone(s, base_value, zone_name, zone_value)
265 type(field_t), intent(inout) :: s
266 real(kind=rp), intent(in) :: base_value
267 character(len=*), intent(in) :: zone_name
268 real(kind=rp), intent(in) :: zone_value
269
270 ! Internal variables
271 character(len=LOG_SIZE) :: log_buf
272 class(point_zone_t), pointer :: zone
273 integer :: size
274
275 call neko_log%message("Type : point_zone")
276 write (log_buf, '(A,ES12.6)') "Base value: ", base_value
277 call neko_log%message(log_buf)
278 call neko_log%message("Zone name : " // trim(zone_name))
279 write (log_buf, '(A,ES12.6)') "Zone value: ", zone_value
280 call neko_log%message(log_buf)
281
282 size = s%dof%size()
283 zone => neko_point_zone_registry%get_point_zone(trim(zone_name))
284
285 call cfill(s%x, base_value, size)
286 call cfill_mask(s%x, zone_value, size, zone%mask%get(), zone%size)
287 call s%copy_from(host_to_device, .true.)
288
289 end subroutine set_scalar_ic_point_zone
290
306 subroutine set_scalar_ic_fld(s, file_name, &
307 interpolate, mesh_file_name, i, target_idx, global_interp_subdict)
308 type(field_t), target, intent(inout) :: s
309 character(len=*), intent(in) :: file_name
310 logical, intent(in) :: interpolate
311 character(len=*), intent(inout) :: mesh_file_name
312 integer, intent(in) :: i
313 integer, intent(in) :: target_idx
314 type(json_file), intent(inout) :: global_interp_subdict
315
316 character(len=LOG_SIZE) :: log_buf
317 type(field_t), pointer :: ss
318 type(field_list_t) :: s_tgt_list
319
320 if (i .ne. target_idx) then
321 write (log_buf, '(A,I0,A,I0)') "Loading scalar #", target_idx, &
322 " into scalar #", i
323 call neko_log%message(log_buf)
324 end if
325
326 ! use a pointer since import_fields needs a pointer as input
327 ss => s
328
329 ! Put ss in a field list of 1 element
330 call s_tgt_list%init(1)
331 call s_tgt_list%assign(1, ss)
332
333 call import_fields(file_name, global_interp_subdict, mesh_file_name, &
334 s_target_list = s_tgt_list, & ! The target field
335 s_index_list = [target_idx], & ! Take values from target scalar
336 interpolate = interpolate)
337
338 call s_tgt_list%free()
339
340 nullify(ss)
341 end subroutine set_scalar_ic_fld
342
343end module scalar_ic
Copy data between host and device (or device and device)
Definition device.F90:72
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.
Abstract interface for user defined initial conditions.
Definition user_intf.f90:73
Defines format-independent checkpoint registration and restart state.
Coefficients.
Definition coef.f90:34
subroutine, public device_col2(a_d, b_d, n, strm)
Vector multiplication .
Device abstraction, common interface for various accelerators.
Definition device.F90:34
integer, parameter, public host_to_device
Definition device.F90:48
integer, parameter, public device_to_host
Definition device.F90:48
Evaluation of mathematical expressions given as strings in the case file.
subroutine, public expression_eval_static(str, res, n, x, y, z, usage)
Compile an expression and evaluate it in a set of points, in a context where there is no time state.
real(kind=rp) function, public field_glmin(a, n)
Global minimum of all elements in a field .
subroutine, public field_cfill(a, c, n)
Set all elements to a constant c .
Defines a field.
Definition field.f90:34
Module for file I/O operations.
Definition file.f90:34
Simple module to handle fld file series. Provides an interface to the different fields sotred in a fl...
NEKTON fld file format.
Definition fld_file.f90:35
Gather-scatter.
Implements global_interpolation given a dofmap.
Importation of fields from fld files.
Routines to interpolate between different spaces.
Utilities for retrieving parameters from the case files.
subroutine, public json_get_subdict_or_empty(json, key, output)
Extract a sub-object from a json object and returns an empty object if the key is missing.
Logging routines.
Definition log.f90:34
type(log_t), public neko_log
Global log stream.
Definition log.f90:92
integer, parameter, public log_size
Definition log.f90:46
Definition math.f90:60
subroutine, public cfill(a, c, n)
Set all elements to a constant c .
Definition math.f90:601
subroutine, public col2(a, b, n)
Vector multiplication .
Definition math.f90:1085
subroutine, public cfill_mask(a, c, n, mask, n_mask)
Fill a constant to a masked vector. .
Definition math.f90:492
Build configurations.
integer, parameter neko_bcknd_device
integer, parameter, public rp
Global precision used in computations.
Definition num_types.f90:14
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.
subroutine set_scalar_ic_fld(s, file_name, interpolate, mesh_file_name, i, target_idx, global_interp_subdict)
Set the initial condition of the scalar based on a field. @detail The field is read from an fld file....
subroutine set_scalar_ic_point_zone(s, base_value, zone_name, zone_value)
Point zone initial condition.
subroutine set_scalar_ic_common(s, coef, gs)
Set scalar initial condition (common)
subroutine set_scalar_ic_int(s, coef, gs, type, params, i)
Set scalar initial condition (builtin)
Definition scalar_ic.f90:89
subroutine set_scalar_ic_expression(s, expr)
Expression initial condition.
subroutine set_scalar_ic_usr(scheme_name, s, coef, gs, user_proc)
Set scalar intial condition (user defined)
Defines a function space.
Definition space.f90:34
integer, parameter, public gll
Definition space.f90:50
Interfaces for user interaction with NEKO.
Definition user_intf.f90:34
Utilities.
Definition utils.f90:35
integer function, public extract_fld_file_index(fld_filename, default_index)
Extracts the index of a field file. For example, "myfield.f00045" will return 45. If the suffix of th...
Definition utils.f90:248
integer, parameter, public neko_fname_len
Definition utils.f90:42
subroutine, public neko_warning(warning_msg)
Reports a warning to standard output.
Definition utils.f90:454
subroutine, public filename_chsuffix(fname, new_fname, new_suffix)
Change a filename's suffix.
Definition utils.f90:195
subroutine, public filename_suffix(fname, suffix)
Extract a filename's suffix.
Definition utils.f90:163
Collection of live simulation data registered for checkpointing.
Coefficients defined on a given (mesh, ) tuple. Arrays use indices (i,j,k,e): element e,...
Definition coef.f90:136
field_list_t, To be able to group fields together
A wrapper around a polymorphic generic_file_t that handles its init. This is essentially a factory fo...
Definition file.f90:56
Interface for NEKTON fld files.
Definition fld_file.f90:66
Gather-scatter kernel.
Implements global interpolation for arbitrary points in the domain.
Interpolation between two space::space_t.
Base abstract type for point zones.
The function space for the SEM solution fields.
Definition space.f90:64