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 \file Laplace2dKernel.cpp
18 \author E. Lunéville
19 \since 17 may 2016
20 \date 17 may 2016
21
22 \brief Implementation of Laplace 2D kernels
23
24 Laplace2D kernel K(k; x, y)=(-1/2 pi)*log(|x-y|)
25 */
26
27 #include "Laplace2dKernel.hpp"
28 #include "utils.h"
29
30 namespace xlifepp
31 {
32
33
34 //--------------------------------------------------------------------------------------------
35 //construct Laplace2d Kernel : G(k; x, y)=-(1/2 pi)*log(|x-y|)
36 //--------------------------------------------------------------------------------------------
37
38 //construct a Laplace2d Kernel
Laplace2dKernel(Parameters & pars)39 Kernel Laplace2dKernel(Parameters& pars)
40 {
41 Kernel K;
42 K.dimPoint=2;
43 K.name="Laplace 2D kernel";
44 K.shortname="Lap2D";
45 K.singularType =_logr;
46 K.singularOrder = 1;
47 K.singularCoefficient = -over2pi_;
48 K.symmetry=_symmetric;
49 K.userData.push(pars);
50 K.kernel = Function(Laplace2d, 2, K.userData);
51 K.gradx = Function(Laplace2dGradx, 2, K.userData);
52 K.grady = Function(Laplace2dGrady, 2, K.userData);
53 K.ndotgradx = Function(Laplace2dNxdotGradx, 2, K.userData);
54 K.ndotgrady = Function(Laplace2dNydotGrady, 2, K.userData);
55 return K;
56 }
57
Laplace2d(const Point & x,const Point & y,Parameters & pars)58 real_t Laplace2d(const Point& x, const Point& y, Parameters& pars)
59 {
60 return -over2pi_*std::log(x.distance(y));
61 }
62
63 //derivatives
Laplace2dGradx(const Point & x,const Point & y,Parameters & pars)64 Vector<real_t> Laplace2dGradx(const Point& x, const Point& y,Parameters& pars)
65 {
66 real_t r = x.distance(y);
67 Vector<real_t> g(2);
68 real_t a = -over2pi_ / (r*r);
69 g[0]=a*(x[0]-y[0]);
70 g[1]=a*(x[1]-y[1]);
71 return g;
72 }
73
Laplace2dGrady(const Point & x,const Point & y,Parameters & pars)74 Vector<real_t> Laplace2dGrady(const Point& x, const Point& y,Parameters& pars)
75 {
76 real_t r = x.distance(y);
77 Vector<real_t> g(2);
78 real_t a = over2pi_ / (r*r);
79 g[0]=a*(x[0]-y[0]);
80 g[1]=a*(x[1]-y[1]);
81 return g;
82 }
83
Laplace2dNxdotGradx(const Point & x,const Point & y,Parameters & pars)84 real_t Laplace2dNxdotGradx(const Point& x, const Point& y, Parameters& pars)
85 {
86 Vector<real_t>& nxp = getNx();
87 std::vector<real_t>::const_iterator itx=x.begin(),ity=y.begin(), itn=nxp.begin();
88 real_t d1=(*itx++ - *ity++), d2=(*itx - *ity);
89 real_t r=x.distance(y);
90 real_t rn = d1* *itn++; rn+= d2* *itn;
91 return -rn*over2pi_/(r*r);
92 }
93
Laplace2dNydotGrady(const Point & x,const Point & y,Parameters & pars)94 real_t Laplace2dNydotGrady(const Point& x, const Point& y, Parameters& pars)
95 {
96 Vector<real_t>& nyp = getNy();
97 std::vector<real_t>::const_iterator itx=x.begin(),ity=y.begin(), itn=nyp.begin();
98 real_t d1=(*itx++ - *ity++), d2=(*itx - *ity);
99 real_t r=x.distance(y);
100 real_t rn = d1* *itn++; rn+= d2* *itn;
101 return rn*over2pi_/(r*r);
102 }
103
104 }
105