Neko 1.99.11
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
ale_manager.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!
33!> ALE Manager: Handles Mesh Motion
35 use num_types, only : rp, dp
36 use json_module, only : json_file
38 use field, only : field_t
39 use coefs, only : coef_t
40 use space, only : space_t
41 use ax_product, only : ax_t, ax_helm_allocator
43 use precon, only : pc_t, precon_factory
44 use bc_list, only : bc_list_t
45 use checkpoint, only : chkp_t
48 use gather_scatter, only : gs_t, gs_op_add
49 use dofmap, only : dofmap_t
51 use file, only : file_t
52 use logger, only : neko_log, log_size
53 use advection, only : advection_t
62 use utils, only : neko_error
64 use mpi_f08, only : mpi_wtime, mpi_barrier
65 use comm, only : neko_comm
66 use registry, only : neko_registry
69 use time_state, only : time_state_t
70 use fld_file, only : fld_file_t
75 use math, only : glmin, pi, copy
77 use field_math, only : field_rzero, field_add2, &
80
82 use operators, only : rotate_cyc
84 use, intrinsic :: iso_c_binding, only : c_associated
85 implicit none
86 private
87
88 public :: compute_stiffness_ale
90 public :: update_ale_mesh
91 public :: log_rot_angles
92 public :: log_pivot
93
94 type, public :: ale_manager_t
95 ! Default
96 logical :: active = .false.
97 logical :: has_moving_boundary = .false.
98
100 type(zero_dirichlet_t) :: bc_moving
101 type(zero_dirichlet_t) :: bc_fixed
102
103 type(ale_config_t) :: config
104
105 !> Mesh velocity fields (Registered in neko_registry)
106 type(field_t), pointer :: wm_x => null()
107 type(field_t), pointer :: wm_y => null()
108 type(field_t), pointer :: wm_z => null()
109
110 !> History buffers for mesh velocity components
111 type(field_series_t) :: wm_x_lag
112 type(field_series_t) :: wm_y_lag
113 type(field_series_t) :: wm_z_lag
114
115 !> Reference initial grid to calculate the rotation accurately
116 type(field_t) :: x_ref, y_ref, z_ref
117
118 !> Pivot states for each body
119 type(pivot_state_t), allocatable :: ale_pivot(:)
120 type(body_kinematics_t), allocatable :: body_kin(:)
121
122 !> Base shape fields for mesh movement (Laplace solution for each body)
123 !> base_shapes(i) is 1.0 on body i and 0.0 on all others.
124 type(field_t), allocatable :: base_shapes(:)
125
126 !> Sum of all base shapes. Should be \f$ \in [0, 1] \f$.
127 type(field_t) :: phi_total
128
129 real(kind=rp), pointer :: global_pivot_pos(:) => null()
130 real(kind=rp), pointer :: global_pivot_vel_lag(:, :) => null()
131
132 ! Basis Vectors for orientation
133 real(kind=rp), pointer :: global_basis_pos(:) => null()
134 ! Store history for the ghost trackers
135 real(kind=rp), pointer :: global_basis_vel_lag(:, :) => null()
136 ! Private handles to the ghost trackers (2 per body)
137 integer, allocatable :: ghost_handles(:,:)
138 ! Rotation matrices
139 real(kind=rp), allocatable :: body_rot_matrices(:,:,:)
140
141 type(point_tracker_t), allocatable :: trackers(:)
142 integer :: n_trackers = 0
143
144 procedure(user_ale_mesh_velocity_intf), nopass, pointer :: &
145 user_ale_mesh_vel => null()
146 procedure(user_ale_base_shapes_intf), nopass, pointer :: &
147 user_ale_base_shapes => null()
148 procedure(user_ale_rigid_kinematics_intf), nopass, pointer :: &
149 user_ale_rigid_kinematics => null()
150
151 contains
152 procedure, pass(this) :: init => ale_manager_init
153 procedure, pass(this) :: free => ale_manager_free
154 procedure, pass(this) :: mesh_preview
155 procedure, pass(this) :: solve_base_mesh_displacement
156 procedure, pass(this) :: advance_mesh
157 procedure, pass(this) :: update_mesh_velocity
158 procedure, pass(this) :: set_initial_mesh_velocity
159 procedure, pass(this) :: set_pivot_restart
160 procedure, pass(this) :: sync_chkp
161 procedure, pass(this) :: request_tracker
162 procedure, pass(this) :: get_tracker_pos
163 procedure, pass(this) :: compute_rotation_matrix
164 procedure, pass(this) :: prep_checkpoint => set_pivot_basis_for_checkpoint
165 procedure, pass(this) :: ghost_tracker_coord_step
166 procedure, pass(this) :: log_rot_angles
167 procedure, pass(this) :: log_pivot
168 procedure, pass(this) :: register_checkpoint_fields
169 end type ale_manager_t
170
171 type(ale_manager_t), public, pointer :: neko_ale => null()
172
173contains
174
175 !> Initialize ALE Manager
176 !> Sets up solver, registers fields, solves for base shape, etc.
177 !! @param coef The coefficients.
178 !! @param json The fluid parameters, i.e. `case.fluid`.
179 !! @param numerics_params The numerical parameters, i.e. `case.numerics`.
180 !! @param user Type with user-defined procedures.
181 !! @param chkp Checkpoint for restarts.
182 subroutine ale_manager_init(this, coef, json, numerics_params, user, chkp)
183 class(ale_manager_t), intent(inout), target :: this
184 type(coef_t), target, intent(inout) :: coef
185 type(json_file), intent(inout) :: json
186 type(json_file), intent(inout) :: numerics_params
187 type(user_t), intent(in) :: user
188 type(chkp_t), intent(inout) :: chkp
189 type(json_file) :: body_sub, bc_subdict
190 type(json_file) :: precon_params, solver_params
191 integer, allocatable :: zone_indices(:)
192 integer :: time_order
193 integer :: n_moving_zones
194 integer :: z, tmp_int
195 integer, allocatable :: moving_zone_ids(:)
196 integer :: i, j, k, n_bcs, n, n_bodies
197 real(kind=rp), allocatable :: tmp_vec(:)
198 real(kind=rp) :: tmp_val, abstol
199 character(len=128) :: log_buf
200 character(len=256) :: log_buf_l
201 character(len=:), allocatable :: bc_type
202 character(len=:), allocatable :: tmp_str
203 character(len=:), allocatable :: ksp_solver
204 character(len=:), allocatable :: precon_type
205 logical :: tmp_logical, oifs
206 logical :: moving_
207 logical :: found_zone
208 logical :: has_user_rigid_kin, has_user_mesh_vel
209 logical :: has_builtin_osc, has_builtin_rot, is_rot_active
210 logical :: import_base_shapes
211
212 if (json%valid_path('ale')) then
213 call json_get(json, 'ale.enabled', this%active)
214 end if
215 call json_get_or_default(numerics_params, 'oifs', oifs, .false.)
216
217 if (.not. this%active) then
218 neko_ale => null()
219 return
220 else if (this%active) then
221 ! force all elements as deformed when mesh changes.
222 call coef%msh%all_deformed()
223
224 if (neko_bcknd_device .eq. 1) then
225 if ((.not. (neko_bcknd_hip .eq. 1)) .and. &
226 (.not. (neko_bcknd_cuda .eq. 1))) then
227 call neko_error("ALE currently " // &
228 "supported only with HIP or CUDA backend.")
229 end if
230 end if
231 if (oifs) then
232 call neko_error("ALE not currently supported with OIFS.")
233 end if
234 neko_ale => this
235 end if
236
237 call neko_log%section("ALE Initialization")
238 call neko_log%message(" ")
239
240 if (neko_bcknd_hip .eq. 1) then
241 call neko_log%message("Initializing ALE " // &
242 "with device backend (HIP).")
243 else if (neko_bcknd_cuda .eq. 1) then
244 call neko_log%message("Initializing ALE " // &
245 "with device backend (CUDA).")
246 else
247 call neko_log%message("Initializing ALE " // &
248 "with CPU backend.")
249 end if
250
251 tmp_logical = .false.
252 n = coef%dof%size()
253
254 call this%x_ref%init(coef%dof, "x_ref")
255 call this%y_ref%init(coef%dof, "y_ref")
256 call this%z_ref%init(coef%dof, "z_ref")
257
258 call copy(this%x_ref%x, coef%dof%x%x, n)
259 call copy(this%y_ref%x, coef%dof%y%x, n)
260 call copy(this%z_ref%x, coef%dof%z%x, n)
261
262 ! Sync to device
263 if (neko_bcknd_device .eq. 1) then
264 call this%x_ref%copy_from(host_to_device, .false.)
265 call this%y_ref%copy_from(host_to_device, .false.)
266 call this%z_ref%copy_from(host_to_device, .true.)
267 end if
268
269 ! Set user function pointers.
270 this%user_ale_mesh_vel => user%ale_mesh_velocity
271 this%user_ale_base_shapes => user%ale_base_shapes
272 this%user_ale_rigid_kinematics => user%ale_rigid_kinematics
273
274 ! Check user association states
275 has_user_rigid_kin = .not. associated(this%user_ale_rigid_kinematics, &
277 has_user_mesh_vel = .not. associated(this%user_ale_mesh_vel, &
279
280 ! Enable B history (Blag, Blaglag)
281 call coef%enable_B_history()
282 call json_get(numerics_params, 'time_order', time_order)
283
284 ! Stuff for zone_id checks
285 n_moving_zones = 0
286 if (allocated(moving_zone_ids)) deallocate(moving_zone_ids)
287 allocate(moving_zone_ids(0))
288
289 ! Register mesh velocity fields
290 call neko_registry%add_field(coef%dof, 'wm_x')
291 call neko_registry%add_field(coef%dof, 'wm_y')
292 call neko_registry%add_field(coef%dof, 'wm_z')
293 this%wm_x => neko_registry%get_field('wm_x')
294 this%wm_y => neko_registry%get_field('wm_y')
295 this%wm_z => neko_registry%get_field('wm_z')
296
297 call get_ale_solver_params_json(this, json, ksp_solver, precon_type, &
298 precon_params, abstol, import_base_shapes, solver_params)
299
300 ! Mark BCs
301 call this%bc_moving%init_from_components(coef)
302 call this%bc_fixed%init_from_components(coef)
303
304 if (json%valid_path('boundary_conditions')) then
305 call json%info('boundary_conditions', n_children = n_bcs)
306
307 do i = 1, n_bcs
308 call json_extract_item(json, 'boundary_conditions', &
309 i, bc_subdict)
310
311 if (allocated(bc_type)) deallocate(bc_type)
312 call json_get(bc_subdict, 'type', bc_type)
313
314 if (allocated(zone_indices)) deallocate(zone_indices)
315 call json_get(bc_subdict, 'zone_indices', zone_indices)
316
317 moving_ = .false.
318 if (trim(bc_type) .eq. 'no_slip') then
319 call json_get_or_default(bc_subdict, 'moving', moving_, .false.)
320 end if
321
322 if (moving_) then
323 do j = 1, size(zone_indices)
324 ! we append unique moving zone ids for future checks
325 call append_unique_int(moving_zone_ids, n_moving_zones, &
326 zone_indices(j))
327 call this%bc_moving%mark_zone(coef%msh%labeled_zones(&
328 zone_indices(j)))
329 end do
330 this%has_moving_boundary = .true.
331 else
332 do j = 1, size(zone_indices)
333 call this%bc_fixed%mark_zone(coef%msh%labeled_zones(&
334 zone_indices(j)))
335 end do
336 end if
337 end do
338 end if
339
340 call this%bc_moving%finalize()
341 call this%bc_fixed%finalize()
342 call this%bc_list%init()
343 call this%bc_list%append(this%bc_moving)
344 call this%bc_list%append(this%bc_fixed)
345
346 ! Mesh Stiffness
347 if (json%valid_path('ale.solver.mesh_stiffness.type')) then
348 call json%get('ale.solver.mesh_stiffness.type', tmp_str)
349 this%config%stiffness_type = tmp_str
350 if (.not. (trim(tmp_str) .eq. 'built-in')) then
351 call neko_error("ALE: stiffness_type must be 'built-in'")
352 end if
353 end if
354
355 if ( associated(this%user_ale_base_shapes, &
356 dummy_user_ale_base_shapes) .and. (.not. import_base_shapes)) then
357 call neko_log%message('Solver Type : (' // &
358 trim(ksp_solver) // ', ' // trim(precon_type) // ')')
359 write(log_buf, '(A,ES13.6)') 'Abs tol :', abstol
360 call neko_log%message(log_buf)
361 call neko_log%message('Mesh Stiffness : ' // &
362 trim(this%config%stiffness_type))
363 end if
364 call neko_log%message(' ')
365
366 ! Bodies
367 if (json%valid_path('ale.bodies')) then
368 call json%info('ale.bodies', n_children = n_bodies)
369 this%config%nbodies = n_bodies
370 allocate(this%config%bodies(n_bodies))
371 allocate(this%ale_pivot(n_bodies))
372 allocate(this%body_kin(n_bodies))
373 allocate(this%base_shapes(n_bodies))
374 allocate(this%global_pivot_pos(3 * this%config%nbodies))
375 allocate(this%global_pivot_vel_lag(3 * this%config%nbodies, 3))
376 allocate(this%global_basis_pos(6 * this%config%nbodies))
377 allocate(this%ghost_handles(2, this%config%nbodies))
378 allocate(this%global_basis_vel_lag(6 * this%config%nbodies, 3))
379 allocate(this%body_rot_matrices(3, 3, this%config%nbodies))
380
381 this%global_pivot_pos = 0.0_rp
382 this%global_pivot_vel_lag = 0.0_rp
383 this%global_basis_pos = 0.0_rp
384 this%global_basis_vel_lag = 0.0_rp
385 this%body_rot_matrices = 0.0_rp
386
387 do i = 1, n_bodies
388 this%body_rot_matrices(1, 1, i) = 1.0_rp
389 this%body_rot_matrices(2, 2, i) = 1.0_rp
390 this%body_rot_matrices(3, 3, i) = 1.0_rp
391 end do
392
393 do i = 1, n_bodies
394 call json_extract_item(json, 'ale.bodies', i, body_sub)
395 this%config%bodies(i)%id = i
396
397 if (body_sub%valid_path('name')) then
398 call json_get(body_sub, 'name', tmp_str)
399 this%config%bodies(i)%name = tmp_str
400 else
401 write(this%config%bodies(i)%name, '(A,I0)') 'body_', i
402 end if
403
404 if (body_sub%valid_path('zone_indices')) then
405 call json_get(body_sub, 'zone_indices', zone_indices)
406 this%config%bodies(i)%zone_indices = zone_indices
407 else
408 call neko_error("ALE: body " // &
409 trim(this%config%bodies(i)%name) // &
410 " must have 'zone_indices'")
411 end if
412
413 ! Oscillation
414 this%config%bodies(i)%osc_amp = 0.0_rp
415 this%config%bodies(i)%osc_freq = 0.0_rp
416 if (body_sub%valid_path('oscillation')) then
417 call json_get(body_sub, 'oscillation.amplitude', tmp_vec, &
418 expected_size = 3)
419 this%config%bodies(i)%osc_amp = tmp_vec
420 call json_get(body_sub, 'oscillation.frequency', tmp_vec, &
421 expected_size = 3)
422 this%config%bodies(i)%osc_freq = tmp_vec
423 end if
424
425 ! Rotation
426 if (body_sub%valid_path('rotation')) then
427 ! Check if pivot exists.
428 if (.not. body_sub%valid_path('pivot')) then
429 call neko_error("ale.bodies.pivot is missing " // &
430 "from the case file.")
431 end if
432
433 call json_get(body_sub, 'rotation.type', tmp_str)
434 this%config%bodies(i)%rotation_type = tmp_str
435
436 select case (trim(tmp_str))
437 case ('harmonic')
438 call json_get(body_sub, 'rotation.amplitude_deg', tmp_vec, &
439 expected_size = 3)
440 this%config%bodies(i)%rot_amp_degree = tmp_vec
441
442 call json_get(body_sub, 'rotation.frequency', tmp_vec, &
443 expected_size = 3)
444 this%config%bodies(i)%rot_freq = tmp_vec
445
446
447 case ('ramp')
448 call json_get(body_sub, 'rotation.ramp_t0', tmp_vec, &
449 expected_size = 3)
450 this%config%bodies(i)%ramp_t0 = tmp_vec
451
452 call json_get(body_sub, 'rotation.ramp_omega0', tmp_vec, &
453 expected_size = 3)
454 this%config%bodies(i)%ramp_omega0 = tmp_vec
455
456
457 case ('smooth_step')
458 call json_get_or_default(body_sub, 'rotation.axis', &
459 tmp_int, 3)
460 if (tmp_int .ge. 1 .and. tmp_int .le. 3) then
461 this%config%bodies(i)%rotation_axis = tmp_int
462 else
463 call neko_error("ALE: rotation.axis must be (integer) " // &
464 "1 -> x, 2 -> y, or 3 -> z")
465 end if
466 call json_get(body_sub, 'rotation.step_control_times', &
467 tmp_vec, expected_size = 4)
468 this%config%bodies(i)%step_control_times = tmp_vec
469
470 call json_get(body_sub, 'rotation.target_angle_deg', tmp_val)
471 this%config%bodies(i)%target_rot_angle_deg = tmp_val
472
473 case default
474 call neko_error("ALE: rotation.type must be 'harmonic', " // &
475 "'ramp', or 'smooth_step'")
476 end select
477 end if
478
479 ! Rotation Center
480 if (body_sub%valid_path('pivot')) then
481 call json_get_or_default(body_sub, 'pivot.type', tmp_str, &
482 'relative')
483 this%config%bodies(i)%rotation_center_type = tmp_str
484 call json_get(body_sub, 'pivot.value', tmp_vec, expected_size = 3)
485 this%config%bodies(i)%rot_center = tmp_vec
486
487
488 tmp_str = this%config%bodies(i)%rotation_center_type
489 if (trim(tmp_str) /= 'relative' .and. &
490 trim(tmp_str) /= 'relative_sin') then
491 call neko_error("ALE: pivot.type must be " // &
492 "'relative', or 'relative_sin'.")
493 end if
494 end if
495
496 ! Stiff Geom
497 if (body_sub%valid_path('stiff_geom')) then
498 call json_get(body_sub, 'stiff_geom.type', tmp_str)
499 this%config%bodies(i)%stiff_geom%type = tmp_str
500 call json_get(body_sub, 'stiff_geom.gain', &
501 this%config%bodies(i)%stiff_geom%gain)
502 call json_get(body_sub, 'stiff_geom.decay_profile', tmp_str)
503 this%config%bodies(i)%stiff_geom%decay_profile = tmp_str
504
505 select case (trim(this%config%bodies(i)%stiff_geom%decay_profile))
506 case ('gaussian')
507 call json_get_or_default(body_sub, &
508 'stiff_geom.cutoff_coef', &
509 this%config%bodies(i)%stiff_geom%cutoff_coef, 9.0_rp)
510 case ('tanh')
511 call json_get_or_default(body_sub, &
512 'stiff_geom.cutoff_coef', &
513 this%config%bodies(i)%stiff_geom%cutoff_coef, 3.5_rp)
514 case default
515 call neko_error("ALE: Invalid stiff_geom.decay_profile: " // &
516 trim(this%config%bodies(i)%stiff_geom%decay_profile))
517 end select
518
519 select case (trim(this%config%bodies(i)%stiff_geom%type))
520 case ('cylinder', 'sphere')
521 call json_get(body_sub, 'stiff_geom.center', tmp_vec, &
522 expected_size = 3)
523 this%config%bodies(i)%stiff_geom%center = tmp_vec
524
525 call json_get(body_sub, 'stiff_geom.radius', &
526 this%config%bodies(i)%stiff_geom%radius)
527 case ('cheap_dist')
528 call json_get(body_sub, 'stiff_geom.stiff_dist', &
529 this%config%bodies(i)%stiff_geom%stiff_dist)
530 case ('box')
531 call neko_error("ALE: stiff_geom.type 'box' not yet" // &
532 " implemented.")
533 case default
534 call neko_error("ALE: Invalid stiff_geom.type: " // &
535 trim(this%config%bodies(i)%stiff_geom%type))
536 end select
537 elseif (import_base_shapes) then
538 ! do nothing.
539 else
540 call neko_error("ALE: Body '" // &
541 trim(this%config%bodies(i)%name) // &
542 "' must have 'stiff_geom' definition.")
543 end if
544
545 ! Initialize the pivots.
546 call init_pivot_state(this%ale_pivot(i), this%config%bodies(i))
547
548 call this%base_shapes(i)%init(coef%dof, &
549 "phi_" // trim(this%config%bodies(i)%name))
550 call field_rzero(this%base_shapes(i))
551
552 ! Create Ghost Trackers for numerically forming the rotation matrix
553 ! of each body.
554 ! Basis X (Pivot + 1.0 in X)
555 this%ghost_handles(1, i) = this%request_tracker( &
556 this%config%bodies(i)%rot_center + [1.0_rp, 0.0_rp, 0.0_rp], &
557 this%config%bodies(i)%id)
558 ! Basis Y (Pivot + 1.0 in Y)
559 this%ghost_handles(2, i) = this%request_tracker( &
560 this%config%bodies(i)%rot_center + [0.0_rp, 1.0_rp, 0.0_rp], &
561 this%config%bodies(i)%id)
562
563 call neko_log%message('Registered Body : ' // &
564 trim(this%config%bodies(i)%name))
565
566 ! Logging Stiff Body
567 call neko_log%message(' ')
568 if (associated(this%user_ale_base_shapes, &
570 (.not. import_base_shapes)) then
571 write(log_buf, '(A,A)') ' Stiff Type : ', &
572 trim(this%config%bodies(i)%stiff_geom%type)
573 call neko_log%message(log_buf)
574 write(log_buf, '(A,ES18.11,A,A,A,ES10.4)') ' Gain : ', &
575 this%config%bodies(i)%stiff_geom%gain, ' | Profile: ', &
576 trim(this%config%bodies(i)%stiff_geom%decay_profile), &
577 ' | Cutoff: ', this%config%bodies(i)%stiff_geom%cutoff_coef
578 call neko_log%message(log_buf)
579 select case (trim(this%config%bodies(i)%stiff_geom%type))
580 case ('cylinder', 'sphere')
581 write(log_buf, '(A,3(ES23.15,1X))') ' Center :', &
582 this%config%bodies(i)%stiff_geom%center
583 call neko_log%message(log_buf)
584 write(log_buf, '(A,ES23.15)') ' Radius :', &
585 this%config%bodies(i)%stiff_geom%radius
586 call neko_log%message(log_buf)
587 case ('cheap_dist')
588 write(log_buf, '(A,ES23.15)') ' Stiff Dist:', &
589 this%config%bodies(i)%stiff_geom%stiff_dist
590 call neko_log%message(log_buf)
591 end select
592 end if
593 call neko_log%message(' ')
594
595 ! Logging Oscillation
596 has_builtin_osc = any(abs(this%config%bodies(i)%osc_amp) .gt. 0.0_rp)
597
598 if (has_builtin_osc) then
599 if (has_user_rigid_kin .or. has_user_mesh_vel) then
600 call neko_log%message(' Oscillation : ' // &
601 'X(t) = Amp*sin(2*pi*Freq*t) + User')
602 write(log_buf, '(A,3(ES18.11,1X))') ' Amp :', &
603 this%config%bodies(i)%osc_amp
604 call neko_log%message(log_buf)
605 write(log_buf, '(A,3(ES18.11,1X))') ' Freq :', &
606 this%config%bodies(i)%osc_freq
607 call neko_log%message(log_buf)
608 else
609 call neko_log%message(' Oscillation : ' // &
610 'X(t) = Amp*sin(2*pi*Freq*t)')
611 write(log_buf, '(A,3(ES18.11,1X))') ' Amp :', &
612 this%config%bodies(i)%osc_amp
613 call neko_log%message(log_buf)
614 write(log_buf, '(A,3(ES18.11,1X))') ' Freq :', &
615 this%config%bodies(i)%osc_freq
616 call neko_log%message(log_buf)
617 end if
618 else
619 if (has_user_rigid_kin .or. has_user_mesh_vel) then
620 call neko_log%message(' Oscillation : User-defined')
621 else
622 call neko_log%message(' Oscillation : None')
623 end if
624 end if
625 call neko_log%message(' ')
626
627 ! Logging Rotation
628 has_builtin_rot = (trim(this%config%bodies(i)%rotation_type) &
629 /= 'user')
630
631 if (trim(this%config%bodies(i)%rotation_type) .eq. 'user') then
632
633 call neko_log%message(' Rotation Type: User-defined')
634
635 elseif (has_builtin_rot) then
636
637 ! Check parameters active
638 is_rot_active = .false.
639 select case (trim(this%config%bodies(i)%rotation_type))
640 case ('harmonic')
641 is_rot_active = any(abs(this%config%bodies(i)%rot_amp_degree) &
642 .gt. 0.0_rp)
643 case ('ramp')
644 is_rot_active = any(abs(this%config%bodies(i)%ramp_omega0) &
645 .gt. 0.0_rp)
646 case ('smooth_step')
647 is_rot_active = &
648 (abs(this%config%bodies(i)%target_rot_angle_deg) &
649 .gt. 0.0_rp)
650 end select
651
652 if (is_rot_active) then
653 ! Harmonic
654 if (trim(this%config%bodies(i)%rotation_type) &
655 .eq. 'harmonic') then
656 if (has_user_rigid_kin .or. has_user_mesh_vel) then
657 call neko_log%message(' Rotation : ' // &
658 'Theta(t) = Amp*sin(2*pi*Freq*t) + User')
659 else
660 call neko_log%message(' Rotation : ' // &
661 'Theta(t) = Amp*sin(2*pi*Freq*t)')
662 end if
663 write(log_buf, '(A,3(ES18.11,1X))') ' Amp (deg) :', &
664 this%config%bodies(i)%rot_amp_degree
665 call neko_log%message(log_buf)
666 write(log_buf, '(A,3(ES18.11,1X))') ' Freq :', &
667 this%config%bodies(i)%rot_freq
668 call neko_log%message(log_buf)
669
670 ! Ramp
671 elseif (trim(this%config%bodies(i)%rotation_type) &
672 .eq. 'ramp') then
673 if (has_user_rigid_kin .or. has_user_mesh_vel) then
674 call neko_log%message(' Rotation : ' // &
675 'Omega(t) = Omega0*(1 - exp(-4.6*t/t0)) + User')
676 else
677 call neko_log%message(' Rotation : ' // &
678 'Omega(t) = Omega0*(1 - exp(-4.6*t/t0))')
679 end if
680 write(log_buf, '(A,3(ES18.11,1X))') ' Omega0 :', &
681 this%config%bodies(i)%ramp_omega0
682 call neko_log%message(log_buf)
683 write(log_buf, '(A,3(ES18.11,1X))') ' t0 :', &
684 this%config%bodies(i)%ramp_t0
685 call neko_log%message(log_buf)
686
687 ! Smooth Step
688 elseif (trim(this%config%bodies(i)%rotation_type) &
689 .eq. 'smooth_step') then
690 if (has_user_rigid_kin .or. has_user_mesh_vel) then
691 call neko_log%message(' Rotation : ' // &
692 'Smooth Step Control + User')
693 else
694 call neko_log%message(' Rotation : ' // &
695 'Smooth Step Control')
696 end if
697 write(log_buf, '(A,I10)') ' Rotation Axis :', &
698 this%config%bodies(i)%rotation_axis
699 call neko_log%message(log_buf)
700 write(log_buf, '(A,ES18.11)') ' Target Rot ' // &
701 'Angle (deg) :', &
702 this%config%bodies(i)%target_rot_angle_deg
703 call neko_log%message(log_buf)
704 write(log_buf, '(A,4(ES18.11,1X))') &
705 ' Control Times [t0, t1, t2, t3] :', &
706 this%config%bodies(i)%step_control_times
707 call neko_log%message(log_buf)
708 end if
709 else
710 if (has_user_rigid_kin .or. has_user_mesh_vel) then
711 call neko_log%message(' Rotation Type: User-defined')
712 else
713 call neko_log%message(' Rotation Type: None')
714 end if
715 end if
716
717 end if
718
719 ! Logging Pivot
720 call neko_log%message(' ')
721 call neko_log%message(' Pivot Type : ' // &
722 trim(this%config%bodies(i)%rotation_center_type))
723
724 write(log_buf, '(A,3(ES18.11,1X))') ' Init Pivot:', &
725 this%config%bodies(i)%rot_center
726 call neko_log%message(log_buf)
727 call neko_log%message(' ')
728
729 end do
730 else
731 call neko_error("ALE: No 'ale bodies' found in case file!")
732 end if
733
734 if (this%config%nbodies .gt. 1 .and. (.not. import_base_shapes)) then
735 call this%phi_total%init(coef%dof, "phi_total")
736 call field_rzero(this%phi_total)
737 end if
738
739 ! Check to be sure moving no_slip ids belong to an ALE body
740 do i = 1, n_moving_zones
741 z = moving_zone_ids(i)
742 found_zone = .false.
743 j = 1
744 do while ((.not. found_zone) .and. (j .le. this%config%nbodies))
745 if (any(this%config%bodies(j)%zone_indices .eq. z)) then
746 found_zone = .true.
747 end if
748 j = j + 1
749 end do
750 if (.not. found_zone) then
751 write(log_buf_l, '(A,I0,A)') &
752 "ALE: zone index ", z, &
753 " has BC no_slip with moving: true, " // &
754 "but it is not registered in ALE bodies."
755 call neko_error(trim(log_buf_l))
756 end if
757 end do
758
759 ! Any id registered in ALE bodies must have
760 ! no_slip with moving: true in BCs.
761 do j = 1, this%config%nbodies
762 if (allocated(this%config%bodies(j)%zone_indices)) then
763 do i = 1, size(this%config%bodies(j)%zone_indices)
764 z = this%config%bodies(j)%zone_indices(i)
765 found_zone = .false.
766 if (n_moving_zones .gt. 0) then
767 if (any(moving_zone_ids(1:n_moving_zones) .eq. z)) then
768 found_zone = .true.
769 end if
770 end if
771 if (.not. found_zone) then
772 write(log_buf_l, '(A,I0,A,A)') &
773 "ALE: zone index ", z, &
774 " is registered in ALE bodies, ", &
775 "but the BC is not no_slip with moving: true."
776 call neko_error(trim(log_buf_l))
777 end if
778 end do
779 end if
780 end do
781
782 ! Check no zone ID is assigned to more than one ALE body.
783 do j = 1, this%config%nbodies
784 if (allocated(this%config%bodies(j)%zone_indices)) then
785 do i = 1, size(this%config%bodies(j)%zone_indices)
786 z = this%config%bodies(j)%zone_indices(i)
787
788 do k = j + 1, this%config%nbodies
789 if (allocated(this%config%bodies(k)%zone_indices)) then
790 if (any(this%config%bodies(k)%zone_indices .eq. z)) then
791 write(log_buf_l, '(A,I0,A,A,A,A,A)') &
792 "ALE: zone index ", z, &
793 " is assigned to multiple bodies ('", &
794 trim(this%config%bodies(j)%name), "' and '", &
795 trim(this%config%bodies(k)%name), "')."
796 call neko_error(trim(log_buf_l))
797 end if
798 end if
799 end do
800
801 end do
802 end if
803 end do
804
805 ! Find the smooth blending function for mesh displacement.
806 call this%solve_base_mesh_displacement(coef, json, import_base_shapes, &
807 solver_params, precon_type, precon_params)
808
809 call this%wm_x_lag%init(this%wm_x, 2)
810 call this%wm_y_lag%init(this%wm_y, 2)
811 call this%wm_z_lag%init(this%wm_z, 2)
812
813 if (allocated(moving_zone_ids)) deallocate(moving_zone_ids)
814 if (allocated(bc_type)) deallocate(bc_type)
815 if (allocated(zone_indices)) deallocate(zone_indices)
816 if (allocated(ksp_solver)) deallocate(ksp_solver)
817 if (allocated(precon_type)) deallocate(precon_type)
818 if (allocated(tmp_str)) deallocate(tmp_str)
819 if (allocated(tmp_vec)) deallocate(tmp_vec)
820
821 ! Performing mesh_preview.
822 call this%mesh_preview(coef, json, numerics_params)
823
824 ! Register checkpoint fields
825 call this%register_checkpoint_fields(coef, chkp)
826
827 call neko_log%end_section()
828 end subroutine ale_manager_init
829
830 !> Solves the Laplace equation to determine the base shape (phi)
831 !> for each body.
832 !> It finds a smooth blending function for mesh deformation.
833 !> For body i: phi_i = 1 on body i zones, phi_i = 0 on all other boundaries.
834 subroutine solve_base_mesh_displacement(this, coef, json, &
835 import_base_shapes, solver_params, precon_type, precon_params)
836 class(ale_manager_t), intent(inout), target :: this
837 class(ax_t), allocatable :: Ax
838 class(ksp_t), allocatable :: ksp
839 class(pc_t), allocatable :: pc
840 type(coef_t), intent(inout) :: coef
841 type(json_file), intent(inout) :: json
842 logical, intent(in) :: import_base_shapes
843 type(json_file), intent(inout) :: solver_params
844 character(len=*), intent(in) :: precon_type
845 type(json_file), intent(inout) :: precon_params
846 type(file_t) :: phi_file
847 type(field_t), pointer :: phi_ptr => null()
848 type(field_t) :: rhs_field
849 type(field_t) :: corr_field
850 type(ksp_monitor_t) :: monitor(1)
851 real(kind=rp) :: sample_start_time, sample_end_time
852 real(kind=rp) :: sample_time
853 character(len=LOG_SIZE) :: log_buf
854 integer :: n, i, m, k, ierr, body_idx, z_idx
855 integer :: j
856 real(kind=rp), allocatable :: h1_restore(:, :, :, :)
857 real(kind=rp), allocatable :: h2_restore(:, :, :, :)
858 type(zero_dirichlet_t) :: bc_active_body
859 type(zero_dirichlet_t) :: bc_inactive_body
860 type(scalar_bc_projector_t) :: bc_projector
861 type(scalar_bc_projector_t) :: bc_projector_zeros_only
862 type(json_file) :: body_sub
863 character(len=256) :: phi_fname
864 character(len=:), allocatable :: tmp_str
865
866
867 if (.not. this%active) return
868 if (.not. this%has_moving_boundary) return
869 if (this%config%nbodies .eq. 0) return
870
871 if (import_base_shapes) then
872 call neko_log%message(" ")
873 call neko_log%message("Importing ALE base shapes" // &
874 " (skipping Laplace solve)...")
875
876 do body_idx = 1, this%config%nbodies
877
878 call json_extract_item(json, 'ale.bodies', &
879 body_idx, body_sub)
880
881 call json_get(body_sub, 'base_shape_import_file', tmp_str)
882 phi_fname = tmp_str
883
884 phi_ptr => this%base_shapes(body_idx)
885
886 ! Load the field
887 call import_fields(fname = trim(phi_fname), p = phi_ptr)
888
889 call neko_log%message(" Loaded: " // &
890 trim(phi_fname) // &
891 " for body: " // &
892 trim(this%config%bodies(body_idx)%name))
893 end do
894
895 return
896 end if
897
898 call neko_log%message(" ")
899 call neko_log%message("Starting base mesh motion solve ...")
900 n = coef%dof%size()
901
902 call ax_helm_allocator(ax, type_name = "standard")
903 call krylov_solver_factory(ksp, n, solver_params)
904 call ale_precon_factory(pc, ksp, coef, this%bc_list, precon_type, &
905 precon_params)
906
907 ! Save original h1/h2
908 h1_restore = coef%h1
909 h2_restore = coef%h2
910
911 call rhs_field%init(coef%dof)
912 call corr_field%init(coef%dof)
913
914
915 ! User Defined Base Shapes (Skip Solver).
916 if (.not. associated(this%user_ale_base_shapes, &
918 call neko_log%message(" Using user-defined base shapes " // &
919 "(skipping Laplace solve)")
920
921 ! Call User Hook (Populates this%base_shapes)
922 call this%user_ale_base_shapes(this%base_shapes)
923
924 ! Compute phi_total (Sum of all user shapes)
925 if (this%config%nbodies .gt. 1) then
926 call field_rzero(this%phi_total)
927 do body_idx = 1, this%config%nbodies
928 call field_add2(this%phi_total, this%base_shapes(body_idx), n)
929 end do
930 end if
931
932 ! Output Shapes
933 if (this%config%if_output_phi) then
934 ! Individual Bodies
935 do body_idx = 1, this%config%nbodies
936 call phi_file%init('phi_' // &
937 trim(this%config%bodies(body_idx)%name) // '.fld', &
938 precision = rp)
939 select type (ft => phi_file%file_type)
940 type is (fld_file_t)
941 ft%skip_pressure = .false.
942 end select
943 call phi_file%write(this%base_shapes(body_idx))
944 call phi_file%free()
945 call neko_log%message(' phi_' // &
946 trim(this%config%bodies(body_idx)%name) // '.fld saved.')
947 end do
948
949 ! Total
950 if (this%config%nbodies .gt. 1) then
951 call neko_log%message(" phi_total.fld saved.")
952 select type (ft => phi_file%file_type)
953 type is (fld_file_t)
954 ft%skip_pressure = .false.
955 end select
956 call phi_file%init('phi_total.fld', precision = rp)
957 call phi_file%write(this%phi_total)
958 call phi_file%free()
959 end if
960 end if
961 else
962 ! Standard Laplace Solve (Requires Stiffness)
963
964 ! Compute Stiffness
965 call compute_stiffness_ale(coef, this%config)
966
967 ! Output Stiffness if requested (for diagnostic)
968 if (this%config%if_output_stiffness) then
969 rhs_field%x = coef%h1
970 call phi_file%init('stiffness.fld')
971 call phi_file%write(rhs_field)
972 call phi_file%free()
973 call field_rzero(rhs_field)
974 end if
975
976 ! Loop over bodies and Solve Laplace
977 do body_idx = 1, this%config%nbodies
978 call mpi_barrier(neko_comm, ierr)
979 sample_start_time = mpi_wtime()
980 call neko_log%message(" Solving laplace for body: " // &
981 trim(this%config%bodies(body_idx)%name))
982
983 call bc_active_body%init_from_components(coef)
984 call bc_inactive_body%init_from_components(coef)
985
986 ! Mark zones
987 do j = 1, size(this%config%bodies(body_idx)%zone_indices)
988 z_idx = this%config%bodies(body_idx)%zone_indices(j)
989 call bc_active_body%mark_zone(coef%msh%labeled_zones(z_idx))
990 end do
991
992 do i = 1, this%config%nbodies
993 if (i /= body_idx) then
994 do j = 1, size(this%config%bodies(i)%zone_indices)
995 z_idx = this%config%bodies(i)%zone_indices(j)
996 call bc_inactive_body%mark_zone(&
997 coef%msh%labeled_zones(z_idx))
998 end do
999 end if
1000 end do
1001
1002 call bc_active_body%finalize()
1003 call bc_inactive_body%finalize()
1004
1005 ! The Full list for the solver (Freeze everything to 0 correction)
1006 call bc_projector%mark(this%bc_fixed)
1007 call bc_projector%mark(bc_active_body)
1008 call bc_projector%mark(bc_inactive_body)
1009
1010 ! The "Zeros Only" list for the field (Reset other boundaries)
1011 call bc_projector_zeros_only%mark(this%bc_fixed)
1012 call bc_projector_zeros_only%mark(bc_inactive_body)
1013
1014 call field_rzero(this%base_shapes(body_idx))
1015 this%base_shapes(body_idx)%x = 0.0_rp
1016 rhs_field%x = 0.0_rp
1017 corr_field%x = 0.0_rp
1018 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1019 ! phi = phi_corr + phi_lifted!
1020 ! A*phi_corr = -A*phi_lifted !
1021 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1022
1023 ! Lift BC (Dirichlet = 1.0 on moving body)
1024 m = bc_active_body%msk(0)
1025 do i = 1, m
1026 k = bc_active_body%msk(i)
1027 this%base_shapes(body_idx)%x(k, 1, 1, 1) = 1.0_rp
1028 end do
1029
1030 if (neko_bcknd_device .eq. 1) then
1031 call device_memcpy(this%base_shapes(body_idx)%x, &
1032 this%base_shapes(body_idx)%x_d, n, host_to_device, .true.)
1033 end if
1034
1035 ! Apply Zeros to others.
1036 ! This ensures fixed walls and other bodies are 0.0,
1037 ! even if they share grid with a moving wall.
1038 call bc_projector_zeros_only%apply(this%base_shapes(body_idx)%x, n)
1039
1040 ! Compute RHS: RHS = -A * Phi_lifted.
1041 ! The following is motivated by implementation in Nek5000.
1042 call ax%compute(rhs_field%x, this%base_shapes(body_idx)%x, &
1043 coef, coef%msh, coef%Xh)
1044 call field_cmult(rhs_field, -1.0_rp)
1045
1046 ! Here we use the FULL list to apply zero Dirichlet BC
1047 ! on all boundaries.
1048 call bc_projector%apply(rhs_field%x, n)
1049 call coef%gs_h%op(rhs_field, gs_op_add)
1050
1051 ! Solve
1052 call field_rzero(corr_field)
1053 call pc%update()
1054 monitor(1) = ksp%solve(ax, corr_field, &
1055 rhs_field%x, n, coef, bc_projector, coef%gs_h)
1056
1057 ! phi = phi_lifted + phi_corr
1058 call field_add2(this%base_shapes(body_idx), corr_field, n)
1059
1060 ! Update Total Phi
1061 ! phi_total should be between 0 and 1.
1062 if (this%config%nbodies .gt. 1) then
1063 call field_add2(this%phi_total, this%base_shapes(body_idx), n)
1064 end if
1065
1066 call mpi_barrier(neko_comm, ierr)
1067 sample_end_time = mpi_wtime()
1068 sample_time = sample_end_time - sample_start_time
1069 write(log_buf, '(A, A, A, ES11.4, A)') " Laplace solve for '", &
1070 trim(this%config%bodies(body_idx)%name), "' took ", &
1071 sample_time, " (s)"
1072
1073 call neko_log%message(log_buf)
1074
1075 call bc_active_body%free()
1076 call bc_inactive_body%free()
1077 call bc_projector%free()
1078 call bc_projector_zeros_only%free()
1079
1080 ! We let the host to also have the base_shapes so in
1081 ! user_ale_mesh_vel
1082 ! it would be easier in general to use it.
1083 if (neko_bcknd_device .eq. 1) then
1084 call device_memcpy(this%base_shapes(body_idx)%x, &
1085 this%base_shapes(body_idx)%x_d, n, device_to_host, .true.)
1086 end if
1087
1088 if (this%config%if_output_phi) then
1089 call phi_file%init('phi_' // &
1090 trim(this%config%bodies(body_idx)%name) // '.fld', &
1091 precision = rp)
1092 select type (ft => phi_file%file_type)
1093 type is (fld_file_t)
1094 ft%skip_pressure = .false.
1095 end select
1096 call phi_file%write(this%base_shapes(body_idx))
1097 call phi_file%free()
1098 call neko_log%message(' phi_' // &
1099 trim(this%config%bodies(body_idx)%name) // '.fld saved.')
1100 end if
1101 end do
1102
1103 if (this%config%if_output_phi .and. (this%config%nbodies .gt. 1)) then
1104
1105 if (neko_bcknd_device .eq. 1) then
1106 call device_memcpy(this%phi_total%x, this%phi_total%x_d, n, &
1107 device_to_host, .true.)
1108 end if
1109
1110 call neko_log%message(" phi_total.fld saved.")
1111 call phi_file%init('phi_total.fld', precision = rp)
1112 select type (ft => phi_file%file_type)
1113 type is (fld_file_t)
1114 ft%skip_pressure = .false.
1115 end select
1116 call phi_file%write(this%phi_total)
1117 call phi_file%free()
1118 end if
1119 end if
1120
1121 call rhs_field%free()
1122 call corr_field%free()
1123 if (this%config%nbodies > 1) then
1124 call this%phi_total%free()
1125 end if
1126
1127 ! Restore h1/h2 to what they were before
1128 coef%h1(:,:,:,:) = h1_restore(:,:,:,:)
1129 coef%h2(:,:,:,:) = h2_restore(:,:,:,:)
1130 if (neko_bcknd_device .eq. 1) then
1131 call device_memcpy(coef%h1, coef%h1_d, n, host_to_device, .false.)
1132 call device_memcpy(coef%h2, coef%h2_d, n, host_to_device, .true.)
1133 end if
1134
1135 if (allocated(h1_restore)) deallocate(h1_restore)
1136 if (allocated(h2_restore)) deallocate(h2_restore)
1137 if (allocated(ax)) then
1138 call ax%free()
1139 deallocate(ax)
1140 end if
1141 if (allocated(ksp)) then
1142 call ksp%free()
1143 deallocate(ksp)
1144 end if
1145 if (allocated(pc)) then
1146 call pc%free()
1147 deallocate(pc)
1148 end if
1149
1150 end subroutine solve_base_mesh_displacement
1151
1152 !> Updates the mesh velocity field based on current time and kinematics
1153 !> Sums contributions from all bodies: mesh_vel = Sum( V_i * Phi_i )
1154 subroutine update_mesh_velocity(this, coef, time_s)
1155 class(ale_manager_t), intent(inout) :: this
1156 type(coef_t), intent(in) :: coef
1157 type(time_state_t), intent(in) :: time_s
1158 integer :: i, n
1159 type(body_kinematics_t) :: current_kin
1160 real(kind=rp) :: rot_mat(3,3)
1161 real(kind=rp) :: initial_rot_center(3)
1162
1163 if (.not. this%active) return
1164 if (.not. this%has_moving_boundary) return
1165 call profiler_start_region('ALE add mesh velocity')
1166
1167 call field_rzero(this%wm_x)
1168 call field_rzero(this%wm_y)
1169 call field_rzero(this%wm_z)
1170
1171 do i = 1, this%config%nbodies
1172 ! Compute kinematics for built-in motions
1173 ! "current_kin" will be like solid body kinematics at current time
1174 call compute_body_kinematics_built_in(current_kin, &
1175 this%config%bodies(i), time_s)
1176
1177 ! User modifier (Superposition or Override)
1178 if (.not. associated(this%user_ale_rigid_kinematics, &
1180 call this%user_ale_rigid_kinematics(this%config%bodies(i)%id, &
1181 time_s, &
1182 current_kin%vel_trans, &
1183 current_kin%vel_ang)
1184 end if
1185
1186 current_kin%center = this%ale_pivot(i)%pos
1187 this%ale_pivot(i)%vel = current_kin%vel_trans
1188
1189 this%body_kin(i)%center = this%ale_pivot(i)%pos
1190 this%body_kin(i)%vel_trans = current_kin%vel_trans
1191 this%body_kin(i)%vel_ang = current_kin%vel_ang
1192
1193 ! Compute rotation matrix at current time
1194 call this%compute_rotation_matrix(i, time_s)
1195 rot_mat = this%body_rot_matrices(:,:,i)
1196 initial_rot_center = this%config%bodies(i)%rot_center
1197
1198 ! Accumulate contribution from each body and add to mesh velocity
1199 call add_kinematics_to_mesh_velocity(this%wm_x, this%wm_y, &
1200 this%wm_z, this%x_ref, this%y_ref, this%z_ref , &
1201 this%base_shapes(i), coef, current_kin, rot_mat, &
1202 initial_rot_center)
1203
1204 ! For checkpointing
1205 call this%prep_checkpoint(i)
1206 end do
1207
1208 ! If user has provided a custom function for mesh velocity.
1209 ! User mesh velocity will be added to the ale computed mesh velocity.
1210 ! This routine should not be used for rigid body motions!
1211 if (.not. associated(this%user_ale_mesh_vel, &
1213 call this%user_ale_mesh_vel(this%wm_x, this%wm_y, this%wm_z, &
1214 coef, this%x_ref, this%y_ref, this%z_ref, this%base_shapes, time_s)
1215 end if
1216
1217 call profiler_end_region('ALE add mesh velocity')
1218
1219 end subroutine update_mesh_velocity
1220
1221 !> Set the mesh velocity at t = 0. Not called on a restart, where the
1222 !! mesh velocity is read from the checkpoint.
1223 !! @param coef The coefficients.
1224 subroutine set_initial_mesh_velocity(this, coef)
1225 class(ale_manager_t), intent(inout) :: this
1226 type(coef_t), intent(in) :: coef
1227 type(time_state_t) :: t_init
1228
1229 t_init%t = 0.0_rp
1230 t_init%tstep = 0
1231 t_init%dt = 0.0_rp
1232 call this%update_mesh_velocity(coef, t_init)
1233
1234 end subroutine set_initial_mesh_velocity
1235
1236 !> Main routine to advance the mesh in time
1237 subroutine advance_mesh(this, coef, time, nadv)
1238 class(ale_manager_t), intent(inout) :: this
1239 type(coef_t), intent(inout) :: coef
1240 type(time_state_t), intent(in) :: time
1241 integer, intent(in) :: nadv
1242 integer :: i
1243
1244 if (.not. this%active) return
1245 if (.not. this%has_moving_boundary) return
1246 call profiler_start_region('ALE update mesh')
1247 do i = 1, this%config%nbodies
1248 ! Advance Point Trackers attached to this body.
1249 ! Can be used for torque calculation (simcomp) at a point distanced
1250 ! from the body.
1251 ! or other purposes like tracking movement (user_check).
1252 call this%ghost_tracker_coord_step(this%body_kin(i), time, nadv, i)
1253 ! Update Pivot Location if requested
1254 call update_pivot_location(this%ale_pivot(i), &
1255 this%ale_pivot(i)%pos, &
1256 this%ale_pivot(i)%vel, &
1257 time, &
1258 nadv, &
1259 this%config%bodies(i))
1260 end do
1261
1262 ! Update lagged B terms (geometry history)
1263 call coef%update_B_history()
1264
1265 ! Update mesh coordinates
1266 call update_ale_mesh(coef, this%wm_x, this%wm_y, this%wm_z, &
1267 this%wm_x_lag, this%wm_y_lag, this%wm_z_lag, &
1268 time, nadv, "ab")
1269
1270 ! Update internal history of mesh velocity.
1271 call this%wm_x_lag%update()
1272 call this%wm_y_lag%update()
1273 call this%wm_z_lag%update()
1274 call profiler_end_region('ALE update mesh')
1275 end subroutine advance_mesh
1276
1277 ! Compute mesh stiffness with per-body gain/decay from stiff_geom.
1278 subroutine compute_stiffness_ale(coef, params)
1279 type(coef_t), intent(inout) :: coef
1280 type(ale_config_t), intent(in) :: params
1281 integer :: i, n, b, ierr
1282 integer, allocatable :: cheap_map(:)
1283 integer :: n_cheap, map_idx
1284 real(kind=rp) :: x, y, z
1285 real(kind=rp) :: raw_dist, body_stiff_val, max_added_stiff
1286 real(kind=rp) :: cx, cy, cz
1287 real(kind=rp) :: arg, decay, gain, norm_dist
1288 real(kind=rp) :: sample_start_time, sample_end_time, sample_time
1289 type(field_t), allocatable :: dist_fields(:)
1290 character(len=128) :: log_buf
1291
1292 n = coef%dof%size()
1293
1294 ! Check how many bodies need cheap_dist and create map
1295 allocate(cheap_map(params%nbodies))
1296 cheap_map = 0
1297 n_cheap = 0
1298
1299 do b = 1, params%nbodies
1300 if (trim(params%bodies(b)%stiff_geom%type) .eq. 'cheap_dist') then
1301 n_cheap = n_cheap + 1
1302 cheap_map(b) = n_cheap
1303 end if
1304 end do
1305
1306 ! Allocate and Compute cheap_dist only for required bodies
1307 if (n_cheap > 0) then
1308 allocate(dist_fields(n_cheap))
1309
1310 do b = 1, params%nbodies
1311 map_idx = cheap_map(b)
1312 if (map_idx .gt. 0) then
1313
1314 call dist_fields(map_idx)%init(coef%dof, "tmp_cheap_dist")
1315
1316 call neko_log%message(' ')
1317 call neko_log%message(" Start: cheap dist calculation " // &
1318 "for body '" // trim(params%bodies(b)%name) // "'")
1319
1320 call mpi_barrier(neko_comm, ierr)
1321 sample_start_time = mpi_wtime()
1322
1323 if (neko_bcknd_device .eq. 1) then
1324 call compute_cheap_dist_device(dist_fields(map_idx), coef, &
1325 coef%msh, params%bodies(b)%zone_indices, &
1326 copy_to_host = .true.)
1327 else
1328 call compute_cheap_dist_v2_cpu(dist_fields(map_idx), coef, &
1329 coef%msh, params%bodies(b)%zone_indices)
1330 end if
1331
1332 call mpi_barrier(neko_comm, ierr)
1333 sample_end_time = mpi_wtime()
1334 sample_time = sample_end_time - sample_start_time
1335
1336 write(log_buf, '(A, A, A, ES11.4, A)') " cheap dist for '", &
1337 trim(params%bodies(b)%name), "' took ", sample_time, " (s)"
1338 call neko_log%message(log_buf)
1339 end if
1340 end do
1341 end if
1342 call neko_log%message(' ')
1343
1344 ! Build stiffness field on Host
1345 select case (trim(params%stiffness_type))
1346 case ('built-in')
1347
1348 do concurrent(i = 1:n)
1349 x = coef%dof%x%x(i, 1, 1, 1)
1350 y = coef%dof%y%x(i, 1, 1, 1)
1351 z = coef%dof%z%x(i, 1, 1, 1)
1352
1353 max_added_stiff = 0.0_rp
1354
1355 ! Loop over bodies, calculate local contribution
1356 do b = 1, params%nbodies
1357 gain = params%bodies(b)%stiff_geom%gain
1358 if (trim(params%bodies(b)%stiff_geom%type) .eq. 'cheap_dist') then
1359 decay = params%bodies(b)%stiff_geom%stiff_dist
1360 else
1361 decay = params%bodies(b)%stiff_geom%radius
1362 end if
1363
1364 ! Geometry Center
1365 cx = params%bodies(b)%stiff_geom%center(1)
1366 cy = params%bodies(b)%stiff_geom%center(2)
1367 cz = params%bodies(b)%stiff_geom%center(3)
1368
1369 raw_dist = huge(0.0_rp)
1370
1371 ! Calculate Distance
1372 select case (trim(params%bodies(b)%stiff_geom%type))
1373 case ('sphere')
1374 raw_dist = sqrt((x - cx)**2 + (y - cy)**2 + (z - cz)**2)
1375
1376 case ('cylinder')
1377 ! Distance to Z-axis centered at (cx, cy)
1378 raw_dist = sqrt((x - cx)**2 + (y - cy)**2)
1379
1380 case ('box')
1381 ! ToDO
1382
1383 case ('cheap_dist')
1384 map_idx = cheap_map(b)
1385 if (map_idx .gt. 0) then
1386 raw_dist = dist_fields(map_idx)%x(i, 1, 1, 1)
1387 end if
1388 end select
1389
1390 ! Apply Profile
1391 body_stiff_val = 0.0_rp
1392 select case (trim(params%bodies(b)%stiff_geom%decay_profile))
1393 case ('gaussian')
1394 ! exp( -(r/decay)^2 )
1395 arg = -(raw_dist**2) / (decay**2)
1396 arg = arg * params%bodies(b)%stiff_geom%cutoff_coef
1397 body_stiff_val = gain * exp(arg)
1398
1399 case ('tanh')
1400 ! Tanh profile
1401 norm_dist = (raw_dist / decay)
1402 norm_dist = norm_dist * params%bodies(b)%stiff_geom%cutoff_coef
1403 body_stiff_val = gain * (1.0_rp - tanh(norm_dist))
1404 end select
1405
1406 if (body_stiff_val .gt. max_added_stiff) then
1407 max_added_stiff = body_stiff_val
1408 end if
1409 end do
1410
1411 coef%h1(i, 1, 1, 1) = 1.0_rp + max_added_stiff
1412 coef%h2(i, 1, 1, 1) = 0.0_rp
1413 end do
1414
1415 case default
1416 call neko_error("ALE Manager: Unknown stiffness type")
1417 end select
1418
1419 coef%ifh2 = .false.
1420
1421 if (neko_bcknd_device .eq. 1) then
1422 call device_memcpy(coef%h1, coef%h1_d, n, host_to_device, .false.)
1423 call device_memcpy(coef%h2, coef%h2_d, n, host_to_device, .true.)
1424 end if
1425
1426 if (allocated(dist_fields)) then
1427 do i = 1, size(dist_fields)
1428 call dist_fields(i)%free()
1429 end do
1430 deallocate(dist_fields)
1431 end if
1432 if (allocated(cheap_map)) deallocate(cheap_map)
1433
1434 end subroutine compute_stiffness_ale
1435
1436 ! Adds kinematics to mesh velocity.
1437 subroutine add_kinematics_to_mesh_velocity(wx, wy, wz, &
1438 x_ref, y_ref, z_ref, phi, coef, kinematics, rot_mat, initial_pivot_loc)
1439 type(field_t), intent(inout) :: wx, wy, wz
1440 type(field_t), intent(in) :: x_ref, y_ref, z_ref
1441 type(field_t), intent(in) :: phi
1442 type(coef_t), intent(in) :: coef
1443 type(body_kinematics_t), intent(in) :: kinematics
1444 real(kind=rp), intent(in) :: initial_pivot_loc(3)
1445 real(kind=rp), intent(in) :: rot_mat(3,3)
1446 if (neko_bcknd_device .eq. 1) then
1448 x_ref, y_ref, z_ref, &
1449 phi, coef, kinematics, rot_mat, initial_pivot_loc)
1450 else
1451 call add_kinematics_to_mesh_velocity_cpu(wx, wy, wz, &
1452 x_ref, y_ref, z_ref, &
1453 phi, coef, kinematics, rot_mat, initial_pivot_loc)
1454 end if
1455 end subroutine add_kinematics_to_mesh_velocity
1456
1457 ! Updates mesh position by integrating mesh velocity in time using AB scheme.
1458 subroutine update_ale_mesh(c_Xh, wm_x, wm_y, wm_z, wm_x_lag, wm_y_lag, &
1459 wm_z_lag, time, nadv, scheme_)
1460 type(coef_t), intent(inout) :: c_xh
1461 type(field_t), intent(in) :: wm_x, wm_y, wm_z
1462 type(field_series_t), intent(in) :: wm_x_lag, wm_y_lag, wm_z_lag
1463 type(time_state_t), intent(in) :: time
1464 integer, intent(in) :: nadv
1465 character(len=*), intent(in) :: scheme_
1466 if (neko_bcknd_device .eq. 1) then
1467 call update_ale_mesh_device(c_xh, wm_x, wm_y, wm_z, &
1468 wm_x_lag, wm_y_lag, wm_z_lag, time, nadv, scheme_)
1469 else
1470 call update_ale_mesh_cpu(c_xh, wm_x, wm_y, wm_z, &
1471 wm_x_lag, wm_y_lag, wm_z_lag, time, nadv, scheme_)
1472 end if
1473 end subroutine update_ale_mesh
1474
1475
1476 subroutine ale_manager_free(this)
1477 class(ale_manager_t), intent(inout), target :: this
1478 integer :: i
1479
1480 if (.not. this%active) return
1481
1482 call this%bc_moving%free()
1483 call this%bc_fixed%free()
1484 call this%bc_list%free()
1485
1486 if (allocated(this%base_shapes)) then
1487 do i = 1, size(this%base_shapes)
1488 call this%base_shapes(i)%free()
1489 end do
1490 deallocate(this%base_shapes)
1491 end if
1492
1493 call this%wm_x_lag%free()
1494 call this%wm_y_lag%free()
1495 call this%wm_z_lag%free()
1496 call this%x_ref%free()
1497 call this%y_ref%free()
1498 call this%z_ref%free()
1499
1500 if (allocated(this%ale_pivot)) deallocate(this%ale_pivot)
1501 if (allocated(this%config%bodies)) deallocate(this%config%bodies)
1502 if (allocated(this%body_kin)) deallocate(this%body_kin)
1503 if (associated(this%global_pivot_pos)) deallocate(this%global_pivot_pos)
1504 if (associated(this%global_pivot_vel_lag)) &
1505 deallocate(this%global_pivot_vel_lag)
1506 if (associated(this%global_basis_pos)) deallocate(this%global_basis_pos)
1507 if (associated(this%global_basis_vel_lag)) &
1508 deallocate(this%global_basis_vel_lag)
1509 if (allocated(this%ghost_handles)) deallocate(this%ghost_handles)
1510 if (allocated(this%body_rot_matrices)) deallocate(this%body_rot_matrices)
1511 if (allocated(this%trackers)) deallocate(this%trackers)
1512 if (associated(neko_ale, this)) nullify(neko_ale)
1513
1514 end subroutine ale_manager_free
1515
1516 !> Factory for ALE Preconditioner
1517 subroutine ale_precon_factory(pc, ksp, coef, bclst, pctype, json)
1518 class(pc_t), allocatable, target, intent(inout) :: pc
1519 class(ksp_t), target, intent(inout) :: ksp
1520 type(coef_t), target, intent(in) :: coef
1521 type(bc_list_t), target, intent(inout) :: bclst
1522 character(len=*), intent(in) :: pctype
1523 type(json_file), intent(inout) :: json
1524
1525 call precon_factory(pc, pctype, coef, bclst, json)
1526 call ksp%set_pc(pc)
1527 end subroutine ale_precon_factory
1528
1529 ! Sets the pivot state at restart.
1530 subroutine set_pivot_restart(this, time_restart)
1531 class(ale_manager_t), intent(inout) :: this
1532 real(kind=dp), intent(in) :: time_restart
1533 type(body_kinematics_t) :: kin_restart
1534 integer :: i, idx, handle_1, handle_2, offset_base
1535 type(time_state_t) :: time_state_dummy
1536 time_state_dummy%t = time_restart
1537
1538 !if (.not. allocated(this%global_pivot_pos)) return
1539
1540 do i = 1, this%config%nbodies
1541
1542 call compute_body_kinematics_built_in(kin_restart, &
1543 this%config%bodies(i), time_state_dummy)
1544
1545 ! User Modifier (Superposition or Override)
1546 if (.not. associated(this%user_ale_rigid_kinematics, &
1548 call this%user_ale_rigid_kinematics(this%config%bodies(i)%id, &
1549 time_state_dummy, &
1550 kin_restart%vel_trans, &
1551 kin_restart%vel_ang)
1552 end if
1553
1554 this%ale_pivot(i)%vel = kin_restart%vel_trans
1555
1556 idx = (i - 1) * 3
1557 ! Restore Position
1558 this%ale_pivot(i)%pos(1:3) = this%global_pivot_pos(idx + 1:idx + 3)
1559 this%body_kin(i)%center = this%ale_pivot(i)%pos
1560 this%body_kin(i)%vel_trans = kin_restart%vel_trans
1561 this%body_kin(i)%vel_ang = kin_restart%vel_ang
1562
1563 ! Restore Velocity History
1564 this%ale_pivot(i)%vel_lag(1:3, 1:3) = &
1565 this%global_pivot_vel_lag(idx + 1:idx + 3, :)
1566
1567
1568 offset_base = (i-1)*6
1569 handle_1 = this%ghost_handles(1, i)
1570 handle_2 = this%ghost_handles(2, i)
1571
1572 if ((handle_1 .gt. 0) .and. (handle_1 .le. this%n_trackers)) then
1573 this%trackers(handle_1)%pos = &
1574 this%global_basis_pos(offset_base + 1 : offset_base + 3)
1575
1576 ! Restore velocity history for ghost-x
1577 this%trackers(handle_1)%vel_lag = &
1578 this%global_basis_vel_lag(offset_base + 1 : offset_base + 3, :)
1579 end if
1580
1581 if ((handle_2 .gt. 0) .and. (handle_2 .le. this%n_trackers)) then
1582 this%trackers(handle_2)%pos = &
1583 this%global_basis_pos(offset_base + 4 : offset_base + 6)
1584
1585 ! Restore velocity history for ghost-y
1586 this%trackers(handle_2)%vel_lag = &
1587 this%global_basis_vel_lag(offset_base + 4 : offset_base + 6, :)
1588 end if
1589 end do
1590 end subroutine set_pivot_restart
1591
1592 ! Restores the current coef and related metrics
1593 ! and the pivot states at restart.
1594 subroutine sync_chkp(this, coef, Xh, adv, chkp, gs_Xh)
1595 class(ale_manager_t), intent(inout) :: this
1596 class(advection_t), intent(inout) :: adv
1597 type(coef_t), intent(inout) :: coef
1598 type(space_t), intent(inout) :: Xh
1599 type(chkp_t), intent(in) :: chkp
1600 type(gs_t), intent(inout) :: gs_Xh
1601 integer :: i, j, n
1602
1603 ! Return if ALE is not active.
1604 if (.not. this%active) return
1605
1606 if (allocated(chkp%previous_mesh%elements)) then
1607 call neko_error("ALE restart failed: " // &
1608 "The current mesh has a different number " // &
1609 "of elements than the checkpoint.")
1610 end if
1611
1612 ! Restarting from a different polynomial order
1613 if (chkp%previous_Xh%lx .ne. xh%lx) then
1614 n = coef%dof%size()
1615 associate(wm_x => this%wm_x, wm_y => this%wm_y, wm_z => this%wm_z)
1616 do concurrent(j = 1:n)
1617 ! Mesh Velocity
1618 wm_x%x(j,1,1,1) = wm_x%x(j,1,1,1) * coef%mult(j,1,1,1)
1619 wm_y%x(j,1,1,1) = wm_y%x(j,1,1,1) * coef%mult(j,1,1,1)
1620 wm_z%x(j,1,1,1) = wm_z%x(j,1,1,1) * coef%mult(j,1,1,1)
1621 end do
1622 end associate
1623
1624 do i = 1, this%wm_x_lag%size()
1625 do concurrent(j = 1:n)
1626 this%wm_x_lag%lf(i)%x(j,1,1,1) = &
1627 this%wm_x_lag%lf(i)%x(j,1,1,1) * coef%mult(j,1,1,1)
1628 this%wm_y_lag%lf(i)%x(j,1,1,1) = &
1629 this%wm_y_lag%lf(i)%x(j,1,1,1) * coef%mult(j,1,1,1)
1630 this%wm_z_lag%lf(i)%x(j,1,1,1) = &
1631 this%wm_z_lag%lf(i)%x(j,1,1,1) * coef%mult(j,1,1,1)
1632 end do
1633 end do
1634 end if
1635
1636 if (neko_bcknd_device .eq. 1) then
1637 call this%wm_x%copy_from(host_to_device, sync = .false.)
1638 call this%wm_y%copy_from(host_to_device, sync = .false.)
1639 call this%wm_z%copy_from(host_to_device, sync = .false.)
1640
1641 call this%wm_x_lag%lf(1)%copy_from(host_to_device, sync = .false.)
1642 call this%wm_x_lag%lf(2)%copy_from(host_to_device, sync = .false.)
1643
1644 call this%wm_y_lag%lf(1)%copy_from(host_to_device, sync = .false.)
1645 call this%wm_y_lag%lf(2)%copy_from(host_to_device, sync = .false.)
1646
1647 call this%wm_z_lag%lf(1)%copy_from(host_to_device, sync = .false.)
1648 call this%wm_z_lag%lf(2)%copy_from(host_to_device, sync = .false.)
1649
1650 if (c_associated(coef%dof%x%x_d)) then
1651 call coef%dof%x%copy_from(host_to_device, sync = .false.)
1652 call coef%dof%y%copy_from(host_to_device, sync = .false.)
1653 call coef%dof%z%copy_from(host_to_device, sync = .false.)
1654 end if
1655
1656 if (c_associated(coef%Blag_d)) then
1657 call device_memcpy(coef%Blag, coef%Blag_d, size(coef%Blag), &
1658 host_to_device, sync = .false.)
1659 end if
1660
1661 if (c_associated(coef%Blaglag_d)) then
1662 call device_memcpy(coef%Blaglag, coef%Blaglag_d, &
1663 size(coef%Blaglag), host_to_device, sync = .false.)
1664 end if
1665 call device_sync()
1666 end if
1667
1668 ! Restarting from a different polynomial order
1669 if (chkp%previous_Xh%lx .ne. xh%lx) then
1670 call rotate_cyc(this%wm_x%x, this%wm_y%x, this%wm_z%x, 1, coef)
1671 call gs_xh%op(this%wm_x, gs_op_add)
1672 call gs_xh%op(this%wm_y, gs_op_add)
1673 call gs_xh%op(this%wm_z, gs_op_add)
1674 call rotate_cyc(this%wm_x%x, this%wm_y%x, this%wm_z%x, 0, coef)
1675
1676 do i = 1, this%wm_x_lag%size()
1677 call rotate_cyc(this%wm_x_lag%lf(i)%x, this%wm_y_lag%lf(i)%x, &
1678 this%wm_z_lag%lf(i)%x, 1, coef)
1679 call gs_xh%op(this%wm_x_lag%lf(i), gs_op_add)
1680 call gs_xh%op(this%wm_y_lag%lf(i), gs_op_add)
1681 call gs_xh%op(this%wm_z_lag%lf(i), gs_op_add)
1682 call rotate_cyc(this%wm_x_lag%lf(i)%x, this%wm_y_lag%lf(i)%x, &
1683 this%wm_z_lag%lf(i)%x, 0, coef)
1684 end do
1685 end if
1686
1687
1688 call this%set_pivot_restart(chkp%t)
1689 call coef%recompute_metrics()
1690
1691 ! If polynomial order changes during restart, we use current's mesh
1692 ! mass matrix for Blag and Blaglag. This will introduce some error,
1693 ! but maybe better than
1694 ! not restarting at all. Otherwise we need to save lagged mesh coordinates
1695 ! as well in order to be more accurate.
1696 if (chkp%previous_Xh%lx .ne. xh%lx) then
1697 coef%Blag = coef%B
1698 coef%Blaglag = coef%B
1699 if (neko_bcknd_device .eq. 1) then
1700 if (c_associated(coef%Blag_d)) then
1701 call device_memcpy(coef%Blag, coef%Blag_d, n, &
1702 host_to_device, sync = .false.)
1703 end if
1704 if (c_associated(coef%Blaglag_d)) then
1705 call device_memcpy(coef%Blaglag, coef%Blaglag_d, n, &
1706 host_to_device, sync = .false.)
1707 end if
1708 call device_sync()
1709 end if
1710 end if
1711
1712 call adv%recompute_metrics(coef, .true.)
1713 end subroutine sync_chkp
1714
1715 subroutine set_pivot_basis_for_checkpoint(this, body_idx)
1716 class(ale_manager_t), intent(inout) :: this
1717 integer, intent(in) :: body_idx
1718 integer :: idx, offset_base, h1, h2
1719
1720 if (.not. this%active) return
1721 if (.not. this%has_moving_boundary) return
1722
1723 idx = (body_idx - 1) * 3
1724 this%global_pivot_pos(idx + 1:idx + 3) = this%ale_pivot(body_idx)%pos(1:3)
1725 this%global_pivot_vel_lag(idx + 1:idx + 3, :) = &
1726 this%ale_pivot(body_idx)%vel_lag(1:3, 1:3)
1727
1728 h1 = this%ghost_handles(1, body_idx)
1729 h2 = this%ghost_handles(2, body_idx)
1730
1731 offset_base = (body_idx-1)*6
1732
1733 ! Save Positions
1734 this%global_basis_pos(offset_base + 1 : offset_base + 3) = &
1735 this%get_tracker_pos(h1)
1736 this%global_basis_pos(offset_base + 4 : offset_base + 6) = &
1737 this%get_tracker_pos(h2)
1738
1739 ! Ghost-x history
1740 this%global_basis_vel_lag(offset_base + 1 : offset_base + 3, :) = &
1741 this%trackers(h1)%vel_lag
1742
1743 ! Ghost-y history
1744 this%global_basis_vel_lag(offset_base + 4 : offset_base + 6, :) = &
1745 this%trackers(h2)%vel_lag
1746 end subroutine set_pivot_basis_for_checkpoint
1747
1748 ! Append val to arr if not already present.
1749 subroutine append_unique_int(arr, n, val)
1750 integer, allocatable, intent(inout) :: arr(:)
1751 integer, intent(inout) :: n
1752 integer, intent(in) :: val
1753 integer, allocatable :: tmp(:)
1754 integer :: k
1755
1756 do k = 1, n
1757 if (arr(k) .eq. val) return
1758 end do
1759
1760 allocate(tmp(n + 1))
1761 if (n .gt. 0) tmp(1:n) = arr(1:n)
1762 tmp(n + 1) = val
1763
1764 if (allocated(arr)) deallocate(arr)
1765 call move_alloc(tmp, arr)
1766
1767 n = n + 1
1768 end subroutine append_unique_int
1769
1770 !> Performs a preview of the mesh motion to verify quality/topology
1771 !! @param coef The coefficients.
1772 !! @param json The fluid parameters, i.e. `case.fluid`.
1773 !! @param numerics_params The numerical parameters, i.e. `case.numerics`.
1774 subroutine mesh_preview(this, coef, json, numerics_params)
1775 class(ale_manager_t), intent(inout) :: this
1776 type(coef_t), intent(inout) :: coef
1777 type(json_file), intent(inout) :: json
1778 type(json_file), intent(inout) :: numerics_params
1779 type(fld_file_output_t) :: fout
1780 type(field_t) :: dummy_field
1781 type(time_state_t) :: t_state
1782 type(file_t) :: out_file
1783 real(kind=rp) :: t_start
1784 real(kind=rp) :: t_end
1785 real(kind=rp) :: dt
1786 real(kind=rp) :: min_jac
1787 integer :: output_freq
1788 integer :: step, n_steps
1789 integer :: nadv, nadv_sim
1790 integer :: n
1791 logical :: mesh_preview_active
1792 character(len=128) :: log_buf
1793
1794 mesh_preview_active = .false.
1795
1796 if (json%valid_path('ale.mesh_preview.enabled')) then
1797 call json%get('ale.mesh_preview.enabled', &
1798 mesh_preview_active)
1799 end if
1800
1801 if (.not. mesh_preview_active) return
1802
1803 call json_get_or_default(json, 'ale.mesh_preview.start_time', &
1804 t_start, 0.0_rp)
1805 call json_get(json, 'ale.mesh_preview.end_time', &
1806 t_end)
1807 call json_get(json, 'ale.mesh_preview.dt', &
1808 dt)
1809 call json_get(json, &
1810 'ale.mesh_preview.output_freq', &
1811 output_freq)
1812
1813 call neko_log%section("ALE Mesh Preview")
1814 call neko_log%message("Executing mesh motion preview...")
1815
1816 n_steps = int((t_end - t_start) / dt)
1817 call json_get(numerics_params, 'time_order', nadv_sim)
1818
1819 write(log_buf, '(A, ES23.15)') ' Start Time : ', t_start
1820 call neko_log%message(log_buf)
1821 write(log_buf, '(A, ES23.15)') ' End Time : ', t_end
1822 call neko_log%message(log_buf)
1823 write(log_buf, '(A, ES23.15)') ' dt : ', dt
1824 call neko_log%message(log_buf)
1825 write(log_buf, '(A, I0)') ' Num Steps : ', n_steps
1826 call neko_log%message(log_buf)
1827 write(log_buf, '(A, I0)') ' Output Freq: ', output_freq
1828 call neko_log%message(log_buf)
1829 call neko_log%message('')
1830
1831 ! Setup dummy field for output
1832 call dummy_field%init(coef%dof, "mesh_preview")
1833 call field_rzero(dummy_field)
1834
1835 call fout%init(rp, "mesh_preview", 1)
1836 call fout%fields%assign_to_field(1, dummy_field)
1837 select type (ft => fout%file_%file_type)
1838 type is (fld_file_t)
1839 ft%write_mesh = .true.
1840 ft%skip_pressure = .false.
1841 end select
1842
1843
1844 ! Time Loop Setup
1845 step = 0
1846 nadv = 1
1847 t_state%t = t_start
1848 t_state%dt = dt
1849 t_state%tstep = 0
1850 t_state%dtlag = dt
1851 n = coef%dof%size()
1852
1853 if (neko_bcknd_device .eq. 1) then
1854 min_jac = device_glmin(coef%jac_d, n)
1855 else
1856 min_jac = glmin(coef%jac, n)
1857 end if
1858
1859 call sync_mesh_preview_step(coef, dummy_field)
1860 call fout%sample(t_state%t)
1861
1862 write(log_buf, '(A,I0, A,ES23.15, A,ES18.11)') &
1863 "Initial Mesh and Mass matrix saved! Step: ", step, " | Time:", &
1864 t_state%t, " | Min Jac: ", min_jac
1865
1866 call neko_log%message(trim(log_buf))
1867 call this%update_mesh_velocity(coef, t_state)
1868
1869 do step = 1, n_steps
1870 t_state%tstep = step
1871 t_state%t = t_start + (step * dt)
1872 nadv = min(step, nadv_sim)
1873
1874 call this%advance_mesh(coef, t_state, nadv)
1875 call coef%recompute_metrics()
1876
1877
1878 if (neko_bcknd_device .eq. 1) then
1879 min_jac = device_glmin(coef%jac_d, n)
1880 else
1881 min_jac = glmin(coef%jac, n)
1882 end if
1883
1884 if (min_jac .le. 0.0_rp) then
1885 write(log_buf, '(A, ES18.11, A, ES23.15)') &
1886 "Negative Jacobian detected (", min_jac, ") at t = ", &
1887 t_state%t
1888 call neko_log%message(log_buf)
1889
1890 call sync_mesh_preview_step(coef, dummy_field)
1891 call fout%sample(t_state%t)
1892
1893 write(log_buf, '(A,I0, A,ES23.15, A,ES18.11)') &
1894 "Mesh and Mass matrix saved! Step: ", step, " | Time:", &
1895 t_state%t, " | Min Jac:", min_jac
1896 call neko_log%message(trim(log_buf))
1897
1898 call neko_error("ALE Mesh Preview Aborted: Negative Jacobian found.")
1899 end if
1900
1901 if (mod(step, output_freq) .eq. 0) then
1902
1903 call sync_mesh_preview_step(coef, dummy_field)
1904 call fout%sample(t_state%t)
1905
1906 write(log_buf, '(A,I0, A,ES23.15, A,ES18.11)') &
1907 "Mesh and Mass matrix saved! Step: ", step, " | Time:", &
1908 t_state%t, " | Min Jac:", min_jac
1909 call neko_log%message(trim(log_buf))
1910
1911 end if
1912
1913 call this%update_mesh_velocity(coef, t_state)
1914
1915 end do
1916
1917 call dummy_field%free()
1918 call fout%free()
1919 call neko_log%end_section()
1920 call neko_log%message("Mesh preview complete.")
1921 call neko_error("ALE Mesh Preview Finished Successfully.")
1922
1923 end subroutine mesh_preview
1924
1925 subroutine sync_mesh_preview_step(coef, dummy_field)
1926 type(fld_file_output_t) :: fout
1927 type(coef_t), intent(inout) :: coef
1928 type(field_t), intent(inout) :: dummy_field
1929 integer :: n
1930
1931 n = coef%dof%size()
1932 if (neko_bcknd_device .eq. 1) then
1933 call device_copy(dummy_field%x_d, coef%B_d, n)
1934 else
1935 call copy(dummy_field%x, coef%B, n)
1936 end if
1937
1938 if (neko_bcknd_device .eq. 1) then
1939 associate(mesh => coef%dof)
1940 call device_memcpy(mesh%x%x, mesh%x%x_d, mesh%size(), &
1941 device_to_host, sync = .false.)
1942 call device_memcpy(mesh%y%x, mesh%y%x_d, mesh%size(), &
1943 device_to_host, sync = .false.)
1944 call device_memcpy(mesh%z%x, mesh%z%x_d, mesh%size(), &
1945 device_to_host, sync = .false.)
1946 end associate
1947 end if
1948
1949 end subroutine sync_mesh_preview_step
1950
1951 ! Asign a tracker point to a body. The tracker moves with body's
1952 ! rigid motion.
1953 function request_tracker(this, initial_pos, body_id) result(handle)
1954 class(ale_manager_t), intent(inout) :: this
1955 real(kind=rp), intent(in) :: initial_pos(3)
1956 integer, intent(in) :: body_id
1957 integer :: handle
1958 type(point_tracker_t), allocatable :: tmp(:)
1959
1960 handle = -100
1961 if (.not. this%active) return
1962 if (.not. this%has_moving_boundary) return
1963
1964 if (.not. allocated(this%trackers)) then
1965 allocate(this%trackers(30))
1966 this%n_trackers = 0
1967 elseif (this%n_trackers .ge. size(this%trackers)) then
1968 allocate(tmp(size(this%trackers) + 30))
1969 tmp(1:size(this%trackers)) = this%trackers
1970 deallocate(this%trackers)
1971 call move_alloc(tmp, this%trackers)
1972 end if
1973 this%n_trackers = this%n_trackers + 1
1974 handle = this%n_trackers
1975
1976 this%trackers(handle)%pos = initial_pos
1977 this%trackers(handle)%body_id = body_id
1978 this%trackers(handle)%vel_lag = this%ale_pivot(body_id)%vel_lag
1979 end function request_tracker
1980
1981 function get_tracker_pos(this, handle) result(pos)
1982 class(ale_manager_t), intent(in) :: this
1983 integer, intent(in) :: handle
1984 real(kind=rp) :: pos(3)
1985
1986 if (handle .gt. 0 .and. handle .le. this%n_trackers) then
1987 pos = this%trackers(handle)%pos
1988 else
1989 pos = 0.0_rp
1990 end if
1991 end function get_tracker_pos
1992
1993
1994 !> Computes Rotation Matrix
1995 subroutine compute_rotation_matrix(this, body_idx, time)
1996 class(ale_manager_t), intent(inout) :: this
1997 integer, intent(in) :: body_idx
1998 type(time_state_t), intent(in) :: time
1999 integer :: h_x, h_y
2000 real(kind=rp) :: p(3), gx(3), gy(3)
2001 real(kind=rp) :: u(3), v(3), w(3), v_temp(3)
2002
2003 if (.not. this%active) return
2004 if (.not. this%has_moving_boundary) return
2005
2006 ! Get Points
2007 h_x = this%ghost_handles(1, body_idx)
2008 h_y = this%ghost_handles(2, body_idx)
2009
2010 p = this%ale_pivot(body_idx)%pos
2011 gx = this%get_tracker_pos(h_x)
2012 gy = this%get_tracker_pos(h_y)
2013
2014 ! Construct u (New X-axis)
2015 u = gx - p
2016 u = u / sqrt(sum(u**2))
2017
2018 ! Construct w via cross product (Z-axis)
2019 v_temp = gy - p
2020 w(1) = u(2)*v_temp(3) - u(3)*v_temp(2)
2021 w(2) = u(3)*v_temp(1) - u(1)*v_temp(3)
2022 w(3) = u(1)*v_temp(2) - u(2)*v_temp(1)
2023 w = w / sqrt(sum(w**2))
2024
2025 ! Construct v via orthogonalization (Y-axis)
2026 v(1) = w(2)*u(3) - w(3)*u(2)
2027 v(2) = w(3)*u(1) - w(1)*u(3)
2028 v(3) = w(1)*u(2) - w(2)*u(1)
2029
2030 this%body_rot_matrices(:, 1, body_idx) = u
2031 this%body_rot_matrices(:, 2, body_idx) = v
2032 this%body_rot_matrices(:, 3, body_idx) = w
2033
2034 end subroutine compute_rotation_matrix
2035
2036
2037 !> Logs rotation angles for all or selected bodies.
2038 !> can be called in user%compute.
2039 !> eg: call neko_ale%log_rot_angles(time, body_idxs)
2040 subroutine log_rot_angles(this, time, body_idxs)
2041 class(ale_manager_t), intent(in) :: this
2042 type(time_state_t), intent(in) :: time
2043 integer, optional, intent(in) :: body_idxs(:)
2044
2045 integer :: i, idx, n_log
2046 real(kind=rp) :: roll_deg, pitch_deg, yaw_deg
2047 real(kind=rp) :: r(3,3)
2048 character(len=256) :: log_buf
2049 real(kind=rp), parameter :: rad_to_deg = 180.0_rp / pi
2050
2051 if (.not. this%active) return
2052 if (.not. this%has_moving_boundary) return
2053
2054 if (present(body_idxs)) then
2055 n_log = size(body_idxs)
2056 else
2057 n_log = this%config%nbodies
2058 end if
2059
2060 call neko_log%message(" ")
2061 call neko_log%message("---------Rotation log---------")
2062 call neko_log%message("variable, time step, time, body, " // &
2063 "x_val, y_val, z_val")
2064
2065 ! If body_idxs is provided, only log those. Otherwise, log all.
2066 do i = 1, n_log
2067
2068 if (present(body_idxs)) then
2069 idx = body_idxs(i)
2070 else
2071 idx = i
2072 end if
2073
2074 r = this%body_rot_matrices(:, :, idx)
2075
2076 ! Angles
2077 yaw_deg = atan2(r(2,1), r(1,1)) * rad_to_deg
2078 pitch_deg = atan2(-r(3,1), sqrt(r(3,2)**2 + r(3,3)**2)) * rad_to_deg
2079 roll_deg = atan2(r(3,2), r(3,3)) * rad_to_deg
2080
2081 ! Log Rotation Angles (Roll, Pitch, Yaw) -> (X, Y, Z)
2082 write(log_buf, '(A, I0, A, ES13.6, A, A, A, 3(ES17.10, :, 2X))') &
2083 "Total_Rot_deg ", time%tstep, " ", time%t, " ", &
2084 trim(this%config%bodies(idx)%name), " ", &
2085 roll_deg, pitch_deg, yaw_deg
2086 call neko_log%message(trim(log_buf))
2087
2088 end do
2089
2090 end subroutine log_rot_angles
2091
2092 !> Logs pivot positions for all or selected bodies.
2093 !> can be called in user%compute.
2094 !> eg: call neko_ale%log_pivot(time, body_idxs)
2095 subroutine log_pivot(this, time, body_idxs)
2096 class(ale_manager_t), intent(in) :: this
2097 type(time_state_t), intent(in) :: time
2098 integer, optional, intent(in) :: body_idxs(:)
2099 integer :: i, idx, n_log
2100 real(kind=rp) :: pivot_pos(3), pivot_vel(3)
2101 character(len=256) :: log_buf
2102
2103 if (.not. this%active) return
2104 if (.not. this%has_moving_boundary) return
2105
2106 if (present(body_idxs)) then
2107 n_log = size(body_idxs)
2108 else
2109 n_log = this%config%nbodies
2110 end if
2111
2112 call neko_log%message(" ")
2113 call neko_log%message("----------Pivot Log-----------")
2114 call neko_log%message("variable, time step, time, body, " // &
2115 "x_val, y_val, z_val")
2116
2117 ! If body_idxs is provided, only log those. Otherwise, log all.
2118 do i = 1, n_log
2119
2120 if (present(body_idxs)) then
2121 idx = body_idxs(i)
2122 else
2123 idx = i
2124 end if
2125
2126 pivot_pos = this%ale_pivot(idx)%pos
2127 pivot_vel = this%ale_pivot(idx)%vel
2128
2129 ! Pivot Position
2130 write(log_buf, '(A, I0, A, ES13.6, A, A, A, 3(ES17.10, :, 2X))') &
2131 "Total_Pivot_pos ", time%tstep, " ", time%t, " ", &
2132 trim(this%config%bodies(idx)%name), " ", &
2133 this%ale_pivot(idx)%pos
2134 call neko_log%message(trim(log_buf))
2135
2136 ! Pivot Velocity
2137 write(log_buf, '(A, I0, A, ES13.6, A, A, A, 3(ES17.10, :, 2X))') &
2138 "Total_Pivot_vel ", time%tstep, " ", time%t, " ", &
2139 trim(this%config%bodies(idx)%name), " ", &
2140 this%ale_pivot(idx)%vel
2141 call neko_log%message(trim(log_buf))
2142 end do
2143
2144 end subroutine log_pivot
2145
2146 subroutine ghost_tracker_coord_step(this, kin_object, time_s, nadv, body_idx)
2147 class(ale_manager_t), intent(inout) :: this
2148 type(body_kinematics_t), intent(in) :: kin_object
2149 type(time_state_t), intent(in) :: time_s
2150 integer, intent(in) :: nadv
2151 integer, intent(in) :: body_idx
2152 integer :: t
2153 real(kind=rp) :: p_vel(3), rel_pos(3), v_tan(3)
2154
2155 if (.not. this%active) return
2156 if (.not. this%has_moving_boundary) return
2157
2158 if (allocated(this%trackers)) then
2159 do t = 1, this%n_trackers
2160 if (this%trackers(t)%body_id .eq. &
2161 this%config%bodies(body_idx)%id) then
2162 if (t .eq. this%ghost_handles(1, body_idx) .or. &
2163 t .eq. this%ghost_handles(2, body_idx)) then
2164
2165 ! Calculate the Arm vector (r) at current step
2166 rel_pos = this%trackers(t)%pos - kin_object%center
2167
2168 ! Calculate tangential velocity (Omega \cross r)
2169 v_tan(1) = kin_object%vel_ang(2) * rel_pos(3) - &
2170 kin_object%vel_ang(3) * rel_pos(2)
2171 v_tan(2) = kin_object%vel_ang(3) * rel_pos(1) - &
2172 kin_object%vel_ang(1) * rel_pos(3)
2173 v_tan(3) = kin_object%vel_ang(1) * rel_pos(2) - &
2174 kin_object%vel_ang(2) * rel_pos(1)
2175
2176 ! Total velocity
2177 p_vel = kin_object%vel_trans + v_tan
2178
2179 if (time_s%tstep .gt. 0) then
2180 call ab_integrate_point_pos(this%trackers(t)%pos, &
2181 this%trackers(t)%vel_lag, p_vel, time_s, nadv)
2182 end if
2183
2184 end if
2185
2186 end if
2187 end do
2188
2189 end if
2190 end subroutine ghost_tracker_coord_step
2191
2192 subroutine get_ale_solver_params_json(this, json, ksp_solver, precon_type, &
2193 precon_params, abstol, import_base_shapes, solver_params)
2194 class(ale_manager_t), intent(inout) :: this
2195 type(json_file), intent(inout) :: json
2196 character(len=:), allocatable, intent(inout) :: ksp_solver
2197 character(len=:), allocatable, intent(inout) :: precon_type
2198 type(json_file), intent(inout) :: precon_params
2199 real(kind=rp), intent(out) :: abstol
2200 logical, intent(out) :: import_base_shapes
2201 type(json_file), intent(inout) :: solver_params
2202 logical :: tmp_logical
2203 character(len=:), allocatable :: tmp_str
2204
2205 if (allocated(ksp_solver)) deallocate(ksp_solver)
2206 if (allocated(precon_type)) deallocate(precon_type)
2207
2208 call json_get_or_default(json, &
2209 'ale.solver.import_base_shape', &
2210 import_base_shapes, .false.)
2211
2212 call json_get_or_default(json, 'ale.solver.type', &
2213 ksp_solver, 'cg')
2214
2215 call json_get_or_default(json, &
2216 'ale.solver.preconditioner.type', precon_type, 'jacobi')
2217
2218 if (json%valid_path('ale.solver.preconditioner')) then
2219 call json_get(json, 'ale.solver.preconditioner', &
2220 precon_params)
2221 end if
2222
2223 call json_get_or_default(json, &
2224 'ale.solver.absolute_tolerance', abstol, 1.0e-10_rp)
2225
2226 call json_get(json, 'ale.solver', solver_params)
2227
2228 if (json%valid_path('ale.solver.output_base_shape')) then
2229 call json%get('ale.solver.output_base_shape', tmp_logical)
2230 this%config%if_output_phi = tmp_logical
2231 end if
2232 if (json%valid_path('ale.solver.output_stiffness')) then
2233 call json%get('ale.solver.output_stiffness', tmp_logical)
2234 this%config%if_output_stiffness = tmp_logical
2235 end if
2236
2237 ! Mesh Stiffness
2238 if (json%valid_path('ale.solver.mesh_stiffness.type')) then
2239 call json%get('ale.solver.mesh_stiffness.type', tmp_str)
2240 this%config%stiffness_type = tmp_str
2241 if (.not. (trim(tmp_str) .eq. 'built-in')) then
2242 call neko_error("ALE: stiffness_type must be 'built-in'")
2243 end if
2244 end if
2245 end subroutine get_ale_solver_params_json
2246
2247 ! Register ALE fields for checkpointing.
2248 !! @param coef Coefficients containing the mesh-dependent arrays.
2249 !! @param checkpoint Checkpoint in which to register the ALE payload.
2250 subroutine register_checkpoint_fields(this, coef, checkpoint)
2251 class(ale_manager_t), intent(inout), target :: this
2252 type(coef_t), target, intent(inout) :: coef
2253 type(chkp_t), intent(inout) :: checkpoint
2254 type(checkpoint_payload_t), pointer :: payload
2255
2256 if (.not. this%active) return
2257
2258 payload => checkpoint%add_payload("ale")
2259 call payload%add_field(this%wm_x)
2260 call payload%add_field(this%wm_y)
2261 call payload%add_field(this%wm_z)
2262 call payload%add_series(this%wm_x_lag)
2263 call payload%add_series(this%wm_y_lag)
2264 call payload%add_series(this%wm_z_lag)
2265 call payload%add_mesh_array("mesh_x", coef%dof%x%x, coef%msh, coef%Xh, &
2266 coef%dof%x%x_d)
2267 call payload%add_mesh_array("mesh_y", coef%dof%y%x, coef%msh, coef%Xh, &
2268 coef%dof%y%x_d)
2269 call payload%add_mesh_array("mesh_z", coef%dof%z%x, coef%msh, coef%Xh, &
2270 coef%dof%z%x_d)
2271 call payload%add_mesh_array("B_lag", coef%Blag, coef%msh, coef%Xh, &
2272 coef%Blag_d)
2273 call payload%add_mesh_array("B_laglag", coef%Blaglag, coef%msh, &
2274 coef%Xh, coef%Blaglag_d)
2275 call payload%add_array("pivot_position", this%global_pivot_pos, &
2276 replicated = .true.)
2277 call payload%add_array("pivot_velocity_lag", &
2278 this%global_pivot_vel_lag, replicated = .true.)
2279 call payload%add_array("basis_position", this%global_basis_pos, &
2280 replicated = .true.)
2281 call payload%add_array("basis_velocity_lag", &
2282 this%global_basis_vel_lag, replicated = .true.)
2283
2284 end subroutine register_checkpoint_fields
2285end module ale_manager
Copy data between host and device (or device and device).
Definition device.F90:72
Synchronize a device or stream.
Definition device.F90:119
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
Apply cyclic boundary condition to a vector field.
Abstract interface for user defined ALE base shapes.
Abstract interface for user defined ALE mesh velocity.
Abstract interface for user defined ALE rigid body kinematics.
Subroutines to add advection terms to the RHS of a transport equation.
Definition advection.f90:34
ALE Manager: Handles Mesh Motion.
type(ale_manager_t), pointer, public neko_ale
subroutine ale_manager_free(this)
subroutine, public log_pivot(this, time, body_idxs)
Logs pivot positions for all or selected bodies. can be called in usercompute. eg: call neko_alelog_p...
real(kind=rp) function, dimension(3) get_tracker_pos(this, handle)
subroutine set_pivot_basis_for_checkpoint(this, body_idx)
subroutine set_initial_mesh_velocity(this, coef)
Set the mesh velocity at t = 0. Not called on a restart, where the mesh velocity is read from the che...
subroutine solve_base_mesh_displacement(this, coef, json, import_base_shapes, solver_params, precon_type, precon_params)
Solves the Laplace equation to determine the base shape (phi) for each body. It finds a smooth blendi...
subroutine compute_rotation_matrix(this, body_idx, time)
Computes Rotation Matrix.
subroutine ale_precon_factory(pc, ksp, coef, bclst, pctype, json)
Factory for ALE Preconditioner.
subroutine get_ale_solver_params_json(this, json, ksp_solver, precon_type, precon_params, abstol, import_base_shapes, solver_params)
subroutine, public update_ale_mesh(c_xh, wm_x, wm_y, wm_z, wm_x_lag, wm_y_lag, wm_z_lag, time, nadv, scheme_)
subroutine ale_manager_init(this, coef, json, numerics_params, user, chkp)
Initialize ALE Manager Sets up solver, registers fields, solves for base shape, etc.
subroutine, public add_kinematics_to_mesh_velocity(wx, wy, wz, x_ref, y_ref, z_ref, phi, coef, kinematics, rot_mat, initial_pivot_loc)
subroutine mesh_preview(this, coef, json, numerics_params)
Performs a preview of the mesh motion to verify quality/topology.
subroutine update_mesh_velocity(this, coef, time_s)
Updates the mesh velocity field based on current time and kinematics Sums contributions from all bodi...
subroutine set_pivot_restart(this, time_restart)
subroutine, public compute_stiffness_ale(coef, params)
subroutine sync_mesh_preview_step(coef, dummy_field)
subroutine append_unique_int(arr, n, val)
integer function request_tracker(this, initial_pos, body_id)
subroutine, public log_rot_angles(this, time, body_idxs)
Logs rotation angles for all or selected bodies. can be called in usercompute. eg: call neko_alelog_r...
subroutine register_checkpoint_fields(this, coef, checkpoint)
subroutine ghost_tracker_coord_step(this, kin_object, time_s, nadv, body_idx)
subroutine advance_mesh(this, coef, time, nadv)
Main routine to advance the mesh in time.
subroutine sync_chkp(this, coef, xh, adv, chkp, gs_xh)
Defines data structures and algorithms for configuring, calculating, and time-integrating the rigid-b...
subroutine, public compute_body_kinematics_built_in(kinematics, body_conf, time)
Compute built-in kinematics for a body. Uses inputs from JSON. CPU-only.
subroutine, public ab_integrate_point_pos(pos, vel_lag, current_vel, time, nadv)
Advance a single point position (x,y,z) from the point's velocity using AB time-integration.
subroutine, public init_pivot_state(pivot, body_conf)
Initialize pivot state.
subroutine, public update_pivot_location(pivot, pivot_loc, pivot_vel, time, nadv, body_conf)
Updates pivot location.
subroutine, public add_kinematics_to_mesh_velocity_cpu(wx, wy, wz, x_ref, y_ref, z_ref, phi, coef, kinematics, rot_mat, inital_pivot_loc)
Adds kinematics to mesh velocity (CPU).
subroutine, public compute_cheap_dist_v2_cpu(dist_field, coef, msh, zone_indices)
Compute cheap_dist field by passing distance information throughout an entire local element before do...
subroutine, public update_ale_mesh_cpu(c_xh, wm_x, wm_y, wm_z, wm_x_lag, wm_y_lag, wm_z_lag, time, nadv, scheme_type)
Updates mesh position by integrating mesh velocity in time using AB (CPU).
subroutine, public add_kinematics_to_mesh_velocity_device(wx, wy, wz, x_ref, y_ref, z_ref, phi, coef, kinematics, rot_mat, inital_pivot_loc)
Add Kinematics to Mesh Velocity.
subroutine, public compute_cheap_dist_device(dist_field, coef, msh, zone_indices, copy_to_host)
Cheap dist device implementation.
subroutine, public update_ale_mesh_device(c_xh, wm_x, wm_y, wm_z, wm_x_lag, wm_y_lag, wm_z_lag, time, nadv, scheme_type)
Update ALE Mesh.
Defines a Matrix-vector product.
Definition ax.f90:34
Defines a list of bc_t.
Definition bc_list.f90:34
Format-independent checkpoint payloads.
Defines format-independent checkpoint registration and restart state.
Coefficients.
Definition coef.f90:34
Definition comm.F90:1
type(mpi_comm), public neko_comm
MPI communicator.
Definition comm.F90:46
subroutine, public device_copy(a_d, b_d, n, strm)
Copy a vector .
real(kind=rp) function, public device_glmin(a_d, n, strm)
Min of a vector of length n.
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
Defines a mapping of the degrees of freedom.
Definition dofmap.f90:35
subroutine, public field_rzero(a, n)
Zero a real vector.
subroutine, public field_add2(a, b, n)
Vector addition .
subroutine, public field_cmult(a, c, n)
Multiplication by constant c .
Contains the field_serties_t type.
Defines a field.
Definition field.f90:34
Module for file I/O operations.
Definition file.f90:34
Implements fld_file_output_t.
NEKTON fld file format.
Definition fld_file.f90:35
Gather-scatter.
Importation of fields from fld files.
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
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
real(kind=rp), parameter, public pi
Definition math.F90:78
subroutine, public copy(a, b, n)
Copy a vector .
Definition math.F90:305
real(kind=rp) function, public glmin(a, n)
Min of a vector of length n.
Definition math.F90:722
Defines a mesh.
Definition mesh.f90:34
Build configurations.
integer, parameter neko_bcknd_hip
integer, parameter neko_bcknd_device
integer, parameter neko_bcknd_cuda
integer, parameter, public dp
Definition num_types.f90:10
integer, parameter, public rp
Global precision used in computations.
Definition num_types.f90:14
Operators.
Definition operators.f90:34
Krylov preconditioner.
Definition precon.f90:34
Profiling interface.
Definition profiler.F90:34
subroutine, public profiler_start_region(name, region_id)
Started a named (name) profiler region.
Definition profiler.F90:79
subroutine, public profiler_end_region(name, region_id)
End the most recently started profiler region.
Definition profiler.F90:116
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
Implements scalar_projector_t.
Defines a function space.
Definition space.f90:34
Module with things related to the simulation time.
Interfaces for user interaction with NEKO.
Definition user_intf.f90:34
subroutine, public dummy_user_ale_mesh_velocity(wm_x, wm_y, wm_z, coef, x_ref, y_ref, z_ref, base_shapes, time)
subroutine, public dummy_user_ale_base_shapes(base_shapes)
subroutine, public dummy_user_ale_rigid_kinematics(body_id, time, vel_trans, vel_ang)
Utilities.
Definition utils.f90:35
Defines a zero-valued Dirichlet boundary condition.
Base abstract type for computing the advection operator.
Definition advection.f90:46
Calculated Kinematics for a body at current time.
State history for time-integration of pivots.
Type for a tracked point linked to a body.
Base type for a matrix-vector product providing .
Definition ax.f90:44
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
Stores a series (sequence) of fields, logically connected to a base field, and arranged according to ...
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
A simple output saving a list of fields to a .fld file.
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
Projector for scalar boundary conditions.
The function space for the SEM solution fields.
Definition space.f90:64
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...
Zero-valued Dirichlet boundary condition. Used for no-slip walls, but also for various auxillary cond...