OptFEM3DP1 Toolbox: valid/validStiff3DP1.m Source File

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