Files
JuliaFEM.jl/src/api.jl
T

217 lines
4.9 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-30 23:00:21 +02:00
# define these
abstract Problem
abstract Element
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
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
2015-11-30 20:03:28 +02:00
node_ids :: Array{Integer, 1}
2015-11-28 13:02:56 +02:00
end
2015-11-30 20:03:28 +02:00
# NodeSet(arr::Array{Int64, 1}) = myn(arr, Dict(zip(arr, collect(1:length(arr)))))
2015-11-29 19:59:47 +02:00
"""
"""
2015-11-30 21:50:09 +02:00
type ElementSet{E<:AbstractElement}
2015-11-29 14:38:04 +02:00
name :: AbstractString
material :: Material
2015-11-30 21:50:09 +02:00
elements :: Vector{E}
2015-11-28 13:02:56 +02:00
end
2015-11-30 21:50:09 +02:00
ElementSet{E<:AbstractElement}(name::ASCIIString, elements::E...) =
ElementSet(name,Material(), E[elements...])
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
2015-11-30 21:50:09 +02:00
name :: ASCIIString
nodes :: Dict{Union{Int64, ASCIIString}, Node}
elements :: Dict{Union{Int64, ASCIIString}, Element}
2015-11-29 19:59:47 +02:00
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-30 21:50:09 +02:00
Model(name::ASCIIString) = Model(name,
Dict{Union{Int64, ASCIIString}, Node}(),
Dict{Union{Int64, ASCIIString}, Element}(),
Dict{AbstractString,
Union{NodeSet, ElementSet}}(),
LoadCase[],
)
2015-11-30 21:50:09 +02:00
function Base.convert{T<:AbstractFloat}(::Type{Node}, data::Vector{T})
Node(data)
end
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
"""
"""
2015-11-30 21:50:09 +02:00
function push!(model::Model, element::Element)
2015-11-30 20:03:28 +02:00
push!(model.elements, element...)
2015-11-29 19:59:47 +02:00
end
"""
"""
2015-11-30 20:03:28 +02:00
function push!(model::Model, elements::Vector{Element})
push!(model.element, elements...)
end
"""
"""
2015-11-30 21:50:09 +02:00
function push!(model::Model, node::Node)
push!(model.nodes, node)
2015-11-30 20:03:28 +02:00
end
function push!(model::Model, nodes::Vector{Node})
push!(mode, nodes...)
2015-11-29 19:59:47 +02:00
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
2015-11-30 21:50:09 +02:00