Skip to content

Commit

Permalink
add HB spline and basis
Browse files Browse the repository at this point in the history
add THB spline
add warning to getString
  • Loading branch information
hverhelst committed Dec 19, 2024
1 parent 5831085 commit 5ac4b45
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 21 deletions.
6 changes: 3 additions & 3 deletions cmake/Gismo.jl.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ include("Declarations.jl")
# Load gsCore
include("gsCore.jl")

# Load gsMatrix
include("gsMatrix.jl")

# Load gsAssembler
include("gsAssembler.jl")

Expand All @@ -17,9 +20,6 @@ include("gsHSplines.jl")
# Load gsIO
include("gsIO.jl")

# Load gsMatrix
include("gsMatrix.jl")

# Load gsMatrix
include("gsModeling.jl")

Expand Down
6 changes: 3 additions & 3 deletions src/Gismo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ include("Declarations.jl")
# Load gsCore
include("gsCore.jl")

# Load gsMatrix
include("gsMatrix.jl")

# Load gsAssembler
include("gsAssembler.jl")

Expand All @@ -17,9 +20,6 @@ include("gsHSplines.jl")
# Load gsIO
include("gsIO.jl")

# Load gsMatrix
include("gsMatrix.jl")

# Load gsMatrix
include("gsModeling.jl")

Expand Down
113 changes: 105 additions & 8 deletions src/gsHSplines.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
export
THBSplineBasis
THBSplineBasis,
HBSplineBasis,
THBSpline,
HBSpline
########################################################################
# gsTHBSplineBasis
########################################################################
Expand All @@ -11,14 +14,11 @@ THBSplineBasis
- `basis::Basis`: a basis object
# Examples
```jldoctest
a = 1
b = 2
a + b
```jldoctest output=(false)
kv = KnotVector([0.,0.,0.,1.,1.,1.])
b = BSplineBasis(kv)
thb = THBSplineBasis(b)
# output
3
```
"""
function THBSplineBasis(basis::Basis)::Basis
Expand All @@ -35,3 +35,100 @@ function THBSplineBasis(basis::Basis)::Basis
end
return Basis(b)
end

"""
HBSplineBasis(basis::Basis)
# Arguments
- `basis::Basis`: a basis object
# Examples
```jldoctest output=(false)
kv = KnotVector([0.,0.,0.,1.,1.,1.])
b = BSplineBasis(kv)
thb = HBSplineBasis(b)
# output
```
"""
function HBSplineBasis(basis::Basis)::Basis
if (domainDim(basis)==1)
b = ccall((:gsHBSplineBasis1_create,libgismo),Ptr{gsCBasis},(Ptr{gsCBasis},),basis.ptr)
elseif (domainDim(basis)==2)
b = ccall((:gsHBSplineBasis2_create,libgismo),Ptr{gsCBasis},(Ptr{gsCBasis},),basis.ptr)
elseif (domainDim(basis)==3)
b = ccall((:gsHBSplineBasis3_create,libgismo),Ptr{gsCBasis},(Ptr{gsCBasis},),basis.ptr)
elseif (domainDim(basis)==4)
b = ccall((:gsHBSplineBasis4_create,libgismo),Ptr{gsCBasis},(Ptr{gsCBasis},),basis.ptr)
else
error("HBSplineBasis not implemented for this dimension")
end
return Basis(b)
end

"""
THBSpline(basis::Basis, coefs::Matrix{Cdouble})
# Arguments
- `basis::Basis`: a basis object
- `coefs::Matrix{Cdouble}`: a matrix of coefficients
# Examples
```jldoctest output=(false)
kv = KnotVector([0.,0.,0.,1.,1.,1.])
b = BSplineBasis(kv)
thb = THBSplineBasis(b)
coefs = rand(3,2)
g = THBSpline(thb,coefs)
# output
```
"""
function THBSpline(basis::Basis, coefs::Matrix{Cdouble})::Geometry
@assert Base.size(coefs,1) == Gismo.size(basis) "THBSpline: coefs must have the same number of rows as the number of degrees of freedom"
cc = EigenMatrix(Base.size(coefs,1),Base.size(coefs,2),pointer(coefs))
if (domainDim(basis)==1)
g = ccall((:gsTHBSpline1_create,libgismo),Ptr{gsCGeometry},(Ptr{gsCBasis},Ptr{EigenMatrix}),basis.ptr,cc.ptr)
elseif (domainDim(basis)==2)
g = ccall((:gsTHBSpline2_create,libgismo),Ptr{gsCGeometry},(Ptr{gsCBasis},Ptr{EigenMatrix}),basis.ptr,cc.ptr)
elseif (domainDim(basis)==3)
g = ccall((:gsTHBSpline3_create,libgismo),Ptr{gsCGeometry},(Ptr{gsCBasis},Ptr{EigenMatrix}),basis.ptr,cc.ptr)
elseif (domainDim(basis)==4)
g = ccall((:gsTHBSpline4_create,libgismo),Ptr{gsCGeometry},(Ptr{gsCBasis},Ptr{EigenMatrix}),basis.ptr,cc.ptr)
else
error("THBSpline not implemented for this dimension")
end
return Geometry(g)
end

"""
HBSpline(basis::Basis, coefs::Matrix{Cdouble})
# Arguments
- `basis::Basis`: a basis object
- `coefs::Matrix{Cdouble}`: a matrix of coefficients
# Examples
```jldoctest output=(false)
kv = KnotVector([0.,0.,0.,1.,1.,1.])
b = BSplineBasis(kv)
hb = HBSplineBasis(b)
coefs = rand(3,2)
g = HBSpline(hb,coefs)
# output
```
"""
function HBSpline(basis::Basis, coefs::Matrix{Cdouble})::Geometry
@assert Base.size(coefs,1) == Gismo.size(basis) "HBSpline: coefs must have the same number of rows as the number of degrees of freedom"
cc = EigenMatrix(Base.size(coefs,1),Base.size(coefs,2),pointer(coefs))
if (domainDim(basis)==1)
g = ccall((:gsHBSpline1_create,libgismo),Ptr{gsCGeometry},(Ptr{gsCBasis},Ptr{EigenMatrix}),basis.ptr,cc.ptr)
elseif (domainDim(basis)==2)
g = ccall((:gsHBSpline2_create,libgismo),Ptr{gsCGeometry},(Ptr{gsCBasis},Ptr{EigenMatrix}),basis.ptr,cc.ptr)
elseif (domainDim(basis)==3)
g = ccall((:gsHBSpline3_create,libgismo),Ptr{gsCGeometry},(Ptr{gsCBasis},Ptr{EigenMatrix}),basis.ptr,cc.ptr)
elseif (domainDim(basis)==4)
g = ccall((:gsHBSpline4_create,libgismo),Ptr{gsCGeometry},(Ptr{gsCBasis},Ptr{EigenMatrix}),basis.ptr,cc.ptr)
else
error("HBSpline not implemented for this dimension")
end
return Geometry(g)
end
11 changes: 4 additions & 7 deletions src/gsIO.jl
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,8 @@ Get a string from the option list
# Return
- `string::Cstring`: the value
# Examples
#```jldoctest
opt = OptionList(Dict("key1"=>"value1"))
println(getString(opt,"key1"))
# output
value1
```
!!! warning
The returned value is a Cstring, and its conversion to a Julia string is not trivial.
"""
function getString(opt::OptionList,key::String)::Cstring
return ccall((:gsOptionList_getString,libgismo),Cstring,(Ptr{gsCOptionList},Cstring),opt.ptr,key)
Expand All @@ -208,6 +203,7 @@ opt = OptionList(Dict("key1"=>1))
println(getInt(opt,"key1"))
# output
1
```
"""
function getInt(opt::OptionList,key::String)::Int
return ccall((:gsOptionList_getInt,libgismo),Cint,(Ptr{gsCOptionList},Cstring),opt.ptr,key)
Expand Down Expand Up @@ -251,6 +247,7 @@ opt = OptionList(Dict("key1"=>true))
println(getSwitch(opt,"key1"))
# output
true
```
"""
function getSwitch(opt::OptionList,key::String)::Bool
return ccall((:gsOptionList_getSwitch,libgismo),Cint,(Ptr{gsCOptionList},Cstring),opt.ptr,key)
Expand Down

0 comments on commit 5ac4b45

Please sign in to comment.