2d mortar

This commit is contained in:
Jukka Aho
2015-11-18 01:19:04 +02:00
parent 95bee76438
commit 9e9bceecff
15 changed files with 428 additions and 233 deletions
+25 -5
View File
@@ -4,27 +4,47 @@
module ElasticityTests
using JuliaFEM.Test
using JuliaFEM: Quad4, Field, FieldSet, CPS4,
using JuliaFEM: Seg2, Quad4, Field, FieldSet, CPS4,
get_basis, solve!,
PlaneStressElasticityProblem
function test_elasticity_one_element()
function test_elasticity_volume_load()
element = Quad4([1, 2, 3, 4])
element["geometry"] = Vector[[0.0, 0.0], [10.0, 0.0], [10.0, 1.0], [0.0, 1.0]]
element["youngs modulus"] = 500.0
element["poissons ratio"] = 0.3
element["displacement load"] = Vector[[0.0, -10.0], [0.0, -10.0], [0.0, -10.0], [0.0, -10.0]]
equation = CPS4(element)
free_dofs = [3, 4, 5, 6]
problem = PlaneStressElasticityProblem([equation])
problem = PlaneStressElasticityProblem()
push!(problem, element)
solve!(problem, free_dofs; max_iterations=10)
#solve!(equation, "displacement", free_dofs; max_iterations=10)
disp = get_basis(element)("displacement", [1.0, 1.0])[2]
info("displacement at tip: $disp")
# verified using Code Aster.
@test isapprox(disp, -8.77303119819776)
end
function test_elasticity_surface_load()
N = Vector[[0.0, 0.0], [10.0, 0.0], [10.0, 1.0], [0.0, 1.0]]
element1 = Quad4([1, 2, 3, 4])
element1["geometry"] = Vector[N[1], N[2], N[3], N[4]]
element1["youngs modulus"] = 500.0
element1["poissons ratio"] = 0.3
element2 = Seg2([3, 4])
element2["geometry"] = Vector[N[3], N[4]]
element2["displacement traction force"] = Vector[[0.0, -10.0], [0.0, -10.0]]
free_dofs = [3, 4, 5, 6]
problem = PlaneStressElasticityProblem()
push!(problem, element1)
push!(problem, element2)
solve!(problem, free_dofs; max_iterations=10)
disp = get_basis(element1)("displacement", [1.0, 1.0])[2]
info("displacement at tip: $disp")
# verified using Code Aster.
@test isapprox(disp, -9.33106637611714)
end
end
+4 -2
View File
@@ -6,6 +6,8 @@
module HeatTests # always wrap tests to module ending with "Tests"
using JuliaFEM.Test # always use JuliaFEM.Test, not Base.Test
using JuliaFEM: HeatEquation
using JuliaFEM: Seg2, Quad4, DC2D4, DC2D2, Assembly, assemble!
function test_one_element() # always start test function with name test_
@@ -25,7 +27,7 @@ function test_one_element() # always start test function with name test_
# Set constant source f=12 with k=6. Accurate solution is
# T=1 on free boundary, u(x,y) = -1/6*(1/2*f*x^2 - f*x)
equation = DC2D4(element)
equation = convert(HeatEquation, element)
#la = initialize_local_assembly()
#calculate_local_assembly!(la, equation, "temperature")
assembly = Assembly()
@@ -37,7 +39,7 @@ function test_one_element() # always start test function with name test_
# Set constant flux g=6 on boundary. Accurate solution is
# u(x,y) = x which equals T=1 on boundary.
boundary_equation = DC2D2(boundary_element)
boundary_equation = convert(HeatEquation, boundary_element)
empty!(assembly)
time = 1.0
+77 -42
View File
@@ -6,78 +6,113 @@ module MortarTests
using JuliaFEM
using JuliaFEM.Test
function test_calc_flat_2d_assembly()
# this is hand calculated and given example in my thesis
using JuliaFEM: MSeg2, Seg2, MortarProblem, MortarEquation, MortarElement, Assembly, assemble!
using JuliaFEM: get_basis, grad, project_from_slave_to_master, project_from_master_to_slave
function get_test_2d_model()
# this is hand calculated and given as an example in my thesis
N = Vector[
[0.0, 2.0], [1.0, 2.0], [2.0, 2.0],
[0.0, 0.0], [1.0, 0.0], [2.0, 0.0],
[0.0, 1.0], [5/4, 1.0], [2.0, 1.0],
[0.0, 1.0], [3/4, 1.0], [2.0, 1.0]]
rotation_matrix(phi) = [cos(phi) -sin(phi); sin(phi) cos(phi)]
slave1 = MSeg2([10, 11])
slave1["geometry"] = Vector[N[10], N[11]]
# should be n = [0 -1]' and t = [1 0]'
slave1["nodal ntsys"] = Matrix[rotation_matrix(-pi/2), rotation_matrix(-pi/2)]
slave2 = MSeg2([11, 12])
slave2["geometry"] = Vector[N[11], N[12]]
# should be n = [0 -1]' and t = [1 0]'
slave2["nodal ntsys"] = Matrix[rotation_matrix(-pi/2), rotation_matrix(-pi/2)]
master1 = MSeg2([7, 8])
master1["geometry"] = Vector[N[7], N[8]]
master2 = MSeg2([8, 9])
master2["geometry"] = Vector[N[8], N[9]]
push!(slave1.master_elements, master1)
push!(slave1.master_elements, master2)
push!(slave2.master_elements, master1)
push!(slave2.master_elements, master2)
return [slave1, slave2], [master1, master2]
end
slave1 = Seg2([10, 11])
slave1["geometry"] = Vector[N10, N11]
slave2 = Seg2([11, 12])
slave2["geometry"] = Vector[N11, N12]
function test_calc_flat_2d_projection()
slaves, masters = get_test_2d_model()
slave1, slave2 = slaves
master1, master2 = masters
master1 = Seg2([7, 8])
master1["geometry"] = Vector[N7, N8]
xi2a = project_from_slave_to_master(slave1, master1, [-1.0])
@test xi2a == [-1.0]
master2 = Seg2([8, 9])
master2["geometry"] = Vector[N8, N9]
xi2b = project_from_slave_to_master(slave1, master1, [1.0])
@test xi2b == [ 0.2]
X2 = get_basis(master1)("geometry", xi2b)
@test X2 == [3/4, 1.0]
xi1a = project_from_master_to_slave(slave1, master1, [-1.0])
@test xi1a == [-1.0]
xi1b = project_from_master_to_slave(slave1, master1, [1.0])
X1 = get_basis(slave1)("geometry", xi1b)
@test X1 == [5/4, 1.0]
end
function test_create_flat_2d_assembly()
slaves, masters = get_test_2d_model()
slave1, slave2 = slaves
master1, master2 = masters
info("creating problem")
problem = MortarProblem()
info("pushing slave elements to problem")
push!(problem, slave1)
push!(problem, slave2)
push!(problem.master_elements, master1)
push!(problem.master_elements, master2)
rotation_matrix(phi) = [cos(phi) -sin(phi); sin(phi) cos(phi)]
# should be n = [0 -1]' and t = [1 0]'
@test isapprox(rotation_matrix(-phi/2), [[0 -1]' [1 0]'])
problem.node_csys = Dict(
10 => rotation_matrix(-phi/2),
11 => rotation_matrix(-phi/2),
12 => rotation_matrix(-phi/2))
# first index = master element id
# second index = slave element id
problem.element_pairs = zeros(2, 2)
# first slave element connects to master element 1
problem.element_pairs[1, 1] = true
# second slave element connects to master element 1
problem.element_pairs[1, 2] = true
# second slave element connects to master element 2
problem.element_pairs[2, 2] = true
B_expected = zeros(12, 9)
B_expected = zeros(12, 12)
S1 = [10, 11]
M1 = [7, 8]
B_expected[S1,S1] += [1/4 1/8; 1/8 1/4]
B_expected[S1,M1] += [3/10 3/40; 9/40 3/20]
B_expected[S1,M1] -= [3/10 3/40; 9/40 3/20]
la = initialize_local_assembly(problem)
calculate_local_assembly!(la, problem.equations[1], "reaction force", 0.0, problem=problem)
B = full(la.lhs)
info("creating assembly")
assembly = Assembly()
assemble!(assembly, problem.equations[1], 0.0, problem)
B = round(full(assembly.lhs, 12, 12), 6)
info("size of B = $(size(B))")
info("B matrix in first slave element = \n$(B[10:11,:])")
info("B matrix expected = \n$(B_expected[10:11,:])")
@test isapprox(B, B_expected)
fill!(B_expected, 0.0)
empty!(assembly)
S2 = [11, 12]
M2 = [7, 8]
B_expected[S2,S2] += [49/150 11/150; 11/150 2/75]
B_expected[S2,M2] += [13/150 47/150; 1/75 13/150]
B_expected[S2,M2] -= [13/150 47/150; 1/75 13/150]
S3 = [11, 12]
M3 = [8, 9]
B_expected[S3,S3] += [9/100 27/200; 27/200 39/100]
B_expected[S3,M3] += [3/20 3/40; 9/40 3/10]
B_expected[S3,M3] -= [3/20 3/40; 9/40 3/10]
assemble!(assembly, problem.equations[2], 0.0, problem)
B = full(assembly.lhs)
info("size of B = $(size(B))")
info("B matrix in second slave element = \n$(B[11:12,:])")
info("B matrix expected = \n$(B_expected[11:12,:])")
la = initialize_local_assembly(problem)
calculate_local_assembly!(la, problem.equations[1], "reaction force", 0.0, problem=problem)
B = full(la.lhs)
@test isapprox(B, B_expected)
end
function test_patch_test_heat_2d()
slaves, masters = get_test_2d_model()
problem2 = MortarProblem()
for slave in slaves:
push!(problem2, slave)
end
end
end
+17 -18
View File
@@ -1,9 +1,11 @@
# This file is a part of JuliaFEM.
# License is MIT: see https://github.com/JuliaFEM/JuliaFEM.jl/blob/master/LICENSE.md
# test SimpleSolver
module SolverTests
using JuliaFEM.Test
using JuliaFEM
using FactCheck
using JuliaFEM: DirichletProblem, Seg2, PlaneHeatProblem, Quad4, SimpleSolver, get_element, get_basis
""" Define Problem 1:
@@ -13,25 +15,16 @@ using JuliaFEM: DirichletProblem, Seg2, PlaneHeatProblem, Quad4, SimpleSolver, g
"""
function get_heatproblem()
el1 = Quad4([1, 2, 3, 4])
# these might look like normal values but believe me, they
# are fields with temporal and spatial dimension
el1["geometry"] = Vector[[0.0, 0.0], [1.0, 0.0], [1.0, 1.0], [0.0, 1.0]]
el1["temperature thermal conductivity"] = 6.0
el1["density"] = 36.0
el2 = Seg2([1, 2])
el2["geometry"] = Vector[[0.0, 0.0], [1.0, 0.0]]
# Boundary load, linear ramp 0 -> 600 at time 0 -> 1
# yet another simplification, if field is given as a tuple,
# multiple fields are created. there is 1 second time step between
# each field. So the following is basically same as
# fieldset = FieldSet("temperature flux")
# field1 = Field(0.0, 0.0)
# field2 = Field(1.0, 600.0)
# push!(fieldset, field1)
# push!(fieldset, field2)
# element["temperature flux"] = fieldset
el2["temperature flux"] = (0.0, 600.0)
el2["temperature flux"] = (
(0.0 => 0.0),
(1.0 => 600.0)
)
problem1 = PlaneHeatProblem()
push!(problem1, el1)
@@ -50,13 +43,17 @@ function get_boundaryproblem()
return problem2
end
facts("test simplesolver") do
function test_simplesolver()
info("construct heat problem")
problem1 = get_heatproblem()
info("construct boundary problem")
problem2 = get_boundaryproblem()
# Create a solver for a set of problems
info("create SimpleSolver with problems.")
solver = SimpleSolver()
push!(solver, problem1)
push!(solver, problem2)
info("solve!")
# Solve problem at time t=1.0 and update fields
call(solver, 1.0)
# Postprocess.
@@ -66,6 +63,8 @@ facts("test simplesolver") do
basis = get_basis(el2)
X = basis("geometry", xi, 1.0)
T = basis("temperature", xi, 1.0)
Logging.info("Temperature at point X = $X is T = $T")
@fact T --> roughly(100.0)
info("Temperature at point X = $X is T = $T")
@test isapprox(mean(T), 100.0)
end
end