From b6b0bc3f55af3226c2bede38bcbfe671443602f6 Mon Sep 17 00:00:00 2001 From: Jukka Aho Date: Sun, 13 Aug 2017 21:56:52 +0300 Subject: [PATCH] Change coords field type from Point to Tuple Change to Tuple, Array is allocating memory. --- src/elements.jl | 8 ++++---- src/elements_lagrange.jl | 2 +- src/integrate.jl | 2 +- src/types.jl | 9 +++++++-- test/test_integration_points.jl | 3 ++- 5 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/elements.jl b/src/elements.jl index 80e01c1..cd569c5 100644 --- a/src/elements.jl +++ b/src/elements.jl @@ -330,8 +330,8 @@ function get_integration_points{E}(element::Element{E}) # first time initialize default integration points if length(element.integration_points) == 0 ips = get_integration_points(element.properties) - if E in (Seg2, Seg3, NSeg) - element.integration_points = [IP(i, w, [xi]) for (i, (w, xi)) in enumerate(ips)] + if E in (Poi1, Seg2, Seg3, NSeg) + element.integration_points = [IP(i, w, (xi,)) for (i, (w, xi)) in enumerate(ips)] else element.integration_points = [IP(i, w, xi) for (i, (w, xi)) in enumerate(ips)] end @@ -344,8 +344,8 @@ of integration scheme mainly for mass matrix. """ function get_integration_points{E}(element::Element{E}, change_order::Int) ips = get_integration_points(element.properties, Val{change_order}) - if E in (Seg2, Seg3, NSeg) - return [IP(i, w, [xi]) for (i, (w, xi)) in enumerate(ips)] + if E in (Poi1, Seg2, Seg3, NSeg) + return [IP(i, w, (xi,)) for (i, (w, xi)) in enumerate(ips)] else return [IP(i, w, xi) for (i, (w, xi)) in enumerate(ips)] end diff --git a/src/elements_lagrange.jl b/src/elements_lagrange.jl index df79789..121c97e 100644 --- a/src/elements_lagrange.jl +++ b/src/elements_lagrange.jl @@ -25,7 +25,7 @@ function get_integration_order(element::Poi1) end function get_integration_points(element::Poi1, order::Int64) - return [ (1.0, [] ) ] + return [ (1.0, 0.0) ] end function size(::Type{Poi1}) diff --git a/src/integrate.jl b/src/integrate.jl index 7679fb0..2dda5bc 100644 --- a/src/integrate.jl +++ b/src/integrate.jl @@ -54,5 +54,5 @@ end # All good codes needs a special case. Here we have it: Poi1 function get_integration_points(element::Poi1) - [ (1.0, [] ) ] + [ (1.0, 0.0) ] end diff --git a/src/types.jl b/src/types.jl index a784c99..e4dcec4 100644 --- a/src/types.jl +++ b/src/types.jl @@ -8,7 +8,7 @@ abstract type AbstractPoint end type Point{P<:AbstractPoint} id :: Int weight :: Float64 - coords :: Vector{Float64} + coords :: Tuple{Vararg{Float64}} fields :: Dict{AbstractString, Field} properties :: P end @@ -66,6 +66,11 @@ end const IP = Point{IntegrationPoint} -function IP(id, weight, coords) +function IP(id, weight, coords::Tuple) + return IP(id, weight, coords, Dict(), IntegrationPoint()) +end + +function IP(id, weight, coords::Vector) + warn("Consider giving coords as Tuple.") return IP(id, weight, [c for c in coords], Dict(), IntegrationPoint()) end diff --git a/test/test_integration_points.jl b/test/test_integration_points.jl index 23c8f84..c7a8a5a 100644 --- a/test/test_integration_points.jl +++ b/test/test_integration_points.jl @@ -5,7 +5,8 @@ using JuliaFEM using JuliaFEM.Testing @testset "test integration point" begin - ip = IP(1, 1.0, sqrt(1.0/3.0)*[-1.0, -1.0]) + a = sqrt(1.0/3.0) + ip = IP(1, 1.0, (a, -a)) strain = [1.0 2.0; 3.0 4.0] update!(ip, "strain", 0.0 => strain) @test isapprox(ip("strain", 0.0), strain)