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

📄 simple.m

📁 C++编译指导
💻 M
字号:
function simple% SIMPLE solves Poisson equation with Dirichlet boundaray condition in a% L-shaped domain with FEM using uniform mesh refinement. %% L. Chen & C. Zhang 10-16-2006%--------------------------------------------------------------------------% Initialize Figure Window%--------------------------------------------------------------------------figure(1); set(gcf,'Units','normal'); set(gcf,'Position',[0.02,0.1,0.8,0.6]);MaxIt = 5; N = zeros(MaxIt,1); energy = zeros(MaxIt,1);%--------------------------------------------------------------------------% PreStep 0: generate initial mesh%--------------------------------------------------------------------------node = [1,0; 1,1; 0,1; -1,1; -1,0; -1,-1; 0,-1; 0,0];  % nodeselem = [1,2,8; 3,8,2; 8,3,5; 4,5,3; 7,8,6; 5,6,8];     % elementsDirichlet = [1,2; 2,3; 3,4; 4,5; 5,6; 6,7; 7,8; 1,8];  % Dirichlet bdry edgesNeumann   = [];                                        % Neumann bdry edgesmesh = getmesh(node,elem,Dirichlet,Neumann);   %--------------------------------------------------------------------------          % Finite Element Method%--------------------------------------------------------------------------for iter = 1: MaxIt    % Step 1: Uniform mesh refinement    mesh = uniformrefine(mesh);    N(iter) = size(mesh.elem,1);    % Step 2: Solve    [mesh.solu,energy(iter)] = Poisson(mesh,@f,@g_D,@g_N);    view(-47,10);    pause(0.2)   endlastenergy = energy(MaxIt);%--------------------------------------------------------------------------          % Plot the convergence rate% by the regularity result, u is in H^(2/3+1)%--------------------------------------------------------------------------          figure(2);loglog(N(1:length(N)-2),energy(1:length(N)-2)-lastenergy,'-*', ...       N(1:length(N)-2),N(1:length(N)-2).^(-2/3),'r-.'); axis tight;title('Energy error', 'FontSize', 14);mesh%--------------------------------------------------------------------------% End of function SIMPLE%--------------------------------------------------------------------------%--------------------------------------------------------------------------% Sub functions called by SIMPLE%--------------------------------------------------------------------------function z = f(p)% load data (right hand side function)z = zeros(size(p,1),1);%--------------------------------------------------------------------------function z = g_D(p) % Dirichlet boundary conditionz = u(p);%--------------------------------------------------------------------------function z = g_N(p) % Neumann boundary conditionz = zeros(size(p,1),1);%--------------------------------------------------------------------------function z = u(p) % exact solution of the test problemr = sqrt(sum(p.^2,2));theta = atan2(p(:,2),p(:,1));theta = (theta>=0).*theta + (theta<0).*(theta+2*pi);z = r.^(2/3).*sin(2*theta/3);%--------------------------------------------------------------------------

⌨️ 快捷键说明

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