rbmatlab  1.13.10
 All Classes Namespaces Files Functions Variables Groups Pages
demo_fem.m
Go to the documentation of this file.
1 % demo of a finite element simulation
2 %
3 % Script solving a laplace problem (-laplace u = 0) with suitable
4 % general dirichlet and neuman boundary conditions
5 % Currently only cartesian grids are supported in the underlying
6 % fem routine
7 
8 % Bernard Haasdonk 5.7.2006
9 
10 %| \todo make work again for release
11 
12 disp('Demonstration that solves a laplace-problem -laplace u = 0:')
13 
14 params = [];
15 
16 disp('setting parameters');
17 
18 
19 params.xrange = [0,1]; % grid x-coordinate range
20 params.yrange = [0,1]; % grid y-coordinate range
21 params.xnumintervals = 100; % number of grid cells in x-direction
22 params.ynumintervals = 50; % number of grid cells in y-direction
23 
24 % the following exceeds the size of sparse-matrices, which can be
25 % linearly indexed (180000 elements, ... sec comp time)
26 %params.nx = 600; % number of grid cells in x-direction
27 %params.ny = 300; % number of grid cells in y-direction
28 
29 % the following is trivially solvable by linear indices <= 1.6e9
30 %params.nx = 200; % number of grid cells in x-direction
31 %params.ny = 100; % number of grid cells in y-direction
32 
33 % set upper boundary to dirichlet, middle of upper and the lower boundary
34 % to neuman, set left and right to neuman
35 params.bnd_rect_corner1 = [params.xrange(1) , params.yrange(2) ; ...
36  params.xrange(1)+ 250e-6 , params.yrange(2); ...
37  params.xrange(1) , params.yrange(1); ...
38  params.xrange(1) , params.yrange(1); ...
39  params.xrange(2) , params.yrange(1);
40  ];
41 params.bnd_rect_corner1 = params.bnd_rect_corner1' - eps;
42 params.bnd_rect_corner2 = [params.xrange(2), params.yrange(2); ...
43  params.xrange(2)-250e-6, params.yrange(2); ...
44  params.xrange(2), params.yrange(1); ...
45  params.xrange(1), params.yrange(2); ...
46  params.xrange(2), params.yrange(2)
47  ];
48 params.bnd_rect_corner2 = params.bnd_rect_corner2' + eps;
49 
50 params.bnd_rect_index = [-1, -2, -2, -2, -2];
51 
52 params.gridtype = 'rectgrid';
53 grid = construct_grid(params);
54 
55 % set data functions
56 
57 params.name_dirichlet_values = 'leftright';
58 params.c_dir_left = 1.0; % pressure left
59 params.c_dir_right = 0.5; % pressure right
60 params.dir_middle = params.xrange(2)/2;
61 
62 %params.name_dirichlet_values = 'homogeneous';
63 %params.c_dir = 1.0;
64 params.name_neuman_values = 'pressure_gdl';
65 params.c_neu_max = 1000; % maximum velocity in middle of left and right side
66 
67 %params.name_neuman_values = 'homogeneous';
68 %params.c_neu = 0;
69 
70 params.show_colorbar = 1;
71 params.nolines = 1;
72 params.verbose = 10;
73 
74 disp('solving system');
75 p = fem_laplace(grid,params);
76 
77 disp('plotting result');
78 figure;
79 
80 plot_vertex_data(grid,p,params);
81 %plot_p1_data(p,params);
82 
83 
84 
85 
86 
87 
88 % TO BE ADJUSTED TO NEW SYNTAX
89 %| \docupdate