rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
demo_fem2_discfunc.m
Go to the documentation of this file.
1 function demo_fem2_discfunc
2 %function demo_fem2_discfunc
3 % This demo shows the basic functionality of the discrete function class
4 % Fem.DiscFunc.
5 
6 % IM, 08.09.2016
7 
8 % poisson_model
9 params = [];
10 pdeg = 4;
11 params.pdeg = pdeg;
12 params.dimrange = 3;
13 params.debug = 1;
14 params.numintervals = 5;
15 
16 model = poisson_model(params);
17 % add fields for generic fem
18 model = generic_fem_model_adapter(model);
19 
20 % construct grid
21 grid = construct_grid(model);
22 % generate discrete function info
23 df_info_scalar = Fem.Lagrange.DefaultInfo(model.pdeg, grid);
24 df_info = Fem.CompositeFunctionSpace(df_info_scalar, 'dim1', ...
25  copy(df_info_scalar), 'dim2', ...
26  copy(df_info_scalar), 'dim3');
27 
28 disp('model initialized, display function space:');
29 display(df_info);
30 
31 % initialize vectorial discrete function, extract scalar
32 % component and plot basis function
33 df = Fem.DiscFunc([], df_info); % initialize zero df
34 
35 fprintf('\n');
36 disp('initialization of discrete function successful, display:');
37 display(df);
38 
39 disp('press enter to continue');
40 pause;
41 
42 % dof consistency / dofmap ?
43 
44 % global dof access:
45 fprintf('\n');
46 disp('example of dof access, scalar component extraction and plot:');
47 % set second vector component in 4th basis function nonzero
48 ncomp = 2;
49 locbasisfunc_index = 4;
50 df.dofs((ncomp-1)*df_info_scalar.ndofs + locbasisfunc_index) = 1;
51 % extract scalar component
52 dfscalar = get_component(df, 2); % should be nonzero function
53 disp(['entry should be 1 : ', ...
54  num2str(dfscalar.dofs(locbasisfunc_index))]);
55 
56 % automatic plot of all dimensions, id-strings are used as titles
57 params = [];
58 params.subsampling_level = 6;
59 figure, plot(df, params);
60 
61 disp('press enter to continue');
62 pause;
63 close all
64 
65 % interpolate global gaussian function, plot result
66 fprintf('\n');
67 disp('interpolation of global function and plot:');
68 func = @(glob, params) exp(-10*sum((glob-repmat([0.5, 0.5], size(glob, 1), 1)).^2, 2));
69 df_gauss = interpol_global(df_info_scalar, func);
70 figure, plot(df_gauss);
71 title('df: interpolated gaussian');
72 
73 disp('press enter to continue');
74 pause;
75 
76 % interpolate the derivatives (smaller pdeg), plot results
77 fprintf('\n');
78 disp('evaluation of derivatives (interpolation of local functions) and plot:');
79 df_info_scalar2 = Fem.Lagrange.DefaultInfo(model.pdeg-1, grid);
80 
81 func = @(vgrid,el,lcoord,params) subsref(df_gauss.evaluate_derivative(el,lcoord), ...
82  struct('type', '()', 'subs', {{':', 1}}));
83 df_dx = interpol_local(df_info_scalar2, func);
84 
85 figure, plot(df_dx);
86 title('df/dx');
87 
88 func = @(vgrid,el,lcoord,params) subsref(df_gauss.evaluate_derivative(el,lcoord), ...
89  struct('type', '()', 'subs', {{':', 2}}));
90 df_dy = interpol_local(df_info_scalar2, func);
91 
92 figure, plot(df_dy);
93 title('df/dy');
94 
95 disp('press enter to continue');
96 pause;
97 close all
98 
99 % norm computations
100 fprintf('\n');
101 disp('examples of norm computation:')
102 dfscalar.dofs(:) = 1;
103 disp(['L2-norm(f(x,y)=1) = ', num2str(l2_norm(dfscalar))]);
104 disp(['H10-norm(f(x,y)=1) = ', num2str(h10_norm(dfscalar))]);
105 disp('previous vector-valued function, only one DoF nonzero:');
106 disp(['L2-norm(f(0.6,0)=(0,1,0)) = ', num2str(l2_norm(df))]);
107 disp(['H10-norm(f(0.6,0)=(0,1,0)) = ', num2str(h10_norm(df))]);
108 
109 end
scalar Lagrange FE functions on triangular grid
Definition: DefaultInfo.m:19
function model = generic_fem_model_adapter(model)
Initializes a default linear and stationary model for more generic fem discretization by modifying mo...
Composite function space for composition of FE function spaces on same grid.
represents a continous piecewise polynomial function of arbitrary dimension. Can be used for all fini...
Definition: DiscFunc.m:18
function demo_fem2_discfunc()
This demo shows the basic functionality of the discrete function class Fem.DiscFunc.