3 % Validation
function for the assembly of the weighted mass matrix
4 %
for `P_1`-Lagrange finite elements
6 % The Weighted Mass Matrix `\MasseF{w}` is given by
7 % ``\MasseF{w}_{i,j}=\int_\DOMH w(\q)\FoncBase_i(\q) \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 MassWAssemblingP1{Version} where {Version} is one of
10 %
'base',
'OptV0',
'OptV1' and
'OptV2'.
11 % - Test 1: Computation of the MassW Matrix using all the versions giving errors and computation times
12 % - Test 2: Computation of the integral ``\int_\DOM w(x,y) u(x,y) v(x,y) dxdy \approx \DOT{\MasseF{w} \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 ``|\int_\DOM u\,v\,w -\Pi_h(u)\,\Pi_h(v)\,\Pi_h(w)d\DOM| \leq C h^2``
18 % #MassWAssemblingP1base, #MassWAssemblingP1OptV0,
19 % #MassWAssemblingP1OptV1, #MassWAssemblingP1OptV2,
20 % #valid_FEMmatrices, #SquareMesh, #GetMaxLengthEdges
23 % \image html images/validMassWP1.png "figure : validMassWP1 Test 3 result"
25 % @author François Cuvelier @date 2012-11-26
29 disp('*******************************************')
30 disp('* MassW Assembling P1 validations *')
31 disp('*******************************************')
37 disp(
'-----------------------------------------')
38 disp(' Test 1: Matrices errors and CPU times ')
39 disp('-----------------------------------------')
41 Tw=w(Th.q(1,:),Th.q(2,:));
48 Test1.error(1)=norm(Mbase-MOptV0,Inf);
49 Test1.name{1}=
'MassWAssemblingP1OptV0';
50 fprintf(
' Error P1base vs OptV0 : %e\n',Test1.error(1))
54 Test1.error(2)=norm(Mbase-MOptV1,Inf);
55 Test1.name{2}=
'MassWAssemblingP1OptV1';
56 fprintf(
' Error P1base vs OptV1 : %e\n',Test1.error(2))
60 Test1.error(3)=norm(Mbase-MOptV2,Inf);
61 Test1.name{3}=
'MassWAssemblingP1OptV2';
62 fprintf(
' Error P1base vs OptV2 : %e\n',Test1.error(3))
64 fprintf(
' CPU times base (ref) : %3.4f (s)\n',T(1))
65 fprintf(
' CPU times OptV0 : %3.4f (s) - Speed Up X%3.3f\n',T(2),T(1)/T(2))
66 fprintf(
' CPU times OptV1 : %3.4f (s) - Speed Up X%3.3f\n',T(3),T(1)/T(3))
67 fprintf(
' CPU times OptV2 : %3.4f (s) - Speed Up X%3.3f\n',T(4),T(1)/T(4))
71 disp(
'-----------------------------------------------------')
72 disp(' Test 2: Validations by integration on [0,1]x[0,1] ')
73 disp('-----------------------------------------------------')
76 U=Test(kk).u(Th.q(1,:),Th.q(2,:));
77 V=Test(kk).v(Th.q(1,:),Th.q(2,:));
78 Tw=Test(kk).w(Th.q(1,:),Th.q(2,:));
80 Test(kk).error=abs(Test(kk).MassW-U*M*V');
81 fprintf(' function %d : u(x,y)=%s, v(x,y)=%s, w(x,y)=%s\n -> MassW error=%e\n', ...
82 kk,Test(kk).cu,Test(kk).cv,Test(kk).cw,Test(kk).error);
87 disp('--------------------------------')
88 disp(' Test 3: Validations by order ')
89 disp('--------------------------------')
98 Tw=w(Th.q(1,:),Th.q(2,:));
99 fprintf(' Matrix size : %d\n',Th.nq);
104 U=u(Th.q(1,:),Th.q(2,:));
105 V=v(Th.q(1,:),Th.q(2,:));
106 Error(k)=abs(ExSol-U*M*V');
108 fprintf(' Error : %e\n',Error(k));
111 loglog(h,Error,'+-r',h,h*1.1*Error(1)/h(1),'-sm',h,1.1*Error(1)*(h/h(1)).^2,'-db')
112 legend('Error','O(h)','O(h^2)')
114 title('Test 3 : MassW Matrix')
118 function checkTest1(Test)
119 I=find(Test.error>1e-14);
121 disp('------------------------')
122 disp(' Test 1 (results): OK')
123 disp('------------------------')
125 disp('----------------------------')
126 disp(' Test 1 (results): FAILED')
127 disp('----------------------------')
131 function checkTest2(Test)
135 if ( ismember(Test(k).degree,[0 1]) )
136 if (Test(k).error>1e-14)
142 disp('------------------------')
143 disp(' Test 2 (results): OK')
144 disp('------------------------')
146 disp('----------------------------')
147 disp(' Test 2 (results): FAILED')
148 disp('----------------------------')
152 function checkTest3(h,error)
154 P=polyfit(log(h),log(error),1);
155 if ( abs(P(1)-2)<5e-2 )
156 disp('------------------------')
157 disp(' Test 3 (results): OK')
158 fprintf(' -> found numerical order %f. Must be 2\n',P(1))
159 disp('------------------------')
161 disp('----------------------------')
162 disp(' Test 3 (results): FAILED')
163 fprintf(' -> found numerical order %f. Must be 2\n',P(1))
164 disp('----------------------------')