mirror of
https://github.com/JuliaFEM/JuliaFEM.jl.git
synced 2026-08-06 04:21:33 +00:00
Add new method to set properties for problem
``` update!(body.properties, "a" => "b", "c" => "d") ``` Usage example is shown in `test_elasticity_2d_linear_with_surface_load.jl`.
This commit is contained in:
@@ -141,6 +141,24 @@ function get_assembly(problem)
|
||||
return problem.assembly
|
||||
end
|
||||
|
||||
"""
|
||||
update!(problem.properties, attr...)
|
||||
|
||||
Update properties for a problem.
|
||||
|
||||
# Example
|
||||
|
||||
```julia
|
||||
update!(body.properties, "finite_strain" => "false")
|
||||
```
|
||||
"""
|
||||
function update!{P<:AbstractProblem}(problem::P, attr::Pair{String, String}...)
|
||||
for (name, value) in attr
|
||||
debug("$P: set $name to $value")
|
||||
setfield!(problem, parse(name), parse(value))
|
||||
end
|
||||
end
|
||||
|
||||
""" Initialize element ready for calculation. """
|
||||
function initialize!(problem::Problem, element::Element, time::Float64)
|
||||
field_name = get_unknown_field_name(problem)
|
||||
|
||||
@@ -1,52 +1,46 @@
|
||||
# This file is a part of JuliaFEM.
|
||||
# License is MIT: see https://github.com/JuliaFEM/JuliaFEM.jl/blob/master/LICENSE.md
|
||||
|
||||
using Base.Test
|
||||
using JuliaFEM
|
||||
using JuliaFEM.Preprocess
|
||||
using JuliaFEM.Postprocess
|
||||
using JuliaFEM.Testing
|
||||
|
||||
#=
|
||||
- solve 2d plane stress problem with known solution:
|
||||
surface traction force in 2d
|
||||
volume load in 2d
|
||||
=#
|
||||
@testset "test 2d linear elasticity with surface + volume load" begin
|
||||
meshfile = "/geometry/2d_block/BLOCK_1elem.med"
|
||||
mesh = aster_read_mesh(dirname(@__DIR__)*meshfile)
|
||||
@testset "2d linear elasticity + volume load + surface load" begin
|
||||
|
||||
X = Dict(1 => [0.0, 0.0],
|
||||
2 => [1.0, 0.0],
|
||||
3 => [1.0, 1.0],
|
||||
4 => [0.0, 1.0])
|
||||
|
||||
props = ("formulation" => "plane_stress",
|
||||
"finite_strain" => "false",
|
||||
"geometric_stiffness" => "false")
|
||||
|
||||
# field problem
|
||||
block = Problem(Elasticity, "BLOCK", 2)
|
||||
block.properties.formulation = :plane_stress
|
||||
block.properties.finite_strain = false
|
||||
block.properties.geometric_stiffness = false
|
||||
block.elements = create_elements(mesh, "BLOCK")
|
||||
block.elements = [Element(Quad4, [1, 2, 3, 4])]
|
||||
update!(block.properties, props...)
|
||||
update!(block.elements, "geometry", X)
|
||||
update!(block.elements, "youngs modulus", 288.0)
|
||||
update!(block.elements, "poissons ratio", 1/3)
|
||||
update!(block.elements, "displacement load 2", 576.0)
|
||||
|
||||
# traction
|
||||
traction = Problem(Elasticity, "TRACTION", 2)
|
||||
traction.properties.formulation = :plane_stress
|
||||
traction.properties.finite_strain = false
|
||||
traction.properties.geometric_stiffness = false
|
||||
traction.elements = create_elements(mesh, "TOP")
|
||||
update!(traction, "displacement traction force 2", 288.0)
|
||||
traction.elements = [Element(Seg2, [3, 4])]
|
||||
update!(traction.properties, props...)
|
||||
update!(traction.elements, "geometry", X)
|
||||
update!(traction.elements, "displacement traction force 2", 288.0)
|
||||
|
||||
# boundary conditions
|
||||
bc_sym_23 = Problem(Dirichlet, "symmetry bc 23", 2, "displacement")
|
||||
bc_sym_23.elements = create_elements(mesh, "LEFT")
|
||||
update!(bc_sym_23, "displacement 1", 0.0)
|
||||
bc_sym_13 = Problem(Dirichlet, "symmetry bc 13", 2, "displacement")
|
||||
bc_sym_13.elements = create_elements(mesh, "BOTTOM")
|
||||
update!(bc_sym_13, "displacement 2", 0.0)
|
||||
bc = Problem(Dirichlet, "symmetry boundary conditions", 2, "displacement")
|
||||
bc.elements = [Element(Seg2, [1, 2]), Element(Seg2, [4, 1])]
|
||||
update!(bc.elements, "geometry", X)
|
||||
update!(bc.elements[1], "displacement 2", 0.0)
|
||||
update!(bc.elements[2], "displacement 1", 0.0)
|
||||
|
||||
solver = Solver(Linear, block, traction, bc_sym_23, bc_sym_13)
|
||||
solver = Solver(Linear, block, traction, bc)
|
||||
solver()
|
||||
|
||||
info("u = ", block.assembly.u)
|
||||
info("λ = ", block.assembly.la)
|
||||
|
||||
f = 288.0
|
||||
g = 576.0
|
||||
E = 288.0
|
||||
|
||||
Reference in New Issue
Block a user