3 % Validation
function for the assembly of the stiffness matrix
for
4 % `P_1`-Lagrange finite element method
6 % The Stiffness Matrix `\Stiff` is given by
7 % ``\Stiff_{i,j}=\int_\DOMH \DOT{\GRAD\FoncBase_i(\q)}{\GRAD\FoncBase_j(\q)}d\q,\ \forall (i,j)\in\ENS{1}{\nq}^2``
8 % where `\FoncBase_i` are `P_1`-Lagrange basis functions.
9 % This Matrix is computed by functions StiffAssemblingP1{Version} where {Version} is one of
10 %
'base',
'OptV0',
'OptV1' and
'OptV2'.
11 % - Test 1: Computation of the Stiffness Matrix using all the versions giving errors and cputimes
12 % - Test 2: Computation of the integral ``\int_\DOM \DOT{\GRAD u(\q)}{\GRAD v(\q)}d\q \approx \DOT{\Stiff \vecb{U}}{\vecb{V}}``
13 % where `\vecb{U}_i=u(\q^i)` and `\vecb{V}_i=v(\q^i)`.
15 % - Test 3: One retrieves the order 2 of `P_1`-Lagrange integration
16 % ``|\int_\DOM \DOT{\GRAD u}{\GRAD v} -\DOT{\GRAD \Pi_h(u)}{\GRAD \Pi_h(v)}d\DOM| \leq C h^2``
24 % \image html images/
validStiffP1.png
"figure : validStiffP1 Test 3 result"
26 % @author François Cuvelier @date 2012-11-26
28 % OptFEM2DP1 [V1.2b1] - Copyright (C) 2013 CJS (LAGA)
30 % This file is part of OptFEM2DP1.
31 % OptFEM2DP1 is free software: you can redistribute it and/or modify
32 % it under the terms of the GNU General Public License as published by
33 % the Free Software Foundation, either version 3 of the License, or
34 % (at your option) any later version.
36 % OptFEM2DP1 is distributed in the hope that it will be useful,
37 % but WITHOUT ANY WARRANTY; without even the implied warranty of
38 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
39 % GNU General Public License
for more details.
41 % You should have received a copy of the GNU General Public License
42 % along with
this program. If not, see <http:
44 disp(
'*******************************************')
45 disp('* Stiff Assembling P1 validations *')
46 disp('*******************************************')
51 disp('-----------------------------------------')
52 disp(' Test 1: Matrices errors and CPU times ')
53 disp('-----------------------------------------')
60 Test1.error(1)=norm(Mbase-MOptV0,Inf);
61 Test1.name{1}=
'StiffAssemblingP1OptV0';
62 fprintf(
' Error P1base vs OptV0 : %e\n',Test1.error(1))
66 Test1.error(2)=norm(Mbase-MOptV1,Inf);
67 Test1.name{2}=
'StiffAssemblingP1OptV1';
68 fprintf(
' Error P1base vs OptV1 : %e\n',Test1.error(2))
72 Test1.error(3)=norm(Mbase-MOptV2,Inf);
73 Test1.name{3}=
'StiffAssemblingP1OptV2';
74 fprintf(
' Error P1base vs OptV2 : %e\n',Test1.error(3))
76 fprintf(
' CPU times base (ref) : %3.4f (s)\n',T(1))
77 fprintf(
' CPU times OptV0 : %3.4f (s) - Speed Up X%3.3f\n',T(2),T(1)/T(2))
78 fprintf(
' CPU times OptV1 : %3.4f (s) - Speed Up X%3.3f\n',T(3),T(1)/T(3))
79 fprintf(
' CPU times OptV2 : %3.4f (s) - Speed Up X%3.3f\n',T(4),T(1)/T(4))
85 disp('-----------------------------------------------------')
86 disp(' Test 2: Validations by integration on [0,1]x[0,1] ')
87 disp('-----------------------------------------------------')
90 U=Test(kk).u(Th.q(1,:),Th.q(2,:));
91 V=Test(kk).v(Th.q(1,:),Th.q(2,:));
92 Test(kk).error=abs(Test(kk).Stiff-U*M*V');
93 fprintf(' functions %d : u(x,y)=%s, v(x,y)=%s,\n -> Stiff error=%e\n',kk,Test(kk).cu,Test(kk).cv,Test(kk).error);
98 disp('--------------------------------')
99 disp(' Test 3: Validations by order ')
100 disp('--------------------------------')
108 fprintf(' Matrix size : %d\n',Th.nq);
113 U=u(Th.q(1,:),Th.q(2,:));
114 V=v(Th.q(1,:),Th.q(2,:));
115 Error(k)=abs(ExSol-U*M*V');
117 fprintf(' Error : %e\n',Error(k));
120 loglog(h,Error,'+-r',h,h*1.1*Error(1)/h(1),'-sm',h,1.1*Error(1)*(h/h(1)).^2,'-db')
121 legend('Error','O(h)','O(h^2)')
123 title('Test 3 : Stiffness Matrix')
127 function checkTest1(Test)
128 I=find(Test.error>1e-14);
130 disp('------------------------')
131 disp(' Test 1 (results): OK')
132 disp('------------------------')
134 disp('----------------------------')
135 disp(' Test 1 (results): FAILED')
136 disp('----------------------------')
140 function checkTest2(Test)
144 if (Test(k).degree<=1)
145 if (Test(k).error>1e-12)
151 disp('------------------------')
152 disp(' Test 2 (results): OK')
153 disp('------------------------')
155 disp('----------------------------')
156 disp(' Test 2 (results): FAILED')
157 disp('----------------------------')
161 function checkTest3(h,error)
163 P=polyfit(log(h),log(error),1);
165 disp('------------------------')
166 disp(' Test 3 (results): OK')
167 fprintf(' -> found numerical order %f. Must be 2\n',P(1))
168 disp('------------------------')
170 disp('----------------------------')
171 disp(' Test 3 (results): FAILED')
172 fprintf(' -> found numerical order %f. Must be 2\n',P(1))
173 disp('----------------------------')