Skip to content

Commit

Permalink
Add rotation and translations methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
gha3mi committed Apr 15, 2024
1 parent cd8b93a commit d545598
Show file tree
Hide file tree
Showing 5 changed files with 217 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ This roadmap outlines upcoming features and enhancements for ForCAD. Contributio
- [x] Add `put_to_nurbs()` method for volumes.
- [x] Get IGA elements connectivity.
- [x] Add predefined shapes: `Circle`, `Tetragon`, `Hexahedron`.
- [x] Add `rotate_Xc` and `rotate_Xg` methods for curves, surfaces and volumes.
- [x] Add basic unit tests.
- [x] Add simple examples.

Expand Down
66 changes: 65 additions & 1 deletion src/forcad_nurbs_curve.f90
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module forcad_nurbs_curve

use forcad_utils, only: rk, basis_bspline, elemConn_C0, compute_multiplicity, compute_knot_vector, basis_bspline_der,&
insert_knot_A_5_1, findspan, elevate_degree_A_5_9, remove_knots_A_5_8, &
elemConn_Cn, unique
elemConn_Cn, unique, rotation

implicit none

Expand Down Expand Up @@ -65,6 +65,10 @@ module forcad_nurbs_curve
procedure :: basis !!> Compute the basis functions of the NURBS curve
procedure :: is_rational !!> Check if the NURBS curve is rational
procedure :: remove_knots !!> Remove knots from the knot vector
procedure :: rotate_Xc !!> Rotate control points
procedure :: rotate_Xg !!> Rotate geometry points
procedure :: translate_Xc !!> Translate control points
procedure :: translate_Xg !!> Translate geometry points

! Shapes
procedure :: set_circle !!> Set a circle
Expand Down Expand Up @@ -1025,4 +1029,64 @@ pure function cmp_elem(this) result(elemConn)
end function
!===============================================================================


!===============================================================================
!> author: Seyed Ali Ghasemi
!> license: BSD 3-Clause
pure subroutine rotate_Xc(this, alpha, beta, theta)
class(nurbs_curve), intent(inout) :: this
real(rk), intent(in) :: alpha, beta, theta
integer :: i

do i = 1, this%nc
this%Xc(i, :) = matmul(rotation(alpha,beta,theta), this%Xc(i, :))
end do
end subroutine
!===============================================================================


!===============================================================================
!> author: Seyed Ali Ghasemi
!> license: BSD 3-Clause
pure subroutine rotate_Xg(this, alpha, beta, theta)
class(nurbs_curve), intent(inout) :: this
real(rk), intent(in) :: alpha, beta, theta
integer :: i

do i = 1, this%ng
this%Xg(i, :) = matmul(rotation(alpha,beta,theta), this%Xg(i, :))
end do
end subroutine
!===============================================================================


!===============================================================================
!> author: Seyed Ali Ghasemi
!> license: BSD 3-Clause
pure subroutine translate_Xc(this, vec)
class(nurbs_curve), intent(inout) :: this
real(rk), intent(in) :: vec(:)
integer :: i

do i = 1, this%nc
this%Xc(i, :) = this%Xc(i, :) + vec
end do
end subroutine
!===============================================================================


!===============================================================================
!> author: Seyed Ali Ghasemi
!> license: BSD 3-Clause
pure subroutine translate_Xg(this, vec)
class(nurbs_curve), intent(inout) :: this
real(rk), intent(in) :: vec(:)
integer :: i

do i = 1, this%nc
this%Xg(i, :) = this%Xg(i, :) + vec
end do
end subroutine
!===============================================================================

end module forcad_nurbs_curve
66 changes: 65 additions & 1 deletion src/forcad_nurbs_surface.f90
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module forcad_nurbs_surface

use forcad_utils, only: rk, basis_bspline, elemConn_C0, kron, ndgrid, compute_multiplicity, compute_knot_vector, &
basis_bspline_der, insert_knot_A_5_1, findspan, elevate_degree_A_5_9, remove_knots_A_5_8, tetragon_Xc, &
elemConn_Cn, unique
elemConn_Cn, unique, rotation

implicit none

Expand Down Expand Up @@ -69,6 +69,10 @@ module forcad_nurbs_surface
procedure :: elevate_degree !!> Elevate degree
procedure :: is_rational !!> Check if the NURBS surface is rational
procedure :: remove_knots !!> Remove knots from the knot vector
procedure :: rotate_Xc !!> Rotate control points
procedure :: rotate_Xg !!> Rotate geometry points
procedure :: translate_Xc !!> Translate control points
procedure :: translate_Xg !!> Translate geometry points

! Shapes
procedure :: set_tetragon !!> Set a tetragon
Expand Down Expand Up @@ -1513,4 +1517,64 @@ pure function cmp_elem(this) result(elemConn)
end function
!===============================================================================


!===============================================================================
!> author: Seyed Ali Ghasemi
!> license: BSD 3-Clause
pure subroutine rotate_Xc(this, alpha, beta, theta)
class(nurbs_surface), intent(inout) :: this
real(rk), intent(in) :: alpha, beta, theta
integer :: i

do i = 1, this%nc(1)*this%nc(2)
this%Xc(i, :) = matmul(rotation(alpha,beta,theta), this%Xc(i, :))
end do
end subroutine
!===============================================================================


!===============================================================================
!> author: Seyed Ali Ghasemi
!> license: BSD 3-Clause
pure subroutine rotate_Xg(this, alpha, beta, theta)
class(nurbs_surface), intent(inout) :: this
real(rk), intent(in) :: alpha, beta, theta
integer :: i

do i = 1, this%ng(1)*this%ng(2)
this%Xg(i, :) = matmul(rotation(alpha,beta,theta), this%Xg(i, :))
end do
end subroutine
!===============================================================================


!===============================================================================
!> author: Seyed Ali Ghasemi
!> license: BSD 3-Clause
pure subroutine translate_Xc(this, vec)
class(nurbs_surface), intent(inout) :: this
real(rk), intent(in) :: vec(:)
integer :: i

do i = 1, this%nc(1)*this%nc(2)
this%Xc(i, :) = this%Xc(i, :) + vec
end do
end subroutine
!===============================================================================


!===============================================================================
!> author: Seyed Ali Ghasemi
!> license: BSD 3-Clause
pure subroutine translate_Xg(this, vec)
class(nurbs_surface), intent(inout) :: this
real(rk), intent(in) :: vec(:)
integer :: i

do i = 1, this%ng(1)*this%ng(2)
this%Xg(i, :) = this%Xg(i, :) + vec
end do
end subroutine
!===============================================================================

end module forcad_nurbs_surface
66 changes: 65 additions & 1 deletion src/forcad_nurbs_volume.f90
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module forcad_nurbs_volume

use forcad_utils, only: rk, basis_bspline, elemConn_C0, kron, ndgrid, compute_multiplicity, compute_knot_vector, &
basis_bspline_der, insert_knot_A_5_1, findspan, elevate_degree_A_5_9, hexahedron_Xc, remove_knots_A_5_8, &
elemConn_Cn, unique
elemConn_Cn, unique, rotation

implicit none

Expand Down Expand Up @@ -72,6 +72,10 @@ module forcad_nurbs_volume
procedure :: is_rational !!> Check if the NURBS volume is rational
procedure :: put_to_nurbs !!> Put a shape to a NURBS volume
procedure :: remove_knots !!> Remove knots from the knot vector
procedure :: rotate_Xc !!> Rotate control points
procedure :: rotate_Xg !!> Rotate geometry points
procedure :: translate_Xc !!> Translate control points
procedure :: translate_Xg !!> Translate geometry points

! Shapes
procedure :: set_hexahedron !!> Set a hexahedron
Expand Down Expand Up @@ -1934,4 +1938,64 @@ pure function cmp_elem(this) result(elemConn)
end function
!===============================================================================


!===============================================================================
!> author: Seyed Ali Ghasemi
!> license: BSD 3-Clause
pure subroutine rotate_Xc(this, alpha, beta, theta)
class(nurbs_volume), intent(inout) :: this
real(rk), intent(in) :: alpha, beta, theta
integer :: i

do i = 1, this%nc(1)*this%nc(2)*this%nc(3)
this%Xc(i, :) = matmul(rotation(alpha,beta,theta), this%Xc(i, :))
end do
end subroutine
!===============================================================================


!===============================================================================
!> author: Seyed Ali Ghasemi
!> license: BSD 3-Clause
pure subroutine rotate_Xg(this, alpha, beta, theta)
class(nurbs_volume), intent(inout) :: this
real(rk), intent(in) :: alpha, beta, theta
integer :: i

do i = 1, this%ng(1)*this%ng(2)*this%ng(3)
this%Xg(i, :) = matmul(rotation(alpha,beta,theta), this%Xg(i, :))
end do
end subroutine
!===============================================================================


!===============================================================================
!> author: Seyed Ali Ghasemi
!> license: BSD 3-Clause
pure subroutine translate_Xc(this, vec)
class(nurbs_volume), intent(inout) :: this
real(rk), intent(in) :: vec(:)
integer :: i

do i = 1, this%nc(1)*this%nc(2)*this%nc(3)
this%Xc(i, :) = this%Xc(i, :) + vec
end do
end subroutine
!===============================================================================


!===============================================================================
!> author: Seyed Ali Ghasemi
!> license: BSD 3-Clause
pure subroutine translate_Xg(this, vec)
class(nurbs_volume), intent(inout) :: this
real(rk), intent(in) :: vec(:)
integer :: i

do i = 1, this%ng(1)*this%ng(2)*this%ng(3)
this%Xg(i, :) = this%Xg(i, :) + vec
end do
end subroutine
!===============================================================================

end module forcad_nurbs_volume
22 changes: 21 additions & 1 deletion src/forcad_utils.f90
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module forcad_utils
private
public :: rk, basis_bernstein, basis_bspline, elemConn_C0, kron, ndgrid, compute_multiplicity, compute_knot_vector, &
basis_bspline_der, insert_knot_A_5_1, findspan, elevate_degree_A_5_9, hexahedron_Xc, tetragon_Xc, remove_knots_A_5_8, &
elemConn_Cn, unique
elemConn_Cn, unique, rotation

integer, parameter :: rk = kind(1.0d0)

Expand Down Expand Up @@ -1022,4 +1022,24 @@ pure function unique_real(vec) result(unique)
end function
!===============================================================================


!===============================================================================
!> author: Seyed Ali Ghasemi
!> license: BSD 3-Clause
pure function rotation(alpha, beta, theta) result(R)
real(rk), intent(in) :: alpha, beta, theta
real(rk), dimension(3,3) :: R

R(1,1) = cosd(beta)*cosd(theta)
R(2,1) = cosd(beta)*sind(theta)
R(3,1) = -sind(beta)
R(1,2) = sind(alpha)*sind(beta)*cosd(theta) - cosd(alpha)*sind(theta)
R(2,2) = sind(alpha)*sind(beta)*sind(theta) + cosd(alpha)*cosd(theta)
R(3,2) = sind(alpha)*cosd(beta)
R(1,3) = cosd(alpha)*sind(beta)*cosd(theta) + sind(alpha)*sind(theta)
R(2,3) = cosd(alpha)*sind(beta)*sind(theta) - sind(alpha)*cosd(theta)
R(3,3) = cosd(alpha)*cosd(beta)
end function
!===============================================================================

end module forcad_utils

0 comments on commit d545598

Please sign in to comment.