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 cputimes
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
27 % OptFEM2DP1 [V1.2b1] - Copyright (C) 2013 CJS (LAGA)
29 % This file is part of OptFEM2DP1.
30 % OptFEM2DP1 is free software: you can redistribute it and/or modify
31 % it under the terms of the GNU General Public License as published by
32 % the Free Software Foundation, either version 3 of the License, or
33 % (at your option) any later version.
35 % OptFEM2DP1 is distributed in the hope that it will be useful,
36 % but WITHOUT ANY WARRANTY; without even the implied warranty of
37 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
38 % GNU General Public License
for more details.
40 % You should have received a copy of the GNU General Public License
41 % along with
this program. If not, see <http:
43 disp(
'*******************************************')
44 disp('* MassW Assembling P1 validations *')
45 disp('*******************************************')
51 disp('-----------------------------------------')
52 disp(' Test 1: Matrices errors and CPU times ')
53 disp('-----------------------------------------')
55 Tw=w(Th.q(1,:),Th.q(2,:));
62 Test1.error(1)=norm(Mbase-MOptV0,Inf);
63 Test1.name{1}=
'MassWAssemblingP1OptV0';
64 fprintf(
' Error P1base vs OptV0 : %e\n',Test1.error(1))
68 Test1.error(2)=norm(Mbase-MOptV1,Inf);
69 Test1.name{2}=
'MassWAssemblingP1OptV1';
70 fprintf(
' Error P1base vs OptV1 : %e\n',Test1.error(2))
74 Test1.error(3)=norm(Mbase-MOptV2,Inf);
75 Test1.name{3}=
'MassWAssemblingP1OptV2';
76 fprintf(
' Error P1base vs OptV2 : %e\n',Test1.error(3))
78 fprintf(
' CPU times base (ref) : %3.4f (s)\n',T(1))
79 fprintf(
' CPU times OptV0 : %3.4f (s) - Speed Up X%3.3f\n',T(2),T(1)/T(2))
80 fprintf(
' CPU times OptV1 : %3.4f (s) - Speed Up X%3.3f\n',T(3),T(1)/T(3))
81 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 Tw=Test(kk).w(Th.q(1,:),Th.q(2,:));
94 Test(kk).error=abs(Test(kk).MassW-U*M*V');
95 fprintf(' function %d : u(x,y)=%s, v(x,y)=%s, w(x,y)=%s\n -> MassW error=%e\n', ...
96 kk,Test(kk).cu,Test(kk).cv,Test(kk).cw,Test(kk).error);
101 disp('--------------------------------')
102 disp(' Test 3: Validations by order ')
103 disp('--------------------------------')
112 Tw=w(Th.q(1,:),Th.q(2,:));
113 fprintf(' Matrix size : %d\n',Th.nq);
118 U=u(Th.q(1,:),Th.q(2,:));
119 V=v(Th.q(1,:),Th.q(2,:));
120 Error(k)=abs(ExSol-U*M*V');
122 fprintf(' Error : %e\n',Error(k));
125 loglog(h,Error,'+-r',h,h*1.1*Error(1)/h(1),'-sm',h,1.1*Error(1)*(h/h(1)).^2,'-db')
126 legend('Error','O(h)','O(h^2)')
128 title('Test 3 : MassW Matrix')
132 function checkTest1(Test)
133 I=find(Test.error>1e-14);
135 disp('------------------------')
136 disp(' Test 1 (results): OK')
137 disp('------------------------')
139 disp('----------------------------')
140 disp(' Test 1 (results): FAILED')
141 disp('----------------------------')
145 function checkTest2(Test)
149 if (Test(k).degree<=1)
150 if (Test(k).error>1e-14)
156 disp('------------------------')
157 disp(' Test 2 (results): OK')
158 disp('------------------------')
160 disp('----------------------------')
161 disp(' Test 2 (results): FAILED')
162 disp('----------------------------')
166 function checkTest3(h,error)
168 P=polyfit(log(h),log(error),1);
170 disp('------------------------')
171 disp(' Test 3 (results): OK')
172 fprintf(' -> found numerical order %f. Must be 2\n',P(1))
173 disp('------------------------')
175 disp('----------------------------')
176 disp(' Test 3 (results): FAILED')
177 fprintf(' -> found numerical order %f. Must be 2\n',P(1))
178 disp('----------------------------')