36 use json_module,
only : json_file
64 use mpi_f08,
only : mpi_wtime, mpi_barrier
84 use,
intrinsic :: iso_c_binding, only : c_associated
96 logical :: active = .false.
97 logical :: has_moving_boundary = .false.
129 real(kind=
rp),
pointer :: global_pivot_pos(:) => null()
130 real(kind=
rp),
pointer :: global_pivot_vel_lag(:, :) => null()
133 real(kind=
rp),
pointer :: global_basis_pos(:) => null()
135 real(kind=
rp),
pointer :: global_basis_vel_lag(:, :) => null()
137 integer,
allocatable :: ghost_handles(:,:)
139 real(kind=
rp),
allocatable :: body_rot_matrices(:,:,:)
142 integer :: n_trackers = 0
145 user_ale_mesh_vel => null()
147 user_ale_base_shapes => null()
149 user_ale_rigid_kinematics => null()
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
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
212 if (json%valid_path(
'ale'))
then
213 call json_get(json,
'ale.enabled', this%active)
217 if (.not. this%active)
then
220 else if (this%active)
then
222 call coef%msh%all_deformed()
228 "supported only with HIP or CUDA backend.")
232 call neko_error(
"ALE not currently supported with OIFS.")
237 call neko_log%section(
"ALE Initialization")
241 call neko_log%message(
"Initializing ALE " // &
242 "with device backend (HIP).")
244 call neko_log%message(
"Initializing ALE " // &
245 "with device backend (CUDA).")
247 call neko_log%message(
"Initializing ALE " // &
251 tmp_logical = .false.
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")
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)
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
275 has_user_rigid_kin = .not.
associated(this%user_ale_rigid_kinematics, &
277 has_user_mesh_vel = .not.
associated(this%user_ale_mesh_vel, &
281 call coef%enable_B_history()
282 call json_get(numerics_params,
'time_order', time_order)
286 if (
allocated(moving_zone_ids))
deallocate(moving_zone_ids)
287 allocate(moving_zone_ids(0))
298 precon_params, abstol, import_base_shapes, solver_params)
301 call this%bc_moving%init_from_components(coef)
302 call this%bc_fixed%init_from_components(coef)
304 if (json%valid_path(
'boundary_conditions'))
then
305 call json%info(
'boundary_conditions', n_children = n_bcs)
311 if (
allocated(bc_type))
deallocate(bc_type)
312 call json_get(bc_subdict,
'type', bc_type)
314 if (
allocated(zone_indices))
deallocate(zone_indices)
315 call json_get(bc_subdict,
'zone_indices', zone_indices)
318 if (trim(bc_type) .eq.
'no_slip')
then
323 do j = 1,
size(zone_indices)
327 call this%bc_moving%mark_zone(coef%msh%labeled_zones(&
330 this%has_moving_boundary = .true.
332 do j = 1,
size(zone_indices)
333 call this%bc_fixed%mark_zone(coef%msh%labeled_zones(&
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)
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'")
355 if (
associated(this%user_ale_base_shapes, &
357 call neko_log%message(
'Solver Type : (' // &
358 trim(ksp_solver) //
', ' // trim(precon_type) //
')')
359 write(log_buf,
'(A,ES13.6)')
'Abs tol :', abstol
361 call neko_log%message(
'Mesh Stiffness : ' // &
362 trim(this%config%stiffness_type))
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))
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
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
395 this%config%bodies(i)%id = i
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
401 write(this%config%bodies(i)%name,
'(A,I0)')
'body_', i
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
409 trim(this%config%bodies(i)%name) // &
410 " must have 'zone_indices'")
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, &
419 this%config%bodies(i)%osc_amp = tmp_vec
420 call json_get(body_sub,
'oscillation.frequency', tmp_vec, &
422 this%config%bodies(i)%osc_freq = tmp_vec
426 if (body_sub%valid_path(
'rotation'))
then
428 if (.not. body_sub%valid_path(
'pivot'))
then
429 call neko_error(
"ale.bodies.pivot is missing " // &
430 "from the case file.")
433 call json_get(body_sub,
'rotation.type', tmp_str)
434 this%config%bodies(i)%rotation_type = tmp_str
436 select case (trim(tmp_str))
438 call json_get(body_sub,
'rotation.amplitude_deg', tmp_vec, &
440 this%config%bodies(i)%rot_amp_degree = tmp_vec
442 call json_get(body_sub,
'rotation.frequency', tmp_vec, &
444 this%config%bodies(i)%rot_freq = tmp_vec
448 call json_get(body_sub,
'rotation.ramp_t0', tmp_vec, &
450 this%config%bodies(i)%ramp_t0 = tmp_vec
452 call json_get(body_sub,
'rotation.ramp_omega0', tmp_vec, &
454 this%config%bodies(i)%ramp_omega0 = tmp_vec
460 if (tmp_int .ge. 1 .and. tmp_int .le. 3)
then
461 this%config%bodies(i)%rotation_axis = tmp_int
463 call neko_error(
"ALE: rotation.axis must be (integer) " // &
464 "1 -> x, 2 -> y, or 3 -> z")
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
470 call json_get(body_sub,
'rotation.target_angle_deg', tmp_val)
471 this%config%bodies(i)%target_rot_angle_deg = tmp_val
474 call neko_error(
"ALE: rotation.type must be 'harmonic', " // &
475 "'ramp', or 'smooth_step'")
480 if (body_sub%valid_path(
'pivot'))
then
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
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'.")
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
505 select case (trim(this%config%bodies(i)%stiff_geom%decay_profile))
508 'stiff_geom.cutoff_coef', &
509 this%config%bodies(i)%stiff_geom%cutoff_coef, 9.0_rp)
512 'stiff_geom.cutoff_coef', &
513 this%config%bodies(i)%stiff_geom%cutoff_coef, 3.5_rp)
515 call neko_error(
"ALE: Invalid stiff_geom.decay_profile: " // &
516 trim(this%config%bodies(i)%stiff_geom%decay_profile))
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, &
523 this%config%bodies(i)%stiff_geom%center = tmp_vec
525 call json_get(body_sub,
'stiff_geom.radius', &
526 this%config%bodies(i)%stiff_geom%radius)
528 call json_get(body_sub,
'stiff_geom.stiff_dist', &
529 this%config%bodies(i)%stiff_geom%stiff_dist)
531 call neko_error(
"ALE: stiff_geom.type 'box' not yet" // &
534 call neko_error(
"ALE: Invalid stiff_geom.type: " // &
535 trim(this%config%bodies(i)%stiff_geom%type))
537 elseif (import_base_shapes)
then
541 trim(this%config%bodies(i)%name) // &
542 "' must have 'stiff_geom' definition.")
548 call this%base_shapes(i)%init(coef%dof, &
549 "phi_" // trim(this%config%bodies(i)%name))
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)
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)
563 call neko_log%message(
'Registered Body : ' // &
564 trim(this%config%bodies(i)%name))
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)
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
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
584 write(log_buf,
'(A,ES23.15)')
' Radius :', &
585 this%config%bodies(i)%stiff_geom%radius
588 write(log_buf,
'(A,ES23.15)')
' Stiff Dist:', &
589 this%config%bodies(i)%stiff_geom%stiff_dist
596 has_builtin_osc = any(abs(this%config%bodies(i)%osc_amp) .gt. 0.0_rp)
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
605 write(log_buf,
'(A,3(ES18.11,1X))')
' Freq :', &
606 this%config%bodies(i)%osc_freq
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
614 write(log_buf,
'(A,3(ES18.11,1X))')
' Freq :', &
615 this%config%bodies(i)%osc_freq
619 if (has_user_rigid_kin .or. has_user_mesh_vel)
then
620 call neko_log%message(
' Oscillation : User-defined')
622 call neko_log%message(
' Oscillation : None')
628 has_builtin_rot = (trim(this%config%bodies(i)%rotation_type) &
631 if (trim(this%config%bodies(i)%rotation_type) .eq.
'user')
then
633 call neko_log%message(
' Rotation Type: User-defined')
635 elseif (has_builtin_rot)
then
638 is_rot_active = .false.
639 select case (trim(this%config%bodies(i)%rotation_type))
641 is_rot_active = any(abs(this%config%bodies(i)%rot_amp_degree) &
644 is_rot_active = any(abs(this%config%bodies(i)%ramp_omega0) &
648 (abs(this%config%bodies(i)%target_rot_angle_deg) &
652 if (is_rot_active)
then
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')
660 call neko_log%message(
' Rotation : ' // &
661 'Theta(t) = Amp*sin(2*pi*Freq*t)')
663 write(log_buf,
'(A,3(ES18.11,1X))')
' Amp (deg) :', &
664 this%config%bodies(i)%rot_amp_degree
666 write(log_buf,
'(A,3(ES18.11,1X))')
' Freq :', &
667 this%config%bodies(i)%rot_freq
671 elseif (trim(this%config%bodies(i)%rotation_type) &
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')
677 call neko_log%message(
' Rotation : ' // &
678 'Omega(t) = Omega0*(1 - exp(-4.6*t/t0))')
680 write(log_buf,
'(A,3(ES18.11,1X))')
' Omega0 :', &
681 this%config%bodies(i)%ramp_omega0
683 write(log_buf,
'(A,3(ES18.11,1X))')
' t0 :', &
684 this%config%bodies(i)%ramp_t0
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')
694 call neko_log%message(
' Rotation : ' // &
695 'Smooth Step Control')
697 write(log_buf,
'(A,I10)')
' Rotation Axis :', &
698 this%config%bodies(i)%rotation_axis
700 write(log_buf,
'(A,ES18.11)')
' Target Rot ' // &
702 this%config%bodies(i)%target_rot_angle_deg
704 write(log_buf,
'(A,4(ES18.11,1X))') &
705 ' Control Times [t0, t1, t2, t3] :', &
706 this%config%bodies(i)%step_control_times
710 if (has_user_rigid_kin .or. has_user_mesh_vel)
then
711 call neko_log%message(
' Rotation Type: User-defined')
713 call neko_log%message(
' Rotation Type: None')
721 call neko_log%message(
' Pivot Type : ' // &
722 trim(this%config%bodies(i)%rotation_center_type))
724 write(log_buf,
'(A,3(ES18.11,1X))')
' Init Pivot:', &
725 this%config%bodies(i)%rot_center
731 call neko_error(
"ALE: No 'ale bodies' found in case file!")
734 if (this%config%nbodies .gt. 1 .and. (.not. import_base_shapes))
then
735 call this%phi_total%init(coef%dof,
"phi_total")
740 do i = 1, n_moving_zones
741 z = moving_zone_ids(i)
744 do while ((.not. found_zone) .and. (j .le. this%config%nbodies))
745 if (any(this%config%bodies(j)%zone_indices .eq. z))
then
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."
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)
766 if (n_moving_zones .gt. 0)
then
767 if (any(moving_zone_ids(1:n_moving_zones) .eq. z))
then
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."
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)
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),
"')."
806 call this%solve_base_mesh_displacement(coef, json, import_base_shapes, &
807 solver_params, precon_type, precon_params)
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)
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)
822 call this%mesh_preview(coef, json, numerics_params)
825 call this%register_checkpoint_fields(coef, chkp)
835 import_base_shapes, solver_params, precon_type, precon_params)
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
847 type(
field_t),
pointer :: phi_ptr => null()
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
856 real(kind=
rp),
allocatable :: h1_restore(:, :, :, :)
857 real(kind=
rp),
allocatable :: h2_restore(:, :, :, :)
862 type(json_file) :: body_sub
863 character(len=256) :: phi_fname
864 character(len=:),
allocatable :: tmp_str
867 if (.not. this%active)
return
868 if (.not. this%has_moving_boundary)
return
869 if (this%config%nbodies .eq. 0)
return
871 if (import_base_shapes)
then
873 call neko_log%message(
"Importing ALE base shapes" // &
874 " (skipping Laplace solve)...")
876 do body_idx = 1, this%config%nbodies
881 call json_get(body_sub,
'base_shape_import_file', tmp_str)
884 phi_ptr => this%base_shapes(body_idx)
889 call neko_log%message(
" Loaded: " // &
892 trim(this%config%bodies(body_idx)%name))
899 call neko_log%message(
"Starting base mesh motion solve ...")
902 call ax_helm_allocator(ax, type_name =
"standard")
911 call rhs_field%init(coef%dof)
912 call corr_field%init(coef%dof)
916 if (.not.
associated(this%user_ale_base_shapes, &
918 call neko_log%message(
" Using user-defined base shapes " // &
919 "(skipping Laplace solve)")
922 call this%user_ale_base_shapes(this%base_shapes)
925 if (this%config%nbodies .gt. 1)
then
927 do body_idx = 1, this%config%nbodies
928 call field_add2(this%phi_total, this%base_shapes(body_idx), n)
933 if (this%config%if_output_phi)
then
935 do body_idx = 1, this%config%nbodies
936 call phi_file%init(
'phi_' // &
937 trim(this%config%bodies(body_idx)%name) //
'.fld', &
939 select type (ft => phi_file%file_type)
941 ft%skip_pressure = .false.
943 call phi_file%write(this%base_shapes(body_idx))
946 trim(this%config%bodies(body_idx)%name) //
'.fld saved.')
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)
954 ft%skip_pressure = .false.
956 call phi_file%init(
'phi_total.fld', precision =
rp)
957 call phi_file%write(this%phi_total)
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)
977 do body_idx = 1, this%config%nbodies
979 sample_start_time = mpi_wtime()
980 call neko_log%message(
" Solving laplace for body: " // &
981 trim(this%config%bodies(body_idx)%name))
983 call bc_active_body%init_from_components(coef)
984 call bc_inactive_body%init_from_components(coef)
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))
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))
1002 call bc_active_body%finalize()
1003 call bc_inactive_body%finalize()
1006 call bc_projector%mark(this%bc_fixed)
1007 call bc_projector%mark(bc_active_body)
1008 call bc_projector%mark(bc_inactive_body)
1011 call bc_projector_zeros_only%mark(this%bc_fixed)
1012 call bc_projector_zeros_only%mark(bc_inactive_body)
1015 this%base_shapes(body_idx)%x = 0.0_rp
1016 rhs_field%x = 0.0_rp
1017 corr_field%x = 0.0_rp
1024 m = bc_active_body%msk(0)
1026 k = bc_active_body%msk(i)
1027 this%base_shapes(body_idx)%x(k, 1, 1, 1) = 1.0_rp
1038 call bc_projector_zeros_only%apply(this%base_shapes(body_idx)%x, n)
1042 call ax%compute(rhs_field%x, this%base_shapes(body_idx)%x, &
1043 coef, coef%msh, coef%Xh)
1048 call bc_projector%apply(rhs_field%x, n)
1049 call coef%gs_h%op(rhs_field, gs_op_add)
1054 monitor(1) = ksp%solve(ax, corr_field, &
1055 rhs_field%x, n, coef, bc_projector, coef%gs_h)
1058 call field_add2(this%base_shapes(body_idx), corr_field, n)
1062 if (this%config%nbodies .gt. 1)
then
1063 call field_add2(this%phi_total, this%base_shapes(body_idx), n)
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 ", &
1075 call bc_active_body%free()
1076 call bc_inactive_body%free()
1077 call bc_projector%free()
1078 call bc_projector_zeros_only%free()
1088 if (this%config%if_output_phi)
then
1089 call phi_file%init(
'phi_' // &
1090 trim(this%config%bodies(body_idx)%name) //
'.fld', &
1092 select type (ft => phi_file%file_type)
1094 ft%skip_pressure = .false.
1096 call phi_file%write(this%base_shapes(body_idx))
1097 call phi_file%free()
1099 trim(this%config%bodies(body_idx)%name) //
'.fld saved.')
1103 if (this%config%if_output_phi .and. (this%config%nbodies .gt. 1))
then
1106 call device_memcpy(this%phi_total%x, this%phi_total%x_d, n, &
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)
1114 ft%skip_pressure = .false.
1116 call phi_file%write(this%phi_total)
1117 call phi_file%free()
1121 call rhs_field%free()
1122 call corr_field%free()
1123 if (this%config%nbodies > 1)
then
1124 call this%phi_total%free()
1128 coef%h1(:,:,:,:) = h1_restore(:,:,:,:)
1129 coef%h2(:,:,:,:) = h2_restore(:,:,:,:)
1135 if (
allocated(h1_restore))
deallocate(h1_restore)
1136 if (
allocated(h2_restore))
deallocate(h2_restore)
1137 if (
allocated(ax))
then
1141 if (
allocated(ksp))
then
1145 if (
allocated(pc))
then
1156 type(
coef_t),
intent(in) :: coef
1160 real(kind=
rp) :: rot_mat(3,3)
1161 real(kind=
rp) :: initial_rot_center(3)
1163 if (.not. this%active)
return
1164 if (.not. this%has_moving_boundary)
return
1171 do i = 1, this%config%nbodies
1175 this%config%bodies(i), time_s)
1178 if (.not.
associated(this%user_ale_rigid_kinematics, &
1180 call this%user_ale_rigid_kinematics(this%config%bodies(i)%id, &
1182 current_kin%vel_trans, &
1183 current_kin%vel_ang)
1186 current_kin%center = this%ale_pivot(i)%pos
1187 this%ale_pivot(i)%vel = current_kin%vel_trans
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
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
1200 this%wm_z, this%x_ref, this%y_ref, this%z_ref , &
1201 this%base_shapes(i), coef, current_kin, rot_mat, &
1205 call this%prep_checkpoint(i)
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)
1226 type(
coef_t),
intent(in) :: coef
1232 call this%update_mesh_velocity(coef, t_init)
1239 type(
coef_t),
intent(inout) :: coef
1241 integer,
intent(in) :: nadv
1244 if (.not. this%active)
return
1245 if (.not. this%has_moving_boundary)
return
1247 do i = 1, this%config%nbodies
1252 call this%ghost_tracker_coord_step(this%body_kin(i), time, nadv, i)
1255 this%ale_pivot(i)%pos, &
1256 this%ale_pivot(i)%vel, &
1259 this%config%bodies(i))
1263 call coef%update_B_history()
1267 this%wm_x_lag, this%wm_y_lag, this%wm_z_lag, &
1271 call this%wm_x_lag%update()
1272 call this%wm_y_lag%update()
1273 call this%wm_z_lag%update()
1279 type(
coef_t),
intent(inout) :: coef
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
1295 allocate(cheap_map(params%nbodies))
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
1307 if (n_cheap > 0)
then
1308 allocate(dist_fields(n_cheap))
1310 do b = 1, params%nbodies
1311 map_idx = cheap_map(b)
1312 if (map_idx .gt. 0)
then
1314 call dist_fields(map_idx)%init(coef%dof,
"tmp_cheap_dist")
1317 call neko_log%message(
" Start: cheap dist calculation " // &
1318 "for body '" // trim(params%bodies(b)%name) //
"'")
1321 sample_start_time = mpi_wtime()
1325 coef%msh, params%bodies(b)%zone_indices, &
1326 copy_to_host = .true.)
1329 coef%msh, params%bodies(b)%zone_indices)
1333 sample_end_time = mpi_wtime()
1334 sample_time = sample_end_time - sample_start_time
1336 write(log_buf,
'(A, A, A, ES11.4, A)')
" cheap dist for '", &
1337 trim(params%bodies(b)%name),
"' took ", sample_time,
" (s)"
1345 select case (trim(params%stiffness_type))
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)
1353 max_added_stiff = 0.0_rp
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
1361 decay = params%bodies(b)%stiff_geom%radius
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)
1369 raw_dist = huge(0.0_rp)
1372 select case (trim(params%bodies(b)%stiff_geom%type))
1374 raw_dist = sqrt((x - cx)**2 + (y - cy)**2 + (z - cz)**2)
1378 raw_dist = sqrt((x - cx)**2 + (y - cy)**2)
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)
1391 body_stiff_val = 0.0_rp
1392 select case (trim(params%bodies(b)%stiff_geom%decay_profile))
1395 arg = -(raw_dist**2) / (decay**2)
1396 arg = arg * params%bodies(b)%stiff_geom%cutoff_coef
1397 body_stiff_val = gain * exp(arg)
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))
1406 if (body_stiff_val .gt. max_added_stiff)
then
1407 max_added_stiff = body_stiff_val
1411 coef%h1(i, 1, 1, 1) = 1.0_rp + max_added_stiff
1412 coef%h2(i, 1, 1, 1) = 0.0_rp
1416 call neko_error(
"ALE Manager: Unknown stiffness type")
1426 if (
allocated(dist_fields))
then
1427 do i = 1,
size(dist_fields)
1428 call dist_fields(i)%free()
1430 deallocate(dist_fields)
1432 if (
allocated(cheap_map))
deallocate(cheap_map)
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
1444 real(kind=
rp),
intent(in) :: initial_pivot_loc(3)
1445 real(kind=
rp),
intent(in) :: rot_mat(3,3)
1448 x_ref, y_ref, z_ref, &
1449 phi, coef, kinematics, rot_mat, initial_pivot_loc)
1452 x_ref, y_ref, z_ref, &
1453 phi, coef, kinematics, rot_mat, initial_pivot_loc)
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
1464 integer,
intent(in) :: nadv
1465 character(len=*),
intent(in) :: scheme_
1468 wm_x_lag, wm_y_lag, wm_z_lag, time, nadv, scheme_)
1471 wm_x_lag, wm_y_lag, wm_z_lag, time, nadv, scheme_)
1480 if (.not. this%active)
return
1482 call this%bc_moving%free()
1483 call this%bc_fixed%free()
1484 call this%bc_list%free()
1486 if (
allocated(this%base_shapes))
then
1487 do i = 1,
size(this%base_shapes)
1488 call this%base_shapes(i)%free()
1490 deallocate(this%base_shapes)
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()
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)
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
1525 call precon_factory(pc, pctype, coef, bclst, json)
1532 real(kind=
dp),
intent(in) :: time_restart
1534 integer :: i, idx, handle_1, handle_2, offset_base
1536 time_state_dummy%t = time_restart
1540 do i = 1, this%config%nbodies
1543 this%config%bodies(i), time_state_dummy)
1546 if (.not.
associated(this%user_ale_rigid_kinematics, &
1548 call this%user_ale_rigid_kinematics(this%config%bodies(i)%id, &
1550 kin_restart%vel_trans, &
1551 kin_restart%vel_ang)
1554 this%ale_pivot(i)%vel = kin_restart%vel_trans
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
1564 this%ale_pivot(i)%vel_lag(1:3, 1:3) = &
1565 this%global_pivot_vel_lag(idx + 1:idx + 3, :)
1568 offset_base = (i-1)*6
1569 handle_1 = this%ghost_handles(1, i)
1570 handle_2 = this%ghost_handles(2, i)
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)
1577 this%trackers(handle_1)%vel_lag = &
1578 this%global_basis_vel_lag(offset_base + 1 : offset_base + 3, :)
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)
1586 this%trackers(handle_2)%vel_lag = &
1587 this%global_basis_vel_lag(offset_base + 4 : offset_base + 6, :)
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
1604 if (.not. this%active)
return
1606 if (
allocated(chkp%previous_mesh%elements))
then
1608 "The current mesh has a different number " // &
1609 "of elements than the checkpoint.")
1613 if (chkp%previous_Xh%lx .ne. xh%lx)
then
1615 associate(wm_x => this%wm_x, wm_y => this%wm_y, wm_z => this%wm_z)
1616 do concurrent(j = 1:n)
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)
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)
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.)
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.)
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.)
1650 if (c_associated(coef%dof%x%x_d))
then
1656 if (c_associated(coef%Blag_d))
then
1657 call device_memcpy(coef%Blag, coef%Blag_d,
size(coef%Blag), &
1661 if (c_associated(coef%Blaglag_d))
then
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)
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)
1688 call this%set_pivot_restart(chkp%t)
1689 call coef%recompute_metrics()
1696 if (chkp%previous_Xh%lx .ne. xh%lx)
then
1698 coef%Blaglag = coef%B
1700 if (c_associated(coef%Blag_d))
then
1704 if (c_associated(coef%Blaglag_d))
then
1712 call adv%recompute_metrics(coef, .true.)
1717 integer,
intent(in) :: body_idx
1718 integer :: idx, offset_base, h1, h2
1720 if (.not. this%active)
return
1721 if (.not. this%has_moving_boundary)
return
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)
1728 h1 = this%ghost_handles(1, body_idx)
1729 h2 = this%ghost_handles(2, body_idx)
1731 offset_base = (body_idx-1)*6
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)
1740 this%global_basis_vel_lag(offset_base + 1 : offset_base + 3, :) = &
1741 this%trackers(h1)%vel_lag
1744 this%global_basis_vel_lag(offset_base + 4 : offset_base + 6, :) = &
1745 this%trackers(h2)%vel_lag
1750 integer,
allocatable,
intent(inout) :: arr(:)
1751 integer,
intent(inout) :: n
1752 integer,
intent(in) :: val
1753 integer,
allocatable :: tmp(:)
1757 if (arr(k) .eq. val)
return
1760 allocate(tmp(n + 1))
1761 if (n .gt. 0) tmp(1:n) = arr(1:n)
1764 if (
allocated(arr))
deallocate(arr)
1765 call move_alloc(tmp, arr)
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
1786 real(kind=rp) :: min_jac
1787 integer :: output_freq
1788 integer :: step, n_steps
1789 integer :: nadv, nadv_sim
1791 logical :: mesh_preview_active
1792 character(len=128) :: log_buf
1794 mesh_preview_active = .false.
1796 if (json%valid_path(
'ale.mesh_preview.enabled'))
then
1797 call json%get(
'ale.mesh_preview.enabled', &
1798 mesh_preview_active)
1801 if (.not. mesh_preview_active)
return
1803 call json_get_or_default(json,
'ale.mesh_preview.start_time', &
1805 call json_get(json,
'ale.mesh_preview.end_time', &
1807 call json_get(json,
'ale.mesh_preview.dt', &
1809 call json_get(json, &
1810 'ale.mesh_preview.output_freq', &
1813 call neko_log%section(
"ALE Mesh Preview")
1814 call neko_log%message(
"Executing mesh motion preview...")
1816 n_steps = int((t_end - t_start) / dt)
1817 call json_get(numerics_params,
'time_order', nadv_sim)
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(
'')
1832 call dummy_field%init(coef%dof,
"mesh_preview")
1833 call field_rzero(dummy_field)
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.
1853 if (neko_bcknd_device .eq. 1)
then
1854 min_jac = device_glmin(coef%jac_d, n)
1856 min_jac = glmin(coef%jac, n)
1860 call fout%sample(t_state%t)
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
1866 call neko_log%message(trim(log_buf))
1867 call this%update_mesh_velocity(coef, t_state)
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)
1874 call this%advance_mesh(coef, t_state, nadv)
1875 call coef%recompute_metrics()
1878 if (neko_bcknd_device .eq. 1)
then
1879 min_jac = device_glmin(coef%jac_d, n)
1881 min_jac = glmin(coef%jac, n)
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 = ", &
1888 call neko_log%message(log_buf)
1891 call fout%sample(t_state%t)
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))
1898 call neko_error(
"ALE Mesh Preview Aborted: Negative Jacobian found.")
1901 if (mod(step, output_freq) .eq. 0)
then
1904 call fout%sample(t_state%t)
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))
1913 call this%update_mesh_velocity(coef, t_state)
1917 call dummy_field%free()
1919 call neko_log%end_section()
1920 call neko_log%message(
"Mesh preview complete.")
1921 call neko_error(
"ALE Mesh Preview Finished Successfully.")
1926 type(fld_file_output_t) :: fout
1927 type(coef_t),
intent(inout) :: coef
1928 type(field_t),
intent(inout) :: dummy_field
1932 if (neko_bcknd_device .eq. 1)
then
1933 call device_copy(dummy_field%x_d, coef%B_d, n)
1935 call copy(dummy_field%x, coef%B, n)
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.)
1955 real(kind=rp),
intent(in) :: initial_pos(3)
1956 integer,
intent(in) :: body_id
1958 type(point_tracker_t),
allocatable :: tmp(:)
1961 if (.not. this%active)
return
1962 if (.not. this%has_moving_boundary)
return
1964 if (.not.
allocated(this%trackers))
then
1965 allocate(this%trackers(30))
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)
1973 this%n_trackers = this%n_trackers + 1
1974 handle = this%n_trackers
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
1983 integer,
intent(in) :: handle
1984 real(kind=rp) :: pos(3)
1986 if (handle .gt. 0 .and. handle .le. this%n_trackers)
then
1987 pos = this%trackers(handle)%pos
1997 integer,
intent(in) :: body_idx
1998 type(time_state_t),
intent(in) :: time
2000 real(kind=rp) :: p(3), gx(3), gy(3)
2001 real(kind=rp) :: u(3), v(3), w(3), v_temp(3)
2003 if (.not. this%active)
return
2004 if (.not. this%has_moving_boundary)
return
2007 h_x = this%ghost_handles(1, body_idx)
2008 h_y = this%ghost_handles(2, body_idx)
2010 p = this%ale_pivot(body_idx)%pos
2011 gx = this%get_tracker_pos(h_x)
2012 gy = this%get_tracker_pos(h_y)
2016 u = u / sqrt(sum(u**2))
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))
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)
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
2042 type(time_state_t),
intent(in) :: time
2043 integer,
optional,
intent(in) :: body_idxs(:)
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
2051 if (.not. this%active)
return
2052 if (.not. this%has_moving_boundary)
return
2054 if (
present(body_idxs))
then
2055 n_log =
size(body_idxs)
2057 n_log = this%config%nbodies
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")
2068 if (
present(body_idxs))
then
2074 r = this%body_rot_matrices(:, :, idx)
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
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))
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
2103 if (.not. this%active)
return
2104 if (.not. this%has_moving_boundary)
return
2106 if (
present(body_idxs))
then
2107 n_log =
size(body_idxs)
2109 n_log = this%config%nbodies
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")
2120 if (
present(body_idxs))
then
2126 pivot_pos = this%ale_pivot(idx)%pos
2127 pivot_vel = this%ale_pivot(idx)%vel
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))
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))
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
2153 real(kind=rp) :: p_vel(3), rel_pos(3), v_tan(3)
2155 if (.not. this%active)
return
2156 if (.not. this%has_moving_boundary)
return
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
2166 rel_pos = this%trackers(t)%pos - kin_object%center
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)
2177 p_vel = kin_object%vel_trans + v_tan
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)
2193 precon_params, abstol, import_base_shapes, solver_params)
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
2205 if (
allocated(ksp_solver))
deallocate(ksp_solver)
2206 if (
allocated(precon_type))
deallocate(precon_type)
2208 call json_get_or_default(json, &
2209 'ale.solver.import_base_shape', &
2210 import_base_shapes, .false.)
2212 call json_get_or_default(json,
'ale.solver.type', &
2215 call json_get_or_default(json, &
2216 'ale.solver.preconditioner.type', precon_type,
'jacobi')
2218 if (json%valid_path(
'ale.solver.preconditioner'))
then
2219 call json_get(json,
'ale.solver.preconditioner', &
2223 call json_get_or_default(json, &
2224 'ale.solver.absolute_tolerance', abstol, 1.0e-10_rp)
2226 call json_get(json,
'ale.solver', solver_params)
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
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
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'")
2252 type(coef_t),
target,
intent(inout) :: coef
2253 type(chkp_t),
intent(inout) :: checkpoint
2254 type(checkpoint_payload_t),
pointer :: payload
2256 if (.not. this%active)
return
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, &
2267 call payload%add_mesh_array(
"mesh_y", coef%dof%y%x, coef%msh, coef%Xh, &
2269 call payload%add_mesh_array(
"mesh_z", coef%dof%z%x, coef%msh, coef%Xh, &
2271 call payload%add_mesh_array(
"B_lag", coef%Blag, coef%msh, coef%Xh, &
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.)
Copy data between host and device (or device and device).
Synchronize a device or stream.
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...
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.
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.
Format-independent checkpoint payloads.
Defines format-independent checkpoint registration and restart state.
type(mpi_comm), public neko_comm
MPI communicator.
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.
integer, parameter, public host_to_device
integer, parameter, public device_to_host
Defines a mapping of the degrees of freedom.
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.
Module for file I/O operations.
Implements fld_file_output_t.
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.
type(log_t), public neko_log
Global log stream.
integer, parameter, public log_size
real(kind=rp), parameter, public pi
subroutine, public copy(a, b, n)
Copy a vector .
real(kind=rp) function, public glmin(a, n)
Min of a vector of length n.
integer, parameter neko_bcknd_hip
integer, parameter neko_bcknd_device
integer, parameter neko_bcknd_cuda
integer, parameter, public dp
integer, parameter, public rp
Global precision used in computations.
subroutine, public profiler_start_region(name, region_id)
Started a named (name) profiler region.
subroutine, public profiler_end_region(name, region_id)
End the most recently started profiler region.
Defines a registry for storing solution fields.
type(registry_t), target, public neko_registry
Global field registry.
Implements scalar_projector_t.
Defines a function space.
Module with things related to the simulation time.
Interfaces for user interaction with NEKO.
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)
Defines a zero-valued Dirichlet boundary condition.
Base abstract type for computing the advection operator.
Global ALE Configuration.
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 .
A list of allocatable `bc_t`. Follows the standard interface of lists.
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,...
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...
Interface for NEKTON fld files.
A simple output saving a list of fields to a .fld file.
Type for storing initial and final residuals in a Krylov solver.
Base abstract type for a canonical Krylov method, solving .
Defines a canonical Krylov preconditioner.
Projector for scalar boundary conditions.
The function space for the SEM solution fields.
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...