Files
JuliaFEM.jl/src/api.jl
T

201 lines
4.3 KiB
Julia
Raw Normal View History

2015-11-28 13:02:56 +02:00
# This file is a part of JuliaFEM.
# License is MIT: see https://github.com/JuliaFEM/JuliaFEM.jl/blob/master/LICENSE.md
2015-11-29 19:59:47 +02:00
abstract BoundaryCondition
2015-11-30 18:45:05 +02:00
type NeumannBC{ S <: AbstractString} <: BoundaryCondition
definition :: S
value :: Any
set_name :: S
2015-11-29 19:59:47 +02:00
end
2015-11-30 18:45:05 +02:00
type DirichletBC{ S <: AbstractString } <: BoundaryCondition
definition :: S
value :: Any
set_name :: S
2015-11-29 19:59:47 +02:00
end
typealias DisplacementBC DirichletBC
typealias TemperatureBC DirichletBC
2015-11-29 19:59:47 +02:00
typealias ForceBC NeumannBC
typealias HeatFluxBC NeumannBC
"""
"""
type Material{S <: AbstractString, T<:Real}
2015-11-29 14:38:04 +02:00
name :: AbstractString
scalar_data :: Dict{S, T}
end
Material(name, data) = Material(name, Dict(data))
Material(name) = Material(name, Dict{AbstractString, Real}())
Material() = Material("", Dict{AbstractString, Real}())
function Base.setindex!{T <: AbstractString }(material::Material, val::Real, name::T)
material.scalar_data[name] = val
2015-11-29 14:38:04 +02:00
end
2015-11-28 13:02:56 +02:00
2015-11-29 19:59:47 +02:00
"""
"""
type Node{T<:Real}
2015-11-28 13:02:56 +02:00
id::Integer
coords::Array{T, 1}
end
2015-11-29 19:59:47 +02:00
#"""
#"""
#type MElement{I <: Integer} #, T <: AbstractElement}
# id :: Integer
# connectivity :: Array{I, 1}
# element_type :: Tet4
#end
"""
Set of nodes. Holds name and the ids
2015-11-29 19:59:47 +02:00
"""
type NodeSet
name :: AbstractString
node_ids :: Array{Integer, 1}
2015-11-28 13:02:56 +02:00
end
#julia> type myn
# arr :: Array{Integer, 1}
# finder :: Dict{Integer, Integer}
# end
#
#julia> myn(arr::Array{Int64, 1}) = myn(arr, Dict(zip(arr, collect(1:length(arr)))))
2015-11-29 19:59:47 +02:00
"""
"""
type ElementSet
2015-11-29 14:38:04 +02:00
name :: AbstractString
element_ids :: Array{Integer, 1}
material :: Material
2015-11-28 13:02:56 +02:00
end
ElementSet(name, el_ids) = ElementSet(name, el_ids, Material())
2015-11-30 18:45:05 +02:00
type LoadCase{ P <: Problem }
problem :: P
boundary_conditions :: Vector{Union{NeumannBC, DirichletBC}}
2015-11-29 14:38:04 +02:00
end
2015-11-30 18:45:05 +02:00
LoadCase{P <: Problem}(a :: P) = LoadCase(a, Vector{Union{NeumannBC,DirichletBC}}())
LoadCase{P <: Problem, B <: BoundaryCondition}(a :: P, b :: B) = LoadCase(a, Vector{Union{NeumannBC,DirichletBC}}([b]))
LoadCase{P <: Problem, B <: BoundaryCondition}(a :: P, b :: Vector{B}) =
LoadCase(a, Vector{Union{NeumannBC,DirichletBC}}(b))
2015-11-29 14:38:04 +02:00
2015-11-29 19:59:47 +02:00
"""
"""
type Model
nodes :: Vector{Node}
elements :: Vector{Element}
sets :: Dict{AbstractString, Union{NodeSet, ElementSet}}
load_cases :: Vector{LoadCase}
# settings :: Dict{AbstractString, Real}
2015-11-29 14:38:04 +02:00
end
2015-11-29 19:59:47 +02:00
Model() = Model(Node[],
Element[],
2015-11-30 18:45:05 +02:00
Dict{AbstractString,
Union{NodeSet, ElementSet}}(),
2015-11-29 19:59:47 +02:00
LoadCase[],
)
function set_material!{S <: AbstractString}(model::Model, material::Material, set_name::S)
model.sets[set_name].material = material
end
2015-11-29 14:38:04 +02:00
2015-11-30 18:45:05 +02:00
function get_element_set(model::Model, set_name::ASCIIString)
get_set = model.sets[set_name]
isa(get_set, ElementSet) ? get_set : err("Found set $(set_name)
but it is not a ElementSet. Check if you have used
dublicate set names.")
end
function add_boundary_condition!{B <: BoundaryCondition}(case::LoadCase, bc::B)
push!(case.boundary_conditions, bc)
end
function add_boundary_condition!{B <: BoundaryCondition}(case::LoadCase, bc::Vector{B})
map(x-> push!(case.boundary_conditions, x), bc)
end
function add_loadcase!(model::Model, case::LoadCase)
push!(model.load_cases, case)
end
function add_loadcase!{T<:LoadCase}(model::Model, case::Vector{T})
map(x-> push!(model.load_cases, x), case)
end
2015-11-29 19:59:47 +02:00
"""
"""
2015-11-29 14:38:04 +02:00
function build_core_elements()
end
2015-11-29 19:59:47 +02:00
"""
"""
2015-11-29 14:38:04 +02:00
function set_core_element_material()
end
2015-11-29 19:59:47 +02:00
"""
element_has_type( ::Type{Val{:C3D4}}) = Tet4
"""
2015-11-29 14:38:04 +02:00
function create_problems()
end
2015-11-29 19:59:47 +02:00
"""
"""
2015-11-29 14:38:04 +02:00
function add_problems!()
end
2015-11-29 19:59:47 +02:00
"""
Get set from model
2015-11-29 19:59:47 +02:00
"""
function get_set{S <: AbstractString}(model::Model, name::S)
try
return model.set[name]
catch
err("Given set: $(name) does not exist in Model")
end
end
"""
"""
function add_element!(model::Model, element::Element)
2015-11-29 19:59:47 +02:00
push!(model.elements, element)
end
"""
"""
function add_node!(model::Model, node::Node)
2015-11-29 19:59:47 +02:00
push!(model.nodes, node)
end
"""
"""
function add_set!(model::Model, set::Union{NodeSet, ElementSet})
2015-11-29 19:59:47 +02:00
model.sets[set.name] = set
end
function add_set!{S <: AbstractString}(model::Model, ::Type{Val{:NSET}},
name::S, ids::Vector{Integer})
new_set = NodeSet(name, ids)
add_set!(model, new_set)
end
function add_set!{S <: AbstractString}(model::Model, ::Type{Val{:ELSET}},
name::S, ids::Vector{Integer})
new_set = ElementSet(name, ids)
add_set!(model, new_set)
end