mirror of
https://github.com/JuliaFEM/JuliaFEM.jl.git
synced 2026-09-27 20:26:58 +00:00
issue #67
This commit is contained in:
@@ -17,8 +17,8 @@ function test_elasticity_volume_load()
|
||||
free_dofs = [3, 4, 5, 6]
|
||||
problem = PlaneStressElasticityProblem()
|
||||
push!(problem, element)
|
||||
solve!(problem, free_dofs; max_iterations=10)
|
||||
disp = get_basis(element)("displacement", [1.0, 1.0])
|
||||
solve!(problem, free_dofs, 0.0; max_iterations=10)
|
||||
disp = get_basis(element)("displacement", [1.0, 1.0], 0.0)
|
||||
info("displacement at tip: $disp")
|
||||
# verified using Code Aster.
|
||||
@test isapprox(disp[2], -8.77303119819776)
|
||||
@@ -39,11 +39,13 @@ function test_elasticity_surface_load()
|
||||
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]
|
||||
solve!(problem, free_dofs, 1.0; max_iterations=10)
|
||||
disp = get_basis(element1)("displacement", [1.0, 1.0], 1.0)[2]
|
||||
info("displacement at tip: $disp")
|
||||
# verified using Code Aster.
|
||||
@test isapprox(disp, -9.33106637611714)
|
||||
end
|
||||
|
||||
#test_elasticity_volume_load()
|
||||
|
||||
end
|
||||
|
||||
+3
-10
@@ -14,6 +14,7 @@ function test_one_element() # always start test function with name test_
|
||||
|
||||
# volume element
|
||||
element = Quad4([1, 2, 3, 4])
|
||||
|
||||
element["geometry"] = Vector[[0.0, 0.0], [1.0, 0.0], [1.0, 1.0], [0.0, 1.0]]
|
||||
element["temperature thermal conductivity"] = 6.0
|
||||
element["temperature load"] = [12.0, 12.0, 12.0, 12.0]
|
||||
@@ -22,14 +23,12 @@ function test_one_element() # always start test function with name test_
|
||||
# boundary element
|
||||
boundary_element = Seg2([1, 2])
|
||||
boundary_element["geometry"] = Vector[[0.0, 0.0], [1.0, 0.0]]
|
||||
# linear ramp from 1 to 6 in time 0 to 1
|
||||
boundary_element["temperature flux"] = (0.0, 0.0), (1.0, 6.0)
|
||||
# linear ramp from 0 to 6 in time 0 to 1
|
||||
boundary_element["temperature flux"] = (0.0 => 0.0, 1.0 => 6.0)
|
||||
|
||||
# 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 = convert(HeatEquation, element)
|
||||
#la = initialize_local_assembly()
|
||||
#calculate_local_assembly!(la, equation, "temperature")
|
||||
assembly = Assembly()
|
||||
assemble!(assembly, equation)
|
||||
fdofs = [1, 2]
|
||||
@@ -44,13 +43,7 @@ function test_one_element() # always start test function with name test_
|
||||
|
||||
time = 1.0
|
||||
assemble!(assembly, equation, time)
|
||||
info("after first element: $(length(assembly.force_vector.V))")
|
||||
info(full(assembly.force_vector)')
|
||||
assemble!(assembly, boundary_equation, time)
|
||||
info("after second element: $(length(assembly.force_vector.V))")
|
||||
info(full(assembly.force_vector)')
|
||||
#calculate_local_assembly!(la, boundary_equation, "temperature")
|
||||
#b = la.force_vector
|
||||
A = full(assembly.stiffness_matrix)
|
||||
b = full(assembly.force_vector)
|
||||
T = A[fdofs, fdofs] \ b[fdofs]
|
||||
|
||||
@@ -23,14 +23,6 @@ type DC2D4NL <: MyEquation
|
||||
integration_points :: Vector{IntegrationPoint}
|
||||
end
|
||||
|
||||
function DC2D4NL(element::Quad4)
|
||||
integration_points = get_default_integration_points(element)
|
||||
if !haskey(element, "temperature")
|
||||
element["temperature"] = zeros(4)
|
||||
end
|
||||
DC2D4NL(element, integration_points)
|
||||
end
|
||||
|
||||
function Base.size(equation::DC2D4NL)
|
||||
return (1, 4)
|
||||
end
|
||||
@@ -41,18 +33,23 @@ type DC2D2NL <: MyEquation
|
||||
integration_points :: Vector{IntegrationPoint}
|
||||
end
|
||||
|
||||
function DC2D2NL(element::Seg2)
|
||||
integration_points = JuliaFEM.line5()
|
||||
if !haskey(element, "temperature")
|
||||
element["temperature"] = zeros(2)
|
||||
end
|
||||
DC2D2NL(element, integration_points)
|
||||
end
|
||||
|
||||
function Base.size(equation::DC2D2NL)
|
||||
return (1, 2)
|
||||
end
|
||||
|
||||
function Base.convert(::Type{MyEquation}, element::Quad4)
|
||||
integration_points = get_default_integration_points(element)
|
||||
haskey(element, "temperature") || (element["temperature"] = 0.0 => zeros(4))
|
||||
DC2D4NL(element, integration_points)
|
||||
end
|
||||
|
||||
function Base.convert(::Type{MyEquation}, element::Seg2)
|
||||
integration_points = JuliaFEM.line5()
|
||||
haskey(element, "temperature") || (element["temperature"] = 0.0 => zeros(2))
|
||||
DC2D2NL(element, integration_points)
|
||||
end
|
||||
|
||||
|
||||
""" Calculate a potential Π = Wint - Wext of system. """
|
||||
function JuliaFEM.get_potential_energy(equation::DC2D4NL, ip, time; variation=nothing)
|
||||
element = get_element(equation)
|
||||
@@ -89,27 +86,13 @@ function test_potential_energy_method()
|
||||
element["temperature load"] = [0.0, 0.0, 0.0, 0.0]
|
||||
element["temperature nodal load"] = [3.0, 3.0, 0.0, 0.0]
|
||||
element["temperature nonlinearity coefficient"] = 6.0
|
||||
equation = DC2D4NL(element)
|
||||
equation = convert(MyEquation, element)
|
||||
# create model -- end
|
||||
|
||||
ass = Assembly()
|
||||
info("unknown field name: $(get_unknown_field_name(equation))")
|
||||
|
||||
T = zeros(4) # create workspace for solution vector
|
||||
dT = zeros(4) #
|
||||
fd = [1, 2] # free dofs
|
||||
# start loops, in principle solve ∂r(u)/∂uΔu = -r(u) and update.
|
||||
for i=1:10
|
||||
empty!(ass)
|
||||
assemble!(ass, equation) # calculate local matrices
|
||||
dT[fd] = full(ass.stiffness_matrix)[fd,fd] \ full(ass.force_vector)[fd]
|
||||
T += dT
|
||||
push!(element["temperature"], T) # add new increment to model
|
||||
@printf("increment %2d, |du| = %8.5f\n", i, norm(dT))
|
||||
err = last(element["temperature"])[1] - 2/3
|
||||
isapprox(err, 0.0) && break
|
||||
end
|
||||
err = last(element["temperature"])[1] - 2/3
|
||||
solve!(equation, [1, 2], 0.0)
|
||||
basis = get_basis(element)
|
||||
temp = basis("temperature", [0.0, -1.0], 0.0)
|
||||
err = temp - 2/3
|
||||
info("error: $err")
|
||||
@test isapprox(err, 0.0)
|
||||
end
|
||||
@@ -118,15 +101,11 @@ end
|
||||
type TestProblem <: Problem
|
||||
unknown_field_name :: ASCIIString
|
||||
unknown_field_dimension :: Int
|
||||
equations :: Vector{Equation}
|
||||
element_mapping :: Dict{DataType, DataType}
|
||||
equations :: Vector{MyEquation}
|
||||
end
|
||||
|
||||
function TestProblem(equations=[])
|
||||
element_mapping = Dict(
|
||||
Quad4 => DC2D4NL,
|
||||
Seg2 => DC2D2NL)
|
||||
TestProblem("temperature", 1, equations, element_mapping)
|
||||
TestProblem("temperature", 1, equations)
|
||||
end
|
||||
|
||||
function test_potential_energy_method_2()
|
||||
@@ -138,41 +117,23 @@ function test_potential_energy_method_2()
|
||||
element1["temperature thermal conductivity"] = 6.0
|
||||
element1["temperature load"] = [0.0, 0.0, 0.0, 0.0]
|
||||
element1["temperature nonlinearity coefficient"] = [0.0, 0.0, 0.0, 0.0]
|
||||
element1["temperature"] = ones(4)
|
||||
|
||||
element2 = Seg2([1, 2])
|
||||
element2["geometry"] = Vector[N[1], N[2]]
|
||||
element2["temperature coefficient"] = 3.0e-8 # ~ 5.7e-8 * 0.5
|
||||
element2["temperature external"] = 100.0
|
||||
element2["temperature"] = ones(2)
|
||||
# create model -- end
|
||||
|
||||
equation1 = DC2D4NL(element1)
|
||||
equation2 = DC2D2NL(element2)
|
||||
|
||||
ass = Assembly()
|
||||
info("unknown field name: $(get_unknown_field_name(equation1))")
|
||||
|
||||
T = zeros(4) # create workspace for solution vector
|
||||
dT = zeros(4) #
|
||||
fd = [1, 2] # free dofs
|
||||
# start loops, in principle solve ∂r(u)/∂uΔu = -r(u) and update.
|
||||
for i=1:10
|
||||
empty!(ass)
|
||||
assemble!(ass, equation1)
|
||||
assemble!(ass, equation2)
|
||||
dT[fd] = full(ass.stiffness_matrix)[fd,fd] \ full(ass.force_vector)[fd]
|
||||
T += dT
|
||||
push!(element1["temperature"], T)
|
||||
push!(element2["temperature"], T[fd])
|
||||
@printf("increment %2d, |du| = %8.5f\n", i, norm(dT))
|
||||
err = last(element1["temperature"])[1] - 0.5
|
||||
isapprox(err, 0.0) && break
|
||||
end
|
||||
problem = TestProblem()
|
||||
push!(problem, element1)
|
||||
push!(problem, element2)
|
||||
solve!(problem, [1, 2], 0.0)
|
||||
|
||||
err = last(element1["temperature"])[1] - 0.5
|
||||
basis = get_basis(element1)
|
||||
temp = basis("temperature", [0.0, -1.0], 0.0)
|
||||
err = temp - 0.5
|
||||
info("error: $err")
|
||||
@test isapprox(err, 0.0)
|
||||
@test isapprox(err, 0.0, atol=1.0e-6)
|
||||
|
||||
# @test isapprox(temp, 2.93509690572300E+00) # tested using Code Aster
|
||||
end
|
||||
|
||||
@@ -5,8 +5,7 @@ module TestAutoDiffWeakForm
|
||||
|
||||
using JuliaFEM.Test
|
||||
using JuliaFEM
|
||||
using JuliaFEM: Quad4, Equation, IntegrationPoint, assemble!,
|
||||
Assembly,
|
||||
using JuliaFEM: Quad4, Equation, IntegrationPoint, assemble!, Assembly,
|
||||
solve!, get_field, get_element, get_basis,
|
||||
grad, get_default_integration_points
|
||||
|
||||
@@ -23,7 +22,7 @@ end
|
||||
function CPS4(element::Quad4)
|
||||
integration_points = get_default_integration_points(element)
|
||||
if !haskey(element, "displacement")
|
||||
element["displacement"] = zeros(2, 4)
|
||||
element["displacement"] = 0.0 => Vector{Float64}[[0.0,0.0], [0.0,0.0], [0.0,0.0], [0.0,0.0]]
|
||||
end
|
||||
CPS4(element, integration_points)
|
||||
end
|
||||
@@ -71,8 +70,8 @@ function test_residual_form()
|
||||
# create model -- end
|
||||
|
||||
free_dofs = [3, 4, 5, 6]
|
||||
solve!(equation, free_dofs) # launch a newton solver for single element
|
||||
disp = get_basis(element)("displacement", [1.0, 1.0])[2]
|
||||
solve!(equation, free_dofs, 0.0) # launch a newton solver for single element
|
||||
disp = get_basis(element)("displacement", [1.0, 1.0], 0.0)[2]
|
||||
println("displacement at tip: $disp")
|
||||
# verified using Code Aster.
|
||||
@test isapprox(disp, -8.77303119819776E+00)
|
||||
|
||||
Reference in New Issue
Block a user