2D Laplace problem with Dirichlet condition#
Let us consider now the case of non-homogeneous Dirichlet condition on the boundaries \(x=0\) (\(\Sigma^-\)) and \(x=1\) (\(\Sigma^+\)):
\[u=1 \mathrm{\;on\;}\Sigma^-\cup \Sigma^+.\]
The variational formulation is now (\(a=0\))
\[\begin{split}\left|
\begin{array}{c}
\mathrm{find\;} u\in V=\left\{v\in L^2(\Omega), \nabla v\in (L^2(\Omega))^2\right\} \mathrm{\;such\;that} \\
\begin{aligned}
& \displaystyle \int_\Omega \nabla u.\nabla v =\int_\Omega f\, v & & \forall v\in V,\ v=0 \mathrm{\;on\;}\Sigma^-\cup \Sigma^+\\
& u=1 & & \mathrm{\;on\;}\Sigma^-\cup \Sigma^+
\end{aligned}
\end{array}
\right.\end{split}\]
Its approximation by P1 Lagrange finite element is implemented in XLiFE++ as follows:
#include "xlife++.h"
using namespace xlifepp;
Real f(const Point& P, Parameters& pa = defaultParameters)
{return -8.;}
int main(int argc, char** argv)
{
init(argc, argv, _lang=en); // mandatory initialization of xlifepp
// create mesh of square
Strings sn("y=0", "x=1", "y=1", "x=0");
SquareGeo sq(_origin=Point(0., 0.), _length=1, _nnodes=20, _domain_name="Omega", _side_names=sn);
Mesh mesh2d(sq, _shape=triangle, _generator=structured);
Domain omega=mesh2d.domain("Omega");
Domain sigmaM=mesh2d.domain("x=0"), sigmaP=mesh2d.domain("x=1");
// create interpolation
Space V(_domain=omega, _interpolation=P1, _name="V");
Unknown u(V, _name="u");
TestFunction v(u, _name="v");
// create bilinear form, linear form and their algebraic representation
BilinearForm auv=intg(omega, grad(u)|grad(v));
LinearForm fv=intg(omega, f*v);
EssentialConditions ecs= (u|sigmaM = 1) & (u|sigmaP = 1);
TermMatrix A(auv, ecs, _name="A");
TermVector B(fv, _name="B");
// solve linear system AX=B
TermVector U=directSolve(A, B);
saveToFile("U_LD", U, _format=vtu);
return 0;
}
Note how easy is to take into account essential conditions. Only two lines has to be modified!