Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix rotation and MPI for multiple IBs #788

Merged
merged 1 commit into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 29 additions & 8 deletions src/common/m_helper.fpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,10 +315,11 @@
!> This procedure creates a transformation matrix.
!! @param p Parameters for the transformation.
!! @return Transformation matrix.
function f_create_transform_matrix(p) result(out_matrix)
function f_create_transform_matrix(p, center) result(out_matrix)

type(ic_model_parameters), intent(in) :: p
t_mat4x4 :: sc, rz, rx, ry, tr, out_matrix
t_vec3, optional, intent(in) :: center
t_mat4x4 :: sc, rz, rx, ry, tr, t_back, t_to_origin, out_matrix

sc = transpose(reshape([ &
p%scale(1), 0._wp, 0._wp, 0._wp, &
Expand Down Expand Up @@ -350,7 +351,25 @@
0._wp, 0._wp, 1._wp, p%translate(3), &
0._wp, 0._wp, 0._wp, 1._wp], shape(tr)))

out_matrix = matmul(tr, matmul(ry, matmul(rx, matmul(rz, sc))))
if (present(center)) then
! Translation matrix to move center to the origin
t_to_origin = transpose(reshape([ &
1._wp, 0._wp, 0._wp, -center(1), &
0._wp, 1._wp, 0._wp, -center(2), &
0._wp, 0._wp, 1._wp, -center(3), &
0._wp, 0._wp, 0._wp, 1._wp], shape(tr)))

Check warning on line 360 in src/common/m_helper.fpp

View check run for this annotation

Codecov / codecov/patch

src/common/m_helper.fpp#L357-L360

Added lines #L357 - L360 were not covered by tests

! Translation matrix to move center back to original position
t_back = transpose(reshape([ &
1._wp, 0._wp, 0._wp, center(1), &
0._wp, 1._wp, 0._wp, center(2), &

Check warning on line 365 in src/common/m_helper.fpp

View check run for this annotation

Codecov / codecov/patch

src/common/m_helper.fpp#L365

Added line #L365 was not covered by tests
0._wp, 0._wp, 1._wp, center(3), &
0._wp, 0._wp, 0._wp, 1._wp], shape(tr)))

out_matrix = matmul(tr, matmul(t_back, matmul(ry, matmul(rx, matmul(rz, matmul(sc, t_to_origin))))))
else
out_matrix = matmul(ry, matmul(rx, rz))
end if

Check warning on line 372 in src/common/m_helper.fpp

View check run for this annotation

Codecov / codecov/patch

src/common/m_helper.fpp#L370-L372

Added lines #L370 - L372 were not covered by tests

end function f_create_transform_matrix

Expand All @@ -372,10 +391,10 @@
!> This procedure transforms a triangle by a matrix, one vertex at a time.
!! @param triangle Triangle to transform.
!! @param matrix Transformation matrix.
subroutine s_transform_triangle(triangle, matrix)
subroutine s_transform_triangle(triangle, matrix, matrix_n)

Check warning on line 394 in src/common/m_helper.fpp

View check run for this annotation

Codecov / codecov/patch

src/common/m_helper.fpp#L394

Added line #L394 was not covered by tests

type(t_triangle), intent(inout) :: triangle
t_mat4x4, intent(in) :: matrix
t_mat4x4, intent(in) :: matrix, matrix_n

integer :: i

Expand All @@ -385,20 +404,22 @@
call s_transform_vec(triangle%v(i, :), matrix)
end do

call s_transform_vec(triangle%n(1:3), matrix_n)

end subroutine s_transform_triangle

!> This procedure transforms a model by a matrix, one triangle at a time.
!! @param model Model to transform.
!! @param matrix Transformation matrix.
subroutine s_transform_model(model, matrix)
subroutine s_transform_model(model, matrix, matrix_n)

Check warning on line 414 in src/common/m_helper.fpp

View check run for this annotation

Codecov / codecov/patch

src/common/m_helper.fpp#L414

Added line #L414 was not covered by tests

type(t_model), intent(inout) :: model
t_mat4x4, intent(in) :: matrix
t_mat4x4, intent(in) :: matrix, matrix_n

integer :: i

do i = 1, size(model%trs)
call s_transform_triangle(model%trs(i), matrix)
call s_transform_triangle(model%trs(i), matrix, matrix_n)
end do

end subroutine s_transform_model
Expand Down
18 changes: 13 additions & 5 deletions src/pre_process/m_patches.fpp
Original file line number Diff line number Diff line change
Expand Up @@ -1978,18 +1978,18 @@ contains

integer :: i, j, k !< Generic loop iterators

type(t_bbox) :: bbox
type(t_bbox) :: bbox, bbox_old
type(t_model) :: model
type(ic_model_parameters) :: params

t_vec3 :: point
t_vec3 :: point, model_center

real(wp) :: grid_mm(1:3, 1:2)

integer :: cell_num
integer :: ncells

t_mat4x4 :: transform
t_mat4x4 :: transform, transform_n

if (present(ib) .and. proc_rank == 0) then
print *, " * Reading model: "//trim(patch_ib(patch_id)%model_filepath)
Expand Down Expand Up @@ -2017,9 +2017,17 @@ contains
print *, " * Transforming model."
end if

transform = f_create_transform_matrix(params)
call s_transform_model(model, transform)
! Get the model center before transforming the model
bbox_old = f_create_bbox(model)
model_center(1:3) = (bbox_old%min(1:3) + bbox_old%max(1:3))/2._wp

! Compute the transform matrices for vertices and normals
transform = f_create_transform_matrix(params, model_center)
transform_n = f_create_transform_matrix(params)

call s_transform_model(model, transform, transform_n)

! Recreate the bounding box after transformation
bbox = f_create_bbox(model)

! Show the number of vertices in the original STL model
Expand Down
4 changes: 2 additions & 2 deletions src/simulation/m_start_up.fpp
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ contains

call MPI_FILE_SET_VIEW(ifile, disp, MPI_INTEGER, MPI_IO_IB_DATA%view, &
'native', mpi_info_int, ierr)
call MPI_FILE_READ(ifile, MPI_IO_IB_DATA%var%sf, data_size * num_ibs, &
call MPI_FILE_READ(ifile, MPI_IO_IB_DATA%var%sf, data_size, &
MPI_INTEGER, status, ierr)

else
Expand Down Expand Up @@ -834,7 +834,7 @@ contains

call MPI_FILE_SET_VIEW(ifile, disp, mpi_p, MPI_IO_levelset_DATA%view, &
'native', mpi_info_int, ierr)
call MPI_FILE_READ(ifile, MPI_IO_levelset_DATA%var%sf, data_size, &
call MPI_FILE_READ(ifile, MPI_IO_levelset_DATA%var%sf, data_size * num_ibs, &
mpi_p, status, ierr)

else
Expand Down
Loading