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_TermIE.cpp
19 \author E. Lunéville
20 \since 13 sept 2013
21 \date 18 sept 2013
22
23 Tests of IE tem computation
24
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 informations in a string
28 */
29
30 #include "xlife++-libs.h"
31 #include "testUtils.hpp"
32
33 using namespace xlifepp;
34
35 namespace unit_TermIE {
36
37 // scalar kernel function
G1(const Point & M,const Point & P,Parameters & pa=defaultParameters)38 Real G1(const Point& M, const Point& P, Parameters& pa = defaultParameters)
39 {
40 return M.distance(P);
41 //return 1.; // computation
42 }
43
44
unit_TermIE(bool check)45 String unit_TermIE(bool check)
46 {
47 String rootname = "unit_TermIE";
48 trace_p->push(rootname);
49 std::stringstream out; // string stream receiving results
50 out.precision(testPrec);
51
52 verboseLevel(9);
53 // create a 2D mesh and Domains
54 std::vector<String> sidenames(4, "");
55 sidenames[0] = "y=0"; sidenames[1] = "x=1"; sidenames[2] = "y=1"; sidenames[3] = "x=0";
56 verboseLevel(10);
57 Mesh mesh2d(Rectangle(_xmin=0,_xmax=1,_ymin=0,_ymax=1,_nnodes=5,_side_names=sidenames),_triangle,1,_structured,"P1 mesh of [0,1]x[0,1]");
58 Domain omega=mesh2d.domain("Omega");
59 Domain gamma1=mesh2d.domain("y=0");
60 Domain gamma2=mesh2d.domain("y=1");
61
62 //create Lagrange P1 space and unknown
63 Interpolation *LagrangeP1=findInterpolation(Lagrange,standard,1,H1);
64 Space V1(omega,*LagrangeP1,"V1",false);
65 Unknown u(V1,"u");
66 TestFunction v(u,"v");
67
68 Parameters pars(1.,"k");
69
70 //test regular Kernel (default quadrature)
71 Kernel G=Helmholtz2dKernel(pars);
72 BilinearForm blf = intg(gamma1, gamma2, u*G*v);
73 out<<blf;
74 TermMatrix MG12(blf,"u*G*v");
75 out<<MG12<<eol;
76 TermVector un_g1(u,gamma1,1.,"un_gamma1");
77 TermVector un_g2(v,gamma2,1.,"un_gamma2");
78 out<<"\n (MG12*1_g1,1_g2)="<<realPart(MG12*un_g2|un_g1)<<"\n\n";
79
80 //test Kernel matrix and integral representation
81 TermMatrix K12(v,gamma1,u, gamma2, G, "K12");
82 out<<K12;
83 TermMatrix M2(intg(gamma2,v*u),"M2");
84 out<<K12*(M2*un_g2);
85
86 //------------------------------------------------------------------------------------
87 // save results in a file or compare results with some references value in a file
88 //------------------------------------------------------------------------------------
89 trace_p->pop();
90 if (check) { return diffResFile(out, rootname); }
91 else { return saveResToFile(out, rootname); }
92 }
93
94 }
95