# Example 10/18 - 2D Maxwell equations using Nedelec elements

XLiFE++ provides Nedelec elements (first and second family) that are H(curl) comforming. Consider the following academic Maxwell problem:

with the following weak form:

Using first family Nedelec’s element, the XLiFE++ program looks like:

#include "xlife++.h"
using namespace xlifepp;

Real omg=1, eps=1, mu=1, a=pi_, ome=omg* omg* mu* eps;

Vector<Real> f(const Point& P, Parameters& pa = defaultParameters)
{
Real x=P(1), y=P(2);
Vector<Real> res(2);
Real c=2*a*a-ome;
res(1)=-c*cos(a*x)*sin(a*y);
res(2)= c*sin(a*x)*cos(a*y);
return res;
}

Vector<Real> solex(const Point& P, Parameters& pa = defaultParameters)
{
Real x=P(1), y=P(2);
Vector<Real> res(2);
res(1)=-cos(a*x)*sin(a*y);
res(2)= sin(a*x)*cos(a*y);
return res;
}

int main(int argc, char** argv)
{
init(argc, argv, _lang=en);
// mesh square using gmsh
SquareGeo sq(_xmin=0, _xmax=1, _ymin=0, _ymax=1, _nnodes=50, _side_names="Gamma");
Mesh mesh2d(sq, triangle, 1, gmsh);
Domain omega=mesh2d.domain("Omega");
Domain gamma=mesh2d.domain("Gamma");
// define space and unknown
Space V(_domain=omega, _FE_type=Nedelec, _order=1, _name="V");
Unknown e(V, "E");
TestFunction q(e, "q");
// define forms, matrices and vectors
BilinearForm aev=intg(omega, curl(e)|curl(q)) - ome*intg(omega, e|q);
LinearForm l=intg(omega, f|q);
EssentialConditions ecs = (ncross(e)|gamma=0);
// compute
TermMatrix A(aev, ecs, "A");
TermVector b(l, "B");
// solve
TermVector E=directSolve(A, b);
// P1 interpolation, L2 projection on H1
Space W(_domain=omega, _interpolation=P1, _name="W");
TermVector EP1=projection(E, W, 2);
EP1.name("E");
saveToFile("E", EP1, vtu);
return 0;
}

As Nedelec finite elements approximation are not conforming in H1, the solution is not continuous across elements (only tangent component is continuous). So to represent the solution, it is projected on H1 as follows:

Using an H1 conforming approximation for ${E}_{1}$ leads to a continuous representation of the projection. We show on the next figure the ${E}_{x}$ component field provided by this example:  Figure 6.1: First component of the solution of the Maxwell 2D problem using Nedelec first family elements, and nodal error Figure 6.2: ${L}^{2}$ errors versus the step $h$ for 1 and 2 order Nedelec first family approximation