1 /*
2 XLiFE++ is an extended library of finite elements written in C++
3 Copyright (C) 2014 Lun�ville, Eric; Kielbasiewicz, Nicolas; Lafranche, Yvon; Nguyen, Manh-Ha; Chambeyron, Colin
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13 You should have received a copy of the GNU General Public License
14 along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17 /*!
18 \file unit_Collection.cpp
19 \author E. Lun�ville
20 \since 18 dec 2017
21 \date 18 dec 2017
22
23 Low level tests of Collection and PCollection classes.
24 Almost functionalities are checked.
25 This function may either creates a reference file storing the results (check=false)
26 or compares results to those stored in the reference file (check=true)
27 It returns reporting information in a string
28 */
29
30 #include "xlife++-libs.h"
31 #include "testUtils.hpp"
32
33 #include <iostream>
34 #include <fstream>
35 #include <sstream>
36
37 using namespace xlifepp;
38
39 namespace unit_collection {
40
unit_collection(bool check)41 String unit_collection(bool check)
42 {
43 String rootname = "unit_collection";
44 trace_p->push(rootname);
45 std::stringstream out; // string stream receiving results
46 out.precision(testPrec);
47
48 // test Strings~Collection<String>
49 out<<"Test Strings ~ Collection<String>"<<eol;
50 out<<"---------------------------------"<<eol;
51 Strings ss0; out<<"ss0 : "<<eol<<ss0<<eol;
52 Strings ss1("s1");out<<"ss1 : "<<eol<<ss1<<eol;
53 Strings ss2("s1","s2");out<<"ss2 : "<<eol<<ss2<<eol;
54 Strings ss3(3,"s3"); out<<"ss3 : "<<eol<<ss3<<eol;
55 Strings ss4;
56 for(Number i=0;i<4;i++) ss4<<"s"+tostring(i+1);
57 out<<"ss4 : "<<eol<<ss4<<eol;
58 Strings ss5(5);
59 for(Number i=1;i<=5;i++) ss5(i)="s"+tostring(i);
60 out<<"ss5 : "<<eol<<ss5<<eol;
61 out<<"join(ss5,',') : "<< join(ss5,",")<<eol;
62 #if __cplusplus >= 201103L
63 Strings ssi={"si1","si2","si3"};
64 out<<eol<<"C++11 initializer list : "<<eol<< ssi<<eol;
65 #endif
66
67 // test Numbers~Collection<Number>
68 out<<eol<<"Test Numbers ~ Collection<Number>"<<eol;
69 out<< "---------------------------------"<<eol;
70 Numbers ns0; out<<"ns0 : "<<eol<<ns0<<eol;
71 Numbers ns1(1);out<<"ns1 : "<<eol<<ns1<<eol;
72 Numbers ns2(1,2);out<<"ns2 : "<<eol<<ns2<<eol;
73 Numbers ns3(1,2,3); out<<"ns3 : "<<eol<<ns3<<eol;
74 Numbers ns4;
75 for(Number i=0;i<4;i++) ns4<<(i+1);
76 out<<"ns4 : "<<eol<<ns4<<eol;
77 Numbers ns5; ns5.resize(5);
78 for(Number i=1;i<=5;i++) ns5(i)=i;
79 out<<"ns5 : "<<eol<<ns5<<eol;
80 #if __cplusplus >= 201103L
81 Numbers nsi={1,2,3};
82 out<<"C++11 initializer list : "<< eol<<nsi<<eol;
83 #endif
84
85 // test Numbers~Collection<Int>
86 out<<eol<<"Test Ints ~ Collection<Int>"<<eol;
87 out<< "---------------------------"<<eol;
88 Ints is0; out<<"is0 : "<<eol<<is0<<eol;
89 Ints is1(1);out<<"is1 : "<<eol<<is1<<eol;
90 Ints is2(1,2);out<<"is2 : "<<eol<<is2<<eol;
91 Ints is3(1,2,3); out<<"is3 : "<<eol<<is3<<eol;
92 Ints is4;
93 for(Int i=0;i<4;i++) is4<<(i+1);
94 out<<"is4 : "<<eol<<is4<<eol;
95 Ints is5; is5.resize(5);
96 for(Int i=1;i<=5;i++) is5(i)=i;
97 out<<"is5 : "<<eol<<is5<<eol;
98 #if __cplusplus >= 201103L
99 Ints isi={1,2,3};
100 out<<"C++11 initializer list : "<< eol<<isi<<eol;
101 #endif
102
103 // test Domains~PCollection<GeomDomain>
104 Strings sn("Gamma1","Gamma2","Gamma3","Gamma4");
105 Mesh mesh2d(Rectangle(_xmin=0,_xmax=0.5,_ymin=0,_ymax=1,_nnodes=Numbers(3,6),_domain_name="Omega",_side_names=sn),_triangle,1,_structured);
106 out<<eol<<"Test Domains ~ PCollection<GeomDomain>"<<eol;
107 out<< "--------------------------------------"<<eol;
108 Domain omega=mesh2d.domain("Omega"), gamma1=mesh2d.domain("Gamma1"), gamma2=mesh2d.domain("Gamma2"),
109 gamma3=mesh2d.domain("Gamma3"),gamma4=mesh2d.domain("Gamma4");
110 Domains ds0; out<<"ds0 : "<<eol<<ds0<<eol;
111 Domains ds1(omega);out<<"ds1 : "<<eol<<ds1<<eol;
112 Domains ds2(gamma1,gamma2);out<<"ds2 : "<<eol<<ds2<<eol;
113 Domains ds3(gamma1,gamma2,gamma3); out<<"ds3 : "<<eol<<ds3<<eol;
114 Domains ds4;
115 for(Number i=0;i<4;i++) ds4<<mesh2d.domain(i+1);
116 out<<"ds4 : "<<eol<<ds4<<eol;
117 Domains ds5(5);
118 for(Number i=1;i<=5;i++) ds5(i)=mesh2d.domain(i-1);
119 out<<"ds5 : "<<eol<<ds5<<eol;
120 #if __cplusplus >= 201103L
121 Domains dsi={gamma1,gamma2,gamma3};
122 out<<"C++11 initializer list : "<< eol<<dsi<<eol;
123 #endif
124
125 // test Spaces~PCollection<Spaces>
126 out<<eol<<"Test Spaces ~ PCollection<Space>"<<eol;
127 out<< "--------------------------------"<<eol;
128 Space V1(omega,_P1,"V1"), V2(omega,_P2,"V2"), V3(omega,_P3,"V3");
129 Spaces Vs0; out<<"ds0 : "<<eol<<ds0<<eol;
130 Spaces Vs1(V1);out<<"Vs1 : "<<eol<<Vs1<<eol;
131 Spaces Vs2(V1,V2);out<<"Vs2 : "<<eol<<Vs2<<eol;
132 Spaces Vs3(V1,V2,V3); out<<"Vs3 : "<<eol<<Vs3<<eol;
133 Spaces Vs4;
134 Vs4<<V1<<V2<<V3<<V1;
135 out<<"Vs4 : "<<eol<<Vs4<<eol;
136 Spaces Vs5(5);
137 for(Number i=1;i<=5;i++)
138 Vs5(i)=Space(omega,interpolation(Lagrange,_standard,i,H1),"V_"+tostring(i));
139 out<<"Vs5 : "<<eol<<Vs5<<eol;
140 #if __cplusplus >= 201103L
141 Spaces Vsi={V1,V2,V3};
142 out<<"C++11 initializer list : "<< eol<<Vsi<<eol;
143 #endif
144 Spaces Ws1=spaces(ds3,interpolation(Lagrange,_standard,1,H1));
145 out<<"test spaces(Domains,Interpolation) : "<<eol<<Ws1<<eol;
146 Interpolations ints(3);
147 for(Number i=1;i<=3;i++) ints(i)=interpolation(Lagrange,_standard,i,H1);
148 Spaces Ws2=spaces(omega,ints);
149 out<<"test spaces(Domain,Interpolations) : "<<eol<<Ws2<<eol;
150 Spaces Ws3=spaces(ds3,ints);
151 out<<"test spaces(Domains,Interpolations) : "<<eol<<Ws3<<eol;
152
153 // test Unknowns~PCollection<Unknown>
154 out<<eol<<"Test Unknowns ~ PCollection<Unknown>"<<eol;
155 out<< "------------------------------------"<<eol;
156 Unknown u1(V1,"u1"), u2(V2,"u2"), u3(V3,"u3");
157 Unknowns us1(u1,u2,u3); out<<"us1 : "<<eol<<us1<<eol;
158 Unknowns us2;
159 us2<<u1<<u2<<u3;
160 out<<"us2 : "<<eol<<us2<<eol;
161 Unknowns us5(5);
162 for(Number i=1;i<=5;i++)
163 us5(i)=Unknown(Vs5(i),"u_"+tostring(i));
164 out<<"us5 : "<<eol<<us5<<eol;
165 #if __cplusplus >= 201103L
166 Unknowns usi={u1,u2,u3};
167 out<<"C++11 initializer list : "<< eol<<usi<<eol;
168 #endif
169
170 TestFunctions ts5=dualOf(us5);
171 out<<"ts5 : "<<eol<<ts5<<eol;
172
173 //------------------------------------------------------------------------------------
174 // save results in a file or compare results with some references value in a file
175 //------------------------------------------------------------------------------------
176 trace_p->pop();
177 if (check) { return diffResFile(out, rootname); }
178 else { return saveResToFile(out, rootname); }
179 }
180
181 }
182