% % @file poisson_fe.m % % @brief % % @copyright % Copyright (©) 2021 EPFL (Ecole Polytechnique Fédérale de Lausanne) % SPC (Swiss Plasma Center) % % SPClibs is free software: you can redistribute it and/or modify it under % the terms of the GNU Lesser General Public License as published by the Free % Software Foundation, either version 3 of the License, or (at your option) % any later version. % % SPClibs is distributed in the hope that it will be useful, but WITHOUT ANY % WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS % FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. % % You should have received a copy of the GNU Lesser General Public License % along with this program. If not, see . % % @author % (in alphabetical order) % @author Trach-Minh Tran % file='poisson_fe.h5'; % nx=h5readatt(file,'/','NX'); ny=h5readatt(file,'/','NY'); kx=h5readatt(file,'/','KX'); ky=h5readatt(file,'/','KY'); nidbas1=h5readatt(file,'/','NIDBAS1'); nidbas2=h5readatt(file,'/','NIDBAS2'); relax=h5readatt(file,'/','RELAX'); nlevels=h5readatt(file,'/','LEVELS'); nu1=h5readatt(file,'/','NU1'); nu2=h5readatt(file,'/','NU2'); mu=h5readatt(file,'/','MU'); title_str=sprintf(['N=(%d,%d), NIDBAS=(%d,%d), relax=%s, nu1=%d, ' ... 'nu2=%d, mu=%d, LEVELS=%d, KX=%d, KY=%d'], ... nx,ny,nidbas1,nidbas2,relax,nu1,nu2,mu,nlevels,kx,ky); % % Prolongation matrices at the coarsest grid % levels=nlevels; mglevel=sprintf('/mglevels/level.%.2d', levels); dset=strcat(mglevel,'/matpx'); matpx=h5read(file,dset); dset=strcat(mglevel,'/matpy'); matpy=h5read(file,dset); % % FE matrix at the finest grid % levels=1; mglevel=sprintf('/mglevels/level.%.2d', levels); dset=strcat(mglevel,'/mata'); [mata,diag]=csr_mat(file,dset); f=h5read(file,strcat(mglevel,'/f')); v=h5read(file,strcat(mglevel,'/v')); f1d=h5read(file,strcat(mglevel,'/f1d')); v1d=h5read(file,strcat(mglevel,'/v1d')); % $$$ figure % $$$ spy(mata) % % Solutions at the finest grid % x=h5read(file,'/solutions/xg'); y=h5read(file,'/solutions/yg'); dense=h5read(file,'/solutions/dense'); sol_anal=h5read(file,'/solutions/anal'); sol_calc=h5read(file,'/solutions/calc'); sol_direct=h5read(file,'/solutions/direct'); nx=int32(size(x,1)); ny=int32(size(y,1)); figure surf(x,y,sol_direct'-sol_anal') xlabel('X'); ylabel('Y'); title('Error on the finest grid') figure subplot(211) [yy,iy] = max(abs(sol_anal),[],2); [xx,ix] = max(yy); iy0=iy(ix); str=sprintf('Solution at y = %.4f', y(iy0)); plot(x, sol_anal(:,iy0),x, sol_direct(:,iy0),'o') xlabel('x'); ylabel(str); grid on legend('Analytic Solution', 'Direct Solution') title(title_str) subplot(212) [xx,ix] = max(abs(sol_anal)); [yy,iy] = max(xx); ix0=ix(iy); str=sprintf('Solution at x = %.4f', x(ix0)); plot(y, sol_anal(ix0,:),y, sol_direct(ix0,:),'o') xlabel('y'); ylabel(str); grid on title(title_str) % % Iterations % dset='/Iterations/'; disc_err=h5read(file, strcat(dset,'disc_errors')); resid=h5read(file, strcat(dset,'residues')); its=0:1:size(resid,1)-1; figure subplot(211) semilogy(its,resid,'o-') grid on xlabel('Iterations'); ylabel('Norm of residue'); title(title_str); subplot(212) semilogy(its,disc_err,'h-') grid on xlabel('Iterations'); ylabel('Norm of error');