From d35b0ea5f4e3c3cbf22dbe2a9f2a5a5590a97c6d Mon Sep 17 00:00:00 2001 From: Hugo Verhelst Date: Thu, 19 Dec 2024 12:23:32 +0100 Subject: [PATCH] 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)