📄 bisection.html
字号:
<span class="comment">% A new node is added to the mesh. Numerical solution at this</span> <span class="comment">% new added node is approximated by linear interpolation.</span> mesh.node(newNode,:) = ( mesh.node(mesh.elem(ct,2),:) + <span class="keyword">...</span> mesh.node(mesh.elem(ct,3),:) )/2; mesh.type(newNode) = 2; <span class="comment">% newNode is added by the refinement</span> mesh.solu(newNode) = ( mesh.solu(mesh.elem(ct,2)) + <span class="keyword">...</span> mesh.solu(mesh.elem(ct,3)) )/2; <span class="comment">% Find the element which shares the base edge of the current</span> <span class="comment">% element. If it is 0, it means the base of the current element</span> <span class="comment">% is on the boundary.</span> ct = dualEdge(mesh.elem(ct,3),mesh.elem(ct,2)); <span class="keyword">if</span> (ct==0), index=0; <span class="keyword">end</span> <span class="comment">% base is on the boundary</span> <span class="comment">% the while will ended if</span> <span class="comment">% 1. ct==0 means we are on the boundary</span> <span class="comment">% 2. base(ct) is already marked</span> <span class="keyword">end</span> <span class="keyword">end</span> <span class="comment">% end while for recursive marking</span><span class="keyword">end</span> <span class="comment">% end of for loop on all elements</span><span class="comment">% Detailed explanation of the algorithm can be found at</span><span class="comment">% Manual --> Algorithms --> Bisection</span><span class="comment">%--------------------------------------------------------------------------</span><span class="comment">% Refine marked edges for each triangle</span><span class="comment">%--------------------------------------------------------------------------</span><span class="keyword">for</span> t = 1:NT base = d2p(mesh.elem(t,2),mesh.elem(t,3)); <span class="keyword">if</span> (marker(base)>0) p = [mesh.elem(t,:), marker(base)]; [mesh,eta] = <a href="#_sub1" class="code" title="subfunction [mesh,eta] = divide(mesh,eta,t,p)">divide</a>(mesh,eta,t,p); left = d2p(p(1),p(2)); right = d2p(p(3),p(1)); <span class="keyword">if</span> (marker(right)>0) [mesh,eta] = <a href="#_sub1" class="code" title="subfunction [mesh,eta] = divide(mesh,eta,t,p)">divide</a>(mesh,eta,size(mesh.elem,1), <span class="keyword">...</span> [p(4),p(3),p(1),marker(right)]); <span class="keyword">end</span> <span class="keyword">if</span> (marker(left)>0) [mesh,eta] = <a href="#_sub1" class="code" title="subfunction [mesh,eta] = divide(mesh,eta,t,p)">divide</a>(mesh,eta,t,[p(4),p(1),p(2),marker(left)]); <span class="keyword">end</span> <span class="keyword">end</span> <span class="comment">% end of refinement of one element</span><span class="keyword">end</span> <span class="comment">% end of for loop on all elements</span><span class="comment">%--------------------------------------------------------------------------</span><span class="comment">% Update boundary edges</span><span class="comment">%--------------------------------------------------------------------------</span>mesh.Dirichlet = <a href="#_sub2" class="code" title="subfunction bdEdge = updatebd(bdEdge,marker,d2p)">updatebd</a>(mesh.Dirichlet,marker,d2p);mesh.Neumann = <a href="#_sub2" class="code" title="subfunction bdEdge = updatebd(bdEdge,marker,d2p)">updatebd</a>(mesh.Neumann,marker,d2p);<span class="comment">%--------------------------------------------------------------------------</span><span class="comment">% Plot refined mesh</span><span class="comment">%--------------------------------------------------------------------------</span>subplot(1,2,2); hold off; trisurf(mesh.elem,mesh.node(:,1),mesh.node(:,2),zeros(size(mesh.node,1),1));view(2), axis equal, axis off;title(<span class="string">'Mesh after refinement'</span>, <span class="string">'FontSize'</span>, 14)<span class="comment">%--------------------------------------------------------------------------</span><span class="comment">% End of function BISECTION</span><span class="comment">%--------------------------------------------------------------------------</span><span class="comment">%--------------------------------------------------------------------------</span><span class="comment">% Sub functions called by BISECTION</span><span class="comment">%--------------------------------------------------------------------------</span><a name="_sub1" href="#_subfunctions" class="code">function [mesh,eta] = divide(mesh,eta,t,p)</a><span class="comment">% DIVIDE divide triangle t into two triangels and update the error</span><span class="comment">% indicator at the same time.</span><span class="comment">%</span><span class="comment">% USAGE</span><span class="comment">% [mesh,eta] = divide(mesh,eta,t,p)</span><span class="comment">%</span><span class="comment">% INPUT</span><span class="comment">% mesh: current mesh</span><span class="comment">% eta: error indicator for each triangle</span><span class="comment">% t: triangle to be divided</span><span class="comment">% p: vertices of triangle t and new vertex</span><span class="comment">% p(1),p(2),p(3) are vertices of t</span><span class="comment">% p(4) new vertex which is opposite to p(1)</span><span class="comment">%</span><span class="comment">% OUTPUT</span><span class="comment">% mesh: new mesh</span><span class="comment">% eta: error indicator for each triangle</span><span class="comment">%</span><span class="comment">%--------------------------------------------------------------------------</span><span class="comment">% Add one element</span><span class="comment">%--------------------------------------------------------------------------</span>new = size(mesh.elem,1) + 1; <span class="comment">% append new element to the end of elem array</span>mesh.elem(t,:) = [p(4),p(1),p(2)]; <span class="comment">% t is always a left child</span>mesh.elem(new,:) = [p(4),p(3),p(1)]; <span class="comment">% new is a right child</span><span class="comment">% the newest vertex p(4) is the first vertex in each triangle</span>eta(new) = eta(t)/2; eta(t) = eta(t)/2; <span class="comment">% update error indicators</span><span class="comment">%--------------------------------------------------------------------------</span><span class="comment">% End of function DIVIDE</span><span class="comment">%--------------------------------------------------------------------------</span><a name="_sub2" href="#_subfunctions" class="code">function bdEdge = updatebd(bdEdge,marker,d2p)</a><span class="comment">% UPDATEDBD refine the boundary edges</span><span class="comment">%</span><span class="comment">% USAGE</span><span class="comment">% bdEdge = updatebd(bdEdge,marker,d2p)</span><span class="comment">%</span><span class="comment">% INPUT</span><span class="comment">% bdEdge: set of boundary edges</span><span class="comment">% marker: new node index for marked edge</span><span class="comment">% d2p: index mapping from dual edge to primary edge</span><span class="comment">%</span><span class="comment">% OUTPUT</span><span class="comment">% bdEdge: set of refined boundary edges</span><span class="comment">%</span>NB = size(bdEdge,1);<span class="keyword">for</span> k = 1:NB i = bdEdge(k,1); j = bdEdge(k,2); <span class="keyword">if</span> marker(d2p(i,j)) >0 bdEdge(k,:) = [i,marker(d2p(i,j))]; bdEdge(size(bdEdge,1)+1,:) = [marker(d2p(i,j)),j]; <span class="keyword">end</span><span class="keyword">end</span><span class="comment">%--------------------------------------------------------------------------</span><span class="comment">% End of function UPDATEDBD</span><span class="comment">%--------------------------------------------------------------------------</span></pre></div><hr><address>Generated on Thu 02-Nov-2006 17:03:56 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/" target="_parent">m2html</a></strong> © 2003</address></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -