Files
JuliaFEM.jl/test/test_api.jl
T

100 lines
2.9 KiB
Julia
Raw Normal View History

2015-11-30 19:11:00 +02:00
# This file is a part of JuliaFEM.
# License is MIT: see https://github.com/JuliaFEM/JuliaFEM.jl/blob/master/LICENSE.md
2016-06-19 20:01:37 +03:00
using JuliaFEM
using JuliaFEM.Preprocess
using JuliaFEM.API
using JuliaFEM.Interfaces
2015-12-01 20:21:54 +02:00
using JuliaFEM.Test
2016-07-03 21:16:03 +03:00
#= TODO: Fix test
2016-06-19 20:01:37 +03:00
@testset "test basic workflow" begin
2015-11-30 19:11:00 +02:00
# basic workflow, copied from test_solver.jl
2015-12-01 16:03:23 +02:00
model = Model("Piston Calculation")
2015-11-30 19:11:00 +02:00
2015-12-03 14:55:05 +02:00
add_node!(model, 1, [0.0, 0.0])
2015-11-30 21:50:09 +02:00
model.nodes[2] = [1.0, 0.0]
2015-12-03 14:55:05 +02:00
add_node!(model, 3, [1.0, 1.0])
2015-11-30 21:50:09 +02:00
model.nodes[4] = [0.0, 1.0]
2015-11-30 20:03:28 +02:00
2015-11-30 19:11:00 +02:00
# create elements
2015-12-01 16:03:23 +02:00
e1 = Element(1, [1, 2, 3, 4], :Quad4)
e2 = Element(2, [1, 2], :Seg2)
2015-12-01 20:21:54 +02:00
e3 = Element(3, [3, 4], :Seg2)
2015-12-01 16:03:23 +02:00
model.elements[1] = e1
model.elements[2] = e2
2015-12-03 14:55:05 +02:00
add_element!(model, 3, :Seg2, [3, 4])
2015-11-30 19:11:00 +02:00
2015-11-30 20:03:28 +02:00
# element set
2015-12-01 16:03:23 +02:00
elset = ElementSet("body", [e1, e2])
2015-12-01 20:21:54 +02:00
elset4 = ElementSet("set_material", [e1])
2015-12-01 16:03:23 +02:00
model.elsets["body"] = elset
2015-12-03 14:55:05 +02:00
add_element_set!(model, "heat_flux", [2])
add_element_set!(model, "constant_temp", [e3])
add_element_set!(model, elset4)
2015-11-30 20:03:28 +02:00
2015-11-30 19:11:00 +02:00
# material properties
2015-12-03 14:55:05 +02:00
material = Material("myMaterial")
2015-12-01 16:03:23 +02:00
material["temperature thermal conductivity"] = 6.0
material["density"] = 36.0
2015-12-01 20:21:54 +02:00
add_material!(model, "set_material", material)
2015-11-30 19:11:00 +02:00
2015-11-30 20:03:28 +02:00
# Create problem
2015-12-04 08:27:59 +02:00
field_problem = Simulation(:HeatProblem)
2015-12-03 14:55:05 +02:00
add_element_set!(field_problem, "body") # is this necessary?
2015-11-30 19:11:00 +02:00
# boundary conditions
2015-12-01 20:21:54 +02:00
bc = DirichletBC("constant_temp", "temperature" => 0.0)
ne = NeumannBC("heat_flux", "temperature flux" => ((0.0 => 0.0),
(1.0 => 600.0)))
2015-11-30 20:03:28 +02:00
# LoadCase
2015-12-01 16:03:23 +02:00
add_boundary_condition!(field_problem, bc)
add_boundary_condition!(field_problem, ne)
2015-11-30 20:03:28 +02:00
# Get solver
2015-12-01 16:03:23 +02:00
add_solver!(field_problem, :LinearSolver)
2015-11-30 20:03:28 +02:00
# add case
add_simulation!(model, "Heat problem", field_problem)
2015-12-03 14:55:05 +02:00
#model.load_cases["Heat problem"] = field_problem
2015-11-30 20:03:28 +02:00
# Solve problem
2015-12-01 20:21:54 +02:00
solve!(model, "Heat problem", 1.0)
xi = [0.0, -1.0]
T = model.elements[1].results("temperature", xi, 1.0)
X = model.elements[2].results("geometry", xi, 1.0)
info("Temperature at point X = $X is T = $T")
#@test isapprox(T, 200.0)
2015-11-30 19:11:00 +02:00
end
2016-07-03 21:16:03 +03:00
=#
2015-11-30 19:11:00 +02:00
2016-07-03 21:16:03 +03:00
#= TODO: Fix test
2016-06-19 20:01:37 +03:00
@testset "test reading piston model using API" begin
2015-12-03 15:39:02 +02:00
abaqus_input = open(parse_abaqus, "./geometry/piston/piston_8789_P1.inp")
2015-12-01 16:03:23 +02:00
model = Model("Piston Calculation", abaqus_input)
2015-12-03 15:39:02 +02:00
@test length(keys(model.elsets)) == 4
@test length(keys(model.nsets)) == 1
@test length(keys(model.elements)) == 37331
@test length(keys(model.nodes)) == 8789
2015-12-01 16:03:23 +02:00
end
2016-07-03 21:16:03 +03:00
=#
2015-12-03 16:57:45 +02:00
2016-07-03 21:16:03 +03:00
function test_piston_107168()
abaqus_input = open(parse_abaqus, "./geometry/piston/piston_107168_P2.inp")
model = Model("Piston Calculation", abaqus_input)
@test length(keys(model.elsets)) == 3
@test length(keys(model.nsets)) == 1
@test length(keys(model.elements)) == 65948
@test length(keys(model.nodes)) == 107168
end
function slow_test_something_that_takes_long_time()
info("This test is SLOW.")
2016-06-19 20:01:37 +03:00
test_piston_170168()
end
2015-12-03 16:57:45 +02:00