In [1]:
using Mesh, PyPlot, MeshPyPlot, FEMP1, AFEM


# Mesh refinement

In [2]:
v, t, b = squaremesh();
meshes = [];
R = 12;
for i = 1:R
Mesh.bisect!(v, t, b, IntSet([1]));
push!(meshes,(copy(v),copy(t)))
end
for i = 1:8
subplot(2,4,i)
(w,s) = meshes[i]
plotlines(plotdata(w,s)...,true,[0,0,0]);
end

In [3]:
for (i,(w,s)) ∈ enumerate(reverse(meshes))
plotlines(plotdata(w,s)...,true,[1.-i/R,i/R,0]);
end


# Uniform refinement

In [4]:
function unifref!(v, t, b, dmap, Nref)
Ndof = Float64[]
errest = Float64[]
u = Float64[]
for i = 1:Nref
bisect!(v, t, b)
ec = edgeconnectivity(t)
a, f = P0ones(length(t)), P0ones(length(t))
u = AFEM.solve(v, t, b, dmap, a, f)
Ni, ei = length(v), norm(residualerrorestimators(v, t, b, dmap, ec, a, f, u))
push!(Ndof, Ni)
push!(errest, ei)
end
return u, Ndof, errest
end

Out[4]:
unifref! (generic function with 1 method)
In [5]:
vsq,tsq,bsq = squaremesh(); dmapsq = fulldirichlet(bsq);
usq, Ndofsq, errestsq = unifref!(vsq, tsq, bsq, dmapsq, 7);
piecewiselinearsurf(plotdata(vsq,tsq)...,usq);

In [6]:
vsq,tsq,bsq = squaremesh(); dmapsq = fulldirichlet(bsq);
usq, Ndofsq, errestsq = unifref!(vsq, tsq, bsq, dmapsq, 16);
piecewiselinearplot(plotdata(vsq,tsq)...,usq);

In [7]:
vl,tl,bl = lshapemesh(); dmapl = fulldirichlet(bl);
ul, Ndofl, errestl = unifref!(vl, tl, bl, dmapl, 16);
piecewiselinearplot(plotdata(vl,tl)...,ul);

In [8]:
vsl,tsl,bsl = slitsquaremesh(); dmapsl = fulldirichlet(bsl);
usl, Ndofsl, errestsl = unifref!(vsl, tsl, bsl, dmapsl, 16);
piecewiselinearplot(plotdata(vsl,tsl)...,usl);