Skip to content
Snippets Groups Projects
Commit 5eb62cf6 authored by Stephan Hilb's avatar Stephan Hilb
Browse files

add support for array-valued functions

parent ff925638
No related branches found
No related tags found
No related merge requests found
using Statistics: mean using Statistics: mean
export Mapper, FeFunction, P1, DP0, DP1, interpolate! export Mapper, FeFunction, P1, DP0, DP1, interpolate!
# Finite Elements
struct P1 end struct P1 end
struct DP0 end struct DP0 end
struct DP1 end struct DP1 end
struct Mapper{T} # Fe: finite element type
struct Mapper{Fe}
mesh mesh
ndofs::Int ndofs::Int
map::Array{Int, 2} map::Array{Int, 2} # (ldof, cid) -> gdof
end end
# dof ordering for vector valued functions:
# (ldof, fdims...)
struct FeFunction struct FeFunction
mapper::Mapper mapper::Mapper
data::Vector{Float64} size::NTuple
data::Array{Float64, 2} # (rdim, gdof) -> data
name::String name::String
end end
function FeFunction(mapper, name=string(gensym("f"))) function FeFunction(mapper, size=(1,); name=string(gensym("f")))
data = Vector{Float64}(undef, mapper.ndofs) data = Array{Float64, 2}(undef, prod(size), mapper.ndofs)
return FeFunction(mapper, data, name) return FeFunction(mapper, size, data, name)
end end
# P1 Elements (1st order Lagrange) # P1 Elements (1st order Lagrange)
...@@ -50,11 +56,8 @@ function interpolate!(dst::FeFunction, mapper::Mapper{P1}, src::Function) ...@@ -50,11 +56,8 @@ function interpolate!(dst::FeFunction, mapper::Mapper{P1}, src::Function)
xid = mesh.cells[ldof, cid] xid = mesh.cells[ldof, cid]
x = mesh.vertices[:, xid] x = mesh.vertices[:, xid]
# currently scalar
fx = src(x)
gdof = mapper.map[ldof, cid] gdof = mapper.map[ldof, cid]
dst.data[gdof] = fx dst.data[:, gdof] .= vec(src(x))
end end
end end
end end
...@@ -65,23 +68,17 @@ function interpolate!(dst::FeFunction, mapper::Mapper{DP0}, src::Function) ...@@ -65,23 +68,17 @@ function interpolate!(dst::FeFunction, mapper::Mapper{DP0}, src::Function)
vertices = mesh.vertices[:, mesh.cells[:, cid]] vertices = mesh.vertices[:, mesh.cells[:, cid]]
centroid = mean(vertices, dims=2) centroid = mean(vertices, dims=2)
fx = src(centroid)
gdof = mapper.map[1, cid] gdof = mapper.map[1, cid]
dst.data[gdof] = fx dst.data[:, gdof] .= vec(src(centroid))
end end
end end
append_data!(vtkfile, f::FeFunction) = append_data!(vtkfile, f, f.mapper) append_data!(vtkfile, f::FeFunction) = append_data!(vtkfile, f, f.mapper)
function append_data!(vtkfile, f::FeFunction, ::Mapper{P1}) function append_data!(vtkfile, f::FeFunction, ::Mapper{P1})
# FIXME: vector-valued data vtk_point_data(vtkfile, f.data, f.name)
fdata = reshape(f.data, 1, :)
vtk_point_data(vtkfile, fdata, f.name)
end end
function append_data!(vtkfile, f::FeFunction, ::Mapper{DP0}) function append_data!(vtkfile, f::FeFunction, ::Mapper{DP0})
# FIXME: vector-valued data vtk_cell_data(vtkfile, f.data, f.name)
fdata = reshape(f.data, 1, :)
vtk_cell_data(vtkfile, fdata, f.name)
end end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment