mirror of
https://github.com/JuliaFEM/JuliaFEM.jl.git
synced 2026-09-17 17:22:10 +00:00
Added a bit more functionality to api
This commit is contained in:
@@ -5,6 +5,12 @@ function add_boundary_condition!(case::LoadCase, bc::NeumannBC)
|
||||
push!(case.neumann_boundary_conditions, bc)
|
||||
end
|
||||
|
||||
function add_node!(model::Model, index::Union{Int64, ASCIIString},
|
||||
coords::Vector{Float64})
|
||||
node = Node(index, coords)
|
||||
model.nodes[index] = node
|
||||
end
|
||||
|
||||
|
||||
function add_boundary_condition!(case::LoadCase, bc::DirichletBC)
|
||||
push!(case.dirichlet_boundary_conditions, bc)
|
||||
@@ -23,6 +29,37 @@ function add_material!(model::Model, set_name::ASCIIString, material::Material)
|
||||
end
|
||||
element_set.material = material
|
||||
end
|
||||
|
||||
function add_element!(model::Model, idx::Union{Int64, ASCIIString},
|
||||
eltype::Symbol, node_ids::Vector{Int64})
|
||||
|
||||
element = Element(idx, node_ids, eltype)
|
||||
model.elements[idx] = element
|
||||
end
|
||||
|
||||
function add_element_set!(model::Model, elset::ElementSet)
|
||||
name = elset.name
|
||||
model.elsets[name] = elset
|
||||
end
|
||||
|
||||
function add_element_set!(model::Model, name::ASCIIString, ids::Vector{Int64})
|
||||
elset = ElementSet(name, ids)
|
||||
model.elsets[name] = elset
|
||||
end
|
||||
|
||||
function add_element_set!(model::Model, name::ASCIIString,
|
||||
elements::Vector{Element})
|
||||
elset = ElementSet(name, elements)
|
||||
model.elsets[name] = elset
|
||||
end
|
||||
|
||||
function add_element_set!(case::LoadCase, name::ASCIIString)
|
||||
push!(case.sets, name)
|
||||
end
|
||||
|
||||
function add_load_case!(model::Model, name::ASCIIString, case::LoadCase)
|
||||
model.load_cases[name] = case
|
||||
end
|
||||
#function Base.convert{T<:AbstractFloat}(::Type{Node}, data::Vector{T})
|
||||
# Node(data)
|
||||
#end:q
|
||||
|
||||
+29
-21
@@ -33,9 +33,9 @@ function Base.setindex!{T <: AbstractString }(material::Material, val::Real, nam
|
||||
end
|
||||
|
||||
|
||||
type Node{T<:Real}
|
||||
type Node
|
||||
id :: Union{Integer, ASCIIString}
|
||||
coords :: Array{T, 1}
|
||||
coords :: Array{Float64, 1}
|
||||
end
|
||||
|
||||
type Element
|
||||
@@ -48,11 +48,16 @@ end
|
||||
|
||||
Element(a, b, c) = Element(a, b, c, nothing, Material())
|
||||
|
||||
type NodeSet
|
||||
name :: ASCIIString
|
||||
nodes :: Vector{Int64}
|
||||
end
|
||||
|
||||
"""
|
||||
"""
|
||||
type ElementSet
|
||||
name :: ASCIIString
|
||||
elements :: Vector{Int64}
|
||||
elements :: Vector{Union{Int64, ASCIIString}}
|
||||
material :: Material
|
||||
end
|
||||
|
||||
@@ -70,21 +75,24 @@ type LoadCase
|
||||
neumann_boundary_conditions :: Vector{NeumannBC}
|
||||
dirichlet_boundary_conditions :: Vector{DirichletBC}
|
||||
solver
|
||||
sets
|
||||
sets :: Vector{ASCIIString}
|
||||
end
|
||||
|
||||
LoadCase(a) = LoadCase(a, NeumannBC[], DirichletBC[], nothing, nothing)
|
||||
LoadCase(a) = LoadCase(a, NeumannBC[], DirichletBC[], nothing, ASCIIString[])
|
||||
|
||||
|
||||
"""
|
||||
Model type
|
||||
|
||||
Used for constructing the calculation model
|
||||
"""
|
||||
type Model
|
||||
name
|
||||
nodes
|
||||
name :: ASCIIString
|
||||
nodes :: Dict{Union{Int64, ASCIIString}}
|
||||
elements :: Dict{Union{ASCIIString, Int64}, Element}
|
||||
elsets
|
||||
nsets
|
||||
load_cases
|
||||
elsets :: Dict{ASCIIString, ElementSet}
|
||||
nsets :: Dict{ASCIIString, NodeSet}
|
||||
load_cases :: Dict{ASCIIString, LoadCase}
|
||||
#settings :: Dict{AbstractString, Real}
|
||||
end
|
||||
|
||||
@@ -94,19 +102,19 @@ Model(name::ASCIIString, abq_input::Dict) = Model(
|
||||
abq_input["elements"],
|
||||
abq_input["elsets"],
|
||||
abq_input["nsets"],
|
||||
Dict())
|
||||
Dict{ASCIIString, LoadCase}())
|
||||
|
||||
Model(name::ASCIIString) = Model(
|
||||
name,
|
||||
Dict(),
|
||||
Dict{Union{ASCIIString, Int64}, Element}(),
|
||||
Dict(),
|
||||
Dict(),
|
||||
Dict(),
|
||||
Dict{Union{Int64, ASCIIString}, Node}(),
|
||||
Dict{Union{Int64, ASCIIString}, Element}(),
|
||||
Dict{ASCIIString, NodeSet}(),
|
||||
Dict{ASCIIString, ElementSet}(),
|
||||
Dict{ASCIIString, LoadCase}(),
|
||||
)
|
||||
|
||||
#function Base.setindex!(dicti::Dict{Union{ASCIIString, Int64}, Element}, el::Element, idx::Union{ASCIIString, Int64})
|
||||
# el.id = idx
|
||||
# dicti[idx] = el
|
||||
# return dicti
|
||||
#end
|
||||
function Base.setindex!(dict::Dict{Union{ASCIIString, Int64}, Node},
|
||||
vals::Vector{Float64}, idx::Union{ASCIIString, Int64})
|
||||
dict[idx] = Node(idx, vals)
|
||||
end
|
||||
|
||||
|
||||
+6
-5
@@ -25,7 +25,7 @@ function solve!(model::Model, case_name::ASCIIString, time::Float64)
|
||||
mat = element.material
|
||||
conn = element.connectivity
|
||||
core_element = JuliaFEM.Core.(el_type)(conn)
|
||||
core_element["geometry"] = map(x->nodes[x], conn)
|
||||
core_element["geometry"] = map(x->nodes[x].coords, conn)
|
||||
for each in keys(mat.scalar_data)
|
||||
core_element[each] = mat.scalar_data[each]
|
||||
end
|
||||
@@ -63,10 +63,11 @@ function solve!(model::Model, case_name::ASCIIString, time::Float64)
|
||||
end
|
||||
|
||||
# Push all the elements, where the field problem is solved into the field_problem
|
||||
element_set = case.sets
|
||||
el_ids = model.elsets[element_set].elements
|
||||
for each in el_ids
|
||||
push!(field_problem, core_elements[each])
|
||||
for element_set in case.sets
|
||||
el_ids = model.elsets[element_set].elements
|
||||
for each in el_ids
|
||||
push!(field_problem, core_elements[each])
|
||||
end
|
||||
end
|
||||
|
||||
# Creating the solver
|
||||
|
||||
+13
-14
@@ -7,7 +7,8 @@ using JuliaFEM.Test
|
||||
|
||||
using JuliaFEM.Preprocess: parse_abaqus
|
||||
using JuliaFEM.API: Model, Element, ElementSet, Material, LoadCase,
|
||||
DirichletBC, NeumannBC, add_boundary_condition!, add_solver!, add_material!
|
||||
DirichletBC, NeumannBC, add_boundary_condition!, add_solver!, add_material!,
|
||||
add_node!, add_element!, add_element_set!, add_load_case!
|
||||
using JuliaFEM.Interfaces: solve!
|
||||
|
||||
|
||||
@@ -15,9 +16,9 @@ function test_basic()
|
||||
# basic workflow, copied from test_solver.jl
|
||||
model = Model("Piston Calculation")
|
||||
|
||||
model.nodes[1] = [0.0, 0.0]
|
||||
add_node!(model, 1, [0.0, 0.0])
|
||||
model.nodes[2] = [1.0, 0.0]
|
||||
model.nodes[3] = [1.0, 1.0]
|
||||
add_node!(model, 3, [1.0, 1.0])
|
||||
model.nodes[4] = [0.0, 1.0]
|
||||
|
||||
# create elements
|
||||
@@ -26,29 +27,26 @@ function test_basic()
|
||||
e3 = Element(3, [3, 4], :Seg2)
|
||||
model.elements[1] = e1
|
||||
model.elements[2] = e2
|
||||
model.elements[3] = e3
|
||||
|
||||
add_element!(model, 3, :Seg2, [3, 4])
|
||||
|
||||
# element set
|
||||
elset = ElementSet("body", [e1, e2])
|
||||
elset2 = ElementSet("heat_flux", [e2])
|
||||
elset3 = ElementSet("constant_temp", [e3])
|
||||
elset4 = ElementSet("set_material", [e1])
|
||||
|
||||
model.elsets["body"] = elset
|
||||
model.elsets["heat_flux"] = elset2
|
||||
model.elsets["constant_temp"] = elset3
|
||||
model.elsets["set_material"] = elset4
|
||||
add_element_set!(model, "heat_flux", [2])
|
||||
add_element_set!(model, "constant_temp", [e3])
|
||||
add_element_set!(model, elset4)
|
||||
|
||||
# material properties
|
||||
material = Material("MatMat")
|
||||
material = Material("myMaterial")
|
||||
material["temperature thermal conductivity"] = 6.0
|
||||
material["density"] = 36.0
|
||||
add_material!(model, "set_material", material)
|
||||
|
||||
# Create problem
|
||||
field_problem = LoadCase(:HeatProblem)
|
||||
field_problem.sets = "body"
|
||||
add_element_set!(field_problem, "body") # is this necessary?
|
||||
|
||||
# boundary conditions
|
||||
bc = DirichletBC("constant_temp", "temperature" => 0.0)
|
||||
@@ -63,7 +61,8 @@ function test_basic()
|
||||
add_solver!(field_problem, :LinearSolver)
|
||||
|
||||
# add case
|
||||
model.load_cases["Heat problem"] = field_problem
|
||||
add_load_case!(model, "Heat problem", field_problem)
|
||||
#model.load_cases["Heat problem"] = field_problem
|
||||
|
||||
# Solve problem
|
||||
solve!(model, "Heat problem", 1.0)
|
||||
@@ -79,5 +78,5 @@ function test_piston_8789()
|
||||
|
||||
model = Model("Piston Calculation", abaqus_input)
|
||||
end
|
||||
test_basic()
|
||||
# test_basic()
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user