From 51b756d35175d013ffafb4042573af14c4a86df0 Mon Sep 17 00:00:00 2001 From: Petr Krysl Date: Tue, 21 May 2024 09:21:11 -0700 Subject: [PATCH] put back a compatibility gather --- src/ElementalFieldModule.jl | 1 + src/FieldModule.jl | 54 ++++++++++++++++++++++++++++--------- src/FinEtools.jl | 2 ++ src/GeneralFieldModule.jl | 1 + src/NodalFieldModule.jl | 1 + test/test_basics.jl | 2 +- 6 files changed, 47 insertions(+), 14 deletions(-) diff --git a/src/ElementalFieldModule.jl b/src/ElementalFieldModule.jl index 055fbaae..8f687e39 100644 --- a/src/ElementalFieldModule.jl +++ b/src/ElementalFieldModule.jl @@ -9,6 +9,7 @@ __precompile__(true) import ..FieldModule: AbstractField, nents import ..FieldModule.@add_Field_fields +import ..FieldModule.KIND_INT import ..FieldModule.DOF_KIND_FREE """ diff --git a/src/FieldModule.jl b/src/FieldModule.jl index 7b40bb96..0eb02c31 100644 --- a/src/FieldModule.jl +++ b/src/FieldModule.jl @@ -24,6 +24,20 @@ See also: [`@add_Field_fields()`](@ref) . """ abstract type AbstractField end +""" + KIND_INT + +Constant representing the type of the integer representing the `kind` of a degree of freedom. +""" +const KIND_INT = Int8 + +""" +Predefined kinds of degrees of freedom. +""" +const DOF_KIND_ALL::KIND_INT = 0 +const DOF_KIND_FREE::KIND_INT = 1 +const DOF_KIND_DATA::KIND_INT = 2 + """ add_Field_fields() @@ -33,18 +47,11 @@ the abstract type depend on these attributes to be present. macro add_Field_fields() return esc(:(values::Array{T,2}; dofnums::Array{IT,2}; - kind::Matrix{Int8}; + kind::Matrix{KIND_INT}; ranges::Vector{UnitRange{IT}} )) end -""" -Predefined kinds of degrees of freedom. -""" -const DOF_KIND_ALL = 0 -const DOF_KIND_FREE = 1 -const DOF_KIND_DATA = 2 - """ ndofs(self::F) @@ -76,21 +83,21 @@ end """ nfreedofs(self::F) where {F<:AbstractField} -Return to number of FREE degrees of freedom (known, data). +Return the number of FREE degrees of freedom (known, data). """ nfreedofs(self::F) where {F<:AbstractField} = length(dofrange(self, DOF_KIND_FREE)) """ nfixeddofs(self::F) -Return to number of FIXED degrees of freedom (known, data). +Return the number of FIXED degrees of freedom (known, data). """ nfixeddofs(self::F) where {F<:AbstractField} = length(dofrange(self, DOF_KIND_DATA)) """ nalldofs(self::F) where {F<:AbstractField} -Return to number of ALL degrees of freedom (known, data). +Return the number of ALL degrees of freedom (known, data). """ nalldofs(self::F) where {F<:AbstractField} = sum(length(v) for v in values(self.ranges)) @@ -139,7 +146,7 @@ function wipe!(self::F) where {F<:AbstractField} end """ - gathersysvec(self::F, kind = DOF_KIND_FREE) where {F<:AbstractField} + gathersysvec(self::F, kind::KIND_INT = DOF_KIND_FREE) where {F<:AbstractField} Gather values from the field for the system vector. @@ -147,12 +154,33 @@ Gather values from the field for the system vector. - `self`: field; - `kind`: kind of degrees of freedom to gather; default is `DOF_KIND_FREE`. """ -function gathersysvec(self::F, kind = DOF_KIND_FREE) where {F<:AbstractField} +function gathersysvec(self::F, kind::KIND_INT = DOF_KIND_FREE) where {F<:AbstractField} N = length(dofrange(self, kind)) vec = zeros(eltype(self.values), N) return gathersysvec!(self, vec, kind) end +""" + gathersysvec(self::F, kind::Symbol) where {F<:AbstractField} + +Gather values from the field for the system vector. + +This is a compatibility version, using a symbol. + +# Arguments +- `self::F`: The field object. +- `kind::Symbol`: The kind of system vector to gather. +""" +function gathersysvec(self::F, kind::Symbol) where {F<:AbstractField} + if kind == :f + return gathersysvec(self, DOF_KIND_FREE) + elseif kind == :d + return gathersysvec(self, DOF_KIND_DATA) + else + return gathersysvec(self, DOF_KIND_ALL) + end +end + """ gathersysvec!(self::F, vec::Vector{T}, which = :f) where {F<:AbstractField, T} diff --git a/src/FinEtools.jl b/src/FinEtools.jl index 12fa4afd..412270fc 100644 --- a/src/FinEtools.jl +++ b/src/FinEtools.jl @@ -121,6 +121,7 @@ export FENodeToFEMap using .FieldModule: AbstractField, + KIND_INT, DOF_KIND_ALL, DOF_KIND_FREE, DOF_KIND_DATA, @@ -147,6 +148,7 @@ using .FieldModule: incrscattersysvec! # Exported: abstract field type, methods for the abstract field type (retrieval of data from a field, setting of data in the field) export AbstractField, + KIND_INT, DOF_KIND_ALL, DOF_KIND_FREE, DOF_KIND_DATA, diff --git a/src/GeneralFieldModule.jl b/src/GeneralFieldModule.jl index ce6ebeef..d5d64836 100644 --- a/src/GeneralFieldModule.jl +++ b/src/GeneralFieldModule.jl @@ -9,6 +9,7 @@ __precompile__(true) import ..FieldModule.AbstractField import ..FieldModule.@add_Field_fields +import ..FieldModule.KIND_INT import ..FieldModule.DOF_KIND_FREE """ diff --git a/src/NodalFieldModule.jl b/src/NodalFieldModule.jl index d630ed7f..8e20914f 100644 --- a/src/NodalFieldModule.jl +++ b/src/NodalFieldModule.jl @@ -9,6 +9,7 @@ __precompile__(true) import ..FieldModule: AbstractField, nents import ..FieldModule.@add_Field_fields +import ..FieldModule.KIND_INT import ..FieldModule.DOF_KIND_FREE """ diff --git a/test/test_basics.jl b/test/test_basics.jl index 3c5cc7f5..b275a41e 100644 --- a/test/test_basics.jl +++ b/test/test_basics.jl @@ -26,7 +26,7 @@ using FinEtools using Test using LinearAlgebra function test() - DOF_KIND_INTERFACE = 3 + DOF_KIND_INTERFACE::KIND_INT = 3 ua = rand(50, 3) u = NodalField(ua) for i in [1, 4, 7, 10, 13, 16, 19, 22, 25]