Neko 1.99.11
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
fluid_scheme_base.f90
Go to the documentation of this file.
1! Copyright (c) 2025-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!
34 use coefs, only : coef_t
35 use dirichlet, only : dirichlet_t
36 use dofmap, only : dofmap_t
37 use field, only : field_t
39 use gather_scatter, only : gs_t
40 use json_module, only : json_file
41 use json_utils, only : json_get
42 use logger, only : neko_log, log_size
44 use num_types, only : rp, dp
45 use checkpoint, only : chkp_t
47 use space, only : space_t
51 use utils, only : neko_error
52 use bc_list, only : bc_list_t
53 use field_list, only : field_list_t
54 use time_state, only : time_state_t
55 implicit none
56 private
57 public :: fluid_scheme_base_t, fluid_scheme_base_factory
58
59 !> Base type of all fluid formulations.
60 type, abstract :: fluid_scheme_base_t
61 !> A name that can be used to distinguish this solver in e.g. user routines
62 character(len=:), allocatable :: name
63
64 type(space_t) :: xh !< Function space \f$ X_h \f$
65 type(dofmap_t) :: dm_xh !< Dofmap associated with \f$ X_h \f$
66 type(gs_t) :: gs_xh !< Gather-scatter associated with \f$ X_h \f$
67 type(coef_t) :: c_xh !< Coefficients associated with \f$ X_h \f$
68
69 type(time_scheme_controller_t), allocatable :: ext_bdf
70
71 !> The velocity field
72 type(field_t), pointer :: u => null() !< x-component of Velocity
73 type(field_t), pointer :: v => null() !< y-component of Velocity
74 type(field_t), pointer :: w => null() !< z-component of Velocity
75 type(field_t), pointer :: p => null() !< Pressure
76 type(field_series_t) :: ulag, vlag, wlag !< fluid field (lag)
77
78 !> Checkpoint
79 type(chkp_t), pointer :: chkp => null()
80
81 !> X-component of the right-hand side.
82 type(field_t), pointer :: f_x => null()
83 !> Y-component of the right-hand side.
84 type(field_t), pointer :: f_y => null()
85 !> Z-component of the right-hand side.
86 type(field_t), pointer :: f_z => null()
87
88 !> Boundary conditions
89 ! List of boundary conditions for pressure
90 type(bc_list_t) :: bcs_prs
91 ! List of boundary conditions for velocity
92 type(bc_list_t) :: bcs_vel
93
94 type(mesh_t), pointer :: msh => null() !< Mesh
95
96 !> Boundary condition labels (if any)
97 character(len=NEKO_MSH_MAX_ZLBL_LEN), allocatable :: bc_labels(:)
98
99 !> Density field
100 type(field_t), pointer :: rho => null()
101
102 !> The dynamic viscosity
103 type(field_t), pointer :: mu => null()
104
105 !> A helper that packs material properties to pass to the user routine.
106 type(field_list_t) :: material_properties
107
108 !> Is the fluid frozen at the moment
109 logical :: freeze = .false.
110
111 !> User material properties routine
112 procedure(user_material_properties_intf), nopass, pointer :: &
113 user_material_properties => null()
114
115 contains
116 !> Constructor
117 procedure(fluid_scheme_base_init_intrf), pass(this), deferred :: init
118 !> Destructor
119 procedure(fluid_scheme_base_free_intrf), pass(this), deferred :: free
120 !> Advance one step in time
121 procedure(fluid_scheme_base_step_intrf), pass(this), deferred :: step
122 !> Restart from a checkpoint
123 procedure(fluid_scheme_base_restart_intrf), pass(this), deferred :: restart
124 !> Set the initial condition
125 procedure, pass(this) :: set_initial_condition => &
127 !> Set the initial condition, for overrides of `set_initial_condition`
128 procedure, pass(this) :: set_initial_condition_base => &
130 !> Set the initial condition with the user routine
132 pass(this), deferred :: set_user_initial_condition
133 ! Setup boundary conditions
134 procedure(fluid_scheme_setup_bcs_intrf), pass(this), deferred :: setup_bcs
135
136 !> Set the user inflow
137 procedure(validate_intrf), pass(this), deferred :: validate
138 !> Compute the CFL number
139 procedure(fluid_scheme_base_compute_cfl_intrf), pass(this), deferred :: &
140 compute_cfl
141 !> Set rho and mu
142 procedure(update_material_properties), pass(this), deferred :: &
144 end type fluid_scheme_base_t
145
146 !> Initialize all fields
147 abstract interface
148 subroutine fluid_base_init_all_intrf(this, msh, lx, params, kspv_init, &
149 kspp_init, scheme, user)
151 import mesh_t
152 import json_file
153 import user_t
154 import rp
155 import log_size
156 class(fluid_scheme_base_t), target, intent(inout) :: this
157 type(mesh_t), target, intent(inout) :: msh
158 integer, intent(inout) :: lx
159 type(json_file), target, intent(inout) :: params
160 type(user_t), target, intent(in) :: user
161 logical :: kspv_init
162 logical :: kspp_init
163 character(len=*), intent(in) :: scheme
164 real(kind=rp) :: abs_tol
165 integer :: integer_val, ierr
166 logical :: logical_val
167 character(len=:), allocatable :: solver_type, precon_type
168 character(len=LOG_SIZE) :: log_buf
169 real(kind=rp) :: gjp_param_a, gjp_param_b
170 end subroutine fluid_base_init_all_intrf
171 end interface
172
173 !> Initialize common data for the current scheme
174 abstract interface
175 subroutine fluid_base_init_common_intrf(this, msh, lx, params, scheme, &
176 user, kspv_init)
178 import mesh_t
179 import json_file
180 import user_t
181 import dirichlet_t
182 import log_size
183 import rp
184 class(fluid_scheme_base_t), target, intent(inout) :: this
185 type(mesh_t), target, intent(inout) :: msh
186 integer, intent(inout) :: lx
187 character(len=*), intent(in) :: scheme
188 type(json_file), target, intent(inout) :: params
189 type(user_t), target, intent(in) :: user
190 logical, intent(in) :: kspv_init
191 type(dirichlet_t) :: bdry_mask
192 character(len=LOG_SIZE) :: log_buf
193 real(kind=rp), allocatable :: real_vec(:)
194 real(kind=rp) :: real_val, kappa, b, z0
195 logical :: logical_val
196 integer :: integer_val, ierr
197 type(json_file) :: wm_json
198 character(len=:), allocatable :: string_val1, string_val2
199 end subroutine fluid_base_init_common_intrf
200 end interface
201
202 !> Deallocate a fluid formulation
203 abstract interface
204 subroutine fluid_base_free_intrf(this)
206 class(fluid_scheme_base_t), intent(inout) :: this
207 end subroutine fluid_base_free_intrf
208 end interface
209
210 !> Abstract interface to initialize a fluid formulation
211 !! @param msh The mesh.
212 !! @param lx The number of GLL points in each direction.
213 !! @param params The fluid parameters, i.e. `case.fluid`.
214 !! @param numerics_params The numerical parameters, i.e. `case.numerics`.
215 !! @param user Type with user-defined procedures.
216 !! @param chkp Checkpoint for restarts.
217 !! @param output_boundary Whether to write the boundary condition markers
218 !! to file.
219 abstract interface
220 subroutine fluid_scheme_base_init_intrf(this, msh, lx, params, &
221 numerics_params, user, chkp, output_boundary)
223 import json_file
224 import mesh_t
225 import user_t
226 import chkp_t
228 class(fluid_scheme_base_t), target, intent(inout) :: this
229 type(mesh_t), target, intent(inout) :: msh
230 integer, intent(in) :: lx
231 type(json_file), target, intent(inout) :: params
232 type(json_file), target, intent(inout) :: numerics_params
233 type(user_t), target, intent(in) :: user
234 type(chkp_t), target, intent(inout) :: chkp
235 logical, intent(in) :: output_boundary
236 end subroutine fluid_scheme_base_init_intrf
237 end interface
238
239 !> Abstract interface to dealocate a fluid formulation
240 abstract interface
243 class(fluid_scheme_base_t), intent(inout) :: this
244 end subroutine fluid_scheme_base_free_intrf
245 end interface
246
247 !> Abstract interface to compute a time-step
248 abstract interface
249 subroutine fluid_scheme_base_step_intrf(this, time, dt_controller)
250 import time_state_t
253 class(fluid_scheme_base_t), target, intent(inout) :: this
254 type(time_state_t), intent(in) :: time
255 type(time_step_controller_t), intent(in) :: dt_controller
256 end subroutine fluid_scheme_base_step_intrf
257 end interface
258
259 !> Abstract interface to restart a fluid scheme
260 abstract interface
261 subroutine fluid_scheme_base_restart_intrf(this, chkp)
263 import chkp_t
264 class(fluid_scheme_base_t), target, intent(inout) :: this
265 type(chkp_t), intent(inout) :: chkp
267 end interface
268
269 !> Abstract interface to set the initial condition of a fluid scheme with
270 !! the user routine
271 abstract interface
274 class(fluid_scheme_base_t), intent(inout) :: this
275 type(user_t), intent(in) :: user
277 end interface
278
279 !> Abstract interface to setup boundary conditions
280 abstract interface
281 subroutine fluid_scheme_setup_bcs_intrf(this, user, params)
282 import fluid_scheme_base_t, user_t, json_file
283 class(fluid_scheme_base_t), target, intent(inout) :: this
284 type(user_t), target, intent(in) :: user
285 type(json_file), intent(inout) :: params
286 end subroutine fluid_scheme_setup_bcs_intrf
287 end interface
288
289 !> Abstract interface to validate the user inflow
290 abstract interface
291 subroutine validate_intrf(this)
293 class(fluid_scheme_base_t), target, intent(inout) :: this
294 end subroutine validate_intrf
295 end interface
296
297 !> Abstract interface to sets rho and mu
298 abstract interface
299 subroutine update_material_properties(this, time)
301 class(fluid_scheme_base_t), intent(inout) :: this
302 type(time_state_t), intent(in) :: time
303 end subroutine update_material_properties
304 end interface
305
306 !> Compute the CFL number
307 abstract interface
308 function fluid_scheme_base_compute_cfl_intrf(this, dt) result(c)
310 import dp
311 class(fluid_scheme_base_t), intent(in) :: this
312 real(kind=dp), intent(in) :: dt
313 real(kind=dp) :: c
315 end interface
316
317 interface
318 !> Initialise a fluid scheme
319 module subroutine fluid_scheme_base_factory(object, type_name)
320 class(fluid_scheme_base_t), intent(inout), allocatable :: object
321 character(len=*) :: type_name
322 end subroutine fluid_scheme_base_factory
323 end interface
324
325contains
326
327 !> Set the initial condition of the velocity and pressure. A built-in
328 !! initial condition is set here, a user one by `set_user_initial_condition`.
329 !! @param params The fluid parameters, i.e. `case.fluid`.
330 !! @param user Type with user-defined procedures.
331 !! @param is_restart Whether the case is restarting from a checkpoint.
332 subroutine fluid_scheme_base_set_initial_condition(this, params, user, &
333 is_restart)
334 class(fluid_scheme_base_t), intent(inout) :: this
335 type(json_file), intent(inout) :: params
336 type(user_t), intent(in) :: user
337 logical, intent(in) :: is_restart
338 character(len=:), allocatable :: ic_type
339 type(json_file) :: ic_params
340
341 call neko_log%section("Fluid initial condition ")
342
343 if (is_restart) then
344 call neko_log%message("Restart file specified, " // &
345 "initial conditions ignored")
346 else
347 call json_get(params, 'initial_condition.type', ic_type)
348
349 ! Common, non-user initial conditions are handled here by the
350 ! base type.
351 if (trim(ic_type) .ne. 'user') then
352 call json_get(params, 'initial_condition', ic_params)
353 call set_flow_ic_builtin(this%u, this%v, this%w, this%p, this%c_Xh, &
354 this%gs_Xh, ic_type, ic_params)
355 call ic_params%destroy()
356 else
357 call this%set_user_initial_condition(user)
358 end if
359
360 deallocate(ic_type)
361 end if
362
363 call neko_log%end_section()
364
365 end subroutine fluid_scheme_base_set_initial_condition
366
367end module fluid_scheme_base
Initialize common data for the current scheme.
Abstract interface to dealocate a fluid formulation.
Abstract interface to initialize a fluid formulation.
Abstract interface to restart a fluid scheme.
Abstract interface to set the initial condition of a fluid scheme with the user routine.
Abstract interface to compute a time-step.
Abstract interface to setup boundary conditions.
Abstract interface to sets rho and mu.
Abstract interface to validate the user inflow.
Retrieves a parameter by name or throws an error.
Abstract interface for setting material properties.
Defines a list of bc_t.
Definition bc_list.f90:34
Defines format-independent checkpoint registration and restart state.
Coefficients.
Definition coef.f90:34
Defines a dirichlet boundary condition.
Definition dirichlet.f90:34
Defines a mapping of the degrees of freedom.
Definition dofmap.f90:35
Contains the field_serties_t type.
Defines a field.
Definition field.f90:34
Initial flow condition.
Definition flow_ic.f90:34
subroutine, public set_flow_ic_builtin(u, v, w, p, coef, gs, type, params)
Set initial flow condition (builtin).
Definition flow_ic.f90:81
subroutine fluid_scheme_base_set_initial_condition(this, params, user, is_restart)
Initialise a fluid scheme.
Gather-scatter.
Utilities for retrieving parameters from the case files.
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
Defines a mesh.
Definition mesh.f90:34
integer, parameter, public neko_msh_max_zlbl_len
Max length of a zone label.
Definition mesh.f90:67
integer, parameter, public dp
Definition num_types.f90:10
integer, parameter, public rp
Global precision used in computations.
Definition num_types.f90:14
Defines a function space.
Definition space.f90:34
Compound scheme for the advection and diffusion operators in a transport equation.
Module with things related to the simulation time.
Implements type time_step_controller.
Interfaces for user interaction with NEKO.
Definition user_intf.f90:34
Utilities.
Definition utils.f90:35
A list of allocatable `bc_t`. Follows the standard interface of lists.
Definition bc_list.f90:49
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
Generic Dirichlet boundary condition on .
Definition dirichlet.f90:49
field_list_t, To be able to group fields together
Stores a series (sequence) of fields, logically connected to a base field, and arranged according to ...
Base type of all fluid formulations.
Gather-scatter kernel.
The function space for the SEM solution fields.
Definition space.f90:64
Implements the logic to compute the time coefficients for the advection and diffusion operators in a ...
A struct that contains all info about the time, expand as needed.
A type collecting all the overridable user routines and flag to suppress type injection from custom m...