added heat equations.

This commit is contained in:
Jukka Aho
2015-09-14 16:15:36 +03:00
parent 4fb017e9d3
commit e4d9cbb6c9
3 changed files with 90 additions and 9 deletions
+21 -8
View File
@@ -135,7 +135,7 @@ end
Assign Lagrange basis for element.
"""
macro create_lagrange_basis(element_name, X, P)
# Logging.debug("Creating Lagrange basis for element ", element_name, ". ")
eltype = esc(element_name)
@@ -271,11 +271,14 @@ Notes
-----
This function assumes that element has field :geometry defined.
"""
function get_Jacobian(el::Element, xi)
dbasisdxi = get_dbasisdxi(el, xi)
X = get_field(el, :geometry)
J = X*dbasisdxi
return J
#function get_Jacobian(el::Element, xi)
# dbasisdxi = get_dbasisdxi(el, xi)
# X = get_field(el, :geometry)
# J = X*dbasisdxi
# return J
#end
function get_Jacobian(el::Element, xi, geometry_field=:geometry)
dinterpolate(el, geometry_field, xi)
end
"""
@@ -316,6 +319,16 @@ function set_field(el::Element, field_name, field_value)
el.fields[field_name] = field_value
end
""" Create new empty field of some type. """
function new_field(el::Element, field_name, field_type)
el.fields[field_name] = field_type[]
end
""" Push to existing field. """
function push_field!(el::Element, field_name, field_value)
push!(el.fields[field_name], field_value)
end
""" Get field variable. """
function get_field(el::Element, field_name)
el.fields[field_name]
@@ -355,10 +368,10 @@ function interpolate(el::Element, field, xis::Array{Vector, 1})
map(interpolate_, xis)
end
function dinterpolate(el::Element, field, xi::Vector)
field = get_field(el, field)
fld = get_field(el, field)
dbasis = get_dbasisdxi(el, xi)
if isa(dbasis, Vector)
return sum(dbasis .* field)
end
return sum([fld[i]*g[i,:] for i in 1:length(fld)])
return sum([fld[i]*dbasis[i,:] for i in 1:length(fld)])
end
+11 -1
View File
@@ -57,7 +57,7 @@ Integrate f over element
Parameters
----------
eq::Equation
f::Function
Function to integrate
"""
@@ -69,3 +69,13 @@ function integrate(eq::Equation, f::Function)
return sum(target)
end
function get_global_dofs(eq::Equation)
eq.global_dofs
end
function set_global_dofs(eq::Equation, dofs)
eq.global_dofs = dofs
end
# Equations for heat problems
include("heat_equations.jl")
+58
View File
@@ -0,0 +1,58 @@
# This file is a part of JuliaFEM.
# License is MIT: see https://github.com/JuliaFEM/JuliaFEM.jl/blob/master/LICENSE.md
abstract Heat <: Equation
"""
Diffusive heat transfer for 4-node bilinear element.
"""
type DC2D4 <: Heat
element :: Quad4
integration_points :: Array{IntegrationPoint, 1}
global_dofs :: Array{Int64, 1}
end
function DC2D4(el::Quad4)
integration_points = [
IntegrationPoint(1.0/sqrt(3.0)*[-1, -1], 1.0),
IntegrationPoint(1.0/sqrt(3.0)*[ 1, -1], 1.0),
IntegrationPoint(1.0/sqrt(3.0)*[ 1, 1], 1.0),
IntegrationPoint(1.0/sqrt(3.0)*[-1, 1], 1.0)]
set_field(el, :temperature, zeros(2, 4))
DC2D4(el, integration_points, [])
end
function get_lhs(eq::DC2D4)
function get_lhs_(eq, ip)
el = get_element(eq)
xi = ip.xi
dNdX = get_dbasisdX(el, xi)'
hc = interpolate(el, :"temperature heat coefficient", xi)
return dNdX'*hc*dNdX
end
integrate(eq, get_lhs_)
end
"""
Diffusive heat transfer for 2-node linear segment.
"""
type DC2D2 <: Heat
element :: Seg2
integration_points :: Array{IntegrationPoint, 1}
global_dofs :: Array{Int64, 1}
end
function DC2D2(el::Seg2)
integration_points = [IntegrationPoint([0.0], 1.0)]
set_field(el, :temperature, zeros(2, 1))
set_field(el, :"temperature flux", zeros(2, 1))
DC2D2(el, integration_points, [])
end
function get_rhs(eq::DC2D2)
function get_rhs_(eq, ip)
el = get_element(eq)
xi = ip.xi
N = get_basis(el, xi)
f = interpolate(el, :"temperature flux", xi)
return f*N
end
integrate(eq, get_rhs_)
end