From 2b1f4dcd95e1f1c0cb6db1e5fdc40f74a20ed0d2 Mon Sep 17 00:00:00 2001 From: Petr Krysl Date: Thu, 15 Feb 2024 09:09:14 -0800 Subject: [PATCH] improve performance of subset --- Project.toml | 2 +- src/FESetModule.jl | 20 +++++++++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/Project.toml b/Project.toml index 694142b9..295e8853 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "FinEtools" uuid = "91bb5406-6c9a-523d-811d-0644c4229550" authors = ["Petr Krysl "] -version = "7.3.4" +version = "7.3.5" [deps] ChunkSplitters = "ae650224-84b6-46f8-82ea-d812ca08434e" diff --git a/src/FESetModule.jl b/src/FESetModule.jl index 0a2778a1..10326508 100644 --- a/src/FESetModule.jl +++ b/src/FESetModule.jl @@ -56,7 +56,7 @@ Define the concrete type for a finite element set. """ macro define_FESet(NAME, MANIFOLD, NODESPERELEM) return esc(:(mutable struct $NAME{IT} <: $MANIFOLD{$NODESPERELEM} - conn::Array{NTuple{$NODESPERELEM, IT}, 1} + conn::Vector{NTuple{$NODESPERELEM, IT}} label::Vector{IT} delegateof::Any function $NAME(conn::AbstractArray{IT}) where {IT} @@ -65,6 +65,19 @@ macro define_FESet(NAME, MANIFOLD, NODESPERELEM) setlabel!(self, 0) return self end + function $NAME{IT}(conn::Vector{NTuple{$NODESPERELEM, IT}}) where {IT} + self = new{IT}(conn, IT[], nothing) + setlabel!(self, 0) + return self + end + function $NAME{IT}(conn::Vector{NTuple{$NODESPERELEM, IT}}, labels::Vector{IT}) where {IT} + self = new{IT}(conn, labels, nothing) + return self + end + function $NAME{IT}(conn::Vector{NTuple{$NODESPERELEM, IT}}, labels::Vector{IT}, delegof) where {IT} + self = new{IT}(conn, labels, delegof) + return self + end end)) end # show(macroexpand(Main, :(@define_FESet FESetT10 AbstractFESet0Manifold 10))) @@ -231,10 +244,7 @@ Extract a subset of the finite elements from the given finite element set. - `L`: an integer vector, tuple, or a range. """ function subset(self::ET, L) where {ET <: AbstractFESet} - result = deepcopy(self) - result.conn = deepcopy(self.conn[L]) - result.label = deepcopy(self.label[L]) - return result + return ET(self.conn[L], self.label[L], self.delegateof) end """