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