mirror of
https://github.com/JuliaFEM/JuliaFEM.jl.git
synced 2026-08-16 18:44:05 +00:00
106 lines
3.2 KiB
Julia
106 lines
3.2 KiB
Julia
# This file is a part of JuliaFEM.
|
|
# License is MIT: see https://github.com/JuliaFEM/JuliaFEM.jl/blob/master/LICENSE.md
|
|
|
|
module ElementTests
|
|
|
|
using JuliaFEM.Test
|
|
|
|
using JuliaFEM.Core: AbstractElement, Element, Field, FieldSet, test_element
|
|
using JuliaFEM.Core: Tri3, Quad4
|
|
import JuliaFEM.Core: get_basis, get_dbasis, calculate_normal_tangential_coordinates!
|
|
import Base: size
|
|
|
|
""" Prototype element
|
|
|
|
This should always pass test_element if everything is ok.
|
|
"""
|
|
abstract TestElement <: AbstractElement
|
|
|
|
function get_basis(::Type{TestElement}, xi::Vector{Float64})
|
|
1/4*[
|
|
(1-xi[1])*(1-xi[2])
|
|
(1+xi[1])*(1-xi[2])
|
|
(1+xi[1])*(1+xi[2])
|
|
(1-xi[1])*(1+xi[2])]'
|
|
end
|
|
|
|
function get_dbasis(::Type{TestElement}, xi::Vector{Float64})
|
|
1/4*[
|
|
-(1-xi[2]) (1-xi[2]) (1+xi[2]) -(1+xi[2])
|
|
-(1-xi[1]) -(1+xi[1]) (1+xi[1]) (1-xi[1])]
|
|
end
|
|
|
|
function size(::Type{TestElement})
|
|
return (2, 4)
|
|
end
|
|
|
|
""" Return test element with some fields. """
|
|
function get_element()
|
|
el = Element{TestElement}([1, 2, 3, 4])
|
|
el["geometry"] = Vector{Float64}[[0.0,0.0], [1.0,0.0], [1.0,1.0], [0.0,1.0]]
|
|
el["temperature"] = (
|
|
0.0 => [0.0, 0.0, 0.0, 0.0],
|
|
1.0 => [1.0, 2.0, 3.0, 4.0])
|
|
el["displacement"] = (
|
|
0.0 => Vector{Float64}[[0.0,0.0], [0.0, 0.0], [0.0,0.0], [0.0,0.0]],
|
|
1.0 => Vector{Float64}[[0.0,0.0], [1.0,-1.0], [2.0,3.0], [0.0,0.0]])
|
|
return el
|
|
end
|
|
|
|
function test_mock_element()
|
|
test_element(TestElement)
|
|
end
|
|
|
|
function test_add_fields_to_element()
|
|
el = get_element()
|
|
info(el.fields)
|
|
end
|
|
|
|
function test_interpolate()
|
|
el = get_element()
|
|
@test isapprox(el("geometry", [0.0, 0.0]), [0.5, 0.5])
|
|
@test isapprox(el("geometry", [0.0, 0.0], 0.0), [0.5, 0.5])
|
|
@test isapprox(el([0.0, 0.0]), [0.25 0.25 0.25 0.25])
|
|
@test isapprox(el([0.0, 0.0], Val{:grad}), [-0.5 0.5 0.5 -0.5; -0.5 -0.5 0.5 0.5])
|
|
gradT = el("temperature", [0.0, 0.0], 1.0, Val{:grad})
|
|
info("gradT = $gradT")
|
|
X = [0.5, 0.5]
|
|
gradT_expected = [1-2*X[2] 3-2*X[1]]
|
|
info("gradT(expected) = $gradT_expected")
|
|
@test isapprox(gradT, gradT_expected)
|
|
|
|
# @test isapprox(el("temperature", [0.0, 0.0], 0.5), 1/2*gradT_expected)
|
|
|
|
# gradT = el("temperature", [0.0, 0.0], 0.5, Val{:grad})
|
|
# info("gradT = $gradT")
|
|
# @test isapprox(gradT, 1/2*gradT_expected)
|
|
end
|
|
|
|
function test_calculate_normal_tangential_coordinates()
|
|
el = Tri3([1, 2, 3])
|
|
el["geometry"] = Vector{Float64}[
|
|
[0.0, 0.0, 0.0],
|
|
[1.0, 0.0, 0.0],
|
|
[0.0, 1.0, 0.0]]
|
|
calculate_normal_tangential_coordinates!(el, 0.0)
|
|
n = [0.0 0.0 1.0]'
|
|
t1 = [1.0 0.0 0.0]'
|
|
t2 = [0.0 1.0 0.0]'
|
|
R = [n t1 t2]
|
|
@test isapprox(el("normal-tangential coordinates", [0.0, 0.0], 0.0), R)
|
|
end
|
|
#test_calculate_normal_tangential_coordinates()
|
|
|
|
function test_manifold_determinant()
|
|
el = Quad4([1, 2, 3, 4])
|
|
#el["geometry"] = Vector{Float64}[[0.0, 0.0], [1.0, 0.0], [1.0, 1.0], [0.0, 1.0]]
|
|
el["geometry"] = Vector{Float64}[[0.0, 0.0, 1.0], [1.0, 0.0, 1.0], [1.0, 1.0, 1.0], [0.0, 1.0, 1.0]]
|
|
# mother element area = 2*2 = 4, this element is 1, determinant should be 1/4 everywhere
|
|
d = det(el, [0.1, 0.2], 0.0)
|
|
d_expected = 0.25
|
|
@test d == d_expected
|
|
end
|
|
#test_manifold_determinant()
|
|
|
|
end
|