added tests

This commit is contained in:
Jukka Aho
2015-10-28 04:29:14 +02:00
parent cde4ed5d96
commit 8bfff34e19
21 changed files with 1218 additions and 1085 deletions
+26
View File
@@ -0,0 +1,26 @@
# This file is a part of JuliaFEM.
# License is MIT: see https://github.com/JuliaFEM/JuliaFEM.jl/blob/master/LICENSE.md
# unit tests for heat equations
using FactCheck
using JuliaFEM: Quad4, Field, FieldSet, CPS4, get_basis, solve!, PlaneStressElasticityProblem
facts("test plane elasticity on single element, volume load") do
element = Quad4([1, 2, 3, 4])
element["geometry"] = FieldSet(Field(Vector[[0.0, 0.0], [10.0, 0.0], [10.0, 1.0], [0.0, 1.0]]))
element["youngs modulus"] = FieldSet(Field(500.0))
element["poissons ratio"] = FieldSet(Field(0.3))
element["displacement load"] = FieldSet(Field(0.0, 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])
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]
Logging.info("displacement at tip: $disp")
# verified using Code Aster.
@fact disp --> roughly(-8.77303119819776E+00)
end
+10 -8
View File
@@ -34,12 +34,14 @@ end
facts("test adding fieldsets and fields to element") do
el = MockElement([1, 2, 3, 4])
fieldset = JuliaFEM.FieldSet("geometry")
field1 = JuliaFEM.Field(0.0, [0.0, 0.0, 0.0, 0.0])
push!(fieldset, field1)
field2 = JuliaFEM.Field(1.0, [1.0, 1.0, 1.0, 1.0])
push!(fieldset, field2)
push!(el, fieldset)
el["geometry"] = fieldset
fields = el["geometry"]
@fact length(fields) --> 2
@fact fields[1] --> field1
@@ -57,13 +59,13 @@ facts("interpolation of fields in some function space") do
fieldset6 = FieldSet("vector field 3", [Field(0.0, Vector[[1.0, 5.0, 9.0], [2.0, 6.0, 10.0], [3.0, 7.0, 11.0], [4.0, 8.0, 12.0]])])
fieldset7 = FieldSet("tensor field 1", [Field(0.0, Matrix[[1.0 5.0; 9.0 13.0], [2.0 6.0; 10.0 14.0], [3.0 7.0; 11.0 15.0], [4.0 8.0; 12.0 16.0]])])
push!(element, fieldset1)
push!(element, fieldset2)
push!(element, fieldset3)
push!(element, fieldset4)
push!(element, fieldset5)
push!(element, fieldset6)
push!(element, fieldset7)
element["geometry"] = fieldset1
element["constant scalar field"] = fieldset2
element["scalar field"] = fieldset3
element["vector field 1"] = fieldset4
element["vector field 2"] = fieldset5
element["vector field 3"] = fieldset6
element["tensor field 1"] = fieldset7
xi = [0.0, 0.0]
t = 0.0
+32
View File
@@ -0,0 +1,32 @@
# This file is a part of JuliaFEM.
# License is MIT: see https://github.com/JuliaFEM/JuliaFEM.jl/blob/master/LICENSE.md
using JuliaFEM: Quad4, Seg2, FieldSet, Field, PlaneHeatProblem
using JuliaFEM: initialize_global_assembly, calculate_global_assembly!
using FactCheck
facts("assemble a simple two element problem and solve") do
el1 = Quad4([1, 2, 3, 4])
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["temperature load"] = [12.0, 12.0, 12.0, 12.0]
el1["density"] = 10
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
el2["temperature flux"] = FieldSet(Field[Field(0.0, 0.0), Field(1.0, 600.0)])
problem = PlaneHeatProblem()
push!(problem, el1)
push!(problem, el2)
global_assembly = initialize_global_assembly(problem)
calculate_global_assembly!(global_assembly, problem)
free_dofs = [1, 2]
A = lufact(global_assembly.stiffness_matrix[free_dofs, free_dofs])
b = full(global_assembly.force_vector)[free_dofs]
u = A \ b
@fact u --> roughly([101.0, 101.0])
end
+43
View File
@@ -0,0 +1,43 @@
# This file is a part of JuliaFEM.
# License is MIT: see https://github.com/JuliaFEM/JuliaFEM.jl/blob/master/LICENSE.md
# unit tests for heat equations
using FactCheck
using JuliaFEM: Seg2, Quad4, Field, FieldSet, DC2D4, initialize_local_assembly, calculate_local_assembly!, DC2D2
facts("tests on [0x1]x[0x1] domain") do
# volume element
element = Quad4([1, 2, 3, 4])
element["geometry"] = FieldSet(Field(Vector[[0.0, 0.0], [1.0, 0.0], [1.0, 1.0], [0.0, 1.0]]))
element["temperature thermal conductivity"] = FieldSet(Field(0.0, 6.0))
element["temperature load"] = FieldSet(Field(0.0, [12.0, 12.0, 12.0, 12.0]))
element["density"] = FieldSet(Field(0.0, 36.0))
# boundary element
boundary_element = Seg2([1, 2])
boundary_element["geometry"] = FieldSet(Field(Vector[[0.0, 0.0], [1.0, 0.0]]))
# linear ramp from 1 to 6 in time 0 to 1
boundary_element["temperature flux"] = FieldSet(Field[Field(0.0, 0.0), Field(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 = DC2D4(element)
la = initialize_local_assembly()
calculate_local_assembly!(la, equation, "temperature")
fdofs = [1, 2]
A = la.stiffness_matrix
b = la.force_vector
@fact A[fdofs, fdofs] \ b[fdofs] --> roughly([1.0, 1.0])
# 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);
calculate_local_assembly!(la, boundary_equation, "temperature")
b = la.force_vector
@fact A[fdofs, fdofs] \ b[fdofs] --> roughly([1.0, 1.0])
end
+9 -20
View File
@@ -4,28 +4,17 @@
using JuliaFEM: get_basis, grad, FieldSet, Field, Quad4
using FactCheck
element = Quad4([1, 2, 3, 4])
geometry_field = Field(0.0, Vector[]) # Create empty field at time t=0.0
push!(geometry_field, [ 0.0, 0.0]) # push some values for field
push!(geometry_field, [ 1.0, 0.0])
push!(geometry_field, [ 1.0, 1.0])
push!(geometry_field, [ 0.0, 1.0])
geometry_fieldset = FieldSet("geometry") # create fieldset "geometry"
push!(geometry_fieldset, geometry_field) # add field to fieldset
push!(element, geometry_fieldset) # add fieldset to element
temperature_fieldset = FieldSet("temperature")
push!(temperature_fieldset, Field(0.0, [0.0, 0.0, 0.0, 0.0]))
push!(temperature_fieldset, Field(1.0, [1.0, 2.0, 3.0, 4.0]))
push!(element, temperature_fieldset)
displacement_fieldset = FieldSet("displacement")
push!(displacement_fieldset, Field(0.0, Vector[[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]))
push!(displacement_fieldset, Field(1.0, Vector[[0.0, 0.0], [0.0, 0.0], [0.25, 0.0], [0.0, 0.0]]))
push!(element, displacement_fieldset)
facts("basic continuum interpolations") do
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"] = ([0.0, 0.0, 0.0, 0.0], [1.0, 2.0, 3.0, 4.0])
element["displacement"] = (
Vector[[0.0, 0.0], [0.0, 0.0], [0.00, 0.0], [0.0, 0.0]],
Vector[[0.0, 0.0], [0.0, 0.0], [0.25, 0.0], [0.0, 0.0]])
# from my old home works
basis = get_basis(element)
dbasis = grad(basis)
+71
View File
@@ -0,0 +1,71 @@
# This file is a part of JuliaFEM.
# License is MIT: see https://github.com/JuliaFEM/JuliaFEM.jl/blob/master/LICENSE.md
# test SimpleSolver
using FactCheck
using JuliaFEM: DirichletProblem, Seg2, PlaneHeatProblem, Quad4, SimpleSolver, get_element, get_basis
""" Define Problem 1:
- Field function: Laplace equation Δu=0 in Ω={u∈R²|(x,y)∈[0,1]×[0,1]}
- Neumann boundary on Γ₁={0<=x<=1, y=0}, ∂u/∂n=600 on Γ₁
"""
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)
problem1 = PlaneHeatProblem()
push!(problem1, el1)
push!(problem1, el2)
return problem1
end
""" Define Problem 2:
- Dirichlet boundary Γ₂={0<=x<=1, y=1}, u=0 on Γ₂
"""
function get_boundaryproblem()
el3 = Seg2([3, 4])
el3["geometry"] = Vector[[1.0, 1.0], [0.0, 1.0]]
problem2 = DirichletProblem(1)
push!(problem2, el3)
return problem2
end
facts("test simplesolver") do
problem1 = get_heatproblem()
problem2 = get_boundaryproblem()
# Create a solver for a set of problems
solver = SimpleSolver()
push!(solver, problem1)
push!(solver, problem2)
# Solve problem at time t=1.0 and update fields
call(solver, 1.0)
# Postprocess.
# Interpolate temperature field along boundary of Γ₁ at time t=1.0
xi = [0.0, -1.0]
el2 = get_element(problem1.equations[2])
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)
end