Skip to content

Commit

Permalink
Initial implementation of material simulator.
Browse files Browse the repository at this point in the history
  • Loading branch information
jvaara committed Sep 15, 2018
1 parent 26b9ca5 commit 05ffd7a
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Materials.jl
Expand Up @@ -76,6 +76,9 @@ export integrate_material!
include("idealplastic.jl")
export IdealPlastic

include("simulator.jl")


# include("olli.jl") # to be uncommented when old code is fixed.

end
45 changes: 45 additions & 0 deletions src/simulator.jl
@@ -0,0 +1,45 @@
# This file is a part of JuliaFEM.
# License is MIT: see https://github.com/JuliaFEM/Materials.jl/blob/master/LICENSE

using Materials

mutable struct Simulator
stresses :: Vector{Vector{Float64}}
strains :: Vector{Vector{Float64}}
times :: Vector{Float64}
material :: Material{<:AbstractMaterial}
end

function Simulator(material)
return Simulator([],[],[],material)
end

function initialize!(simulator, strains, times)
simulator.strains = strains
simulator.times = times
return nothing
end

function run!(simulator)
material = simulator.material
times = simulator.times
strains = simulator.strains
t_n = times[1]
strain_n = strains[1]
push!(simulator.stresses, copy(material.stress))
for i in 2:length(times)
strain = strains[i]
t = times[i]
dstrain = strain - strain_n
dt = t - t_n
material.dstrain = dstrain
material.dtime = dt
integrate_material!(material)
material.stress[:] .+= material.dstress
material.strain[:] .+= material.dstrain
push!(simulator.stresses, copy(material.stress))
strain_n = strain
t_n = t
end
return nothing
end
4 changes: 4 additions & 0 deletions test/runtests.jl
Expand Up @@ -10,4 +10,8 @@ using FEMBase, Materials, Test
@testset "test ideal plastic material model" begin
include("test_idealplastic.jl")
end

@testset "test simulator" begin
include("test_simulator.jl")
end
end
38 changes: 38 additions & 0 deletions test/test_simulator.jl
@@ -0,0 +1,38 @@
# This file is a part of JuliaFEM.
# License is MIT: see https://github.com/JuliaFEM/Materials.jl/blob/master/LICENSE

using Materials, Test
using Materials: Simulator

m1 = 1.0e-3*[-0.3, -0.3, 1.0, 0.0, 0.0, 0.0]
m2 = 1.0e-3*[-0.5, -0.5, 1.0, 0.0, 0.0, 0.0]
mat = Material(IdealPlastic, ())
mat.properties.youngs_modulus = 200.0e3
mat.properties.poissons_ratio = 0.3
mat.properties.yield_stress = 100.0
mat.stress = zeros(6)
times = [0.0]
strains = [zeros(6)]
dt = 0.5
# Go to elastic border
push!(times, times[end]+dt)
push!(strains, strains[end] + m1*dt)

# Proceed to plastic flow
push!(times, times[end]+dt)
push!(strains, strains[end] + m2*dt)

# Reverse direction
push!(times, times[end]+dt)
push!(strains, strains[end] - m1*dt)

# Continue and pass yield criterion
push!(times, times[end]+dt)
push!(strains, strains[end] - (m1 + m2)*dt)

sim = Simulator(mat)
Materials.initialize!(sim, strains, times)
Materials.run!(sim)

s33s = [s[3] for s in sim.stresses]
@test isapprox(s33s, [0.0, 100.0, 100.0, 0.0, -100.0])

0 comments on commit 05ffd7a

Please sign in to comment.