mirror of
https://github.com/JuliaFEM/JuliaFEM.jl.git
synced 2026-09-22 18:52:16 +00:00
optics
This commit is contained in:
+23
-55
@@ -1,61 +1,10 @@
|
||||
# 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
|
||||
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])
|
||||
@@ -89,7 +38,6 @@ function test_calculate_normal_tangential_coordinates()
|
||||
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])
|
||||
@@ -100,6 +48,26 @@ function test_manifold_determinant()
|
||||
d_expected = 0.25
|
||||
@test d == d_expected
|
||||
end
|
||||
#test_manifold_determinant()
|
||||
|
||||
@testset "add new discrete constant time-variant field and interpolate it" begin
|
||||
element = Element(Quad4, [1, 2, 3, 4])
|
||||
element["my field"] = (0.0 => 0.0, 1.0 => 1.0)
|
||||
@test isapprox(element("my field", [0.0, 0.0], 0.5), 0.5)
|
||||
update!(element, "my field 2", 0.0 => 0.0, 1.0 => 1.0)
|
||||
@test isapprox(element("my field 2", [0.0, 0.0], 0.5), 0.5)
|
||||
end
|
||||
|
||||
=#
|
||||
|
||||
@testset "test add time dependent field to element" begin
|
||||
el = Element(Seg2, [1, 2])
|
||||
u1 = Vector{Float64}[[0.0, 0.0], [0.0, 0.0]]
|
||||
u2 = Vector{Float64}[[1.0, 1.0], [1.0, 1.0]]
|
||||
update!(el, "displacement", 0.0 => u1)
|
||||
update!(el, "displacement", 1.0 => u2)
|
||||
@test length(el["displacement"]) == 2
|
||||
@test isapprox(el("displacement", [0.0], 0.0), [0.0, 0.0])
|
||||
@test isapprox(el("displacement", [0.0], 0.5), [0.5, 0.5])
|
||||
@test isapprox(el("displacement", [0.0], 1.0), [1.0, 1.0])
|
||||
end
|
||||
|
||||
|
||||
@@ -1,14 +1,7 @@
|
||||
# This file is a part of JuliaFEM.
|
||||
# License is MIT: see https://github.com/JuliaFEM/JuliaFEM.jl/blob/master/LICENSE.md
|
||||
|
||||
using JuliaFEM
|
||||
using JuliaFEM.Test
|
||||
|
||||
using JuliaFEM.Core: Quad4, update!
|
||||
|
||||
@testset "add new discrete constant time-variant field and interpolate it" begin
|
||||
element = Quad4([1, 2, 3, 4])
|
||||
element["my field"] = (0.0 => 0.0, 1.0 => 1.0)
|
||||
@test isapprox(element("my field", [0.0, 0.0], 0.5), 0.5)
|
||||
update!(element, "my field 2", 0.0 => 0.0, 1.0 => 1.0)
|
||||
@test isapprox(element("my field 2", [0.0, 0.0], 0.5), 0.5)
|
||||
end
|
||||
|
||||
@@ -24,3 +24,4 @@ end
|
||||
update!(f, 2.0)
|
||||
@test f.data == 2.0
|
||||
end
|
||||
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
# This file is a part of JuliaFEM.
|
||||
# License is MIT: see https://github.com/JuliaFEM/JuliaFEM.jl/blob/master/LICENSE.md
|
||||
|
||||
using JuliaFEM
|
||||
using JuliaFEM.Test
|
||||
|
||||
@testset "find intersection of Seg3 element" begin
|
||||
el = Element(Seg3, [1, 2, 3])
|
||||
update!(el, "geometry", Vector{Float64}[[0.0, 1.0], [1.0, 0.0], sqrt(2.0)/2.0*[1.0, 1.0]])
|
||||
s = [ 1.0, 0.5]
|
||||
d = [-1.0, 0.0]
|
||||
t, xi = find_intersection(el, s, d, 0.0)
|
||||
x = el("geometry", xi, 0.0)
|
||||
@test isapprox(x, [0.8604093371313943, 0.5])
|
||||
end
|
||||
|
||||
@testset "find intersection of 2. order NSeg element" begin
|
||||
# this is a exact quarter of circle
|
||||
a = 1.0
|
||||
b = 1.0
|
||||
el = Element(NSeg, [1, 2, 3])
|
||||
el.properties.order = 2
|
||||
el.properties.knots = [0.0, 0.0, 0.0, 1.0, 1.0, 1.0]
|
||||
el.properties.weights = [1.0, 1.0, 2.0]
|
||||
update!(el, "geometry", Vector{Float64}[[a, 0], [a, b], [0, b]])
|
||||
s = [ 1.0, 0.5]
|
||||
d = [-1.0, 0.0]
|
||||
t, xi = find_intersection(el, s, d, 0.0)
|
||||
X = el("geometry", xi, 0.0)
|
||||
@test isapprox(X, [sqrt(3)/2, 1/2])
|
||||
end
|
||||
|
||||
@testset "find intersection of 1. order NSurf" begin
|
||||
# node ordering, it's not same as in Quad4
|
||||
el = Element(NSurf, [1, 2, 3, 4])
|
||||
el.properties.order_u = 1
|
||||
el.properties.order_v = 1
|
||||
el.properties.knots_u = [0.0, 0.0, 1.0, 1.0]
|
||||
el.properties.knots_v = [0.0, 0.0, 1.0, 1.0]
|
||||
el.properties.weights = ones(2, 2)
|
||||
# +-- v
|
||||
# |
|
||||
# u
|
||||
nodes = Vector{Float64}[[0.0,0.0,0.0], [1.0,0.0,0.0],
|
||||
[0.0,1.0,0.0], [1.0,1.0,0.0]]
|
||||
update!(el, "geometry", nodes)
|
||||
s = [0.5, 0.5, 0.5]
|
||||
d = [0.0, 0.0, -1.0]
|
||||
t, xi = find_intersection(el, s, d, 0.0)
|
||||
X = el("geometry", xi, 0.0)
|
||||
@test isapprox(X, [0.5, 0.5, 0.0])
|
||||
k = calc_reflection(el, xi, d, 0.0)
|
||||
@test isapprox(k, [0.0, 0.0, 1.0])
|
||||
s = [1.5, 1.5, 0.5]
|
||||
t, xi = find_intersection(el, s, d, 0.0)
|
||||
@test isnan(t)
|
||||
end
|
||||
|
||||
@testset "find intersection of 3. order NSeg element with multiple reflections" begin
|
||||
el = Element(NSeg, [1, 2, 3, 4])
|
||||
el.properties.order = 3
|
||||
el.properties.knots = [0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0]
|
||||
el.properties.weights = [1.0, 1/3, 1/3, 1.0]
|
||||
update!(el, "geometry", Vector{Float64}[[1, 0], [1, 2], [-1, 2], [-1, 0]])
|
||||
s1 = [-sqrt(3)/2.0, 0.0]
|
||||
k1 = [ 0.0, 1.0]
|
||||
t1, xi1 = find_intersection(el, s1, k1, 0.0)
|
||||
s2 = el("geometry", xi1, 0.0)
|
||||
@test isapprox(s2, [-sqrt(3)/2, 0.5])
|
||||
k2 = calc_reflection(el, xi1, k1, 0.0)
|
||||
t2, xi2 = find_intersection(el, s2, k2, 0.0; secondary=true)
|
||||
s3 = el("geometry", xi2, 0.0)
|
||||
@test isapprox(s3, [0.0, 1.0])
|
||||
k3 = calc_reflection(el, xi2, k2, 0.0)
|
||||
t3, xi3 = find_intersection(el, s3, k3, 0.0; secondary=true)
|
||||
s4 = el("geometry", xi3, 0.0)
|
||||
@test isapprox(s4, [sqrt(3)/2, 0.5])
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user