mirror of
https://github.com/JuliaFEM/JuliaFEM.jl.git
synced 2026-08-18 19:30:10 +00:00
Api test working, starting iteration #2
This commit is contained in:
+18
-5
@@ -1,15 +1,28 @@
|
||||
# This file is a part of JuliaFEM.
|
||||
# License is MIT: see https://github.com/JuliaFEM/JuliaFEM.jl/blob/master/LICENSE.md
|
||||
|
||||
function add_boundary_condition!{P<:APIProblem}(case::LoadCase{P}, bc)
|
||||
push!(case.boundary_conditions, bc)
|
||||
function add_boundary_condition!(case::LoadCase, bc::NeumannBC)
|
||||
push!(case.neumann_boundary_conditions, bc)
|
||||
end
|
||||
|
||||
function add_solver!{P<:APIProblem, S<:APISolver}(case::LoadCase{P},
|
||||
bc::Type{S})
|
||||
case.solver = bc
|
||||
|
||||
function add_boundary_condition!(case::LoadCase, bc::DirichletBC)
|
||||
push!(case.dirichlet_boundary_conditions, bc)
|
||||
end
|
||||
|
||||
function add_solver!(case::LoadCase, solver)
|
||||
case.solver = solver
|
||||
end
|
||||
|
||||
function add_material!(model::Model, set_name::ASCIIString, material::Material)
|
||||
element_set = model.elsets[set_name]
|
||||
set_ids = element_set.elements
|
||||
for each in set_ids
|
||||
element = model.elements[each]
|
||||
element.material = material
|
||||
end
|
||||
element_set.material = material
|
||||
end
|
||||
#function Base.convert{T<:AbstractFloat}(::Type{Node}, data::Vector{T})
|
||||
# Node(data)
|
||||
#end:q
|
||||
|
||||
+15
-59
@@ -1,24 +1,6 @@
|
||||
# This file is a part of JuliaFEM.
|
||||
# License is MIT: see https://github.com/JuliaFEM/JuliaFEM.jl/blob/master/LICENSE.md
|
||||
|
||||
#abstract APIType
|
||||
#
|
||||
#abstract Mesh <: APIType
|
||||
#abstract APIElement <: Mesh
|
||||
#abstract APINode <: Mesh
|
||||
#
|
||||
#abstract APIProblem <: APIType
|
||||
#abstract HeatProblem <: APIProblem
|
||||
#abstract ElasticityProblem <: APIProblem
|
||||
#
|
||||
#abstract APISolver <: APIType
|
||||
#abstract SolverLinear <: APISolver
|
||||
# define these
|
||||
#abstract Problem
|
||||
#abstract Element
|
||||
|
||||
#abstract BoundaryCondition
|
||||
|
||||
type NeumannBC
|
||||
set_name :: ASCIIString
|
||||
value :: Any
|
||||
@@ -51,7 +33,7 @@ function Base.setindex!{T <: AbstractString }(material::Material, val::Real, nam
|
||||
end
|
||||
|
||||
|
||||
type Node{T<:Real} <: APINode
|
||||
type Node{T<:Real}
|
||||
id :: Union{Integer, ASCIIString}
|
||||
coords :: Array{T, 1}
|
||||
end
|
||||
@@ -60,29 +42,11 @@ type Element
|
||||
id :: Union{Integer, ASCIIString, Void}
|
||||
connectivity :: Vector{Int64}
|
||||
element_type :: Symbol
|
||||
fields :: Any # Dict{}
|
||||
results :: Any # Dict{}
|
||||
material :: Any
|
||||
end
|
||||
|
||||
#Element{I<:Integer}(eltype::Symbol, conn::Vector{I}) = Element(
|
||||
# nothing,
|
||||
# conn,
|
||||
# eltype )
|
||||
#
|
||||
#Element{I<:Integer}(conn::Vector{I}, eltype::ASCIIString) = Element(
|
||||
# nothing,
|
||||
# conn,
|
||||
# eltype)
|
||||
|
||||
#"""
|
||||
#Set of nodes. Holds name and the ids
|
||||
#"""
|
||||
#type NodeSet}
|
||||
# name :: AbstractString
|
||||
# node_ids :: Array{Integer, 1}
|
||||
#end
|
||||
|
||||
# NodeSet(arr::Array{Int64, 1}) = myn(arr, Dict(zip(arr, collect(1:length(arr)))))
|
||||
|
||||
Element(a, b, c) = Element(a, b, c, nothing, Material())
|
||||
|
||||
"""
|
||||
"""
|
||||
@@ -90,7 +54,7 @@ type ElementSet
|
||||
name :: ASCIIString
|
||||
elements :: Vector{Int64}
|
||||
material :: Material
|
||||
end#
|
||||
end
|
||||
|
||||
ElementSet(name::ASCIIString, elements::Vector{Element}) =
|
||||
ElementSet(name, map(x-> x.id, elements), Material())
|
||||
@@ -98,17 +62,19 @@ ElementSet(name::ASCIIString, elements::Vector{Element}) =
|
||||
ElementSet(name::ASCIIString, ids::Vector{Int64}) =
|
||||
ElementSet(name, ids, Material())
|
||||
|
||||
type LoadCase{ P <: APIProblem }
|
||||
problem :: Type{P}
|
||||
boundary_conditions #:: Vector{Union{NeumannBC, DirichletBC}}
|
||||
"""
|
||||
LoadCase
|
||||
"""
|
||||
type LoadCase
|
||||
problem :: Symbol
|
||||
neumann_boundary_conditions :: Vector{NeumannBC}
|
||||
dirichlet_boundary_conditions :: Vector{DirichletBC}
|
||||
solver
|
||||
sets
|
||||
end
|
||||
|
||||
#LoadCase{P <: APIProblem}(a :: P) = LoadCase(a, Vector{Union{NeumannBC,DirichletBC}}())
|
||||
LoadCase(a) = LoadCase(a, [], nothing)
|
||||
#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))
|
||||
LoadCase(a) = LoadCase(a, NeumannBC[], DirichletBC[], nothing, nothing)
|
||||
|
||||
|
||||
"""
|
||||
"""
|
||||
@@ -120,7 +86,6 @@ type Model
|
||||
nsets
|
||||
load_cases
|
||||
#settings :: Dict{AbstractString, Real}
|
||||
#results
|
||||
end
|
||||
|
||||
Model(name::ASCIIString, abq_input::Dict) = Model(
|
||||
@@ -145,12 +110,3 @@ Model(name::ASCIIString) = Model(
|
||||
# dicti[idx] = el
|
||||
# return dicti
|
||||
#end
|
||||
|
||||
#Model(name::ASCIIString) = Model(name,
|
||||
# Dict{Union{Int64, ASCIIString}, Node}(),
|
||||
# Dict{Union{Int64, ASCIIString}, Element}(),
|
||||
# Dict{AbstractString,
|
||||
# Union{NodeSet, ElementSet}}(),
|
||||
# LoadCase[],
|
||||
#)
|
||||
|
||||
|
||||
+58
-43
@@ -1,58 +1,73 @@
|
||||
# This file is a part of JuliaFEM.
|
||||
# License is MIT: see https://github.com/JuliaFEM/JuliaFEM.jl/blob/master/LICENSE.md
|
||||
using JuliaFEM
|
||||
using JuliaFEM.Core
|
||||
using JuliaFEM.API: Model
|
||||
|
||||
"""
|
||||
This needs this a bit honing ...
|
||||
"""
|
||||
function solve!(model::Model, case_name::ASCIIString, time::Float64)
|
||||
element_ids = keys(model.elements)
|
||||
all_eles = model.elements
|
||||
all_elements = model.elements
|
||||
case = model.load_cases[case_name]
|
||||
bcs = case.boundary_conditions
|
||||
neumann_bcs = case.neumann_boundary_conditions
|
||||
dirichlet_bcs = case.dirichlet_boundary_conditions
|
||||
nodes = model.nodes
|
||||
field_problem = JuliaFEM.Core.(case.problem)()
|
||||
core_elements = Dict()
|
||||
|
||||
# luodaan core elementit
|
||||
# for each in elements
|
||||
# end
|
||||
|
||||
# Lisätään Neumann:nin reunaehdot ja listään field probleemaan
|
||||
# for each in neumann
|
||||
# end
|
||||
|
||||
# lisätään Dirichlet:in reunaehdot ja lisätään reunaehtoon
|
||||
# for each in dirichlet
|
||||
# end
|
||||
#
|
||||
# SOLVE !
|
||||
|
||||
# Adding elements to field problem
|
||||
# for element in all_eles
|
||||
# el_type = element.element_type
|
||||
# el_id = element.id
|
||||
# mat = element.material
|
||||
# conn = element.connectivity
|
||||
# core_element = JuliaFEM.Core.(el_type)(conn)
|
||||
# core_element["geometry"] = map(x->nodes[x], conn)
|
||||
# for each in keys(mat)
|
||||
# core_element[each] = mat[each]
|
||||
# end
|
||||
# # TODO ! Lisätään Neumann:nin reunaehdot ennen kuin
|
||||
# # lisätään probleemaan
|
||||
# push!(field_problem, core_element)
|
||||
# model.elements[el_id].fields = core_element.fields
|
||||
# end
|
||||
# # käydaan läpi Dirichlet:in reunaehdot
|
||||
# for bc in bcs
|
||||
# elset_name = bc.set_name
|
||||
# elset = model.elsets[elset_name]
|
||||
# for element in elset.elements
|
||||
# element_id = element.id
|
||||
# el_type = element.element_type
|
||||
# core_element = JuliaFEM.Core.(el_type)(element.connectivity)
|
||||
#
|
||||
# model.elements[element_id].fields = core_element.fields
|
||||
# println(core_element)
|
||||
for el_id in element_ids
|
||||
element = all_elements[el_id]
|
||||
el_type = element.element_type
|
||||
el_id = element.id
|
||||
mat = element.material
|
||||
conn = element.connectivity
|
||||
core_element = JuliaFEM.Core.(el_type)(conn)
|
||||
core_element["geometry"] = map(x->nodes[x], conn)
|
||||
for each in keys(mat.scalar_data)
|
||||
core_element[each] = mat.scalar_data[each]
|
||||
end
|
||||
core_elements[el_id] = core_element
|
||||
model.elements[el_id].results = core_element
|
||||
end
|
||||
end
|
||||
|
||||
# # Lisätään Neumann:nin reunaehdot ja listään field probleemaan
|
||||
for each in neumann_bcs
|
||||
set_for_bc = each.set_name
|
||||
set_ids = model.elsets[set_for_bc]
|
||||
bc = each.value
|
||||
for el_id in set_ids.elements
|
||||
core_element = core_elements[el_id]
|
||||
core_element[bc[1]] = bc[2]
|
||||
end
|
||||
end
|
||||
dirile_arr = Any[]
|
||||
for each in dirichlet_bcs
|
||||
set_name = each.set_name
|
||||
value = each.value
|
||||
problem = JuliaFEM.Core.DirichletProblem(value[1], 1)
|
||||
set_for_bc = each.set_name
|
||||
set_ids = model.elsets[set_for_bc]
|
||||
bc = each.value
|
||||
for el_id in set_ids.elements
|
||||
core_element = core_elements[el_id]
|
||||
core_element[bc[1]] = bc[2]
|
||||
push!(problem, core_element)
|
||||
end
|
||||
push!(dirile_arr, problem)
|
||||
end
|
||||
element_set = case.sets
|
||||
el_ids = model.elsets[element_set].elements
|
||||
for each in el_ids
|
||||
push!(field_problem, core_elements[each])
|
||||
end
|
||||
solver = JuliaFEM.Core.(case.solver)(field_problem, dirile_arr[1])
|
||||
solver(1.0)
|
||||
|
||||
|
||||
end
|
||||
|
||||
function foo()
|
||||
return "bar"
|
||||
|
||||
+23
-13
@@ -3,10 +3,11 @@
|
||||
|
||||
module APITests
|
||||
|
||||
using JuliaFEM.Test
|
||||
|
||||
using JuliaFEM.Preprocess: parse_abaqus
|
||||
using JuliaFEM.API: Model, Element, ElementSet, Material, LoadCase,
|
||||
HeatConduction, DirichletBC, NeumannBC, SolverLinear,
|
||||
add_boundary_condition!, add_solver!
|
||||
DirichletBC, NeumannBC, add_boundary_condition!, add_solver!, add_material!
|
||||
using JuliaFEM.Interfaces: solve!
|
||||
|
||||
|
||||
@@ -22,30 +23,37 @@ function test_basic()
|
||||
# create elements
|
||||
e1 = Element(1, [1, 2, 3, 4], :Quad4)
|
||||
e2 = Element(2, [1, 2], :Seg2)
|
||||
e3 = Element(3, [3, 4], :Seg2)
|
||||
model.elements[1] = e1
|
||||
model.elements[2] = e2
|
||||
model.elements[3] = e3
|
||||
|
||||
|
||||
# element set
|
||||
elset = ElementSet("body", [e1, e2])
|
||||
elset2 = ElementSet("boundary", [1])
|
||||
elset2 = ElementSet("heat_flux", [e2])
|
||||
elset3 = ElementSet("constant_temp", [e3])
|
||||
elset4 = ElementSet("set_material", [e1])
|
||||
|
||||
model.elsets["body"] = elset
|
||||
model.elsets["boundary"] = elset2
|
||||
model.elsets["heat_flux"] = elset2
|
||||
model.elsets["constant_temp"] = elset3
|
||||
model.elsets["set_material"] = elset4
|
||||
|
||||
# material properties
|
||||
material = Material("MatMat")
|
||||
material["temperature thermal conductivity"] = 6.0
|
||||
material["density"] = 36.0
|
||||
elset.material = material
|
||||
add_material!(model, "set_material", material)
|
||||
|
||||
# Create problem
|
||||
field_problem = LoadCase(HeatConduction)
|
||||
field_problem = LoadCase(:HeatProblem)
|
||||
field_problem.sets = "body"
|
||||
|
||||
# boundary conditions
|
||||
bc = DirichletBC("body", "temperature" => 0.0)
|
||||
ne = NeumannBC("boundary", "temperature flux" => ((0.0 => 0.0),
|
||||
(1.0=>600.0)))
|
||||
bc = DirichletBC("constant_temp", "temperature" => 0.0)
|
||||
ne = NeumannBC("heat_flux", "temperature flux" => ((0.0 => 0.0),
|
||||
(1.0 => 600.0)))
|
||||
|
||||
# LoadCase
|
||||
add_boundary_condition!(field_problem, bc)
|
||||
@@ -58,10 +66,12 @@ function test_basic()
|
||||
model.load_cases["Heat problem"] = field_problem
|
||||
|
||||
# Solve problem
|
||||
results = solve(model, "Heat problem", 1.0)
|
||||
# xi = [0.0, -1.0]
|
||||
# T = el1("temperature", xi, 1.0)
|
||||
# T = model("temperature", [0.5, 0.0], 1)
|
||||
solve!(model, "Heat problem", 1.0)
|
||||
xi = [0.0, -1.0]
|
||||
T = model.elements[1].results("temperature", xi, 1.0)
|
||||
X = model.elements[2].results("geometry", xi, 1.0)
|
||||
info("Temperature at point X = $X is T = $T")
|
||||
@test isapprox(T, 100.0)
|
||||
end
|
||||
|
||||
function test_piston_8789()
|
||||
|
||||
Reference in New Issue
Block a user