Skip to content

Commit

Permalink
Merge pull request #9 from gha3mi/dev
Browse files Browse the repository at this point in the history
Clean up memory in examples and tests and general improvements
  • Loading branch information
gha3mi authored May 8, 2024
2 parents 3437225 + abc2a8a commit 080b426
Show file tree
Hide file tree
Showing 18 changed files with 72 additions and 13 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
- Add NURBS surface to PPM conversion examples.
- Utilized ForUnitTest for testing.
- Added Support for `OpenMP` and `do concurrent`.
- Implemented memory cleanup in the examples and tests.

### Changed

- Updated `README.md` file.
- Updated tests to use ForUnitTest.
- Added ParaView to the list of References in the README file.
- Used `matmul` instead of `dot_product` in the `put_to_nurbs` subroutine.

### Removed

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

![](logo/logo.png)

**ForCAD**: A Parallel Fortran library for Geometric Modeling using NURBS (Non-Uniform Rational B-Splines).
**ForCAD**: A parallel Fortran library for geometric modeling using NURBS (Non-Uniform Rational B-Splines).

ForCAD supports **B-Spline**, **NURBS**, **Bezier**, and **Rational Bezier** curves, surfaces, and volumes.

Expand Down
3 changes: 3 additions & 0 deletions example/demo_curve.f90
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ program example_nurbs_curve
!> Set control points and weights for the NURBS curve object
call nurbs%set(Xc, Wc)

!> Deallocate local arrays
deallocate(Xc, Wc)

!> Export initial control points to a VTK file
call nurbs%export_Xc('vtk/demo_curve_Xc.vtk')

Expand Down
3 changes: 3 additions & 0 deletions example/demo_surface.f90
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ program example_nurbs_surface
!> Set control points and weights for the NURBS surface object
call nurbs%set([10,10],Xc,Wc)

!> Deallocate local arrays
deallocate(Xc, Wc)

!> Export initial control points to a VTK file
call nurbs%export_Xc('vtk/demo_surface_Xc.vtk')

Expand Down
3 changes: 3 additions & 0 deletions example/demo_volume.f90
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ program example_nurbs_volume
!> Set control points and weights for the NURBS volume object
call nurbs%set([2,2,2], Xc, Wc)

!> Deallocate local arrays
deallocate(Xc, Wc)

!> Export initial control points to a VTK file
call nurbs%export_Xc('vtk/demo_volume_Xc.vtk')

Expand Down
3 changes: 3 additions & 0 deletions example/example_curve_1.f90
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ program example1_curve
!> Wc is optional
call nurbs%set(knot, Xc, Wc)

!> Deallocate local arrays
deallocate(Xc, Wc)

!> Export control points to a VTK file
call nurbs%export_Xc('vtk/nurbs_curve_Xc.vtk')

Expand Down
10 changes: 10 additions & 0 deletions example/example_ppm1.f90
Original file line number Diff line number Diff line change
Expand Up @@ -354,4 +354,14 @@ program example_ppm1
call image%finalize()
call t%timer_stop(message='Saving the image')







! Clean up
! call cmap%finalize()
deallocate(px, Xg, z_values)

end program
10 changes: 10 additions & 0 deletions example/example_ppm2.f90
Original file line number Diff line number Diff line change
Expand Up @@ -363,4 +363,14 @@ program example_ppm2
call image%finalize()
call t%timer_stop(message='Saving the image')







! Clean up
! call cmap%finalize()
deallocate(px, Xg, z_values)

end program
10 changes: 10 additions & 0 deletions example/example_ppm3.f90
Original file line number Diff line number Diff line change
Expand Up @@ -346,4 +346,14 @@ program example_ppm3
call image%finalize()
call t%timer_stop(message='Saving the image')







! Clean up
! call cmap%finalize()
deallocate(px, Xg, z_values)

end program
3 changes: 3 additions & 0 deletions example/example_surface_1.f90
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ program example3_surface
!> Set knot vectors, control points, and weights for the NURBS surface object
call nurbs%set(knot1, knot2, Xc, Wc)

!> Deallocate local arrays
deallocate(Xc, Wc)

!> Export the control points to a VTK file
call nurbs%export_Xc('vtk/nurbs_surface_Xc.vtk')

Expand Down
3 changes: 3 additions & 0 deletions example/example_volume_1.f90
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ program example3_volume
!> Wc is optional.
call nurbs%set(knot1, knot2, knot3, Xc, Wc)

!> Deallocate local arrays
deallocate(Xc, Wc)

!> Export the control points to a VTK file
call nurbs%export_Xc('vtk/nurbs_volume_Xc.vtk')

Expand Down
6 changes: 6 additions & 0 deletions example/put_to_nurbs.f90
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ program example_morph
!> Map the shape into the shape
call control_shape%put_to_nurbs(X, elem)

!> Deallocate local variables
deallocate(X, elem)

!> Export the shape and the control shape to vtk files
call control_shape%export_Xc('vtk/control_shape.vtk')
call control_shape%export_Xg('vtk/shape.vtk')
Expand All @@ -47,4 +50,7 @@ program example_morph
!> Show the control geometry and geometry using PyVista
call control_shape%show('vtk/control_shape.vtk','vtk/shape.vtk')

!> Finalize the control shape
call control_shape%finalize()

end program
2 changes: 2 additions & 0 deletions src/forcad_nurbs_surface.f90
Original file line number Diff line number Diff line change
Expand Up @@ -2103,6 +2103,8 @@ impure function compute_Xg_nurbs_2d(Xt, knot1, knot2, degree, nc, ng, Xc, Wc) re
integer :: i

allocate(Xg(ng(1)*ng(2), size(Xc,2)))
allocate(Tgc(nc(1)*nc(2)))

!$OMP PARALLEL DO PRIVATE(Tgc)
do i = 1, ng(1)*ng(2)
Tgc = kron(&
Expand Down
14 changes: 7 additions & 7 deletions src/forcad_nurbs_volume.f90
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,8 @@ pure function compute_Xg_bspline_3d(f_Xt, f_knot1, f_knot2, f_knot3, f_degree, f
end if

if (allocated(this%Xg)) deallocate(this%Xg)

allocate(this%Xg(this%ng(1)*this%ng(2)*this%ng(3), size(this%Xc,2)))

if (allocated(this%Wc)) then ! NURBS volume
this%Xg = compute_Xg_nurbs_3d(Xt_, this%knot1, this%knot2, this%knot3, this%degree, this%nc, this%ng, this%Xc, this%Wc)
else
Expand Down Expand Up @@ -1813,6 +1814,7 @@ pure subroutine put_to_nurbs(this, X, elemConn)
Xt(:,3) = (X(:,3) - min_X3) / (max_X3 - min_X3)

allocate(this%Xg(size(Xt,1), size(this%Xc,2)))
allocate(Tgc(this%nc(1)*this%nc(2)*this%nc(3)))

if (allocated(this%Wc)) then ! NURBS volume
do i = 1, size(Xt, 1)
Expand All @@ -1821,19 +1823,15 @@ pure subroutine put_to_nurbs(this, X, elemConn)
Tgc3 = basis_bspline(Xt(i,3), this%knot3, this%nc(3), this%degree(3))
Tgc = kron(Tgc3, kron(Tgc2, Tgc1))
Tgc = Tgc*(this%Wc/(dot_product(Tgc,this%Wc)))
do j = 1, size(this%Xc, 2)
this%Xg(i,j) = dot_product(Tgc,this%Xc(:,j))
end do
this%Xg(i,:) = matmul(Tgc,this%Xc)
end do
else ! B-Spline volume
do i = 1, size(Xt, 1)
Tgc1 = basis_bspline(Xt(i,1), this%knot1, this%nc(1), this%degree(1))
Tgc2 = basis_bspline(Xt(i,2), this%knot2, this%nc(2), this%degree(2))
Tgc3 = basis_bspline(Xt(i,3), this%knot3, this%nc(3), this%degree(3))
Tgc = kron(Tgc3, kron(Tgc2, Tgc1))
do j = 1, size(this%Xc, 2)
this%Xg(i,j) = dot_product(Tgc,this%Xc(:,j))
end do
this%Xg(i,:) = matmul(Tgc,this%Xc)
end do
end if

Expand Down Expand Up @@ -2596,6 +2594,8 @@ impure function compute_Xg_nurbs_3d(Xt, knot1, knot2, knot3, degree, nc, ng, Xc,
integer :: i

allocate(Xg(ng(1)*ng(2)*ng(3), size(Xc,2)))
allocate(Tgc(nc(1)*nc(2)*nc(3)))

!$OMP PARALLEL DO PRIVATE(Tgc)
do i = 1, ng(1)*ng(2)*ng(3)
Tgc = kron(basis_bspline(Xt(i,3), knot3, nc(3), degree(3)),&
Expand Down
8 changes: 3 additions & 5 deletions src/forcad_utils.f90
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ pure function repelem(a, b) result(c)
c(l+1:l+n) = a(i)
l = l + n
end do
end function repelem
end function
!===============================================================================


Expand Down Expand Up @@ -328,18 +328,16 @@ pure subroutine cmp_elemConn_Cn_L(nnode, p, Xth,vecKnot_mul, elemConn)
real(rk), intent(in), contiguous :: Xth(:)
integer, allocatable, intent(out) :: elemConn(:,:)
integer, allocatable :: nodes(:)
integer :: i, l, nnel, m, nelem
integer :: i, nnel, m, nelem

nnel = p + 1
nodes = [(i, i=1, nnode)]
nelem = size(Xth) - 1
allocate(elemConn(nelem,nnel))
l = 0
m = -p
do i = 1, nelem
m = m + vecKnot_mul(i)
l = l + 1
elemConn(l,:) = nodes(m:m+p)
elemConn(i,:) = nodes(m:m+p)
end do
end subroutine
!===============================================================================
Expand Down
1 change: 1 addition & 0 deletions test/test_curve.f90
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,6 @@ program test_curve

call nurbs%finalize()
call bsp%finalize()
deallocate(Xc, Wc, Xg, Xgb)

end program
1 change: 1 addition & 0 deletions test/test_surface.f90
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ program test_surface

call nurbs%finalize()
call bsp%finalize()
deallocate(Xc, Wc, Xg, Xgb)

contains

Expand Down
1 change: 1 addition & 0 deletions test/test_volume.f90
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ program test_volume

call nurbs%finalize()
call bsp%finalize()
deallocate(Xc, Wc, Xg, Xgb)

contains

Expand Down

0 comments on commit 080b426

Please sign in to comment.