⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 simple.html

📁 五点差分型多重网格方法:各种插值算子的比较)
💻 HTML
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"                "http://www.w3.org/TR/REC-html40/loose.dtd"><html><head>  <title>Description of simple</title>  <meta name="keywords" content="simple">  <meta name="description" content="SIMPLE solves Poisson equation with Dirichlet boundaray condition in a">  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">  <meta name="generator" content="m2html &copy; 2003 Guillaume Flandin">  <meta name="robots" content="index, follow">  <link type="text/css" rel="stylesheet" href="../../m2html.css"></head><body><a name="_top"></a><!-- # AFEM@matlab --><!-- menu.html 1_Example --><h1>simple</h1><h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2><div class="box"><strong>SIMPLE solves Poisson equation with Dirichlet boundaray condition in a</strong></div><h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2><div class="box"><strong>function simple </strong></div><h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2><div class="fragment"><pre class="comment"> SIMPLE solves Poisson equation with Dirichlet boundaray condition in a L-shaped domain with FEM using uniform mesh refinement.</pre></div><!-- crossreference --><h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>This function calls:<ul style="list-style-image:url(../../matlabicon.gif)"><li><a href="../../AFEM@matlab/2_Solve/Poisson.html" class="code" title="function [u, energy] = Poisson(mesh, f, g_D, g_N)">Poisson</a>	POISSON solve the 2-D Poisson equation</li><li><a href="../../AFEM@matlab/4_Refine/uniformrefine.html" class="code" title="function [mesh] = uniformrefine(mesh)">uniformrefine</a>	UNIFORMREFINE refines the current triangulation by dividing</li><li><a href="../../AFEM@matlab/5_Mesh/getmesh.html" class="code" title="function mesh = getmesh(node,elem,Dirichlet,Neumann,type,solu)">getmesh</a>	GETMESH generates initial mesh data structure.</li></ul>This function is called by:<ul style="list-style-image:url(../../matlabicon.gif)"><li><a href="demo.html" class="code" title="function varargout = demo(varargin)">demo</a>	DEMO M-file for demo.fig</li></ul><!-- crossreference --><h2><a name="_subfunctions"></a>SUBFUNCTIONS <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2><ul style="list-style-image:url(../../matlabicon.gif)"><li><a href="#_sub1" class="code">function z = f(p)</a></li><li><a href="#_sub2" class="code">function z = g_D(p)</a></li><li><a href="#_sub3" class="code">function z = g_N(p)</a></li><li><a href="#_sub4" class="code">function z = u(p)</a></li></ul><h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2><div class="fragment"><pre><a name="_sub0" href="#_subfunctions" class="code">function simple</a><span class="comment">% SIMPLE solves Poisson equation with Dirichlet boundaray condition in a</span><span class="comment">% L-shaped domain with FEM using uniform mesh refinement.</span><span class="comment">%</span><span class="comment">% L. Chen &amp; C. Zhang 10-16-2006</span><span class="comment">%--------------------------------------------------------------------------</span><span class="comment">% Initialize Figure Window</span><span class="comment">%--------------------------------------------------------------------------</span>figure(1); set(gcf,<span class="string">'Units'</span>,<span class="string">'normal'</span>); set(gcf,<span class="string">'Position'</span>,[0.02,0.1,0.8,0.6]);MaxIt = 5; N = zeros(MaxIt,1); energy = zeros(MaxIt,1);<span class="comment">%--------------------------------------------------------------------------</span><span class="comment">% PreStep 0: generate initial mesh</span><span class="comment">%--------------------------------------------------------------------------</span>node = [1,0; 1,1; 0,1; -1,1; -1,0; -1,-1; 0,-1; 0,0];  <span class="comment">% nodes</span>elem = [1,2,8; 3,8,2; 8,3,5; 4,5,3; 7,8,6; 5,6,8];     <span class="comment">% elements</span>Dirichlet = [1,2; 2,3; 3,4; 4,5; 5,6; 6,7; 7,8; 1,8];  <span class="comment">% Dirichlet bdry edges</span>Neumann   = [];                                        <span class="comment">% Neumann bdry edges</span>mesh = <a href="../../AFEM@matlab/5_Mesh/getmesh.html" class="code" title="function mesh = getmesh(node,elem,Dirichlet,Neumann,type,solu)">getmesh</a>(node,elem,Dirichlet,Neumann);   <span class="comment">%--------------------------------------------------------------------------</span><span class="comment">% Finite Element Method</span><span class="comment">%--------------------------------------------------------------------------</span><span class="keyword">for</span> iter = 1: MaxIt    <span class="comment">% Step 1: Uniform mesh refinement</span>    mesh = <a href="../../AFEM@matlab/4_Refine/uniformrefine.html" class="code" title="function [mesh] = uniformrefine(mesh)">uniformrefine</a>(mesh);    N(iter) = size(mesh.elem,1);    <span class="comment">% Step 2: Solve</span>    [mesh.solu,energy(iter)] = <a href="../../AFEM@matlab/2_Solve/Poisson.html" class="code" title="function [u, energy] = Poisson(mesh, f, g_D, g_N)">Poisson</a>(mesh,@<a href="#_sub1" class="code" title="subfunction z = f(p)">f</a>,@<a href="#_sub2" class="code" title="subfunction z = g_D(p)">g_D</a>,@<a href="#_sub3" class="code" title="subfunction z = g_N(p)">g_N</a>);    <span class="comment">% Step 3: Graphic representation</span>    subplot(1,2,1); hold off    trisurf(mesh.elem, mesh.node(:,1), mesh.node(:,2), mesh.solu', <span class="keyword">...</span>            <span class="string">'FaceColor'</span>, <span class="string">'interp'</span>, <span class="string">'EdgeColor'</span>, <span class="string">'interp'</span>);    view(-47,10);    title(<span class="string">'Solution to the Poisson equation'</span>, <span class="string">'FontSize'</span>, 14)    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(sprintf(<span class="string">'Mesh after %d iterations'</span>,iter), <span class="string">'FontSize'</span>, 14)    pause(0.2)  <span class="keyword">end</span>lastenergy = energy(MaxIt);<span class="comment">%--------------------------------------------------------------------------</span><span class="comment">% Plot the convergence rate</span><span class="comment">% by the regularity result, u is in H^(2/3+1)</span><span class="comment">%--------------------------------------------------------------------------</span>figure(2);loglog(N(1:length(N)-2),energy(1:length(N)-2)-lastenergy,<span class="string">'-*'</span>, <span class="keyword">...</span>       N(1:length(N)-2),N(1:length(N)-2).^(-2/3),<span class="string">'r-.'</span>); axis tight;title(<span class="string">'Energy error'</span>, <span class="string">'FontSize'</span>, 14);mesh<span class="comment">%--------------------------------------------------------------------------</span><span class="comment">% End of function SIMPLE</span><span class="comment">%--------------------------------------------------------------------------</span><span class="comment">%--------------------------------------------------------------------------</span><span class="comment">% Sub functions called by SIMPLE</span><span class="comment">%--------------------------------------------------------------------------</span><a name="_sub1" href="#_subfunctions" class="code">function z = f(p)</a><span class="comment">% load data (right hand side function)</span>z = zeros(size(p,1),1);<span class="comment">%--------------------------------------------------------------------------</span><a name="_sub2" href="#_subfunctions" class="code">function z = g_D(p) </a><span class="comment">% Dirichlet boundary condition</span>z = <a href="#_sub4" class="code" title="subfunction z = u(p)">u</a>(p);<span class="comment">%--------------------------------------------------------------------------</span><a name="_sub3" href="#_subfunctions" class="code">function z = g_N(p) </a><span class="comment">% Neumann boundary condition</span>z = zeros(size(p,1),1);<span class="comment">%--------------------------------------------------------------------------</span><a name="_sub4" href="#_subfunctions" class="code">function z = u(p) </a><span class="comment">% exact solution of the test problem</span>r = sqrt(sum(p.^2,2));theta = atan2(p(:,2),p(:,1));theta = (theta&gt;=0).*theta + (theta&lt;0).*(theta+2*pi);z = r.^(2/3).*sin(2*theta/3);<span class="comment">%--------------------------------------------------------------------------</span></pre></div><hr><address>Generated on Fri 17-Nov-2006 11:02:53 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/" target="_parent">m2html</a></strong> &copy; 2003</address></body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -