OptFEM3DP1 Toolbox: valid/validMass3DP1.m Source File

| OptFEM3DP1 Toolbox 20130614_170440 Matlab/Octave Optimized P1-Lagrange Finite Element Method in 3D

- Main Page
- Related Pages
- Files

- File List
- File Members

All Files Functions Variables Pages
validMass3DP1.m
Go to the documentation of this file.
1 function validMass3DP1()
2 % Copyright:
3 % See \ref license
4
5 addpath([pwd,filesep,'..',filesep,'base'])
6 addpath([pwd,filesep,'..',filesep,'sage'])
7 addpath([pwd,filesep,'..',filesep,'Opt'])
8 addpath([pwd,filesep,'..',filesep,'ElemMat'])
9
10 Th=CubeMesh(3);
11 %M=MassAssembling3DP1base(Th.nq,Th.nme,Th.me,Th.volumes);
12
13
14 disp('-----------------------------------------')
15 disp(' Test 1: Matrices errors and CPU times ')
16 disp('-----------------------------------------')
17 tic();
18 Mbase=MassAssembling3DP1base(Th.nq,Th.nme,Th.me,Th.volumes);
19 T(1)=toc();
20 tic();
21 MOptV0=MassAssembling3DP1OptV0(Th.nq,Th.nme,Th.me,Th.volumes);
22 T(2)=toc();
23 Test1.error(1)=norm(Mbase-MOptV0,Inf);
24 Test1.name{1}='MassAssembling3DP1OptV0';
25 fprintf(' Error P1base vs OptV0 : %e\n',Test1.error(1))
26 tic();
27 MOptV1=MassAssembling3DP1OptV1(Th.nq,Th.nme,Th.me,Th.volumes);
28 T(3)=toc();
29 Test1.error(2)=norm(Mbase-MOptV1,Inf);
30 Test1.name{2}='MassAssembling3DP1OptV1';
31 fprintf(' Error P1base vs OptV1 : %e\n',Test1.error(2))
32 tic();
33 MOptV2=MassAssembling3DP1OptV2(Th.nq,Th.nme,Th.me,Th.volumes);
34 T(4)=toc();
35 Test1.error(3)=norm(Mbase-MOptV2,Inf);
36 Test1.name{3}='MassAssembling3DP1OptV2';
37 fprintf(' Error P1base vs OptV2 : %e\n',Test1.error(3))
38
39 fprintf(' CPU times base (ref) : %3.4f (s)\n',T(1))
40 fprintf(' CPU times OptV0 : %3.4f (s) - Speed Up X%3.3f\n',T(2),T(1)/T(2))
41 fprintf(' CPU times OptV1 : %3.4f (s) - Speed Up X%3.3f\n',T(3),T(1)/T(3))
42 fprintf(' CPU times OptV2 : %3.4f (s) - Speed Up X%3.3f\n',T(4),T(1)/T(4))
43 checkTest1(Test1)
44
45 % TEST 2
46 disp('-----------------------------------------------------------')
47 disp(' Test 2: Validations by integration on [0,1]x[0,1]x[0,1] ')
48 disp('-----------------------------------------------------------')
49 Test=valid_FEMmatrices();
50 M=Mbase;
51 for kk=1:length(Test)
52 U=Test(kk).u(Th.q(1,:),Th.q(2,:),Th.q(3,:));
53 V=Test(kk).v(Th.q(1,:),Th.q(2,:),Th.q(3,:));
54 Test(kk).error=abs(Test(kk).Mass-U*M*V');
55 fprintf(' function %d : u(x,y,z)=%s, v(x,y,z)=%s,\n -> Mass error=%e\n',kk,Test(kk).cu,Test(kk).cv,abs(Test(kk).Mass-U*M*V'));
56 end
57 checkTest2(Test)
58
59 % TEST 3
60 disp('--------------------------------')
61 disp(' Test 3: Validations by order ')
62 disp('--------------------------------')
63 n=length(Test);
64 u=Test(n).u;
65 v=Test(n).v;
66 ExSol=Test(n).Mass;
67 N=10;
68 for k=1:10
69 Th=CubeMesh(5+k*3);
70 fprintf('(%d/%d) Matrix size : %d\n',k,N,Th.nq);
71 h(k)=GetMaxLengthEdges(Th.q,Th.me);
72 tic();
73 M=MassAssembling3DP1OptV2(Th.nq,Th.nme,Th.me,Th.volumes);
74 TT(k)=toc();
75 U=u(Th.q(1,:),Th.q(2,:),Th.q(3,:));
76 V=v(Th.q(1,:),Th.q(2,:),Th.q(3,:));
77 Error(k)=abs(ExSol-U*M*V');
78 fprintf(' MassAssembling3DP1OptV2 CPU times : %3.3f(s)\n',TT(k));
79 fprintf(' Error : %e\n',Error(k));
80 end
81
82 loglog(h,Error,'+-r',h,h*1.1*Error(1)/h(1),'-sm',h,1.1*Error(1)*(h/h(1)).^2,'-db')
83 legend('Error','O(h)','O(h^2)')
84 xlabel('h')
85 title('Test 3 : Mass Matrix')
86 checkTest3(h,Error)
87 end
88
89
90 function checkTest1(Test)
91 I=find(Test.error>1e-14);
92 if isempty(I)
93 disp('------------------------')
94 disp(' Test 1 (results): OK')
95 disp('------------------------')
96 else
97 disp('----------------------------')
98 disp(' Test 1 (results): FAILED')
99 disp('----------------------------')
100 end
101 end
102
103 function checkTest2(Test)
104 N=length(Test);
105 cntFalse=0;
106 for k=1:N
107 if (Test(k).degree<=1)
108 if (Test(k).error>1e-14)
109 cntFalse=cntFalse+1;
110 end
111 end
112 end
113 if (cntFalse==0)
114 disp('------------------------')
115 disp(' Test 2 (results): OK')
116 disp('------------------------')
117 else
118 disp('----------------------------')
119 disp(' Test 2 (results): FAILED')
120 disp('----------------------------')
121 end
122 end
123
124 function checkTest3(h,error)
125 % order 2
126 P=polyfit(log(h),log(error),1);
127 if abs(P(1)-2)< 0.1
128 disp('------------------------')
129 disp(' Test 3 (results): OK')
130 fprintf(' -> found numerical order %f. Must be 2\n',P(1))
131 disp('------------------------')
132 else
133 disp('----------------------------')
134 disp(' Test 3 (results): FAILED')
135 fprintf(' -> found numerical order %f. Must be 2\n',P(1))
136 disp('----------------------------')
137 end
138 end
139