From 9bd090babdd631e3034ead12ca8118cc1e6dee36 Mon Sep 17 00:00:00 2001 From: Hugo Verhelst Date: Wed, 11 Dec 2024 13:53:05 +0100 Subject: [PATCH 01/16] add evaluation of singles add size function overloads add gsGeometry::knots add docs --- docs/make.jl | 5 +- src/gsCore.jl | 134 ++++++++++++++++++++++++++++++++++++++++++++++++ src/gsMatrix.jl | 16 +++--- src/gsNurbs.jl | 35 ++++++++++--- 4 files changed, 171 insertions(+), 19 deletions(-) diff --git a/docs/make.jl b/docs/make.jl index dc67464..70a0dc2 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -1,6 +1,4 @@ -using Documenter, Example - -push!(LOAD_PATH, "../src/") +using Documenter using Gismo DocMeta.setdocmeta!(Gismo, @@ -10,6 +8,7 @@ DocMeta.setdocmeta!(Gismo, # List of subsection pages SUBSECTION_PAGES = [ + "gsMatrix.md", "gsCore.md", "gsNurbs.md", "gsHSplines.md" diff --git a/src/gsCore.jl b/src/gsCore.jl index b9e12af..bf190e1 100644 --- a/src/gsCore.jl +++ b/src/gsCore.jl @@ -141,6 +141,9 @@ Returns the size of a basis function size(obj::Basis)::Cint return ccall((:gsBasis_size,libgismo),Cint,(Ptr{gsCBasis},),obj.ptr) end +function Base.size(obj::Basis)::Cint + return Gismo.size(obj) +end """ Refines a basis @@ -225,6 +228,98 @@ function eval(obj::Basis,u::Matrix{Cdouble})::EigenMatrix obj.ptr,uu.ptr,result.ptr) return result; end +function Base.eval(obj::Basis,u::Matrix{Cdouble})::EigenMatrix + return Gismo.eval(obj,u) +end + +""" +Returns the derivative of a basis +... +# Arguments +- `obj::Basis`: a Gismo Basis +- `u::Matrix{Cdouble}`: a matrix of points +... +""" +function deriv(obj::Basis,u::Matrix{Cdouble})::EigenMatrix + @assert Base.size(u,1)==domainDim(obj) "Domain dimension should be equal to the number of rows of the points" + uu = EigenMatrix(Base.size(u,1), Base.size(u,2), pointer(u) ) + result = EigenMatrix() + ccall((:gsFunctionSet_deriv_into,libgismo),Cvoid, + (Ptr{gsCBasis},Ptr{gsCMatrix},Ptr{gsCMatrix},), + obj.ptr,uu.ptr,result.ptr) + return result; +end +""" +Returns the second derivative of a basis +... +# Arguments +- `obj::Basis`: a Gismo Basis +- `u::Matrix{Cdouble}`: a matrix of points +... +""" +function deriv2(obj::Basis,u::Matrix{Cdouble})::EigenMatrix + @assert Base.size(u,1)==domainDim(obj) "Domain dimension should be equal to the number of rows of the points" + uu = EigenMatrix(Base.size(u,1), Base.size(u,2), pointer(u) ) + result = EigenMatrix() + ccall((:gsFunctionSet_deriv2_into,libgismo),Cvoid, + (Ptr{gsCBasis},Ptr{gsCMatrix},Ptr{gsCMatrix},), + obj.ptr,uu.ptr,result.ptr) + return result; +end + +""" +Returns the evaluation of a single basis function +... +# Arguments +- `obj::Basis`: a Gismo Basis +- `u::Matrix{Cdouble}`: a matrix of points +... +""" +function evalSingle(obj::Basis,i::Cint,u::Matrix{Cdouble})::EigenMatrix + @assert Base.size(u,1)==domainDim(obj) "Domain dimension should be equal to the number of rows of the points" + uu = EigenMatrix(Base.size(u,1), Base.size(u,2), pointer(u) ) + result = EigenMatrix() + ccall((:gsBasis_evalSingle_into,libgismo),Cvoid, + (Ptr{gsCBasis},Cint,Ptr{gsCMatrix},Ptr{gsCMatrix},), + obj.ptr,i,uu.ptr,result.ptr) + return result; +end + +""" +Returns the derivative of a single basis function +... +# Arguments +- `obj::Basis`: a Gismo Basis +- `u::Matrix{Cdouble}`: a matrix of points +... +""" +function derivSingle(obj::Basis,i::Cint,u::Matrix{Cdouble})::EigenMatrix + @assert Base.size(u,1)==domainDim(obj) "Domain dimension should be equal to the number of rows of the points" + uu = EigenMatrix(Base.size(u,1), Base.size(u,2), pointer(u) ) + result = EigenMatrix() + ccall((:gsBasis_derivSingle_into,libgismo),Cvoid, + (Ptr{gsCBasis},Cint,Ptr{gsCMatrix},Ptr{gsCMatrix},), + obj.ptr,i,uu.ptr,result.ptr) + return result; +end + +""" +Returns the second derivative of a single basis function +... +# Arguments +- `obj::Basis`: a Gismo Basis +- `u::Matrix{Cdouble}`: a matrix of points +... +""" +function deriv2Single(obj::Basis,i::Cint,u::Matrix{Cdouble})::EigenMatrix + @assert Base.size(u,1)==domainDim(obj) "Domain dimension should be equal to the number of rows of the points" + uu = EigenMatrix(Base.size(u,1), Base.size(u,2), pointer(u) ) + result = EigenMatrix() + ccall((:gsBasisSet_deriv2Single_into,libgismo),Cvoid, + (Ptr{gsCBasis},Cint,Ptr{gsCMatrix},Ptr{gsCMatrix},), + obj.ptr,i,uu.ptr,result.ptr) + return result; +end ######################################################################## # gsGeometry @@ -332,6 +427,45 @@ function eval(obj::Geometry,u::Matrix{Cdouble})::EigenMatrix obj.ptr,uu.ptr,result.ptr) return result; end +function Base.eval(obj::Geometry,u::Matrix{Cdouble})::EigenMatrix + return Gismo.eval(obj,u) +end + +""" +Returns the derivative of a geometry +... +# Arguments +- `obj::Geometry`: a Gismo Geometry +- `u::Matrix{Cdouble}`: a matrix of points +... +""" +function deriv(obj::Geometry,u::Matrix{Cdouble})::EigenMatrix + @assert Base.size(u,1)==domainDim(obj) "Domain dimension should be equal to the number of rows of the points" + uu = EigenMatrix(Base.size(u,1), Base.size(u,2), pointer(u) ) + result = EigenMatrix() + ccall((:gsFunctionSet_deriv_into,libgismo),Cvoid, + (Ptr{gsCGeometry},Ptr{gsCMatrix},Ptr{gsCMatrix},), + obj.ptr,uu.ptr,result.ptr) + return result; +end + +""" +Returns the second derivative of a geometry +... +# Arguments +- `obj::Geometry`: a Gismo Geometry +- `u::Matrix{Cdouble}`: a matrix of points +... +""" +function deriv2(obj::Geometry,u::Matrix{Cdouble})::EigenMatrix + @assert Base.size(u,1)==domainDim(obj) "Domain dimension should be equal to the number of rows of the points" + uu = EigenMatrix(Base.size(u,1), Base.size(u,2), pointer(u) ) + result = EigenMatrix() + ccall((:gsFunctionSet_deriv2_into,libgismo),Cvoid, + (Ptr{gsCGeometry},Ptr{gsCMatrix},Ptr{gsCMatrix},), + obj.ptr,uu.ptr,result.ptr) + return result; +end """ Returns the normal of a geometry diff --git a/src/gsMatrix.jl b/src/gsMatrix.jl index 7676fbe..97372e4 100644 --- a/src/gsMatrix.jl +++ b/src/gsMatrix.jl @@ -15,9 +15,9 @@ Creates an empty matrix. # Example -```jldoctest -m = EigenMatrix() -``` +# ```jldoctest +# julia> m = Gismo.EigenMatrix() +# ``` """ mutable struct EigenMatrix ptr::Ptr{gsCMatrix} @@ -48,17 +48,15 @@ mutable struct EigenMatrix end """ - rows(object::EigenMatrix) - Returns the number of rows in the matrix. - +... # Arguments - `object::EigenMatrix`: the matrix - +... # Examples ```jldoctest myEigenMatrix -julia> m = EigenMatrix(3,3) -julia> print(rows(m)) +m = Gismo.EigenMatrix(3,3) +print(Gismo.rows(m)) # output 3 ``` diff --git a/src/gsNurbs.jl b/src/gsNurbs.jl index d865c1c..3c30725 100644 --- a/src/gsNurbs.jl +++ b/src/gsNurbs.jl @@ -21,13 +21,22 @@ export - `a::Vector{Float64}`: the knot vector # Examples -```jldoctest myKnotVector -julia> kv = KnotVector(Float64[0.,0.,0.,0.,0.5,1.,1.,1.,1.]) +```jldoctest myKnotVector; output=(false) +kv = KnotVector(Float64[0.,0.,0.,0.,0.5,1.,1.,1.,1.]) +# output ``` """ mutable struct KnotVector ptr::Ptr{gsCKnotVector} + function KnotVector(knots::Ptr{gsCKnotVector},delete::Bool=true) + b = new(knots) + if (delete) + finalizer(destroy,b) + end + return b + end + function KnotVector(filename::String) g = new(ccall((:gsCReadFile,libgismo),Ptr{gsCKnotVector},(Cstring,),filename) ) finalizer(destroy, g) @@ -56,15 +65,19 @@ Returns the number of elements in the knot vector. - `kv::KnotVector`: the knot vector # Examples -```jldoctest myKnotVector -julia> print(Gismo.size(kv)) -# output -9 -``` +# ```jldoctest myKnotVector +# kv = KnotVector(Float64[0.,0.,0.,0.,0.5,1.,1.,1.,1.]) +# print(Gismo.uSize(kv)) +# # output +# 9 +# ``` """ function size(kv::KnotVector)::Int64 return ccall((:gsKnotVector_size,libgismo),Cint,(Ptr{gsCKnotVector},),kv.ptr) end +function Base.size(kv::KnotVector)::Int64 + return Gismo.size(kv) +end function uSize(kv::KnotVector)::Int64 return ccall((:gsKnotVector_uSize,libgismo),Cint,(Ptr{gsCKnotVector},),kv.ptr) @@ -178,6 +191,14 @@ function TensorBSplineBasis(kv1::KnotVector,kv2::KnotVector,kv3::KnotVector,kv4: return Basis(b) end +function knots(basis::Basis, dir::Cint)::KnotVector + if (domainDim(basis)==1) + kv = ccall((:gsBSplineBasis_knots,libgismo),Ptr{gsCKnotVector},(Ptr{gsCBasis},Cint),basis.ptr,dir) + else + kv = ccall((:gsTensorBSplineBasis_knots,libgismo),Ptr{gsCKnotVector},(Ptr{gsCBasis},Cint),basis.ptr,dir) + end + return KnotVector(kv) +end ######################################################################## # gsTensorBSpline From 45add5e5dbc4e3d86e878f366d2dfe594ee0557a Mon Sep 17 00:00:00 2001 From: Hugo Verhelst Date: Wed, 11 Dec 2024 19:16:36 +0100 Subject: [PATCH 02/16] add Vararg statements in gsNurbs add Fitting add QuadRule add OptionList add Matrix docs (file) add .gitignore fix Multipatch delete --- .gitignore | 1 + cmake/Gismo.jl.in | 18 +++- docs/src/gsMatrix.md | 12 +++ src/Declarations.jl | 16 ++- src/Gismo.jl | 18 +++- src/gsAssembler.jl | 26 +++++ src/gsCore.jl | 2 +- src/gsIO.jl | 47 +++++++++ src/gsModeling.jl | 49 +++++++++ src/gsNurbs.jl | 236 +++++++++++++++++++++++++++---------------- 10 files changed, 327 insertions(+), 98 deletions(-) create mode 100644 .gitignore create mode 100644 docs/src/gsMatrix.md create mode 100644 src/gsAssembler.jl create mode 100644 src/gsIO.jl create mode 100644 src/gsModeling.jl diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..107bb59 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +docs/build/* \ No newline at end of file diff --git a/cmake/Gismo.jl.in b/cmake/Gismo.jl.in index c84a5eb..73250fc 100644 --- a/cmake/Gismo.jl.in +++ b/cmake/Gismo.jl.in @@ -5,17 +5,25 @@ module Gismo # Forward declaration of structs include("Declarations.jl") -# Load gsMatrix -include("gsMatrix.jl") +# Load gsAssembler +include("gsAssembler.jl") # Load gsCore include("gsCore.jl") -# Load gsNurbs -include("gsNurbs.jl") - # Load gsHSplines include("gsHSplines.jl") +# Load gsIO +include("gsIO.jl") + +# Load gsMatrix +include("gsMatrix.jl") + +# Load gsMatrix +include("gsModeling.jl") + +# Load gsNurbs +include("gsNurbs.jl") end #module diff --git a/docs/src/gsMatrix.md b/docs/src/gsMatrix.md new file mode 100644 index 0000000..00dce64 --- /dev/null +++ b/docs/src/gsMatrix.md @@ -0,0 +1,12 @@ +# gsMatrix + +## Function Documentation +```@autodocs +Modules = [Gismo] +Pages = ["src/gsMatrix.jl"] +Order = [:function, :type] +``` + +```@contents +Pages = Main.SUBSECTION_PAGES +``` \ No newline at end of file diff --git a/src/Declarations.jl b/src/Declarations.jl index 91fcf86..3e98955 100644 --- a/src/Declarations.jl +++ b/src/Declarations.jl @@ -2,12 +2,26 @@ # CTypes ######################################################################## +# Matrix mutable struct gsCMatrix end mutable struct gsCMatrixInt end mutable struct gsCVector end + +# Core mutable struct gsCFunctionSet end mutable struct gsCMultiPatch end mutable struct gsCMultiBasis end mutable struct gsCBasis end mutable struct gsCGeometry end -mutable struct gsCKnotVector end \ No newline at end of file + +# NURBS +mutable struct gsCKnotVector end + +# Assembler +mutable struct gsCQuadRule end + +# ΙO +mutable struct gsCOptionList end + +# Modeling +mutable struct gsCFitting end diff --git a/src/Gismo.jl b/src/Gismo.jl index c67b84a..7a04e1e 100644 --- a/src/Gismo.jl +++ b/src/Gismo.jl @@ -5,17 +5,25 @@ import gismo_jll:libgismo # Forward declaration of structs include("Declarations.jl") -# Load gsMatrix -include("gsMatrix.jl") +# Load gsAssembler +include("gsAssembler.jl") # Load gsCore include("gsCore.jl") -# Load gsNurbs -include("gsNurbs.jl") - # Load gsHSplines include("gsHSplines.jl") +# Load gsIO +include("gsIO.jl") + +# Load gsMatrix +include("gsMatrix.jl") + +# Load gsMatrix +include("gsModeling.jl") + +# Load gsNurbs +include("gsNurbs.jl") end #module diff --git a/src/gsAssembler.jl b/src/gsAssembler.jl new file mode 100644 index 0000000..b6ff0db --- /dev/null +++ b/src/gsAssembler.jl @@ -0,0 +1,26 @@ +export + QuadRule + #= TODO =# + +######################################################################## +# gsQuadRule +######################################################################## + +mutable struct QuadRule + ptr::Ptr{gsCQuadRule} + + function QuadRule(quad::Ptr{gsCQuadRule},delete::Bool=true) + b = new(quad) + if (delete) + finalizer(destroy,b) + end + return b + end + + function destroy(qr::QuadRule) + ccall((:gsQuadRule_delete,libgismo),Cvoid,(Ptr{gsCQuadRule},),qr.ptr) + end +end + +Base.show(io::IO, obj::QuadRule) = ccall((:gsQuadRule_print,libgismo),Cvoid,(Ptr{gsCQuadRule},),obj.ptr) + diff --git a/src/gsCore.jl b/src/gsCore.jl index bf190e1..3223de4 100644 --- a/src/gsCore.jl +++ b/src/gsCore.jl @@ -544,7 +544,7 @@ mutable struct MultiPatch end function destroy(m::MultiPatch) - ccall((:gsMultiPatch_delete,libgismo),Cvoid,(Ptr{gsCFunctionSet},),m.ptr) + ccall((:gsFunctionSet_delete,libgismo),Cvoid,(Ptr{gsCFunctionSet},),m.ptr) end end diff --git a/src/gsIO.jl b/src/gsIO.jl new file mode 100644 index 0000000..5720a63 --- /dev/null +++ b/src/gsIO.jl @@ -0,0 +1,47 @@ +export + OptionList + #= TODO =# + +######################################################################## +# gsOptionList +######################################################################## + +mutable struct OptionList + ptr::Ptr{gsCOptionList} + + function OptionList(opt::Ptr{gsCOptionList},delete::Bool=true) + b = new(opt) + if (delete) + finalizer(destroy,b) + end + return b + end + + function OptionList(options::Dict) + opt = ccall((:gsOptionList_new,libgismo),Ptr{gsCOptionList},(),) + # Empty string + desc::String = "" + for (key,value) in options + if (typeof(value) == String) + ccall((:gsOptionList_addString,libgismo),Cvoid,(Ptr{gsCOptionList},Cstring,Cstring,Cstring),opt,key,desc,value) + elseif (typeof(value) == Int) + ccall((:gsOptionList_addInr,libgismo),Cvoid,(Ptr{gsCOptionList},Cstring,Cstring,Cint),opt,key,desc,value) + elseif (typeof(value) == Float64) + ccall((:gsOptionList_addReal,libgismo),Cvoid,(Ptr{gsCOptionList},Cstring,Cstring,Cdouble),opt,key,desc,value) + elseif (typeof(value) == Bool) + ccall((:gsOptionList_addSwitch,libgismo),Cvoid,(Ptr{gsCOptionList},Cstring,Cstring,Cint),opt,key,desc,Int(value)) + else + error("OptionList: Unsupported type for value") + end + end + return OptionList(opt) + end + + function destroy(opt::OptionList) + ccall((:gsOptionList_delete,libgismo),Cvoid,(Ptr{gsCOptionList},),opt.ptr) + end +end + +Base.show(io::IO, obj::OptionList) = ccall((:gsOptionList_print,libgismo),Cvoid,(Ptr{gsCOptionList},),obj.ptr) + + diff --git a/src/gsModeling.jl b/src/gsModeling.jl new file mode 100644 index 0000000..4042ac1 --- /dev/null +++ b/src/gsModeling.jl @@ -0,0 +1,49 @@ +export + Fitting + #= TODO =# + +######################################################################## +# gsFitting +######################################################################## + +mutable struct Fitting + ptr::Ptr{gsCFitting} + + function Fitting(opt::Ptr{gsCFitting},delete::Bool=true)::Fitting + b = new(opt) + if (delete) + finalizer(destroy,b) + end + return b + end + + function Fitting(parValues::Matrix{Cdouble}, pts::Matrix{Cdouble}, basis::Basis)::Fitting + @assert Base.size(parValues,2) == Base.size(pts,2) "Fitting: parValues and points must have the same number of columns" + param_values = EigenMatrix(Base.size(parValues,1),Base.size(parValues,2),pointer(parValues)) + points = EigenMatrix(Base.size(pts,1),Base.size(pts,2),pointer(pts)) + fitter = ccall((:gsFitting_create,libgismo),Ptr{gsCFitting},(Ptr{EigenMatrix},Ptr{EigenMatrix},Ptr{gsCBasis}),param_values.ptr,points.ptr,basis.ptr) + return Fitting(fitter) + end + + function destroy(fit::Fitting) + ccall((:gsFitting_delete,libgismo),Cvoid,(Ptr{gsCFitting},),fit.ptr) + end +end + +function compute(fit::Fitting, lambda::Cdouble=0.0) + ccall((:gsFitting_compute,libgismo),Cvoid,(Ptr{gsCFitting},Cdouble),fit.ptr,lambda) +end + +#= TODO: + gsFitting_parameterCorrection + gsFitting_computeErrors + gsFitting_minPointError + gsFitting_maxPointError + gsFitting_pointWiseErrors + gsFitting_numPointsBelow + =# + +function result(fit::Fitting)::Geometry + geom = ccall((:gsFitting_result,libgismo),Ptr{gsCGeometry},(Ptr{gsCFitting},),fit.ptr) + return Geometry(geom) +end \ No newline at end of file diff --git a/src/gsNurbs.jl b/src/gsNurbs.jl index 3c30725..ac642c3 100644 --- a/src/gsNurbs.jl +++ b/src/gsNurbs.jl @@ -4,6 +4,7 @@ export BSpline, TensorBSplineBasis, TensorBSpline + #= TODO =# ######################################################################## # gsKnotVector @@ -140,54 +141,33 @@ end Defines a 2D tensor B-spline basis. # Arguments -- `kv1::KnotVector`: the first knot vector -- `kv2::KnotVector`: the second knot vector +- `kv::KnotVector`: the knot vectors """ -function TensorBSplineBasis(kv1::KnotVector,kv2::KnotVector)::Basis - b = ccall((:gsTensorBSplineBasis2_create,libgismo),Ptr{gsCBasis},(Ptr{gsCKnotVector},Ptr{gsCKnotVector},),kv1.ptr,kv2.ptr) - return Basis(b) -end - -""" - TensorBSplineBasis(kv1::KnotVector,kv2::KnotVector,kv3::KnotVector) - -Defines a 3D tensor B-spline basis. - -# Arguments -- `kv1::KnotVector`: the first knot vector -- `kv2::KnotVector`: the second knot vector -- `kv3::KnotVector`: the third knot vector -""" -function TensorBSplineBasis(kv1::KnotVector,kv2::KnotVector,kv3::KnotVector)::Basis - b = ccall((:gsTensorBSplineBasis3_create,libgismo),Ptr{gsCBasis},(Ptr{gsCKnotVector}, +function TensorBSplineBasis(kv::Vararg{KnotVector})::Basis + d = Base.length(kv) + if (d==1) + b = ccall((:gsBSplineBasis_create,libgismo),Ptr{gsCBasis},(Ptr{gsCKnotVector},),kv[1].ptr) + elseif (d==2) + b = ccall((:gsTensorBSplineBasis2_create,libgismo),Ptr{gsCBasis},(Ptr{gsCKnotVector},Ptr{gsCKnotVector},),kv[1].ptr,kv[2].ptr) + elseif (d==3) + b = ccall((:gsTensorBSplineBasis3_create,libgismo),Ptr{gsCBasis},(Ptr{gsCKnotVector}, Ptr{gsCKnotVector}, Ptr{gsCKnotVector},), - kv1.ptr, - kv2.ptr, - kv3.ptr) - return Basis(b) -end - -""" - TensorBSplineBasis(kv1::KnotVector,kv2::KnotVector,kv3::KnotVector,kv4::KnotVector) - -Defines a 4D tensor B-spline basis. - -# Arguments -- `kv1::KnotVector`: the first knot vector -- `kv2::KnotVector`: the second knot vector -- `kv3::KnotVector`: the third knot vector -- `kv4::KnotVector`: the fourth knot vector -""" -function TensorBSplineBasis(kv1::KnotVector,kv2::KnotVector,kv3::KnotVector,kv4::KnotVector)::Basis - b = ccall((:gsTensorBSplineBasis3_create,libgismo),Ptr{gsCBasis},(Ptr{gsCKnotVector}, + kv[1].ptr, + kv[2].ptr, + kv[3].ptr) + elseif (d==4) + b = ccall((:gsTensorBSplineBasis4_create,libgismo),Ptr{gsCBasis},(Ptr{gsCKnotVector}, Ptr{gsCKnotVector}, Ptr{gsCKnotVector}, Ptr{gsCKnotVector},), - kv1.ptr, - kv2.ptr, - kv3.ptr, - kv4.ptr) + kv[1].ptr, + kv[2].ptr, + kv[3].ptr, + kv[4].ptr) + else + error("TensorBSplineBasis not implemented for this dimension") + end return Basis(b) end @@ -284,58 +264,35 @@ end Defines a 2D tensor NURBS basis. # Arguments -- `kv1::KnotVector`: the first knot vector -- `kv2::KnotVector`: the second knot vector -""" -function TensorNurbsBasis(kv1::KnotVector,kv2::KnotVector)::Basis - b = ccall((:gsTensorNurbsBasis2_create,libgismo),Ptr{gsCBasis},(Ptr{gsCKnotVector},Ptr{gsCKnotVector},),kv1.ptr,kv2.ptr) - return Basis(b) -end - -""" - TensorNurbsBasis(kv1::KnotVector,kv2::KnotVector,kv3::KnotVector) - -Defines a 3D tensor NURBS basis. - -# Arguments -- `kv1::KnotVector`: the first knot vector -- `kv2::KnotVector`: the second knot vector -- `kv3::KnotVector`: the third knot vector +- `kv::KnotVector`: knot vectors """ -function TensorNurbsBasis(kv1::KnotVector,kv2::KnotVector,kv3::KnotVector)::Basis - b = ccall((:gsTensorNurbsBasis3_create,libgismo),Ptr{gsCBasis},(Ptr{gsCKnotVector}, +function TensorNurbsBasis(kv::Vararg{KnotVector})::Basis + d = Base.length(kv) + if (d==1) + b = ccall((:gsNurbsBasis_create,libgismo),Ptr{gsCBasis},(Ptr{gsCKnotVector},),kv[1].ptr) + elseif (d==2) + b = ccall((:gsTensorNurbsBasis2_create,libgismo),Ptr{gsCBasis},(Ptr{gsCKnotVector},Ptr{gsCKnotVector},),kv[1].ptr,kv[2].ptr) + elseif (d==3) + b = ccall((:gsTensorNurbsBasis3_create,libgismo),Ptr{gsCBasis},(Ptr{gsCKnotVector}, Ptr{gsCKnotVector}, Ptr{gsCKnotVector},), - kv1.ptr, - kv2.ptr, - kv3.ptr) - return Basis(b) -end - -""" - TensorNurbsBasis(kv1::KnotVector,kv2::KnotVector,kv3::KnotVector,kv4::KnotVector) - -Defines a 4D tensor NURBS basis. - -# Arguments -- `kv1::KnotVector`: the first knot vector -- `kv2::KnotVector`: the second knot vector -- `kv3::KnotVector`: the third knot vector -- `kv4::KnotVector`: the fourth knot vector -""" -function TensorNurbsBasis(kv1::KnotVector,kv2::KnotVector,kv3::KnotVector,kv4::KnotVector)::Basis - b = ccall((:gsTensorNurbsBasis3_create,libgismo),Ptr{gsCBasis},(Ptr{gsCKnotVector}, + kv[1].ptr, + kv[2].ptr, + kv[3].ptr) + elseif (d==4) + b = ccall((:gsTensorNurbsBasis4_create,libgismo),Ptr{gsCBasis},(Ptr{gsCKnotVector}, Ptr{gsCKnotVector}, Ptr{gsCKnotVector}, Ptr{gsCKnotVector},), - kv1.ptr, - kv2.ptr, - kv3.ptr, - kv4.ptr) - return Basis(b) + kv[1].ptr, + kv[2].ptr, + kv[3].ptr, + kv[4].ptr) + else + error("TensorNurbsBasis not implemented for this dimension") + end end - ######################################################################## # gsTensorNurbs ######################################################################## @@ -369,3 +326,110 @@ function TensorNurbs(basis::Basis,coefs::Matrix{Cdouble})::Geometry end return Geometry(g) end + +######################################################################## +# gsNurbsCreator +######################################################################## + +function BSplineUnitInterval(deg::Cint)::Geometry + g = ccall((:gsNurbsCreator_BSplineUnitInterval,libgismo),Ptr{gsCGeometry},(Cint,),deg) + return Geometry(g) +end + +function BSplineRectangle(low_x::Cdouble=0.0, + low_y::Cdouble=0.0, + upp_x::Cdouble=1.0, + upp_y::Cdouble=1.0, + turndeg::Cdouble=0.0)::Geometry + g = ccall((:gsNurbsCreator_BSplineRectangle,libgismo),Ptr{gsCGeometry},(Cdouble,Cdouble,Cdouble,Cdouble,Cdouble),low_x,low_y,upp_x,upp_y,turndeg) + return Geometry(g) +end + +function BSplineTrapezium(Lbot::Cdouble=1.0, + Ltop::Cdouble=0.5, + H::Cdouble=1.0, + d::Cdouble=0.0, + turndeg::Cdouble=0.0)::Geometry + g = ccall((:gsNurbsCreator_BSplineTrapezium,libgismo),Ptr{gsCGeometry},(Cdouble,Cdouble,Cdouble,Cdouble,Cdouble),Lbot,Ltop,H,d,turndeg) + return Geometry(g) +end + +function BSplineSquare(r::Cdouble=1.0, + x::Cdouble=0.0, + y::Cdouble=0.0)::Geometry + g = ccall((:gsNurbsCreator_BSplineSquare,libgismo),Ptr{gsCGeometry},(Cdouble,Cdouble,Cdouble),r,x,y) + return Geometry(g) +end + +function BSplineSquareGrid(n::Cint, + m::Cint, + r::Cdouble=1.0, + lx::Cdouble=0.0, + ly::Cdouble=0.0)::MultiPatch + g = ccall((:gsNurbsCreator_BSplineSquareGrid,libgismo),Ptr{gsCMultiPatch},(Cint,Cint,Cdouble,Cdouble,Cdouble),n,m,r,lx,ly) + return MultiPatch(g) +end + +function BSplineCube(r::Cdouble=1.0, + x::Cdouble=0.0, + y::Cdouble=0.0, + z::Cdouble=0.0)::Geometry + g = ccall((:gsNurbsCreator_BSplineCube,libgismo),Ptr{gsCGeometry},(Cdouble,Cdouble,Cdouble,Cdouble),r,x,y,z) + return Geometry(g) +end + +function BSplineCubeGrid(n::Cint, + m::Cint, + p::Cint, + r::Cdouble=1.0, + lx::Cdouble=0.0, + ly::Cdouble=0.0, + lz::Cdouble=0.0)::MultiPatch + g = ccall((:gsNurbsCreator_BSplineCubeGrid,libgismo),Ptr{gsCMultiPatch},(Cint,Cint,Cint,Cdouble,Cdouble,Cdouble,Cdouble),n,m,p,r,lx,ly,lz) + return MultiPatch(g) +end + +function NurbsQuarterAnnulus(r1::Cdouble=1.0, + r2::Cdouble=2.0)::Geometry + g = ccall((:gsNurbsCreator_NurbsQuarterAnnulus,libgismo),Ptr{gsCGeometry},(Cdouble,Cdouble),r1,r2) + return Geometry(g) +end + +function NurbsAnnulus(r1::Cdouble=1.0, + r2::Cdouble=2.0)::Geometry + g = ccall((:gsNurbsCreator_NurbsAnnulus,libgismo),Ptr{gsCGeometry},(Cdouble,Cdouble),r1,r2) + return Geometry(g) +end + +function BSplineSaddle()::Geometry + g = ccall((:gsNurbsCreator_BSplineSaddle,libgismo),Ptr{gsCGeometry},(),) + return Geometry(g) +end + +function NurbsSphere(r::Cdouble=1.0, + x::Cdouble=0.0, + y::Cdouble=0.0, + z::Cdouble=0.0)::Geometry + g = ccall((:gsNurbsCreator_NurbsSphere,libgismo),Ptr{gsCGeometry},(Cdouble,Cdouble,Cdouble,Cdouble),r,x,y,z) + return Geometry(g) +end + +function NurbsCircle(r::Cdouble=1.0, + x::Cdouble=0.0, + y::Cdouble=0.0)::Geometry + g = ccall((:gsNurbsCreator_NurbsCircle,libgismo),Ptr{gsCGeometry},(Cdouble,Cdouble,Cdouble),r,x,y) + return Geometry(g) +end + +function BSplineTriangle(H::Cdouble=1.0, + W::Cdouble=1.0)::Geometry + g = ccall((:gsNurbsCreator_BSplineTriangle,libgismo),Ptr{gsCGeometry},(Cdouble,Cdouble),H,W) + return Geometry(g) +end + +function BSplineStar(N::Cint=3, + R0::Cdouble=1.0, + R1::Cdouble=0.5)::MultiPatch + g = ccall((:gsNurbsCreator_BSplineStar,libgismo),Ptr{gsCMultiPatch},(Cint,Cdouble,Cdouble),N,R0,R1) + return MultiPatch(g) +end \ No newline at end of file From 3e871a02f6b4c7f806cb8aff602147129ee0f62b Mon Sep 17 00:00:00 2001 From: Albe2107200 <76699437+Albe21072000@users.noreply.github.com.> Date: Thu, 12 Dec 2024 16:31:12 +0100 Subject: [PATCH 03/16] updated fitting and solved eval warning --- examples/BSpline_example.jl | 3 +- examples/THBSpline_example.jl | 2 +- examples/TensorBSpline_example.jl | 2 +- examples/fitting_example.jl | 43 +++++++++ examples/gismo_example.jl | 10 +-- src/Gismo.jl | 2 +- src/gsCore.jl | 13 +-- src/gsModeling.jl | 141 ++++++++++++++++++++++++++++-- 8 files changed, 189 insertions(+), 27 deletions(-) create mode 100644 examples/fitting_example.jl diff --git a/examples/BSpline_example.jl b/examples/BSpline_example.jl index 748adc1..fc9f71a 100644 --- a/examples/BSpline_example.jl +++ b/examples/BSpline_example.jl @@ -14,7 +14,7 @@ B = Gismo.BSpline(BB,coefs) # Create a matrix of linearly spaced evaluation points points1D = zeros(1,100) points1D[1,:] = range(0,stop=1,length=100) -ev = Gismo.asMatrix(Gismo.eval(B,points1D)) +ev = Gismo.asMatrix(Gismo.val(B,points1D)) # Plot the geometry plot(ev[1,:],ev[2,:],legend=false) @@ -22,4 +22,3 @@ plot!(coefs[:,1],coefs[:,2],legend=false) plot!(coefs[:,1],coefs[:,2],legend=false,seriestype=:scatter) gui() - diff --git a/examples/THBSpline_example.jl b/examples/THBSpline_example.jl index d4a60c4..723a012 100644 --- a/examples/THBSpline_example.jl +++ b/examples/THBSpline_example.jl @@ -26,7 +26,7 @@ points2D = zeros(2,N*N) points2D[1,:] = repeat(points1D, N) points2D[2,:] = repeat(points1D, inner=N) -ev = Gismo.asMatrix(Gismo.eval(TB,points2D)) +ev = Gismo.asMatrix(Gismo.val(TB,points2D)) # Plot the geometry surface!(ev[1,:],ev[2,:],ev[3,:],legend=false) diff --git a/examples/TensorBSpline_example.jl b/examples/TensorBSpline_example.jl index ef848f7..62e1a36 100644 --- a/examples/TensorBSpline_example.jl +++ b/examples/TensorBSpline_example.jl @@ -21,7 +21,7 @@ points2D = zeros(2,N*N) points2D[1,:] = repeat(points1D, N) points2D[2,:] = repeat(points1D, inner=N) -ev = Gismo.asMatrix(Gismo.eval(TB,points2D)) +ev = Gismo.asMatrix(Gismo.val(TB,points2D)) # Plot the geometry surface!(ev[1,:],ev[2,:],ev[3,:],legend=false) diff --git a/examples/fitting_example.jl b/examples/fitting_example.jl new file mode 100644 index 0000000..b656de3 --- /dev/null +++ b/examples/fitting_example.jl @@ -0,0 +1,43 @@ +using Gismo +using DelimitedFiles +using Plots + +# Create the knot vector +KV = Gismo.KnotVector([0.,0.,0.,1.,1.,1.]) +# Load the points and their parameters +pars_file::String = "../try_gismo/julia/filedata/shiphull_pars.csv" +points_file::String = "../try_gismo/julia/filedata/shiphull_points.csv" +pars = readdlm(pars_file, ',', Float64) +points = readdlm(points_file, ',', Float64) +# Define the basis using the knots +BB2 = Gismo.TensorBSplineBasis(KV,KV) +# Create the fitter +fitter = Gismo.Fitting(pars,points,BB2) +# Perform the least squares error approssimation +Gismo.compute(fitter) +# Compute the errors +Gismo.computeErrors(fitter) +# Display the outputs +println(Gismo.minPointError(fitter)) +println(Gismo.maxPointError(fitter)) +println(Gismo.pointWiseErrors(fitter)) +println(unsafe_wrap(Vector{Float64}, Gismo.pointWiseErrors(fitter), 264, own=false)) +println(Gismo.numPointsBelow(fitter, 0.02)) +# Obtain the geometry +geo = Gismo.result(fitter) +# Create a matrix of linearly spaced evaluation points +N = 10 +points1D = range(0,stop=1,length=N) +points2D = zeros(2,N*N) +# Create a meshgrid of evaluation points +points2D[1,:] = repeat(points1D, N) +points2D[2,:] = repeat(points1D, inner=N) + +ev = Gismo.asMatrix(Gismo.val(geo,points2D)) + +# Plot the geometry +surface!(ev[1,:],ev[2,:],ev[3,:],legend=false) +gui() +# Press enter to exit +println("Press enter to exit!") +readline() \ No newline at end of file diff --git a/examples/gismo_example.jl b/examples/gismo_example.jl index 5b1cf2a..5cb3388 100644 --- a/examples/gismo_example.jl +++ b/examples/gismo_example.jl @@ -21,7 +21,7 @@ println("Evaluation points:") display(pts) println("Evaluation result:") -values = Gismo.eval(geom,pts) +values = Gismo.val(geom,pts) println("Rows: ", Gismo.rows(values) ) println("Cols: ", Gismo.cols(values) ) @@ -43,7 +43,7 @@ display(Gismo.asMatrix(par)) # println("Basis:") # println(basis) -# values = Gismo.eval(basis,pts) +# values = Gismo.val(basis,pts) # println("Rows: ", Gismo.rows(values) ) # println("Cols: ", Gismo.cols(values) ) # vals = Gismo.asMatrix(values) @@ -54,7 +54,7 @@ basis = Gismo.TensorBSplineBasis(kv,kv) println("Basis:") println(basis) -values = Gismo.eval(basis,pts) +values = Gismo.val(basis,pts) println("Rows: ", Gismo.rows(values) ) println("Cols: ", Gismo.cols(values) ) vals = Gismo.asMatrix(values) @@ -62,7 +62,7 @@ display(vals) coefs = rand(Gismo.size(basis),3) geom = Gismo.TensorBSpline(basis,coefs) -values = Gismo.eval(geom,pts) +values = Gismo.val(geom,pts) println("Rows: ", Gismo.rows(values) ) println("Cols: ", Gismo.cols(values) ) vals = Gismo.asMatrix(values) @@ -77,7 +77,7 @@ display(Gismo.actives(basis,pts)) display(Gismo.asMatrix(Gismo.coefs(geom))) Gismo.THBSplineBasis(basis) -values = Gismo.eval(basis,pts) +values = Gismo.val(basis,pts) println("Rows: ", Gismo.rows(values) ) println("Cols: ", Gismo.cols(values) ) vals = Gismo.asMatrix(values) diff --git a/src/Gismo.jl b/src/Gismo.jl index 7a04e1e..09185fa 100644 --- a/src/Gismo.jl +++ b/src/Gismo.jl @@ -1,6 +1,6 @@ module Gismo -import gismo_jll:libgismo +libgismo = "/Users/none/gismo2/gismo/build/lib/libgismo" # Forward declaration of structs include("Declarations.jl") diff --git a/src/gsCore.jl b/src/gsCore.jl index 3223de4..25906b5 100644 --- a/src/gsCore.jl +++ b/src/gsCore.jl @@ -9,7 +9,7 @@ export uniformRefine, refineElements, actives, - eval, + val, Geometry, basis, coefs, @@ -219,7 +219,7 @@ Returns the evaluation of a basis - `u::Matrix{Cdouble}`: a matrix of points ... """ -function eval(obj::Basis,u::Matrix{Cdouble})::EigenMatrix +function val(obj::Basis,u::Matrix{Cdouble})::EigenMatrix @assert Base.size(u,1)==domainDim(obj) "Domain dimension should be equal to the number of rows of the points" uu = EigenMatrix(Base.size(u,1), Base.size(u,2), pointer(u) ) result = EigenMatrix() @@ -228,9 +228,7 @@ function eval(obj::Basis,u::Matrix{Cdouble})::EigenMatrix obj.ptr,uu.ptr,result.ptr) return result; end -function Base.eval(obj::Basis,u::Matrix{Cdouble})::EigenMatrix - return Gismo.eval(obj,u) -end + """ Returns the derivative of a basis @@ -418,7 +416,7 @@ Returns the evaluation of a geometry - `u::Matrix{Cdouble}`: a matrix of points ... """ -function eval(obj::Geometry,u::Matrix{Cdouble})::EigenMatrix +function val(obj::Geometry,u::Matrix{Cdouble})::EigenMatrix @assert Base.size(u,1)==domainDim(obj) "Domain dimension should be equal to the number of rows of the points" uu = EigenMatrix(Base.size(u,1), Base.size(u,2), pointer(u) ) result = EigenMatrix() @@ -427,9 +425,6 @@ function eval(obj::Geometry,u::Matrix{Cdouble})::EigenMatrix obj.ptr,uu.ptr,result.ptr) return result; end -function Base.eval(obj::Geometry,u::Matrix{Cdouble})::EigenMatrix - return Gismo.eval(obj,u) -end """ Returns the derivative of a geometry diff --git a/src/gsModeling.jl b/src/gsModeling.jl index 4042ac1..ded221b 100644 --- a/src/gsModeling.jl +++ b/src/gsModeling.jl @@ -6,9 +6,20 @@ export # gsFitting ######################################################################## +""" + Creates a fitting structure +""" mutable struct Fitting ptr::Ptr{gsCFitting} + """ + Fitting(opt::Ptr{gsCFitting},delete:Bool) + ... + # Arguments + - `opt::Ptr{gsCFitting}`: A pointer to a gsCFiting object + - `delete::Bool`: Whether to destroy the fitting structure when unused + ... + """ function Fitting(opt::Ptr{gsCFitting},delete::Bool=true)::Fitting b = new(opt) if (delete) @@ -17,6 +28,15 @@ mutable struct Fitting return b end + """ + Fitting(parValues::Matrix{Cdouble}, pts::Matrix{Cdouble}, basis::Basis)::Fitting + ... + # Arguments + - `parValues::Matrix{Cdouble}`: a matrix containing the parameters values + - `pts::Matrix{Cdouble}`: a matrix of points + - `basis::Basis`: a Basis structure containing the desired basis + ... + """ function Fitting(parValues::Matrix{Cdouble}, pts::Matrix{Cdouble}, basis::Basis)::Fitting @assert Base.size(parValues,2) == Base.size(pts,2) "Fitting: parValues and points must have the same number of columns" param_values = EigenMatrix(Base.size(parValues,1),Base.size(parValues,2),pointer(parValues)) @@ -30,19 +50,124 @@ mutable struct Fitting end end + +""" +compute(fit::Fitting, lambda::Cdouble=0.0) +Computes the least squares fit +... +# Arguments +- `fit::Fitting`: a fitting structure +- `lambda::Cdouble`: the value to assign to the lambda ridge parameter +... +""" function compute(fit::Fitting, lambda::Cdouble=0.0) ccall((:gsFitting_compute,libgismo),Cvoid,(Ptr{gsCFitting},Cdouble),fit.ptr,lambda) end -#= TODO: - gsFitting_parameterCorrection - gsFitting_computeErrors - gsFitting_minPointError - gsFitting_maxPointError - gsFitting_pointWiseErrors - gsFitting_numPointsBelow - =# +""" +parameterCorrection(fit::Fitting, accuracy::Cdouble, maxIter::Cint, tol0rth::Cdouble) +Performs the parameters corrections step +... +# Arguments +- `fit::Fitting`: a fitting structure +- `accuracy::Cdouble`: The desired accuracy +- `maxIter::Cint`: The desired number of iterations +- `tol0rth::Cdouble`: The desired value of the tolleance +... +""" +function parameterCorrection(fit::Fitting, accuracy::Cdouble, maxIter::Cint, tol0rth::Cdouble) + @assert maxIter >= 0 "Fitting: cannot have a negative number of iterations!" + @assert accuracy >= 0 "Fitting: cannot have a negative accuracy!" + ccall((:gsFitting_parameterCorrection,libgismo),Cvoid,(Ptr{gsCFitting},Cdouble,Cint,Cdouble),fit.ptr,accuracy,maxIter,tol0rth) +end + +""" +computeErrors(fit::Fitting) +Computes the error for each point +... +# Arguments +- `fit::Fitting`: a fitting structure +... +""" +function computeErrors(fit::Fitting) + ccall((:gsFitting_computeErrors,libgismo),Cvoid,(Ptr{gsCFitting},),fit.ptr) +end + +""" +minPointError(fit::Fitting)::Cdouble +Returns the smallest error obtained between all the points +... +# Arguments +- `fit::Fitting`: a fitting structure +# Return +- `min_error::Cdouble`: The minimum error obtained +... +""" +function minPointError(fit::Fitting)::Cdouble + min_error=ccall((:gsFitting_minPointError,libgismo),Cdouble,(Ptr{gsCFitting},),fit.ptr) + return min_error +end + +""" +maxPointError(fit::Fitting)::Cdouble +Returns the maximum error obtained +... +# Arguments +- `fit::Fitting`: a fitting structure +# Return +- `max_error::Cdouble`: The maximum error obtained +... +""" +function maxPointError(fit::Fitting)::Cdouble + max_err=ccall((:gsFitting_maxPointError,libgismo),Cdouble,(Ptr{gsCFitting},),fit.ptr) + return max_err +end + +""" +pointWiseErrors(fit::Fitting)::Ptr{Cdouble} +Returns the error obtained for each point +... +# Arguments +- `fit::Fitting`: a fitting structure +... +# Return +- `errors::Ptr{Cdouble}`: Pointer pointing to an array containing the error value for each point +... +""" +function pointWiseErrors(fit::Fitting)::Ptr{Cdouble} + errors=ccall((:gsFitting_pointWiseErrors,libgismo),Ptr{Cdouble},(Ptr{gsCFitting},),fit.ptr) + return errors +end + +""" +numPointsBelow(fit::Fitting, threshold::Cdouble)::Cint +Returns the number of points where the error is below the threshold +... +# Arguments +- `fit::Fitting`: a fitting structure +- `threshold::Cdouble`: The desired threshold +... +# Return +- `number_pts_blw::Cint`: number of points where the error is below the given threshold +... +""" +function numPointsBelow(fit::Fitting, threshold::Cdouble)::Cint + @assert threshold >= 0 "The threshold must be a positive real number!" + number_pts_blw=ccall((:gsFitting_numPointsBelow,libgismo),Cint,(Ptr{gsCFitting},Cdouble),fit.ptr,threshold) + return number_pts_blw +end +""" +result(fit::Fitting)::Geometry +Returns a geometry from the fitting structure +... +# Arguments +- `fit::Fitting`: a fitting structure +... +# Return +- `geom::Geometry`: the desired geometry +... +""" function result(fit::Fitting)::Geometry geom = ccall((:gsFitting_result,libgismo),Ptr{gsCGeometry},(Ptr{gsCFitting},),fit.ptr) return Geometry(geom) From 665fdf30e8cb97fba9224fac5b5d07ec375d7184 Mon Sep 17 00:00:00 2001 From: Alberto Biliotti <76699437+Albe21072000@users.noreply.github.com> Date: Thu, 12 Dec 2024 16:34:51 +0100 Subject: [PATCH 04/16] Update Gismo.jl --- src/Gismo.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Gismo.jl b/src/Gismo.jl index 09185fa..7a04e1e 100644 --- a/src/Gismo.jl +++ b/src/Gismo.jl @@ -1,6 +1,6 @@ module Gismo -libgismo = "/Users/none/gismo2/gismo/build/lib/libgismo" +import gismo_jll:libgismo # Forward declaration of structs include("Declarations.jl") From e213b941ad588057b0203d15e8d0c3f0f76cb702 Mon Sep 17 00:00:00 2001 From: Albe2107200 <76699437+Albe21072000@users.noreply.github.com.> Date: Fri, 13 Dec 2024 11:03:22 +0100 Subject: [PATCH 05/16] update tests to use val instead of eval --- test/runbenchmarks.jl | 2 +- test/runtests.jl | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/runbenchmarks.jl b/test/runbenchmarks.jl index 82bf2b1..83119ea 100644 --- a/test/runbenchmarks.jl +++ b/test/runbenchmarks.jl @@ -10,7 +10,7 @@ coefs = rand(Gismo.size(TBB),3) TB = Gismo.TensorBSpline(TBB,coefs) display(@benchmark normal(TB,rand(Float64, (2, 1)))) -display(@benchmark Gismo.eval(TB,rand(Float64, (2, 1)))) +display(@benchmark Gismo.val(TB,rand(Float64, (2, 1)))) diff --git a/test/runtests.jl b/test/runtests.jl index 6d40605..29877d6 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -65,8 +65,8 @@ using Test points2D = zeros(2,N*N) points2D[1,:] = repeat(points1D, N) points2D[2,:] = repeat(points1D, inner=N) - @test_nowarn(ev = Gismo.asMatrix(Gismo.eval(TB,points2D))) - @test_nowarn(ev = Gismo.asMatrix(Gismo.eval(THB,points2D))) + @test_nowarn(ev = Gismo.asMatrix(Gismo.val(TB,points2D))) + @test_nowarn(ev = Gismo.asMatrix(Gismo.val(THB,points2D))) end end end \ No newline at end of file From feab0e562be3efc333cb685f270a749aa94f59a9 Mon Sep 17 00:00:00 2001 From: Albe2107200 <76699437+Albe21072000@users.noreply.github.com.> Date: Fri, 13 Dec 2024 23:50:35 +0100 Subject: [PATCH 06/16] Update the names of some methods to respect the ! notation and add the export of all the structures and methods --- examples/BSpline_example.jl | 15 +++-- examples/THBSpline_example.jl | 25 +++---- examples/TensorBSpline_example.jl | 17 ++--- examples/fitting_example.jl | 24 +++---- examples/gismo_example.jl | 104 +++++++++++++++--------------- src/Gismo.jl | 2 +- src/gsAssembler.jl | 8 ++- src/gsCore.jl | 49 ++++++++------ src/gsHSplines.jl | 3 +- src/gsIO.jl | 6 +- src/gsMatrix.jl | 32 +++++---- src/gsModeling.jl | 27 +++++--- src/gsNurbs.jl | 34 ++++++++-- test/runbenchmarks.jl | 14 ++-- test/runtests.jl | 67 +++++++++---------- 15 files changed, 244 insertions(+), 183 deletions(-) diff --git a/examples/BSpline_example.jl b/examples/BSpline_example.jl index fc9f71a..8ea9205 100644 --- a/examples/BSpline_example.jl +++ b/examples/BSpline_example.jl @@ -1,20 +1,21 @@ using Plots using Gismo +import Gismo.size -KV = Gismo.KnotVector([0.,0.,0.,1.,1.,1.]) -BB = Gismo.BSplineBasis(KV) -Gismo.uniformRefine(BB) -Gismo.uniformRefine(BB) +KV = KnotVector([0.,0.,0.,1.,1.,1.]) +BB = BSplineBasis(KV) +uniformRefine!(BB) +uniformRefine!(BB) # Create a matrix of random coefficients -coefs = rand(Gismo.size(BB),2) +coefs = rand(size(BB),2) # Create a BSpline geometry -B = Gismo.BSpline(BB,coefs) +B = BSpline(BB,coefs) # Create a matrix of linearly spaced evaluation points points1D = zeros(1,100) points1D[1,:] = range(0,stop=1,length=100) -ev = Gismo.asMatrix(Gismo.val(B,points1D)) +ev = asMatrix(val(B,points1D)) # Plot the geometry plot(ev[1,:],ev[2,:],legend=false) diff --git a/examples/THBSpline_example.jl b/examples/THBSpline_example.jl index 723a012..eee3b44 100644 --- a/examples/THBSpline_example.jl +++ b/examples/THBSpline_example.jl @@ -1,21 +1,22 @@ using Plots using Gismo - -KV = Gismo.KnotVector([0.,0.,0.,1.,1.,1.]) -TBB = Gismo.TensorBSplineBasis(KV,KV) -print("The size of the basis is: ",Gismo.size(TBB),"\n") -Gismo.uniformRefine(TBB) -print("The size of the basis is: ",Gismo.size(TBB),"\n") -THB = Gismo.THBSplineBasis(TBB) +import Gismo.size + +KV = KnotVector([0.,0.,0.,1.,1.,1.]) +TBB = TensorBSplineBasis(KV,KV) +print("The size of the basis is: ",size(TBB),"\n") +uniformRefine!(TBB) +print("The size of the basis is: ",size(TBB),"\n") +THB = THBSplineBasis(TBB) boxes = Vector{Int32}([1,0,0,2,2]) -Gismo.refineElements(THB,boxes) +refineElements!(THB,boxes) -print("The size of the basis is: ",Gismo.size(THB),"\n") +print("The size of the basis is: ",size(THB),"\n") # Create a matrix of random coefficients -coefs = rand(Gismo.size(TBB),3) +coefs = rand(size(TBB),3) # Create a BSpline geometry -TB = Gismo.TensorBSpline(TBB,coefs) +TB = TensorBSpline(TBB,coefs) # Create a matrix of linearly spaced evaluation points N = 10 @@ -26,7 +27,7 @@ points2D = zeros(2,N*N) points2D[1,:] = repeat(points1D, N) points2D[2,:] = repeat(points1D, inner=N) -ev = Gismo.asMatrix(Gismo.val(TB,points2D)) +ev = asMatrix(val(TB,points2D)) # Plot the geometry surface!(ev[1,:],ev[2,:],ev[3,:],legend=false) diff --git a/examples/TensorBSpline_example.jl b/examples/TensorBSpline_example.jl index 62e1a36..52c40f9 100644 --- a/examples/TensorBSpline_example.jl +++ b/examples/TensorBSpline_example.jl @@ -1,16 +1,17 @@ using Plots using Gismo +import Gismo.size -KV = Gismo.KnotVector([0.,0.,0.,1.,1.,1.]) -TBB = Gismo.TensorBSplineBasis(KV,KV) -print("The size of the basis is: ",Gismo.size(TBB),"\n") -Gismo.uniformRefine(TBB) -print("The size of the basis is: ",Gismo.size(TBB),"\n") +KV = KnotVector([0.,0.,0.,1.,1.,1.]) +TBB = TensorBSplineBasis(KV,KV) +print("The size of the basis is: ",size(TBB),"\n") +uniformRefine!(TBB) +print("The size of the basis is: ",size(TBB),"\n") # Create a matrix of random coefficients -coefs = rand(Gismo.size(TBB),3) +coefs = rand(size(TBB),3) # Create a BSpline geometry -TB = Gismo.TensorBSpline(TBB,coefs) +TB = TensorBSpline(TBB,coefs) # Create a matrix of linearly spaced evaluation points N = 10 @@ -21,7 +22,7 @@ points2D = zeros(2,N*N) points2D[1,:] = repeat(points1D, N) points2D[2,:] = repeat(points1D, inner=N) -ev = Gismo.asMatrix(Gismo.val(TB,points2D)) +ev = asMatrix(val(TB,points2D)) # Plot the geometry surface!(ev[1,:],ev[2,:],ev[3,:],legend=false) diff --git a/examples/fitting_example.jl b/examples/fitting_example.jl index b656de3..1a143f2 100644 --- a/examples/fitting_example.jl +++ b/examples/fitting_example.jl @@ -3,28 +3,28 @@ using DelimitedFiles using Plots # Create the knot vector -KV = Gismo.KnotVector([0.,0.,0.,1.,1.,1.]) +KV = KnotVector([0.,0.,0.,1.,1.,1.]) # Load the points and their parameters pars_file::String = "../try_gismo/julia/filedata/shiphull_pars.csv" points_file::String = "../try_gismo/julia/filedata/shiphull_points.csv" pars = readdlm(pars_file, ',', Float64) points = readdlm(points_file, ',', Float64) # Define the basis using the knots -BB2 = Gismo.TensorBSplineBasis(KV,KV) +BB2 = TensorBSplineBasis(KV,KV) # Create the fitter -fitter = Gismo.Fitting(pars,points,BB2) +fitter = Fitting(pars,points,BB2) # Perform the least squares error approssimation -Gismo.compute(fitter) +compute!(fitter) # Compute the errors -Gismo.computeErrors(fitter) +computeErrors!(fitter) # Display the outputs -println(Gismo.minPointError(fitter)) -println(Gismo.maxPointError(fitter)) -println(Gismo.pointWiseErrors(fitter)) -println(unsafe_wrap(Vector{Float64}, Gismo.pointWiseErrors(fitter), 264, own=false)) -println(Gismo.numPointsBelow(fitter, 0.02)) +println(minPointError(fitter)) +println(maxPointError(fitter)) +println(pointWiseErrors(fitter)) +println(unsafe_wrap(Vector{Float64}, pointWiseErrors(fitter), 264, own=false)) +println(numPointsBelow(fitter, 0.02)) # Obtain the geometry -geo = Gismo.result(fitter) +geo = result(fitter) # Create a matrix of linearly spaced evaluation points N = 10 points1D = range(0,stop=1,length=N) @@ -33,7 +33,7 @@ points2D = zeros(2,N*N) points2D[1,:] = repeat(points1D, N) points2D[2,:] = repeat(points1D, inner=N) -ev = Gismo.asMatrix(Gismo.val(geo,points2D)) +ev = asMatrix(val(geo,points2D)) # Plot the geometry surface!(ev[1,:],ev[2,:],ev[3,:],legend=false) diff --git a/examples/gismo_example.jl b/examples/gismo_example.jl index 5cb3388..cbdd7d6 100644 --- a/examples/gismo_example.jl +++ b/examples/gismo_example.jl @@ -4,15 +4,15 @@ using Gismo -m = Gismo.EigenMatrix(3,3) -Gismo.setZero(m) -display(Gismo.asMatrix(m)) +m = EigenMatrix(3,3) +setZero!(m) +display(asMatrix(m)) -geom = Gismo.Geometry( "surfaces/simple.xml" ) +geom = Geometry( "surfaces/simple.xml" ) println("Geometry:") println(geom) -println("Domain dim: ", Gismo.domainDim(geom) ) -println("Target dim: ", Gismo.targetDim(geom) ) +println("Domain dim: ", domainDim(geom) ) +println("Target dim: ", targetDim(geom) ) pts = zeros((2, 3)) pts[:,2] .= 0.5; @@ -21,94 +21,94 @@ println("Evaluation points:") display(pts) println("Evaluation result:") -values = Gismo.val(geom,pts) -println("Rows: ", Gismo.rows(values) ) -println("Cols: ", Gismo.cols(values) ) +values = val(geom,pts) +println("Rows: ", rows(values) ) +println("Cols: ", cols(values) ) -vals = Gismo.asMatrix(values) +vals = asMatrix(values) display(vals) -pts2 = Gismo.invertPoints(geom,vals) -display(Gismo.asMatrix(pts2)) +pts2 = invertPoints(geom,vals) +display(asMatrix(pts2)) -normals = Gismo.normal(geom,pts) +normals = normal(geom,pts) println("Normals at points:") -display(Gismo.asMatrix(normals)) +display(asMatrix(normals)) -display(Gismo.asMatrix(values)[:,1]) -dist,par = Gismo.closest(geom,Gismo.asMatrix(values)[:,1]) -display(Gismo.asMatrix(par)) +display(asMatrix(values)[:,1]) +dist,par = closest(geom,asMatrix(values)[:,1]) +display(asMatrix(par)) -# basis = Gismo.Basis( "filedata/bspbasis/tpBSpline2_01.xml" ) +# basis = Basis( "filedata/bspbasis/tpBSpline2_01.xml" ) # println("Basis:") # println(basis) -# values = Gismo.val(basis,pts) -# println("Rows: ", Gismo.rows(values) ) -# println("Cols: ", Gismo.cols(values) ) -# vals = Gismo.asMatrix(values) +# values = val(basis,pts) +# println("Rows: ", rows(values) ) +# println("Cols: ", cols(values) ) +# vals = asMatrix(values) # display(vals) -kv = Gismo.KnotVector([0.,0.,0.,0.,0.5,1.,1.,1.,1.]) -basis = Gismo.TensorBSplineBasis(kv,kv) +kv = KnotVector([0.,0.,0.,0.,0.5,1.,1.,1.,1.]) +basis = TensorBSplineBasis(kv,kv) println("Basis:") println(basis) -values = Gismo.val(basis,pts) -println("Rows: ", Gismo.rows(values) ) -println("Cols: ", Gismo.cols(values) ) -vals = Gismo.asMatrix(values) +values = val(basis,pts) +println("Rows: ", rows(values) ) +println("Cols: ", cols(values) ) +vals = asMatrix(values) display(vals) -coefs = rand(Gismo.size(basis),3) -geom = Gismo.TensorBSpline(basis,coefs) -values = Gismo.val(geom,pts) -println("Rows: ", Gismo.rows(values) ) -println("Cols: ", Gismo.cols(values) ) -vals = Gismo.asMatrix(values) +coefs = rand(size(basis),3) +geom = TensorBSpline(basis,coefs) +values = val(geom,pts) +println("Rows: ", rows(values) ) +println("Cols: ", cols(values) ) +vals = asMatrix(values) display(vals) -Gismo.uniformRefine(basis) +uniformRefine!(basis) println("Basis (refined):") println(basis) -display(Gismo.actives(basis,pts)) +display(actives(basis,pts)) -display(Gismo.asMatrix(Gismo.coefs(geom))) +display(asMatrix(coefs(geom))) -Gismo.THBSplineBasis(basis) -values = Gismo.val(basis,pts) -println("Rows: ", Gismo.rows(values) ) -println("Cols: ", Gismo.cols(values) ) -vals = Gismo.asMatrix(values) +THBSplineBasis(basis) +values = val(basis,pts) +println("Rows: ", rows(values) ) +println("Cols: ", cols(values) ) +vals = asMatrix(values) display(vals) -mp = Gismo.MultiPatch() -Gismo.addPatch(mp,geom) +mp = MultiPatch() +addPatch(mp,geom) display(mp) -patch = Gismo.patch(mp,0) +patch = patch(mp,0) display(patch) -display(Gismo.basis(mp,0)) -display(Gismo.uniformRefine(Gismo.basis(mp,0))) -display(Gismo.basis(mp,0)) +display(basis(mp,0)) +display(uniformRefine!(basis(mp,0))) +display(basis(mp,0)) # display(dist) # knots = [0.0,0.0,0.5,1.0,1.0] -# kv = Gismo.KnotVector(knots) +# kv = KnotVector(knots) # println("KnotVector:") # println(kv) # println("\n") -#basis = Gismo.TensorBSplineBasis(kv,kv) +#basis = TensorBSplineBasis(kv,kv) #println(basis) -#basis = Gismo.THBSplineBasis(basis) +#basis = THBSplineBasis(basis) #println(basis) #coefs = zeros((4, 3)) -#geom = Gismo.THBSpline(basis,coefs) +#geom = THBSpline(basis,coefs) #println(geom) diff --git a/src/Gismo.jl b/src/Gismo.jl index 7a04e1e..09185fa 100644 --- a/src/Gismo.jl +++ b/src/Gismo.jl @@ -1,6 +1,6 @@ module Gismo -import gismo_jll:libgismo +libgismo = "/Users/none/gismo2/gismo/build/lib/libgismo" # Forward declaration of structs include("Declarations.jl") diff --git a/src/gsAssembler.jl b/src/gsAssembler.jl index b6ff0db..3091bc6 100644 --- a/src/gsAssembler.jl +++ b/src/gsAssembler.jl @@ -1,5 +1,7 @@ export - QuadRule + QuadRule, + destroy!, + show #= TODO =# ######################################################################## @@ -12,12 +14,12 @@ mutable struct QuadRule function QuadRule(quad::Ptr{gsCQuadRule},delete::Bool=true) b = new(quad) if (delete) - finalizer(destroy,b) + finalizer(destroy!,b) end return b end - function destroy(qr::QuadRule) + function destroy!(qr::QuadRule) ccall((:gsQuadRule_delete,libgismo),Cvoid,(Ptr{gsCQuadRule},),qr.ptr) end end diff --git a/src/gsCore.jl b/src/gsCore.jl index 25906b5..b663268 100644 --- a/src/gsCore.jl +++ b/src/gsCore.jl @@ -1,15 +1,23 @@ export Basis, + show, + destroy!, domainDim, targetDim, component, degree, numElements, size, - uniformRefine, - refineElements, + uniformRefine!, + refineElements!, + refine!, actives, val, + deriv, + deriv2, + evalSingle, + derivSingle, + deriv2Single, Geometry, basis, coefs, @@ -17,8 +25,9 @@ export closest, invertPoints, MultiPatch, - addPatch, - patch + addPatch!, + patch, + MultiBasis ######################################################################## # gsBasis @@ -41,7 +50,7 @@ mutable struct Basis function Basis(basis::Ptr{gsCBasis},delete::Bool=true) b = new(basis) if (delete) - finalizer(destroy,b) + finalizer(destroy!,b) end return b end @@ -55,7 +64,7 @@ mutable struct Basis """ function Basis(filename::String) b = new(ccall((:gsCReadFile,libgismo),Ptr{gsCBasis},(Cstring,),filename) ) - finalizer(destroy, b) + finalizer(destroy!, b) return b end @@ -66,7 +75,7 @@ mutable struct Basis - `b::Basis`: a Gismo Basis ... """ - function destroy(b::Basis) + function destroy!(b::Basis) ccall((:gsFunctionSet_delete,libgismo),Cvoid,(Ptr{gsCFunctionSet},),b.ptr) end end @@ -155,7 +164,7 @@ Refines a basis - `dir::Cint=Int32(-1)`: the direction of the refinement ... """ -function uniformRefine(obj::Basis,numKnots::Cint=Int32(1),mul::Cint=Int32(1),dir::Cint=Int32(-1))::Nothing +function uniformRefine!(obj::Basis,numKnots::Cint=Int32(1),mul::Cint=Int32(1),dir::Cint=Int32(-1))::Nothing ccall((:gsBasis_uniformRefine,libgismo),Cvoid, (Ptr{gsCBasis},Cint,Cint,Cint),obj.ptr,numKnots,mul,dir) end @@ -168,7 +177,7 @@ Refines a basis - `boxes::Vector{Cint}`: the boxes to refine (in index format) ... """ -function refineElements(obj::Basis,boxes::Vector{Cint})::Nothing +function refineElements!(obj::Basis,boxes::Vector{Cint})::Nothing @assert mod(length(boxes),2*domainDim(obj)+1)==0 "Boxes should have size 2*domainDim+1" ccall((:gsBasis_refineElements,libgismo),Cvoid, (Ptr{gsCBasis},Ptr{Cint},Cint), @@ -183,7 +192,7 @@ Refines a basis - `boxes::Matrix{Cdouble}`: the boxes to refine (first column is the lower bound, second column is the upper bound) ... """ -function refine(obj::Basis,boxes::Matrix{Cdouble},refExt::Cint=Int32(0))::Nothing +function refine!(obj::Basis,boxes::Matrix{Cdouble},refExt::Cint=Int32(0))::Nothing @assert Base.size(boxes,1)==domainDim(obj) "The boxes should have the same number of rows as the domain dimension" @assert Base.size(boxes,2)==2 "The boxes should have two columns" bb = EigenMatrix(Base.size(boxes,1), Base.size(boxes,2), pointer(boxes) ) @@ -343,18 +352,18 @@ mutable struct Geometry g = new(geom) if (delete) - finalizer(destroy,g) + finalizer(destroy!,g) end return g end function Geometry(filename::String) g = new(ccall((:gsCReadFile,libgismo),Ptr{gsCGeometry},(Cstring,),filename) ) - finalizer(destroy, g) + finalizer(destroy!, g) return g end - function destroy(g::Geometry) + function destroy!(g::Geometry) ccall((:gsFunctionSet_delete,libgismo),Cvoid,(Ptr{gsCFunctionSet},),g.ptr) end end @@ -528,17 +537,17 @@ mutable struct MultiPatch # function MultiPatch(filename::String) # g = new(ccall((:gsCReadFile,libgismo),Ptr{gsCMultiPatch},(Cstring,),filename) ) - # finalizer(destroy, g) + # finalizer(destroy!, g) # return g # end function MultiPatch() m = new(ccall((:gsMultiPatch_create,libgismo),Ptr{gsCMultiPatch},(),) ) - finalizer(destroy, m) + finalizer(destroy!, m) return m end - function destroy(m::MultiPatch) + function destroy!(m::MultiPatch) ccall((:gsFunctionSet_delete,libgismo),Cvoid,(Ptr{gsCFunctionSet},),m.ptr) end end @@ -575,7 +584,7 @@ Returns the basis of a MultiPatch - `obj::MultiPatch`: a Gismo MultiPatch ... """ -function addPatch(obj::MultiPatch,geom::Geometry)::Nothing +function addPatch!(obj::MultiPatch,geom::Geometry)::Nothing ccall((:gsMultiPatch_addPatch,libgismo),Cvoid,(Ptr{gsCMultiPatch},Ptr{gsCGeometry},),obj.ptr,geom.ptr) end @@ -615,17 +624,17 @@ mutable struct MultiBasis # function MultiBasis(filename::String) # g = new(ccall((:gsCReadFile,libgismo),Ptr{gsCMultiBasis},(Cstring,),filename) ) - # finalizer(destroy, g) + # finalizer(destroy!, g) # return g # end function MultiBasis() m = new(ccall((:gsMultiBasis_create,libgismo),Ptr{gsCMultiBasis},(),) ) - finalizer(destroy, m) + finalizer(destroy!, m) return m end - function destroy(m::MultiBasis) + function destroy!(m::MultiBasis) ccall((:gsMultiBasis_delete,libgismo),Cvoid,(Ptr{gsCFunctionSet},),m.ptr) end end diff --git a/src/gsHSplines.jl b/src/gsHSplines.jl index 716b267..e967c3e 100644 --- a/src/gsHSplines.jl +++ b/src/gsHSplines.jl @@ -1,4 +1,5 @@ - +export +THBSplineBasis ######################################################################## # gsTHBSplineBasis ######################################################################## diff --git a/src/gsIO.jl b/src/gsIO.jl index 5720a63..219ae22 100644 --- a/src/gsIO.jl +++ b/src/gsIO.jl @@ -1,5 +1,7 @@ export - OptionList + OptionList, + destroy! + show #= TODO =# ######################################################################## @@ -37,7 +39,7 @@ mutable struct OptionList return OptionList(opt) end - function destroy(opt::OptionList) + function destroy!(opt::OptionList) ccall((:gsOptionList_delete,libgismo),Cvoid,(Ptr{gsCOptionList},),opt.ptr) end end diff --git a/src/gsMatrix.jl b/src/gsMatrix.jl index 5819152..d97d945 100644 --- a/src/gsMatrix.jl +++ b/src/gsMatrix.jl @@ -1,5 +1,15 @@ export - EigenMatrix +EigenMatrix, +destroy!, +show, +rows, +cols, +data, +asMatrix, +setZero!, +EigenMatrixInt, +asMatrixInt, +deepcopy ######################################################################## # gsMatrix @@ -28,25 +38,25 @@ mutable struct EigenMatrix function EigenMatrix() m = new( ccall((:gsMatrix_create,libgismo),Ptr{gsCMatrix},()) ) - finalizer(destroy, m) + finalizer(destroy!, m) return m end function EigenMatrix(r::Int64,c::Int64) m = new(ccall((:gsMatrix_create_rc,libgismo),Ptr{gsCMatrix}, (Cint,Cint), r, c) ) - finalizer(destroy, m) + finalizer(destroy!, m) return m end function EigenMatrix(r::Int,c::Int, data::Ptr{Cdouble}) m = new(ccall((:gsMatrix_create_rcd,libgismo),Ptr{gsCMatrix}, (Cint,Cint,Ptr{Cdouble},), r, c, data) ) - finalizer(destroy, m) + finalizer(destroy!, m) return m end - function destroy(m::EigenMatrix) + function destroy!(m::EigenMatrix) ccall((:gsMatrix_delete,libgismo),Cvoid,(Ptr{gsCMatrix},),m.ptr) end end @@ -87,7 +97,7 @@ Base.deepcopy(obj::EigenMatrix) = EigenMatrix(rows(obj),cols(obj),data(obj)) # Base.show(io::IO, obj::EigenMatrix) = asMatrix(obj) Base.show(io::IO, obj::EigenMatrix) = ccall((:gsMatrix_print,libgismo),Cvoid,(Ptr{gsCMatrix},),obj.ptr) -function setZero(object::EigenMatrix)::Nothing +function setZero!(object::EigenMatrix)::Nothing ccall((:gsMatrix_setZero,libgismo),Cvoid,(Ptr{gsCMatrix},),object.ptr) end @@ -106,25 +116,25 @@ mutable struct EigenMatrixInt function EigenMatrixInt() m = new( ccall((:gsMatrixInt_create,libgismo),Ptr{gsCMatrixInt},()) ) - finalizer(destroy, m) + finalizer(destroy!, m) return m end function EigenMatrixInt(r::Int64,c::Int64) m = new(ccall((:gsMatrixInt_create_rc,libgismo),Ptr{gsCMatrixInt}, (Cint,Cint), r, c) ) - finalizer(destroy, m) + finalizer(destroy!, m) return m end function EigenMatrixInt(r::Int,c::Int, data::Ptr{Cint}) m = new(ccall((:gsMatrixInt_create_rcd,libgismo),Ptr{gsCMatrixInt}, (Cint,Cint,Ptr{Cint},), r, c, data) ) - finalizer(destroy, m) + finalizer(destroy!, m) return m end - function destroy(m::EigenMatrixInt) + function destroy!(m::EigenMatrixInt) ccall((:gsMatrixInt_delete,libgismo),Cvoid,(Ptr{gsCMatrixInt},),m.ptr) end end @@ -151,6 +161,6 @@ Base.deepcopy(obj::EigenMatrixInt) = EigenMatrixInt(rows(obj),cols(obj),data(obj # Base.show(io::IO, obj::EigenMatrixInt) = asMatrixInt(obj) Base.show(io::IO, obj::EigenMatrixInt) = ccall((:gsMatrixInt_print,libgismo),Cvoid,(Ptr{gsCMatrixInt},),obj.ptr) -function setZero(object::EigenMatrixInt)::Nothing +function setZero!(object::EigenMatrixInt)::Nothing ccall((:gsMatrixInt_setZero,libgismo),Cvoid,(Ptr{gsCMatrixInt},),object.ptr) end diff --git a/src/gsModeling.jl b/src/gsModeling.jl index ded221b..348d8d7 100644 --- a/src/gsModeling.jl +++ b/src/gsModeling.jl @@ -1,5 +1,14 @@ export - Fitting + Fitting, + destroy!, + compute!, + parameterCorrection!, + computeErrors!, + minPointError, + maxPointError, + pointWiseErrors, + numPointsBelow, + result #= TODO =# ######################################################################## @@ -23,7 +32,7 @@ mutable struct Fitting function Fitting(opt::Ptr{gsCFitting},delete::Bool=true)::Fitting b = new(opt) if (delete) - finalizer(destroy,b) + finalizer(destroy!,b) end return b end @@ -45,14 +54,14 @@ mutable struct Fitting return Fitting(fitter) end - function destroy(fit::Fitting) + function destroy!(fit::Fitting) ccall((:gsFitting_delete,libgismo),Cvoid,(Ptr{gsCFitting},),fit.ptr) end end """ -compute(fit::Fitting, lambda::Cdouble=0.0) +compute!(fit::Fitting, lambda::Cdouble=0.0) Computes the least squares fit ... # Arguments @@ -60,12 +69,12 @@ Computes the least squares fit - `lambda::Cdouble`: the value to assign to the lambda ridge parameter ... """ -function compute(fit::Fitting, lambda::Cdouble=0.0) +function compute!(fit::Fitting, lambda::Cdouble=0.0) ccall((:gsFitting_compute,libgismo),Cvoid,(Ptr{gsCFitting},Cdouble),fit.ptr,lambda) end """ -parameterCorrection(fit::Fitting, accuracy::Cdouble, maxIter::Cint, tol0rth::Cdouble) +parameterCorrection!(fit::Fitting, accuracy::Cdouble, maxIter::Cint, tol0rth::Cdouble) Performs the parameters corrections step ... # Arguments @@ -75,21 +84,21 @@ Performs the parameters corrections step - `tol0rth::Cdouble`: The desired value of the tolleance ... """ -function parameterCorrection(fit::Fitting, accuracy::Cdouble, maxIter::Cint, tol0rth::Cdouble) +function parameterCorrection!(fit::Fitting, accuracy::Cdouble, maxIter::Cint, tol0rth::Cdouble) @assert maxIter >= 0 "Fitting: cannot have a negative number of iterations!" @assert accuracy >= 0 "Fitting: cannot have a negative accuracy!" ccall((:gsFitting_parameterCorrection,libgismo),Cvoid,(Ptr{gsCFitting},Cdouble,Cint,Cdouble),fit.ptr,accuracy,maxIter,tol0rth) end """ -computeErrors(fit::Fitting) +computeErrors!(fit::Fitting) Computes the error for each point ... # Arguments - `fit::Fitting`: a fitting structure ... """ -function computeErrors(fit::Fitting) +function computeErrors!(fit::Fitting) ccall((:gsFitting_computeErrors,libgismo),Cvoid,(Ptr{gsCFitting},),fit.ptr) end diff --git a/src/gsNurbs.jl b/src/gsNurbs.jl index 6845dde..f251253 100644 --- a/src/gsNurbs.jl +++ b/src/gsNurbs.jl @@ -1,9 +1,33 @@ export KnotVector, + destroy!, + show, + size, + uSize, + numElements, BSplineBasis, BSpline, TensorBSplineBasis, - TensorBSpline + knots, + TensorBSpline, + NurbsBasis, + Nurbs, + TensorNurbsBasis, + TensorNurbs, + BSplineUnitInterval, + BSplineRectangle, + BSplineTrapezium, + BSplineSquare, + BSplineSquareGrid, + BSplineCube, + BSplineCubeGrid, + NurbsQuarterAnnulus, + NurbsAnnulus, + BSplineSaddle, + NurbsSphere, + NurbsCircle, + BSplineTriangle, + BSplineStar #= TODO =# ######################################################################## @@ -33,24 +57,24 @@ mutable struct KnotVector function KnotVector(knots::Ptr{gsCKnotVector},delete::Bool=true) b = new(knots) if (delete) - finalizer(destroy,b) + finalizer(destroy!,b) end return b end function KnotVector(filename::String) g = new(ccall((:gsCReadFile,libgismo),Ptr{gsCKnotVector},(Cstring,),filename) ) - finalizer(destroy, g) + finalizer(destroy!, g) return g end function KnotVector(a::Vector{Float64}) kv = new(ccall((:gsKnotVector_create,libgismo),Ptr{gsCKnotVector},(Ptr{Cdouble},Cint),a, length(a)) ) - finalizer(destroy, kv) + finalizer(destroy!, kv) return kv end - function destroy(kv::KnotVector) + function destroy!(kv::KnotVector) ccall((:gsKnotVector_delete,libgismo),Cvoid,(Ptr{gsCKnotVector},),kv.ptr) end end diff --git a/test/runbenchmarks.jl b/test/runbenchmarks.jl index 83119ea..b3b72db 100644 --- a/test/runbenchmarks.jl +++ b/test/runbenchmarks.jl @@ -1,16 +1,16 @@ using BenchmarkTools using BenchmarkPlots - using Gismo +import Gismo.size -KV = Gismo.KnotVector([0.,0.,0.,1.,1.,1.]) -TBB = Gismo.TensorBSplineBasis(KV,KV) -Gismo.uniformRefine(TBB) -coefs = rand(Gismo.size(TBB),3) -TB = Gismo.TensorBSpline(TBB,coefs) +KV = KnotVector([0.,0.,0.,1.,1.,1.]) +TBB = TensorBSplineBasis(KV,KV) +uniformRefine!(TBB) +coefs = rand(size(TBB),3) +TB = TensorBSpline(TBB,coefs) display(@benchmark normal(TB,rand(Float64, (2, 1)))) -display(@benchmark Gismo.val(TB,rand(Float64, (2, 1)))) +display(@benchmark val(TB,rand(Float64, (2, 1)))) diff --git a/test/runtests.jl b/test/runtests.jl index 29877d6..2422d81 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,21 +1,22 @@ using Gismo using Test +import Gismo.size -@testset verbose = true "Gismo.jl" begin +@testset verbose = true "jl" begin @testset verbose = true "bases" begin @testset "constructors" begin - @test_nowarn(KV = Gismo.KnotVector([0.,0.,0.,1.,1.,1.])) - KV = Gismo.KnotVector([0.,0.,0.,1.,1.,1.]) - @test_nowarn(TBB = Gismo.TensorBSplineBasis(KV,KV)) - TBB = Gismo.TensorBSplineBasis(KV,KV) - @test_nowarn(THB = Gismo.THBSplineBasis(TBB)) - THB = Gismo.THBSplineBasis(TBB) + @test_nowarn(KV = KnotVector([0.,0.,0.,1.,1.,1.])) + KV = KnotVector([0.,0.,0.,1.,1.,1.]) + @test_nowarn(TBB = TensorBSplineBasis(KV,KV)) + TBB = TensorBSplineBasis(KV,KV) + @test_nowarn(THB = THBSplineBasis(TBB)) + THB = THBSplineBasis(TBB) end # @testset "print" begin - # KV = Gismo.KnotVector([0.,0.,0.,1.,1.,1.]) - # TBB = Gismo.TensorBSplineBasis(KV,KV) - # THB = Gismo.THBSplineBasis(TBB) + # KV = KnotVector([0.,0.,0.,1.,1.,1.]) + # TBB = TensorBSplineBasis(KV,KV) + # THB = THBSplineBasis(TBB) # oldstd = stdout # redirect_stdout(devnull) @@ -26,47 +27,47 @@ using Test # end @testset "refinement" begin - KV = Gismo.KnotVector([0.,0.,0.,1.,1.,1.]) - TBB = Gismo.TensorBSplineBasis(KV,KV) - THB = Gismo.THBSplineBasis(TBB) - @test_nowarn(Gismo.uniformRefine(TBB)) - @test_nowarn(Gismo.uniformRefine(THB)) + KV = KnotVector([0.,0.,0.,1.,1.,1.]) + TBB = TensorBSplineBasis(KV,KV) + THB = THBSplineBasis(TBB) + @test_nowarn(uniformRefine!(TBB)) + @test_nowarn(uniformRefine!(THB)) boxes = Matrix{Cdouble}([0.0 0.5; 0.0 0.5]) - @test_nowarn(Gismo.refine(THB,boxes)) + @test_nowarn(refine!(THB,boxes)) boxes = Vector{Int32}([1,0,0,2,2]) - @test_nowarn(Gismo.refineElements(THB,boxes)) + @test_nowarn(refineElements!(THB,boxes)) end end @testset verbose = true "splines" begin @testset "constructors" begin - KV = Gismo.KnotVector([0.,0.,0.,1.,1.,1.]) - TBB = Gismo.TensorBSplineBasis(KV,KV) - THB = Gismo.THBSplineBasis(TBB) + KV = KnotVector([0.,0.,0.,1.,1.,1.]) + TBB = TensorBSplineBasis(KV,KV) + THB = THBSplineBasis(TBB) - coefs_TBB = rand(Gismo.size(TBB),3) - @test_nowarn(TB = Gismo.TensorBSpline(TBB,coefs_TBB)) - coefs_THB = rand(Gismo.size(THB),3) - @test_nowarn(THB = Gismo.TensorBSpline(THB,coefs_THB)) + coefs_TBB = rand(size(TBB),3) + @test_nowarn(TB = TensorBSpline(TBB,coefs_TBB)) + coefs_THB = rand(size(THB),3) + @test_nowarn(THB = TensorBSpline(THB,coefs_THB)) end @testset "evaluation" begin - KV = Gismo.KnotVector([0.,0.,0.,1.,1.,1.]) - TBB = Gismo.TensorBSplineBasis(KV,KV) - THB = Gismo.THBSplineBasis(TBB) - coefs_TBB = rand(Gismo.size(TBB),3) - TB = Gismo.TensorBSpline(TBB,coefs_TBB) - coefs_THB = rand(Gismo.size(THB),3) - THB = Gismo.TensorBSpline(THB,coefs_THB) + KV = KnotVector([0.,0.,0.,1.,1.,1.]) + TBB = TensorBSplineBasis(KV,KV) + THB = THBSplineBasis(TBB) + coefs_TBB = rand(size(TBB),3) + TB = TensorBSpline(TBB,coefs_TBB) + coefs_THB = rand(size(THB),3) + THB = TensorBSpline(THB,coefs_THB) N = 10 points1D = range(0,stop=1,length=N) points2D = zeros(2,N*N) points2D[1,:] = repeat(points1D, N) points2D[2,:] = repeat(points1D, inner=N) - @test_nowarn(ev = Gismo.asMatrix(Gismo.val(TB,points2D))) - @test_nowarn(ev = Gismo.asMatrix(Gismo.val(THB,points2D))) + @test_nowarn(ev = asMatrix(val(TB,points2D))) + @test_nowarn(ev = asMatrix(val(THB,points2D))) end end end \ No newline at end of file From c6625aeffac3f00c815a90496b743d417e3c3d02 Mon Sep 17 00:00:00 2001 From: Alberto Biliotti <76699437+Albe21072000@users.noreply.github.com> Date: Fri, 13 Dec 2024 23:55:45 +0100 Subject: [PATCH 07/16] Update Gismo.jl I forgot to remove the local path again --- src/Gismo.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Gismo.jl b/src/Gismo.jl index 09185fa..7a04e1e 100644 --- a/src/Gismo.jl +++ b/src/Gismo.jl @@ -1,6 +1,6 @@ module Gismo -libgismo = "/Users/none/gismo2/gismo/build/lib/libgismo" +import gismo_jll:libgismo # Forward declaration of structs include("Declarations.jl") From 0280d8ddd1536c47b76c957cb73c16071ee758c9 Mon Sep 17 00:00:00 2001 From: Albe2107200 <76699437+Albe21072000@users.noreply.github.com.> Date: Mon, 16 Dec 2024 18:37:38 +0100 Subject: [PATCH 08/16] Update fitted example to include synthetic data, fixed documentation, remove gismo_example --- examples/fitting_example.jl | 46 ++++++++++----- examples/gismo_example.jl | 114 ------------------------------------ src/gsCore.jl | 3 + src/gsModeling.jl | 4 +- 4 files changed, 35 insertions(+), 132 deletions(-) delete mode 100644 examples/gismo_example.jl diff --git a/examples/fitting_example.jl b/examples/fitting_example.jl index 1a143f2..10adb66 100644 --- a/examples/fitting_example.jl +++ b/examples/fitting_example.jl @@ -1,28 +1,43 @@ using Gismo -using DelimitedFiles using Plots # Create the knot vector KV = KnotVector([0.,0.,0.,1.,1.,1.]) -# Load the points and their parameters -pars_file::String = "../try_gismo/julia/filedata/shiphull_pars.csv" -points_file::String = "../try_gismo/julia/filedata/shiphull_points.csv" -pars = readdlm(pars_file, ',', Float64) -points = readdlm(points_file, ',', Float64) + +# Generate random parameters and points +num_points = 1000 +pars = rand(num_points, 2) # 2D parameters in [0, 1] interval +points = zeros(num_points, 3) # 3D points +# Define the radius of the circle +radius = 0.25 + +# Generate points +for i in 1:num_points + x, y = pars[i, :] + z = ifelse((x - 0.5)^2 + (y - 0.5)^2 <= radius^2, 1.0, 0.0) + points[i, :] = [x, y, z] +end + + # Define the basis using the knots -BB2 = TensorBSplineBasis(KV,KV) +BB2 = TensorBSplineBasis(KV, KV) +pars=pars' +points=points' # Create the fitter -fitter = Fitting(pars,points,BB2) -# Perform the least squares error approssimation +fitter = Fitting(pars, points, BB2) + +# Perform the parameter correction +parameterCorrection!(fitter) +# Perform the least squares error approximation compute!(fitter) # Compute the errors computeErrors!(fitter) # Display the outputs -println(minPointError(fitter)) -println(maxPointError(fitter)) -println(pointWiseErrors(fitter)) -println(unsafe_wrap(Vector{Float64}, pointWiseErrors(fitter), 264, own=false)) -println(numPointsBelow(fitter, 0.02)) +println("Minimum point error: ", minPointError(fitter)) +println("Maximum point error: ", maxPointError(fitter)) +println("Pointwise errors: ", unsafe_wrap(Vector{Float64}, pointWiseErrors(fitter), num_points, own=false)) + +println("Number of points under the tolleance of 0.1: ",numPointsBelow(fitter, 0.1)) # Obtain the geometry geo = result(fitter) # Create a matrix of linearly spaced evaluation points @@ -32,10 +47,9 @@ points2D = zeros(2,N*N) # Create a meshgrid of evaluation points points2D[1,:] = repeat(points1D, N) points2D[2,:] = repeat(points1D, inner=N) - ev = asMatrix(val(geo,points2D)) - # Plot the geometry +scatter(points[1,:],points[2,:],points[3,:],legend=false) surface!(ev[1,:],ev[2,:],ev[3,:],legend=false) gui() # Press enter to exit diff --git a/examples/gismo_example.jl b/examples/gismo_example.jl deleted file mode 100644 index cbdd7d6..0000000 --- a/examples/gismo_example.jl +++ /dev/null @@ -1,114 +0,0 @@ -using Gismo - - - - - -m = EigenMatrix(3,3) -setZero!(m) -display(asMatrix(m)) - -geom = Geometry( "surfaces/simple.xml" ) -println("Geometry:") -println(geom) -println("Domain dim: ", domainDim(geom) ) -println("Target dim: ", targetDim(geom) ) - -pts = zeros((2, 3)) -pts[:,2] .= 0.5; -pts[:,3] .= 0.99; -println("Evaluation points:") -display(pts) - -println("Evaluation result:") -values = val(geom,pts) -println("Rows: ", rows(values) ) -println("Cols: ", cols(values) ) - -vals = asMatrix(values) -display(vals) -pts2 = invertPoints(geom,vals) -display(asMatrix(pts2)) - -normals = normal(geom,pts) -println("Normals at points:") -display(asMatrix(normals)) - -display(asMatrix(values)[:,1]) -dist,par = closest(geom,asMatrix(values)[:,1]) -display(asMatrix(par)) - - -# basis = Basis( "filedata/bspbasis/tpBSpline2_01.xml" ) -# println("Basis:") -# println(basis) - -# values = val(basis,pts) -# println("Rows: ", rows(values) ) -# println("Cols: ", cols(values) ) -# vals = asMatrix(values) -# display(vals) - -kv = KnotVector([0.,0.,0.,0.,0.5,1.,1.,1.,1.]) -basis = TensorBSplineBasis(kv,kv) -println("Basis:") -println(basis) - -values = val(basis,pts) -println("Rows: ", rows(values) ) -println("Cols: ", cols(values) ) -vals = asMatrix(values) -display(vals) - -coefs = rand(size(basis),3) -geom = TensorBSpline(basis,coefs) -values = val(geom,pts) -println("Rows: ", rows(values) ) -println("Cols: ", cols(values) ) -vals = asMatrix(values) -display(vals) - -uniformRefine!(basis) -println("Basis (refined):") -println(basis) - -display(actives(basis,pts)) - -display(asMatrix(coefs(geom))) - -THBSplineBasis(basis) -values = val(basis,pts) -println("Rows: ", rows(values) ) -println("Cols: ", cols(values) ) -vals = asMatrix(values) -display(vals) - -mp = MultiPatch() -addPatch(mp,geom) -display(mp) -patch = patch(mp,0) -display(patch) - -display(basis(mp,0)) -display(uniformRefine!(basis(mp,0))) -display(basis(mp,0)) - - - -# display(dist) - -# knots = [0.0,0.0,0.5,1.0,1.0] -# kv = KnotVector(knots) -# println("KnotVector:") -# println(kv) -# println("\n") - -#basis = TensorBSplineBasis(kv,kv) -#println(basis) - -#basis = THBSplineBasis(basis) -#println(basis) - -#coefs = zeros((4, 3)) -#geom = THBSpline(basis,coefs) -#println(geom) diff --git a/src/gsCore.jl b/src/gsCore.jl index b663268..545d8cd 100644 --- a/src/gsCore.jl +++ b/src/gsCore.jl @@ -279,6 +279,7 @@ Returns the evaluation of a single basis function ... # Arguments - `obj::Basis`: a Gismo Basis +- `i::Cint`: the index of the basis function - `u::Matrix{Cdouble}`: a matrix of points ... """ @@ -297,6 +298,7 @@ Returns the derivative of a single basis function ... # Arguments - `obj::Basis`: a Gismo Basis +- `i::Cint`: the index of the basis function - `u::Matrix{Cdouble}`: a matrix of points ... """ @@ -315,6 +317,7 @@ Returns the second derivative of a single basis function ... # Arguments - `obj::Basis`: a Gismo Basis +- `i::Cint`: the index of the basis function - `u::Matrix{Cdouble}`: a matrix of points ... """ diff --git a/src/gsModeling.jl b/src/gsModeling.jl index 348d8d7..1d9f02b 100644 --- a/src/gsModeling.jl +++ b/src/gsModeling.jl @@ -46,7 +46,7 @@ mutable struct Fitting - `basis::Basis`: a Basis structure containing the desired basis ... """ - function Fitting(parValues::Matrix{Cdouble}, pts::Matrix{Cdouble}, basis::Basis)::Fitting + function Fitting(parValues::AbstractMatrix{Cdouble}, pts::AbstractMatrix{Cdouble}, basis::Basis)::Fitting @assert Base.size(parValues,2) == Base.size(pts,2) "Fitting: parValues and points must have the same number of columns" param_values = EigenMatrix(Base.size(parValues,1),Base.size(parValues,2),pointer(parValues)) points = EigenMatrix(Base.size(pts,1),Base.size(pts,2),pointer(pts)) @@ -84,7 +84,7 @@ Performs the parameters corrections step - `tol0rth::Cdouble`: The desired value of the tolleance ... """ -function parameterCorrection!(fit::Fitting, accuracy::Cdouble, maxIter::Cint, tol0rth::Cdouble) +function parameterCorrection!(fit::Fitting, accuracy::Cdouble=1.0, maxIter::Cint=Cint(10), tol0rth::Cdouble=1e-6) @assert maxIter >= 0 "Fitting: cannot have a negative number of iterations!" @assert accuracy >= 0 "Fitting: cannot have a negative accuracy!" ccall((:gsFitting_parameterCorrection,libgismo),Cvoid,(Ptr{gsCFitting},Cdouble,Cint,Cdouble),fit.ptr,accuracy,maxIter,tol0rth) From d35b0ea5f4e3c3cbf22dbe2a9f2a5a5590a97c6d Mon Sep 17 00:00:00 2001 From: Hugo Verhelst Date: Thu, 19 Dec 2024 12:23:32 +0100 Subject: [PATCH 09/16] ADD documentation ADD example for quadrature --- README.md | 4 +- cmake/Gismo.jl.in | 6 +- docs/make.jl | 9 +- docs/src/gsAssembler.md | 10 + docs/src/gsCore.md | 6 +- docs/src/gsHSplines.md | 2 + docs/src/gsIO.md | 10 + docs/src/gsMatrix.md | 6 +- docs/src/gsModeling.md | 10 + docs/src/gsNurbs.md | 2 + docs/src/index.md | 48 ++++- examples/OptionList_example.jl | 21 +++ examples/QuadRule_example.jl | 15 ++ examples/TensorBSpline_example.jl | 2 + src/Gismo.jl | 8 +- src/gsAssembler.jl | 138 +++++++++++++- src/gsCore.jl | 154 ++++++++------- src/gsHSplines.jl | 3 +- src/gsIO.jl | 299 +++++++++++++++++++++++++++++- src/gsMatrix.jl | 196 ++++++++++++++++++-- src/gsModeling.jl | 48 ++--- src/gsNurbs.jl | 251 +++++++++++++++++++++++-- 22 files changed, 1091 insertions(+), 157 deletions(-) create mode 100644 docs/src/gsAssembler.md create mode 100644 docs/src/gsIO.md create mode 100644 docs/src/gsModeling.md create mode 100644 examples/OptionList_example.jl create mode 100644 examples/QuadRule_example.jl diff --git a/README.md b/README.md index ddf0bca..e557e43 100644 --- a/README.md +++ b/README.md @@ -14,10 +14,10 @@ The Gismo.jl package can be directly downloaded from Julia's package management ``` ] add Gismo ``` -This command fetches the dependency [`gismo_jll`](LINK) contaning pre-compiled library files, and it fetches the current repository which calls `gismo_jll`. +This command fetches the dependency [`gismo_jll`](https://github.com/JuliaBinaryWrappers/gismo_jll.jl) contaning pre-compiled library files, and it fetches the current repository which calls `gismo_jll`. ### Enabling Gismo.jl locally -Alternatively, one can use a local build of G+Smo as a back-end for the Julia bindings. This requires the [`gsCInterface`](LINK) module to be compiled, and the Gismo.jl package to be fetched as a submodule in G+Smo. +Alternatively, one can use a local build of G+Smo as a back-end for the Julia bindings. This requires the [`gsCInterface`](https://github.com/gismo/gsCInterface) module to be compiled, and the Gismo.jl package to be fetched as a submodule in G+Smo. #### a. Fetching and compiling the required G+Smo submodules Enable the `gsCInterface` and the `Gismo.jl` modules inside G+Smo diff --git a/cmake/Gismo.jl.in b/cmake/Gismo.jl.in index 73250fc..7e67846 100644 --- a/cmake/Gismo.jl.in +++ b/cmake/Gismo.jl.in @@ -5,12 +5,12 @@ module Gismo # Forward declaration of structs include("Declarations.jl") -# Load gsAssembler -include("gsAssembler.jl") - # Load gsCore include("gsCore.jl") +# Load gsAssembler +include("gsAssembler.jl") + # Load gsHSplines include("gsHSplines.jl") diff --git a/docs/make.jl b/docs/make.jl index de096cb..9df4aa5 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -17,10 +17,13 @@ DocMeta.setdocmeta!(Gismo, # List of subsection pages SUBSECTION_PAGES = [ - "gsMatrix.md", "gsCore.md", - "gsNurbs.md", - "gsHSplines.md" + "gsAssembler.md", + "gsHSplines.md", + "gsIO.md", + "gsMatrix.md", + "gsModeling.md", + "gsNurbs.md" ] makedocs( diff --git a/docs/src/gsAssembler.md b/docs/src/gsAssembler.md new file mode 100644 index 0000000..c5d2c43 --- /dev/null +++ b/docs/src/gsAssembler.md @@ -0,0 +1,10 @@ +# gsAssembler + +The methods in `gsAssembler` contain methods used for assembly. + +## Function Documentation +```@autodocs +Modules = [Gismo] +Pages = ["src/gsAssembler.jl"] +Order = [:function, :type] +``` \ No newline at end of file diff --git a/docs/src/gsCore.md b/docs/src/gsCore.md index 16acff7..f23aa62 100644 --- a/docs/src/gsCore.md +++ b/docs/src/gsCore.md @@ -1,12 +1,10 @@ # gsCore +The methods in `gsCore` contain basis, geometry and function methods. + ## Function Documentation ```@autodocs Modules = [Gismo] Pages = ["src/gsCore.jl"] Order = [:function, :type] -``` - -```@contents -Pages = Main.SUBSECTION_PAGES ``` \ No newline at end of file diff --git a/docs/src/gsHSplines.md b/docs/src/gsHSplines.md index 22f73ac..ec15d63 100644 --- a/docs/src/gsHSplines.md +++ b/docs/src/gsHSplines.md @@ -1,5 +1,7 @@ # gsHSplines +The methods in `gsHSplines` contain methods for hierarchical splines. + ## Function Documentation ```@autodocs Modules = [Gismo] diff --git a/docs/src/gsIO.md b/docs/src/gsIO.md new file mode 100644 index 0000000..6124240 --- /dev/null +++ b/docs/src/gsIO.md @@ -0,0 +1,10 @@ +# gsIO + +The methods in `gsIO` contain G+Smo's methods for input and output. + +## Function Documentation +```@autodocs +Modules = [Gismo] +Pages = ["src/gsIO.jl"] +Order = [:function, :type] +``` \ No newline at end of file diff --git a/docs/src/gsMatrix.md b/docs/src/gsMatrix.md index 00dce64..657288d 100644 --- a/docs/src/gsMatrix.md +++ b/docs/src/gsMatrix.md @@ -1,12 +1,10 @@ # gsMatrix +The methods in `gsMatrix` are an interface to G+Smo's linear algebra, supported by `Eigen`. + ## Function Documentation ```@autodocs Modules = [Gismo] Pages = ["src/gsMatrix.jl"] Order = [:function, :type] -``` - -```@contents -Pages = Main.SUBSECTION_PAGES ``` \ No newline at end of file diff --git a/docs/src/gsModeling.md b/docs/src/gsModeling.md new file mode 100644 index 0000000..32de773 --- /dev/null +++ b/docs/src/gsModeling.md @@ -0,0 +1,10 @@ +# gsModeling + +The methods in `gsModeling` contain methods for geometric modelling, such as fitting. + +## Function Documentation +```@autodocs +Modules = [Gismo] +Pages = ["src/gsModeling.jl"] +Order = [:function, :type] +``` \ No newline at end of file diff --git a/docs/src/gsNurbs.md b/docs/src/gsNurbs.md index f231725..61d0ae0 100644 --- a/docs/src/gsNurbs.md +++ b/docs/src/gsNurbs.md @@ -1,5 +1,7 @@ # gsNurbs +The methods in `gsNurbs` contain methods related to NURBS and B-splines. + ## Function Documentation ```@autodocs Modules = [Gismo] diff --git a/docs/src/index.md b/docs/src/index.md index 1170e8a..ac68a28 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -1,8 +1,52 @@ Julia interface for the Geometry + Simulation modules (G+Smo) -## Installation instructions +# Gismo.jl: Geometry + Simulation Modules meet Julia +The Gismo.jl package provides an interface to the [Geometry + Simulation Modules](https://github.com/gismo/gismo) inside Julia. + +## Getting started +We provide a hand full of examples in the `examples` directory, which can be run after [installation](#installation) of the package. + +## Installation +There are two ways to install Gismo.jl: via Julia's package manager, or by linking it to a local build of G+Smo. + +### Via `Pkg` +The Gismo.jl package can be directly downloaded from Julia's package management system `Pkg` using +``` +] add Gismo +``` +This command fetches the dependency [`gismo_jll`](https://github.com/JuliaBinaryWrappers/gismo_jll.jl) contaning pre-compiled library files, and it fetches the current repository which calls `gismo_jll`. + +### Enabling Gismo.jl locally +Alternatively, one can use a local build of G+Smo as a back-end for the Julia bindings. This requires the [`gsCInterface`](https://github.com/gismo/gsCInterface) module to be compiled, and the Gismo.jl package to be fetched as a submodule in G+Smo. + +#### a. Fetching and compiling the required G+Smo submodules +Enable the `gsCInterface` and the `Gismo.jl` modules inside G+Smo +``` +cd path/to/gismo/build +cmake . -DGISMO_OPTIONAL=";gsCInterface;Gismo.jl" \ + -DGISMO_JL_DEVELOP=ON +``` +And compile everything +``` +make gismo +``` +#### b. Link libgismo to Gismo.jl +In the file `Gismo.jl/src/Gismo.jl`, the shared library should be included as follows: +``` +libgismo = "path/to/gismo/build/lib/libgismo" +``` + +#### c. Install Gismo.jl in Julia +Add the local package Gismo.jl to Julia's development packages +``` +cd path/to/gismo/ +cd optional +julia -e 'using Pkg; Pkg.develop(path="Gismo.jl")' +``` + +## Structure of the package +The package is structured according to the `src/` folder in `gismo`'s C++ library. That is, for every directory `dir` in `src/dir`, `Gismo.jl/src` contains a `jl` file. -## Function Documentation ```@docs ``` diff --git a/examples/OptionList_example.jl b/examples/OptionList_example.jl new file mode 100644 index 0000000..89663d6 --- /dev/null +++ b/examples/OptionList_example.jl @@ -0,0 +1,21 @@ +using Gismo + +options = Dict([("a",1), ("b",1.1), ("c", true), ("d", "one")]) +println(options) +gsOptionList = OptionList(options) +println(gsOptionList) + +Gismo.setInt(gsOptionList,"a",Int32(2)) +Gismo.setReal(gsOptionList,"b",2.0) +Gismo.setSwitch(gsOptionList,"c",false) +Gismo.setString(gsOptionList,"d","two") +println(gsOptionList) + +int::Int64 = Gismo.getInt(gsOptionList,"a") +println("Integer read from option list: ",int) +double::Float64 = Gismo.getReal(gsOptionList,"b") +println("Double read from option list: ",double) +bool::Bool = Gismo.getSwitch(gsOptionList,"c") +println("Bool read from option list: ",bool) +string::Cstring = Gismo.getString(gsOptionList,"d") +println("String read from option list: ",string) \ No newline at end of file diff --git a/examples/QuadRule_example.jl b/examples/QuadRule_example.jl new file mode 100644 index 0000000..e84207b --- /dev/null +++ b/examples/QuadRule_example.jl @@ -0,0 +1,15 @@ +using Gismo + +# Gauss quadrature rule (1D) +rule1D = GaussRule(Int32(2)) +nodes,weights = mapTo(rule1D,0.0,1.0) +println("Gauss nodes: ",asMatrix(nodes)) +println("Gauss nodes: ",asVector(weights)) + +# Lobatto quadrature rule (2D) +rule2D = LobattoRule(Int32(2),Array{Int32}([2,2])) +low = Vector{Float64}([0.0,0.0]) +upp = Vector{Float64}([1.0,1.0]) +nodes,weights = mapTo(rule2D,low,upp) +println("Lobatto nodes: ",asMatrix(nodes)) +println("Lobatto weights: ",asVector(weights)) diff --git a/examples/TensorBSpline_example.jl b/examples/TensorBSpline_example.jl index 52c40f9..ada5445 100644 --- a/examples/TensorBSpline_example.jl +++ b/examples/TensorBSpline_example.jl @@ -13,6 +13,8 @@ coefs = rand(size(TBB),3) # Create a BSpline geometry TB = TensorBSpline(TBB,coefs) +Gismo.size(KV) + # Create a matrix of linearly spaced evaluation points N = 10 points1D = range(0,stop=1,length=N) diff --git a/src/Gismo.jl b/src/Gismo.jl index 7a04e1e..3f86c24 100644 --- a/src/Gismo.jl +++ b/src/Gismo.jl @@ -1,16 +1,16 @@ module Gismo -import gismo_jll:libgismo +libgismo = "/home/hverhelst/Documents/code/gismo_mex/build/lib/libgismo" # Forward declaration of structs include("Declarations.jl") -# Load gsAssembler -include("gsAssembler.jl") - # Load gsCore include("gsCore.jl") +# Load gsAssembler +include("gsAssembler.jl") + # Load gsHSplines include("gsHSplines.jl") diff --git a/src/gsAssembler.jl b/src/gsAssembler.jl index 3091bc6..1df78ef 100644 --- a/src/gsAssembler.jl +++ b/src/gsAssembler.jl @@ -1,13 +1,22 @@ export QuadRule, + GaussRule, + LobattoRule, destroy!, - show + show, + numNodes, + dim, + mapTo, + mapTo #= TODO =# ######################################################################## # gsQuadRule ######################################################################## +""" +A struct that represents a quadrature rule +""" mutable struct QuadRule ptr::Ptr{gsCQuadRule} @@ -19,6 +28,12 @@ mutable struct QuadRule return b end + #= This function depends on Basis and OptionList, which are dependencies. Can we do some forward declarations, or should we take care of this in the ordering in Declaraions.jl? =# + # function QuadRule(basis::Basis, options::OptionList, fixDirection::Bool=false) + # quad = ccall((:gsQuadRule_get,libgismo),Ptr{gsCQuadRule},(Ptr{gsCBasis},Ptr{gsCOptionList},Cint),basis.ptr,options.ptr,Int(fixDirection)) + # return QuadRule(quad) + # end + function destroy!(qr::QuadRule) ccall((:gsQuadRule_delete,libgismo),Cvoid,(Ptr{gsCQuadRule},),qr.ptr) end @@ -26,3 +41,124 @@ end Base.show(io::IO, obj::QuadRule) = ccall((:gsQuadRule_print,libgismo),Cvoid,(Ptr{gsCQuadRule},),obj.ptr) +""" +Returns a Gauss rule for numerical integration + +# Arguments +- `d::Cint`: the dimension of the rule +- `numNodes::Array{Cint}`: a vector of length `d` with the number of points in each direction +- `digits::Cint`: the number of digits of precision for the rule (optionals) + +""" +function GaussRule(d::Cint, numNodes::Array{Cint}, digits::Cint=Cint(0))::QuadRule + @assert d == length(numNodes) "GaussRule: numNodes must have the same size as the dimension" + qr = ccall((:gsGaussRule_create,libgismo),Ptr{gsCQuadRule},(Cint,Ptr{Cint},Cint),d,numNodes,digits) + return QuadRule(qr) +end + +""" +Returns a Gauss rule for numerical integration + +# Arguments +- `numNodes::Cint`: the number of points in each direction +- `digits::Cint`: the number of digits of precision for the rule (optionals) + +""" +function GaussRule(numNodes::Cint, digits::Cint=Cint(0))::QuadRule + d::Cint = 1; + numNodesVec::Array{Cint} = [numNodes] + qr = ccall((:gsGaussRule_create,libgismo),Ptr{gsCQuadRule},(Cint,Ptr{Cint},Cint),d,numNodesVec,digits) + return QuadRule(qr) +end + +""" +Returns a Lobatto rule for numerical integration + +# Arguments +- `d::Cint`: the dimension of the rule +- `numNodes::Array{Cint}`: a vector of length `d` with the number of points in each direction +- `digits::Cint`: the number of digits of precision for the rule (optionals) + +""" +function LobattoRule(d::Cint, numNodes::Array{Cint}, digits::Cint=Cint(0))::QuadRule + @assert d == length(numNodes) "LobattoRule: numNodes must have the same size as the dimension" + qr = ccall((:gsLobattoRule_create,libgismo),Ptr{gsCQuadRule},(Cint,Ptr{Cint},Cint),d,numNodes,digits) + return QuadRule(qr) +end + +""" +Returns a Lobatto rule for numerical integration + +# Arguments +- `numNodes::Cint`: the number of points in each direction +- `digits::Cint`: the number of digits of precision for the rule (optionals) + +""" +function LobattoRule(numNodes::Cint, digits::Cint=Cint(0))::QuadRule + d::Cint = 1; + numNodesVec::Array{Cint} = [numNodes] + qr = ccall((:LobattoRule_create,libgismo),Ptr{gsCQuadRule},(Cint,Ptr{Cint},Cint),d,numNodesVec,digits) + return QuadRule(qr) +end + +""" +Returns the number of nodes + +# Arguments +- `qr::QuadRule`: the quad rule + +""" +function numNodes(qr::QuadRule) + return ccall((:gsQuadRule_numNodes,libgismo),Cint,(Ptr{gsCQuadRule},),qr.ptr) +end + +""" +Returns the dimension of the quad rule + +# Arguments +- `qr::QuadRule`: the quad rule + +""" +function dim(qr::QuadRule) + return ccall((:gsQuadRule_dim,libgismo),Cint,(Ptr{gsCQuadRule},),qr.ptr) +end + +""" +Maps the quad rule to a given interval + +# Arguments +- `qr::QuadRule`: the quad rule +- `lower::Vector{Cdouble}`: the lower bound of the interval +- `upper::Vector{Cdouble}`: the upper bound of the interval + +""" +function mapTo(qr::QuadRule, lower::Vector{Cdouble}, upper::Vector{Cdouble})::Tuple{EigenMatrix,EigenMatrix} + @assert length(lower) == length(upper) == dim(qr) "mapTo: lower and upper must have the same size as the dimension of the quad rule" + nodes = EigenMatrix(); + weights = EigenMatrix(); + low = EigenMatrix(Base.size(lower,1),1,pointer(lower)); + upp = EigenMatrix(Base.size(upper,1),1,pointer(upper)); + ccall((:gsQuadRule_mapTo,libgismo),Cvoid, + (Ptr{gsCQuadRule},Ptr{gsCMatrix},Ptr{gsCMatrix},Ptr{gsCMatrix},Ptr{gsCMatrix}), + qr.ptr,low.ptr,upp.ptr,nodes.ptr,weights.ptr) + return nodes, weights +end + +""" +Maps the quad rule to a given interval + +# Arguments +- `qr::QuadRule`: the quad rule +- `startVal::Cdouble`: the lower bound of the interval +- `endVal::Cdouble`: the upper bound of the interval + +""" +function mapTo(qr::QuadRule, startVal::Cdouble, endVal::Cdouble)::Tuple{EigenMatrix,EigenMatrix} + @assert startVal < endVal "mapTo: startVal must be smaller than endVal" + nodes = EigenMatrix(); + weights = EigenMatrix(); + ccall((:gsQuadRule_mapToScalar,libgismo),Cvoid, + (Ptr{gsCQuadRule},Cdouble,Cdouble,Ptr{gsCMatrix},Ptr{gsCMatrix}), + qr.ptr,startVal,endVal,nodes.ptr,weights.ptr) + return nodes, weights +end \ No newline at end of file diff --git a/src/gsCore.jl b/src/gsCore.jl index 545d8cd..ebe8e82 100644 --- a/src/gsCore.jl +++ b/src/gsCore.jl @@ -40,11 +40,11 @@ mutable struct Basis """ Makes a Gismo Basis from a pointer to a G+Smo basis. - ... + # Arguments - `basis::Ptr{gsCBasis}`: pointer to a G+Smo basis - `delete::Bool=true`: if true, julia will delete the pointer - ... + """ function Basis(basis::Ptr{gsCBasis},delete::Bool=true) @@ -57,10 +57,10 @@ mutable struct Basis """ Makes a Gismo Basis from a file. - ... + # Arguments - `filename::String`: the name of the file - ... + """ function Basis(filename::String) b = new(ccall((:gsCReadFile,libgismo),Ptr{gsCBasis},(Cstring,),filename) ) @@ -70,10 +70,10 @@ mutable struct Basis """ Deletes a Gismo Basis - ... + # Arguments - `b::Basis`: a Gismo Basis - ... + """ function destroy!(b::Basis) ccall((:gsFunctionSet_delete,libgismo),Cvoid,(Ptr{gsCFunctionSet},),b.ptr) @@ -82,10 +82,10 @@ end """ Returns the domain dimension of a basis -... + # Arguments - `object::Basis`: a Gismo Basis -... + """ function domainDim(object::Basis)::Cint return ccall((:gsFunctionSet_domainDim,libgismo),Cint,(Ptr{gsCFunctionSet},),object.ptr) @@ -93,10 +93,10 @@ end """ Returns the target dimension of a basis -... + # Arguments - `object::Basis`: a Gismo Basis -... + """ function targetDim(object::Basis)::Cint return ccall((:gsFunctionSet_targetDim,libgismo),Cint,(Ptr{gsCFunctionSet},),object.ptr) @@ -106,11 +106,11 @@ Base.show(io::IO, obj::Basis) = ccall((:gsFunctionSet_print,libgismo),Cvoid,(Ptr """ Returns the component of a basis -... + # Arguments - `obj::Basis`: a Gismo Basis - `i::Cint`: the index of the component -... + """ function component(obj::Basis,i::Cint)::Basis b = ccall((:gsBasis_component,libgismo),Ptr{gsCBasis},(Ptr{gsCBasis},Cint),obj.ptr,i) @@ -119,11 +119,11 @@ end """ Returns the degree of a basis -... + # Arguments - `obj::Basis`: a Gismo Basis - `i::Cint`: the index of the component -... + """ function degree(obj::Basis,i::Cint)::Cint return ccall((:gsBasis_degree,libgismo),Cint,(Ptr{gsCBasis},Cint),obj.ptr,i) @@ -131,10 +131,10 @@ end """ Returns the number of elements of a basis -... + # Arguments - `obj::Basis`: a Gismo Basis -... + """ function numElements(obj::Basis)::Cint return ccall((:gsBasis_numElements,libgismo),Cint,(Ptr{gsCBasis},),obj.ptr) @@ -142,10 +142,10 @@ end """ Returns the size of a basis -... + # Arguments - `obj::Basis`: a Gismo Basis -... + """ function size(obj::Basis)::Cint return ccall((:gsBasis_size,libgismo),Cint,(Ptr{gsCBasis},),obj.ptr) @@ -156,13 +156,13 @@ end """ Refines a basis -... + # Arguments - `obj::Basis`: a Gismo Basis - `numKnots::Cint=Int32(1)`: the number of knots to add - `mul::Cint=Int32(1)`: the multiplicity of the knots - `dir::Cint=Int32(-1)`: the direction of the refinement -... + """ function uniformRefine!(obj::Basis,numKnots::Cint=Int32(1),mul::Cint=Int32(1),dir::Cint=Int32(-1))::Nothing ccall((:gsBasis_uniformRefine,libgismo),Cvoid, @@ -171,11 +171,11 @@ end """ Refines a basis -... + # Arguments - `obj::Basis`: a Gismo Basis - `boxes::Vector{Cint}`: the boxes to refine (in index format) -... + """ function refineElements!(obj::Basis,boxes::Vector{Cint})::Nothing @assert mod(length(boxes),2*domainDim(obj)+1)==0 "Boxes should have size 2*domainDim+1" @@ -186,11 +186,12 @@ end """ Refines a basis -... + # Arguments - `obj::Basis`: a Gismo Basis - `boxes::Matrix{Cdouble}`: the boxes to refine (first column is the lower bound, second column is the upper bound) -... +- `refExt::Cint=Int32(0)`: the refinement extension + """ function refine!(obj::Basis,boxes::Matrix{Cdouble},refExt::Cint=Int32(0))::Nothing @assert Base.size(boxes,1)==domainDim(obj) "The boxes should have the same number of rows as the domain dimension" @@ -204,11 +205,11 @@ end """ Returns the actives of a basis -... + # Arguments - `obj::Basis`: a Gismo Basis - `u::Matrix{Cdouble}`: a matrix of points -... + """ function actives(obj::Basis,u::Matrix{Cdouble})::EigenMatrixInt @assert Base.size(u,1)==domainDim(obj) "Domain dimension should be equal to the number of rows of the points" @@ -222,11 +223,11 @@ end """ Returns the evaluation of a basis -... + # Arguments - `obj::Basis`: a Gismo Basis - `u::Matrix{Cdouble}`: a matrix of points -... + """ function val(obj::Basis,u::Matrix{Cdouble})::EigenMatrix @assert Base.size(u,1)==domainDim(obj) "Domain dimension should be equal to the number of rows of the points" @@ -241,11 +242,11 @@ end """ Returns the derivative of a basis -... + # Arguments - `obj::Basis`: a Gismo Basis - `u::Matrix{Cdouble}`: a matrix of points -... + """ function deriv(obj::Basis,u::Matrix{Cdouble})::EigenMatrix @assert Base.size(u,1)==domainDim(obj) "Domain dimension should be equal to the number of rows of the points" @@ -258,11 +259,11 @@ function deriv(obj::Basis,u::Matrix{Cdouble})::EigenMatrix end """ Returns the second derivative of a basis -... + # Arguments - `obj::Basis`: a Gismo Basis - `u::Matrix{Cdouble}`: a matrix of points -... + """ function deriv2(obj::Basis,u::Matrix{Cdouble})::EigenMatrix @assert Base.size(u,1)==domainDim(obj) "Domain dimension should be equal to the number of rows of the points" @@ -276,12 +277,12 @@ end """ Returns the evaluation of a single basis function -... + # Arguments - `obj::Basis`: a Gismo Basis - `i::Cint`: the index of the basis function - `u::Matrix{Cdouble}`: a matrix of points -... + """ function evalSingle(obj::Basis,i::Cint,u::Matrix{Cdouble})::EigenMatrix @assert Base.size(u,1)==domainDim(obj) "Domain dimension should be equal to the number of rows of the points" @@ -295,12 +296,12 @@ end """ Returns the derivative of a single basis function -... + # Arguments - `obj::Basis`: a Gismo Basis - `i::Cint`: the index of the basis function - `u::Matrix{Cdouble}`: a matrix of points -... + """ function derivSingle(obj::Basis,i::Cint,u::Matrix{Cdouble})::EigenMatrix @assert Base.size(u,1)==domainDim(obj) "Domain dimension should be equal to the number of rows of the points" @@ -314,12 +315,12 @@ end """ Returns the second derivative of a single basis function -... + # Arguments - `obj::Basis`: a Gismo Basis - `i::Cint`: the index of the basis function - `u::Matrix{Cdouble}`: a matrix of points -... + """ function deriv2Single(obj::Basis,i::Cint,u::Matrix{Cdouble})::EigenMatrix @assert Base.size(u,1)==domainDim(obj) "Domain dimension should be equal to the number of rows of the points" @@ -344,11 +345,11 @@ mutable struct Geometry # delete==true: julia will delete the pointer """ Makes a Gismo Geometry from a pointer to a G+Smo geometry. - ... + # Arguments - `geom::Ptr{gsCGeometry}`: pointer to a G+Smo geometry - `delete::Bool=true`: if true, julia will delete the pointer - ... + """ function Geometry(geom::Ptr{gsCGeometry},delete::Bool=true) @@ -373,10 +374,10 @@ end """ Return the domain dimension of a geometry -... + # Arguments - `object::Geometry`: a Gismo Geometry -... + """ function domainDim(object::Geometry)::Cint return ccall((:gsFunctionSet_domainDim,libgismo),Cint,(Ptr{gsCFunctionSet},),object.ptr) @@ -384,10 +385,10 @@ end """ Returns the target dimension of a geometry -... + # Arguments - `object::Geometry`: a Gismo Geometry -... + """ function targetDim(object::Geometry)::Cint return ccall((:gsFunctionSet_targetDim,libgismo),Cint,(Ptr{gsCFunctionSet},),object.ptr) @@ -397,10 +398,10 @@ Base.show(io::IO, obj::Geometry) = ccall((:gsFunctionSet_print,libgismo),Cvoid,( """ Returns the basis of a geometry -... + # Arguments - `obj::Geometry`: a Gismo Geometry -... + """ function basis(obj::Geometry)::Basis b = ccall((:gsBasis_basis,libgismo),Ptr{gsCBasis},(Ptr{gsCGeometry},),obj.ptr) @@ -409,10 +410,10 @@ end """ Returns the coefficients of a geometry -... + # Arguments - `obj::Geometry`: a Gismo Geometry -... + """ function coefs(obj::Geometry)::EigenMatrix result = EigenMatrix() @@ -422,11 +423,11 @@ end """ Returns the evaluation of a geometry -... + # Arguments - `obj::Geometry`: a Gismo Geometry - `u::Matrix{Cdouble}`: a matrix of points -... + """ function val(obj::Geometry,u::Matrix{Cdouble})::EigenMatrix @assert Base.size(u,1)==domainDim(obj) "Domain dimension should be equal to the number of rows of the points" @@ -440,11 +441,11 @@ end """ Returns the derivative of a geometry -... + # Arguments - `obj::Geometry`: a Gismo Geometry - `u::Matrix{Cdouble}`: a matrix of points -... + """ function deriv(obj::Geometry,u::Matrix{Cdouble})::EigenMatrix @assert Base.size(u,1)==domainDim(obj) "Domain dimension should be equal to the number of rows of the points" @@ -458,11 +459,11 @@ end """ Returns the second derivative of a geometry -... + # Arguments - `obj::Geometry`: a Gismo Geometry - `u::Matrix{Cdouble}`: a matrix of points -... + """ function deriv2(obj::Geometry,u::Matrix{Cdouble})::EigenMatrix @assert Base.size(u,1)==domainDim(obj) "Domain dimension should be equal to the number of rows of the points" @@ -476,11 +477,11 @@ end """ Returns the normal of a geometry -... + # Arguments - `obj::Geometry`: a Gismo Geometry - `u::Matrix{Cdouble}`: a matrix of points -... + """ function normal(obj::Geometry,u::Matrix{Cdouble})::EigenMatrix @assert Base.size(u,1)==domainDim(obj) "Domain dimension should be equal to the number of rows of the points" @@ -494,12 +495,12 @@ end """ Returns the closest point of a geometry -... + # Arguments - `obj::Geometry`: a Gismo Geometry - `x::Matrix{Cdouble}`: a matrix of points - `accuracy::Cdouble=1e-6`: the accuracy of the computation -... + """ function closest(obj::Geometry,x::Matrix{Cdouble},accuracy::Cdouble=1e-6)::Tuple{Cdouble,EigenMatrix} xx = EigenMatrix(Base.size(x,1), Base.size(x,2), pointer(x) ) @@ -512,12 +513,12 @@ end """ Inverts a set of points -... + # Arguments - `obj::Geometry`: a Gismo Geometry - `x::Matrix{Cdouble}`: a matrix of points - `accuracy::Cdouble=1e-6`: the accuracy of the computation -... + """ function invertPoints(obj::Geometry,x::Matrix{Cdouble},accuracy::Cdouble=1e-6)::EigenMatrix xx = EigenMatrix(Base.size(x,1), 1, pointer(x) ) @@ -544,6 +545,14 @@ mutable struct MultiPatch # return g # end + function MultiPatch(multipatch::Ptr{gsCMultiPatch},delete::Bool=true) + b = new(multipatch) + if (delete) + finalizer(destroy!,b) + end + return b + end + function MultiPatch() m = new(ccall((:gsMultiPatch_create,libgismo),Ptr{gsCMultiPatch},(),) ) finalizer(destroy!, m) @@ -557,11 +566,11 @@ end """ Adds a patch to a MultiPatch -... + # Arguments - `obj::MultiPatch`: a Gismo MultiPatch - `geom::Geometry`: a Gismo Geometry -... + """ function domainDim(object::MultiPatch)::Cint return ccall((:gsFunctionSet_domainDim,libgismo),Cint,(Ptr{gsCFunctionSet},),object.ptr) @@ -569,10 +578,10 @@ end """ Returns the target dimension of a MultiPatch -... + # Arguments - `object::MultiPatch`: a Gismo MultiPatch -... + """ function targetDim(object::MultiPatch)::Cint return ccall((:gsFunctionSet_targetDim,libgismo),Cint,(Ptr{gsCFunctionSet},),object.ptr) @@ -582,10 +591,10 @@ Base.show(io::IO, obj::MultiPatch) = ccall((:gsFunctionSet_print,libgismo),Cvoid """ Returns the basis of a MultiPatch -... + # Arguments - `obj::MultiPatch`: a Gismo MultiPatch -... + """ function addPatch!(obj::MultiPatch,geom::Geometry)::Nothing ccall((:gsMultiPatch_addPatch,libgismo),Cvoid,(Ptr{gsCMultiPatch},Ptr{gsCGeometry},),obj.ptr,geom.ptr) @@ -593,10 +602,10 @@ end """ Returns the coefficients of a MultiPatch -... + # Arguments - `obj::MultiPatch`: a Gismo MultiPatch -... + """ function basis(obj::MultiPatch,i::Int)::Basis b = ccall((:gsMultiPatch_basis,libgismo),Ptr{gsCBasis},(Ptr{gsCFunctionSet},Cint),obj.ptr,i) @@ -605,10 +614,11 @@ end """ Returns the coefficients of a MultiPatch -... + # Arguments - `obj::MultiPatch`: a Gismo MultiPatch -... +- `i::Int`: the index of the patch + """ function patch(obj::MultiPatch,i::Int)::Geometry g = ccall((:gsMultiPatch_patch,libgismo),Ptr{gsCGeometry},(Ptr{gsCMultiPatch},Cint),obj.ptr,i) @@ -644,11 +654,11 @@ end """ Returns the basus of a MultiBasis -... + # Arguments - `obj::MultiBasis`: a Gismo MultiBasis - `i::Int`: the index of the basis -... + """ function basis(obj::MultiBasis,i::Int)::Basis b = ccall((:gsMultiBasis_basis,libgismo),Ptr{gsCBasis},(Ptr{gsCFunctionSet},Cint),obj.ptr,i) diff --git a/src/gsHSplines.jl b/src/gsHSplines.jl index e967c3e..070e64b 100644 --- a/src/gsHSplines.jl +++ b/src/gsHSplines.jl @@ -6,10 +6,9 @@ THBSplineBasis """ THBSplineBasis(basis::Basis) -... + # Arguments - `basis::Basis`: a basis object -... # Examples ```jldoctest diff --git a/src/gsIO.jl b/src/gsIO.jl index 219ae22..ac0bf96 100644 --- a/src/gsIO.jl +++ b/src/gsIO.jl @@ -1,33 +1,75 @@ export OptionList, - destroy! - show + destroy!, + show, + addString, + addInt, + addSwitch, + addReal, + getString, + getInt, + getSwitch, + getReal, + setString, + setInt, + setSwitch, + setReal #= TODO =# ######################################################################## # gsOptionList ######################################################################## +""" +A struct that represents a list of options +""" mutable struct OptionList ptr::Ptr{gsCOptionList} function OptionList(opt::Ptr{gsCOptionList},delete::Bool=true) b = new(opt) if (delete) - finalizer(destroy,b) + finalizer(destroy!,b) end return b end + """ + Create an empty option list + + # Examples + ```jldoctest output=(false) + opt = OptionList() + # output + ``` + """ + function OptionList() + opt = ccall((:gsOptionList_create,libgismo),Ptr{gsCOptionList},(),) + return OptionList(opt) + end + + """ + Create an option list from a dictionary + + # Arguments + - `options::Dict`: a dictionary with the options + + # Examples + ```jldoctest output=(false) + options = Dict("key1"=>"value1","key2"=>2,"key3"=>3.0,"key4"=>true) + opt = OptionList(options) + # output + ``` + """ function OptionList(options::Dict) - opt = ccall((:gsOptionList_new,libgismo),Ptr{gsCOptionList},(),) + opt = ccall((:gsOptionList_create,libgismo),Ptr{gsCOptionList},(),) # Empty string desc::String = "" for (key,value) in options if (typeof(value) == String) ccall((:gsOptionList_addString,libgismo),Cvoid,(Ptr{gsCOptionList},Cstring,Cstring,Cstring),opt,key,desc,value) elseif (typeof(value) == Int) - ccall((:gsOptionList_addInr,libgismo),Cvoid,(Ptr{gsCOptionList},Cstring,Cstring,Cint),opt,key,desc,value) + ccall((:gsOptionList_addInt,libgismo),Cvoid,(Ptr{gsCOptionList},Cstring,Cstring,Cint),opt,key,desc,value) elseif (typeof(value) == Float64) ccall((:gsOptionList_addReal,libgismo),Cvoid,(Ptr{gsCOptionList},Cstring,Cstring,Cdouble),opt,key,desc,value) elseif (typeof(value) == Bool) @@ -46,4 +88,251 @@ end Base.show(io::IO, obj::OptionList) = ccall((:gsOptionList_print,libgismo),Cvoid,(Ptr{gsCOptionList},),obj.ptr) +# Adders +""" +Add a string to the option list + +# Arguments +- `opt::OptionList`: the option list +- `key::String`: the key +- `string::String`: the value +- `desc::String`: the description + +# Examples +```jldoctest output=(false) +opt = OptionList() +addString(opt,"key","value","description") +# output +``` +""" +function addString(opt::OptionList,key::String,string::String,desc::String="") + ccall((:gsOptionList_addString,libgismo),Cvoid,(Ptr{gsCOptionList},Cstring,Cstring,Cstring),opt.ptr,key,desc,string) +end + +""" +Add an integer to the option list + +# Arguments +- `opt::OptionList`: the option list +- `key::String`: the key +- `int::Int64`: the value +- `desc::String`: the description + +# Examples +```jldoctest output=(false) +opt = OptionList() +addInt(opt,"key",1,"description") +# output +``` +""" +function addInt(opt::OptionList,key::String,int::Int64,desc::String="") + ccall((:gsOptionList_addInt,libgismo),Cvoid,(Ptr{gsCOptionList},Cstring,Cstring,Cint),opt.ptr,key,desc,int) +end + +""" +Add a real to the option list + +# Arguments +- `opt::OptionList`: the option list +- `key::String`: the key +- `real::Cdouble`: the value +- `desc::String`: the description + +# Examples +```jldoctest output=(false) +opt = OptionList() +addReal(opt,"key",1.0,"description") +# output +``` +""" +function addReal(opt::OptionList,key::String,real::Cdouble,desc::String="") + ccall((:gsOptionList_addReal,libgismo),Cvoid,(Ptr{gsCOptionList},Cstring,Cstring,Cdouble),opt.ptr,key,desc,real) +end + +""" +Add a switch to the option list + +# Arguments +- `opt::OptionList`: the option list +- `key::String`: the key +- `switch::Bool`: the value +- `desc::String`: the description + +# Examples +```jldoctest output=(false) +opt = OptionList() +addSwitch(opt,"key",true,"description") +# output +``` +""" +function addSwitch(opt::OptionList,key::String,switch::Bool,desc::String="") + ccall((:gsOptionList_addSwitch,libgismo),Cvoid,(Ptr{gsCOptionList},Cstring,Cstring,Cint),opt.ptr,key,desc,Cint(switch)) +end + +# Getters +""" +Get a string from the option list + +# Arguments +- `opt::OptionList`: the option list +- `key::String`: the key + +# Return +- `string::Cstring`: the value + +# Examples +#```jldoctest +opt = OptionList(Dict("key1"=>"value1")) +println(getString(opt,"key1")) +# output +value1 +``` +""" +function getString(opt::OptionList,key::String)::Cstring + return ccall((:gsOptionList_getString,libgismo),Cstring,(Ptr{gsCOptionList},Cstring),opt.ptr,key) +end + +""" +Get an integer from the option list + +# Arguments +- `opt::OptionList`: the option list +- `key::String`: the key + +# Return +- `int::Cint`: the value + +# Examples +```jldoctest +opt = OptionList(Dict("key1"=>1)) +println(getInt(opt,"key1")) +# output +1 +""" +function getInt(opt::OptionList,key::String)::Cint + return ccall((:gsOptionList_getInt,libgismo),Cint,(Ptr{gsCOptionList},Cstring),opt.ptr,key) +end + +""" +Get a real from the option list + +# Arguments +- `opt::OptionList`: the option list +- `key::String`: the key + +# Return +- `real::Cdouble`: the value + +# Examples +```jldoctest +opt = OptionList(Dict("key1"=>1.0)) +println(getReal(opt,"key1")) +# output +1.0 +``` +""" +function getReal(opt::OptionList,key::String)::Cdouble + return ccall((:gsOptionList_getReal,libgismo),Cdouble,(Ptr{gsCOptionList},Cstring),opt.ptr,key) +end + +""" +Get a switch from the option list + +# Arguments +- `opt::OptionList`: the option list +- `key::String`: the key + +# Return +- `switch::Bool`: the value + +# Examples +```jldoctest +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) +end + +# Setters +""" +Set a string to the option list + +# Arguments +- `opt::OptionList`: the option list +- `key::String`: the key +- `string::String`: the value + +# Examples +```jldoctest output=(false) +opt = OptionList(Dict("key"=>"value")) +setString(opt,"key","value") +# output +``` +""" +function setString(opt::OptionList,key::String,string::String) + try + ccall((:gsOptionList_setString,libgismo),Cvoid,(Ptr{gsCOptionList},Cstring,Cstring),opt.ptr,key,string) + catch + error("OptionList: Key not found") + end +end + +""" +Set an integer to the option list + +# Arguments +- `opt::OptionList`: the option list +- `key::String`: the key +- `int::Cint`: the value + +# Εxamples +```jldoctest output=(false) +opt = OptionList(Dict("key"=>1)) +setInt(opt,"key",2) +# output +``` +""" +function setInt(opt::OptionList,key::String,int::Int64) + ccall((:gsOptionList_setInt,libgismo),Cvoid,(Ptr{gsCOptionList},Cstring,Cint),opt.ptr,key,int) +end + +""" +Set a real to the option list + +# Arguments +- `opt::OptionList`: the option list +- `key::String`: the key +- `real::Cdouble`: the value + +# Examples +```jldoctest output=(false) +opt = OptionList(Dict("key"=>1.0)) +setReal(opt,"key",2.0) +# output +``` +""" +function setReal(opt::OptionList,key::String,real::Cdouble) + ccall((:gsOptionList_setReal,libgismo),Cvoid,(Ptr{gsCOptionList},Cstring,Cdouble),opt.ptr,key,real) +end + +""" +Set a switch to the option list + +# Arguments +- `opt::OptionList`: the option list +- `key::String`: the key +- `switch::Bool`: the value +# Examples +```jldoctest output=(false) +opt = OptionList(Dict("key"=>true)) +setSwitch(opt,"key",false) +# output +``` +""" +function setSwitch(opt::OptionList,key::String,switch::Bool) + ccall((:gsOptionList_setSwitch,libgismo),Cvoid,(Ptr{gsCOptionList},Cstring,Cint),opt.ptr,key,Cint(switch)) +end \ No newline at end of file diff --git a/src/gsMatrix.jl b/src/gsMatrix.jl index d97d945..6f5b034 100644 --- a/src/gsMatrix.jl +++ b/src/gsMatrix.jl @@ -6,21 +6,21 @@ rows, cols, data, asMatrix, +asVector, +toMatrix, +toVector, setZero!, EigenMatrixInt, asMatrixInt, +asVectorInt, +toMatrixInt, +toVectorInt, deepcopy ######################################################################## # gsMatrix ######################################################################## -#@ccall library.function_name(argvalue1::argtype1, ...)::returntype - -#@inline function wrap_gsCMatrix(m::Ptr{gsCMatrix}) -# return unsafe_wrap(Array{Float64}, gsMatrix_data(m), (gsMatrix_rows(m), gsMatrix_cols(m))) -#end - """ EigenMatrix() @@ -49,7 +49,7 @@ mutable struct EigenMatrix return m end - function EigenMatrix(r::Int,c::Int, data::Ptr{Cdouble}) + function EigenMatrix(r::Int64,c::Int64, data::Ptr{Cdouble}) m = new(ccall((:gsMatrix_create_rcd,libgismo),Ptr{gsCMatrix}, (Cint,Cint,Ptr{Cdouble},), r, c, data) ) finalizer(destroy!, m) @@ -63,10 +63,10 @@ end """ Returns the number of rows in the matrix. -... + # Arguments - `object::EigenMatrix`: the matrix -... + # Examples ```jldoctest myEigenMatrix m = EigenMatrix(3,3) @@ -79,24 +79,90 @@ function rows(object::EigenMatrix)::Int64 return ccall((:gsMatrix_rows,libgismo),Cint,(Ptr{gsCMatrix},),object.ptr) end +""" +Returns the number of columns in the matrix. + +# Arguments +- `object::EigenMatrix`: the matrix + +# Examples +```jldoctest myEigenMatrix +m = EigenMatrix(3,3) +print(Gismo.cols(m)) +# output +3 +``` +""" function cols(object::EigenMatrix)::Int64 return ccall((:gsMatrix_cols,libgismo),Cint,(Ptr{gsCMatrix},),object.ptr) end +""" +Returns a pointer to the data of the matrix. + +# Arguments +- `object::EigenMatrix`: the matrix + +""" function data(object::EigenMatrix)::Ptr{Cdouble} return ccall((:gsMatrix_data,libgismo),Ptr{Cdouble},(Ptr{gsCMatrix},),object.ptr) end +""" +Returns the matrix as a Julia matrix (transfers ownership). + +# Arguments +- `object::EigenMatrix`: the matrix + +""" +function toMatrix(object::EigenMatrix)::Matrix{Cdouble} + return unsafe_wrap(Array, data(object), (rows(object),cols(object)); own = true) +end + +""" +Returns the matrix as a Julia vector (transfers ownership). + +# Arguments +- `object::EigenMatrix`: the matrix + +""" +function toVector(object::EigenMatrix)::Vector{Cdouble} + return unsafe_wrap(Array, data(object), (rows(object)); own = true) +end + +""" +Returns the matrix as a Julia matrix. + +# Arguments +- `object::EigenMatrix`: the matrix + +""" function asMatrix(object::EigenMatrix)::Matrix{Cdouble} - return unsafe_wrap(Array, data(object), (rows(object),cols(object)); own = false) + return unsafe_wrap(Array, Base.unsafe_convert(Ptr{Cdouble},data(object)), (rows(object),cols(object)); own = false) end +""" +Returns the matrix as a Julia vector. + +# Arguments +- `object::EigenMatrix`: the matrix + +""" +function asVector(object::EigenMatrix)::Vector{Cdouble} + return unsafe_wrap(Array, data(object), (rows(object)); own = false) +end Base.deepcopy(obj::EigenMatrix) = EigenMatrix(rows(obj),cols(obj),data(obj)) -# Base.show(io::IO, obj::EigenMatrix) = asMatrix(obj) Base.show(io::IO, obj::EigenMatrix) = ccall((:gsMatrix_print,libgismo),Cvoid,(Ptr{gsCMatrix},),obj.ptr) +""" +Sets all the elements of the matrix to zero. + +# Arguments +- `object::EigenMatrix`: the matrix + +""" function setZero!(object::EigenMatrix)::Nothing ccall((:gsMatrix_setZero,libgismo),Cvoid,(Ptr{gsCMatrix},),object.ptr) end @@ -105,21 +171,25 @@ end # gsMatrixInt ######################################################################## -#@ccall library.function_name(argvalue1::argtype1, ...)::returntype - -#@inline function wrap_gsCMatrix(m::Ptr{gsCMatrix}) -# return unsafe_wrap(Array{Float64}, gsMatrix_data(m), (gsMatrix_rows(m), gsMatrix_cols(m))) -#end - mutable struct EigenMatrixInt ptr::Ptr{gsCMatrixInt} + """ + Creates an empty matrix. + """ function EigenMatrixInt() m = new( ccall((:gsMatrixInt_create,libgismo),Ptr{gsCMatrixInt},()) ) finalizer(destroy!, m) return m end + """ + Creates an empty matrix + + # Arguments + - `r::Int64`: the number of rows + - `c::Int64`: the number of columns + """ function EigenMatrixInt(r::Int64,c::Int64) m = new(ccall((:gsMatrixInt_create_rc,libgismo),Ptr{gsCMatrixInt}, (Cint,Cint), r, c) ) @@ -127,7 +197,15 @@ mutable struct EigenMatrixInt return m end - function EigenMatrixInt(r::Int,c::Int, data::Ptr{Cint}) + """ + Creates a matrix from a pointer to the data + + # Arguments + - `r::Int64`: the number of rows + - `c::Int64`: the number of columns + - `data::Ptr{Cint}`: the pointer to the data + """ + function EigenMatrixInt(r::Int64,c::Int64, data::Ptr{Cint}) m = new(ccall((:gsMatrixInt_create_rcd,libgismo),Ptr{gsCMatrixInt}, (Cint,Cint,Ptr{Cint},), r, c, data) ) finalizer(destroy!, m) @@ -139,28 +217,110 @@ mutable struct EigenMatrixInt end end +""" +Returns the number of rows in the matrix. + +# Arguments +- `object::EigenMatrixInt`: the matrix + +# Examples +```jldoctest myEigenMatrixInt +m = EigenMatrixInt(3,3) +print(Gismo.rows(m)) +# output +3 +``` +""" function rows(object::EigenMatrixInt)::Int64 return ccall((:gsMatrixInt_rows,libgismo),Cint,(Ptr{gsCMatrixInt},),object.ptr) end +""" +Returns the number of columns in the matrix. + +# Arguments +- `object::EigenMatrixInt`: the matrix + +# Examples +```jldoctest myEigenMatrixInt +m = EigenMatrixInt(3,3) +print(Gismo.cols(m)) +# output +3 +``` +""" function cols(object::EigenMatrixInt)::Int64 return ccall((:gsMatrixInt_cols,libgismo),Cint,(Ptr{gsCMatrixInt},),object.ptr) end +""" +Returns a pointer to the data of the matrix. + +# Arguments +- `object::EigenMatrixInt`: the matrix + +""" function data(object::EigenMatrixInt)::Ptr{Cint} return ccall((:gsMatrixInt_data,libgismo),Ptr{Cint},(Ptr{gsCMatrixInt},),object.ptr) end +""" +Returns the matrix as a Julia matrix (transfers ownership). + +# Arguments +- `object::EigenMatrixInt`: the matrix + +""" +function toMatrixInt(object::EigenMatrixInt)::MatrixInt{Cint} + return unsafe_wrap(Array, data(object), (rows(object),cols(object)); own = true) +end + +""" +Returns the matrix as a Julia vector (transfers ownership). + +# Arguments +- `object::EigenMatrixInt`: the matrix + +""" +function toVectorInt(object::EigenMatrixInt)::Vector{Cint} + return unsafe_wrap(Array, data(object), (rows(object)); own = true) +end + +""" +Returns the matrix as a Julia matrix. + +# Arguments +- `object::EigenMatrixInt`: the matrix + +""" function asMatrixInt(object::EigenMatrixInt)::MatrixInt{Cint} return unsafe_wrap(Array, data(object), (rows(object),cols(object)); own = false) end +""" +Returns the matrix as a Julia vector. + +# Arguments +- `object::EigenMatrixInt`: the matrix + +""" +function asVectorInt(object::EigenMatrixInt)::Vector{Cint} + return unsafe_wrap(Array, data(object), (rows(object)); own = false) +end Base.deepcopy(obj::EigenMatrixInt) = EigenMatrixInt(rows(obj),cols(obj),data(obj)) # Base.show(io::IO, obj::EigenMatrixInt) = asMatrixInt(obj) Base.show(io::IO, obj::EigenMatrixInt) = ccall((:gsMatrixInt_print,libgismo),Cvoid,(Ptr{gsCMatrixInt},),obj.ptr) +""" +Sets all the elements of the matrix to zero. + +# Arguments +- `object::EigenMatrixInt`: the matrix + +""" function setZero!(object::EigenMatrixInt)::Nothing ccall((:gsMatrixInt_setZero,libgismo),Cvoid,(Ptr{gsCMatrixInt},),object.ptr) end + diff --git a/src/gsModeling.jl b/src/gsModeling.jl index 1d9f02b..4100a39 100644 --- a/src/gsModeling.jl +++ b/src/gsModeling.jl @@ -23,11 +23,11 @@ mutable struct Fitting """ Fitting(opt::Ptr{gsCFitting},delete:Bool) - ... + # Arguments - `opt::Ptr{gsCFitting}`: A pointer to a gsCFiting object - `delete::Bool`: Whether to destroy the fitting structure when unused - ... + """ function Fitting(opt::Ptr{gsCFitting},delete::Bool=true)::Fitting b = new(opt) @@ -37,14 +37,14 @@ mutable struct Fitting return b end - """ + """ Fitting(parValues::Matrix{Cdouble}, pts::Matrix{Cdouble}, basis::Basis)::Fitting - ... + # Arguments - `parValues::Matrix{Cdouble}`: a matrix containing the parameters values - `pts::Matrix{Cdouble}`: a matrix of points - `basis::Basis`: a Basis structure containing the desired basis - ... + """ function Fitting(parValues::AbstractMatrix{Cdouble}, pts::AbstractMatrix{Cdouble}, basis::Basis)::Fitting @assert Base.size(parValues,2) == Base.size(pts,2) "Fitting: parValues and points must have the same number of columns" @@ -63,11 +63,11 @@ end """ compute!(fit::Fitting, lambda::Cdouble=0.0) Computes the least squares fit -... + # Arguments - `fit::Fitting`: a fitting structure - `lambda::Cdouble`: the value to assign to the lambda ridge parameter -... + """ function compute!(fit::Fitting, lambda::Cdouble=0.0) ccall((:gsFitting_compute,libgismo),Cvoid,(Ptr{gsCFitting},Cdouble),fit.ptr,lambda) @@ -76,13 +76,13 @@ end """ parameterCorrection!(fit::Fitting, accuracy::Cdouble, maxIter::Cint, tol0rth::Cdouble) Performs the parameters corrections step -... + # Arguments - `fit::Fitting`: a fitting structure - `accuracy::Cdouble`: The desired accuracy - `maxIter::Cint`: The desired number of iterations - `tol0rth::Cdouble`: The desired value of the tolleance -... + """ function parameterCorrection!(fit::Fitting, accuracy::Cdouble=1.0, maxIter::Cint=Cint(10), tol0rth::Cdouble=1e-6) @assert maxIter >= 0 "Fitting: cannot have a negative number of iterations!" @@ -93,10 +93,10 @@ end """ computeErrors!(fit::Fitting) Computes the error for each point -... + # Arguments - `fit::Fitting`: a fitting structure -... + """ function computeErrors!(fit::Fitting) ccall((:gsFitting_computeErrors,libgismo),Cvoid,(Ptr{gsCFitting},),fit.ptr) @@ -105,12 +105,12 @@ end """ minPointError(fit::Fitting)::Cdouble Returns the smallest error obtained between all the points -... + # Arguments - `fit::Fitting`: a fitting structure # Return - `min_error::Cdouble`: The minimum error obtained -... + """ function minPointError(fit::Fitting)::Cdouble min_error=ccall((:gsFitting_minPointError,libgismo),Cdouble,(Ptr{gsCFitting},),fit.ptr) @@ -120,12 +120,12 @@ end """ maxPointError(fit::Fitting)::Cdouble Returns the maximum error obtained -... + # Arguments - `fit::Fitting`: a fitting structure # Return - `max_error::Cdouble`: The maximum error obtained -... + """ function maxPointError(fit::Fitting)::Cdouble max_err=ccall((:gsFitting_maxPointError,libgismo),Cdouble,(Ptr{gsCFitting},),fit.ptr) @@ -135,13 +135,13 @@ end """ pointWiseErrors(fit::Fitting)::Ptr{Cdouble} Returns the error obtained for each point -... + # Arguments - `fit::Fitting`: a fitting structure -... + # Return - `errors::Ptr{Cdouble}`: Pointer pointing to an array containing the error value for each point -... + """ function pointWiseErrors(fit::Fitting)::Ptr{Cdouble} errors=ccall((:gsFitting_pointWiseErrors,libgismo),Ptr{Cdouble},(Ptr{gsCFitting},),fit.ptr) @@ -151,14 +151,14 @@ end """ numPointsBelow(fit::Fitting, threshold::Cdouble)::Cint Returns the number of points where the error is below the threshold -... + # Arguments - `fit::Fitting`: a fitting structure - `threshold::Cdouble`: The desired threshold -... + # Return - `number_pts_blw::Cint`: number of points where the error is below the given threshold -... + """ function numPointsBelow(fit::Fitting, threshold::Cdouble)::Cint @assert threshold >= 0 "The threshold must be a positive real number!" @@ -169,13 +169,13 @@ end """ result(fit::Fitting)::Geometry Returns a geometry from the fitting structure -... + # Arguments - `fit::Fitting`: a fitting structure -... + # Return - `geom::Geometry`: the desired geometry -... + """ function result(fit::Fitting)::Geometry geom = ccall((:gsFitting_result,libgismo),Ptr{gsCGeometry},(Ptr{gsCFitting},),fit.ptr) diff --git a/src/gsNurbs.jl b/src/gsNurbs.jl index f251253..6a668be 100644 --- a/src/gsNurbs.jl +++ b/src/gsNurbs.jl @@ -90,11 +90,10 @@ Returns the number of elements in the knot vector. - `kv::KnotVector`: the knot vector # Examples -# ```jldoctest output=(false) -# kv = KnotVector(Float64[0.,0.,0.,0.,0.5,1.,1.,1.,1.]) -# print(Gismo.size(kv)) -# # output -# ``` +```jldoctest output=(false) +kv = KnotVector(Float64[0.,0.,0.,0.,0.5,1.,1.,1.,1.]) +# output +``` """ function size(kv::KnotVector)::Int64 return ccall((:gsKnotVector_size,libgismo),Cint,(Ptr{gsCKnotVector},),kv.ptr) @@ -103,10 +102,38 @@ function Base.size(kv::KnotVector)::Int64 return Gismo.size(kv) end +""" +Size of the unique knots + +# Arguments +- `kv::KnotVector`: the knot vector + +# Examples +```jldoctest +kv = KnotVector(Float64[0.,0.,0.,0.,0.5,0.5,1.,1.,1.,1.]) +print(uSize(kv)) +# output +3 +``` +""" function uSize(kv::KnotVector)::Int64 return ccall((:gsKnotVector_uSize,libgismo),Cint,(Ptr{gsCKnotVector},),kv.ptr) end +""" +Number of elements in the knot vector + +# Arguments +- `kv::KnotVector`: the knot vector + +# Examples +```jldoctest +kv = KnotVector(Float64[0.,0.,0.,0.,0.5,1.,1.,1.,1.]) +print(numElements(kv)) +# output +2 +``` +""" function numElements(kv::KnotVector)::Int64 return ccall((:gsKnotVector_numElements,libgismo),Cint,(Ptr{gsCKnotVector},),kv.ptr) end @@ -194,7 +221,7 @@ function TensorBSplineBasis(kv::Vararg{KnotVector})::Basis return Basis(b) end -function knots(basis::Basis, dir::Cint)::KnotVector +function knots(basis::Basis, dir::Int64)::KnotVector if (domainDim(basis)==1) kv = ccall((:gsBSplineBasis_knots,libgismo),Ptr{gsCKnotVector},(Ptr{gsCBasis},Cint),basis.ptr,dir) else @@ -354,11 +381,39 @@ end # gsNurbsCreator ######################################################################## -function BSplineUnitInterval(deg::Cint)::Geometry +""" +Create a unit interval represented by a B-spline + +# Arguments +- `deg::Int64`: the degree of the B-spline + +# Examples +```jldoctest output=(false) +g = BSplineUnitInterval(2) +# output +``` +""" +function BSplineUnitInterval(deg::Int64)::Geometry g = ccall((:gsNurbsCreator_BSplineUnitInterval,libgismo),Ptr{gsCGeometry},(Cint,),deg) return Geometry(g) end +""" +Create a rectangle represented by a B-spline + +# Arguments +- `low_x::Cdouble`: the lower bound in x +- `low_y::Cdouble`: the lower bound in y +- `upp_x::Cdouble`: the upper bound in x +- `upp_y::Cdouble`: the upper bound in y +- `turndeg::Cdouble`: the turning degree + +# Examples +```jldoctest output=(false) +g = BSplineRectangle(0.0,0.0,1.0,1.0,0.0) +# output +``` +""" function BSplineRectangle(low_x::Cdouble=0.0, low_y::Cdouble=0.0, upp_x::Cdouble=1.0, @@ -368,6 +423,22 @@ function BSplineRectangle(low_x::Cdouble=0.0, return Geometry(g) end +""" +Create a trapezium represented by a B-spline + +# Arguments +- `Lbot::Cdouble`: the length of the bottom side +- `Ltop::Cdouble`: the length of the top side +- `H::Cdouble`: the height +- `d::Cdouble`: the offset of the top-side w.r.t. the bottom side +- `turndeg::Cdouble`: the turning degree + +# Examples +```jldoctest output=(false) +g = BSplineTrapezium(1.0,0.5,1.0,0.0,0.0) +# output +``` +""" function BSplineTrapezium(Lbot::Cdouble=1.0, Ltop::Cdouble=0.5, H::Cdouble=1.0, @@ -377,6 +448,20 @@ function BSplineTrapezium(Lbot::Cdouble=1.0, return Geometry(g) end +""" +Create a square represented by a B-spline + +# Arguments +- `r::Cdouble`: the radius of the square +- `x::Cdouble`: the x-coordinate of the center +- `y::Cdouble`: the y-coordinate of the center + +# Examples +```jldoctest output=(false) +g = BSplineSquare(1.0,0.0,0.0) +# output +``` +""" function BSplineSquare(r::Cdouble=1.0, x::Cdouble=0.0, y::Cdouble=0.0)::Geometry @@ -384,8 +469,24 @@ function BSplineSquare(r::Cdouble=1.0, return Geometry(g) end -function BSplineSquareGrid(n::Cint, - m::Cint, +""" +Create a square grid represented by a multi-patch + +# Arguments +- `n::Int64`: the number of patches in x-direction +- `m::Int64`: the number of patches in y-direction +- `r::Cdouble`: the radius of the square +- `lx::Cdouble`: the x-coordinate of the center +- `ly::Cdouble`: the y-coordinate of the center + +# Examples +```jldoctest output=(false) +g = BSplineSquareGrid(2,2,1.0,0.0,0.0) +# output +``` +""" +function BSplineSquareGrid(n::Int64, + m::Int64, r::Cdouble=1.0, lx::Cdouble=0.0, ly::Cdouble=0.0)::MultiPatch @@ -393,6 +494,21 @@ function BSplineSquareGrid(n::Cint, return MultiPatch(g) end +""" +Create a cube represented by a B-spline + +# Arguments +- `r::Cdouble`: the radius of the cube +- `x::Cdouble`: the x-coordinate of the center +- `y::Cdouble`: the y-coordinate of the center +- `z::Cdouble`: the z-coordinate of the center + +# Examples +```jldoctest output=(false) +g = BSplineCube(1.0,0.0,0.0,0.0) +# output +``` +""" function BSplineCube(r::Cdouble=1.0, x::Cdouble=0.0, y::Cdouble=0.0, @@ -401,9 +517,27 @@ function BSplineCube(r::Cdouble=1.0, return Geometry(g) end -function BSplineCubeGrid(n::Cint, - m::Cint, - p::Cint, +""" +Create a cube grid represented by a multi-patch + +# Arguments +- `n::Int64`: the number of patches in x-direction +- `m::Int64`: the number of patches in y-direction +- `p::Int64`: the number of patches in z-direction +- `r::Cdouble`: the radius of the cube +- `lx::Cdouble`: the x-coordinate of the center +- `ly::Cdouble`: the y-coordinate of the center +- `lz::Cdouble`: the z-coordinate of the center + +# Examples +```jldoctest output=(false) +g = BSplineCubeGrid(2,2,2,1.0,0.0,0.0,0.0) +# output +``` +""" +function BSplineCubeGrid(n::Int64, + m::Int64, + p::Int64, r::Cdouble=1.0, lx::Cdouble=0.0, ly::Cdouble=0.0, @@ -412,23 +546,73 @@ function BSplineCubeGrid(n::Cint, return MultiPatch(g) end +""" +Create a quarter annulus represented by a NURBS + +# Arguments +- `r1::Cdouble`: the inner radius +- `r2::Cdouble`: the outer radius + +# Examples +```jldoctest output=(false) +g = NurbsQuarterAnnulus(1.0,2.0) +# output +``` +""" function NurbsQuarterAnnulus(r1::Cdouble=1.0, r2::Cdouble=2.0)::Geometry g = ccall((:gsNurbsCreator_NurbsQuarterAnnulus,libgismo),Ptr{gsCGeometry},(Cdouble,Cdouble),r1,r2) return Geometry(g) end +""" +Create an annulus represented by a NURBS + +# Arguments +- `r1::Cdouble`: the inner radius +- `r2::Cdouble`: the outer radius + +# Examples +```jldoctest output=(false) +g = NurbsAnnulus(1.0,2.0) +# output +``` +""" function NurbsAnnulus(r1::Cdouble=1.0, r2::Cdouble=2.0)::Geometry g = ccall((:gsNurbsCreator_NurbsAnnulus,libgismo),Ptr{gsCGeometry},(Cdouble,Cdouble),r1,r2) return Geometry(g) end +""" +Create a saddle represented by a B-spline + +# Examples +```jldoctest output=(false) +g = BSplineSaddle() +# output +``` +""" function BSplineSaddle()::Geometry g = ccall((:gsNurbsCreator_BSplineSaddle,libgismo),Ptr{gsCGeometry},(),) return Geometry(g) end +""" +Create a sphere represented by a NURBS + +# Arguments +- `r::Cdouble`: the radius +- `x::Cdouble`: the x-coordinate of the center +- `y::Cdouble`: the y-coordinate of the center +- `z::Cdouble`: the z-coordinate of the center + +# Examples +```jldoctest output=(false) +g = NurbsSphere(1.0,0.0,0.0,0.0) +# output +``` +""" function NurbsSphere(r::Cdouble=1.0, x::Cdouble=0.0, y::Cdouble=0.0, @@ -437,6 +621,20 @@ function NurbsSphere(r::Cdouble=1.0, return Geometry(g) end +""" +Create a circle represented by a NURBS + +# Arguments +- `r::Cdouble`: the radius +- `x::Cdouble`: the x-coordinate of the center +- `y::Cdouble`: the y-coordinate of the center + +# Examples +```jldoctest output=(false) +g = NurbsCircle(1.0,0.0,0.0) +# output +``` +""" function NurbsCircle(r::Cdouble=1.0, x::Cdouble=0.0, y::Cdouble=0.0)::Geometry @@ -444,13 +642,40 @@ function NurbsCircle(r::Cdouble=1.0, return Geometry(g) end +""" +Create a triangle represented by a B-spline + +# Arguments +- `H::Cdouble`: the height +- `W::Cdouble`: the width + +# Examples +```jldoctest output=(false) +g = BSplineTriangle(1.0,1.0) +# output +``` +""" function BSplineTriangle(H::Cdouble=1.0, W::Cdouble=1.0)::Geometry g = ccall((:gsNurbsCreator_BSplineTriangle,libgismo),Ptr{gsCGeometry},(Cdouble,Cdouble),H,W) return Geometry(g) end -function BSplineStar(N::Cint=3, +""" +Create a star represented by a multi-patch + +# Arguments +- `N::Int64`: the number of arms +- `R0::Cdouble`: the outer radius +- `R1::Cdouble`: the inner radius + +# Examples +```jldoctest output=(false) +g = BSplineStar(3,1.0,0.5) +# output +``` +""" +function BSplineStar(N::Int64=3, R0::Cdouble=1.0, R1::Cdouble=0.5)::MultiPatch g = ccall((:gsNurbsCreator_BSplineStar,libgismo),Ptr{gsCMultiPatch},(Cint,Cdouble,Cdouble),N,R0,R1) From 2ac0bcf71855c5536db88d291f19fe6b90fce2d4 Mon Sep 17 00:00:00 2001 From: Alberto Biliotti <76699437+Albe21072000@users.noreply.github.com> Date: Thu, 19 Dec 2024 12:27:01 +0100 Subject: [PATCH 10/16] Update Gismo.jl You forgot to remove your local path --- src/Gismo.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Gismo.jl b/src/Gismo.jl index 3f86c24..94c79cc 100644 --- a/src/Gismo.jl +++ b/src/Gismo.jl @@ -1,6 +1,6 @@ module Gismo -libgismo = "/home/hverhelst/Documents/code/gismo_mex/build/lib/libgismo" +import gismo_jll:libgismo # Forward declaration of structs include("Declarations.jl") From 43123ef8c0ceca3db2835411d282b503b9a6b7be Mon Sep 17 00:00:00 2001 From: Hugo Verhelst Date: Thu, 19 Dec 2024 12:29:07 +0100 Subject: [PATCH 11/16] undo path --- src/Gismo.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Gismo.jl b/src/Gismo.jl index 3f86c24..94c79cc 100644 --- a/src/Gismo.jl +++ b/src/Gismo.jl @@ -1,6 +1,6 @@ module Gismo -libgismo = "/home/hverhelst/Documents/code/gismo_mex/build/lib/libgismo" +import gismo_jll:libgismo # Forward declaration of structs include("Declarations.jl") From ca27ecc7df365d0ad2dd22ab9e9755e9d1eb6b08 Mon Sep 17 00:00:00 2001 From: Hugo Verhelst Date: Thu, 19 Dec 2024 12:39:32 +0100 Subject: [PATCH 12/16] Change int types --- examples/OptionList_example.jl | 2 +- src/gsIO.jl | 12 +++++------ src/gsMatrix.jl | 24 ++++++++++----------- src/gsModeling.jl | 12 +++++------ src/gsNurbs.jl | 38 +++++++++++++++++----------------- 5 files changed, 44 insertions(+), 44 deletions(-) diff --git a/examples/OptionList_example.jl b/examples/OptionList_example.jl index 89663d6..af7bb64 100644 --- a/examples/OptionList_example.jl +++ b/examples/OptionList_example.jl @@ -11,7 +11,7 @@ Gismo.setSwitch(gsOptionList,"c",false) Gismo.setString(gsOptionList,"d","two") println(gsOptionList) -int::Int64 = Gismo.getInt(gsOptionList,"a") +int::Int = Gismo.getInt(gsOptionList,"a") println("Integer read from option list: ",int) double::Float64 = Gismo.getReal(gsOptionList,"b") println("Double read from option list: ",double) diff --git a/src/gsIO.jl b/src/gsIO.jl index ac0bf96..0e8cabf 100644 --- a/src/gsIO.jl +++ b/src/gsIO.jl @@ -115,7 +115,7 @@ Add an integer to the option list # Arguments - `opt::OptionList`: the option list - `key::String`: the key -- `int::Int64`: the value +- `int::Int`: the value - `desc::String`: the description # Examples @@ -125,7 +125,7 @@ addInt(opt,"key",1,"description") # output ``` """ -function addInt(opt::OptionList,key::String,int::Int64,desc::String="") +function addInt(opt::OptionList,key::String,int::Int,desc::String="") ccall((:gsOptionList_addInt,libgismo),Cvoid,(Ptr{gsCOptionList},Cstring,Cstring,Cint),opt.ptr,key,desc,int) end @@ -200,7 +200,7 @@ Get an integer from the option list - `key::String`: the key # Return -- `int::Cint`: the value +- `int::Int`: the value # Examples ```jldoctest @@ -209,7 +209,7 @@ println(getInt(opt,"key1")) # output 1 """ -function getInt(opt::OptionList,key::String)::Cint +function getInt(opt::OptionList,key::String)::Int return ccall((:gsOptionList_getInt,libgismo),Cint,(Ptr{gsCOptionList},Cstring),opt.ptr,key) end @@ -286,7 +286,7 @@ Set an integer to the option list # Arguments - `opt::OptionList`: the option list - `key::String`: the key -- `int::Cint`: the value +- `int::Int`: the value # Εxamples ```jldoctest output=(false) @@ -295,7 +295,7 @@ setInt(opt,"key",2) # output ``` """ -function setInt(opt::OptionList,key::String,int::Int64) +function setInt(opt::OptionList,key::String,int::Int) ccall((:gsOptionList_setInt,libgismo),Cvoid,(Ptr{gsCOptionList},Cstring,Cint),opt.ptr,key,int) end diff --git a/src/gsMatrix.jl b/src/gsMatrix.jl index 6f5b034..4d92817 100644 --- a/src/gsMatrix.jl +++ b/src/gsMatrix.jl @@ -42,14 +42,14 @@ mutable struct EigenMatrix return m end - function EigenMatrix(r::Int64,c::Int64) + function EigenMatrix(r::Int,c::Int) m = new(ccall((:gsMatrix_create_rc,libgismo),Ptr{gsCMatrix}, (Cint,Cint), r, c) ) finalizer(destroy!, m) return m end - function EigenMatrix(r::Int64,c::Int64, data::Ptr{Cdouble}) + function EigenMatrix(r::Int,c::Int, data::Ptr{Cdouble}) m = new(ccall((:gsMatrix_create_rcd,libgismo),Ptr{gsCMatrix}, (Cint,Cint,Ptr{Cdouble},), r, c, data) ) finalizer(destroy!, m) @@ -75,7 +75,7 @@ print(Gismo.rows(m)) 3 ``` """ -function rows(object::EigenMatrix)::Int64 +function rows(object::EigenMatrix)::Int return ccall((:gsMatrix_rows,libgismo),Cint,(Ptr{gsCMatrix},),object.ptr) end @@ -93,7 +93,7 @@ print(Gismo.cols(m)) 3 ``` """ -function cols(object::EigenMatrix)::Int64 +function cols(object::EigenMatrix)::Int return ccall((:gsMatrix_cols,libgismo),Cint,(Ptr{gsCMatrix},),object.ptr) end @@ -187,10 +187,10 @@ mutable struct EigenMatrixInt Creates an empty matrix # Arguments - - `r::Int64`: the number of rows - - `c::Int64`: the number of columns + - `r::Int`: the number of rows + - `c::Int`: the number of columns """ - function EigenMatrixInt(r::Int64,c::Int64) + function EigenMatrixInt(r::Int,c::Int) m = new(ccall((:gsMatrixInt_create_rc,libgismo),Ptr{gsCMatrixInt}, (Cint,Cint), r, c) ) finalizer(destroy!, m) @@ -201,11 +201,11 @@ mutable struct EigenMatrixInt Creates a matrix from a pointer to the data # Arguments - - `r::Int64`: the number of rows - - `c::Int64`: the number of columns + - `r::Int`: the number of rows + - `c::Int`: the number of columns - `data::Ptr{Cint}`: the pointer to the data """ - function EigenMatrixInt(r::Int64,c::Int64, data::Ptr{Cint}) + function EigenMatrixInt(r::Int,c::Int, data::Ptr{Cint}) m = new(ccall((:gsMatrixInt_create_rcd,libgismo),Ptr{gsCMatrixInt}, (Cint,Cint,Ptr{Cint},), r, c, data) ) finalizer(destroy!, m) @@ -231,7 +231,7 @@ print(Gismo.rows(m)) 3 ``` """ -function rows(object::EigenMatrixInt)::Int64 +function rows(object::EigenMatrixInt)::Int return ccall((:gsMatrixInt_rows,libgismo),Cint,(Ptr{gsCMatrixInt},),object.ptr) end @@ -249,7 +249,7 @@ print(Gismo.cols(m)) 3 ``` """ -function cols(object::EigenMatrixInt)::Int64 +function cols(object::EigenMatrixInt)::Int return ccall((:gsMatrixInt_cols,libgismo),Cint,(Ptr{gsCMatrixInt},),object.ptr) end diff --git a/src/gsModeling.jl b/src/gsModeling.jl index 4100a39..53dcc03 100644 --- a/src/gsModeling.jl +++ b/src/gsModeling.jl @@ -74,17 +74,17 @@ function compute!(fit::Fitting, lambda::Cdouble=0.0) end """ -parameterCorrection!(fit::Fitting, accuracy::Cdouble, maxIter::Cint, tol0rth::Cdouble) +parameterCorrection!(fit::Fitting, accuracy::Cdouble, maxIter::Int, tol0rth::Cdouble) Performs the parameters corrections step # Arguments - `fit::Fitting`: a fitting structure - `accuracy::Cdouble`: The desired accuracy -- `maxIter::Cint`: The desired number of iterations +- `maxIter::Int`: The desired number of iterations - `tol0rth::Cdouble`: The desired value of the tolleance """ -function parameterCorrection!(fit::Fitting, accuracy::Cdouble=1.0, maxIter::Cint=Cint(10), tol0rth::Cdouble=1e-6) +function parameterCorrection!(fit::Fitting, accuracy::Cdouble=1.0, maxIter::Int=Int(10), tol0rth::Cdouble=1e-6) @assert maxIter >= 0 "Fitting: cannot have a negative number of iterations!" @assert accuracy >= 0 "Fitting: cannot have a negative accuracy!" ccall((:gsFitting_parameterCorrection,libgismo),Cvoid,(Ptr{gsCFitting},Cdouble,Cint,Cdouble),fit.ptr,accuracy,maxIter,tol0rth) @@ -149,7 +149,7 @@ function pointWiseErrors(fit::Fitting)::Ptr{Cdouble} end """ -numPointsBelow(fit::Fitting, threshold::Cdouble)::Cint +numPointsBelow(fit::Fitting, threshold::Cdouble)::Int Returns the number of points where the error is below the threshold # Arguments @@ -157,10 +157,10 @@ Returns the number of points where the error is below the threshold - `threshold::Cdouble`: The desired threshold # Return -- `number_pts_blw::Cint`: number of points where the error is below the given threshold +- `number_pts_blw::Int`: number of points where the error is below the given threshold """ -function numPointsBelow(fit::Fitting, threshold::Cdouble)::Cint +function numPointsBelow(fit::Fitting, threshold::Cdouble)::Int @assert threshold >= 0 "The threshold must be a positive real number!" number_pts_blw=ccall((:gsFitting_numPointsBelow,libgismo),Cint,(Ptr{gsCFitting},Cdouble),fit.ptr,threshold) return number_pts_blw diff --git a/src/gsNurbs.jl b/src/gsNurbs.jl index 6a668be..076bfef 100644 --- a/src/gsNurbs.jl +++ b/src/gsNurbs.jl @@ -95,10 +95,10 @@ kv = KnotVector(Float64[0.,0.,0.,0.,0.5,1.,1.,1.,1.]) # output ``` """ -function size(kv::KnotVector)::Int64 +function size(kv::KnotVector)::Int return ccall((:gsKnotVector_size,libgismo),Cint,(Ptr{gsCKnotVector},),kv.ptr) end -function Base.size(kv::KnotVector)::Int64 +function Base.size(kv::KnotVector)::Int return Gismo.size(kv) end @@ -116,7 +116,7 @@ print(uSize(kv)) 3 ``` """ -function uSize(kv::KnotVector)::Int64 +function uSize(kv::KnotVector)::Int return ccall((:gsKnotVector_uSize,libgismo),Cint,(Ptr{gsCKnotVector},),kv.ptr) end @@ -134,7 +134,7 @@ print(numElements(kv)) 2 ``` """ -function numElements(kv::KnotVector)::Int64 +function numElements(kv::KnotVector)::Int return ccall((:gsKnotVector_numElements,libgismo),Cint,(Ptr{gsCKnotVector},),kv.ptr) end @@ -221,7 +221,7 @@ function TensorBSplineBasis(kv::Vararg{KnotVector})::Basis return Basis(b) end -function knots(basis::Basis, dir::Int64)::KnotVector +function knots(basis::Basis, dir::Int)::KnotVector if (domainDim(basis)==1) kv = ccall((:gsBSplineBasis_knots,libgismo),Ptr{gsCKnotVector},(Ptr{gsCBasis},Cint),basis.ptr,dir) else @@ -385,7 +385,7 @@ end Create a unit interval represented by a B-spline # Arguments -- `deg::Int64`: the degree of the B-spline +- `deg::Int`: the degree of the B-spline # Examples ```jldoctest output=(false) @@ -393,7 +393,7 @@ g = BSplineUnitInterval(2) # output ``` """ -function BSplineUnitInterval(deg::Int64)::Geometry +function BSplineUnitInterval(deg::Int)::Geometry g = ccall((:gsNurbsCreator_BSplineUnitInterval,libgismo),Ptr{gsCGeometry},(Cint,),deg) return Geometry(g) end @@ -473,8 +473,8 @@ end Create a square grid represented by a multi-patch # Arguments -- `n::Int64`: the number of patches in x-direction -- `m::Int64`: the number of patches in y-direction +- `n::Int`: the number of patches in x-direction +- `m::Int`: the number of patches in y-direction - `r::Cdouble`: the radius of the square - `lx::Cdouble`: the x-coordinate of the center - `ly::Cdouble`: the y-coordinate of the center @@ -485,8 +485,8 @@ g = BSplineSquareGrid(2,2,1.0,0.0,0.0) # output ``` """ -function BSplineSquareGrid(n::Int64, - m::Int64, +function BSplineSquareGrid(n::Int, + m::Int, r::Cdouble=1.0, lx::Cdouble=0.0, ly::Cdouble=0.0)::MultiPatch @@ -521,9 +521,9 @@ end Create a cube grid represented by a multi-patch # Arguments -- `n::Int64`: the number of patches in x-direction -- `m::Int64`: the number of patches in y-direction -- `p::Int64`: the number of patches in z-direction +- `n::Int`: the number of patches in x-direction +- `m::Int`: the number of patches in y-direction +- `p::Int`: the number of patches in z-direction - `r::Cdouble`: the radius of the cube - `lx::Cdouble`: the x-coordinate of the center - `ly::Cdouble`: the y-coordinate of the center @@ -535,9 +535,9 @@ g = BSplineCubeGrid(2,2,2,1.0,0.0,0.0,0.0) # output ``` """ -function BSplineCubeGrid(n::Int64, - m::Int64, - p::Int64, +function BSplineCubeGrid(n::Int, + m::Int, + p::Int, r::Cdouble=1.0, lx::Cdouble=0.0, ly::Cdouble=0.0, @@ -665,7 +665,7 @@ end Create a star represented by a multi-patch # Arguments -- `N::Int64`: the number of arms +- `N::Int`: the number of arms - `R0::Cdouble`: the outer radius - `R1::Cdouble`: the inner radius @@ -675,7 +675,7 @@ g = BSplineStar(3,1.0,0.5) # output ``` """ -function BSplineStar(N::Int64=3, +function BSplineStar(N::Int=3, R0::Cdouble=1.0, R1::Cdouble=0.5)::MultiPatch g = ccall((:gsNurbsCreator_BSplineStar,libgismo),Ptr{gsCMultiPatch},(Cint,Cdouble,Cdouble),N,R0,R1) From 58310855d8028b76ddd85a2519c86c3f76e6237b Mon Sep 17 00:00:00 2001 From: Hugo Verhelst Date: Thu, 19 Dec 2024 12:45:33 +0100 Subject: [PATCH 13/16] Change int types --- examples/OptionList_example.jl | 2 +- examples/QuadRule_example.jl | 4 +-- examples/THBSpline_example.jl | 2 +- src/gsAssembler.jl | 36 +++++++++++------------ src/gsCore.jl | 52 +++++++++++++++++----------------- src/gsMatrix.jl | 10 +++---- test/runtests.jl | 2 +- 7 files changed, 54 insertions(+), 54 deletions(-) diff --git a/examples/OptionList_example.jl b/examples/OptionList_example.jl index af7bb64..c538eed 100644 --- a/examples/OptionList_example.jl +++ b/examples/OptionList_example.jl @@ -5,7 +5,7 @@ println(options) gsOptionList = OptionList(options) println(gsOptionList) -Gismo.setInt(gsOptionList,"a",Int32(2)) +Gismo.setInt(gsOptionList,"a",2) Gismo.setReal(gsOptionList,"b",2.0) Gismo.setSwitch(gsOptionList,"c",false) Gismo.setString(gsOptionList,"d","two") diff --git a/examples/QuadRule_example.jl b/examples/QuadRule_example.jl index e84207b..b40cbe7 100644 --- a/examples/QuadRule_example.jl +++ b/examples/QuadRule_example.jl @@ -1,13 +1,13 @@ using Gismo # Gauss quadrature rule (1D) -rule1D = GaussRule(Int32(2)) +rule1D = GaussRule(2) nodes,weights = mapTo(rule1D,0.0,1.0) println("Gauss nodes: ",asMatrix(nodes)) println("Gauss nodes: ",asVector(weights)) # Lobatto quadrature rule (2D) -rule2D = LobattoRule(Int32(2),Array{Int32}([2,2])) +rule2D = LobattoRule(2,Array{Int}([2,2])) low = Vector{Float64}([0.0,0.0]) upp = Vector{Float64}([1.0,1.0]) nodes,weights = mapTo(rule2D,low,upp) diff --git a/examples/THBSpline_example.jl b/examples/THBSpline_example.jl index eee3b44..6175cfd 100644 --- a/examples/THBSpline_example.jl +++ b/examples/THBSpline_example.jl @@ -8,7 +8,7 @@ print("The size of the basis is: ",size(TBB),"\n") uniformRefine!(TBB) print("The size of the basis is: ",size(TBB),"\n") THB = THBSplineBasis(TBB) -boxes = Vector{Int32}([1,0,0,2,2]) +boxes = Vector{Int}([1,0,0,2,2]) refineElements!(THB,boxes) print("The size of the basis is: ",size(THB),"\n") diff --git a/src/gsAssembler.jl b/src/gsAssembler.jl index 1df78ef..590543c 100644 --- a/src/gsAssembler.jl +++ b/src/gsAssembler.jl @@ -45,12 +45,12 @@ Base.show(io::IO, obj::QuadRule) = ccall((:gsQuadRule_print,libgismo),Cvoid,(Ptr Returns a Gauss rule for numerical integration # Arguments -- `d::Cint`: the dimension of the rule -- `numNodes::Array{Cint}`: a vector of length `d` with the number of points in each direction -- `digits::Cint`: the number of digits of precision for the rule (optionals) +- `d::Int`: the dimension of the rule +- `numNodes::Array{Int}`: a vector of length `d` with the number of points in each direction +- `digits::Int`: the number of digits of precision for the rule (optionals) """ -function GaussRule(d::Cint, numNodes::Array{Cint}, digits::Cint=Cint(0))::QuadRule +function GaussRule(d::Int, numNodes::Array{Int}, digits::Int=Int(0))::QuadRule @assert d == length(numNodes) "GaussRule: numNodes must have the same size as the dimension" qr = ccall((:gsGaussRule_create,libgismo),Ptr{gsCQuadRule},(Cint,Ptr{Cint},Cint),d,numNodes,digits) return QuadRule(qr) @@ -60,13 +60,13 @@ end Returns a Gauss rule for numerical integration # Arguments -- `numNodes::Cint`: the number of points in each direction -- `digits::Cint`: the number of digits of precision for the rule (optionals) +- `numNodes::Int`: the number of points in each direction +- `digits::Int`: the number of digits of precision for the rule (optionals) """ -function GaussRule(numNodes::Cint, digits::Cint=Cint(0))::QuadRule - d::Cint = 1; - numNodesVec::Array{Cint} = [numNodes] +function GaussRule(numNodes::Int, digits::Int=Int(0))::QuadRule + d::Int = 1; + numNodesVec::Array{Int} = [numNodes] qr = ccall((:gsGaussRule_create,libgismo),Ptr{gsCQuadRule},(Cint,Ptr{Cint},Cint),d,numNodesVec,digits) return QuadRule(qr) end @@ -75,12 +75,12 @@ end Returns a Lobatto rule for numerical integration # Arguments -- `d::Cint`: the dimension of the rule -- `numNodes::Array{Cint}`: a vector of length `d` with the number of points in each direction -- `digits::Cint`: the number of digits of precision for the rule (optionals) +- `d::Int`: the dimension of the rule +- `numNodes::Array{Int}`: a vector of length `d` with the number of points in each direction +- `digits::Int`: the number of digits of precision for the rule (optionals) """ -function LobattoRule(d::Cint, numNodes::Array{Cint}, digits::Cint=Cint(0))::QuadRule +function LobattoRule(d::Int, numNodes::Array{Int}, digits::Int=Int(0))::QuadRule @assert d == length(numNodes) "LobattoRule: numNodes must have the same size as the dimension" qr = ccall((:gsLobattoRule_create,libgismo),Ptr{gsCQuadRule},(Cint,Ptr{Cint},Cint),d,numNodes,digits) return QuadRule(qr) @@ -90,13 +90,13 @@ end Returns a Lobatto rule for numerical integration # Arguments -- `numNodes::Cint`: the number of points in each direction -- `digits::Cint`: the number of digits of precision for the rule (optionals) +- `numNodes::Int`: the number of points in each direction +- `digits::Int`: the number of digits of precision for the rule (optionals) """ -function LobattoRule(numNodes::Cint, digits::Cint=Cint(0))::QuadRule - d::Cint = 1; - numNodesVec::Array{Cint} = [numNodes] +function LobattoRule(numNodes::Int, digits::Int=Int(0))::QuadRule + d::Int = 1; + numNodesVec::Array{Int} = [numNodes] qr = ccall((:LobattoRule_create,libgismo),Ptr{gsCQuadRule},(Cint,Ptr{Cint},Cint),d,numNodesVec,digits) return QuadRule(qr) end diff --git a/src/gsCore.jl b/src/gsCore.jl index ebe8e82..86d12ac 100644 --- a/src/gsCore.jl +++ b/src/gsCore.jl @@ -87,7 +87,7 @@ Returns the domain dimension of a basis - `object::Basis`: a Gismo Basis """ -function domainDim(object::Basis)::Cint +function domainDim(object::Basis)::Int return ccall((:gsFunctionSet_domainDim,libgismo),Cint,(Ptr{gsCFunctionSet},),object.ptr) end @@ -98,7 +98,7 @@ Returns the target dimension of a basis - `object::Basis`: a Gismo Basis """ -function targetDim(object::Basis)::Cint +function targetDim(object::Basis)::Int return ccall((:gsFunctionSet_targetDim,libgismo),Cint,(Ptr{gsCFunctionSet},),object.ptr) end @@ -109,10 +109,10 @@ Returns the component of a basis # Arguments - `obj::Basis`: a Gismo Basis -- `i::Cint`: the index of the component +- `i::Int`: the index of the component """ -function component(obj::Basis,i::Cint)::Basis +function component(obj::Basis,i::Int)::Basis b = ccall((:gsBasis_component,libgismo),Ptr{gsCBasis},(Ptr{gsCBasis},Cint),obj.ptr,i) return Basis(b) end @@ -122,10 +122,10 @@ Returns the degree of a basis # Arguments - `obj::Basis`: a Gismo Basis -- `i::Cint`: the index of the component +- `i::Int`: the index of the component """ -function degree(obj::Basis,i::Cint)::Cint +function degree(obj::Basis,i::Int)::Int return ccall((:gsBasis_degree,libgismo),Cint,(Ptr{gsCBasis},Cint),obj.ptr,i) end @@ -136,7 +136,7 @@ Returns the number of elements of a basis - `obj::Basis`: a Gismo Basis """ -function numElements(obj::Basis)::Cint +function numElements(obj::Basis)::Int return ccall((:gsBasis_numElements,libgismo),Cint,(Ptr{gsCBasis},),obj.ptr) end @@ -147,10 +147,10 @@ Returns the size of a basis - `obj::Basis`: a Gismo Basis """ -function size(obj::Basis)::Cint +function size(obj::Basis)::Int return ccall((:gsBasis_size,libgismo),Cint,(Ptr{gsCBasis},),obj.ptr) end -function Base.size(obj::Basis)::Cint +function Base.size(obj::Basis)::Int return Gismo.size(obj) end @@ -159,12 +159,12 @@ Refines a basis # Arguments - `obj::Basis`: a Gismo Basis -- `numKnots::Cint=Int32(1)`: the number of knots to add -- `mul::Cint=Int32(1)`: the multiplicity of the knots -- `dir::Cint=Int32(-1)`: the direction of the refinement +- `numKnots::Int=Int(1)`: the number of knots to add +- `mul::Int=Int(1)`: the multiplicity of the knots +- `dir::Int=Int(-1)`: the direction of the refinement """ -function uniformRefine!(obj::Basis,numKnots::Cint=Int32(1),mul::Cint=Int32(1),dir::Cint=Int32(-1))::Nothing +function uniformRefine!(obj::Basis,numKnots::Int=Int(1),mul::Int=Int(1),dir::Int=Int(-1))::Nothing ccall((:gsBasis_uniformRefine,libgismo),Cvoid, (Ptr{gsCBasis},Cint,Cint,Cint),obj.ptr,numKnots,mul,dir) end @@ -177,7 +177,7 @@ Refines a basis - `boxes::Vector{Cint}`: the boxes to refine (in index format) """ -function refineElements!(obj::Basis,boxes::Vector{Cint})::Nothing +function refineElements!(obj::Basis,boxes::Vector{Int})::Nothing @assert mod(length(boxes),2*domainDim(obj)+1)==0 "Boxes should have size 2*domainDim+1" ccall((:gsBasis_refineElements,libgismo),Cvoid, (Ptr{gsCBasis},Ptr{Cint},Cint), @@ -190,10 +190,10 @@ Refines a basis # Arguments - `obj::Basis`: a Gismo Basis - `boxes::Matrix{Cdouble}`: the boxes to refine (first column is the lower bound, second column is the upper bound) -- `refExt::Cint=Int32(0)`: the refinement extension +- `refExt::Int=Int(0)`: the refinement extension """ -function refine!(obj::Basis,boxes::Matrix{Cdouble},refExt::Cint=Int32(0))::Nothing +function refine!(obj::Basis,boxes::Matrix{Cdouble},refExt::Int=Int(0))::Nothing @assert Base.size(boxes,1)==domainDim(obj) "The boxes should have the same number of rows as the domain dimension" @assert Base.size(boxes,2)==2 "The boxes should have two columns" bb = EigenMatrix(Base.size(boxes,1), Base.size(boxes,2), pointer(boxes) ) @@ -280,11 +280,11 @@ Returns the evaluation of a single basis function # Arguments - `obj::Basis`: a Gismo Basis -- `i::Cint`: the index of the basis function +- `i::Int`: the index of the basis function - `u::Matrix{Cdouble}`: a matrix of points """ -function evalSingle(obj::Basis,i::Cint,u::Matrix{Cdouble})::EigenMatrix +function evalSingle(obj::Basis,i::Int,u::Matrix{Cdouble})::EigenMatrix @assert Base.size(u,1)==domainDim(obj) "Domain dimension should be equal to the number of rows of the points" uu = EigenMatrix(Base.size(u,1), Base.size(u,2), pointer(u) ) result = EigenMatrix() @@ -299,11 +299,11 @@ Returns the derivative of a single basis function # Arguments - `obj::Basis`: a Gismo Basis -- `i::Cint`: the index of the basis function +- `i::Int`: the index of the basis function - `u::Matrix{Cdouble}`: a matrix of points """ -function derivSingle(obj::Basis,i::Cint,u::Matrix{Cdouble})::EigenMatrix +function derivSingle(obj::Basis,i::Int,u::Matrix{Cdouble})::EigenMatrix @assert Base.size(u,1)==domainDim(obj) "Domain dimension should be equal to the number of rows of the points" uu = EigenMatrix(Base.size(u,1), Base.size(u,2), pointer(u) ) result = EigenMatrix() @@ -318,11 +318,11 @@ Returns the second derivative of a single basis function # Arguments - `obj::Basis`: a Gismo Basis -- `i::Cint`: the index of the basis function +- `i::Int`: the index of the basis function - `u::Matrix{Cdouble}`: a matrix of points """ -function deriv2Single(obj::Basis,i::Cint,u::Matrix{Cdouble})::EigenMatrix +function deriv2Single(obj::Basis,i::Int,u::Matrix{Cdouble})::EigenMatrix @assert Base.size(u,1)==domainDim(obj) "Domain dimension should be equal to the number of rows of the points" uu = EigenMatrix(Base.size(u,1), Base.size(u,2), pointer(u) ) result = EigenMatrix() @@ -379,7 +379,7 @@ Return the domain dimension of a geometry - `object::Geometry`: a Gismo Geometry """ -function domainDim(object::Geometry)::Cint +function domainDim(object::Geometry)::Int return ccall((:gsFunctionSet_domainDim,libgismo),Cint,(Ptr{gsCFunctionSet},),object.ptr) end @@ -390,7 +390,7 @@ Returns the target dimension of a geometry - `object::Geometry`: a Gismo Geometry """ -function targetDim(object::Geometry)::Cint +function targetDim(object::Geometry)::Int return ccall((:gsFunctionSet_targetDim,libgismo),Cint,(Ptr{gsCFunctionSet},),object.ptr) end @@ -572,7 +572,7 @@ Adds a patch to a MultiPatch - `geom::Geometry`: a Gismo Geometry """ -function domainDim(object::MultiPatch)::Cint +function domainDim(object::MultiPatch)::Int return ccall((:gsFunctionSet_domainDim,libgismo),Cint,(Ptr{gsCFunctionSet},),object.ptr) end @@ -583,7 +583,7 @@ Returns the target dimension of a MultiPatch - `object::MultiPatch`: a Gismo MultiPatch """ -function targetDim(object::MultiPatch)::Cint +function targetDim(object::MultiPatch)::Int return ccall((:gsFunctionSet_targetDim,libgismo),Cint,(Ptr{gsCFunctionSet},),object.ptr) end diff --git a/src/gsMatrix.jl b/src/gsMatrix.jl index 4d92817..b2a901c 100644 --- a/src/gsMatrix.jl +++ b/src/gsMatrix.jl @@ -260,7 +260,7 @@ Returns a pointer to the data of the matrix. - `object::EigenMatrixInt`: the matrix """ -function data(object::EigenMatrixInt)::Ptr{Cint} +function data(object::EigenMatrixInt)::Ptr{Int} return ccall((:gsMatrixInt_data,libgismo),Ptr{Cint},(Ptr{gsCMatrixInt},),object.ptr) end @@ -271,7 +271,7 @@ Returns the matrix as a Julia matrix (transfers ownership). - `object::EigenMatrixInt`: the matrix """ -function toMatrixInt(object::EigenMatrixInt)::MatrixInt{Cint} +function toMatrixInt(object::EigenMatrixInt)::MatrixInt{Int} return unsafe_wrap(Array, data(object), (rows(object),cols(object)); own = true) end @@ -282,7 +282,7 @@ Returns the matrix as a Julia vector (transfers ownership). - `object::EigenMatrixInt`: the matrix """ -function toVectorInt(object::EigenMatrixInt)::Vector{Cint} +function toVectorInt(object::EigenMatrixInt)::Vector{Int} return unsafe_wrap(Array, data(object), (rows(object)); own = true) end @@ -293,7 +293,7 @@ Returns the matrix as a Julia matrix. - `object::EigenMatrixInt`: the matrix """ -function asMatrixInt(object::EigenMatrixInt)::MatrixInt{Cint} +function asMatrixInt(object::EigenMatrixInt)::MatrixInt{Int} return unsafe_wrap(Array, data(object), (rows(object),cols(object)); own = false) end @@ -304,7 +304,7 @@ Returns the matrix as a Julia vector. - `object::EigenMatrixInt`: the matrix """ -function asVectorInt(object::EigenMatrixInt)::Vector{Cint} +function asVectorInt(object::EigenMatrixInt)::Vector{Int} return unsafe_wrap(Array, data(object), (rows(object)); own = false) end diff --git a/test/runtests.jl b/test/runtests.jl index 2422d81..c3cbb3e 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -34,7 +34,7 @@ import Gismo.size @test_nowarn(uniformRefine!(THB)) boxes = Matrix{Cdouble}([0.0 0.5; 0.0 0.5]) @test_nowarn(refine!(THB,boxes)) - boxes = Vector{Int32}([1,0,0,2,2]) + boxes = Vector{Int}([1,0,0,2,2]) @test_nowarn(refineElements!(THB,boxes)) end From 5ac4b454f606780cfee14d53c45989323293ce28 Mon Sep 17 00:00:00 2001 From: Hugo Verhelst Date: Thu, 19 Dec 2024 13:30:12 +0100 Subject: [PATCH 14/16] add HB spline and basis add THB spline add warning to getString --- cmake/Gismo.jl.in | 6 +-- src/Gismo.jl | 6 +-- src/gsHSplines.jl | 113 ++++++++++++++++++++++++++++++++++++++++++---- src/gsIO.jl | 11 ++--- 4 files changed, 115 insertions(+), 21 deletions(-) diff --git a/cmake/Gismo.jl.in b/cmake/Gismo.jl.in index 7e67846..e21f9eb 100644 --- a/cmake/Gismo.jl.in +++ b/cmake/Gismo.jl.in @@ -8,6 +8,9 @@ include("Declarations.jl") # Load gsCore include("gsCore.jl") +# Load gsMatrix +include("gsMatrix.jl") + # Load gsAssembler include("gsAssembler.jl") @@ -17,9 +20,6 @@ include("gsHSplines.jl") # Load gsIO include("gsIO.jl") -# Load gsMatrix -include("gsMatrix.jl") - # Load gsMatrix include("gsModeling.jl") diff --git a/src/Gismo.jl b/src/Gismo.jl index 94c79cc..57a5dff 100644 --- a/src/Gismo.jl +++ b/src/Gismo.jl @@ -8,6 +8,9 @@ include("Declarations.jl") # Load gsCore include("gsCore.jl") +# Load gsMatrix +include("gsMatrix.jl") + # Load gsAssembler include("gsAssembler.jl") @@ -17,9 +20,6 @@ include("gsHSplines.jl") # Load gsIO include("gsIO.jl") -# Load gsMatrix -include("gsMatrix.jl") - # Load gsMatrix include("gsModeling.jl") diff --git a/src/gsHSplines.jl b/src/gsHSplines.jl index 070e64b..ab224b8 100644 --- a/src/gsHSplines.jl +++ b/src/gsHSplines.jl @@ -1,5 +1,8 @@ export -THBSplineBasis + THBSplineBasis, + HBSplineBasis, + THBSpline, + HBSpline ######################################################################## # gsTHBSplineBasis ######################################################################## @@ -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 @@ -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 \ No newline at end of file diff --git a/src/gsIO.jl b/src/gsIO.jl index 0e8cabf..d5a275b 100644 --- a/src/gsIO.jl +++ b/src/gsIO.jl @@ -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) @@ -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) @@ -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) From 8b54584422b3c438b50767cf373db632e5faf1f1 Mon Sep 17 00:00:00 2001 From: Hugo Verhelst Date: Thu, 19 Dec 2024 18:08:09 +0100 Subject: [PATCH 15/16] fix quadrature example --- examples/QuadRule_example.jl | 4 ++-- src/gsAssembler.jl | 14 ++++++-------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/examples/QuadRule_example.jl b/examples/QuadRule_example.jl index b40cbe7..119eca4 100644 --- a/examples/QuadRule_example.jl +++ b/examples/QuadRule_example.jl @@ -1,13 +1,13 @@ using Gismo # Gauss quadrature rule (1D) -rule1D = GaussRule(2) +rule1D = GaussRule(Cint(2)) nodes,weights = mapTo(rule1D,0.0,1.0) println("Gauss nodes: ",asMatrix(nodes)) println("Gauss nodes: ",asVector(weights)) # Lobatto quadrature rule (2D) -rule2D = LobattoRule(2,Array{Int}([2,2])) +rule2D = LobattoRule(Cint(2),Array{Cint}([3,3])) low = Vector{Float64}([0.0,0.0]) upp = Vector{Float64}([1.0,1.0]) nodes,weights = mapTo(rule2D,low,upp) diff --git a/src/gsAssembler.jl b/src/gsAssembler.jl index 590543c..a37b597 100644 --- a/src/gsAssembler.jl +++ b/src/gsAssembler.jl @@ -39,8 +39,6 @@ mutable struct QuadRule end end -Base.show(io::IO, obj::QuadRule) = ccall((:gsQuadRule_print,libgismo),Cvoid,(Ptr{gsCQuadRule},),obj.ptr) - """ Returns a Gauss rule for numerical integration @@ -50,7 +48,7 @@ Returns a Gauss rule for numerical integration - `digits::Int`: the number of digits of precision for the rule (optionals) """ -function GaussRule(d::Int, numNodes::Array{Int}, digits::Int=Int(0))::QuadRule +function GaussRule(d::Cint, numNodes::Array{Cint}, digits::Cint=Cint(0))::QuadRule @assert d == length(numNodes) "GaussRule: numNodes must have the same size as the dimension" qr = ccall((:gsGaussRule_create,libgismo),Ptr{gsCQuadRule},(Cint,Ptr{Cint},Cint),d,numNodes,digits) return QuadRule(qr) @@ -64,9 +62,9 @@ Returns a Gauss rule for numerical integration - `digits::Int`: the number of digits of precision for the rule (optionals) """ -function GaussRule(numNodes::Int, digits::Int=Int(0))::QuadRule - d::Int = 1; - numNodesVec::Array{Int} = [numNodes] +function GaussRule(numNodes::Cint, digits::Cint=Cint(0))::QuadRule + d::Cint = 1; + numNodesVec::Array{Cint} = [numNodes] qr = ccall((:gsGaussRule_create,libgismo),Ptr{gsCQuadRule},(Cint,Ptr{Cint},Cint),d,numNodesVec,digits) return QuadRule(qr) end @@ -80,7 +78,7 @@ Returns a Lobatto rule for numerical integration - `digits::Int`: the number of digits of precision for the rule (optionals) """ -function LobattoRule(d::Int, numNodes::Array{Int}, digits::Int=Int(0))::QuadRule +function LobattoRule(d::Cint, numNodes::Array{Cint}, digits::Cint=Cint(0))::QuadRule @assert d == length(numNodes) "LobattoRule: numNodes must have the same size as the dimension" qr = ccall((:gsLobattoRule_create,libgismo),Ptr{gsCQuadRule},(Cint,Ptr{Cint},Cint),d,numNodes,digits) return QuadRule(qr) @@ -94,7 +92,7 @@ Returns a Lobatto rule for numerical integration - `digits::Int`: the number of digits of precision for the rule (optionals) """ -function LobattoRule(numNodes::Int, digits::Int=Int(0))::QuadRule +function LobattoRule(numNodes::Int, digits::Int=Cint(0))::QuadRule d::Int = 1; numNodesVec::Array{Int} = [numNodes] qr = ccall((:LobattoRule_create,libgismo),Ptr{gsCQuadRule},(Cint,Ptr{Cint},Cint),d,numNodesVec,digits) From 15c1be3802165703eb5692d6fffdb31acdb6e853 Mon Sep 17 00:00:00 2001 From: Hugo Verhelst Date: Thu, 9 Jan 2025 15:18:29 +0100 Subject: [PATCH 16/16] update version, add pieces| --- Project.toml | 4 ++-- src/gsCore.jl | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/Project.toml b/Project.toml index 42727ff..a93de40 100644 --- a/Project.toml +++ b/Project.toml @@ -1,13 +1,13 @@ name = "Gismo" uuid = "f019f137-166b-4455-b646-ee200b009b83" authors = ["Hugo Verhelst "] -version = "0.1.0" +version = "25.1.0" [deps] gismo_jll = "c3015cfb-32aa-504c-ba3d-5541e7ecaf35" [compat] -gismo_jll = "24.8.0" +gismo_jll = "25.1.0" julia = "1.9" [extras] diff --git a/src/gsCore.jl b/src/gsCore.jl index 86d12ac..f053ce4 100644 --- a/src/gsCore.jl +++ b/src/gsCore.jl @@ -27,6 +27,7 @@ export MultiPatch, addPatch!, patch, + computeTopology!, MultiBasis ######################################################################## @@ -625,6 +626,28 @@ function patch(obj::MultiPatch,i::Int)::Geometry return Geometry(g,false) end +""" +Computes the topology of a MultiPatch + +# Arguments +- `obj::MultiPatch`: a Gismo MultiPatch + +""" +function computeTopology!(obj::MultiPatch)::Nothing + ccall((:gsMultiPatch_computeTopology,libgismo),Cvoid,(Ptr{gsCMultiPatch},),obj.ptr) +end + +""" +Returns the size of a MultiPatch (number of patches) + +# Arguments +- `obj::MultiPatch`: a Gismo MultiPatch + +""" +function size(obj::MultiPatch)::Int + return ccall((:gsFunctionSet_nPieces,libgismo),Cint,(Ptr{gsCFunctionSet},),obj.ptr) +end + ######################################################################## # gsMultiBasis ########################################################################