rbmatlab 0.10.01
|
00001 function demo_femdiscfunc 00002 % function demo_femdiscfunc 00003 % 00004 % Script demonstrating some basic functionality of lagrange finite 00005 % element functions. 00006 00007 % B. Haasdonk, I. Maier 26.04.2011 00008 00009 disp('---------------------------------'); 00010 disp(' lagrange FE-functions '); 00011 disp('---------------------------------'); 00012 00013 % poisson_model 00014 params = []; 00015 pdeg = 4; 00016 params.pdeg = pdeg; 00017 params.dimrange = 3; 00018 % params.dimrange = 1; 00019 params.debug = 1; 00020 params.numintervals = 5; 00021 model = poisson_model(params); 00022 % convert to local_model: 00023 model = elliptic_discrete_model(model); 00024 grid = construct_grid(model); 00025 df_info = feminfo(params,grid); 00026 %tmp = load('circle_grid'); 00027 %grid = triagrid(tmp.p,tmp.t,[]); 00028 disp('model initialized'); 00029 00030 % without model_data, detailed_simulation, etc. but explicit 00031 % calls of fem operations 00032 00033 % initialize vectorial discrete function, extract scalar 00034 % component and plot basis function 00035 df = femdiscfunc([],df_info); % initialize zero df 00036 00037 fprintf('\n'); 00038 disp('initialization of femdiscfunc successful, display:'); 00039 display(df); 00040 00041 disp('press enter to continue'); 00042 pause; 00043 00044 % for check of dof consistency we have a plot routine: 00045 fprintf('\n'); 00046 disp('plot of global_dof_index map for consistency check:'); 00047 p = plot_dofmap(df); 00048 00049 disp('press enter to continue'); 00050 pause; 00051 00052 % global dof access: 00053 fprintf('\n'); 00054 disp('example of dof access, scalar component extraction and plot:'); 00055 % set second vector component in 4th basis function nonzero; 00056 ncomp = 2; 00057 locbasisfunc_index = 4; 00058 df.dofs((locbasisfunc_index-1)*df.dimrange+ncomp) = 1; 00059 dfscalar = scalar_component(df,2); % should be nonzero function 00060 disp(['entry should be 1 : ',... 00061 num2str(dfscalar.dofs(locbasisfunc_index))]); 00062 00063 params = []; 00064 params.subsampling_level = 6; 00065 figure,plot(dfscalar,params); 00066 dfscalar.dofs(:) = 0; % now zero again. 00067 % keyboard; 00068 00069 disp('press enter to continue'); 00070 pause; 00071 00072 fprintf('\n'); 00073 disp('example of local dof access:'); 00074 % local dof access via local to global map 00075 eind = 4; % set dof on element number 4 00076 lind = (pdeg+2); % local basis function index with lcoord (0,1/pdeg) 00077 dfscalar.dofs(dfscalar.global_dof_index(eind,lind)) = 1; 00078 00079 % example of local evaluation of femdiscfunc simultaneous on 00080 % several elements in the same local coordinate point 00081 elids = [4,6,7,10]; % evaluation on some elements 00082 lcoord = [0,1/pdeg]; % local coordinate vector == last point in all triangles 00083 f = evaluate(dfscalar,elids,lcoord); 00084 disp(['first entry should be 1 : ',num2str(f(1))]); 00085 % equivalent call (!) by () operator as abbreviation for local evaluation: 00086 f = dfscalar(elids,lcoord); 00087 disp(['first entry should be 1 : ',num2str(f(1))]); 00088 00089 disp('press enter to continue'); 00090 pause; 00091 00092 disp('examples of norm computation:') 00093 params.dimrange = 1; 00094 params.pdeg = 1; 00095 dfinfo1 = feminfo(params,grid); 00096 df1 = femdiscfunc([],dfinfo1); 00097 df1.dofs(:) = 1; 00098 disp(['L2-norm(f(x,y)=1) = ',num2str(fem_l2_norm(df1))]); 00099 disp(['H10-norm(f(x,y)=1) = ',num2str(fem_h10_norm(df1))]); 00100 df1.dofs(:) = df1.grid.X(:); 00101 disp(['L2-norm(f(x,y)=x) = ',num2str(fem_l2_norm(df1))]); 00102 disp(['H10-norm(f(x,y)=x) = ',num2str(fem_h10_norm(df1))]); 00103 df1.dofs(:) = df1.grid.Y(:); 00104 disp(['L2-norm(f(x,y)=y) = ',num2str(fem_l2_norm(df1))]); 00105 disp(['H10-norm(f(x,y)=y) = ',num2str(fem_h10_norm(df1))]); 00106 00107 disp('press enter to continue'); 00108 pause; 00109 00110 % evaluate df in all lagrange nodes of element 4 by loop 00111 fprintf('\n'); 00112 disp(['dfscalar on element 4 in all lagrange nodes,' ... 00113 'only (pdeg+2) entry should be 1:']); 00114 lagrange_nodes = lagrange_nodes_lcoord(pdeg); 00115 elid = 4; 00116 for i = 1:size(lagrange_nodes,1); 00117 f = evaluate(dfscalar,elid,lagrange_nodes(i,:)); 00118 disp(['f(l(',num2str(i),')) = ',num2str(f)]); 00119 end; 00120 00121 disp('press enter to continue'); 00122 pause; 00123 00124 fprintf('\n'); 00125 disp('example of requirement of subsampling in plot of discfuncs:'); 00126 figure; 00127 subsamp_levels = [0,2,4,16]; 00128 for i=1:length(subsamp_levels) 00129 subplot(2,2,i), 00130 params.axis_equal = 1; 00131 params.subsampling_level = subsamp_levels(i); 00132 params.clim = [-0.15 1.15]; % rough bounds 00133 plot(dfscalar,params); 00134 title(['subsampling level = ',num2str(subsamp_levels(i))]); 00135 end;