Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
hverhelst committed May 24, 2024
2 parents 20fda09 + d726ed2 commit a474426
Show file tree
Hide file tree
Showing 18 changed files with 1,700 additions and 197 deletions.
15 changes: 13 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@
##
######################################################################

project(gsCInterface LANGUAGES C Fortran)
project(gsCInterface LANGUAGES C)

include(CheckLanguage)
check_language(Fortran)
if(CMAKE_Fortran_COMPILER)
enable_language(Fortran)
else()
message(STATUS "No Fortran support")
endif()

# Apply G+Smo config
include(gsConfig)
Expand Down Expand Up @@ -43,4 +51,7 @@ install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/src/"

add_gismo_executable(${CMAKE_CURRENT_SOURCE_DIR}/examples/basis_cexample.c)
add_gismo_executable(${CMAKE_CURRENT_SOURCE_DIR}/examples/geometry_cexample.c)
add_gismo_executable(${CMAKE_CURRENT_SOURCE_DIR}/examples/geometry_fexample.F90)

if(CMAKE_Fortran_COMPILER)
add_gismo_executable(${CMAKE_CURRENT_SOURCE_DIR}/examples/geometry_fexample.F90)
endif()
2 changes: 1 addition & 1 deletion examples/basis_cexample.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ int main(int argc, char* argv[])
udata[3]=1.00;
gsCMatrix * u = gsMatrix_create_rcd(1,4,udata);
gsCMatrix * result = gsMatrix_create();
eval_into(b, u, result);
gsFunctionSet_eval_into(b, u, result);
printf("Matrix with %d rows and %d columns:\n", rows(result), cols(result) );
print(result);
printf("\n");
Expand Down
4 changes: 2 additions & 2 deletions examples/geometry_cexample.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ int main(int argc, char* argv[])
// evaluate positions (x,y,z) at given parameter values

gsCMatrix * out_p = gsMatrix_create();
eval_into(G, uvm, out_p);
gsFunctionSet_eval_into(G, uvm, out_p);
double* out_data = data(out_p);
int out_rows = rows(out_p), out_cols = cols(out_p);

Expand All @@ -71,7 +71,7 @@ int main(int argc, char* argv[])

// evaluate first derivatives d(x,y,z)/du and d(x,y,z)/dv at given parameter values
gsCMatrix * out_d = gsMatrix_create();
deriv_into(G, uvm, out_d);
gsFunctionSet_deriv_into(G, uvm, out_d);
out_data = data(out_d);
out_rows = rows(out_d);
out_cols = cols(out_d);
Expand Down
158 changes: 54 additions & 104 deletions examples/geometry_fexample.F90
Original file line number Diff line number Diff line change
Expand Up @@ -16,44 +16,28 @@ program geometry_fexample
implicit none
# include "gsCInterface/gismo.ifc"
character(len=80, kind=C_CHAR) :: some_file
type(c_ptr) :: g
type(c_ptr) :: g
integer :: nu, nv
logical, parameter :: use_thb = .false.

! TODO: input option for xml-file?

if (use_thb) then
write(*,'(2(a,f5.1),a,i3)') 'reading XML for THB-spline'
some_file = 'optional/gsWRContact/examples/sw_crossing/sw_thb.xml' // C_NULL_CHAR
g = gsCReadFile(some_file)
else
write(*,'(2(a,f5.1),a,i3)') 'reading XML for tensor B-spline'
some_file = 'optional/gsWRContact/examples/sw_crossing/sw_tp.xml' // C_NULL_CHAR
g = gsCReadFile(some_file)
endif
write(*,'(a,i3)') 'done, g.dim=', domainDim(g)
write(*,'(2(a,f5.1),a,i3)') 'reading XML for tensor B-spline'
some_file = 'sw_tp.xml' // C_NULL_CHAR
g = gsCReadFile(some_file)

write(*,'(a,i3)') 'done, g.dim=', gsFunctionSet_domainDim(g)

call print(g)
call gsFunctionSet_print(g)

if (.true.) then
call show_basic_usage( g )
endif

if (.false.) then
nu = 251
nv = 201
call sample_surface( g, nu, nv )
endif

if (.true.) then
call show_recover_points( g )
endif

if (use_thb) then
call destroy(g)
else
call destroy(g)
endif
call gsFunctionSet_delete(g)
write(*,*) 'done.'

end program geometry_fexample
Expand All @@ -66,10 +50,12 @@ subroutine show_basic_usage( g )
implicit none
# include "gsCInterface/gismo.ifc"
!--subroutine arguments
type(c_ptr) :: g, uvm, xyzm, xyz1
type(c_ptr) :: g
!--local variables
integer(C_INT) :: nRows, nCols, out_rows, out_cols, irow, icol, icoor, ipar
real(C_DOUBLE), dimension(:,:), target, allocatable :: uv, xyz
type(C_PTR) :: uvm, xyzm, xyz_p
real(C_DOUBLE), dimension(:,:), allocatable :: uv
real(C_DOUBLE), dimension(:,:), pointer :: xyz
character(len=1), parameter :: c_param(2) = (/ 'u', 'v' /)
character(len=1), parameter :: c_coor(3) = (/ 'x', 'y', 'z' /)

Expand All @@ -87,80 +73,29 @@ subroutine show_basic_usage( g )

! evaluate positions (x,y,z) at given parameter values

uvm = gsMatrix_create_rcd(nRows, nCols, c_loc(uv(1,1)))
uvm = gsMatrix_create()
call eval_into(G, uvm, xyzm)
xyz1 = gsMatrix_data(xyzm)
call C_F_POINTER(xyz1,xyz)
write(*,'(3(a,i3))') 'Got #rows =', out_rows, ', #cols =', out_cols
do irow = 1, out_rows
write(*,'(3a,10f10.3)') ' ',c_coor(irow),': ', (xyz(irow,icol), icol=1,out_cols)
enddo
deallocate(uv)

end subroutine show_basic_usage

!-----------------------------------------------------------------------------------------------------------

subroutine sample_surface( g, nu, nv )
!--purpose: evaluate positions (x,y,z) at uniform grid [0:du:1] x [0:dv:1], print table of results
use, intrinsic :: iso_c_binding
implicit none
# include "gsCInterface/gismo.ifc"
!--subroutine arguments
type(c_ptr) :: g
integer, intent(in) :: nu, nv
!--local variables
integer :: iu, iv, ii
real(kind=8) :: du, dv, ui, vj
integer(C_INT) :: nRows, nCols, out_rows, out_cols, mode, irow, icol, icoor, ipar
real(C_DOUBLE), dimension(:,:), allocatable :: uv
real(C_DOUBLE), dimension(:,:), allocatable :: xyz
character(len=1), parameter :: c_param(2) = (/ 'u', 'v' /)
character(len=1), parameter :: c_coor(3) = (/ 'x', 'y', 'z' /)
uvm = gsMatrix_create_rcd(nRows, nCols, uv)
xyzm = gsMatrix_create()
call gsFunctionSet_eval_into(G, uvm, xyzm)
! call gsMatrix_print(xyzm)

write(*,*) '-------------------------------- sample_surface --------------------------------'
! set step-sizes for parameters u, v, interval [0,1] divided into equidistant positions
! get pointer to matrix data

du = 1d0 / (nu - 1)
dv = 1d0 / (nv - 1)
out_rows = gsMatrix_rows(xyzm)
out_cols = gsMatrix_cols(xyzm)
xyz_p = gsMatrix_data(xyzm)
call C_F_POINTER(xyz_p, xyz, (/ out_rows, out_cols /))

! create input for gs_eval_geometry

nRows = 2
nCols = nu * nv
allocate(uv(nRows,nCols))

do iu = 1, nu
do iv = 1, nv
ii = (iu-1) * nv + iv
uv(1, ii) = (iu-1) * du
uv(2, ii) = (iv-1) * dv
enddo
write(*,'(3(a,i3))') 'Got #rows =', out_rows, ', #cols =', out_cols
do irow = 1, out_rows
write(*,'(3a,10f10.3)') ' ',c_coor(irow),': ', (xyz(irow,icol), icol=1,out_cols)
enddo

write(*,'(2(a,i4),a)') 'Parameter grid nu x nv =',nu,' x',nv,' positions'

! evaluate positions (x,y,z) at given parameter values

mode = 0
allocate(xyz(3,nCols))
call eval_into(G, uv, nRows, nCols, xyz, 3*nCols, out_rows, out_cols, mode)

! print results in tabular form

write(*,'(2(a,i3),a,i7)') 'Mode =',mode,': got #rows =', out_rows, ', #cols =', out_cols
write(*,'(a)') '% iu iv ii ui vj xij yij zij'
do iu = 1, nu
do iv = 1, nv
ii = (iu-1) * nv + iv
write(*,'(3i8,2f12.6,f14.6,2f12.6)') iu, iv, ii, uv(1,ii), uv(2,ii), &
(xyz(irow,ii), irow=1,out_rows)
enddo
enddo
deallocate(xyz)
call gsMatrix_delete(uvm)
call gsMatrix_delete(xyzm)
! write(*,*) 'deallocate uv'
! deallocate(uv)

end subroutine sample_surface
end subroutine show_basic_usage

!-----------------------------------------------------------------------------------------------------------

Expand All @@ -170,35 +105,46 @@ subroutine show_recover_points( g )
implicit none
# include "gsCInterface/gismo.ifc"
!--subroutine arguments
type(c_ptr) :: g
type(c_ptr) :: g
!--local variables
integer(C_INT), parameter :: XDIR = 0, YDIR = 1, ZDIR = 2
integer(C_INT) :: nCols, irow, icol
real(C_DOUBLE), dimension(:,:), allocatable :: uv, xyz
integer(C_INT) :: nCols, irow, icol, out_rows, out_cols
real(C_DOUBLE) :: eps
real(C_DOUBLE), dimension(:,:), allocatable :: xyz
real(C_DOUBLE), dimension(:,:), pointer :: uv
type(C_PTR) :: uvm, xyzm, uv_p
character(len=1), parameter :: c_param(2) = (/ 'u', 'v' /)
character(len=1), parameter :: c_coor(3) = (/ 'x', 'y', 'z' /)

write(*,*) '----------------------------- show_recover_points -----------------------------'
nCols = 4
allocate(xyz(3,ncols))
allocate(uv(2,ncols))

xyz(1, 1:ncols) = (/ 2451.0, 210.001, 708.0, 210.0 /)
xyz(2, 1:ncols) = (/ 122.3, -38.957, 18.568, -13.9 /)
xyz(3, 1:ncols) = (/ 0.0, 0.0, 0.0, 0.0 /)

do icol = 1, nCols
uv(:,icol) = 0d0
enddo

write(*,'(a,i3,a)') 'Input #cols =', nCols,', (x,y,z) ='
do irow = 1, 3
write(*,'(3a,10f10.3)') ' ',c_coor(irow),': ', (xyz(irow,icol), icol=1,nCols)
enddo

! evaluate z-positions and (u,v)-values for given (x,y)-positions

call gs_recover_points(G, uv, xyz, nCols, ZDIR)
! evaluate positions (x,y,z) at given parameter values

xyzm = gsMatrix_create_rcd(3, ncols, xyz)
uvm = gsMatrix_create()

eps = 1d-6
call gsGeometry_recoverPoints(G, uvm, xyzm, ZDIR, eps)

! get pointer to matrix data

out_rows = gsMatrix_rows(uvm)
out_cols = gsMatrix_cols(uvm)
uv_p = gsMatrix_data(uvm)
call C_F_POINTER(uv_p, uv, (/ out_rows, out_cols /))

write(*,'(a)') 'Output (u,v) ='
do irow = 1, 2
Expand All @@ -209,9 +155,13 @@ subroutine show_recover_points( g )
write(*,'(3a,10f10.3)') ' ',c_coor(irow),': ', (xyz(irow,icol), icol=1, nCols)
enddo

deallocate(uv)
! clean up input data, matrices used

call gsMatrix_delete(xyzm)
call gsMatrix_delete(uvm)
deallocate(xyz)

end subroutine show_recover_points

!-----------------------------------------------------------------------------------------------------------

Loading

0 comments on commit a474426

Please sign in to comment.