In [1]:
include("../src/HPFEM.jl")


Out[1]:
HPFEM

In [2]:
nel = 10
nnodes = nel + 1
idir = [1,nnodes]
M = 5
Q = M+2
bas = HPFEM.Basis1d(M,Q)
lmap = HPFEM.locmap(bas)
dof = HPFEM.DofMap1d(lmap, nnodes, idir);

In [3]:
uexact(x) = sin(x)
rhsfun(x) = 2*sin(x)


Out[3]:
rhsfun (generic function with 1 method)

In [4]:
a = 1.0
b = 15.0
nodes = collect(linspace(a, b, nnodes));

In [5]:
elems = [HPFEM.Element1d(e, nodes[e], nodes[e+1], bas) for e = 1:nel];

In [6]:
solver = HPFEM.CholeskySC(dof, HPFEM.BBSymTri);

In [7]:
for e = 1:nel
    Ae = zeros(M, M)
    HPFEM.add_stiff_matrix!(bas, elems[e], Ae)
    HPFEM.add_mass_matrix!(bas, elems[e], Ae)
    HPFEM.add_local_matrix(solver, e, Ae)
end

In [8]:
Fe = zeros(HPFEM.nmodes(lmap), nel)

for e = 1:nel
    fe = rhsfun(elems[e].x)
    HPFEM.add_rhs!(bas, elems[e], fe, sub(Fe, :, e))
end

# Apply Dirichilet BCs:
Fe[1,1] = uexact(a);
Fe[2,nel] = uexact(b);

In [9]:
HPFEM.solve!(solver, Fe);

In [10]:
 = 101
ξ = collect(linspace(-1,1,));
ϕ = zeros(, M)
for i = 1:M
    ϕ[:,i] = bas(ξ, i)
end

Ue = ϕ * Fe;

In [11]:
using PyPlot
maxerr = 0.0
for e = 1:nel
    el = elems[e]
    x = (1-ξ)*el.a/2 + (1+ξ)*el.b/2 
    uu = uexact(x)
    err = maxabs(uu-Ue[:,e])
    if err > maxerr maxerr = err end
        
    plot(x, Ue[:,e], "r", x, uu, "b")
end
maxerr


Out[11]:
0.00012751287452419935

In [ ]: