rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
demo_femdiscfunc.m
Go to the documentation of this file.
1 function demo_femdiscfunc
2 % function demo_femdiscfunc
3 % Script demonstrating some basic functionality of lagrange finite
4 % element functions in the RBmatlab fem implementation
5 %
6 % See also demo_fem2_discfunc using
7 % the more general RBmatlab +Fem Routines
8 
9 % B. Haasdonk, I. Maier 26.04.2011
10 
11 disp('---------------------------------');
12 disp(' lagrange FE-functions ');
13 disp('---------------------------------');
14 
15 % poisson_model
16 params = [];
17 pdeg = 4;
18 params.pdeg = pdeg;
19 params.dimrange = 3;
20 % params.dimrange = 1;
21 params.debug = 1;
22 params.numintervals = 5;
23 model = poisson_model(params);
24 % convert to local_model:
25 model = elliptic_discrete_model(model);
26 grid = construct_grid(model);
27 df_info = feminfo(params,grid);
28 %tmp = load('circle_grid');
29 %grid = triagrid(tmp.p,tmp.t,[]);
30 disp('model initialized');
31 
32 % without model_data, detailed_simulation, etc. but explicit
33 % calls of fem operations
34 
35 % initialize vectorial discrete function, extract scalar
36 % component and plot basis function
37 df = femdiscfunc([],df_info); % initialize zero df
38 
39 fprintf('\n');
40 disp('initialization of femdiscfunc successful, display:');
41 display(df);
42 
43 disp('press enter to continue');
44 pause;
45 
46 % for check of dof consistency we have a plot routine:
47 fprintf('\n');
48 disp('plot of global_dof_index map for consistency check:');
49 p = plot_dofmap(df);
50 
51 disp('press enter to continue');
52 pause;
53 
54 % global dof access:
55 fprintf('\n');
56 disp('example of dof access, scalar component extraction and plot:');
57 % set second vector component in 4th basis function nonzero;
58 ncomp = 2;
59 locbasisfunc_index = 4;
60 df.dofs((locbasisfunc_index-1)*df.dimrange+ncomp) = 1;
61 dfscalar = scalar_component(df,2); % should be nonzero function
62 disp(['entry should be 1 : ',...
63  num2str(dfscalar.dofs(locbasisfunc_index))]);
64 
65 params = [];
66 params.subsampling_level = 6;
67 figure,plot(dfscalar,params);
68 dfscalar.dofs(:) = 0; % now zero again.
69 % keyboard;
70 
71 disp('press enter to continue');
72 pause;
73 
74 fprintf('\n');
75 disp('example of local dof access:');
76 % local dof access via local to global map
77 eind = 4; % set dof on element number 4
78 lind = (pdeg+2); % local basis function index with lcoord (0,1/pdeg)
79 dfscalar.dofs(dfscalar.global_dof_index(eind,lind)) = 1;
80 
81 % example of local evaluation of femdiscfunc simultaneous on
82 % several elements in the same local coordinate point
83 elids = [4,6,7,10]; % evaluation on some elements
84 lcoord = [0,1/pdeg]; % local coordinate vector == last point in all triangles
85 f = evaluate(dfscalar,elids,lcoord);
86 disp(['first entry should be 1 : ',num2str(f(1))]);
87 % equivalent call (!) by () operator as abbreviation for local evaluation:
88 f = dfscalar(elids,lcoord);
89 disp(['first entry should be 1 : ',num2str(f(1))]);
90 
91 disp('press enter to continue');
92 pause;
93 
94 disp('examples of norm computation:')
95 params.dimrange = 1;
96 params.pdeg = 1;
97 dfinfo1 = feminfo(params,grid);
98 df1 = femdiscfunc([],dfinfo1);
99 df1.dofs(:) = 1;
100 disp(['L2-norm(f(x,y)=1) = ',num2str(fem_l2_norm(df1))]);
101 disp(['H10-norm(f(x,y)=1) = ',num2str(fem_h10_norm(df1))]);
102 df1.dofs(:) = df1.grid.X(:);
103 disp(['L2-norm(f(x,y)=x) = ',num2str(fem_l2_norm(df1))]);
104 disp(['H10-norm(f(x,y)=x) = ',num2str(fem_h10_norm(df1))]);
105 df1.dofs(:) = df1.grid.Y(:);
106 disp(['L2-norm(f(x,y)=y) = ',num2str(fem_l2_norm(df1))]);
107 disp(['H10-norm(f(x,y)=y) = ',num2str(fem_h10_norm(df1))]);
108 
109 disp('press enter to continue');
110 pause;
111 
112 % evaluate df in all lagrange nodes of element 4 by loop
113 fprintf('\n');
114 disp(['dfscalar on element 4 in all lagrange nodes,' ...
115  'only (pdeg+2) entry should be 1:']);
116 lagrange_nodes = lagrange_nodes_lcoord(pdeg);
117 elid = 4;
118 for i = 1:size(lagrange_nodes,1);
119  f = evaluate(dfscalar,elid,lagrange_nodes(i,:));
120  disp(['f(l(',num2str(i),')) = ',num2str(f)]);
121 end;
122 
123 disp('press enter to continue');
124 pause;
125 
126 fprintf('\n');
127 disp('example of requirement of subsampling in plot of discfuncs:');
128 figure;
129 subsamp_levels = [0,2,4,16];
130 for i=1:length(subsamp_levels)
131  subplot(2,2,i),
132  params.axis_equal = 1;
133  params.subsampling_level = subsamp_levels(i);
134  params.clim = [-0.15 1.15]; % rough bounds
135  plot(dfscalar,params);
136  title(['subsampling level = ',num2str(subsamp_levels(i))]);
137 end;
class representing a continous piecewise polynomial function of arbitrary dimension. DOFS correspond to the values of Lagrange-nodes.
Definition: femdiscfunc.m:17
A triangular conforming grid in two dimensions.
Definition: triagrid.m:17
function demo_femdiscfunc()
Script demonstrating some basic functionality of lagrange finite element functions in the RBmatlab fe...
function local_model = elliptic_discrete_model(model)
function creating a model with local functions out of a model with global functions. See detailed description for explanation.
structure representing the fem-space information shared by all fem-functions. Implemented as handle c...
Definition: feminfo.m:17
function demo_fem2_discfunc()
This demo shows the basic functionality of the discrete function class Fem.DiscFunc.