diff --git a/README.md b/README.md deleted file mode 100644 index 63846587ec73d8f4a6c348fb7bae0bca1df8fd36..0000000000000000000000000000000000000000 --- a/README.md +++ /dev/null @@ -1,93 +0,0 @@ -# PDE-VKOGA-paper-experiments - - - -## Getting started - -To make it easy for you to get started with GitLab, here's a list of recommended next steps. - -Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)! - -## Add your files - -- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files -- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command: - -``` -cd existing_repo -git remote add origin https://gitlab.mathematik.uni-stuttgart.de/pub/ians-anm/pde-vkoga-paper-experiments.git -git branch -M main -git push -uf origin main -``` - -## Integrate with your tools - -- [ ] [Set up project integrations](https://gitlab.mathematik.uni-stuttgart.de/pub/ians-anm/pde-vkoga-paper-experiments/-/settings/integrations) - -## Collaborate with your team - -- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/) -- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html) -- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically) -- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/) -- [ ] [Set auto-merge](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html) - -## Test and Deploy - -Use the built-in continuous integration in GitLab. - -- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html) -- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing (SAST)](https://docs.gitlab.com/ee/user/application_security/sast/) -- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html) -- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/) -- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html) - -*** - -# Editing this README - -When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thanks to [makeareadme.com](https://www.makeareadme.com/) for this template. - -## Suggestions for a good README - -Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information. - -## Name -Choose a self-explaining name for your project. - -## Description -Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors. - -## Badges -On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge. - -## Visuals -Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method. - -## Installation -Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection. - -## Usage -Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README. - -## Support -Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc. - -## Roadmap -If you have ideas for releases in the future, it is a good idea to list them in the README. - -## Contributing -State if you are open to contributions and what your requirements are for accepting them. - -For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self. - -You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser. - -## Authors and acknowledgment -Show your appreciation to those who have contributed to the project. - -## License -For open source projects, say how it is licensed. - -## Project status -If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers. diff --git a/fem_sector_example.m b/fem_sector_example.m new file mode 100644 index 0000000000000000000000000000000000000000..b73fd4536c35e2e351b6ec6988906bb22c49ee3a --- /dev/null +++ b/fem_sector_example.m @@ -0,0 +1,326 @@ +function fem_sector_example(step) +%function fem_sector_example(step) +% +% Demonstration of FEM error convergence for sector example. +% very expensive as point with global coordinates need to be +% searched and found in FEM mesh. But this is required to be consistent +% with other approximation techniques using these uniform grids. +% the code can be run if RBmatlab from version 16.09 is installed +% as obtained from www.morepas.org. + +% B. Haasdonk 26.7.2023 + +if nargin < 1 + step = 4; +end; + +disp('FEM error convergence study for sector geometry') +disp('Note that the global to local coordinate search is extremely') +disp('expensive due to the many test points, and will overall take') +disp('several hours.') + +switch step + +% case 1 % create scale of refined gridfiles +% fns = {'sectorg_alpha5over3','sectorg_alpha2over3'}; +% for fni = 1:length(fns) +% fn = fns{fni} +% [p,e,t] = initmesh(fn); +% meshfile = [fn,'_r0.mat']; +% save(meshfile,'p','e','t'); +% for i = 1:4 +% [p,e,t] = refinemesh(fn,p,e,t); +% meshfile = [fn,'_r',num2str(i),'.mat']; +% save(meshfile,'p','e','t'); +% end; +% end; +% disp('mesh sequence generated and stored'); + +% % continue with error computation: +% fem_sector_example(4); + + case 2 % load and plot mesh + + load('sectorg_alpha5over3_r1','p','t'); + grid = triagrid(p,t,[]); + plot(grid); + axis equal; + + figure; + load('sectorg_alpha2over3_r1','p','t'); + grid = triagrid(p,t,[]); + plot(grid); + axis equal; + + case 3 % fem on mesh + + params = []; +% params.solution_number = 1; % example with smooth solution + params.solution_number = 2; % example with singular sol, inhom bv + +% params.alpha = 5/3; +% params.grid_initfile = 'sectorg_alpha5over3_r1.mat'; +% params.grid_initfile = 'sectorg_alpha5over3_r2.mat'; +% params.grid_initfile = 'sectorg_alpha5over3_r3.mat'; +% params.grid_initfile = 'sectorg_alpha5over3_r4.mat'; + params.alpha = 2/3; + params.grid_initfile = 'sectorg_alpha2over3_r1.mat'; +% params.grid_initfile = 'sectorg_alpha2over3_r2.mat'; +% params.grid_initfile = 'sectorg_alpha2over3_r3.mat'; +% params.grid_initfile = 'sectorg_alpha2over3_r4.mat'; + model = pacman_model(params); + % generate grid and fem matrices: + model_data = gen_model_data(model); + figure, plot(model_data.grid); + axis equal; axis tight; title('FEM grid') + sim_data = detailed_simulation(model, model_data); + % plot results + figure, plot_sim_data(model,model_data,sim_data,[]); + title('FEM solution of -Laplace u = f') + axis equal; + axis tight; +% disp(['ndofs = ',num2str(sim_data.uh.df_info.ndofs)]); + + case 4 % fem on mesh and convergence study + + params = []; + params.solution_number = 1; % example with smooth solution +% params.solution_number = 2; % example with singular sol, inhom bv + + disp(' '); + disp('ndofs | L2-error | H1-error | infty-error | L2-error-grid | infty-error-grid | t_CPU') + disp('---------------------------------------------------------------------------------------------------------------------') + + for i = 1:4 + % params.alpha = 5/3; + % params.grid_initfile = ['sectorg_alpha5over3_r',num2str(i),'.mat']; + % params.grid_initfile = 'sectorg_alpha5over3_r2.mat'; + % params.grid_initfile = 'sectorg_alpha5over3_r3.mat'; + % params.grid_initfile = 'sectorg_alpha5over3_r4.mat'; + params.alpha = 2/3; + params.grid_initfile = ['sectorg_alpha2over3_r',num2str(i),'.mat']; + % params.grid_initfile = 'sectorg_alpha2over3_r2.mat'; + % params.grid_initfile = 'sectorg_alpha2over3_r3.mat'; + % params.grid_initfile = 'sectorg_alpha2over3_r4.mat'; + model = pacman_model(params); + % generate grid and fem matrices: + tic + model_data = gen_model_data(model); + sim_data = detailed_simulation(model, model_data); + t = toc; + % error computation: + % project exact solution onto higher degree polynomial fem func + par.pdeg = 4; + par.qdeg = 8; + par.dimrange = 1; + p4_df_info = feminfo(par,model_data.grid); + + uexact_h = femdiscfunc([],p4_df_info); + uexact_h = fem_interpol_global(model.solution,uexact_h); + uh = femdiscfunc([],p4_df_info); + u_local_eval = @(grid,elids,lcoord,params) ... + my_uh_local_eval(grid,elids,lcoord,params,sim_data.uh); + uh = fem_interpol_local(u_local_eval,uh); + + err = uh - uexact_h; + if i == 1 + plot(err); + title('error for i=1') + axis equal; + axis tight; + end; +% keyboard; + l2err = fem_l2_norm(err); + h1err = fem_h1_norm(err); + linftyerr = max(abs(err.dofs)); + [l2err_uniformgrid, linftyerr_uniformgrid] = errors_uniformgrid(model,uh); +% l2err_uniformgrid = zeros(size(l2err)); +% linftyerr_uniformgrid = zeros(size(l2err)); + ndofs = sim_data.uh.df_info.ndofs; + disp([num2str(ndofs,'%10.4d'),' | ',... + num2str(l2err,'%10.5e'),' | ',... + num2str(h1err,'%10.5e'),' | ',... + num2str(linftyerr,'%10.5e'),' | ',... + num2str(l2err_uniformgrid,'%10.5e'),' | ',... + num2str(linftyerr_uniformgrid,'%10.5e'),' | ',... + num2str(t,'%10.5e')]); + end; + + otherwise + error('step number unknown'); +end; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% auxiliary functions +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +function [l2err_uniformgrid, linftyerr_uniformgrid] = errors_uniformgrid(model, uh); +% determine test points + h = 0.002; +% h = 0.002; +% h = 0.002; + x = -1:h:1; + [XX,YY] = meshgrid(x,x); + i = find((XX.^2+YY.^2)<=1); + XX = XX(i); + YY = YY(i); + Phi = atan(YY./XX); + i = find(Phi<0 & XX>=0); + Phi(i) = Phi(i) + 2*pi; + i = find(XX<0); + Phi(i) = Phi(i) + pi; + i = find(Phi<model.alpha*pi); + XX = XX(i); + YY = YY(i); + Phi = Phi(i); + %scatter3(XX,YY,Phi) + test_sol = model.solution([XX,YY]); + test_uh = zeros(size(test_sol)); + % evaluate fem approximation in global points + % bad... : loop over points, should be vectorized... + f = waitbar(0,'Iterating over points'); + for i = 1:length(Phi); + if mod(i,1000)==0; + waitbar(i/length(Phi),f,'Iterating over points'); + end; + eind = find_triangle(uh.grid,[XX(i),YY(i)]); + if eind>0 + lcoord = global2local(uh.grid,eind,[XX(i),YY(i)]); + test_uh(i) = fem_evaluate(uh,eind,lcoord); + % sanity check: transform local coordinate back to global: + p = local2global(uh.grid,eind,lcoord,[]); + d = p-[XX(i),YY(i)]; +% if norm(d)>10*eps +% disp('norm of reconstructed point too large!, please inspect');% +% keyboard +% end; + else + test_uh(i) = NaN; + end; + end; + close(f); + + linftyerr_uniformgrid = max(abs(test_sol-test_uh)); + i = find(~isnan(test_uh)); + l2err_uniformgrid = sqrt(h*h*sum((test_sol(i)-test_uh(i)).^2)); + + %figure;scatter3(XX,YY,double(isnan(test_uh))) +% if isnan(l2err_uniformgrid) +% disp('NaN in error!') +% keyboard; +% end; + +function eind = find_triangle(grid,glob) +% returns the index of a triangle in grid containing the global point glob +% if no triangle is found, then -1 is returned. +inside = ones(grid.nelements,1); +for j = 1:3 % check if point is "above" edge connecting point j to j+1 + jp1 = mod(j,3)+1; + jp2 = mod(jp1,3)+1; + Xj = grid.X(grid.VI(:,j)); + Yj = grid.Y(grid.VI(:,j)); + Xjp1 = grid.X(grid.VI(:,jp1)); + Yjp1 = grid.Y(grid.VI(:,jp1)); + Vjjp1 = [Xjp1-Xj, Yjp1-Yj]; + Vjglob = [glob(1)*ones(size(Xj)) - Xj, glob(2)*ones(size(Yj)) - Yj]; + crossz = sign(Vjjp1(:,1).*Vjglob(:,2) - Vjjp1(:,2).*Vjglob(:,1)); + if j==1 + Xjp2 = grid.X(grid.VI(:,jp2)); + Yjp2 = grid.Y(grid.VI(:,jp2)); + Vjjp2 = [Xjp2-Xj, Yjp2-Yj]; + crossz2 = sign(Vjjp1(:,1).*Vjjp2(:,2) - Vjjp1(:,2).*Vjjp2(:,1)); % orientation of trias + end; + i = find(crossz.*crossz2<0); + inside(i) = 0; +end; +eind = find(inside); +if isempty(eind) + eind = -1; +end +if length(eind)>1 + % disp('length eind > 1, please check! '); + eind = eind(1); +end; +%if length(eind)==1 +% disp('length eind == 1, nice :-) '); +%end; + +% settings for pacman model +function model = pacman_model(params); + if ~isfield(params,'alpha') + alpha = 5/3; + else + alpha = params.alpha; + end; +% disp(['chosen alpha = ',num2str(alpha)]); + %alpha = 5/3; % hard coded in sectorg.m if changed here, change there! + model = poisson_model(params); + model.alpha = alpha; + model = rmfield(model,{'boundary_type','normals',... + 'xnumintervals','ynumintervals','xrange','yrange'}); + model.has_reaction = 0; + model.has_advection = 0; + model.has_diffusivity = 1; + model.has_source = 1; + model.has_dirichlet_values = 1; + model.has_neumann_values = 0; + model.has_robin_values = 0; + model.compute_output_functional = 0; + switch params.solution_number + case 1 % smooth solution + model.solution = @(glob,params) ... + sum(glob.^2,2); + model.source = @(glob,params) ... + - 4 * ones(size(glob,1),1); + case 2 % solution with singularity and inhomogeneous bnd val. + model.solution = @(glob,params) ... + pacman_exact_solution(glob',alpha); + model.source = @(glob,params) ... + neg_Laplace_pacman_exact_solution(glob',alpha); + % case 3 % solution wiht singularity and homogeneous bnd val. + % % someting seems to be buggy here, no convergence observed... + % model.solution = @(glob,params) ... + % pacman_exact_solution2(glob',alpha); + % model.source = @(glob,params) ... + % neg_Laplace_pacman_exact_solution2(glob',alpha); + % error('please use solution_number=1 or 2.') + end; + model.diffusivity_tensor = @(glob,params) ... + [ones(size(glob,1),1),... + zeros(size(glob,1),1),... + zeros(size(glob,1),1),... + ones(size(glob,1),1)]; + model.reaction = @(glob,params) zeros(size(glob,1),1); + model.dirichlet_values = @(glob,params) ... + params.solution(glob,params); + model.grid_initfile = params.grid_initfile; + model.gridtype = 'triagrid'; + model.pdeg = 1; + model.qdeg = 2; + model.dimrange = 1; + model = elliptic_discrete_model(model); + %model.detailed_simulation = @pacman_detailed_simulation; + +function f = pacman_exact_solution(x,alpha); +% function u(x) = |x|^(1/alpha)sin(phi(x)/alpha) +% with phi(x) = atan(x2/x1). +% which has -Laplace u = 0 on pacman shape +% but non-homogeneous boundary values. +f1 = sum(x.^2,1).^(0.5/alpha); +phi = atan(x(2,:)./x(1,:)); +i = find(phi<0 & x(1,:)>=0); +phi(i) = phi(i) + 2*pi; +i = find(x(1,:)<0); +phi(i) = phi(i) + pi; +f2 = sin(phi/alpha); +i = find(isnan(f2)); +f2(i) = 0; +f = f1.*f2; + +function f = neg_Laplace_pacman_exact_solution(x,alpha); +f = zeros(size(x,2),1); + +function res = my_uh_local_eval(grid,elids,lcoord,params,df) +% dummy function used for evaluating a discrete function at finer +% lagrange-grid nodes +res = fem_evaluate(df,elids,lcoord,[],[]); diff --git a/sectorg_alpha2over3.m b/sectorg_alpha2over3.m new file mode 100644 index 0000000000000000000000000000000000000000..d19d857241826759fab51941f5456e8973c01eb9 --- /dev/null +++ b/sectorg_alpha2over3.m @@ -0,0 +1,55 @@ +function [x,y]=sectorg_alpha2over3(bs,s) + +nbs=3; +alpha = 2/3 * pi; + +if nargin==0, + x=nbs; % number of boundary segments + return +end + +d=[ + 0 0 1% start parameter value + 1 alpha 0% end parameter value + 1 1 1% left hand region + 0 0 0% right hand region +]; + +bs1=bs(:)'; + +if find(bs1<1 | bs1>nbs), + error('semicircleg:InvalidBs', 'Non existent boundary segment number.') +end + +if nargin==1, + x=d(:,bs1); + return +end + +x=zeros(size(s)); +y=zeros(size(s)); +[m,n]=size(bs); +if m==1 && n==1, + bs=bs*ones(size(s)); % expand bs +elseif m~=size(s,1) || n~=size(s,2), + error('semicircleg:SizeBs', 'bs must be scalar or of same size as s.'); +end + +if ~isempty(s), + % boundary segment 1 + ii=find(bs==1); + x(ii) = s(ii); + y(ii) = zeros(size(ii)); + + % boundary segment 2 + ii=find(bs==2); + x(ii) = cos(s(ii)); + y(ii) = sin(s(ii)); + + + % boundary segment 3 + ii=find(bs==3); + x(ii) = s(ii)*cos(alpha); + y(ii) = s(ii)*sin(alpha); +end + diff --git a/sectorg_alpha2over3_r0.mat b/sectorg_alpha2over3_r0.mat new file mode 100644 index 0000000000000000000000000000000000000000..a8ec254b844f96404d101dbafba803fcb6453035 Binary files /dev/null and b/sectorg_alpha2over3_r0.mat differ diff --git a/sectorg_alpha2over3_r1.mat b/sectorg_alpha2over3_r1.mat new file mode 100644 index 0000000000000000000000000000000000000000..6804659dc8e566139987c619a4a2b81d48bd9cbe Binary files /dev/null and b/sectorg_alpha2over3_r1.mat differ diff --git a/sectorg_alpha2over3_r2.mat b/sectorg_alpha2over3_r2.mat new file mode 100644 index 0000000000000000000000000000000000000000..b7b76c8521dde9a6cb1a3aae803d646337eb129f Binary files /dev/null and b/sectorg_alpha2over3_r2.mat differ diff --git a/sectorg_alpha2over3_r3.mat b/sectorg_alpha2over3_r3.mat new file mode 100644 index 0000000000000000000000000000000000000000..ce0a2f57245ce2b2e1ad3139db526ad0bd48238a Binary files /dev/null and b/sectorg_alpha2over3_r3.mat differ diff --git a/sectorg_alpha2over3_r4.mat b/sectorg_alpha2over3_r4.mat new file mode 100644 index 0000000000000000000000000000000000000000..ee6049b51654b069a191f780c5e433fe71e194fd Binary files /dev/null and b/sectorg_alpha2over3_r4.mat differ