3 % Validation
function for MassWAssembling P1 functions.
5 % The Mass Weight Matrix, `\MasseF{w}`, is given by
6 % ``\MasseF{w}_{i,j}=\int_\DOMH w(\q)\FoncBase_i(\q) \FoncBase_j(\q) d\q,\ \forall (i,j)\in\ENS{1}{\nq}^2``
7 % where `\FoncBase_i` are `P_1`-Lagrange basis functions.
8 % This Matrix is computed by functions MassWAssemblingP1{Version} where {Version} is one of
9 %
'base',
'OptV0',
'OptV1' and
'OptV2'.
10 % - Test 1: compute MassW Matrix using previous functions and give errors and cputimes
11 % - Test 2: compute ``\int_\DOM w(x,y) u(x,y) v(x,y) dxdy \approx \DOT{\MasseF{w} \vecb{U}}{\vecb{V}}``
12 % where `\vecb{U}_i=u(\q^i)` and `\vecb{V}_i=v(\q^i)`. Use fonctions `u`, `v` and `w` defined in #
valid_FEMmatrices.
13 % - Test 3: retrieve order 2 of `P_1`-Lagrange integration ``|\int_\DOM uvw -\Pi_h(u)\Pi_h(v)\Pi_h(w)d\DOM| \leq C h^2``
16 % #MassWAssemblingP1base, #MassWAssemblingP1OptV0, #MassWAssemblingP1OptV1, #MassWAssemblingP1OptV2
18 % @author Francois Cuvelier @date 2012-11-26
20 disp('*******************************************')
21 disp('* MassW Assembling P1 validations *')
22 disp('*******************************************')
28 disp(
'-----------------------------------------')
29 disp(' Test 1: Matrices errors and CPU times ')
30 disp('-----------------------------------------')
32 Tw=w(Th.q(1,:),Th.q(2,:));
39 Test1.error(1)=norm(Mbase-MOptV0,Inf);
40 Test1.name{1}=
'MassWAssemblingP1OptV0';
41 fprintf(
' Error P1base vs OptV0 : %e\n',Test1.error(1))
45 Test1.error(2)=norm(Mbase-MOptV1,Inf);
46 Test1.name{2}=
'MassWAssemblingP1OptV1';
47 fprintf(
' Error P1base vs OptV1 : %e\n',Test1.error(2))
51 Test1.error(3)=norm(Mbase-MOptV2,Inf);
52 Test1.name{3}=
'MassWAssemblingP1OptV2';
53 fprintf(
' Error P1base vs OptV2 : %e\n',Test1.error(3))
55 fprintf(
' CPU times base (ref) : %3.4f (s)\n',T(1))
56 fprintf(
' CPU times OptV0 : %3.4f (s) - Speed Up X%3.3f\n',T(2),T(1)/T(2))
57 fprintf(
' CPU times OptV1 : %3.4f (s) - Speed Up X%3.3f\n',T(3),T(1)/T(3))
58 fprintf(
' CPU times OptV2 : %3.4f (s) - Speed Up X%3.3f\n',T(4),T(1)/T(4))
62 disp(
'-----------------------------------------------------')
63 disp(' Test 2: Validations by integration on [0,1]x[0,1] ')
64 disp('-----------------------------------------------------')
67 U=Test(kk).u(Th.q(1,:),Th.q(2,:));
68 V=Test(kk).v(Th.q(1,:),Th.q(2,:));
69 Tw=Test(kk).w(Th.q(1,:),Th.q(2,:));
71 Test(kk).error=abs(Test(kk).MassW-U*M*V');
72 fprintf(' function %d : u(x,y)=%s, v(x,y)=%s, w(x,y)=%s\n -> MassW error=%e\n', ...
73 kk,Test(kk).cu,Test(kk).cv,Test(kk).cw,Test(kk).error);
78 disp('--------------------------------')
79 disp(' Test 3: Validations by order ')
80 disp('--------------------------------')
89 Tw=w(Th.q(1,:),Th.q(2,:));
90 fprintf(' Matrix size : %d\n',Th.nq);
95 U=u(Th.q(1,:),Th.q(2,:));
96 V=v(Th.q(1,:),Th.q(2,:));
97 Error(k)=abs(ExSol-U*M*V');
99 fprintf(' Error : %e\n',Error(k));
102 loglog(h,Error,'+-k',h,h*1.1*Error(1)/h(1),'-.k',h,1.1*Error(1)*(h/h(1)).^2,'k:')
103 legend('Error','O(h)','O(h^2)')
105 title('Test 3 : MassW Matrix')
109 function checkTest1(Test)
110 I=find(Test.error>1e-14);
112 disp('------------------------')
113 disp(' Test 1 (results): OK')
114 disp('------------------------')
116 disp('----------------------------')
117 disp(' Test 1 (results): FAILED')
118 disp('----------------------------')
122 function checkTest2(Test)
126 if (Test(k).degree<=1)
127 if (Test(k).error>1e-14)
133 disp('------------------------')
134 disp(' Test 2 (results): OK')
135 disp('------------------------')
137 disp('----------------------------')
138 disp(' Test 2 (results): FAILED')
139 disp('----------------------------')
143 function checkTest3(h,error)
145 P=polyfit(log(h),log(error),1);
147 disp('------------------------')
148 disp(' Test 3 (results): OK')
149 fprintf(' -> found numerical order %f. Must be 2\n',P(1))
150 disp('------------------------')
152 disp('----------------------------')
153 disp(' Test 3 (results): FAILED')
154 fprintf(' -> found numerical order %f. Must be 2\n',P(1))
155 disp('----------------------------')