Neko 1.99.11
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
scalar_scheme.f90
Go to the documentation of this file.
1! Copyright (c) 2022-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!
33!> Contains the scalar_scheme_t type.
34
36 use gather_scatter, only : gs_t
37 use checkpoint, only : chkp_t
39 use num_types, only : rp
40 use field, only : field_t
41 use field_list, only : field_list_t
42 use space, only : space_t
43 use dofmap, only : dofmap_t
45 use coefs, only : coef_t
46 use bc_list, only : bc_list_t
47 use bc, only : bc_t
48 use precon, only : pc_t, precon_factory
49 use mesh, only : mesh_t
52 use registry, only : neko_registry
55 use json_module, only : json_file
66 use time_state, only : time_state_t
68 use scalar_ic, only : set_scalar_ic
70 implicit none
71
72 !> Base type for a scalar advection-diffusion solver.
73 type, abstract :: scalar_scheme_t
74 !> A name that can be used to distinguish this solver in e.g. user routines
75 character(len=:), allocatable :: name
76 !> x-component of Velocity
77 type(field_t), pointer :: u
78 !> y-component of Velocity
79 type(field_t), pointer :: v
80 !> z-component of Velocity
81 type(field_t), pointer :: w
82 !> The scalar.
83 type(field_t), pointer :: s
84 !> Lag arrays, i.e. solutions at previous timesteps.
85 type(field_series_t) :: slag
86 !> Function space \f$ X_h \f$.
87 type(space_t), pointer :: xh
88 !> Dofmap associated with \f$ X_h \f$.
89 type(dofmap_t), pointer :: dm_xh
90 !> Gather-scatter associated with \f$ X_h \f$.
91 type(gs_t), pointer :: gs_xh
92 !> Coefficients associated with \f$ X_h \f$.
93 type(coef_t), pointer :: c_xh
94 !> Right-hand side.
95 type(field_t), pointer :: f_xh => null()
96 !> The source term for equation.
98 !> Krylov solver.
99 class(ksp_t), allocatable :: ksp
100 !> Max iterations in the Krylov solver.
101 integer :: ksp_maxiter
102 !> Projection space size.
103 integer :: projection_dim
104 !< Steps to activate projection for ksp
105 integer :: projection_activ_step
106 !> Preconditioner.
107 class(pc_t), allocatable :: pc
108 !> List of boundary conditions, including the user one.
109 type(bc_list_t) :: bcs
110 !> Mesh.
111 type(mesh_t), pointer :: msh => null()
112 !> Checkpoint for restarts.
113 type(chkp_t), pointer :: chkp => null()
114 !> The turbulent kinematic viscosity field name
115 character(len=:), allocatable :: nut_field_name
116 !> The turbulent diffusivity field name
117 character(len=:), allocatable :: alphat_field_name
118 !> Density.
119 type(field_t), pointer :: rho => null()
120 !> Thermal diffusivity.
121 type(field_t), pointer :: lambda => null()
122 !> Specific heat capacity.
123 type(field_t), pointer :: cp => null()
124 !> Total diffusivity.
125 type(field_t), pointer :: lambda_tot => null()
126 !> Turbulent Prandtl number.
127 real(kind=rp) :: pr_turb
128 !> Field list with cp and lambda
129 type(field_list_t) :: material_properties
130 procedure(user_material_properties_intf), nopass, pointer :: &
131 user_material_properties => null()
132 !> Freeze the scheme, i.e. do nothing in step()
133 logical :: freeze = .false.
134 !> Whether spectral vanishing viscosity is enabled.
135 logical :: svv_enabled = .false.
136 !> Spectral vanishing viscosity data.
137 type(svv_t), allocatable :: svv
138 contains
139 !> Constructor for the base type.
140 procedure, pass(this) :: scheme_init => scalar_scheme_init
141 !> Destructor for the base type.
142 procedure, pass(this) :: scheme_free => scalar_scheme_free
143 !> Validate successful initialization.
144 procedure, pass(this) :: validate => scalar_scheme_validate
145 !> Set the initial condition.
146 procedure, pass(this) :: set_initial_condition => &
148 !> Register the scheme fields for checkpointing.
149 procedure, pass(this) :: register_checkpoint => &
151 !> Set lambda and cp
152 procedure, pass(this) :: set_material_properties => &
154 !> Update variable material properties
155 procedure, pass(this) :: update_material_properties => &
157 !> Constructor.
158 procedure(scalar_scheme_init_intrf), pass(this), deferred :: init
159 !> Destructor.
160 procedure(scalar_scheme_free_intrf), pass(this), deferred :: free
161 !> Solve for the current timestep.
162 procedure(scalar_scheme_step_intrf), pass(this), deferred :: step
163 !> Restart from a checkpoint.
164 procedure(scalar_scheme_restart_intrf), pass(this), deferred :: restart
165 end type scalar_scheme_t
166
167 !> Abstract interface to initialize a scalar formulation
168 abstract interface
169 subroutine scalar_scheme_init_intrf(this, msh, coef, gs, params, &
170 numerics_params, user, chkp, ulag, vlag, wlag, time_scheme, rho)
171 import scalar_scheme_t
172 import json_file
173 import coef_t
174 import gs_t
175 import mesh_t
176 import user_t
177 import field_series_t, field_t
179 import rp
180 import chkp_t
181 class(scalar_scheme_t), target, intent(inout) :: this
182 type(mesh_t), target, intent(in) :: msh
183 type(coef_t), target, intent(in) :: coef
184 type(gs_t), target, intent(inout) :: gs
185 type(json_file), target, intent(inout) :: params
186 type(json_file), target, intent(inout) :: numerics_params
187 type(user_t), target, intent(in) :: user
188 type(chkp_t), target, intent(inout) :: chkp
189 type(field_series_t), target, intent(in) :: ulag, vlag, wlag
190 type(time_scheme_controller_t), target, intent(in) :: time_scheme
191 type(field_t), target, intent(in) :: rho
192 end subroutine scalar_scheme_init_intrf
193 end interface
194
195 !> Abstract interface to restart a scalar formulation
196 abstract interface
197 subroutine scalar_scheme_restart_intrf(this, chkp)
198 import scalar_scheme_t
199 import chkp_t
200 import rp
201 class(scalar_scheme_t), target, intent(inout) :: this
202 type(chkp_t), intent(inout) :: chkp
203 end subroutine scalar_scheme_restart_intrf
204 end interface
205
206 !> Abstract interface to dealocate a scalar formulation
207 abstract interface
209 import scalar_scheme_t
210 class(scalar_scheme_t), intent(inout) :: this
211 end subroutine scalar_scheme_free_intrf
212 end interface
213
214 !> Abstract interface to compute a time-step
215 abstract interface
216 subroutine scalar_scheme_step_intrf(this, time, ext_bdf, dt_controller, &
217 ksp_results)
218 import scalar_scheme_t
219 import time_state_t
222 import ksp_monitor_t
223 class(scalar_scheme_t), intent(inout) :: this
224 type(time_state_t), intent(in) :: time
225 type(time_scheme_controller_t), intent(in) :: ext_bdf
226 type(time_step_controller_t), intent(in) :: dt_controller
227 type(ksp_monitor_t), intent(inout) :: ksp_results
228 end subroutine scalar_scheme_step_intrf
229 end interface
230
231 ! ========================================================================== !
232 ! Helper functions and types for scalar_scheme_t
233 ! ========================================================================== !
234
235 !> A helper type that is needed to have an array of polymorphic objects
237 class(scalar_scheme_t), allocatable :: scalar
238 contains
239 !> Constructor. Just allocates the object.
240 procedure, pass(this) :: init => scalar_scheme_wrapper_init
241 !> Destructor. Just deallocates the object.
242 procedure, pass(this) :: free => scalar_scheme_wrapper_free
243 !> Move operator for the wrapper, needed for storing schemes
244 !! in lists and arrays.
245 procedure, pass(this) :: move_from => &
247 !> Return allocation status.
248 procedure, pass(this) :: is_allocated => &
251
252
253 interface
254 !> Scalar scheme factory.
255 !! Both constructs and initializes the object.
256 !! @param object The object to be created and initialized.
257 !! @param msh The mesh.
258 !! @param coef The coefficients.
259 !! @param gs The gather-scatter.
260 !! @param params The parameter dictionary in json.
261 !! @param numerics_params The numerical parameter dictionary in json.
262 !! @param user Type with user-defined procedures.
263 !! @param chkp Checkpoint for restarts.
264 !! @param ulag, vlag, wlag The lagged velocity fields.
265 !! @param time_scheme The time scheme controller.
266 !! @param rho The density field.
267 module subroutine scalar_scheme_factory(object, msh, coef, gs, params, &
268 numerics_params, user, chkp, ulag, vlag, wlag, time_scheme, rho)
269 class(scalar_scheme_t), allocatable, intent(inout) :: object
270 type(mesh_t), target, intent(in) :: msh
271 type(coef_t), target, intent(in) :: coef
272 type(gs_t), target, intent(inout) :: gs
273 type(json_file), target, intent(inout) :: params
274 type(json_file), target, intent(inout) :: numerics_params
275 type(user_t), target, intent(in) :: user
276 type(chkp_t), target, intent(inout) :: chkp
277 type(field_series_t), target, intent(in) :: ulag, vlag, wlag
278 type(time_scheme_controller_t), target, intent(in) :: time_scheme
279 type(field_t), target, intent(in) :: rho
280 end subroutine scalar_scheme_factory
281 end interface
282
283 interface
284 !> Scalar scheme allocator.
285 !! @param object The object to be allocated.
286 !! @param type_name The name of the scalar scheme type.
287 module subroutine scalar_scheme_allocator(object, type_name)
288 class(scalar_scheme_t), allocatable, intent(inout) :: object
289 character(len=*), intent(in):: type_name
290 end subroutine scalar_scheme_allocator
291 end interface
292
293 !
294 ! Machinery for injecting user-defined types
295 !
296
297 !> Interface for an object allocator.
298 !! Implemented in the user modules, should allocate the `obj` to the custom
299 !! user type.
300 abstract interface
301 subroutine scalar_scheme_allocate(obj)
302 import scalar_scheme_t
303 class(scalar_scheme_t), allocatable, intent(inout) :: obj
304 end subroutine scalar_scheme_allocate
305 end interface
306
307 interface
308 !> Called in user modules to add an allocator for custom types.
309 module subroutine register_scalar_scheme(type_name, allocator)
310 character(len=*), intent(in) :: type_name
311 procedure(scalar_scheme_allocate), pointer, intent(in) :: allocator
312 end subroutine register_scalar_scheme
313 end interface
314
315 ! A name-allocator pair for user-defined types. A helper type to define a
316 ! registry of custom allocators.
317 type scalar_scheme_allocator_entry
318 character(len=NEKO_TYPENAME_LEN) :: type_name
319 procedure(scalar_scheme_allocate), pointer, nopass :: allocator
320 end type scalar_scheme_allocator_entry
321
322 !> Registry of allocators for user-defined types
323 type(scalar_scheme_allocator_entry), allocatable, private :: &
324 scalar_scheme_registry(:)
325
326 !> The size of the `scalar_scheme_registry`
327 integer, private :: scalar_scheme_registry_size = 0
328
329contains
330
331 !> Initialize all related components of the current scheme
332 !! @param msh The mesh.
333 !! @param c_Xh The coefficients.
334 !! @param gs_Xh The gather-scatter.
335 !! @param params The parameter dictionary in json.
336 !! @param scheme The name of the scalar scheme.
337 !! @param user Type with user-defined procedures.
338 !! @param rho The density of the fluid.
339 subroutine scalar_scheme_init(this, msh, c_Xh, gs_Xh, params, scheme, user, &
340 rho)
341 class(scalar_scheme_t), target, intent(inout) :: this
342 type(mesh_t), target, intent(in) :: msh
343 type(coef_t), target, intent(in) :: c_Xh
344 type(gs_t), target, intent(inout) :: gs_Xh
345 type(json_file), target, intent(inout) :: params
346 character(len=*), intent(in) :: scheme
347 type(user_t), target, intent(in) :: user
348 type(field_t), target, intent(in) :: rho
349 ! IO buffer for log output
350 character(len=LOG_SIZE) :: log_buf
351 ! Variables for retrieving json parameters
352 real(kind=rp) :: real_val, solver_abstol
353 integer :: ierr
354 character(len=:), allocatable :: solver_type, solver_precon
355 type(json_file) :: precon_params
356 type(json_file) :: json_subdict, solver_params
357 logical :: nut_dependency
358
359 this%u => neko_registry%get_field('u')
360 this%v => neko_registry%get_field('v')
361 this%w => neko_registry%get_field('w')
362 this%rho => rho
363
364 ! Assign a name
365 ! Note that the keyword is added by `scalars_t`, so there is always a
366 ! default.
367 call json_get(params, 'name', this%name)
368
369 ! Set the freeze flag
370 call json_get_or_default(params, 'freeze', this%freeze, .false.)
371
372 call neko_log%section('Scalar')
373 call json_get(params, 'solver.type', solver_type)
374 call json_get(params, 'solver.preconditioner.type', &
375 solver_precon)
376 call json_get(params, 'solver.preconditioner', precon_params)
377 call json_get_or_lookup(params, 'solver.absolute_tolerance', &
378 solver_abstol)
379
380 call json_get_or_lookup_or_default(params, &
381 'solver.projection_space_size', &
382 this%projection_dim, 0)
383 call json_get_or_lookup_or_default(params, &
384 'solver.projection_hold_steps', &
385 this%projection_activ_step, 5)
386
387
388 write(log_buf, '(A, A)') 'Type : ', trim(scheme)
389 call neko_log%message(log_buf)
390 write(log_buf, '(A, A)') 'Name : ', trim(this%name)
391 call neko_log%message(log_buf)
392 call neko_log%message('Ksp scalar : ('// trim(solver_type) // &
393 ', ' // trim(solver_precon) // ')')
394 write(log_buf, '(A,ES13.6)') ' `-abs tol :', solver_abstol
395 call neko_log%message(log_buf)
396
397 this%Xh => this%u%Xh
398 this%dm_Xh => this%u%dof
399 this%msh => msh
400
401 call neko_registry%add_field(this%dm_Xh, this%name, &
402 ignore_existing = .true.)
403
404 this%s => neko_registry%get_field(this%name)
405
406 call this%slag%init(this%s, 2)
407
408 this%gs_Xh => gs_xh
409 this%c_Xh => c_xh
410
411 !
412 ! Material properties
413 !
414 call this%set_material_properties(params, user)
415
416 !
417 ! Spectral vanishing viscosity
418 !
419 if (params%valid_path('svv')) then
420 call json_get_or_default(params, 'svv.enabled', this%svv_enabled, &
421 .false.)
422 if (this%svv_enabled) then
423 allocate(this%svv)
424 call this%svv%init(params, this%c_Xh, this%rho)
425 end if
426 end if
427
428
429 !
430 ! Turbulence modelling
431 !
432 this%alphat_field_name = ""
433 this%nut_field_name = ""
434 if (params%valid_path('alphat')) then
435 call json_get(params, 'alphat', json_subdict)
436 call json_get(json_subdict, 'nut_dependency', nut_dependency)
437 if (nut_dependency) then
438 call json_get_or_lookup(json_subdict, 'Pr_t', this%pr_turb)
439 call json_get(json_subdict, 'nut_field', this%nut_field_name)
440 else
441 call json_get(json_subdict, 'alphat_field', this%alphat_field_name)
442 end if
443 end if
444
445 !
446 ! Setup right-hand side field.
447 !
448 allocate(this%f_Xh)
449 call this%f_Xh%init(this%dm_Xh, fld_name = "scalar_rhs")
450
451 ! Initialize the source term
452 call this%source_term%init(this%f_Xh, this%c_Xh, user, this%name)
453 call this%source_term%add(params, 'source_terms')
454
455 call json_get(params, 'solver', solver_params)
456 call scalar_scheme_solver_factory(this%ksp, this%dm_Xh%size(), &
457 solver_params)
458 call scalar_scheme_precon_factory(this%pc, this%ksp, &
459 this%c_Xh, this%bcs, &
460 solver_precon, precon_params)
461
462 call neko_log%end_section()
463
464 end subroutine scalar_scheme_init
465
466 !> Set the initial condition.
467 !! @param params The parameters of this scalar, i.e. `case.scalar` or an
468 !! element of `case.scalars`.
469 !! @param user Type with user-defined procedures.
470 !! @param scalar_index Index of the scalar in a field file.
471 subroutine scalar_scheme_set_initial_condition(this, params, user, &
472 scalar_index)
473 class(scalar_scheme_t), intent(inout) :: this
474 type(json_file), intent(inout) :: params
475 type(user_t), intent(in) :: user
476 integer, intent(in) :: scalar_index
477 character(len=:), allocatable :: ic_type
478 type(json_file) :: ic_params
479
480 call json_get(params, 'initial_condition.type', ic_type)
481 call json_get(params, 'initial_condition', ic_params)
482
483 if (trim(ic_type) .ne. 'user') then
484 call set_scalar_ic(this%s, this%c_Xh, this%gs_Xh, ic_type, &
485 ic_params, scalar_index)
486 else
487 call set_scalar_ic(this%name, this%s, this%c_Xh, this%gs_Xh, &
488 user%initial_conditions)
489 end if
490
491 call ic_params%destroy()
492 deallocate(ic_type)
493
494 end subroutine scalar_scheme_set_initial_condition
495
496 !> Register this scalar scheme with the checkpoint.
497 !! @param chkp Checkpoint object to register with.
498 subroutine scalar_scheme_register_checkpoint(this, chkp)
499 class(scalar_scheme_t), target, intent(inout) :: this
500 type(chkp_t), intent(inout) :: chkp
501 type(checkpoint_payload_t), pointer :: payload
502
503 payload => chkp%add_payload("scalars/" // trim(this%name))
504 call payload%add_field(this%s)
505 call payload%add_series(this%slag)
506
507 end subroutine scalar_scheme_register_checkpoint
508
509
510 !> Deallocate a scalar formulation
511 subroutine scalar_scheme_free(this)
512 class(scalar_scheme_t), intent(inout) :: this
513 class(bc_t), pointer :: bc
514 integer :: i
515
516 bc => null()
517
518 if (allocated(this%svv)) then
519 call this%svv%free()
520 deallocate(this%svv)
521 end if
522 this%svv_enabled = .false.
523
524 nullify(this%Xh)
525 nullify(this%dm_Xh)
526 nullify(this%gs_Xh)
527 nullify(this%c_Xh)
528
529 if (allocated(this%ksp)) then
530 call this%ksp%free()
531 deallocate(this%ksp)
532 end if
533
534 if (allocated(this%pc)) then
535 call this%pc%free()
536 deallocate(this%pc)
537 end if
538
539 if (allocated(this%name)) then
540 deallocate(this%name)
541 end if
542
543 call this%source_term%free()
544
545 if (associated(this%f_Xh)) then
546 call this%f_Xh%free()
547 deallocate(this%f_Xh)
548 end if
549
550 do i = 1, this%bcs%size()
551 bc => this%bcs%get(i)
552 if (associated(bc)) then
553 call bc%free()
554 deallocate(bc)
555 end if
556 end do
557
558 call this%bcs%free()
559 call this%slag%free()
560 call this%material_properties%free()
561
562 if (allocated(this%nut_field_name)) then
563 deallocate(this%nut_field_name)
564 end if
565
566 if (allocated(this%alphat_field_name)) then
567 deallocate(this%alphat_field_name)
568 end if
569
570 nullify(this%cp)
571 nullify(this%lambda)
572 nullify(this%lambda_tot)
573 nullify(bc)
574
575 end subroutine scalar_scheme_free
576
577 !> Validate that all fields, solvers etc necessary for
578 !! performing time-stepping are defined
579 subroutine scalar_scheme_validate(this)
580 class(scalar_scheme_t), target, intent(inout) :: this
581
582 if ( (.not. allocated(this%u%x)) .or. &
583 (.not. allocated(this%v%x)) .or. &
584 (.not. allocated(this%w%x)) .or. &
585 (.not. allocated(this%s%x))) then
586 call neko_error('Fields are not allocated')
587 end if
588
589 if (.not. allocated(this%ksp)) then
590 call neko_error('No Krylov solver for velocity defined')
591 end if
592
593 if (.not. associated(this%Xh)) then
594 call neko_error('No function space defined')
595 end if
596
597 if (.not. associated(this%dm_Xh)) then
598 call neko_error('No dofmap defined')
599 end if
600
601 if (.not. associated(this%c_Xh)) then
602 call neko_error('No coefficients defined')
603 end if
604
605 if (.not. associated(this%f_Xh)) then
606 call neko_error('No rhs allocated')
607 end if
608
609 if (.not. associated(this%rho)) then
610 call neko_error('No density field defined')
611 end if
612
613 end subroutine scalar_scheme_validate
614
615 !> Initialize a linear solver from its JSON solver block
616 !! @note Currently only supporting Krylov solvers
617 subroutine scalar_scheme_solver_factory(ksp, n, params)
618 class(ksp_t), allocatable, target, intent(inout) :: ksp
619 integer, intent(in), value :: n
620 type(json_file), intent(inout) :: params
621
622 call krylov_solver_factory(ksp, n, params)
623
624 end subroutine scalar_scheme_solver_factory
625
626 !> Initialize a Krylov preconditioner
627 subroutine scalar_scheme_precon_factory(pc, ksp, coef, bclst, &
628 pctype, json)
629 class(pc_t), allocatable, target, intent(inout) :: pc
630 class(ksp_t), target, intent(inout) :: ksp
631 type(coef_t), target, intent(in) :: coef
632 type(bc_list_t), target, intent(inout) :: bclst
633 character(len=*) :: pctype
634 type(json_file), intent(inout) :: json
635
636 call precon_factory(pc, pctype, coef, bclst, json)
637
638 call ksp%set_pc(pc)
639
640 end subroutine scalar_scheme_precon_factory
641
642 !> Call user material properties routine and update the values of `lambda`
643 !! if necessary.
644 !! @param t Time value.
645 !! @param tstep Current time step.
646 subroutine scalar_scheme_update_material_properties(this, time)
647 class(scalar_scheme_t), intent(inout) :: this
648 type(time_state_t), intent(in) :: time
649 type(field_t), pointer :: nut, alphat
650 integer :: index
651 ! Factor to transform nu_t to lambda_t
652 type(field_t), pointer :: lambda_factor
653
654 call this%user_material_properties(this%name, this%material_properties, &
655 time)
656
657 ! factor = rho * cp / pr_turb
658 if (len_trim(this%nut_field_name) .gt. 0 &
659 .and. len_trim(this%alphat_field_name) .eq. 0 ) then
660 nut => neko_registry%get_field(this%nut_field_name)
661
662 ! lambda_tot = lambda + rho * cp * nut / pr_turb
663 call neko_scratch_registry%request_field(lambda_factor, index, .false.)
664 call field_cmult2(lambda_factor, nut, 1.0_rp / this%pr_turb)
665 call field_col2(lambda_factor, this%cp)
666 call field_col2(lambda_factor, this%rho)
667 call field_add3(this%lambda_tot, this%lambda, lambda_factor)
668 call neko_scratch_registry%relinquish_field(index)
669
670 else if (len_trim(this%alphat_field_name) .gt. 0 &
671 .and. len_trim(this%nut_field_name) .eq. 0 ) then
672 alphat => neko_registry%get_field(this%alphat_field_name)
673
674 ! lambda_tot = lambda + rho * cp * alphat
675 call neko_scratch_registry%request_field(lambda_factor, index, .false.)
676 call field_col3(lambda_factor, this%cp, alphat)
677 call field_col2(lambda_factor, this%rho)
678 call field_add3(this%lambda_tot, this%lambda, lambda_factor)
679 call neko_scratch_registry%relinquish_field(index)
680
681 else if (len_trim(this%alphat_field_name) .gt. 0 &
682 .and. len_trim(this%nut_field_name) .gt. 0 ) then
683 call neko_error("Conflicting definition of eddy diffusivity " // &
684 "for the scalar equation")
685 end if
686
687 ! Since cp is a fields and we use the %x(1,1,1,1) of the
688 ! host array data to pass constant material properties
689 ! to some routines, we need to make sure that the host
690 ! values are also filled
691 if (neko_bcknd_device .eq. 1) then
692 call device_memcpy(this%cp%x, this%cp%x_d, this%cp%size(), &
693 device_to_host, sync = .false.)
694 end if
695
696 end subroutine scalar_scheme_update_material_properties
697
698 !> Set lamdba and cp.
699 !! @param params The case file configuration dictionary.
700 !! @param user The user interface.
701 subroutine scalar_scheme_set_material_properties(this, params, user)
702 class(scalar_scheme_t), intent(inout) :: this
703 type(json_file), intent(inout) :: params
704 type(user_t), target, intent(in) :: user
705 character(len=LOG_SIZE) :: log_buf
706 ! A local pointer that is needed to make Intel happy
707 procedure(user_material_properties_intf), pointer :: dummy_mp_ptr
708 real(kind=rp) :: const_cp, const_lambda
709 ! Dummy time state set to 0
710 type(time_state_t) :: time
711
712 dummy_mp_ptr => dummy_user_material_properties
713
714 ! Fill lambda field with the physical value
715
716 call neko_registry%add_field(this%dm_Xh, this%name // "_lambda")
717 call neko_registry%add_field(this%dm_Xh, this%name // "_lambda_tot")
718 call neko_registry%add_field(this%dm_Xh, this%name // "_cp")
719 this%lambda => neko_registry%get_field(this%name // "_lambda")
720 this%lambda_tot => neko_registry%get_field(this%name // "_lambda_tot")
721 this%cp => neko_registry%get_field(this%name // "_cp")
722
723 call this%material_properties%init(2)
724 call this%material_properties%assign(1, this%cp)
725 call this%material_properties%assign(2, this%lambda)
726
727 if (.not. associated(user%material_properties, dummy_mp_ptr)) then
728
729 write(log_buf, '(A)') "Material properties must be set in the user " // &
730 "file!"
731 call neko_log%message(log_buf)
732 this%user_material_properties => user%material_properties
733
734 call user%material_properties(this%name, this%material_properties, time)
735 else
736 this%user_material_properties => dummy_user_material_properties
737 if (params%valid_path('Pe') .and. &
738 (params%valid_path('lambda') .or. &
739 params%valid_path('cp'))) then
740 call neko_error("To set the material properties for the scalar, " // &
741 "either provide Pe OR lambda and cp in the case file.")
742 ! Non-dimensional case
743 else if (params%valid_path('Pe')) then
744 write(log_buf, '(A)') 'Non-dimensional scalar material properties' //&
745 ' input.'
746 call neko_log%message(log_buf, lvl = neko_log_verbose)
747 write(log_buf, '(A)') 'Specific heat capacity will be set to 1, '
748 call neko_log%message(log_buf, lvl = neko_log_verbose)
749 write(log_buf, '(A)') 'conductivity to 1/Pe. Assumes density is 1.'
750 call neko_log%message(log_buf, lvl = neko_log_verbose)
751
752 ! Read Pe into lambda for further manipulation.
753 call json_get_or_lookup(params, 'Pe', const_lambda)
754 write(log_buf, '(A,ES13.6)') 'Pe :', const_lambda
755 call neko_log%message(log_buf)
756
757 ! Set cp and rho to 1 since the setup is non-dimensional.
758 const_cp = 1.0_rp
759 ! Invert the Pe to get conductivity
760 const_lambda = 1.0_rp/const_lambda
761 ! Dimensional case
762 else
763 call json_get_or_lookup(params, 'lambda', const_lambda)
764 call json_get_or_lookup(params, 'cp', const_cp)
765 end if
766 end if
767 ! We need to fill the fields based on the parsed const values
768 ! if the user routine is not used.
769 if (associated(user%material_properties, dummy_mp_ptr)) then
770 ! Fill mu and rho field with the physical value
771 call field_cfill(this%lambda, const_lambda)
772 call field_cfill(this%cp, const_cp)
773
774 write(log_buf, '(A,ES13.6)') 'lambda :', const_lambda
775 call neko_log%message(log_buf)
776 write(log_buf, '(A,ES13.6)') 'cp :', const_cp
777 call neko_log%message(log_buf)
778 end if
779
780 ! Copy over material property to the total one
781 call field_copy(this%lambda_tot, this%lambda)
782
783 ! Since cp is a field and we use the %x(1,1,1,1) of the
784 ! host array data to pass constant material properties
785 ! to some routines, we need to make sure that the host
786 ! values are also filled
787 if (neko_bcknd_device .eq. 1) then
788 call device_memcpy(this%cp%x, this%cp%x_d, this%cp%size(), &
789 device_to_host, sync = .false.)
790 end if
791 end subroutine scalar_scheme_set_material_properties
792
793 ! ========================================================================== !
794 ! Scalar scheme wrapper type methods
795
796 !> Constructor. Initializes the object.
797 subroutine scalar_scheme_wrapper_init(this, msh, coef, gs, params, &
798 numerics_params, user, chkp, ulag, vlag, wlag, time_scheme, rho)
799 class(scalar_scheme_wrapper_t), intent(inout) :: this
800 type(mesh_t), target, intent(in) :: msh
801 type(coef_t), target, intent(in) :: coef
802 type(gs_t), target, intent(inout) :: gs
803 type(json_file), target, intent(inout) :: params
804 type(json_file), target, intent(inout) :: numerics_params
805 type(user_t), target, intent(in) :: user
806 type(chkp_t), target, intent(inout) :: chkp
807 type(field_series_t), target, intent(in) :: ulag, vlag, wlag
808 type(time_scheme_controller_t), target, intent(in) :: time_scheme
809 type(field_t), target, intent(in) :: rho
810
811 call this%free()
812 call scalar_scheme_factory(this%scalar, msh, coef, gs, params, &
813 numerics_params, user, chkp, ulag, vlag, wlag, time_scheme, rho)
814
815 end subroutine scalar_scheme_wrapper_init
816
817 !> Destructor. Just deallocates the pointer.
818 subroutine scalar_scheme_wrapper_free(this)
819 class(scalar_scheme_wrapper_t), intent(inout) :: this
820
821 if (allocated(this%scalar)) then
822 call this%scalar%free()
823 deallocate(this%scalar)
824 end if
825
826 end subroutine scalar_scheme_wrapper_free
827
828 !> Move assignment operator for the wrapper, needed for storing schemes
829 !! in lists and arrays.
830 !! @param this The wrapper to move to.
831 !! @param other The other wrapper to move from. Will be deallocated.
832 subroutine scalar_scheme_wrapper_move_from(this, other)
833 class(scalar_scheme_wrapper_t), intent(inout) :: this
834 class(scalar_scheme_wrapper_t), intent(inout) :: other
835
836 ! Move the pointer
837 call move_alloc(other%scalar, this%scalar)
838
839 end subroutine scalar_scheme_wrapper_move_from
840
841 !> Return allocation status.
842 !! @param this The wrapper to check.
843 function scalar_scheme_wrapper_is_allocated(this) result(is_alloc)
844 class(scalar_scheme_wrapper_t), intent(in) :: this
845 logical :: is_alloc
846 is_alloc = allocated(this%scalar)
847 end function scalar_scheme_wrapper_is_allocated
848
849end module scalar_scheme
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.
Factory for Krylov solvers. Both creates and initializes the object, either from its parameters or fr...
Definition krylov.f90:221
Abstract interface to dealocate a scalar formulation.
Abstract interface to initialize a scalar formulation.
Abstract interface to restart a scalar formulation.
Abstract interface to compute a time-step.
Abstract interface for setting material properties.
Defines a list of bc_t.
Definition bc_list.f90:34
Defines a boundary condition.
Definition bc.f90:34
Format-independent checkpoint payloads.
Defines format-independent checkpoint registration and restart state.
Coefficients.
Definition coef.f90:34
Device abstraction, common interface for various accelerators.
Definition device.F90:34
integer, parameter, public device_to_host
Definition device.F90:48
Defines a mapping of the degrees of freedom.
Definition dofmap.f90:35
subroutine, public field_col2(a, b, n)
Vector multiplication .
subroutine, public field_cmult2(a, b, c, n)
Multiplication by constant c .
subroutine, public field_cfill(a, c, n)
Set all elements to a constant c .
subroutine, public field_col3(a, b, c, n)
Vector multiplication with 3 vectors .
subroutine, public field_copy(a, b, n)
Copy a vector .
subroutine, public field_add3(a, b, c, n)
Vector addition .
Contains the field_serties_t type.
Defines a field.
Definition field.f90:34
Gather-scatter.
Utilities for retrieving parameters from the case files.
Implements the base abstract type for Krylov solvers plus helper types.
Definition krylov.f90:34
Logging routines.
Definition log.f90:34
integer, parameter, public neko_log_verbose
Verbose.
Definition log.f90:54
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
Build configurations.
integer, parameter neko_bcknd_device
integer, parameter, public rp
Global precision used in computations.
Definition num_types.f90:14
Krylov preconditioner.
Definition precon.f90:34
Defines a registry for storing solution fields.
Definition registry.f90:34
type(registry_t), target, public neko_registry
Global field registry.
Definition registry.f90:158
Scalar initial condition.
Definition scalar_ic.f90:34
Contains the scalar_scheme_t type.
subroutine scalar_scheme_init(this, msh, c_xh, gs_xh, params, scheme, user, rho)
Initialize all related components of the current scheme.
logical function scalar_scheme_wrapper_is_allocated(this)
Return allocation status.
subroutine scalar_scheme_wrapper_free(this)
Destructor. Just deallocates the pointer.
subroutine scalar_scheme_free(this)
Deallocate a scalar formulation.
subroutine scalar_scheme_validate(this)
Validate that all fields, solvers etc necessary for performing time-stepping are defined.
subroutine scalar_scheme_update_material_properties(this, time)
Call user material properties routine and update the values of lambda if necessary.
subroutine scalar_scheme_register_checkpoint(this, chkp)
Register this scalar scheme with the checkpoint.
subroutine scalar_scheme_set_material_properties(this, params, user)
Set lamdba and cp.
subroutine scalar_scheme_wrapper_init(this, msh, coef, gs, params, numerics_params, user, chkp, ulag, vlag, wlag, time_scheme, rho)
Constructor. Initializes the object.
subroutine scalar_scheme_wrapper_move_from(this, other)
Move assignment operator for the wrapper, needed for storing schemes in lists and arrays.
subroutine scalar_scheme_set_initial_condition(this, params, user, scalar_index)
Set the initial condition.
Implements the scalar_source_term_t type.
Defines a registry for storing and requesting temporary objects This can be used when you have a func...
type(scratch_registry_t), target, public neko_scratch_registry
Global scratch registry.
Implements the source_term_t type and a wrapper source_term_wrapper_t.
Defines a function space.
Definition space.f90:34
Data and filter construction for spectral vanishing viscosity.
Compound scheme for the advection and diffusion operators in a transport equation.
Base class for time integration schemes.
Module with things related to the simulation time.
Implements type time_step_controller.
Interfaces for user interaction with NEKO.
Definition user_intf.f90:34
subroutine, public dummy_user_material_properties(scheme_name, properties, time)
Utilities.
Definition utils.f90:35
integer, parameter, public neko_typename_len
Definition utils.f90:44
Base type for a boundary condition.
Definition bc.f90:73
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.
A named collection of live fields to checkpoint together.
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
Stores a series (sequence) of fields, logically connected to a base field, and arranged according to ...
Gather-scatter kernel.
Type for storing initial and final residuals in a Krylov solver.
Definition krylov.f90:60
Base abstract type for a canonical Krylov method, solving .
Definition krylov.f90:77
Defines a canonical Krylov preconditioner.
Definition precon.f90:44
Base type for a scalar advection-diffusion solver.
A helper type that is needed to have an array of polymorphic objects.
Wrapper contaning and executing the scalar source terms.
The function space for the SEM solution fields.
Definition space.f90:64
Spectral vanishing viscosity configuration and coefficients.
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...