Uploading ex6

This commit is contained in:
Georg Thomas Mandl 2026-01-14 18:42:17 +01:00
commit a2769c0417
4 changed files with 78 additions and 0 deletions

18
Sheet_6/adapt_h.m Normal file
View file

@ -0,0 +1,18 @@
% h-adaptivity
% for a given mesh and solution we generate a new adapted mesh by splitting
% the elements with large errors into two new elements
function mesh = adapt_h(nodes,u,lambda)
n_nodes = length(nodes);
flux_jumps = jumps_flux(nodes,u,lambda);
alpha = 0.5; % parameter for choosing elements to refine
crit_error = alpha*max(abs(flux_jumps));
mesh = nodes; % will be the new nodes/mesh
% finding elements to refine
for i=2:n_nodes-1
if abs(flux_jumps(i)) > crit_error
mesh = [mesh, nodes(i-1)+(nodes(i)-nodes(i-1))/2, nodes(i)+(nodes(i+1)-nodes(i))/2];
end
end
mesh = unique(mesh);
end